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

Step inside the EVM

A stack machine that turns bytecode into checked state changes.

LET’S PICTURE IT

Think of a calculator with a stack of sticky notes. Each instruction adds, removes or transforms the top notes.

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.

A shared execution model

The Ethereum Virtual Machine runs contract bytecode. Nodes reproduce execution to check the result. It operates with 256-bit stack values and has instructions, called opcodes, for arithmetic, memory, storage and contract calls.

Push, then add

PUSH1 0x02 places 2 on the stack. PUSH1 0x03 places 3 above it. ADD takes the two top values and pushes their sum, 5. Step through the experiment to see the stack change. The example is a tiny fixed program, not a complete virtual machine.

Memory and storage differ

Memory is temporary working space for a call. Storage is persistent state associated with the executing contract’s context. Calldata holds the input for a call. These spaces have different access rules and gas costs.

Execution can fail

An instruction can revert, run out of gas, or fail another check. A REVERT rolls back the call’s state changes and can return error data. An outer call may handle an inner failure. Use revert decoding to identify common error forms before investigating the complete call trace.

QUICK CHECK · NO PRESSURE

What happens after pushing 2, pushing 3, then ADD?

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.