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:
- Tail calls. A function that ends by calling another function and immediately returning still pays for a
CALLF+RETFround trip and a return-stack frame. - Error helpers. Shared helpers that always end in
REVERTare 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):
JUMPFinto a returning section: the stack height must be exactlycurrent.outputs - target.outputs + target.inputs, andcurrent.outputs >= target.outputs. A section with more outputs can reuse a helper with fewer outputs if it leaves the difference on the stack.JUMPFinto a non-returning section: the stack only needs at leasttarget.inputsitems. Extra items can be left behind.CALLFinto a non-returning section is invalid; useJUMPF.JUMPFis a terminating instruction, likeRETForSTOP.
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;
JUMPFonly exists in an EOF context. - Because EOF rejects unknown opcodes at deploy time, adding
JUMPFcannot change any existing EOF contract's behavior. RJUMP*offsets (EIP-4200) may not point intoJUMPF'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.