A comprehensive guide to using the EVM Rust command-line interface.
- Rust 1.70+ installed
- Git (for cloning the repository)
# Clone the repository
git clone https://github.com/panditdhamdhere/Rust_EVM
cd evm-rust
# Build the project
cargo build --release
# The binary will be available at target/release/evm-rust# Run with help to see all available commands
./target/release/evm-rust --help
# Or if you have cargo installed
cargo run -- --helpThe EVM Rust CLI provides several commands for interacting with the Ethereum Virtual Machine:
evm-rust <COMMAND> [OPTIONS]--help: Show help information--version: Show version information
Execute EVM bytecode directly.
evm-rust execute [OPTIONS]| Option | Description | Default | Example |
|---|---|---|---|
--code <HEX> |
Bytecode to execute (hex string) | Required | --code "6002600301" |
--gas-limit <LIMIT> |
Gas limit for execution | 1000000 |
--gas-limit 500000 |
--debug |
Enable debug output | false |
--debug |
--trace |
Enable basic tracing | false |
--trace |
--detailed-trace |
Enable detailed execution tracing | false |
--detailed-trace |
--caller <ADDRESS> |
Caller address (hex) | 0x0000...0000 |
--caller "0x1234..." |
--address <ADDRESS> |
Contract address (hex) | 0x0000...0000 |
--address "0x5678..." |
--value <WEI> |
Call value in wei | 0 |
--value "1000000000000000000" |
--input <HEX> |
Input data (hex) | "" |
--input "0x1234" |
--no-validate |
Disable validation checks | false |
--no-validate |
--export-trace <FILE> |
Export trace to file | None | --export-trace trace.json |
Basic execution:
evm-rust execute --code "6002600301"With custom gas limit:
evm-rust execute --code "6002600301" --gas-limit 500000With debug output:
evm-rust execute --code "6002600301" --debugWith detailed tracing:
evm-rust execute --code "6002600301" --detailed-traceExport execution trace:
evm-rust execute --code "6002600301" --export-trace execution.jsonWith custom context:
evm-rust execute \
--code "6002600301" \
--caller "0x1234567890123456789012345678901234567890" \
--address "0xabcdefabcdefabcdefabcdefabcdefabcdefabcd" \
--value "1000000000000000000" \
--input "0x1234"Execute predefined EVM examples.
evm-rust examples [OPTIONS]| Option | Description | Default | Example |
|---|---|---|---|
--number <NUM> |
Run specific example (1-10) | None | --number 5 |
--list |
List all available examples | false |
--list |
List all examples:
evm-rust examples --listRun specific example:
evm-rust examples --number 3Run all examples:
evm-rust examplesStart an interactive EVM shell (placeholder).
evm-rust shell [OPTIONS]| Option | Description | Default | Example |
|---|---|---|---|
--gas-limit <LIMIT> |
Gas limit for shell execution | 1000000 |
--gas-limit 500000 |
evm-rust shell
evm-rust shell --gas-limit 2000000Display EVM information and statistics.
evm-rust info [OPTIONS]| Option | Description | Default | Example |
|---|---|---|---|
--opcodes |
Show supported opcodes | false |
--opcodes |
--gas-costs |
Show gas cost information | false |
--gas-costs |
--validation |
Show validation limits | false |
--validation |
Show all information:
evm-rust info --opcodes --gas-costs --validationShow only opcodes:
evm-rust info --opcodesShow validation limits:
evm-rust info --validation# Add 2 + 3 = 5
evm-rust execute --code "6002600301" --debugBytecode breakdown:
60 02: PUSH1 0x02 (push 2 to stack)60 03: PUSH1 0x03 (push 3 to stack)01: ADD (pop 2 values, add them, push result)
# Demonstrate stack operations
evm-rust execute --code "600160026003808080" --detailed-trace# Store and load from memory
evm-rust execute --code "600260005260016000f3" --debug# Hash data using SHA3
evm-rust execute --code "60016000536020" --detailed-trace# Emit a LOG0 event
evm-rust execute --code "60016000536020a0" --debugThe EVM includes a comprehensive validation system that checks:
- Bytecode validation: Ensures all opcodes are valid
- Jump destination validation: Verifies JUMP/JUMPI targets
- Security checks: Detects potential infinite loops and expensive opcode patterns
- Address validation: Ensures addresses are properly formatted
- Gas limit validation: Checks gas limits are within reasonable bounds
- Value validation: Prevents overflow attacks
Disable validation:
evm-rust execute --code "6002600301" --no-validateThe EVM provides detailed execution tracing capabilities:
evm-rust execute --code "6002600301" --traceevm-rust execute --code "6002600301" --detailed-traceTrace output includes:
- Step-by-step execution
- Stack state changes
- Memory modifications
- Storage changes
- Gas consumption per step
- Execution statistics
JSON format (when Serialize is implemented):
evm-rust execute --code "6002600301" --export-trace trace.jsonCSV format (fallback):
evm-rust execute --code "6002600301" --export-trace trace.json
# Automatically exports as CSV if JSON failsThe EVM tracks detailed gas consumption:
evm-rust execute --code "6002600301" --detailed-traceGas information includes:
- Total gas consumed
- Gas per opcode
- Gas efficiency metrics
- Memory expansion costs
- Storage operation costs
The EVM supports Ethereum-style event logging:
evm-rust execute --code "60016000536020a0" --debugEvent features:
- LOG0, LOG1, LOG2, LOG3, LOG4 operations
- Topic and data logging
- Event filtering and analysis
The EVM provides access to blockchain context:
evm-rust execute --code "42" --debug # BLOCKHASH
evm-rust execute --code "41" --debug # COINBASE
evm-rust execute --code "42" --debug # TIMESTAMPAvailable context:
- Block number, timestamp, difficulty
- Gas limit, coinbase, chain ID
- Block hash, base fee
- Transaction context (gas price, origin, etc.)
Error:
❌ Error: Invalid bytecode: Invalid opcode 0xfe at position 0
Solution:
- Ensure bytecode is valid hex
- Check that all opcodes are supported
- Use
--no-validateto bypass validation (not recommended)
Error:
❌ Error: Stack error: Stack underflow: not enough items on stack
Solution:
- Ensure sufficient values are pushed before operations
- Check bytecode logic for proper stack management
Error:
❌ Error: Gas limit exceeded
Solution:
- Increase gas limit with
--gas-limit - Optimize bytecode to use less gas
- Check for infinite loops
Error:
❌ Error: Invalid gas limit: 50000000
Solution:
- Use gas limits between 21,000 and 30,000,000
- Check address formats (42 characters, starts with 0x)
- Ensure values are reasonable
evm-rust execute --code "YOUR_CODE" --debugevm-rust execute --code "YOUR_CODE" --detailed-traceevm-rust execute --code "YOUR_CODE" --export-trace analysis.csvevm-rust info --validation- Use appropriate gas limits: Start with 1M gas for simple operations
- Enable validation: Always use validation unless debugging
- Export traces: Use CSV export for large executions
- Batch operations: Combine multiple operations in single execution
-
Command help:
evm-rust --help evm-rust execute --help
-
Information commands:
evm-rust info --opcodes evm-rust info --gas-costs evm-rust info --validation
-
Examples:
evm-rust examples --list evm-rust examples --number 1
To contribute to the EVM Rust project:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
For support and questions:
- Create an issue on GitHub
- Check the documentation
- Review the examples
- Use the built-in help system
Happy EVM coding! 🚀