{"eip":7979,"title":"Call and Return Opcodes for the EVM","description":"Three new instructions to support calls and returns.","authors":["Greg Colvin (@gcolvin) \u003cgreg@colvin.org\u003e","Martin Holst Swende (@holiman)","Brooklyn Zelenka (@expede)","John Max Skaller"],"status":"Review","type":"Standards Track","category":"Core","created":"2025-12-17","discussionsTo":"https://ethereum-magicians.org/t/eip-7979-call-and-return-opcodes-for-the-evm/24615","repo":"EIPs","label":"EIP-7979","officialUrl":"https://eips.ethereum.org/EIPS/eip-7979","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7979.md","url":"https://eips.huatuo.xyz/eip-7979/","tldr":{"en":"Adds three EVM opcodes, `CALLSUB`, `CALLDEST` and `RETURNSUB`, plus a hidden return stack, so compilers can express function calls directly instead of faking them with dynamic jumps, making code smaller, cheaper and statically analysable.","ja":"EVM に `CALLSUB`、`CALLDEST`、`RETURNSUB` の 3 つのオペコードと隠れた return stack を追加する。コンパイラは動的ジャンプで関数呼び出しを擬似的に作る代わりに直接表現でき、コードは小さく安価になり、静的解析も可能になる。","ko":"EVM에 `CALLSUB`, `CALLDEST`, `RETURNSUB` 세 가지 opcode와 숨겨진 return stack을 추가한다. 컴파일러가 동적 점프로 함수 호출을 흉내 내는 대신 직접 표현할 수 있어 코드가 더 작고 저렴해지며 정적 분석도 가능해진다.","zh":"新增三个 EVM 操作码 `CALLSUB`、`CALLDEST` 和 `RETURNSUB`，以及一个隐藏的返回栈，使编译器可以直接表达函数调用，而不必用动态跳转来模拟，从而让代码更小、更省 gas，并可进行静态分析。"},"tags":["evm","opcodes","subroutines","control-flow","compilers"],"explainers":{"en":{"lang":"en","tldr":"Adds three EVM opcodes, `CALLSUB`, `CALLDEST` and `RETURNSUB`, plus a hidden return stack, so compilers can express function calls directly instead of faking them with dynamic jumps, making code smaller, cheaper and statically analysable.","tags":["evm","opcodes","subroutines","control-flow","compilers"],"related":[8173,7937,2315,615,3540],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-7979/","markdown":"## What problem does it solve?\n\nThe EVM has no instruction for \"call a function\" or \"return from it\". Compilers like Solidity fake both with `JUMP`: they push a return address onto the data stack, jump into the function, and at the end jump back to whatever address is on the stack. That has two costs:\n\n- **Gas and bytes.** Every call and return needs extra pushes, swaps and jumpdests.\n- **Opaque control flow.** A return is a jump whose destination is *data*. Any tool that wants to follow the program's control flow (validators, AOT/JIT compilers, formal verifiers) must consider every possible destination, which can take quadratic time or worse. For on-chain analysis at deploy or run time, anything worse than linear is a denial-of-service risk. [EIP-8173](/eip-8173/) lays out this problem in detail.\n\n## How it works\n\nThe EVM gains a **return stack** (up to 1024 entries) that EVM code cannot read or modify, and three instructions:\n\n| Opcode | Name | Gas | Effect |\n| --- | --- | --- | --- |\n| `0xBC` | `CALLSUB` | 8 | Pop a destination from the data stack, push `PC + 1` onto the return stack, jump. The destination must be a `CALLDEST`. |\n| `0xBB` | `CALLDEST` | 1 | Marks a subroutine entry; otherwise a no-op like `JUMPDEST`. |\n| `0xBF` | `RETURNSUB` | 5 | Pop the return stack into `PC`. |\n\nCalling a non-`CALLDEST`, overflowing the return stack, or returning with an empty return stack is an exceptional halt. A `CALLDEST` is also a valid `JUMP`/`JUMPI` target, which allows tail calls: jumping into a subroutine reuses the caller's return address, so recursion in tail position runs at constant return-stack depth.\n\nBecause return addresses live outside the data stack, code cannot corrupt them. Code that avoids dynamic jumps can be checked in a single linear pass, which the authors argue enables safe AOT/JIT compilation and cheaper ZK proving of EVM code. There are no code sections or immediates, so unlike EOF ([EIP-3540](/eip-3540/)) existing code is unaffected.\n\n## Sample code\n\nThe spec's simplest test, as bytecode `0x6004BC00BBBF`:\n\n```\nPC 0: PUSH1 0x04   ; destination of the subroutine\nPC 2: CALLSUB      ; return stack = [3], jump to 4\nPC 3: STOP\nPC 4: CALLDEST     ; subroutine entry\nPC 5: RETURNSUB    ; pop 3 -\u003e PC = 3\n; total gas: 3 + 8 + 1 + 5 + 0 = 17\n```\n\nA squaring routine, from the spec's comparison:\n\n```\nSQUARE:      calldest          ; 1\n             dup1              ; 3\n             mul               ; 5\n             returnsub         ; 5\nCALL_SQUARE: calldest\n             push 2\n             push SQUARE\n             callsub           ; 8\n             returnsub\n```\n\nThe authors' example shrinks from 17 to 12 bytes and from 50 to 34 gas versus the `JUMP`-based version.\n\n## Things to know\n\n- **Status: Review.** Not scheduled for a network upgrade; gas costs still need benchmarking according to the spec.\n- Fully backwards compatible: opcodes `0xBB`, `0xBC`, `0xBF` were unassigned, and existing code behaves exactly as before. `0xBD`/`0xBE` are left free for a possible future multi-way jump.\n- Savings only appear once compilers emit the new opcodes; existing contracts gain nothing.\n- Explicit subroutines have a long history: earlier attempts include [EIP-615](/eip-615/) and [EIP-2315](/eip-2315/). The spec's performance figures also use the 64-bit opcodes of [EIP-7937](/eip-7937/).\n"},"ja":{"lang":"ja","tldr":"EVM に `CALLSUB`、`CALLDEST`、`RETURNSUB` の 3 つのオペコードと隠れた return stack を追加する。コンパイラは動的ジャンプで関数呼び出しを擬似的に作る代わりに直接表現でき、コードは小さく安価になり、静的解析も可能になる。","tags":["evm","opcodes","subroutines","control-flow","compilers"],"related":[8173,7937,2315,615,3540],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-7979/","markdown":"## 何を解決するのか\n\nEVM には「関数を呼ぶ」命令も「関数から戻る」命令もありません。Solidity などのコンパイラはどちらも `JUMP` で擬似的に実現しています。戻り先アドレスをデータスタックに積み、関数へジャンプし、最後にスタック上のアドレスへジャンプで戻ります。これには 2 つのコストがあります。\n\n- **ガスとバイト数。** 呼び出しと復帰のたびに、余分な push、swap、jumpdest が必要になります。\n- **不透明な制御フロー。** return は、ジャンプ先が*データ*であるジャンプです。プログラムの制御フローを追いたいツール（バリデータ、AOT/JIT コンパイラ、形式検証器）は、あり得るすべてのジャンプ先を考慮する必要があり、二次時間以上かかることがあります。デプロイ時や実行時のオンチェーン解析では、線形より悪いものはすべてサービス拒否のリスクになります。[EIP-8173](/eip-8173/) がこの問題を詳しく説明しています。\n\n## 仕組み\n\nEVM に、EVM コードから読み取りも変更もできない **return stack**（最大 1024 エントリ）と、3 つの命令が加わります。\n\n| オペコード | 名前 | ガス | 効果 |\n| --- | --- | --- | --- |\n| `0xBC` | `CALLSUB` | 8 | データスタックからジャンプ先を pop し、`PC + 1` を return stack に push してジャンプする。ジャンプ先は `CALLDEST` でなければならない。 |\n| `0xBB` | `CALLDEST` | 1 | サブルーチンの入口を示す。それ以外は `JUMPDEST` と同じ no-op。 |\n| `0xBF` | `RETURNSUB` | 5 | return stack を pop して `PC` に設定する。 |\n\n`CALLDEST` ではない場所の呼び出し、return stack のオーバーフロー、空の return stack での復帰は、例外的停止になります。`CALLDEST` は `JUMP` / `JUMPI` の有効なジャンプ先でもあり、これにより末尾呼び出しが可能です。サブルーチンへジャンプすると呼び出し元の戻り先アドレスが再利用されるため、末尾位置の再帰は一定の return stack の深さで動きます。\n\n戻り先アドレスがデータスタックの外にあるため、コードがそれを壊すことはできません。動的ジャンプを使わないコードは 1 回の線形パスで検証でき、著者らはこれにより安全な AOT/JIT コンパイルと、EVM コードのより安価な ZK 証明が可能になると主張しています。コードセクションやイミディエイトはないため、EOF（[EIP-3540](/eip-3540/)）と違って既存コードには影響しません。\n\n## サンプルコード\n\n仕様の最も単純なテスト。バイトコードは `0x6004BC00BBBF`:\n\n```\nPC 0: PUSH1 0x04   ; destination of the subroutine\nPC 2: CALLSUB      ; return stack = [3], jump to 4\nPC 3: STOP\nPC 4: CALLDEST     ; subroutine entry\nPC 5: RETURNSUB    ; pop 3 -\u003e PC = 3\n; total gas: 3 + 8 + 1 + 5 + 0 = 17\n```\n\n仕様の比較にある二乗ルーチン:\n\n```\nSQUARE:      calldest          ; 1\n             dup1              ; 3\n             mul               ; 5\n             returnsub         ; 5\nCALL_SQUARE: calldest\n             push 2\n             push SQUARE\n             callsub           ; 8\n             returnsub\n```\n\n著者の例では、`JUMP` ベースの版と比べて 17 バイトから 12 バイト、50 ガスから 34 ガスに縮みます。\n\n## 知っておくべきこと\n\n- **ステータス: Review。** ネットワークアップグレードには予定されていません。仕様によると、ガスコストはまだベンチマークが必要です。\n- 完全に後方互換です。オペコード `0xBB`、`0xBC`、`0xBF` は未割り当てで、既存コードはこれまでとまったく同じ動作をします。`0xBD` / `0xBE` は、将来の多方向ジャンプのために空けてあります。\n- 節約が現れるのは、コンパイラが新しいオペコードを出力するようになってからです。既存のコントラクトには何の利点もありません。\n- 明示的なサブルーチンには長い歴史があります。以前の試みには [EIP-615](/eip-615/) と [EIP-2315](/eip-2315/) があります。仕様の性能数値では、[EIP-7937](/eip-7937/) の 64 ビットオペコードも使っています。\n"},"ko":{"lang":"ko","tldr":"EVM에 `CALLSUB`, `CALLDEST`, `RETURNSUB` 세 가지 opcode와 숨겨진 return stack을 추가한다. 컴파일러가 동적 점프로 함수 호출을 흉내 내는 대신 직접 표현할 수 있어 코드가 더 작고 저렴해지며 정적 분석도 가능해진다.","tags":["evm","opcodes","subroutines","control-flow","compilers"],"related":[8173,7937,2315,615,3540],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-7979/","markdown":"## 어떤 문제를 해결하나요?\n\nEVM에는 \"함수를 호출한다\"거나 \"함수에서 돌아온다\"는 명령이 없습니다. Solidity 같은 컴파일러는 둘 다 `JUMP`로 흉내 냅니다. 반환 주소를 데이터 스택에 push하고, 함수로 점프하고, 끝에서 스택에 있는 주소로 다시 점프합니다. 여기에는 두 가지 비용이 있습니다.\n\n- **가스와 바이트.** 호출과 반환마다 push, swap, jumpdest가 추가로 필요합니다.\n- **불투명한 제어 흐름.** return은 점프 대상이 *데이터*인 점프입니다. 프로그램의 제어 흐름을 따라가려는 도구(검증기, AOT/JIT 컴파일러, 형식 검증기)는 가능한 모든 대상을 고려해야 하며, 이는 이차 시간 이상이 걸릴 수 있습니다. 배포 시점이나 실행 시점의 온체인 분석에서는 선형보다 느린 것은 모두 서비스 거부 위험이 됩니다. [EIP-8173](/eip-8173/)이 이 문제를 자세히 설명합니다.\n\n## 어떻게 동작하나요?\n\nEVM에 EVM 코드가 읽거나 바꿀 수 없는 **return stack**(최대 1024개 항목)과 세 가지 명령이 추가됩니다.\n\n| Opcode | 이름 | 가스 | 효과 |\n| --- | --- | --- | --- |\n| `0xBC` | `CALLSUB` | 8 | 데이터 스택에서 대상을 pop하고, `PC + 1`을 return stack에 push한 뒤 점프합니다. 대상은 `CALLDEST`여야 합니다. |\n| `0xBB` | `CALLDEST` | 1 | 서브루틴 진입점을 표시합니다. 그 외에는 `JUMPDEST`처럼 아무 일도 하지 않습니다. |\n| `0xBF` | `RETURNSUB` | 5 | return stack을 pop해서 `PC`에 넣습니다. |\n\n`CALLDEST`가 아닌 곳을 호출하거나, return stack이 넘치거나, return stack이 빈 상태에서 반환하면 예외적 중단이 됩니다. `CALLDEST`는 유효한 `JUMP`/`JUMPI` 대상이기도 해서 tail call이 가능합니다. 서브루틴으로 점프하면 호출자의 반환 주소를 재사용하므로, 꼬리 위치의 재귀는 일정한 return stack 깊이로 실행됩니다.\n\n반환 주소가 데이터 스택 밖에 있으므로 코드가 이를 망가뜨릴 수 없습니다. 동적 점프를 피하는 코드는 한 번의 선형 패스로 검사할 수 있으며, 저자들은 이것이 안전한 AOT/JIT 컴파일과 EVM 코드의 더 저렴한 ZK 증명을 가능하게 한다고 주장합니다. 코드 섹션이나 immediate가 없기 때문에 EOF([EIP-3540](/eip-3540/))와 달리 기존 코드는 영향을 받지 않습니다.\n\n## 샘플 코드\n\n사양에서 가장 단순한 테스트, 바이트코드는 `0x6004BC00BBBF`입니다.\n\n```\nPC 0: PUSH1 0x04   ; destination of the subroutine\nPC 2: CALLSUB      ; return stack = [3], jump to 4\nPC 3: STOP\nPC 4: CALLDEST     ; subroutine entry\nPC 5: RETURNSUB    ; pop 3 -\u003e PC = 3\n; total gas: 3 + 8 + 1 + 5 + 0 = 17\n```\n\n사양의 비교에 나오는 제곱 루틴:\n\n```\nSQUARE:      calldest          ; 1\n             dup1              ; 3\n             mul               ; 5\n             returnsub         ; 5\nCALL_SQUARE: calldest\n             push 2\n             push SQUARE\n             callsub           ; 8\n             returnsub\n```\n\n저자의 예시는 `JUMP` 기반 버전과 비교해 17바이트에서 12바이트로, 50 가스에서 34 가스로 줄어듭니다.\n\n## 알아둘 점\n\n- **상태: Review.** 네트워크 업그레이드에 예정되어 있지 않으며, 사양에 따르면 가스 비용은 아직 벤치마크가 필요합니다.\n- 완전히 하위 호환됩니다. opcode `0xBB`, `0xBC`, `0xBF`는 미할당이었고 기존 코드는 이전과 똑같이 동작합니다. `0xBD`/`0xBE`는 나중에 있을 수 있는 다중 분기 점프를 위해 비워 둡니다.\n- 절감 효과는 컴파일러가 새 opcode를 내보내기 시작해야 나타나며, 기존 컨트랙트는 얻는 것이 없습니다.\n- 명시적 서브루틴에는 오랜 역사가 있습니다. 이전 시도로는 [EIP-615](/eip-615/)와 [EIP-2315](/eip-2315/)가 있습니다. 사양의 성능 수치는 [EIP-7937](/eip-7937/)의 64비트 opcode도 사용합니다.\n"},"zh":{"lang":"zh","tldr":"新增三个 EVM 操作码 `CALLSUB`、`CALLDEST` 和 `RETURNSUB`，以及一个隐藏的返回栈，使编译器可以直接表达函数调用，而不必用动态跳转来模拟，从而让代码更小、更省 gas，并可进行静态分析。","tags":["evm","opcodes","subroutines","control-flow","compilers"],"related":[8173,7937,2315,615,3540],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-7979/","markdown":"## 它解决什么问题？\n\nEVM 没有\"调用函数\"或\"从函数返回\"的指令。Solidity 等编译器都用 `JUMP` 来模拟：先把返回地址压入数据栈，跳进函数，结束时再跳回栈上的那个地址。这有两个代价：\n\n- **gas 和字节数。** 每次调用和返回都需要额外的 push、swap 和 jumpdest。\n- **不透明的控制流。** 返回是一个目标为*数据*的跳转。任何想跟踪程序控制流的工具（验证器、AOT/JIT 编译器、形式化验证器）都必须考虑每一个可能的目标，这可能需要二次方甚至更长的时间。对于部署时或运行时的链上分析，任何比线性更差的复杂度都是拒绝服务风险。[EIP-8173](/eip-8173/) 详细阐述了这个问题。\n\n## 它如何运作\n\nEVM 新增一个 EVM 代码无法读取或修改的**返回栈**（最多 1024 项），以及三条指令：\n\n| 操作码 | 名称 | Gas | 效果 |\n| --- | --- | --- | --- |\n| `0xBC` | `CALLSUB` | 8 | 从数据栈弹出一个目标地址，把 `PC + 1` 压入返回栈，然后跳转。目标必须是 `CALLDEST`。 |\n| `0xBB` | `CALLDEST` | 1 | 标记子程序入口；其余行为与 `JUMPDEST` 一样是空操作。 |\n| `0xBF` | `RETURNSUB` | 5 | 弹出返回栈并赋给 `PC`。 |\n\n调用非 `CALLDEST` 的位置、返回栈溢出、或在返回栈为空时返回，都属于异常中止。`CALLDEST` 同时也是有效的 `JUMP`/`JUMPI` 目标，这使尾调用成为可能：跳进子程序会复用调用者的返回地址，因此处于尾位置的递归可以在恒定的返回栈深度下运行。\n\n由于返回地址存放在数据栈之外，代码无法破坏它们。避免动态跳转的代码可以一次线性扫描完成检查，作者认为这使安全的 AOT/JIT 编译以及更便宜的 EVM 代码 ZK 证明成为可能。它没有代码段，也没有立即数，因此与 EOF（[EIP-3540](/eip-3540/)）不同，现有代码不受影响。\n\n## 示例代码\n\n规范中最简单的测试，字节码为 `0x6004BC00BBBF`：\n\n```\nPC 0: PUSH1 0x04   ; destination of the subroutine\nPC 2: CALLSUB      ; return stack = [3], jump to 4\nPC 3: STOP\nPC 4: CALLDEST     ; subroutine entry\nPC 5: RETURNSUB    ; pop 3 -\u003e PC = 3\n; total gas: 3 + 8 + 1 + 5 + 0 = 17\n```\n\n规范对比中的一个求平方例程：\n\n```\nSQUARE:      calldest          ; 1\n             dup1              ; 3\n             mul               ; 5\n             returnsub         ; 5\nCALL_SQUARE: calldest\n             push 2\n             push SQUARE\n             callsub           ; 8\n             returnsub\n```\n\n与基于 `JUMP` 的版本相比，作者的示例从 17 字节缩小到 12 字节，从 50 gas 降到 34 gas。\n\n## 需要注意\n\n- **状态：Review。** 尚未排入网络升级；根据规范，gas 成本仍需基准测试。\n- 完全向后兼容：操作码 `0xBB`、`0xBC`、`0xBF` 原本未分配，现有代码的行为与以前完全一致。`0xBD`/`0xBE` 保持空闲，留给将来可能的多路跳转。\n- 只有编译器开始生成新的操作码后才会出现节省效果；现有合约不会有任何收益。\n- 显式子程序有很长的历史：早期的尝试包括 [EIP-615](/eip-615/) 和 [EIP-2315](/eip-2315/)。规范中的性能数据还使用了 [EIP-7937](/eip-7937/) 的 64 位操作码。\n"}},"requiredBy":[8013,8337]}
