{"eip":1380,"title":"Reduced gas cost for call to self","description":"Reduce the gas cost for call instructions, when the goal is to run a new instance of the currently loaded contract.","authors":["Alex Beregszaszi (@axic)","Jacques Wagener (@jacqueswww)"],"status":"Stagnant","type":"Standards Track","category":"Core","created":"2018-08-31","requires":[150],"discussionsTo":"https://ethereum-magicians.org/t/eip-1380-reduced-gas-cost-for-call-to-self/1242","repo":"EIPs","label":"EIP-1380","officialUrl":"https://eips.ethereum.org/EIPS/eip-1380","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1380.md","url":"https://eips.huatuo.xyz/eip-1380/","tldr":{"en":"Proposed cutting the gas for a CALL from a contract to itself from 700 to 40, so compilers could use cheap self-calls with clean memory instead of JUMP-based internal functions.","ja":"コントラクトから自分自身への CALL のガスを 700 から 40 に引き下げることを提案した。これにより、コンパイラが JUMP ベースの内部関数の代わりに、クリーンなメモリを持つ安価なセルフコールを使えるようになる。","ko":"컨트랙트가 자기 자신을 호출하는 CALL의 gas를 700에서 40으로 낮춰, 컴파일러가 JUMP 기반 내부 함수 대신 깨끗한 메모리를 가진 저렴한 셀프 호출을 쓸 수 있게 하자고 제안했다.","zh":"提议把合约对自身的 CALL 的 gas 从 700 降到 40，让编译器可以使用廉价且内存干净的自调用，而不是基于 JUMP 的内部函数。"},"tags":["gas","evm","call","compilers","core"],"explainers":{"en":{"lang":"en","tldr":"Proposed cutting the gas for a CALL from a contract to itself from 700 to 40, so compilers could use cheap self-calls with clean memory instead of JUMP-based internal functions.","tags":["gas","evm","call","compilers","core"],"related":[150,2929,2046],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-1380/","markdown":"## What problem does it solve?\n\nLanguages like Solidity and Vyper implement internal function calls with `JUMP`: the same EVM context is reused, and the compiler has to save and restore stack and memory around each call. That is complex, makes \"pure\" functions hard to guarantee (leftover memory can leak into the callee), and burns through the 1024-item stack limit quickly when calls are nested.\n\nA `CALL` to the contract's own address would give each internal function a fresh memory and stack, for free in terms of compiler complexity. But at the time every call type cost 700 gas, set by [EIP-150](/eip-150/) mainly to pay for loading another contract's code from disk. A call to *yourself* needs no such load, since the code is already in memory.\n\n## How it works\n\nAfter the fork block, `CALL`, `DELEGATECALL`, `CALLCODE` and `STATICCALL` would cost **40 gas instead of 700** if and only if the destination address equals the current contract's address.\n\nThe authors' reasoning: before EIP-150 these calls cost 40. EIP-150 added roughly 660 for disk I/O. Since a self-call does no new I/O, the original 40 is a fair price for starting a new VM instance of already-loaded code.\n\nEverything else about the call is unchanged (value transfer costs, memory expansion, the 63/64 gas rule).\n\n## Sample code\n\nWhat a compiler could emit for an internal function if self-calls were cheap, shown as Solidity:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract SelfCall {\n    // Today: internal call compiled to JUMP, shares memory with the caller.\n    function _double(uint256 x) internal pure returns (uint256) { return x * 2; }\n\n    // Style EIP-1380 aimed to make cheap: a fresh EVM frame via call-to-self.\n    function doubleExt(uint256 x) external pure returns (uint256) { return x * 2; }\n\n    function viaSelfCall(uint256 x) external view returns (uint256) {\n        (bool ok, bytes memory out) =\n            address(this).staticcall(abi.encodeCall(this.doubleExt, (x)));\n        require(ok);\n        return abi.decode(out, (uint256));\n    }\n}\n```\n\nCost rule in pseudocode:\n\n```python\ndef call_base_cost(caller, target):\n    if block.number \u003e= FORK_BLKNUM and target == caller:\n        return 40\n    return 700\n```\n\n## Things to know\n\n- Status is **Stagnant**; it was never scheduled into a hard fork.\n- The pricing it targeted no longer exists. [EIP-2929](/eip-2929/) (Berlin) replaced the flat 700 with cold/warm access pricing, under which an address already accessed in the transaction, including the currently executing contract, is charged the warm rate of 100 gas.\n- No mainstream compiler switched internal functions to self-calls; they still use `JUMP`.\n- A related idea for cheaper calls to precompiles is [EIP-2046](/eip-2046/).\n"},"ja":{"lang":"ja","tldr":"コントラクトから自分自身への CALL のガスを 700 から 40 に引き下げることを提案した。これにより、コンパイラが JUMP ベースの内部関数の代わりに、クリーンなメモリを持つ安価なセルフコールを使えるようになる。","tags":["gas","evm","call","compilers","core"],"related":[150,2929,2046],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-1380/","markdown":"## 何を解決するのか\n\nSolidity や Vyper などの言語は、内部関数の呼び出しを `JUMP` で実装しています。同じ EVM コンテキストが再利用されるため、コンパイラは呼び出しのたびにスタックとメモリを退避・復元しなければなりません。これは複雑で、「pure」な関数を保証しにくく（残ったメモリが呼び出された側に漏れる可能性がある）、呼び出しがネストするとスタックの上限 1024 個をすぐに使い果たします。\n\nコントラクト自身のアドレスへの `CALL` なら、各内部関数に新しいメモリとスタックを、コンパイラの複雑さという面ではコストなしで与えられます。しかし当時は、あらゆる種類の呼び出しが 700 gas で、これは主に別のコントラクトのコードをディスクから読み込むコストを賄うために [EIP-150](/eip-150/) が定めたものでした。*自分自身*への呼び出しには、コードがすでにメモリ上にあるため、そのような読み込みは必要ありません。\n\n## 仕組み\n\nフォークブロック以降、`CALL`、`DELEGATECALL`、`CALLCODE`、`STATICCALL` は、宛先アドレスが現在のコントラクトのアドレスと等しい場合に限り、700 gas ではなく **40 gas** になります。\n\n提案者の理屈はこうです。EIP-150 以前、これらの呼び出しは 40 gas でした。EIP-150 は、ディスク I/O の分として約 660 を加えました。セルフコールは新たな I/O を行わないため、元の 40 は、すでに読み込まれたコードの新しい VM インスタンスを開始する価格として妥当です。\n\n呼び出しのそれ以外の部分は変わりません（value 転送のコスト、メモリ拡張、63/64 のガスルール）。\n\n## サンプルコード\n\nセルフコールが安価なら、コンパイラが内部関数に対して出力しうるものを Solidity で示します。\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract SelfCall {\n    // Today: internal call compiled to JUMP, shares memory with the caller.\n    function _double(uint256 x) internal pure returns (uint256) { return x * 2; }\n\n    // Style EIP-1380 aimed to make cheap: a fresh EVM frame via call-to-self.\n    function doubleExt(uint256 x) external pure returns (uint256) { return x * 2; }\n\n    function viaSelfCall(uint256 x) external view returns (uint256) {\n        (bool ok, bytes memory out) =\n            address(this).staticcall(abi.encodeCall(this.doubleExt, (x)));\n        require(ok);\n        return abi.decode(out, (uint256));\n    }\n}\n```\n\nコストのルールを疑似コードで示します。\n\n```python\ndef call_base_cost(caller, target):\n    if block.number \u003e= FORK_BLKNUM and target == caller:\n        return 40\n    return 700\n```\n\n## 知っておくべきこと\n\n- ステータスは **Stagnant** で、ハードフォークに組み込まれる予定になったことはありません。\n- 対象としていた価格設定は、もう存在しません。[EIP-2929](/eip-2929/)（Berlin）が一律の 700 を cold/warm のアクセス価格に置き換えました。これにより、トランザクション内ですでにアクセスされたアドレス（現在実行中のコントラクトを含む）には、warm 料金の 100 gas が課されます。\n- 内部関数をセルフコールに切り替えた主要なコンパイラはなく、今も `JUMP` を使っています。\n- プリコンパイルへの呼び出しを安くする関連アイデアが [EIP-2046](/eip-2046/) です。\n"},"ko":{"lang":"ko","tldr":"컨트랙트가 자기 자신을 호출하는 CALL의 gas를 700에서 40으로 낮춰, 컴파일러가 JUMP 기반 내부 함수 대신 깨끗한 메모리를 가진 저렴한 셀프 호출을 쓸 수 있게 하자고 제안했다.","tags":["gas","evm","call","compilers","core"],"related":[150,2929,2046],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-1380/","markdown":"## 어떤 문제를 해결하나요?\n\nSolidity와 Vyper 같은 언어는 내부 함수 호출을 `JUMP`로 구현합니다. 같은 EVM 컨텍스트를 재사용하기 때문에 컴파일러는 호출 전후로 스택과 메모리를 저장하고 복원해야 합니다. 이는 복잡하고, \"pure\" 함수를 보장하기 어렵게 만들며(남은 메모리가 피호출자에게 새어 들어갈 수 있음), 호출이 중첩되면 1024개 항목의 스택 한도를 금방 소진합니다.\n\n컨트랙트 자신의 주소로 하는 `CALL`은 각 내부 함수에 새로운 메모리와 스택을, 컴파일러 복잡도 측면에서는 공짜로 제공할 수 있습니다. 하지만 당시에는 모든 종류의 호출이 700 gas였고, 이는 주로 다른 컨트랙트의 코드를 디스크에서 불러오는 비용을 충당하려고 [EIP-150](/eip-150/)이 정한 것이었습니다. *자기 자신*을 호출할 때는 코드가 이미 메모리에 있으므로 그런 로딩이 필요 없습니다.\n\n## 어떻게 동작하나요?\n\n포크 블록 이후, `CALL`, `DELEGATECALL`, `CALLCODE`, `STATICCALL`은 목적지 주소가 현재 컨트랙트의 주소와 같을 때에 한해서 700 gas 대신 **40 gas**가 듭니다.\n\n저자들의 논리는 이렇습니다. EIP-150 이전에 이런 호출은 40이었습니다. EIP-150이 디스크 I/O 몫으로 약 660을 더했습니다. 셀프 호출은 새로운 I/O를 하지 않으므로, 원래의 40은 이미 로드된 코드의 새 VM 인스턴스를 시작하는 데 공정한 가격입니다.\n\n호출의 나머지 부분은 모두 그대로입니다(value 전송 비용, 메모리 확장, 63/64 gas 규칙).\n\n## 샘플 코드\n\n셀프 호출이 저렴하다면 컴파일러가 내부 함수에 대해 내보낼 수 있는 코드를 Solidity로 나타낸 것:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract SelfCall {\n    // Today: internal call compiled to JUMP, shares memory with the caller.\n    function _double(uint256 x) internal pure returns (uint256) { return x * 2; }\n\n    // Style EIP-1380 aimed to make cheap: a fresh EVM frame via call-to-self.\n    function doubleExt(uint256 x) external pure returns (uint256) { return x * 2; }\n\n    function viaSelfCall(uint256 x) external view returns (uint256) {\n        (bool ok, bytes memory out) =\n            address(this).staticcall(abi.encodeCall(this.doubleExt, (x)));\n        require(ok);\n        return abi.decode(out, (uint256));\n    }\n}\n```\n\n비용 규칙을 의사 코드로 나타낸 것:\n\n```python\ndef call_base_cost(caller, target):\n    if block.number \u003e= FORK_BLKNUM and target == caller:\n        return 40\n    return 700\n```\n\n## 알아둘 점\n\n- 상태는 **Stagnant**이며, 하드포크에 포함되도록 예정된 적이 없습니다.\n- 목표로 했던 가격 책정은 이제 존재하지 않습니다. [EIP-2929](/eip-2929/)(Berlin)가 고정 700을 cold/warm 접근 가격으로 대체했고, 그에 따라 트랜잭션에서 이미 접근한 주소(현재 실행 중인 컨트랙트 포함)에는 warm 요율인 100 gas가 부과됩니다.\n- 내부 함수를 셀프 호출로 바꾼 주류 컴파일러는 없으며, 여전히 `JUMP`를 사용합니다.\n- 프리컴파일 호출을 더 저렴하게 만드는 관련 아이디어가 [EIP-2046](/eip-2046/)입니다.\n"},"zh":{"lang":"zh","tldr":"提议把合约对自身的 CALL 的 gas 从 700 降到 40，让编译器可以使用廉价且内存干净的自调用，而不是基于 JUMP 的内部函数。","tags":["gas","evm","call","compilers","core"],"related":[150,2929,2046],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-1380/","markdown":"## 它解决什么问题？\n\nSolidity 和 Vyper 等语言用 `JUMP` 来实现内部函数调用：复用同一个 EVM 上下文，编译器必须在每次调用前后保存和恢复栈与内存。这很复杂，使\"pure\"函数难以得到保证（残留的内存可能泄漏给被调用者），而且调用嵌套时会很快耗尽 1024 项的栈上限。\n\n对合约自身地址的 `CALL` 可以为每个内部函数提供全新的内存和栈，而在编译器复杂度方面不需要任何代价。但当时所有类型的调用都要 700 gas，这是 [EIP-150](/eip-150/) 设定的，主要用来支付从磁盘加载另一个合约代码的开销。对*自己*的调用不需要这样的加载，因为代码已经在内存中了。\n\n## 它如何运作\n\n在分叉区块之后，当且仅当目标地址等于当前合约的地址时，`CALL`、`DELEGATECALL`、`CALLCODE` 和 `STATICCALL` 的费用将是 **40 gas 而不是 700**。\n\n作者的理由是：在 EIP-150 之前，这些调用的费用是 40。EIP-150 为磁盘 I/O 增加了大约 660。由于自调用不会进行新的 I/O，原来的 40 对于为已加载的代码启动一个新的虚拟机实例来说是公平的价格。\n\n调用的其他方面保持不变（value 转账费用、内存扩展、63/64 gas 规则）。\n\n## 示例代码\n\n如果自调用很便宜，编译器可能为内部函数生成的代码，用 Solidity 展示如下：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract SelfCall {\n    // Today: internal call compiled to JUMP, shares memory with the caller.\n    function _double(uint256 x) internal pure returns (uint256) { return x * 2; }\n\n    // Style EIP-1380 aimed to make cheap: a fresh EVM frame via call-to-self.\n    function doubleExt(uint256 x) external pure returns (uint256) { return x * 2; }\n\n    function viaSelfCall(uint256 x) external view returns (uint256) {\n        (bool ok, bytes memory out) =\n            address(this).staticcall(abi.encodeCall(this.doubleExt, (x)));\n        require(ok);\n        return abi.decode(out, (uint256));\n    }\n}\n```\n\n用伪代码表示的费用规则：\n\n```python\ndef call_base_cost(caller, target):\n    if block.number \u003e= FORK_BLKNUM and target == caller:\n        return 40\n    return 700\n```\n\n## 需要注意\n\n- 状态为 **Stagnant**；它从未被排入任何硬分叉。\n- 它所针对的定价已不复存在。[EIP-2929](/eip-2929/)（Berlin）用冷/热访问定价取代了统一的 700，在新规则下，交易中已经访问过的地址（包括当前正在执行的合约）按热访问费率 100 gas 收费。\n- 没有主流编译器把内部函数改成自调用；它们仍然使用 `JUMP`。\n- 关于让预编译合约调用更便宜的相关想法是 [EIP-2046](/eip-2046/)。\n"}}}
