EIP-8013 EVM static relative jumps and calls (Static relative jumps and calls for the EVM)

No call decision · EVM & execution · EIP status Draft · created 2025-08-19

Adds five new jump and call instructions (RJUMP, RJUMPI, RJUMPV, RJUMPSUB, RJUMPSUBV) to the EVM that pre-record the jump destination as a signed relative value inside the instruction. Jump costs go down and code analysis becomes easier.

Why it is needed

Right now the EVM has only two jump instructions, JUMP and JUMPI, and both are dynamic jumps whose destination is determined at runtime by popping it from the stack. This approach is very flexible but comes at a high cost. It makes analyzing where code actually flows beforehand complicated and often effectively impossible, and it is also the reason JUMPDEST markers are needed to mark valid jump targets. In practice, however, control flow in real contract code is mostly static. That is, the jump destination is already fixed when the code is written, so dynamic behavior is not actually needed. This proposal introduces a minimal set of static jump instructions, including function (subroutine) calls, returning to the call site, and switch-case style branch tables, so that compilers can generate code without dynamic jumps. The main benefits are lower gas costs for both deployment and execution, better performance, and easier static analysis.

What changes

Today

After EIP-8013

Who is affected

In depth

Five new instructions and immediate value encoding

RJUMP (0xe0) is an unconditional jump that sets the PC to PC_post_instruction + relative_offset. RJUMPI (0xe1) pops condition from the stack; if it is 0 it proceeds normally, and if it is nonzero it jumps by relative_offset. RJUMPV (0xe2) has max_index and an offset table as immediate values and jumps to relative_offset[case] corresponding to the case popped from the stack. RJUMPSUB (0xe3) is a subroutine call that pushes PC_post_instruction onto the return stack before jumping, and RJUMPSUBV (0xe4) is its table version. relative_offset is a 16-bit signed (two's complement) big-endian value, and PC_post_instruction means the PC position right after the entire immediate value ends.

RJUMPV and RJUMPSUBV jump tables and default path

The table's max_index is an unsigned 8-bit value, and the number of relative_offset entries that follow is max_index+1, so the table size is at most 256. RJUMPV must have at least one offset, so it occupies at least 4 bytes. If case > max_index, it does not branch and proceeds to the next instruction, which can be used to place a default path right after the instruction. This approach was chosen instead of the alternative of aborting with an exception on a match failure, leaving it to the programmer to decide how to fill empty table slots with zero. RJUMPV 0 relative_offset is an RJUMPI with the condition inverted, so it can replace the two instructions ISZERO RJUMPI. Table entries are at most 256 single-byte units, so reading offsets does not become a DoS attack surface.

Connection with EIP-7979 subroutines

The destination of RJUMPSUB and RJUMPSUBV must be ENTERSUB, and returning to the caller is done via EIP-7979's RETURNSUB. Since both instructions enter with the same effect as CALLSUB, they are a form of direct, immediate-value-based jump access to the return-to-caller mechanism that CALLSUB provides. This resolves all three requirements, function support, return-to-caller, and dynamic-index branch tables, with static instructions, and lets compilers generate code using only RJUMP/RJUMPI/RJUMPSUB.

Validation algorithm extension

Extends EIP-7979's validation algorithm to check that the relative_offset of all five instructions points to an actual instruction. It is invalid if it points inside the immediate data of PUSHn or RJUMP/RJUMPI/RJUMPV, or outside the code range. RJUMPSUB and RJUMPSUBV must, and only these two may, point to ENTERSUB; the other three may point to JUMPDEST but it is not required. Other invalid cases include a truncated immediate value, and RJUMPI or RJUMPV being the last instruction in a code section. RJUMP may be the last instruction.

Recommended gas cost

Since destinations written as immediate values are already checked during the jumpdest analysis stage, they do not need to be checked again at runtime, and can therefore be priced more cheaply than dynamic jumps. The source text recommends 2 for RJUMP, 4 for RJUMPI and RJUMPV, and 5 for RJUMPSUB and RJUMPSUBV. Also, since static jump destinations do not need JUMPDEST, 200 gas in per-byte deployment cost is saved for each destination, and the 1 gas that JUMPDEST itself cost when executed during a jump is also saved, 1 gas per jump.

Why relative addressing and a 16-bit immediate value were chosen

Relative addressing was chosen to make code relocatable. Code fragments can be inserted into other code, the PUSHn PC ADD JUMPI technique previously used for the same purpose becomes unnecessary, and the PC instruction can even be deprecated. With a 16-bit signed immediate value, the maximum jump distance is 32767, and starting RJUMP at PC=0 reaches up to PC=32770. Considering MAX_CODE_SIZE = 24576 (EIP-170) and MAX_INITCODE_SIZE = 49152 (EIP-3860), this is a sufficient size. An 8-bit version would only reach 125 bytes backward and 127 bytes forward, which is insufficient for jumps between functions, while 16 bits is the same size as a dynamic jump (JUMP PUSH1 n, 3 bytes), so the choice was made to reduce the number of instructions. If a different size is needed later, a new opcode can be added, as was done with PUSH.

Why no discount is given to the PUSHn JUMP sequence

If absolute addresses were chosen, RJUMP would look similar to a PUSHn JUMP sequence, which could lead to arguments for giving that sequence a gas discount instead of adding a new instruction. The source document views this as the wrong direction. It would make the already complex gas accounting rules even more complex, and would either require a consensus-level defined internal representation of EVM code or force each implementation to perform its own optimization. Both are risky: implementations should be free to choose which optimizations to apply, and are not required to pass those savings on as gas reductions. Also, current implementations stream-execute one instruction at a time without lookahead, so this would require substantial changes. The semantics of the existing PUSHn JUMP sequence are left to EIP-7979.

Compatibility and current status

This change poses no backwards compatibility risk and does not prevent the use of legacy code. It also does not preclude introducing other forms of control flow later, and can coexist with higher-level function declarations, allowing static relative jumps to be used for control flow within a function's body. EIP-8173 covers the historical background and technical basis of static control flow. This EIP was created on August 19, 2025 and is in Draft status, so the specification may still change.

Original EIP · ← EIPs