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

JUMP, JUMPI and JUMPDEST

Control flow must target a valid destination instruction.

LET’S PICTURE IT

A train can switch tracks only at marked junctions, not at arbitrary printed labels.

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.

Read an unconditional jump

JUMP takes a destination from the stack and transfers control if that destination is valid. It does not interpret the destination as a source line number.

Read a conditional branch

JUMPI also checks a condition. A nonzero condition takes the jump, while a zero condition continues to the next instruction.

Validate the destination

The destination must be an actual JUMPDEST instruction in code. A byte equal to 0x5b inside PUSH immediate data is not automatically a valid destination.

Trace the chosen path

A program can contain instructions that are never reached for particular inputs. Follow conditions and destinations instead of counting every listed instruction as executed.

Trace the idea

PC 0: PUSH1 0x03
PC 2: JUMP
PC 3: JUMPDEST
PC 4: STOP

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 0x5b inside PUSH data automatically form a valid jump target?

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.