---
eip: 5450
label: EIP-5450
title: EOF - Stack Validation
status: Stagnant
type: Standards Track
category: Core
created: 2022-08-12
requires: 3540, 3670, 4200, 4750
official: https://eips.ethereum.org/EIPS/eip-5450
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-5450.md
canonical: https://eips.huatuo.xyz/eip-5450/
lang: en
tldr: "Part of EOF: a deploy-time, single-pass check that proves an EOF function can never underflow the stack and can only overflow at CALLF/JUMPF, so the EVM can skip most per-instruction stack checks."
tags: [eof, evm, validation, stack, core]
---

# EIP-5450: EOF - Stack Validation

> Deploy-time validation of stack usage for EOF functions.

**TL;DR:** Part of EOF: a deploy-time, single-pass check that proves an EOF function can never underflow the stack and can only overflow at CALLF/JUMPF, so the EVM can skip most per-instruction stack checks.

## What problem does it solve?

Today's EVM checks for stack underflow and overflow on **every instruction** it executes. That costs time, and it means bad bytecode is only caught when it runs.

The EVM Object Format (EOF, [EIP-3540](/eip-3540/)) validates code when it is deployed instead. EIP-5450 adds stack validation to that process. Every EOF code section is analyzed once, before deployment, and rejected unless the analysis proves stack errors are impossible. After that:

- run-time **underflow** checks can be removed entirely,
- **overflow** is checked only at `CALLF`/`JUMPF`, once for the whole called function,
- every path ends in a terminating instruction, and unreachable code (sometimes used to hide data in code) is rejected,
- AOT/JIT compilation of EVM code becomes easier.

## How it works

The rules build on [EIP-3670](/eip-3670/) (opcode validation), [EIP-4200](/eip-4200/) (static relative jumps `RJUMP`/`RJUMPI`/`RJUMPV`) and [EIP-4750](/eip-4750/) (functions with a type section declaring `inputs`, `outputs` and `max_stack_increase`).

Each code section is scanned **once, in order**. For each instruction the validator keeps a range `[stack_height_min, stack_height_max]` of possible stack heights:

1. The first instruction starts at `inputs`. An instruction that has no recorded range was never reached by fall-through or a forward jump, so it is unreachable and the code is rejected. Compilers must order basic blocks so that no block is reached *only* by a backward jump.
2. The lower bound must cover what the instruction pops. `RETF` needs exactly `outputs` items, and `CALLF` needs at least the callee's `inputs`.
3. For `CALLF`/`JUMPF`, the upper bound plus the callee's `max_stack_increase` must not exceed 1024.
4. Successors reached by **forward jumps** widen the target's range. A **backward jump** must reach its target at exactly the recorded height, so loops cannot grow or shrink the stack without limit.
5. At the end, the highest height seen minus `inputs` must equal the declared `max_stack_increase`.

The pass is linear in code size. Other terminating instructions (`STOP`, `RETURN`, `REVERT`, …) may leave extra items on the stack. That allows the common compiler pattern of several `assert`s jumping into one shared revert block from different stack heights.

## Sample code

A simplified version of the validator loop:

```python
def validate_stack(code, types, sec):
    lo = {0: types[sec].inputs}; hi = {0: types[sec].inputs}
    for pc, ins in instructions(code):
        if pc not in lo: raise Invalid("unreachable")
        need, out = stack_effect(ins, types)          # pops, pushes (CALLF uses callee type)
        if lo[pc] < need: raise Invalid("underflow")
        if ins.op in ("CALLF", "JUMPF") and hi[pc] > 1024 - types[ins.target].max_stack_increase:
            raise Invalid("overflow")
        nlo, nhi = lo[pc] - need + out, hi[pc] - need + out
        for succ in successors(pc, ins):
            if succ < pc:                              # backward jump
                if (lo[succ], hi[succ]) != (nlo, nhi): raise Invalid("loop height mismatch")
            else:
                lo[succ] = min(lo.get(succ, nlo), nlo); hi[succ] = max(hi.get(succ, nhi), nhi)
    if max(hi.values()) - types[sec].inputs != types[sec].max_stack_increase:
        raise Invalid("max_stack_increase mismatch")
```

## Things to know

- **Status: Stagnant**, together with the rest of EOF ([EIP-7692](/eip-7692/) is the EOFv1 meta EIP). EOF was considered for several network upgrades but has not shipped on mainnet.
- The rules apply only to EOF-formatted contracts. Legacy bytecode is unaffected.
- An earlier, stricter design required one exact stack height per instruction. Compiler teams objected, so the current version uses min/max ranges for forward jumps.
- `JUMPF` and `RETURNCODE` are defined in separate EOF EIPs.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-5450
