---
eip: 3779
label: EIP-3779
title: Safer Control Flow for the EVM
status: Withdrawn
type: Standards Track
category: Core
created: 2021-08-30
official: https://eips.ethereum.org/EIPS/eip-3779
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3779.md
canonical: https://eips.huatuo.xyz/eip-3779/
lang: en
tldr: A withdrawn proposal to reject, at deployment time, EVM code that could hit invalid jumps, invalid opcodes or stack underflow, using a linear-time static check.
tags: [evm, validation, control-flow, core, withdrawn]
---

# EIP-3779: Safer Control Flow for the EVM

> Ensure an essential level of safety for EVM code.

**TL;DR:** A withdrawn proposal to reject, at deployment time, EVM code that could hit invalid jumps, invalid opcodes or stack underflow, using a linear-time static check.

## What problem does it solve?

Today the EVM discovers many bugs only while running: a jump to a bad destination, an undefined opcode, or popping from an empty stack all cause an exceptional halt at runtime. The EVM also has to keep checking for these conditions on every instruction.

EIP-3779 proposed defining a *safe* contract as one that can never reach such a state, and validating that property once, when the code is deployed. Unsafe code would simply never make it onchain, and clients could skip some runtime checks.

## How it works

The EIP adds no new opcodes. It restricts how existing and proposed control-flow instructions may be used, so that a validator can walk the control-flow graph once, in time and space linear in the code size (important to avoid denial-of-service via expensive validation).

Of the five exceptional halting states the Yellow Paper defines, three would be ruled out at validation time:

| Halting state | Where it is caught |
| --- | --- |
| Invalid instruction | Validation |
| Invalid jump destination | Validation |
| Stack underflow | Validation |
| Out of gas | Runtime |
| Stack overflow (recursive) | Runtime |

Constraints on valid code include:

- Every instruction is defined.
- Every `JUMP`/`JUMPI` is **static**: its destination was pushed with a `PUSH` and only moved by `DUP`/`SWAP` since. Relative jumps (`RJUMP`, `RJUMPI` from [EIP-4200](/eip-4200/)) and subroutine calls (`RJUMPSUB`/`RETURNSUB` from [EIP-2315](/eip-2315/)) are static by construction.
- No jump may land inside immediate data.
- Data and return stack heights stay within bounds, and the data stack height on entering a basic block is the same on every path ("consistently aligned"). This is what prevents underflow and catches subroutine calls with the wrong number of arguments.

## Sample code

The classic "subroutine via JUMP" pattern that stays valid, because both addresses are constants pushed onto the stack:

```text
TEST_SQUARE:
    JUMPDEST
    PUSH RTN_SQUARE   ; return address, a constant
    PUSH 0x02         ; argument
    PUSH SQUARE       ; destination, a constant
    JUMP              ; static: target came from PUSH
RTN_SQUARE:
    JUMPDEST
    SWAP1
    JUMP              ; static: target is the pushed RTN_SQUARE
SQUARE:
    JUMPDEST
    DUP1
    MUL
    SWAP1
    JUMP
```

Something like `CALLDATALOAD` followed by `JUMP` (destination taken from user input) would be rejected.

## Things to know

- Status: **Withdrawn**. Its material was folded back into [EIP-2315](/eip-2315/), which was itself later withdrawn.
- The idea of deploy-time validation lives on in the EVM Object Format work: [EIP-3540](/eip-3540/) (container), [EIP-3670](/eip-3670/) (code validation) and [EIP-5450](/eip-5450/) (stack validation), which took the route of banning dynamic jumps inside EOF code instead of constraining them.
- Validation is conservative: code with an invalid path that can never actually execute is still rejected.


---

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