EVM from Scratch

An educational Ethereum bytecode interpreter in Rust, with a 256-bit stack, memory, storage, gas accounting, and a command-line runner.

1 min readIn ProgressSolo developer

Topics: Rust · Ethereum · EVM · Virtual Machines · U256

Inside the execution loop

I built an Ethereum bytecode interpreter in Rust to understand what happens between an opcode and a change in machine state. The workspace separates the execution library, evm-core, from a small command-line runner, evm-cli.

The interpreter keeps track of the program counter, stack, memory, storage, remaining gas, call data, logs, and execution flags. It reads an opcode, dispatches to its handler, and continues until execution stops or an error occurs.

What is implemented

  • Arithmetic, comparison, bitwise operations, and Keccak hashing.
  • Stack instructions including PUSH, DUP, and SWAP.
  • Memory access, persistent storage, and transient storage.
  • Control flow through jumps, stop, and revert.
  • Gas consumption and explicit execution errors.

This is an educational implementation under development. Its current instruction set covers core execution mechanics; it does not implement the complete Ethereum execution environment.

Inspecting execution

The CLI accepts hex bytecode and prints the resulting stack and remaining gas. Tests include simple stack operations and a factorial loop written in bytecode, which exercises memory, arithmetic, and conditional jumps together.

Explore the interpreter and CLI source to follow the opcode handlers and execution state.