Skip to content
LogoLogo

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.

FieldTypeDefaultEnforcement & purpose
hardforkHardforkHardfork.DEFAULT (.OSAKA)Default fork when vm.init() receives hardfork == null. The Voltaire enum includes .AMSTERDAM
stack_sizeu121024Wired into Frame.pushStack(); pushing at stack.items.len >= config.stack_size returns error.StackOverflow
max_bytecode_sizeu3224576Wired into Evm.inner_create() (Spurious Dragon+); deployed runtime code exceeding this limit fails with error.CreateContractSizeLimit
max_initcode_sizeu3249152Wired into Evm.inner_create() (Shanghai+); initcode exceeding this limit fails with error.OutOfGas
block_gas_limitu6430_000_000Default BlockContext.block_gas_limit when vm.init() receives block_context == null
memory_initial_capacityusize4096Config field with no core execution consumer
memory_limitu640xFFFFFF (~16.7 MB)Wired into Frame memory expansion (@min(config.memory_limit, maxInt(u32)) & ~31); exceeding it fails with error.OutOfGas
max_call_depthu161024Evm.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?u321_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_rootsbooltrueEIP-4788 config flag with no core execution consumer
enable_historical_block_hashesbooltrueEIP-2935 config flag with no core execution consumer
enable_validator_depositsbooltrueEIP-6110 config flag with no core execution consumer
enable_validator_withdrawalsbooltrueEIP-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

MethodFallback 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.