REVM Transaction Simulator and Analyzer v3.0
A high-performance, multi-threaded Rust library that combines powerful transaction simulation with comprehensive analysis capabilities for EVM-based blockchains. Built on REVM, this tool enables you to:
- 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:
- DeFi developers testing complex interactions
- Wallet developers validating transaction safety
- Protocol teams analyzing contract behaviors
- Security researchers investigating transaction patterns
- High-throughput applications requiring concurrent transaction processing
🚀 What's New in v3.0
- 🔥 Multi-Threading by Default: All EVM instances are now thread-safe and optimized for concurrent processing
- ⚡ Dual EVM Modes: Choose between high-performance execution or detailed tracing based on your needs
- 🎯 Simplified API: Unified interface with
create_evm()
andcreate_evm_with_tracer()
functions - 🌐 Universal Protocol Support: Seamless HTTP/WebSocket support with automatic connection management
Key Features
-
Dual EVM Mode Support
- Standard EVM: Ultra-fast execution without tracing (
create_evm()
) - Tracing EVM: Full transaction analysis with comprehensive trace data (
create_evm_with_tracer()
) - Seamless switching between modes based on your requirements
- Built-in thread safety for concurrent processing
- Standard EVM: Ultra-fast execution without tracing (
-
Multi-Threading by Default
- All EVM instances are thread-safe out of the box
- Shared cache database for optimal performance
- Concurrent transaction simulation and analysis
- Optimized for high-throughput applications
-
Flexible Inspector System
- Built on REVM's inspector framework
- Custom
TxInspector
for detailed transaction analysis - Support for custom inspector implementations
- Comprehensive asset transfer tracking
- Optional no-op inspector for performance-critical scenarios
-
Complete Call Hierarchy Analysis
- Full depth call stack tracking
- Detailed call context information
- Internal transaction tracing
- Precise error location in call stack
- Step-by-step execution tracing
-
Enhanced Error Handling
- Detailed error messages and traces
- Error location in call stack
- Revert reason decoding
- Custom error parsing
- Contract-specific error context
-
Batch Transaction Processing
- Process multiple transactions
- Stateful/stateless execution modes
- Automatic state management
- Detailed execution results
-
Asset Analysis
- Native token transfers
- ERC20 token transfers
- Transfer event parsing
- Balance change tracking
- Complete transaction logs
-
Universal Multicall Support
- Dynamic Multicall contract deployment
- Batch execution of multiple contract calls
- Works on any EVM-compatible chain
- Zero dependency on pre-deployed contracts
- Optimized for cross-chain compatibility
- Support for 100+ calls in single batch
Installation
Add this to your Cargo.toml
:
[]
= "3.0.0"
TLS Backend Selection
Important: The TLS backend features are mutually exclusive. Choose only one:
[]
# Option 1: Default - uses native-tls (OpenSSL) for maximum compatibility
= "3.0.0"
# Option 2: Pure Rust TLS with rustls for system-dependency-free builds
= { = "3.0.0", = false, = ["rustls-tls"] }
Do not specify both features simultaneously, as this will include both TLS implementations and increase binary size unnecessarily.
Quick Start
REVM-Trace v3.0 provides two distinct EVM modes to match your specific use case:
🚀 Mode 1: Standard EVM (High Performance)
Use create_evm()
when you need maximum speed and only require execution results:
use ;
use ;
async
🔍 Mode 2: Tracing EVM (Full Analysis)
Use create_evm_with_tracer()
when you need comprehensive analysis with detailed trace data:
use ;
use ;
async
🌐 WebSocket Support
Both EVM modes support WebSocket connections for real-time blockchain data:
use ;
// High-performance EVM with WebSocket (auto-detected from URL)
let evm = create_evm.await?;
// Full tracing EVM with WebSocket (auto-detected from URL)
let tracer = new;
let evm = create_evm_with_tracer.await?;
🔧 Batch Contract Calls with Multicall
The library includes universal Multicall support that works on any EVM-compatible chain:
use ;
use ;
async
🚀 Multi-Threading & Concurrent Processing
REVM-Trace v3.0 is designed from the ground up for high-performance concurrent processing:
use ;
use Arc;
use task;
async
🎯 Performance Tips
Scenario | Recommended Mode | Why |
---|---|---|
High-frequency trading simulations | create_evm() |
Maximum speed, minimal overhead |
DeFi protocol analysis | create_evm_with_tracer() |
Rich trace data for comprehensive analysis |
Batch processing | create_evm() + concurrent tasks |
Optimal throughput |
Transaction debugging | create_evm_with_tracer() |
Detailed error traces and call stacks |
More Examples
For more detailed examples and use cases, please check:
-
Example Directory: Contains standalone examples demonstrating specific features
- DeFi interaction simulations
- Token transfer analysis
- Complex contract interactions
- Proxy contract handling
-
Integration Tests: Comprehensive test cases showing various usage scenarios
- Transaction batching
- Error handling
- State tracking
- Event analysis
These examples cover common use cases and demonstrate best practices for using the library.
For a quick overview, here are some key examples:
- Simulating DeFi Swaps
- Analyzing Token Transfers
- Handling Complex Contract Interactions
- Working with Proxy Contracts
Important Notes
🛡️ Thread Safety in v3.0
✅ What's New: Built-in Multi-Threading Support
REVM-Trace v3.0 introduces native multi-threading capabilities with optimized concurrent processing patterns:
use ;
use task;
// ✅ Recommended: Each task creates its own EVM instance
async
🚀 Performance Patterns
Pattern | v3.0 Recommendation | Performance |
---|---|---|
Single-threaded | create_evm() or create_evm_with_tracer() |
⭐⭐⭐ Good |
Multi-threaded | One EVM per thread | ⭐⭐⭐⭐⭐ Excellent |
High-throughput | create_evm() + concurrent tasks |
⭐⭐⭐⭐⭐ Maximum |
⚠️ Migration from v2.x
In v2.x, EVM instances were NOT thread-safe and could NOT be used concurrently, even with Arc<Mutex<>>
wrapping due to underlying database connection limitations. v3.0 introduces true multi-threading support:
// ❌ v2.x: NO concurrent support - this would fail!
// let evm = Arc::new(Mutex::new(create_evm().await?)); // ← This doesn't work!
// Multiple threads would cause database connection conflicts
// ✅ v3.0: True multi-threading - each thread gets its own optimized EVM
let mut evm = create_evm.await?; // Thread-safe from ground up
🛡️ Safe Simulation Environment
All simulations run in an isolated environment:
- ✅ No actual blockchain state is modified
- ✅ No real transactions are submitted
- ✅ No gas fees are spent
- ✅ Perfect for testing and validation
- ✅ Full rollback support for complex scenarios
📈 Performance Considerations
- RPC Optimization: Each EVM instance maintains optimized RPC connections
- Memory Efficiency: Smart caching reduces memory footprint
- Concurrent Processing: Built-in support for high-throughput scenarios
- Resource Management: Automatic cleanup and connection pooling
Recommended Patterns:
- Small batches: Use single EVM instance with
execute_batch()
- Large batches: Use multiple EVM instances across threads
- Real-time processing: Use WebSocket connections with
create_evm("wss://...")"
Working with Proxy Contracts
The library automatically handles proxy contracts by resolving their implementations:
- EIP-1967 proxies
- EIP-1967 beacon proxies
- OpenZeppelin transparent proxies
- EIP-1822 (UUPS) proxies
Features in Detail
Asset Transfer Tracking
- Native token transfers (including internal transfers)
- ERC20 token transfers
- Transaction logs and events
- Chronological ordering of transfers
- Complete token information collection
Transaction Simulation
- Full EVM context simulation
- Custom environment configuration
- Detailed execution results
- Error handling and revert messages
Historical State Access
Simulations can be run against different historical states:
- Recent blocks: Available on all nodes
- Historical blocks: Requires archive node access
- Future blocks: Uses latest state as base
🌐 Web API Integration
Actix-Web Integration
REVM-Trace v3.0 provides seamless integration with web frameworks. Here's a complete example using Actix-Web:
// examples/actix_web_integration.rs
use ;
use ;
async
Key Features:
- 🚀 Two Implementation Approaches: Choose between
tokio::task::spawn_blocking
orweb::block
- ⚡ High Performance: Each request creates optimized EVM instances
- 🛡️ Thread Safety: Built-in multi-threading support for concurrent requests
- 📊 Flexible Responses: Optional tracing with detailed call traces and asset transfers
- 🔧 Easy Integration: Drop-in solution for existing Actix-Web applications
API Example:
Request:
Response:
Multi-Threading Approaches:
Approach 1: web::block
(Recommended)
async
Approach 2: tokio::task::spawn_blocking
async
Run the Example:
# Test with curl:
💡 Production Tip: Consider using Nginx rate limiting for production deployments to manage request frequency and prevent resource exhaustion.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📄 License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
🙏 Acknowledgments
Built with ❤️ using:
- REVM - The Rust Ethereum Virtual Machine
- Alloy - High-performance Ethereum library
- Foundry Fork DB - Efficient blockchain state forking and caching
REVM-Trace v3.0 - Multi-threaded EVM simulation with comprehensive analysis