EvmConfig & HostInterface
EvmConfig
Defined in src/evm_config.zig. Passed at compile time to Evm(config) and Frame(config). The table describes how each field is used by Evm and Frame.
| Field | Type | Default | Enforcement & purpose |
|---|---|---|---|
hardfork | Hardfork | Hardfork.DEFAULT (.OSAKA) | Default fork when vm.init() receives hardfork == null. The Voltaire enum includes .AMSTERDAM |
stack_size | u12 | 1024 | Wired into Frame.pushStack(); pushing at stack.items.len >= config.stack_size returns error.StackOverflow |
max_bytecode_size | u32 | 24576 | Wired into Evm.inner_create() (Spurious Dragon+); deployed runtime code exceeding this limit fails with error.CreateContractSizeLimit |
max_initcode_size | u32 | 49152 | Wired into Evm.inner_create() (Shanghai+); initcode exceeding this limit fails with error.OutOfGas |
block_gas_limit | u64 | 30_000_000 | Default BlockContext.block_gas_limit when vm.init() receives block_context == null |
memory_initial_capacity | usize | 4096 | Config field with no core execution consumer |
memory_limit | u64 | 0xFFFFFF (~16.7 MB) | Wired into Frame memory expansion (@min(config.memory_limit, maxInt(u32)) & ~31); exceeding it fails with error.OutOfGas |
max_call_depth | u16 | 1024 | Evm.inner_call() reports error.callDepthExceeded and Evm.inner_create() reports error.CallDepthExceeded. The limit also pre-sizes Evm.frames to max_call_depth + 1 |
opcode_overrides | []const OpcodeOverride | &.{} | Custom native opcode handlers checked in Frame.executeOpcode() |
precompile_overrides | []const PrecompileOverride | &.{} | Custom or replaced precompiles checked in Evm.executePrecompile() |
loop_quota | ?u32 | 1_000_000 (Debug/ReleaseSafe), null (ReleaseFast/Small) | Wired into Frame.execute(); executing more than quota opcodes in a single frame returns error.ExecutionTimeout |
enable_beacon_roots | bool | true | EIP-4788 config flag with no core execution consumer |
enable_historical_block_hashes | bool | true | EIP-2935 config flag with no core execution consumer |
enable_validator_deposits | bool | true | EIP-6110 config flag with no core execution consumer |
enable_validator_withdrawals | bool | true | EIP-7002 config flag with no core execution consumer |
Loading from Zig build options (fromBuildOptions)
EvmConfig.fromBuildOptions() constructs an EvmConfig from @import("build_options"), applying any configured hardfork, max_call_depth, stack_size, max_bytecode_size, max_initcode_size, block_gas_limit, memory_initial_capacity, and memory_limit. The hardfork name may be an exact enum tag ("TANGERINE_WHISTLE"), the case-insensitive alias "TANGERINE" or "SPURIOUS", or any name Hardfork.fromString() accepts case-insensitively (such as "osaka", "Paris", "ConstantinopleFix", or "Glamsterdam"). Unknown names fall back to Hardfork.DEFAULT (.OSAKA).
Override structs
pub const OpcodeOverride = struct {
opcode: u8,
handler: *const anyopaque, // *const fn (*FrameType) EvmError!void
};
pub const PrecompileOverride = struct {
address: Address,
execute: *const fn (
ctx: ?*anyopaque,
allocator: std.mem.Allocator,
input: []const u8,
gas_limit: u64,
) anyerror!PrecompileOutput,
context: ?*anyopaque = null,
};
pub const PrecompileOutput = struct {
output: []const u8,
gas_used: u64,
success: bool,
};HostInterface
Defined in src/host.zig. Type-erased vtable for external state storage.
pub const HostInterface = struct {
ptr: *anyopaque,
vtable: *const VTable,
pub const VTable = struct {
// Required (8)
getBalance: *const fn (ptr: *anyopaque, address: Address) u256,
setBalance: *const fn (ptr: *anyopaque, address: Address, balance: u256) void,
getCode: *const fn (ptr: *anyopaque, address: Address) []const u8,
setCode: *const fn (ptr: *anyopaque, address: Address, code: []const u8) void,
getStorage: *const fn (ptr: *anyopaque, address: Address, slot: u256) u256,
setStorage: *const fn (ptr: *anyopaque, address: Address, slot: u256, value: u256) void,
getNonce: *const fn (ptr: *anyopaque, address: Address) u64,
setNonce: *const fn (ptr: *anyopaque, address: Address, nonce: u64) void,
// Optional (3) — defaults provided by wrapper methods when null
accountExists: ?*const fn (ptr: *anyopaque, address: Address) bool = null,
accountHasStorage: ?*const fn (ptr: *anyopaque, address: Address) bool = null,
deleteAccount: ?*const fn (ptr: *anyopaque, address: Address) void = null,
};
};Fallback behavior when optional pointers are null
| Method | Fallback when null |
|---|---|
accountExists(addr) | getBalance(addr) != 0 or getNonce(addr) != 0 or getCode(addr).len != 0 |
accountHasStorage(addr) | false |
deleteAccount(addr) | Sets balance to 0, code to &.{}, nonce to 0 |
Ownership rule for setCode
The code slice passed to setCode may reside in vm.arena. Implementations whose lifetime exceeds vm.deinit() must duplicate the slice.