#smartcontracts

blockchain-runtime: Blockchain-Agnostic Testing and Simulation Framework for Rust

Red Asgard releases blockchain-runtime, a powerful Rust crate for dynamic blockchain analysis, testing, and simulation across multiple chains without vendor lock-in.

Red Asgard Security Team
October 24, 2025
rustblockchaintestingethereumsimulationopen-source

blockchain-runtime: Blockchain-Agnostic Testing and Simulation Framework

Today we're releasing blockchain-runtime, an open-source Rust library that provides a unified runtime abstraction for blockchain testing, simulation, and dynamic analysis across multiple chains.

Package: blockchain-runtime on crates.io
Repository: github.com/redasgard/blockchain-runtime
License: MIT
Version: 0.1.0
Downloads: 177+


The Problem: Chain-Specific Testing Tools

When testing smart contracts or blockchain applications, developers face several challenges:

Fragmentation:

  • Each blockchain has its own testing framework
  • Ethereum uses Hardhat/Foundry
  • Solana uses Anchor
  • TON uses different tooling
  • No unified approach across chains

Simulation Limitations:

  • Hard to test cross-chain interactions
  • Difficult to simulate realistic chain conditions
  • Time-consuming to switch between environments
  • Limited dynamic analysis capabilities

Security Testing Gaps:

  • Static analysis misses runtime behavior
  • Integration tests don't cover edge cases
  • Fuzzing requires chain-specific setup
  • Difficult to reproduce exploits

Solution: Chain-Agnostic Runtime Abstraction

blockchain-runtime provides a unified interface for:

1. Dynamic Contract Analysis

use blockchain_runtime::{Runtime, Chain};

// Works with any supported chain
let runtime = Runtime::new(Chain::Ethereum);

// Deploy and interact with contracts
let contract = runtime.deploy_contract(bytecode, constructor_args)?;
let result = runtime.call(contract, "transfer", args)?;

// Inspect state
let balance = runtime.get_storage(contract, slot)?;
let traces = runtime.get_execution_trace()?;

2. Multi-Chain Testing

use blockchain_runtime::{Runtime, Chain};

#[test]
fn test_cross_chain_bridge() {
    let eth = Runtime::new(Chain::Ethereum);
    let bsc = Runtime::new(Chain::BSC);
    
    // Test bridge logic on both chains
    let lock_tx = eth.execute_transaction(lock_tokens)?;
    let unlock_tx = bsc.execute_transaction(unlock_tokens)?;
    
    assert_eq!(eth.get_balance(user), 0);
    assert_eq!(bsc.get_balance(user), locked_amount);
}

3. Realistic Simulation

use blockchain_runtime::{Runtime, SimulationConfig};

let config = SimulationConfig {
    block_time: 12, // seconds
    gas_limit: 30_000_000,
    base_fee: 20_000_000_000, // wei
    timestamp: 1730000000,
};

let runtime = Runtime::with_config(Chain::Ethereum, config);

// Advance chain state
runtime.mine_blocks(100)?;
runtime.set_block_timestamp(future_time)?;

// Test time-dependent logic
let vested_amount = runtime.call(vesting_contract, "getVestedAmount", [])?;

Core Features

Supported Blockchains

Current (v0.1.0):

  • Ethereum (EVM)
  • BSC (EVM-compatible)
  • Polygon (EVM-compatible)

Planned (v0.2.0):

  • Solana
  • TON
  • Arbitrum/Optimism
  • Cosmos chains

Runtime Capabilities

State Management:

  • Account balance manipulation
  • Storage slot access
  • Block parameters control
  • Timestamp manipulation

Transaction Execution:

  • Contract deployment
  • Function calls with ABI encoding
  • Raw transaction execution
  • Gas profiling

Debugging & Analysis:

  • Execution traces
  • Event log capture
  • Revert reason extraction
  • Gas usage breakdown

Simulation:

  • Block mining
  • Time travel
  • State snapshots and rollback
  • Fork from mainnet state

Technical Architecture

Abstraction Layers

???????????????????????????????????????
?     User API (Chain-Agnostic)       ?
???????????????????????????????????????
?   Runtime Abstraction Layer         ?
???????????????????????????????????????
?   Chain Adapters                    ?
?   ?? EVM Adapter                    ?
?   ?? Solana Adapter (planned)       ?
?   ?? TON Adapter (planned)          ?
???????????????????????????????????????
?   Execution Engines                 ?
?   ?? revm (Ethereum)                ?
?   ?? Solana SBF VM (planned)        ?
?   ?? TON VM (planned)               ?
???????????????????????????????????????

Design Principles

1. Zero-Copy Where Possible

  • Efficient memory usage
  • Minimal allocations
  • Borrowed data by default

2. Type-Safe

  • Strong typing for addresses, hashes, amounts
  • Compile-time chain validation
  • No runtime type errors

3. Extensible

  • Plugin architecture for new chains
  • Custom adapter registration
  • Hook system for instrumentation

Real-World Usage

Security Testing

use blockchain_runtime::{Runtime, Chain};

#[test]
fn test_reentrancy_vulnerability() {
    let runtime = Runtime::new(Chain::Ethereum);
    
    // Deploy vulnerable contract
    let vulnerable = runtime.deploy(VULNERABLE_BYTECODE)?;
    
    // Deploy attacker contract
    let attacker = runtime.deploy(ATTACKER_BYTECODE)?;
    
    // Execute reentrancy attack
    let result = runtime.call(
        attacker,
        "attack",
        vec![vulnerable.address()]
    )?;
    
    // Verify exploit succeeded (for testing)
    let stolen = runtime.get_balance(attacker)?;
    assert!(stolen > 0, "Reentrancy exploit failed - contract may be secure");
}

