This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.
Overview
Opcode:0x56Introduced: Frontier (EVM genesis)JUMP performs an unconditional jump to a destination in the bytecode. The destination MUST be a valid JUMPDEST opcode - any other destination causes InvalidJump error and halts execution.This strict validation prevents arbitrary code execution and maintains the EVM’s security model.
1. Pop destination from stack2. Validate destination is JUMPDEST3. Validate destination is not in PUSH data4. Set PC = destination
Behavior
JUMP alters program flow by changing the program counter:
Consumes 8 gas (GasMidStep)
Pops destination address from stack
Validates destination is valid JUMPDEST
Updates program counter to destination
Execution continues at new location
Validation Requirements:
Destination must be JUMPDEST opcode (0x5b)
Destination must not be inside PUSH data
Destination must be within bytecode bounds
Failure causes InvalidJump error
Examples
Basic Jump
import { createFrame } from '@tevm/voltaire/evm/Frame';import { handler_0x56_JUMP } from '@tevm/voltaire/evm/control';// Bytecode with JUMPDEST at position 5const bytecode = new Uint8Array([ 0x60, 0x05, // PUSH1 5 0x56, // JUMP 0x00, // STOP (skipped) 0x00, // STOP (skipped) 0x5b, // JUMPDEST (destination) 0x60, 0x2a, // PUSH1 42]);const frame = createFrame({ bytecode, stack: [5n], // Jump to position 5 pc: 2 // At JUMP instruction});const err = handler_0x56_JUMP(frame);console.log(err); // null (success)console.log(frame.pc); // 5 (jumped to JUMPDEST)console.log(frame.stack); // [] (destination popped)
Function Call Pattern
assembly { // Jump to function push(func) jump // Return here after function jumpdest // Continue execution func: jumpdest // Function implementation // ... jump(return_address)}
Bytecode pattern:
PUSH2 0x0010 // Push return addressPUSH2 0x0020 // Push function addressJUMP // Jump to function// Return pointJUMPDEST // 0x0010// Continue execution// FunctionJUMPDEST // 0x0020// Function bodySWAP1JUMP // Return to caller
Invalid Jump
// Attempt to jump to non-JUMPDESTconst bytecode = new Uint8Array([ 0x60, 0x05, // PUSH1 5 0x56, // JUMP 0x00, // STOP 0x00, // STOP 0x60, 0x00, // PUSH1 0 (NOT a JUMPDEST)]);const frame = createFrame({ bytecode, stack: [5n], // Try to jump to PUSH1 pc: 2});const err = handler_0x56_JUMP(frame);console.log(err); // { type: "InvalidJump" }console.log(frame.pc); // 2 (unchanged - jump failed)
Jump Into PUSH Data
// Attempt to jump into PUSH dataconst bytecode = new Uint8Array([ 0x60, 0x05, // PUSH1 5 0x56, // JUMP 0x61, 0x5b, 0x00, // PUSH2 0x5b00 (0x5b is PUSH data, not instruction)]);const frame = createFrame({ bytecode, stack: [4n], // Try to jump to byte that looks like JUMPDEST pc: 2});const err = handler_0x56_JUMP(frame);console.log(err); // { type: "InvalidJump" }// Destination 4 is inside PUSH2 data, not a real JUMPDEST
Gas Cost
Cost: 8 gas (GasMidStep)Comparison:
JUMP: 8 gas (unconditional)
JUMPI: 10 gas (conditional)
PC: 2 gas (read counter)
JUMPDEST: 1 gas (destination marker)
Total Jump Cost:
PUSH1 dest: 3 gasJUMP: 8 gasJUMPDEST: 1 gasTotal: 12 gas (minimum for jump operation)
Edge Cases
Out of Bounds
// Jump destination exceeds bytecode lengthconst bytecode = new Uint8Array([0x56]); // Just JUMPconst frame = createFrame({ bytecode, stack: [1000n], // Beyond bytecode pc: 0});const err = handler_0x56_JUMP(frame);console.log(err); // { type: "InvalidJump" }// Destination 1000 is out of bounds
// No destination on stackconst frame = createFrame({ stack: [], pc: 0});const err = handler_0x56_JUMP(frame);console.log(err); // { type: "StackUnderflow" }
Jump to Self
// Jump to JUMPDEST at current position (infinite loop)const bytecode = new Uint8Array([ 0x5b, // JUMPDEST (position 0) 0x60, 0x00, // PUSH1 0 0x56, // JUMP (back to position 0)]);const frame = createFrame({ bytecode, stack: [0n], pc: 3});handler_0x56_JUMP(frame);console.log(frame.pc); // 0 (jumped to self)// Execution will loop until out of gas
Common Usage
Function Calls
Solidity internal functions use JUMP for calls:
function main() public { uint256 result = helper(42); // Use result}function helper(uint256 x) internal pure returns (uint256) { return x * 2;}
Compiled pattern:
// main() calls helper()PUSH1 0x2a // Argument: 42PUSH2 helper // Function addressJUMP// Return from helperJUMPDEST// Use return value// helper() implementationhelper: JUMPDEST DUP1 PUSH1 0x02 MUL SWAP1 JUMP // Return to caller
Switch Statements
assembly { switch value case 0 { jump(case0) } case 1 { jump(case1) } default { jump(defaultCase) } case0: jumpdest // Handle case 0 jump(end) case1: jumpdest // Handle case 1 jump(end) defaultCase: jumpdest // Handle default jump(end) end: jumpdest}
Early Exit
assembly { // Check condition let shouldExit := iszero(sload(0)) // Jump to exit if true if shouldExit { jump(exit) } // Continue normal execution // ... exit: jumpdest return(0, 0)}
Implementation
TypeScript
import { consumeGas } from "../Frame/consumeGas.js";import { popStack } from "../Frame/popStack.js";import { isValidJumpDest } from "../../primitives/Bytecode/isValidJumpDest.js";import { MidStep } from "../../primitives/GasConstants/constants.js";/** * JUMP opcode (0x56) - Unconditional jump * * @param frame - Frame instance * @returns Error if operation fails */export function handler_0x56_JUMP(frame: FrameType): EvmError | null { const gasErr = consumeGas(frame, MidStep); if (gasErr) return gasErr; const { value: dest, error } = popStack(frame); if (error) return error; // Check if destination fits in u32 range if (dest > 0xffffffffn) { return { type: "OutOfBounds" }; } const destPc = Number(dest); // Validate jump destination if (!isValidJumpDest(frame.bytecode, destPc)) { return { type: "InvalidJump" }; } frame.pc = destPc; return null;}