{"eip":4750,"title":"EOF - Functions","description":"Individual sections for functions with `CALLF` and `RETF` instructions","authors":["Andrei Maiboroda (@gumb0)","Alex Beregszaszi (@axic)","Paweł Bylica (@chfast)"],"status":"Stagnant","type":"Standards Track","category":"Core","created":"2022-01-10","requires":[3540,3670,5450],"discussionsTo":"https://ethereum-magicians.org/t/eip-4750-eof-functions/8195","repo":"EIPs","label":"EIP-4750","officialUrl":"https://eips.ethereum.org/EIPS/eip-4750","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-4750.md","url":"https://eips.huatuo.xyz/eip-4750/","tldr":{"en":"Part of the EOF upgrade set: splits contract code into function sections called with CALLF/RETF, and bans dynamic JUMP/JUMPI inside EOF code.","ja":"EOF アップグレード群の一部。コントラクトコードを CALLF/RETF で呼び出す関数セクションに分割し、EOF コード内の動的な JUMP/JUMPI を禁止する。","ko":"EOF 업그레이드 묶음의 일부. 컨트랙트 코드를 CALLF/RETF로 호출하는 함수 섹션으로 나누고, EOF 코드 안에서 동적 JUMP/JUMPI를 금지한다.","zh":"EOF 升级套件的一部分：把合约代码拆分为通过 CALLF/RETF 调用的函数段，并禁止在 EOF 代码中使用动态 JUMP/JUMPI。"},"tags":["evm","eof","opcodes","functions","core"],"explainers":{"en":{"lang":"en","tldr":"Part of the EOF upgrade set: splits contract code into function sections called with CALLF/RETF, and bans dynamic JUMP/JUMPI inside EOF code.","tags":["evm","eof","opcodes","functions","core"],"related":[3540,3670,5450,4200,7692],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-4750/","markdown":"## What problem does it solve?\n\nIn today's EVM every jump is dynamic: the destination is a stack value, so the interpreter must keep a table of valid `JUMPDEST`s and check each jump at runtime. Compilers like Solidity already emit mostly \"static\" jumps (`PUSH dest; JUMP`), but the EVM cannot rely on that. Function calls are emulated by pushing a return address and jumping, which is opaque to analysis tools and blocks optimizations.\n\n[EIP-4200](/eip-4200/) adds relative static jumps, which cover most uses, but not calling into and returning from functions. EIP-4750 adds that missing piece for EVM Object Format ([EIP-3540](/eip-3540/)) contracts, so dynamic jumps can be removed entirely.\n\n## How it works\n\n- **Multiple code sections.** An EOF container can hold several code sections, one per function. A *type section* stores 4 bytes per section: `inputs` (uint8), `outputs` (uint8) and `max_stack_increase` (uint16). Section 0 is the entry point: it takes no inputs and must be non-returning.\n- **Return stack.** The EVM gains a separate return stack (max 1024 items) holding `(code_section_index, offset)` pairs. Functions cannot see the caller's stack items beyond their declared inputs.\n- **`CALLF` (`0xe3`)**, 5 gas: takes a 2-byte section index immediate, pushes the return location and jumps to byte 0 of that section. It halts if the call could overflow the 1024-item operand stack or the return stack is full.\n- **`RETF` (`0xe4`)**, 3 gas: pops the return stack and continues after the `CALLF`.\n- **Removed in EOF code:** `JUMP`, `JUMPI` and `PC` become invalid; `JUMPDEST` becomes a 1-gas `NOP`. JUMPDEST analysis is no longer needed.\n- **Validation** (with [EIP-3670](/eip-3670/) and [EIP-5450](/eip-5450/)): `CALLF` targets must exist, relative jumps may not land inside `CALLF` immediates, and every section must be reachable. Because stack heights are validated at deploy time, runtime underflow checks (and most overflow checks) are dropped.\n\nIn legacy (non-EOF) code `CALLF` and `RETF` remain undefined, so existing contracts are unaffected.\n\n## Sample code\n\nIllustrative EOF layout with two sections, a `main` that calls a `square` function:\n\n```text\ntype section:\n  [0] inputs=0 outputs=0x80 (non-returning) max_stack_increase=2\n  [1] inputs=1 outputs=1                     max_stack_increase=1\n\ncode section 0 (main):\n  PUSH1 0x07\n  CALLF 0x0001      ; e3 0001 -\u003e call section 1 with 1 input\n  ...               ; result (0x31) is on the stack\n  STOP\n\ncode section 1 (square):\n  DUP1\n  MUL\n  RETF              ; e4 -\u003e back to main, 1 output\n```\n\n## Things to know\n\n- Status: **Stagnant**. It is one piece of the EOF bundle tracked in [EIP-7692](/eip-7692/), which is also Stagnant; EOF has not been activated on Ethereum mainnet.\n- Later EOF proposals in the same bundle add `JUMPF` (tail calls) and non-returning functions; this EIP refers to those as \"separate EIPs\".\n- The spec reserves the high bit of `inputs`/`outputs`, so functions are limited to 127 inputs and outputs, and `outputs == 0x80` marks a non-returning function.\n- Its predecessor approach, subroutines in legacy code ([EIP-2315](/eip-2315/)), was withdrawn.\n"},"ja":{"lang":"ja","tldr":"EOF アップグレード群の一部。コントラクトコードを CALLF/RETF で呼び出す関数セクションに分割し、EOF コード内の動的な JUMP/JUMPI を禁止する。","tags":["evm","eof","opcodes","functions","core"],"related":[3540,3670,5450,4200,7692],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-4750/","markdown":"## 何を解決するのか\n\n現在の EVM ではすべてのジャンプが動的です。ジャンプ先はスタック上の値なので、インタープリターは有効な `JUMPDEST` のテーブルを保持し、ジャンプのたびに実行時に検査しなければなりません。Solidity などのコンパイラーはすでにほとんど「静的な」ジャンプ（`PUSH dest; JUMP`）を出力していますが、EVM はそれに頼れません。関数呼び出しは、戻りアドレスを push してジャンプすることで模倣されており、解析ツールからは不透明で、最適化の妨げにもなります。\n\n[EIP-4200](/eip-4200/) は相対的な静的ジャンプを追加し、ほとんどの用途をカバーしますが、関数の呼び出しとそこからの復帰はカバーしません。EIP-4750 は EVM Object Format（[EIP-3540](/eip-3540/)）のコントラクトにこの欠けていた部分を加え、動的ジャンプを完全に取り除けるようにします。\n\n## 仕組み\n\n- **複数のコードセクション。** EOF コンテナは関数ごとに 1 つ、複数のコードセクションを持てます。*type セクション*はセクションごとに 4 バイトを保持します。`inputs`（uint8）、`outputs`（uint8）、`max_stack_increase`（uint16）です。セクション 0 はエントリーポイントで、入力を取らず、復帰しない（non-returning）ものでなければなりません。\n- **リターンスタック。** EVM に、`(code_section_index, offset)` の組を保持する別のリターンスタック（最大 1024 要素）が加わります。関数は、宣言された入力を超えて呼び出し元のスタック項目を見ることはできません。\n- **`CALLF`（`0xe3`）**、5 gas: 2 バイトのセクションインデックスを即値として取り、戻り先を push して、そのセクションの 0 バイト目にジャンプします。呼び出しによって 1024 要素のオペランドスタックがあふれる可能性がある場合、またはリターンスタックが満杯の場合は停止します。\n- **`RETF`（`0xe4`）**、3 gas: リターンスタックを pop し、`CALLF` の直後から続行します。\n- **EOF コードで削除されるもの:** `JUMP`、`JUMPI`、`PC` は無効になり、`JUMPDEST` は 1 gas の `NOP` になります。JUMPDEST 解析はもう不要です。\n- **検証**（[EIP-3670](/eip-3670/) および [EIP-5450](/eip-5450/) と併せて）: `CALLF` の対象が存在すること、相対ジャンプが `CALLF` の即値の内部に着地しないこと、すべてのセクションに到達可能であることが求められます。スタックの高さがデプロイ時に検証されるため、実行時のアンダーフロー検査（とほとんどのオーバーフロー検査）は不要になります。\n\nレガシー（非 EOF）コードでは `CALLF` と `RETF` は未定義のままなので、既存のコントラクトには影響しません。\n\n## サンプルコード\n\n2 つのセクションを持つ EOF レイアウトの例です。`main` が `square` 関数を呼び出します。\n\n```text\ntype section:\n  [0] inputs=0 outputs=0x80 (non-returning) max_stack_increase=2\n  [1] inputs=1 outputs=1                     max_stack_increase=1\n\ncode section 0 (main):\n  PUSH1 0x07\n  CALLF 0x0001      ; e3 0001 -\u003e call section 1 with 1 input\n  ...               ; result (0x31) is on the stack\n  STOP\n\ncode section 1 (square):\n  DUP1\n  MUL\n  RETF              ; e4 -\u003e back to main, 1 output\n```\n\n## 知っておくべきこと\n\n- ステータス: **Stagnant**。[EIP-7692](/eip-7692/) で管理されている EOF バンドルの一部で、そのバンドル自体も Stagnant です。EOF は Ethereum メインネットではアクティベートされていません。\n- 同じバンドル内の後続の EOF 提案で `JUMPF`（末尾呼び出し）と non-returning 関数が追加されます。この EIP ではそれらを「別の EIP」として参照しています。\n- 仕様では `inputs`/`outputs` の最上位ビットが予約されているため、関数の入力と出力はそれぞれ 127 個までに制限され、`outputs == 0x80` は non-returning 関数を示します。\n- その前身のアプローチであるレガシーコードのサブルーチン（[EIP-2315](/eip-2315/)）は Withdrawn になりました。\n"},"ko":{"lang":"ko","tldr":"EOF 업그레이드 묶음의 일부. 컨트랙트 코드를 CALLF/RETF로 호출하는 함수 섹션으로 나누고, EOF 코드 안에서 동적 JUMP/JUMPI를 금지한다.","tags":["evm","eof","opcodes","functions","core"],"related":[3540,3670,5450,4200,7692],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-4750/","markdown":"## 어떤 문제를 해결하나요?\n\n오늘날의 EVM에서는 모든 점프가 동적입니다. 목적지가 스택 값이므로 인터프리터는 유효한 `JUMPDEST` 테이블을 유지하고 점프할 때마다 런타임에 검사해야 합니다. Solidity 같은 컴파일러는 이미 대부분 \"정적\" 점프(`PUSH dest; JUMP`)를 내보내지만, EVM은 이에 의존할 수 없습니다. 함수 호출은 복귀 주소를 push하고 점프하는 방식으로 흉내 내는데, 이는 분석 도구에는 불투명하고 최적화를 가로막습니다.\n\n[EIP-4200](/eip-4200/)은 상대 정적 점프를 추가해 대부분의 용도를 해결하지만, 함수 호출과 복귀는 다루지 않습니다. EIP-4750은 EVM Object Format([EIP-3540](/eip-3540/)) 컨트랙트에 이 빠진 부분을 더해, 동적 점프를 완전히 없앨 수 있게 합니다.\n\n## 어떻게 동작하나요?\n\n- **여러 코드 섹션.** EOF 컨테이너는 함수마다 하나씩 여러 코드 섹션을 담을 수 있습니다. *type 섹션*은 섹션당 4바이트를 저장합니다. `inputs`(uint8), `outputs`(uint8), `max_stack_increase`(uint16)입니다. 섹션 0은 진입점으로, 입력을 받지 않으며 반드시 복귀하지 않는(non-returning) 섹션이어야 합니다.\n- **리턴 스택.** EVM에 `(code_section_index, offset)` 쌍을 담는 별도의 리턴 스택(최대 1024개 항목)이 추가됩니다. 함수는 선언된 입력을 넘어서는 호출자의 스택 항목을 볼 수 없습니다.\n- **`CALLF`(`0xe3`)**, 5 gas: 2바이트 섹션 인덱스를 즉시값으로 받아 복귀 위치를 push하고 해당 섹션의 0번째 바이트로 점프합니다. 호출로 1024개 항목의 피연산자 스택이 넘칠 수 있거나 리턴 스택이 가득 찬 경우 중단됩니다.\n- **`RETF`(`0xe4`)**, 3 gas: 리턴 스택을 pop하고 `CALLF` 다음부터 계속 실행합니다.\n- **EOF 코드에서 제거되는 것:** `JUMP`, `JUMPI`, `PC`는 무효가 되고, `JUMPDEST`는 1 gas짜리 `NOP`가 됩니다. JUMPDEST 분석은 더 이상 필요하지 않습니다.\n- **검증**([EIP-3670](/eip-3670/), [EIP-5450](/eip-5450/)과 함께): `CALLF` 대상이 존재해야 하고, 상대 점프가 `CALLF` 즉시값 안으로 떨어져서는 안 되며, 모든 섹션에 도달할 수 있어야 합니다. 스택 높이가 배포 시점에 검증되므로 런타임 언더플로 검사(와 대부분의 오버플로 검사)는 생략됩니다.\n\n레거시(비 EOF) 코드에서는 `CALLF`와 `RETF`가 계속 정의되지 않은 상태이므로 기존 컨트랙트는 영향을 받지 않습니다.\n\n## 샘플 코드\n\n두 섹션으로 이루어진 EOF 레이아웃 예시로, `main`이 `square` 함수를 호출합니다.\n\n```text\ntype section:\n  [0] inputs=0 outputs=0x80 (non-returning) max_stack_increase=2\n  [1] inputs=1 outputs=1                     max_stack_increase=1\n\ncode section 0 (main):\n  PUSH1 0x07\n  CALLF 0x0001      ; e3 0001 -\u003e call section 1 with 1 input\n  ...               ; result (0x31) is on the stack\n  STOP\n\ncode section 1 (square):\n  DUP1\n  MUL\n  RETF              ; e4 -\u003e back to main, 1 output\n```\n\n## 알아둘 점\n\n- 상태: **Stagnant**. [EIP-7692](/eip-7692/)에서 추적하는 EOF 묶음의 한 조각이며, 그 묶음 자체도 Stagnant입니다. EOF는 이더리움 메인넷에서 활성화되지 않았습니다.\n- 같은 묶음의 이후 EOF 제안에서 `JUMPF`(꼬리 호출)와 복귀하지 않는 함수가 추가됩니다. 이 EIP는 이들을 \"별도의 EIP\"로 언급합니다.\n- 사양은 `inputs`/`outputs`의 최상위 비트를 예약해 두었으므로 함수의 입력과 출력은 각각 127개로 제한되며, `outputs == 0x80`은 복귀하지 않는 함수를 나타냅니다.\n- 이전 접근 방식인 레거시 코드의 서브루틴([EIP-2315](/eip-2315/))은 Withdrawn되었습니다.\n"},"zh":{"lang":"zh","tldr":"EOF 升级套件的一部分：把合约代码拆分为通过 CALLF/RETF 调用的函数段，并禁止在 EOF 代码中使用动态 JUMP/JUMPI。","tags":["evm","eof","opcodes","functions","core"],"related":[3540,3670,5450,4200,7692],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-4750/","markdown":"## 它解决什么问题？\n\n在当今的 EVM 中，每次跳转都是动态的：目标地址是栈上的值，因此解释器必须维护一张有效 `JUMPDEST` 表，并在运行时检查每一次跳转。Solidity 等编译器已经主要生成\"静态\"跳转（`PUSH dest; JUMP`），但 EVM 无法依赖这一点。函数调用是通过压入返回地址再跳转来模拟的，这对分析工具不透明，也阻碍了优化。\n\n[EIP-4200](/eip-4200/) 增加了相对静态跳转，覆盖了大部分用途，但不包括调用函数和从函数返回。EIP-4750 为 EVM 对象格式（[EIP-3540](/eip-3540/)）的合约补上了这块缺失的拼图，从而可以彻底移除动态跳转。\n\n## 它如何运作\n\n- **多个代码段。** 一个 EOF 容器可以包含多个代码段，每个函数一个。*类型段*为每个代码段存储 4 字节：`inputs`（uint8）、`outputs`（uint8）和 `max_stack_increase`（uint16）。第 0 段是入口点：它没有输入，且必须是不返回的。\n- **返回栈。** EVM 新增一个独立的返回栈（最多 1024 项），保存 `(code_section_index, offset)` 对。函数看不到调用者栈中超出其声明输入的内容。\n- **`CALLF`（`0xe3`）**，5 gas：接受一个 2 字节的段索引立即数，压入返回位置并跳转到该段的第 0 字节。如果调用可能使 1024 项的操作数栈溢出，或返回栈已满，则中止。\n- **`RETF`（`0xe4`）**，3 gas：弹出返回栈，并从 `CALLF` 之后继续执行。\n- **EOF 代码中移除的内容：** `JUMP`、`JUMPI` 和 `PC` 变为无效；`JUMPDEST` 变为 1 gas 的 `NOP`。不再需要 JUMPDEST 分析。\n- **验证**（配合 [EIP-3670](/eip-3670/) 和 [EIP-5450](/eip-5450/)）：`CALLF` 的目标必须存在，相对跳转不能落在 `CALLF` 立即数内部，每个代码段都必须可达。由于栈高度在部署时已被验证，运行时的下溢检查（以及大多数上溢检查）被省去。\n\n在旧版（非 EOF）代码中，`CALLF` 和 `RETF` 仍未定义，因此现有合约不受影响。\n\n## 示例代码\n\n一个包含两个代码段的 EOF 布局示意，`main` 调用 `square` 函数：\n\n```text\ntype section:\n  [0] inputs=0 outputs=0x80 (non-returning) max_stack_increase=2\n  [1] inputs=1 outputs=1                     max_stack_increase=1\n\ncode section 0 (main):\n  PUSH1 0x07\n  CALLF 0x0001      ; e3 0001 -\u003e call section 1 with 1 input\n  ...               ; result (0x31) is on the stack\n  STOP\n\ncode section 1 (square):\n  DUP1\n  MUL\n  RETF              ; e4 -\u003e back to main, 1 output\n```\n\n## 需要注意\n\n- 状态：**Stagnant**。它是 [EIP-7692](/eip-7692/) 所跟踪的 EOF 套件中的一环，该套件同样是 Stagnant；EOF 尚未在以太坊主网激活。\n- 同一套件中后续的 EOF 提案增加了 `JUMPF`（尾调用）和不返回函数；本 EIP 将它们称为\"单独的 EIP\"。\n- 规范保留了 `inputs`/`outputs` 的最高位，因此函数的输入和输出各限制为 127 个，`outputs == 0x80` 表示不返回的函数。\n- 其前身方案，即旧版代码中的子程序（[EIP-2315](/eip-2315/)），已被撤回。\n"}},"requiredBy":[5450,6206,7692,7756,7961]}