Fuzzing Integration

use blockchain_runtime::Runtime;
use arbitrary::Arbitrary;

#[derive(Arbitrary, Debug)]
struct FuzzInput {
    amount: u64,
    recipient: [u8; 20],
    data: Vec<u8>,
}

fuzz_target!(|input: FuzzInput| {
    let runtime = Runtime::new(Chain::Ethereum);
    let contract = setup_contract(&runtime);
    
    // Fuzz contract calls
    let _ = runtime.call(
        contract,
        "process",
        vec![input.amount, input.recipient, input.data]
    );
    
    // Check invariants
    assert_balance_invariants(&runtime, contract);
});

Exploit Reproduction

use blockchain_runtime::{Runtime, Chain};

fn reproduce_balancer_exploit() -> Result<()> {
    let runtime = Runtime::fork_from_mainnet(
        Chain::Ethereum,
        21_xxx_xxx // Block before exploit
    )?;
    
    // Setup: Deploy contracts in same state
    let vault = runtime.get_contract(BALANCER_VAULT_ADDRESS)?;
    let attacker = runtime.create_account()?;
    
    // Reproduce exploit transaction
    let tx_data = hex::decode(EXPLOIT_CALLDATA)?;
    let result = runtime.send_transaction(
        attacker,
        vault.address(),
        0,
        tx_data
    )?;
    
    // Analyze what happened
    let trace = runtime.get_execution_trace()?;
    let stolen = runtime.get_balance_change(attacker)?;
    
    Ok(())
}

Installation & Quick Start

Add to Cargo.toml

[dependencies]
blockchain-runtime = "0.1"

# With optional tracing
blockchain-runtime = { version = "0.1", features = ["tracing"] }

# Dev dependencies for testing
[dev-dependencies]
blockchain-runtime = "0.1"

Quick Example

use blockchain_runtime::{Runtime, Chain};

fn main() -> Result<()> {
    // Create runtime
    let runtime = Runtime::new(Chain::Ethereum);
    
    // Create test accounts
    let deployer = runtime.create_account_with_balance(1_000_000)?;
    let user = runtime.create_account_with_balance(1_000)?;
    
    // Deploy contract
    let contract = runtime.deploy_from_file(
        "MyContract.sol",
        deployer
    )?;
    
    // Execute transaction
    let tx = runtime.transaction()
        .from(user)
        .to(contract.address())
        .function("myFunction", vec![42])
        .send()?;
    
    // Check result
    assert!(tx.success);
    println!("Gas used: {}", tx.gas_used);
    
    Ok(())
}

Use Cases

1. Smart Contract Auditing

Run dynamic analysis during security audits:

  • Test edge cases not covered by unit tests
  • Simulate attack scenarios
  • Verify fix effectiveness
  • Generate proof-of-concept exploits

2. Integration Testing

Test cross-contract and cross-chain interactions:

  • Multi-contract test scenarios
  • Bridge testing
  • Oracle integration testing
  • Complex DeFi flows

3. Research & Education

Study blockchain behavior:

  • Analyze historical exploits
  • Research new attack vectors
  • Educational demonstrations
  • Protocol comparison

4. Continuous Security

Integrate into CI/CD:

# .github/workflows/security.yml
- name: Run security tests
  run: cargo test --features blockchain-runtime

Performance

Optimized for test performance:

OperationTime
Runtime initialization~5ms
Contract deployment~10ms
Simple call~0.5ms
Complex call (100+ ops)~15ms
Fork from mainnet~200ms
Mine 1000 blocks~100ms

Memory Usage:

  • Base runtime: ~10MB
  • Per contract: ~1-5MB
  • Mainnet fork: ~500MB (depending on state size)

Comparison with Existing Tools

Featureblockchain-runtimeFoundryHardhatGanache
LanguageRustSolidity/RustJavaScriptJavaScript
Multi-chainYes (abstracted)EVM onlyEVM onlyEVM only
SpeedFast (~0.5ms/call)FastMediumSlow
Fork from mainnetYesYesYesYes
Type safetyStrongMediumWeakWeak
Programmatic APIYesLimitedYesYes

Roadmap

v0.2.0 (Q4 2025)

  • Solana runtime support
  • TON runtime support
  • State diff visualization
  • Performance profiling tools

v0.3.0 (Q1 2026)

  • Layer 2 support (Arbitrum, Optimism, Base)
  • Enhanced debugging (step-through execution)
  • Symbolic execution integration
  • Formal verification hooks

Future

  • More chain adapters
  • Cloud-based fork API
  • Visual debugger
  • IDE integration

Contributing

We welcome contributions!

Areas for contribution:

  • New chain adapters
  • Performance optimizations
  • Additional test utilities
  • Documentation improvements
  • Example test suites

Get started:

git clone https://github.com/redasgard/blockchain-runtime
cd blockchain-runtime
cargo test

About Red Asgard

This library emerged from our security audit practice. When testing complex DeFi protocols, we needed better tools for dynamic analysis and exploit reproduction.

Our open-source ecosystem:

  • llm-security - LLM prompt injection defense
  • path-security - Path traversal protection
  • quantum-shield - Post-quantum cryptography
  • module-registry - Dynamic plugin system
  • threat-intel - Threat intelligence framework

All MIT licensed and maintained by Red Asgard's security research team.


Get Started

cargo add blockchain-runtime

Read the full documentation on GitHub.

For professional blockchain security audits, contact Red Asgard.


Released: October 24, 2025
Version: 0.1.0
License: MIT

Share this article

Help spread the word about security best practices.

Need Security Help?

Our team can help secure your blockchain, web applications, and infrastructure.