In this track: Inside the EVM
advanced · 4 MIN READ

Trace a small EVM program

Track byte positions and stack changes before reasoning about state.

LET’S PICTURE IT

A good calculation worksheet records each intermediate step instead of only the final answer.

SEE IT FOR YOURSELF
Watch a stack machine execute a tiny programStep 1 / 4
Watch a stack machine execute a tiny programProgram→ PUSH1 0x02PUSH1 0x03ADD · STOPStackEmptyPC = 0A fixed local model; not a complete EVM implementationPUSH1 0x02Push immediate 2Next PC = 2Stack · top first2PUSH1 occupies one opcode byte plus one immediate bytePUSH1 0x03Push immediate 3Next PC = 4Stack · top first32The first value is below the most recently pushed valueADD3 + 2 = 5Next: STOP at PC 5Stack5No automatic SSTOREStack, memory and persistent storage are different locations

The program bytes are PUSH1 02, PUSH1 03, ADD, STOP. The program counter begins at byte zero.

Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.

Decode the byte sequence

The toy code 600260030100 contains PUSH1 2, PUSH1 3, ADD and STOP. Immediate bytes belong to their PUSH instructions.

Write the stack after each step

Starting empty, the stack becomes [2], then [2,3], then [5]. ADD consumes both input values and leaves one result.

Separate an internal result from output

STOP finishes successfully but does not return the stack contents as output. A return operation would need a selected memory range.

State the model’s limits

This program does not write storage, emit a log or transfer value. A correct trace does not invent those effects merely because a number was calculated.

Trace the idea

bytecode: 0x600260030100
PC 0 PUSH1 2 → [2]
PC 2 PUSH1 3 → [2,3]
PC 4 ADD → [5]
PC 5 STOP → success, empty output

Stack examples list the bottom first and the top last. These small traces omit gas and surrounding dispatch unless stated.

QUICK CHECK · NO PRESSURE

Does STOP automatically return the remaining stack value 5?

Your progress stays in this browser.
Keep exploring the original referenceethereum.org ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.