Skip to main content
This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.

Overview

EVM instructions are the atomic operations that smart contract bytecode compiles to. Voltaire implements all 166 opcodes from the Ethereum Yellow Paper, organized into 11 functional categories. Each instruction operates on a 256-bit word stack with precise gas costs and well-defined semantics. All implementations are zero-copy, tree-shakeable, and tested against official Ethereum test vectors.

Complete Instruction Reference

Arithmetic Operations (0x01-0x0b)

11 opcodes for integer arithmetic with 256-bit overflow semantics:

Comparison & Logic (0x10-0x15)

6 opcodes for comparison operations returning 0 or 1:

Bitwise Operations (0x16-0x1d)

8 opcodes for bit manipulation:

Keccak (0x20)

1 opcode for cryptographic hashing:

Execution Context (0x30-0x3f)

16 opcodes for accessing transaction and account context:

Block Information (0x40-0x4a)

11 opcodes for accessing block context:

Stack Operations (0x50, 0x5f-0x9f)

86 opcodes for stack manipulation: POP (0x50): Remove top item (2 gas) PUSH0-PUSH32 (0x5f-0x7f): Push N-byte value onto stack (3 gas)
  • 0x5f: PUSH0 (Cancun+)
  • 0x60-0x7f: PUSH1 through PUSH32
DUP1-DUP16 (0x80-0x8f): Duplicate Nth stack item (3 gas)
  • 0x80: DUP1 (duplicate 1st item)
  • 0x8f: DUP16 (duplicate 16th item)
SWAP1-SWAP16 (0x90-0x9f): Swap top with Nth item (3 gas)
  • 0x90: SWAP1 (swap with 2nd item)
  • 0x9f: SWAP16 (swap with 17th item)
See Stack Operations for complete reference.

Memory Operations (0x51-0x53, 0x5e)

4 opcodes for volatile memory access:

Storage Operations (0x54-0x55, 0x5c-0x5d)

4 opcodes for persistent and transient storage:

Control Flow (0x00, 0x56-0x58, 0x5b, 0xf3, 0xfd)

7 opcodes for program flow control:

Logging (0xa0-0xa4)

5 opcodes for event emission:

System Operations (0xf0-0xf2, 0xf4-0xf5, 0xfa, 0xff)

7 opcodes for contract interaction:

Gas Cost Details

Base Costs

All opcodes have minimum gas costs defined in the Yellow Paper:
  • 0 gas: STOP, RETURN (base), REVERT (base)
  • 2 gas: Most context/block info reads
  • 3 gas: Arithmetic, comparison, bitwise, stack ops
  • 5 gas: MUL, DIV, MOD family
  • 8 gas: ADDMOD, MULMOD, JUMP

Dynamic Costs

Several instructions have variable costs:
  • Memory expansion: 3 gas/word + quadratic growth
  • SSTORE: 100-20,000 based on storage slot state
  • EXP: 50 gas per byte of exponent
  • LOG: 375 base + 375/topic + 8/byte
  • CALL/CREATE: 100 base + value transfer + memory + gas forwarding

Access Lists (EIP-2929)

Post-Berlin, storage and account access costs vary:
  • Cold access: First access in transaction (2,600 gas for accounts, 2,100 for storage)
  • Warm access: Subsequent accesses (100 gas)
  • Precompiles: Always warm

Stack Machine Model

Stack Properties

  • Depth: 1024 elements maximum
  • Word size: 256 bits (32 bytes)
  • Access: Only top 16 elements accessible (via DUP/SWAP)
  • Overflow: Pushing to full stack causes exception
  • Underflow: Pop from empty stack causes exception

Stack Notation

a, b → c means:
  1. Pop b from top
  2. Pop a from new top
  3. Push c to stack
Example: ADD pops two values, pushes their sum.

Memory Model

Memory Properties

  • Size: Grows dynamically, starts at 0
  • Expansion: Quadratic cost prevents abuse
  • Volatility: Cleared after transaction
  • Alignment: Byte-addressable, no alignment requirements
  • Zero-initialized: Unwritten memory reads as 0

Memory Gas

memory_cost = memory_size_word * 3 + memory_size_word^2 / 512 Expansion cost is incremental from previous maximum size.

Storage Model

Persistent Storage (SLOAD/SSTORE)

  • Key-value: 256-bit keys and values
  • Initial zero: All slots start at 0
  • Permanence: Survives transactions
  • Gas complexity: SSTORE pricing based on:
    • Cold vs. warm access (EIP-2929)
    • Original value vs. current value (EIP-2200)
    • Zero vs. nonzero transitions

Transient Storage (TLOAD/TSTORE) - Cancun+

  • Ephemeral: Cleared after transaction
  • Fixed cost: 100 gas per operation
  • Use case: Reentrancy guards, temporary state
  • No refunds: Unlike persistent storage

Hardfork Changes

London (EIP-1559)

  • BASEFEE (0x48): Access to block base fee

Shanghai

  • PUSH0 (0x5f): Push constant zero (cheaper than PUSH1)

Cancun (Dencun)

  • MCOPY (0x5e): Efficient memory copying
  • TLOAD (0x5c): Transient storage read
  • TSTORE (0x5d): Transient storage write
  • BLOBHASH (0x49): Access to blob versioned hashes
  • BLOBBASEFEE (0x4a): Blob gas pricing

Prague (upcoming)

Implementation

TypeScript

Zig

References