{"eip":7637,"title":"Optimize EOA EXTCODEHASH","description":"Modify the output value of EXTCODEHASH for EOA accounts to `0x`","authors":["Jame (@ZWJKFLC)"],"status":"Stagnant","type":"Standards Track","category":"Core","created":"2024-02-26","requires":[1052],"discussionsTo":"https://ethereum-magicians.org/t/eip-7637-extcodehash-optimize/18946","repo":"EIPs","label":"EIP-7637","officialUrl":"https://eips.ethereum.org/EIPS/eip-7637","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7637.md","url":"https://eips.huatuo.xyz/eip-7637/","tldr":{"en":"Proposed making EXTCODEHASH return 0 for any account with no code, instead of keccak256(\"\") for code-less accounts that hold a balance, so 'codehash == 0' becomes a safe, cheap 'is there no contract here?' check.","ja":"コードを持たないアカウントについて、残高があっても keccak256(\"\") ではなく、EXTCODEHASH が 0 を返すようにすることを提案している。これにより「codehash == 0」が、「ここにコントラクトはないか」を安全かつ安価に確認する方法になる。","ko":"코드가 없는 모든 계정에 대해 EXTCODEHASH가 0을 반환하도록 제안한다. 잔액이 있는 코드 없는 계정에 keccak256(\"\")을 반환하는 대신, \"codehash == 0\"이 \"여기에 컨트랙트가 없는가?\"를 확인하는 안전하고 저렴한 방법이 되게 한다.","zh":"提议让 EXTCODEHASH 对任何没有代码的账户都返回 0，而不是对持有余额的无代码账户返回 keccak256(\"\")，这样\"codehash == 0\"就成了一种安全又廉价的\"这里没有合约吗？\"检查方式。"},"tags":["evm","opcodes","extcodehash","core"],"explainers":{"en":{"lang":"en","tldr":"Proposed making EXTCODEHASH return 0 for any account with no code, instead of keccak256(\"\") for code-less accounts that hold a balance, so 'codehash == 0' becomes a safe, cheap 'is there no contract here?' check.","tags":["evm","opcodes","extcodehash","core"],"related":[1052,161,1014,7702],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-7637/","markdown":"## What problem does it solve?\n\n[EIP-1052](/eip-1052/) added `EXTCODEHASH`, which returns the hash of an account's code more cheaply than copying it. Its rules give two different answers for \"no code\":\n\n- `0` if the account does not exist or is *empty* (in the [EIP-161](/eip-161/) sense: no code, zero balance, zero nonce),\n- `keccak256(\"\")` = `0xc5d2…a470` if the account exists but has no code, for example an address that has received ETH.\n\nThat distinction surprises developers. Contract addresses can be predicted in advance (especially with [CREATE2](/eip-1014/)), and anyone can send a little ETH to an address before a contract is deployed there. Code that checks `codehash == 0` to mean \"not deployed yet\" then silently gets a different value. As a result, careful contracts fall back to `extcodesize`/`code.length == 0`, and the gas-saving purpose of `EXTCODEHASH` is partly lost.\n\n## How it works\n\nThe proposal changes one rule: if an account has no code, `EXTCODEHASH` returns `0`, regardless of balance. In the spec's execution-specs style reference implementation, after computing the hash, a result equal to `keccak256(\"\")` is replaced with `0`.\n\n| Account | Today | Proposed |\n| --- | --- | --- |\n| Non-existent / empty | `0` | `0` |\n| Exists, no code (e.g. funded address) | `keccak256(\"\")` | `0` |\n| Has code | `keccak256(code)` | `keccak256(code)` |\n\n## Sample code\n\nThe pitfall the proposal targets:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Checker {\n    // Fragile today: returns false if someone sent ETH to `a` before deployment,\n    // because codehash is then keccak256(\"\") instead of 0.\n    function notDeployedFragile(address a) external view returns (bool) {\n        return a.codehash == bytes32(0);\n    }\n\n    // Robust today: treats both \"no account\" and \"account without code\" as not deployed.\n    bytes32 constant EMPTY_CODEHASH = keccak256(\"\");\n    function notDeployed(address a) external view returns (bool) {\n        bytes32 h = a.codehash;\n        return h == bytes32(0) || h == EMPTY_CODEHASH;\n    }\n}\n```\n\nUnder EIP-7637 both functions would give the same answer.\n\n## Things to know\n\n- Status is **Stagnant**; current mainnet behaviour still follows EIP-1052, so write checks like `notDeployed` above.\n- It is a consensus change to an existing opcode. Contracts that use `codehash` to tell \"never touched\" from \"funded but code-less\" addresses would lose that distinction, as the spec notes.\n- The spec motivates the change only in terms of balance; accounts that are non-empty for other reasons (such as a non-zero nonce) are also code-less and would likewise return `0` under the reference implementation.\n- Since [EIP-7702](/eip-7702/), EOAs can carry delegation code, which is another case to consider when reasoning about `EXTCODEHASH` on EOAs.\n"},"ja":{"lang":"ja","tldr":"コードを持たないアカウントについて、残高があっても keccak256(\"\") ではなく、EXTCODEHASH が 0 を返すようにすることを提案している。これにより「codehash == 0」が、「ここにコントラクトはないか」を安全かつ安価に確認する方法になる。","tags":["evm","opcodes","extcodehash","core"],"related":[1052,161,1014,7702],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-7637/","markdown":"## 何を解決するのか\n\n[EIP-1052](/eip-1052/) は `EXTCODEHASH` を追加しました。これはアカウントのコードのハッシュを、コードをコピーするより安価に返します。そのルールでは、「コードなし」に対して 2 つの異なる答えがあります。\n\n- アカウントが存在しない、または*空*（[EIP-161](/eip-161/) の意味で、コードなし・残高ゼロ・nonce ゼロ）の場合は `0`\n- アカウントは存在するがコードがない場合（たとえば ETH を受け取ったアドレス）は `keccak256(\"\")` = `0xc5d2…a470`\n\nこの区別は開発者を驚かせます。コントラクトアドレスは（特に [CREATE2](/eip-1014/) では）事前に予測でき、コントラクトがデプロイされる前に、誰でもそのアドレスに少額の ETH を送れます。`codehash == 0` を「まだデプロイされていない」の意味で確認しているコードは、そのとき気づかないうちに別の値を得ることになります。その結果、慎重なコントラクトは `extcodesize`/`code.length == 0` にフォールバックし、`EXTCODEHASH` のガス節約という目的は一部失われます。\n\n## 仕組み\n\nこの提案は 1 つのルールを変えます。アカウントにコードがなければ、残高に関係なく `EXTCODEHASH` は `0` を返します。仕様の execution-specs スタイルのリファレンス実装では、ハッシュを計算した後、結果が `keccak256(\"\")` に等しければ `0` に置き換えます。\n\n| アカウント | 現在 | 提案後 |\n| --- | --- | --- |\n| 存在しない／空 | `0` | `0` |\n| 存在するがコードなし（例: 入金済みアドレス） | `keccak256(\"\")` | `0` |\n| コードあり | `keccak256(code)` | `keccak256(code)` |\n\n## サンプルコード\n\nこの提案が対象とする落とし穴:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Checker {\n    // Fragile today: returns false if someone sent ETH to `a` before deployment,\n    // because codehash is then keccak256(\"\") instead of 0.\n    function notDeployedFragile(address a) external view returns (bool) {\n        return a.codehash == bytes32(0);\n    }\n\n    // Robust today: treats both \"no account\" and \"account without code\" as not deployed.\n    bytes32 constant EMPTY_CODEHASH = keccak256(\"\");\n    function notDeployed(address a) external view returns (bool) {\n        bytes32 h = a.codehash;\n        return h == bytes32(0) || h == EMPTY_CODEHASH;\n    }\n}\n```\n\nEIP-7637 の下では、両方の関数が同じ答えを返します。\n\n## 知っておくべきこと\n\n- ステータスは **Stagnant** です。現在のメインネットの挙動は引き続き EIP-1052 に従うため、上の `notDeployed` のようなチェックを書いてください。\n- 既存の opcode に対するコンセンサス変更です。仕様が述べているとおり、`codehash` を使って「一度も触れられていない」アドレスと「入金済みだがコードなし」のアドレスを区別しているコントラクトは、その区別を失います。\n- 仕様は残高の観点からのみ変更の動機を述べていますが、他の理由（nonce がゼロでないなど）で空でないアカウントもコードを持たず、リファレンス実装では同様に `0` を返します。\n- [EIP-7702](/eip-7702/) 以降、EOA は委任コードを持てるようになりました。これは EOA に対する `EXTCODEHASH` を考えるときに検討すべき別のケースです。\n"},"ko":{"lang":"ko","tldr":"코드가 없는 모든 계정에 대해 EXTCODEHASH가 0을 반환하도록 제안한다. 잔액이 있는 코드 없는 계정에 keccak256(\"\")을 반환하는 대신, \"codehash == 0\"이 \"여기에 컨트랙트가 없는가?\"를 확인하는 안전하고 저렴한 방법이 되게 한다.","tags":["evm","opcodes","extcodehash","core"],"related":[1052,161,1014,7702],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-7637/","markdown":"## 어떤 문제를 해결하나요?\n\n[EIP-1052](/eip-1052/)는 계정 코드의 해시를 코드를 복사하는 것보다 싸게 반환하는 `EXTCODEHASH`를 추가했습니다. 그 규칙은 \"코드 없음\"에 대해 두 가지 다른 답을 줍니다.\n\n- 계정이 존재하지 않거나 *비어 있으면*([EIP-161](/eip-161/) 의미에서: 코드 없음, 잔액 0, nonce 0) `0`\n- 계정은 존재하지만 코드가 없으면(예: ETH를 받은 주소) `keccak256(\"\")` = `0xc5d2…a470`\n\n이 구분은 개발자를 놀라게 합니다. 컨트랙트 주소는 미리 예측할 수 있고(특히 [CREATE2](/eip-1014/)), 컨트랙트가 배포되기 전에 누구든 그 주소로 소량의 ETH를 보낼 수 있습니다. `codehash == 0`을 \"아직 배포되지 않음\"의 의미로 확인하는 코드는 그러면 조용히 다른 값을 얻게 됩니다. 그 결과 신중한 컨트랙트는 `extcodesize`/`code.length == 0`으로 돌아가고, `EXTCODEHASH`의 가스 절약이라는 목적은 일부 사라집니다.\n\n## 어떻게 동작하나요?\n\n이 제안은 규칙 하나를 바꿉니다. 계정에 코드가 없으면 잔액과 관계없이 `EXTCODEHASH`가 `0`을 반환합니다. 명세의 execution-specs 스타일 참조 구현에서는 해시를 계산한 뒤 결과가 `keccak256(\"\")`과 같으면 `0`으로 바꿉니다.\n\n| 계정 | 현재 | 제안 후 |\n| --- | --- | --- |\n| 존재하지 않음 / 비어 있음 | `0` | `0` |\n| 존재하지만 코드 없음(예: 입금된 주소) | `keccak256(\"\")` | `0` |\n| 코드 있음 | `keccak256(code)` | `keccak256(code)` |\n\n## 샘플 코드\n\n이 제안이 겨냥하는 함정:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Checker {\n    // Fragile today: returns false if someone sent ETH to `a` before deployment,\n    // because codehash is then keccak256(\"\") instead of 0.\n    function notDeployedFragile(address a) external view returns (bool) {\n        return a.codehash == bytes32(0);\n    }\n\n    // Robust today: treats both \"no account\" and \"account without code\" as not deployed.\n    bytes32 constant EMPTY_CODEHASH = keccak256(\"\");\n    function notDeployed(address a) external view returns (bool) {\n        bytes32 h = a.codehash;\n        return h == bytes32(0) || h == EMPTY_CODEHASH;\n    }\n}\n```\n\nEIP-7637 아래에서는 두 함수가 같은 답을 줍니다.\n\n## 알아둘 점\n\n- 상태는 **Stagnant**입니다. 현재 메인넷 동작은 여전히 EIP-1052를 따르므로, 위의 `notDeployed` 같은 확인 코드를 작성하세요.\n- 기존 opcode에 대한 합의 변경입니다. 명세가 언급하듯, `codehash`로 \"한 번도 건드리지 않은\" 주소와 \"입금되었으나 코드 없는\" 주소를 구분하는 컨트랙트는 그 구분을 잃게 됩니다.\n- 명세는 잔액 측면에서만 변경의 동기를 설명하지만, 다른 이유(예: 0이 아닌 nonce)로 비어 있지 않은 계정도 코드가 없고 참조 구현에서는 마찬가지로 `0`을 반환합니다.\n- [EIP-7702](/eip-7702/) 이후 EOA가 위임 코드를 가질 수 있으며, 이는 EOA에 대한 `EXTCODEHASH`를 따질 때 고려할 또 하나의 경우입니다.\n"},"zh":{"lang":"zh","tldr":"提议让 EXTCODEHASH 对任何没有代码的账户都返回 0，而不是对持有余额的无代码账户返回 keccak256(\"\")，这样\"codehash == 0\"就成了一种安全又廉价的\"这里没有合约吗？\"检查方式。","tags":["evm","opcodes","extcodehash","core"],"related":[1052,161,1014,7702],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-7637/","markdown":"## 它解决什么问题？\n\n[EIP-1052](/eip-1052/) 添加了 `EXTCODEHASH`，它返回账户代码的哈希，比复制代码更便宜。它的规则对\"没有代码\"给出两种不同的答案：\n\n- 如果账户不存在或为*空*（按 [EIP-161](/eip-161/) 的含义：没有代码、余额为零、nonce 为零），返回 `0`；\n- 如果账户存在但没有代码，例如一个收到过 ETH 的地址，返回 `keccak256(\"\")` = `0xc5d2…a470`。\n\n这种区别会让开发者感到意外。合约地址可以提前预测（尤其是使用 [CREATE2](/eip-1014/) 时），而且任何人都可以在合约部署之前向某个地址发送少量 ETH。检查 `codehash == 0` 来表示\"尚未部署\"的代码，随后会悄无声息地得到另一个值。结果是，谨慎的合约退而使用 `extcodesize`/`code.length == 0`，`EXTCODEHASH` 节省 gas 的用途也就部分丧失了。\n\n## 它如何运作\n\n该提案只改变一条规则：如果账户没有代码，无论余额多少，`EXTCODEHASH` 都返回 `0`。在规范的 execution-specs 风格参考实现中，计算出哈希之后，等于 `keccak256(\"\")` 的结果会被替换为 `0`。\n\n| 账户 | 现在 | 提案后 |\n| --- | --- | --- |\n| 不存在 / 为空 | `0` | `0` |\n| 存在但无代码（例如已充值的地址） | `keccak256(\"\")` | `0` |\n| 有代码 | `keccak256(code)` | `keccak256(code)` |\n\n## 示例代码\n\n该提案所针对的陷阱：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Checker {\n    // Fragile today: returns false if someone sent ETH to `a` before deployment,\n    // because codehash is then keccak256(\"\") instead of 0.\n    function notDeployedFragile(address a) external view returns (bool) {\n        return a.codehash == bytes32(0);\n    }\n\n    // Robust today: treats both \"no account\" and \"account without code\" as not deployed.\n    bytes32 constant EMPTY_CODEHASH = keccak256(\"\");\n    function notDeployed(address a) external view returns (bool) {\n        bytes32 h = a.codehash;\n        return h == bytes32(0) || h == EMPTY_CODEHASH;\n    }\n}\n```\n\n在 EIP-7637 下，两个函数会给出相同的答案。\n\n## 需要注意\n\n- 状态为 **Stagnant**；当前主网行为仍遵循 EIP-1052，所以请像上面的 `notDeployed` 那样编写检查。\n- 这是对现有 opcode 的共识变更。正如规范所指出的，使用 `codehash` 来区分\"从未被触及\"和\"已充值但无代码\"地址的合约会失去这一区分。\n- 规范只从余额的角度说明变更动机；因其他原因而非空的账户（例如 nonce 非零）同样没有代码，按参考实现同样会返回 `0`。\n- 自 [EIP-7702](/eip-7702/) 起，EOA 可以携带委托代码，这是在分析 EOA 上的 `EXTCODEHASH` 时需要考虑的另一种情况。\n"}}}
