| Crates.io | revm-trace |
| lib.rs | revm-trace |
| version | 4.2.0 |
| created_at | 2024-11-24 04:21:34.641751+00 |
| updated_at | 2025-07-29 06:33:39.441416+00 |
| description | High-performance multi-threaded EVM transaction simulator and analyzer with comprehensive tracing capabilities |
| homepage | https://github.com/Rollp0x/revm-trace |
| repository | https://github.com/Rollp0x/revm-trace |
| max_upload_size | |
| id | 1458958 |
| size | 458,896 |
A high-performance, multi-threaded Rust library for EVM transaction simulation and analysis, built on REVM.
Simulate complex transactions and their interactions before actual execution
Analyze potential outcomes, asset transfers, and state changes
Detect possible errors and their root causes
Preview all transaction effects in a safe, isolated environment
Process multiple transactions concurrently with built-in thread safety
Perfect for:
overrides field in SimulationBatch. This enables advanced scenarios such as simulating Safe wallet proposals, presetting ERC20 balances, or testing contracts under custom state conditions.SlotAccess), with full details (slot address, old/new value, access type, call context, etc.).CallTrace) now recursively collects all slot accesses (read/write/all), supporting deep contract call trees and complex exploit analysis.SimulationBatch struct now requires an overrides field (use None for default behavior). Please update your code accordingly.EvmBuilder for full control (custom block height, inspector, etc.). For convenience, use create_evm and create_evm_with_tracer for quick EVM creation at the latest block.set_db_block (which also resets the database cache to ensure state consistency).foundry-fork feature for high-performance, thread-safe simulation with Foundry-fork-db (see examples/concurrent_shared_backend.rs).block_env parameter; block context is managed at EVM creation.TokenTransfer struct now includes token_type and id fields to support NFTs.Quick Start (Latest Block)
let mut evm = create_evm("https://eth.llamarpc.com").await?;
// or with tracing:
let tracer = TxInspector::new();
let mut evm = create_evm_with_tracer("https://eth.llamarpc.com", tracer).await?;
Custom Block Height (Recommended for Historical Simulation)
let mut evm = EvmBuilder::new_alloy("https://eth.llamarpc.com")
.with_block_number(18_000_000)
.with_tracer(TxInspector::new())
.build()
.await?;
Change Block Context After Creation
// After creating the EVM, you can update the block context:
// This will also create a brand new EVM environment and clears all internal cache.
evm.set_db_block(block_env)?;
Multi-Threaded Simulation (Foundry-fork-db)
foundry-fork feature in Cargo.toml.examples/concurrent_shared_backend.rs for a complete example.| Mode | API | Inspector | Use Case | Performance |
|---|---|---|---|---|
| 1. Simple Execution | create_evm() + execute_batch() |
NoOpInspector |
Gas estimation, fast simulation | Fastest, no tracing |
| 2. Manual Inspector | create_evm_with_tracer() + manual inspect_replay_commit() |
Custom (e.g. TxInspector) |
Debugging, custom tracing, research | Full control |
| 3. Automatic Batch | create_evm_with_tracer() + trace_transactions() |
Must implement TraceOutput |
Standard trace analysis, automation | Clean API, auto state mgmt |
TxInspector or your own inspector for tracing and analysis.While trace_transactions provides a convenient batch simulation and tracing API for most use cases, advanced users can construct and control the EVM instance directly using REVM and this crate’s inspector system.
The core value of this crate lies in the TxInspector and its output TxTraceOutput, which provide detailed, structured tracing of transaction execution, asset transfers, call trees, events, and errors.
For custom analysis (e.g., storage slot changes, balance diffs, or other state introspection), users can run their own simulation loop, obtain ResultAndState from REVM, and combine it with TxInspector for maximum flexibility.
Add this to your Cargo.toml:
[dependencies]
revm-trace = "4.2.0"
Important: The TLS backend features are mutually exclusive. Choose only one:
# Option 1: Default - uses native-tls (OpenSSL) for maximum compatibility
revm-trace = "4.2.0"
# Option 2: Pure Rust TLS with rustls for system-dependency-free builds
revm-trace = { version = "4.2.0", default-features = false, features = ["rustls-tls"] }
Simulate an ERC20 transfer and print slot changes in just a few lines:
use revm_trace::{create_evm_with_tracer, types::SlotAccessType, SimulationTx, SimulationBatch, TxInspector};
use alloy::primitives::{address, U256, TxKind};
#[tokio::main]
async fn main() {
let inspector = TxInspector::new();
let mut evm = create_evm_with_tracer("https://eth.llamarpc.com", inspector).await.unwrap();
let tx = SimulationTx {
caller: address!("28C6c06298d514Db089934071355E5743bf21d60"),
transact_to: TxKind::Call(address!("A0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48")),
value: U256::ZERO,
data: hex::decode("a9059cbb00000000000000000000000034e5dacdc16ff5bcdbdfa66c21a20f46347d86cf00000000000000000000000000000000000000000000000000000000000f4240").unwrap().into(),
};
let result = &evm.trace_transactions(SimulationBatch {
is_stateful: false,
transactions: vec![tx],
overrides: None,
}).into_iter().map(|v| v.unwrap()).collect::<Vec<_>>()[0];
// Print all slot writes in the call trace
if let Some(call_trace) = result.2.call_trace.as_ref() {
for change in call_trace.all_slot_accesses(SlotAccessType::Write) {
println!("Slot Write: {:?}", change);
}
}
}
See examples/ for advanced usage: multi-threaded simulation, custom inspectors, batch processing, DeFi/security analysis, and more.
This project is licensed under either of
at your option.
Built with ❤️ using:
REVM-Trace v4.2.0 - Multi-threaded EVM simulation with comprehensive analysis