EIPs Explained

EIP-615 · Stagnant · Core · 2016-12-10

EIP-615: Subroutines and Static Jumps for the EVM

A proposal to replace the EVM's dynamic jumps with static jumps, real subroutines and deploy-time validation, so EVM code becomes easier to analyze, verify and compile.

What problem does it solve?

The EVM has only one kind of jump: JUMP / JUMPI to an address taken from the stack. Compilers even use these dynamic jumps for function returns. Because a jump target can be any value computed at runtime, tools cannot easily work out the control flow of a contract. That makes these jobs hard or slow:

  • formal verification and static analysis for bugs,
  • compiling EVM bytecode to fast machine code,
  • proving ahead of time that code won't hit stack underflow or bad jumps.

The authors argue that analysis must run in near-linear (n log n) time, otherwise attackers can craft contracts that cause quadratic blow-ups in validators or optimizers.

How it works

EIP-615 deprecates JUMP and JUMPI for new code and adds structured replacements that map closely to Wasm and CPU instructions:

New opcode Purpose
JUMPTO t / JUMPIF t Unconditional / conditional jump to an immediate target
JUMPV n, targets Jump table (switch) through an inline vector of targets
BEGINSUB n_args, n_results Marks a subroutine entry and its stack signature
JUMPSUB t / JUMPSUBV n, targets Call a subroutine, directly or through a table
RETURNSUB Return to the instruction after the call
GETLOCAL n / PUTLOCAL n Read and write frame-local stack slots
BEGINDATA Everything after this is data, not code

Subroutine calls use a separate return stack and frame pointer that the program cannot touch. New-style bytecode starts with a header (\0evm plus a version) and is validated at deploy time. Code that could underflow the stack, jump to an invalid place or misuse subroutines is rejected before it reaches the chain. Only out-of-gas and stack overflow still need runtime checks. Mixing new and legacy code relies on account versioning (EIP-1702).

Sample code

Illustrative assembly: a subroutine that adds two numbers, called with a static jump.

; header: "\0evm" + version
BEGINSUB 0, 0          ; main routine
  PUSH1 10
  PUSH1 11
  JUMPSUB add          ; immediate target, no dynamic jump
  ; stack now holds 21
  STOP

add:
BEGINSUB 2, 1          ; takes 2 args, returns 1
  ADD
  RETURNSUB

BEGINDATA              ; optional data section

Compare with legacy EVM, where the caller pushes a return address and the callee does JUMP to whatever is on the stack.

Things to know

  • This proposal is Stagnant and was never adopted. Current EVM bytecode still uses dynamic JUMP / JUMPI.
  • Its ideas continued in later proposals. EIP-2315 (simple subroutines) is Withdrawn. The EVM Object Format family, including EIP-3540, EIP-4750 (functions) and the meta EIP-7692, brought back deploy-time validation and real functions, and is also listed as Stagnant.
  • The opcode numbers and header format here are specific to this draft. Do not assume they match any later design.

#evm #opcodes #subroutines #validation #core

Details

Authors
Greg Colvin <[email protected]>, Brooklyn Zelenka (@expede), Paweł Bylica (@chfast), Christian Reitwiessner (@chriseth)
Status
Stagnant
Type
Standards Track / Core
Created
2016-12-10

Machine-readable: Markdown · JSON