Topic lesson Sun, Aug 23, 2026 · 8 min read

How the EVM Runs Code

A stack machine, four places data can live, and why one opcode explains both proxies and EIP-7702.

EVM Fundamentals · intro

Where this sits

A stack machine

PUSH1 0x02      // stack: [2]
PUSH1 0x03      // stack: [3, 2]
ADD             // stack: [5]

Solidity, Vyper and every other language compile down to this. Nothing else runs.

Four places data can live

WhereLifetimeWritableCost
StackOne call framePush/pop only~3 gas per op
MemoryOne call frameYes3 gas, plus expansion
CalldataOne call frameNo3 gas to read a word
StorageForeverYesHundreds to thousands of gas

The cost gap between memory and storage is the single biggest fact about writing contracts. Arithmetic is 3–5 gas. A memory write is 3. A storage write is three to four orders of magnitude more. Storage is expensive because every node on Earth must keep the result forever, whereas memory is discarded microseconds later. Almost every real gas optimisation is some version of touching storage less.

Gas

Calls, and who "self" is

A contract calling another contract creates a new call frame: fresh stack, fresh memory, its own gas allowance. Which storage that frame writes to depends on the opcode.

OpcodeCode that runsStorage writtenmsg.sender inside
CALLTarget'sTarget'sThe caller
DELEGATECALLTarget'sCaller'sThe caller's caller
STATICCALLTarget'sNone — writes revertThe caller

Reverting

Why it matters

Where to go deeper

Threads left open

  • Storage layout and packing — how Solidity assigns slots
  • The actual warm/cold constants and where they get repriced
  • Precompiles and contract creation via CREATE/CREATE2 at the EVM level

The next topic lesson picks these up.

Sources