A minimal Rust EVM prototype for experimentation. This file is intentionally short and points to the most relevant locations.
Purpose
- Small EVM core for learning and extension.
- Not production-ready: no gas metering, limited validation, and some panics (
unwrap()).
Project layout (essential)
crates/evm_core— VM core:Opcodeenum, jump table, handlers.crates/primitives— runtime primitives:Memory,Stack,EvmStorage,Transaction,BlockEnv.bins/evm— example runner that creates anEvminstance.
Dispatch (runtime)
Evm::step()reads a byte frommemory[pc], converts it withOpcode::from_u8, looks up the handler in the 256-entry table frombuild_jump_table(), calls the handler (fn(&mut Evm)), then incrementspc. Handlers that perform jumps must setevm.pcdirectly.
Short opcode snippet (Rust)
pub enum Opcode {
STOP = 0x00,
ADD = 0x01,
MUL = 0x02,
SUB = 0x03,
DIV = 0x04,
SDIV = 0x05,
MOD = 0x06,
SMOD = 0x07,
ADDMOD = 0x08,
MULMOD = 0x09,
EXP = 0x0A,
SIGNEXTEND = 0x0B,
// ... remainder in file
}
How to add an opcode (3 steps)
- Add/confirm enum entry and
from_u8mapping incrates/evm_core/src/opcodes.rs. - Implement handler
fn(&mut Evm)incrates/evm_core/src/operations/. - Register it in
crates/evm_core/src/jump_tables.rs:
jump_table[Opcode::MYOP as usize] = myop_handler;Notes
-
For exact semantics and gas rules consult https://www.evm.codes/.
-
To run locally: from repo root use
cargo build --workspace