Vm Struct
The main virtual machine state container.16 general-purpose 64-bit registers (R0-R15)
Linear memory up to 1MB
Program counter pointing to current instruction
Gas metering for execution costs
Bytecode being executed
Whether execution has stopped
Address of the calling account
Address of the current contract
Value sent with the call
Current block number
Current block timestamp
Optional persistent storage backend
Values logged during execution
Methods
new
Create a new VM with the given bytecode and gas limit.Bytecode to execute
Maximum gas allowed for execution
Address of the calling account
Address of the current contract
Value sent with the call
A new VM instance with 1MB memory limit and default block context
new_with_context
Create a new VM with additional context fields.Current block number
Current block timestamp
run
Run the VM until it halts or runs out of gas.Execution result containing success status, gas used, return data, and logs
Result<ExecutionResult, VmError> - Success result or error
set_storage
Set the storage backend for persistent state.Storage backend implementing SLOAD/SSTORE operations
set_block_context
Set the block context for execution.Block number
Block timestamp
get_registers
Get current register values for inspection or tracing.Array of 16 register values
gas_remaining
Get remaining gas.Amount of gas remaining
ExecutionResult
Result of VM execution.Whether execution completed successfully (true) or failed (false)
Total gas consumed during execution
Data returned by the execution
Values logged via LOG opcode
VmError
Errors that can occur during execution.Variants
Insufficient gas to continue execution
Unknown opcode byte encountered
DivisionByZero
Attempted division or modulo by zero
MemoryOverflow
Memory access beyond 1MB limit
Jump to invalid bytecode position
StackUnderflow
Attempted to pop from empty stack
Reverted
Execution explicitly reverted via REVERT opcode
StorageBackend Trait
Interface for persistent storage operations.sload
Read 32 bytes from storage slot.32-byte storage key
32-byte value at the storage slot
sstore
Write 32 bytes to storage slot.32-byte storage key
32-byte value to store