EIPs Explained

EIP-6206 · Stagnant · Core · 2022-12-21

EIP-6206: EOF - JUMPF and non-returning functions

Adds JUMPF, an EOF instruction that jumps into another function without a return frame (a tail call), and lets functions be marked non-returning for smaller, cheaper code.

What problem does it solve?

The EVM Object Format (EOF) introduces real functions: code is split into sections, CALLF calls a section and RETF returns (EIP-4750). That leaves two inefficiencies:

  1. Tail calls. A function that ends by calling another function and immediately returning still pays for a CALLF + RETF round trip and a return-stack frame.
  2. Error helpers. Shared helpers that always end in REVERT are common. Because stack validation (EIP-5450) requires exact stack heights on return, callers would have to clean up extra stack items before calling them, even though control never comes back.

EIP-6206 solves both with one new instruction and a "non-returning" flag.

How it works

JUMPF (opcode 0xe5) takes a 2-byte immediate target_section_index. It sets the current section to the target and PC to 0 without pushing a return frame. It costs 5 gas and does not touch the operand stack. Before jumping, it checks that the target's declared max_stack_increase cannot overflow the 1024-item stack limit.

Non-returning sections. In the EOF type section, a code section's outputs value can be 0x80, meaning it never returns to its caller. A section must be marked non-returning if and only if it contains no RETF and no JUMPF into a returning section. The first code section must have 0 inputs and be non-returning.

Validation rules (at deploy time):

  • JUMPF into a returning section: the stack height must be exactly current.outputs - target.outputs + target.inputs, and current.outputs >= target.outputs. A section with more outputs can reuse a helper with fewer outputs if it leaves the difference on the stack.
  • JUMPF into a non-returning section: the stack only needs at least target.inputs items. Extra items can be left behind.
  • CALLF into a non-returning section is invalid; use JUMPF.
  • JUMPF is a terminating instruction, like RETF or STOP.

In legacy (non-EOF) bytecode, 0xe5 remains invalid.

Sample code

EOF assembly pseudocode: two functions share one non-returning error helper.

; type section: section 0 -> inputs 0, outputs 0x80 (non-returning)
;               section 1 -> inputs 1, outputs 1
;               section 2 -> inputs 0, outputs 0x80 (non-returning: revert helper)

code_section_1:            ; f(x) -> y
    DUP1
    ISZERO
    RJUMPI @bad            ; if x == 0, jump to error path
    PUSH1 2
    MUL
    RETF
bad:
    JUMPF 2                ; tail-jump to helper; leftover x on stack is fine

code_section_2:            ; revert helper, never returns
    PUSH0
    PUSH0
    REVERT

Things to know

  • Status: Stagnant. EOF as a whole (EIP-3540 and the EIP-7692 meta list) is Stagnant and is not active on Ethereum mainnet; JUMPF only exists in an EOF context.
  • Because EOF rejects unknown opcodes at deploy time, adding JUMPF cannot change any existing EOF contract's behavior.
  • RJUMP* offsets (EIP-4200) may not point into JUMPF's 2-byte immediate.
  • The main beneficiaries are compiler authors: smaller bytecode and lower gas for shared code paths, not new capabilities for contract developers.

#evm #eof #opcodes #compilers #core

Details

Authors
Andrei Maiboroda (@gumb0), Alex Beregszaszi (@axic), Paweł Bylica (@chfast), Matt Garnett (@lightclient)
Status
Stagnant
Type
Standards Track / Core
Created
2022-12-21
Requires
Required by

Machine-readable: Markdown · JSON