{"eip":8151,"title":"Account Code Restricted ecRecover","description":"Restrict ecRecover results to accounts with empty code or a delegation indicator","authors":["Liyi Guo (@colinlyguo)","Nicolas Consigny (@nconsigny)"],"status":"Draft","type":"Standards Track","category":"Core","created":"2026-02-09","requires":[3607,7702,8038],"discussionsTo":"https://ethereum-magicians.org/t/eip-8151-account-code-restricted-ecrecover/27690","repo":"EIPs","label":"EIP-8151","officialUrl":"https://eips.ethereum.org/EIPS/eip-8151","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-8151.md","url":"https://eips.huatuo.xyz/eip-8151/","tldr":{"en":"Makes the ecRecover precompile refuse to return an address whose account now holds real contract code, so an old ECDSA key cannot keep authorizing permits after an account migrates to post-quantum control.","ja":"ecRecover プリコンパイルが、アカウントが実際のコントラクトコードを保持するようになったアドレスを返さないようにする。これにより、アカウントがポスト量子の制御に移行した後も、古い ECDSA 鍵で permit を承認し続けることはできなくなる。","ko":"ecRecover 프리컴파일이 이제 실제 컨트랙트 코드를 가진 계정의 주소를 반환하지 않게 하여, 계정이 양자 내성 제어로 마이그레이션한 뒤에는 예전 ECDSA 키가 permit을 계속 승인하지 못하도록 한다.","zh":"让 ecRecover 预编译拒绝返回如今持有真实合约代码的账户地址，这样在账户迁移到后量子控制之后，旧的 ECDSA 密钥就无法继续授权 permit。"},"tags":["precompile","ecrecover","post-quantum","signatures","core"],"explainers":{"en":{"lang":"en","tldr":"Makes the ecRecover precompile refuse to return an address whose account now holds real contract code, so an old ECDSA key cannot keep authorizing permits after an account migrates to post-quantum control.","tags":["precompile","ecrecover","post-quantum","signatures","core"],"related":[3607,7702,8038,2612,7928],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-8151/","markdown":"## What problem does it solve?\n\nWith [EIP-7702](/eip-7702/) an ordinary account (EOA) can install code. One proposed path to post-quantum security is for an EOA to migrate to code that checks a quantum-safe signature instead. Once the account's code is no longer a plain 7702 delegation, [EIP-3607](/eip-3607/) already stops the old ECDSA key from sending transactions.\n\nBut the `ecRecover` precompile (address `0x01`) does not look at state. Any contract that authorizes actions with `ecRecover`, most notably ERC-20 `permit` ([ERC-2612](/eip-2612/)), would still accept a signature from the old key. An attacker who derives that key with a quantum computer could drain tokens through permits. Many of those contracts are immutable, so the fix has to happen in the protocol.\n\n## How it works\n\nAfter recovering an address from `(hash, v, r, s)`, `ecRecover` now reads that address's **raw** account code (it does not follow a delegation):\n\n- code is empty, or exactly the 23-byte 7702 delegation `0xef0100 || delegate` → return the address as before;\n- anything else → return **empty output** with `success = 1`, exactly what it already returns for a bad signature.\n\nEmpty output (not 32 zero bytes, not a revert) was chosen so existing callers treat a blocked account the same as an invalid signature and do not accidentally match the zero address.\n\nGas changes on successful recovery, because the precompile now reads state with [EIP-8038](/eip-8038/) pricing:\n\n| Case | Old | New |\n| --- | --- | --- |\n| Recovery fails | 3000 | 3000 |\n| Success, address cold | 3000 | 6100 (3000 + 3000 cold access + 100 code read) |\n| Success, address warm | 3000 | 3200 (3000 + 100 + 100) |\n\nThe address is added to the warm set after the fee is paid, and with [EIP-7928](/eip-7928/) block access lists the read is recorded even if the check rejects it or an outer call reverts.\n\n## Sample code\n\nThe account check, from the reference implementation:\n\n```python\nDELEGATION_PREFIX = b\"\\xef\\x01\\x00\"\n\ndef permits_ecrecover(state, recovered_address) -\u003e bool:\n    code = state.get_raw_code(recovered_address)   # absent account == empty code\n    return len(code) == 0 or (len(code) == 23 and code[:3] == DELEGATION_PREFIX)\n```\n\nA Solidity caller that stays safe under the new rules: forward enough gas and treat zero/empty as failure.\n\n```solidity\nfunction verify(bytes32 h, uint8 v, bytes32 r, bytes32 s, address expected) internal view returns (bool) {\n    require(expected != address(0), \"zero signer\");\n    address signer = ecrecover(h, v, r, s); // returns address(0) on empty output\n    return signer == expected;\n}\n```\n\n## Things to know\n\n- **Status: Draft.** Details, including gas costs, may still change.\n- **Fixed-gas callers break.** Code like `staticcall(3000, 0x01, ...)` will run out of gas on every *valid* signature after activation, and raising the transaction gas limit does not help. Libraries and contracts that hard-code 3000 gas need review.\n- Only the precompile is affected. ECDSA recovery written in pure Solidity or other application code bypasses the check.\n- `ecRecover` stops being a pure function of its input. L2s and fault-proof systems that re-execute it elsewhere must apply the code check against their own state, or use a separate secp256k1 implementation.\n- Contracts that already fail to reject `address(0)` from `ecrecover` remain vulnerable to invalid signatures, as they are today.\n"},"ja":{"lang":"ja","tldr":"ecRecover プリコンパイルが、アカウントが実際のコントラクトコードを保持するようになったアドレスを返さないようにする。これにより、アカウントがポスト量子の制御に移行した後も、古い ECDSA 鍵で permit を承認し続けることはできなくなる。","tags":["precompile","ecrecover","post-quantum","signatures","core"],"related":[3607,7702,8038,2612,7928],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-8151/","markdown":"## 何を解決するのか\n\n[EIP-7702](/eip-7702/) により、通常のアカウント（EOA）にコードをインストールできます。ポスト量子セキュリティへの提案されている道筋の 1 つは、EOA が代わりに量子安全な署名を検証するコードへ移行することです。アカウントのコードが単なる 7702 のデリゲーションでなくなると、[EIP-3607](/eip-3607/) によってすでに古い ECDSA 鍵からのトランザクション送信は止められます。\n\nしかし `ecRecover` プリコンパイル（アドレス `0x01`）は状態を参照しません。`ecRecover` でアクションを承認するコントラクト、とりわけ ERC-20 の `permit`（[ERC-2612](/eip-2612/)）は、古い鍵による署名を依然として受け入れてしまいます。量子コンピューターでその鍵を導出した攻撃者は、permit を通じてトークンを抜き取れる可能性があります。そうしたコントラクトの多くはイミュータブルなので、修正はプロトコル側で行う必要があります。\n\n## 仕組み\n\n`(hash, v, r, s)` からアドレスを復元した後、`ecRecover` はそのアドレスの**生の**アカウントコードを読み取ります（デリゲーションは辿りません）。\n\n- コードが空、またはちょうど 23 バイトの 7702 デリゲーション `0xef0100 || delegate` である場合 → 従来どおりアドレスを返します。\n- それ以外 → `success = 1` で**空の出力**を返します。これは不正な署名に対して既にこのプリコンパイルが返しているものと同じです。\n\n既存の呼び出し側がブロックされたアカウントを不正な署名と同じように扱い、誤ってゼロアドレスと一致しないようにするため、空の出力（32 バイトのゼロでもリバートでもなく）が選ばれました。\n\nプリコンパイルが [EIP-8038](/eip-8038/) の価格設定で状態を読むようになるため、復元に成功した場合のガスが変わります。\n\n| ケース | 従来 | 新 |\n| --- | --- | --- |\n| 復元に失敗 | 3000 | 3000 |\n| 成功、アドレスが cold | 3000 | 6100（3000 + cold アクセス 3000 + コード読み取り 100） |\n| 成功、アドレスが warm | 3000 | 3200（3000 + 100 + 100） |\n\nアドレスは料金の支払い後に warm セットへ追加され、[EIP-7928](/eip-7928/) のブロックアクセスリストでは、チェックで拒否された場合や外側の呼び出しがリバートした場合でも、その読み取りは記録されます。\n\n## サンプルコード\n\nリファレンス実装のアカウントチェック:\n\n```python\nDELEGATION_PREFIX = b\"\\xef\\x01\\x00\"\n\ndef permits_ecrecover(state, recovered_address) -\u003e bool:\n    code = state.get_raw_code(recovered_address)   # absent account == empty code\n    return len(code) == 0 or (len(code) == 23 and code[:3] == DELEGATION_PREFIX)\n```\n\n新しいルールの下でも安全な Solidity の呼び出し側: 十分なガスを渡し、ゼロまたは空を失敗として扱います。\n\n```solidity\nfunction verify(bytes32 h, uint8 v, bytes32 r, bytes32 s, address expected) internal view returns (bool) {\n    require(expected != address(0), \"zero signer\");\n    address signer = ecrecover(h, v, r, s); // returns address(0) on empty output\n    return signer == expected;\n}\n```\n\n## 知っておくべきこと\n\n- **ステータス: Draft。** ガスコストを含む詳細は今後も変わる可能性があります。\n- **ガスを固定している呼び出し側は壊れます。** `staticcall(3000, 0x01, ...)` のようなコードは、有効化後は*有効な*署名のたびにガス切れになり、トランザクションのガスリミットを上げても解決しません。3000 gas をハードコードしているライブラリやコントラクトは見直しが必要です。\n- 影響を受けるのはプリコンパイルだけです。純粋な Solidity やその他のアプリケーションコードで書かれた ECDSA の復元は、このチェックを迂回します。\n- `ecRecover` は入力だけの純粋関数ではなくなります。これを別の場所で再実行する L2 やフォールトプルーフのシステムは、自身の状態に対してコードチェックを適用するか、別の secp256k1 実装を使う必要があります。\n- `ecrecover` が返す `address(0)` を既に拒否していないコントラクトは、現在と同じく、不正な署名に対して脆弱なままです。\n"},"ko":{"lang":"ko","tldr":"ecRecover 프리컴파일이 이제 실제 컨트랙트 코드를 가진 계정의 주소를 반환하지 않게 하여, 계정이 양자 내성 제어로 마이그레이션한 뒤에는 예전 ECDSA 키가 permit을 계속 승인하지 못하도록 한다.","tags":["precompile","ecrecover","post-quantum","signatures","core"],"related":[3607,7702,8038,2612,7928],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-8151/","markdown":"## 어떤 문제를 해결하나요?\n\n[EIP-7702](/eip-7702/)를 쓰면 일반 계정(EOA)이 코드를 설치할 수 있습니다. 제안된 양자 내성 보안 경로 중 하나는 EOA가 양자 안전 서명을 대신 검사하는 코드로 마이그레이션하는 것입니다. 계정의 코드가 단순한 7702 위임이 아니게 되면 [EIP-3607](/eip-3607/)이 이미 예전 ECDSA 키의 트랜잭션 전송을 막습니다.\n\n하지만 `ecRecover` 프리컴파일(주소 `0x01`)은 상태를 보지 않습니다. `ecRecover`로 동작을 승인하는 모든 컨트랙트, 특히 ERC-20 `permit`([ERC-2612](/eip-2612/))은 여전히 예전 키의 서명을 받아들입니다. 양자 컴퓨터로 그 키를 도출한 공격자는 permit을 통해 토큰을 빼낼 수 있습니다. 그런 컨트랙트 중 상당수는 불변이어서 수정은 프로토콜에서 이루어져야 합니다.\n\n## 어떻게 동작하나요?\n\n`(hash, v, r, s)`로 주소를 복구한 뒤 `ecRecover`는 이제 그 주소의 **원본** 계정 코드를 읽습니다(위임을 따라가지 않습니다).\n\n- 코드가 비어 있거나 정확히 23바이트의 7702 위임 `0xef0100 || delegate`이면 → 예전처럼 주소를 반환합니다.\n- 그 밖의 경우 → `success = 1`과 함께 **빈 출력**을 반환합니다. 이는 잘못된 서명에 대해 이미 반환하는 것과 똑같습니다.\n\n기존 호출자가 차단된 계정을 잘못된 서명과 똑같이 처리하고 실수로 제로 주소와 일치시키지 않도록, 빈 출력(32바이트의 0도, 리버트도 아님)이 선택되었습니다.\n\n프리컴파일이 이제 [EIP-8038](/eip-8038/)의 가격 책정으로 상태를 읽기 때문에 복구 성공 시 가스가 바뀝니다.\n\n| 경우 | 기존 | 신규 |\n| --- | --- | --- |\n| 복구 실패 | 3000 | 3000 |\n| 성공, 주소가 cold | 3000 | 6100(3000 + cold 접근 3000 + 코드 읽기 100) |\n| 성공, 주소가 warm | 3000 | 3200(3000 + 100 + 100) |\n\n주소는 수수료를 낸 뒤에 warm 집합에 추가되며, [EIP-7928](/eip-7928/) 블록 접근 목록에서는 검사에서 거부되거나 바깥 호출이 리버트되더라도 그 읽기가 기록됩니다.\n\n## 샘플 코드\n\n레퍼런스 구현의 계정 검사:\n\n```python\nDELEGATION_PREFIX = b\"\\xef\\x01\\x00\"\n\ndef permits_ecrecover(state, recovered_address) -\u003e bool:\n    code = state.get_raw_code(recovered_address)   # absent account == empty code\n    return len(code) == 0 or (len(code) == 23 and code[:3] == DELEGATION_PREFIX)\n```\n\n새 규칙에서도 안전한 Solidity 호출자: 충분한 가스를 전달하고 0 또는 빈 값을 실패로 취급합니다.\n\n```solidity\nfunction verify(bytes32 h, uint8 v, bytes32 r, bytes32 s, address expected) internal view returns (bool) {\n    require(expected != address(0), \"zero signer\");\n    address signer = ecrecover(h, v, r, s); // returns address(0) on empty output\n    return signer == expected;\n}\n```\n\n## 알아둘 점\n\n- **상태: Draft.** 가스 비용을 포함한 세부 사항은 아직 바뀔 수 있습니다.\n- **가스를 고정한 호출자는 깨집니다.** `staticcall(3000, 0x01, ...)` 같은 코드는 활성화 후 *유효한* 서명마다 가스가 부족해지며, 트랜잭션 가스 한도를 올려도 소용없습니다. 3000 gas를 하드코딩한 라이브러리와 컨트랙트는 검토가 필요합니다.\n- 영향을 받는 것은 프리컴파일뿐입니다. 순수 Solidity나 다른 애플리케이션 코드로 작성한 ECDSA 복구는 이 검사를 우회합니다.\n- `ecRecover`는 더 이상 입력만의 순수 함수가 아닙니다. 이를 다른 곳에서 다시 실행하는 L2와 폴트 프루프 시스템은 자체 상태에 대해 코드 검사를 적용하거나 별도의 secp256k1 구현을 써야 합니다.\n- `ecrecover`가 반환하는 `address(0)`을 이미 거부하지 않는 컨트랙트는 현재와 마찬가지로 잘못된 서명에 계속 취약합니다.\n"},"zh":{"lang":"zh","tldr":"让 ecRecover 预编译拒绝返回如今持有真实合约代码的账户地址，这样在账户迁移到后量子控制之后，旧的 ECDSA 密钥就无法继续授权 permit。","tags":["precompile","ecrecover","post-quantum","signatures","core"],"related":[3607,7702,8038,2612,7928],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-8151/","markdown":"## 它解决什么问题？\n\n借助 [EIP-7702](/eip-7702/)，普通账户（EOA）可以安装代码。一条被提出的后量子安全路径是让 EOA 迁移到改为验证抗量子签名的代码。一旦账户的代码不再只是普通的 7702 委托，[EIP-3607](/eip-3607/) 就已经阻止旧的 ECDSA 密钥发送交易。\n\n但是 `ecRecover` 预编译（地址 `0x01`）不会查看状态。任何用 `ecRecover` 授权操作的合约，最典型的是 ERC-20 `permit`（[ERC-2612](/eip-2612/)），仍然会接受旧密钥的签名。用量子计算机推导出该密钥的攻击者可以通过 permit 转走代币。其中许多合约是不可变的，所以修复必须在协议层完成。\n\n## 它如何运作\n\n从 `(hash, v, r, s)` 恢复出地址之后，`ecRecover` 现在会读取该地址的**原始**账户代码（不会跟随委托）：\n\n- 代码为空，或恰好是 23 字节的 7702 委托 `0xef0100 || delegate` → 像以前一样返回该地址；\n- 其他任何情况 → 返回**空输出**，且 `success = 1`，这与它对错误签名已有的返回完全一致。\n\n选择空输出（而不是 32 个零字节，也不是回滚），是为了让现有的调用方把被阻止的账户当作无效签名处理，而不会意外匹配到零地址。\n\n成功恢复时的 gas 会发生变化，因为预编译现在按 [EIP-8038](/eip-8038/) 的定价读取状态：\n\n| 情形 | 旧 | 新 |\n| --- | --- | --- |\n| 恢复失败 | 3000 | 3000 |\n| 成功，地址为冷 | 3000 | 6100（3000 + 3000 冷访问 + 100 读取代码） |\n| 成功，地址为热 | 3000 | 3200（3000 + 100 + 100） |\n\n地址在支付费用之后才被加入热集合；在 [EIP-7928](/eip-7928/) 的区块访问列表中，即使检查拒绝了它或外层调用回滚，这次读取也会被记录。\n\n## 示例代码\n\n参考实现中的账户检查：\n\n```python\nDELEGATION_PREFIX = b\"\\xef\\x01\\x00\"\n\ndef permits_ecrecover(state, recovered_address) -\u003e bool:\n    code = state.get_raw_code(recovered_address)   # absent account == empty code\n    return len(code) == 0 or (len(code) == 23 and code[:3] == DELEGATION_PREFIX)\n```\n\n在新规则下仍然安全的 Solidity 调用方：转发足够的 gas，并把零/空视为失败。\n\n```solidity\nfunction verify(bytes32 h, uint8 v, bytes32 r, bytes32 s, address expected) internal view returns (bool) {\n    require(expected != address(0), \"zero signer\");\n    address signer = ecrecover(h, v, r, s); // returns address(0) on empty output\n    return signer == expected;\n}\n```\n\n## 需要注意\n\n- **状态：Draft。** 包括 gas 成本在内的细节仍可能改变。\n- **固定 gas 的调用方会失效。** 像 `staticcall(3000, 0x01, ...)` 这样的代码在激活后，每遇到一个*有效*签名都会耗尽 gas，提高交易的 gas 上限也无济于事。硬编码 3000 gas 的库和合约需要审查。\n- 只有预编译受影响。用纯 Solidity 或其他应用代码编写的 ECDSA 恢复会绕过这一检查。\n- `ecRecover` 不再是其输入的纯函数。在别处重新执行它的 L2 和故障证明系统，必须针对自身状态应用代码检查，或使用单独的 secp256k1 实现。\n- 本来就没有拒绝 `ecrecover` 返回的 `address(0)` 的合约，仍然像现在一样容易受到无效签名的攻击。\n"}}}
