Public API
The library exports the following public modules and types fromsrc/lib.rs:1:
Core Modules
vm- The virtual machine that executes EVM bytecodelexer- Parses and tokenizes bytecode stringsinstruction- EVM opcode definitions and parsingstack- EVM stack implementation (1024 item limit)memory- EVM memory heap implementationstorage- Persistent storage using HashMap
Utilities
utils::bytes32- 32-byte value type for EVM operationsutils::errors- Error types for stack, memory, and VM operationsutils::history- Execution history tracking (for verbose mode)utils::cli- Command-line interface helpers
Re-exported Types
For convenience, these types are re-exported at the crate root:Key Types
Vm Struct
The main entry point for bytecode execution, defined in src/vm.rs:18:
Vm::new(bytecode: &str, verbose: bool)- Create a new VM instance fromsrc/vm.rs:29vm.run()- Execute the loaded bytecode fromsrc/vm.rs:37
Stack<T> Struct
A generic stack implementation with EVM’s 1024 item limit from src/stack.rs:8:
Public Methods:
Stack::new()- Create an empty stackpush(item: T)- Push an item onto the stackpop()- Pop an item from the stackpeek()- View the top item without removing itdup(index: usize)- Duplicate an item at a given indexswap(index: usize)- Swap an item with the top of the stack (unsafe)is_empty()- Check if the stack is empty
Memory Struct
EVM memory heap implementation from src/memory.rs:4:
Public Methods:
Memory::new()- Create empty memorymload(location: Bytes32)- Load 32 bytes from memory (unsafe)mstore(location: Bytes32, data: Bytes32)- Store 32 bytes to memory (unsafe)msize()- Get current memory size
Storage Struct
Persistent storage using HashMap from src/storage.rs:6:
Public Methods:
Storage::new()- Create empty storagesstore(slot: Bytes32, value: Bytes32)- Store a valuesload(slot: Bytes32)- Load a valuesize()- Get number of stored valuesis_empty()- Check if storage is empty
Library vs CLI
Use the library when:- You need to embed EVM execution in a Rust application
- You want programmatic access to execution state (stack, memory, storage)
- You need to test smart contract bytecode in your test suite
- You want to build custom tooling around EVM bytecode
- You want to quickly test bytecode snippets
- You need verbose execution traces with
--verbose - You prefer command-line interaction over programmatic control