Visualizing the Ethereum Virtual Machine

December 18, 2025

I like the vision of an open, verifiable, and censorship-resistant financial system. While the vision is still a heavy work in progress, I find the tech behind Ethereum to be interesting. So, I wanted to go through the exercise of building and visualizing an ethereum virtual machine, to understand how smart contracts actually run on Ethereum.

The actual implementation turned out to be pretty straightforward, although I ended up implementing a limited number of opcodes.

PC: 0 Gas: 21000 Status: RUNNING

Instructions

0: PUSH1 0x2a ← PC
2: PUSH1 0x00
4: MSTORE
5: PUSH1 0x00
7: MLOAD
8: PUSH1 0x00
10: SSTORE
11: PUSH1 0x00
13: SLOAD
14: PUSH1 0x00
16: MSTORE
17: PUSH1 0x20
19: PUSH1 0x00
21: RETURN

Stack (0/1024)

Empty

Memory

0x

Storage

Empty

Transient

Empty

Implemented Opcodes

OpcodeNameMinimum GasDescription
0x00STOP0Halt execution
0x01ADD3Pop two values, push their sum
0x02MUL5Pop two values, push their product
0x03SUB3Pop two values, push their difference
0x04DIV5Pop two values, push their quotient
0x10LT3Less than comparison (a < b → 1, else 0)
0x11GT3Greater than comparison (a > b → 1, else 0)
0x14EQ3Equality check (a == b → 1, else 0)
0x15ISZERO3Check if value is zero (0 → 1, else 0)
0x16AND3Bitwise AND of two values
0x17OR3Bitwise OR of two values
0x18XOR3Bitwise XOR of two values
0x19NOT3Bitwise NOT (256-bit inversion)
0x50POP2Remove top stack item
0x51MLOAD3Load 32 bytes from memory (+ expansion cost)
0x52MSTORE3Store 32 bytes to memory (+ expansion cost)
0x54SLOAD100Load value from storage
0x55SSTORE100Store to storage (100-20000 depending on state)
0x5CTLOAD100Load from transient storage (EIP-1153)
0x5DTSTORE100Store to transient storage (EIP-1153)
0x60PUSH13Push 1-byte value onto stack
0x80DUP13Duplicate top stack item
0x81DUP23Duplicate 2nd stack item
0x90SWAP13Swap top two stack items
0xF3RETURN0Return from execution