Skip to main content

Overview

The Ethereum Virtual Machine is a stack-based virtual machine that executes smart contract bytecode. Voltaire provides type-first EVM primitives - strongly-typed execution types, instruction handlers, and precompiled contracts in both TypeScript and Zig. Every execution primitive is a branded type:
  • Opcode - Branded number (0x00-0xFF)
  • Instruction - Opcode + offset + immediate data
  • BrandedFrame - Execution frame (stack, memory, gas, state)
  • InstructionHandler - Opcode handler function signature
  • CallParams / CallResult - Cross-contract call types
  • CreateParams / CreateResult - Contract deployment types
This section documents 166 instruction handlers across 11 categories plus 21 precompiled contracts, all implemented with:
  • Type safety - Branded types prevent passing wrong values
  • Zero-copy operations - Direct Uint8Array manipulation
  • Tree-shakeable exports - Import only what you need
  • WASM compilation support - High-performance native execution
  • Comprehensive test coverage - Every opcode tested against official vectors
For complete spec-compliant EVM implementations that use these primitives, see evmts/guillotine and evmts/tevm-monorepo.

EVM Components

Types

Strongly-typed execution primitives:
  • Opcode - Branded number type for instructions (0x00-0xFF)
  • Instruction - Opcode with offset and immediate data
  • BrandedFrame - Complete execution state (stack, memory, gas, context)
  • BrandedHost - Pluggable state backend interface
  • InstructionHandler - Function signature for opcode implementations
  • CallParams/CallResult - Cross-contract call types
  • CreateParams/CreateResult - Contract deployment types
  • EvmError - Execution error types
See EVM Types for complete type reference with examples.

Instructions

166 opcode handlers organized by function:
  • Arithmetic (11): ADD, MUL, SUB, DIV, SDIV, MOD, SMOD, ADDMOD, MULMOD, EXP, SIGNEXTEND
  • Comparison (6): LT, GT, SLT, SGT, EQ, ISZERO
  • Bitwise (8): AND, OR, XOR, NOT, BYTE, SHL, SHR, SAR
  • Keccak (1): SHA3
  • Context (16): ADDRESS, BALANCE, ORIGIN, CALLER, CALLVALUE, CALLDATALOAD, etc.
  • Block (11): BLOCKHASH, COINBASE, TIMESTAMP, NUMBER, DIFFICULTY, GASLIMIT, CHAINID, etc.
  • Stack (86): POP, PUSH0-32, DUP1-16, SWAP1-16
  • Memory (4): MLOAD, MSTORE, MSTORE8, MCOPY
  • Storage (4): SLOAD, SSTORE, TLOAD, TSTORE
  • Control Flow (7): STOP, JUMP, JUMPI, PC, JUMPDEST, RETURN, REVERT
  • Log (5): LOG0-4
  • System (7): CREATE, CALL, CALLCODE, DELEGATECALL, CREATE2, STATICCALL, SELFDESTRUCT

Precompiles

21 precompiled contracts at addresses 0x01-0x13:
  • Cryptography (1): ECRECOVER
  • Hashing (3): SHA256, RIPEMD160, BLAKE2F
  • Data (1): IDENTITY
  • Mathematics (1): MODEXP
  • zkSNARKs (3): BN254_ADD, BN254_MUL, BN254_PAIRING
  • Blob Data (1): POINT_EVALUATION (EIP-4844)
  • BLS12-381 (9): G1/G2 operations for Ethereum 2.0 consensus

Architecture

Type-First Design

All EVM operations use strongly-typed primitives:

TypeScript Implementation

Opcode Categories

Computational Operations

Stack manipulation and arithmetic form the foundation of EVM computation:
  • Stack: 1024 elements max, 256-bit words
  • Arithmetic: Big-integer operations with overflow semantics
  • Bitwise: Bit manipulation for flags, masks, compression

State Access

Instructions for reading/modifying blockchain state:
  • Storage: Persistent (SLOAD/SSTORE) and transient (TLOAD/TSTORE)
  • Memory: Volatile scratch space within transaction
  • Context: Access to msg.sender, msg.value, block data

Control Flow

Program counter manipulation and execution flow:
  • Jumps: JUMP, JUMPI require JUMPDEST validation
  • Termination: STOP, RETURN, REVERT for execution halting
  • PC: Program counter inspection for dynamic code

External Interactions

Cross-contract calls and logging:
  • Calls: CALL, STATICCALL, DELEGATECALL with gas forwarding
  • Creation: CREATE, CREATE2 for contract deployment
  • Logs: LOG0-4 for event emission
  • Destruction: SELFDESTRUCT for contract removal

Gas Metering

All operations have precise gas costs defined in the Yellow Paper:

Dynamic Gas

Some operations have variable costs:
  • Memory expansion: Quadratic growth prevents DoS
  • Storage changes: SSTORE pricing based on cold/warm, zero/nonzero transitions
  • Call gas: 63/64 rule for subcall forwarding
  • Precompiles: Dynamic based on input size (MODEXP, MSM)

Hardfork Evolution

EVM instructions and precompiles introduced over time:

Implementation Status

Zig: Complete

All 166 instructions and 21 precompiles fully implemented with:
  • Native C library integration (blst, c-kzg-4844, arkworks)
  • Comprehensive test coverage
  • WASM compilation support

TypeScript: Functional

  • Instructions: All 166 handlers implemented in pure TypeScript
  • Precompiles: Production-ready for most, stubs for BLS12-381 (use WASM)
For security-critical operations, always use Zig/WASM implementations.

Security

Validation

All implementations validate:
  • Stack depth (1024 max)
  • Memory bounds
  • Gas sufficiency
  • Input lengths
  • Opcode validity for hardfork

Constant-Time Operations

Cryptographic operations use constant-time algorithms to prevent timing attacks on sensitive data.

DoS Protection

Gas metering prevents computational DoS:
  • Memory expansion costs grow quadratically
  • Storage operations priced to prevent abuse
  • Call depth limited to 1024
  • Precompile gas checked before execution

References