{"eip":7851,"title":"Code-Controlled EOA Delegation","description":"Allow EIP-7702 delegated EOAs to update delegation through code while permanently disabling residual ECDSA authority.","authors":["Liyi Guo (@colinlyguo)","Nicolas Consigny (@nconsigny)"],"status":"Draft","type":"Standards Track","category":"Core","created":"2024-12-27","requires":[7702],"discussionsTo":"https://ethereum-magicians.org/t/eip-7851-code-controlled-eoa-delegation/22344","repo":"EIPs","label":"EIP-7851","officialUrl":"https://eips.ethereum.org/EIPS/eip-7851","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7851.md","url":"https://eips.huatuo.xyz/eip-7851/","tldr":{"en":"Extends EIP-7702 with a SETSELFDELEGATE opcode that lets wallet code change its own delegation and permanently disable the account's original private key.","ja":"EIP-7702 を拡張し、ウォレットのコードが自身の委任を変更し、アカウントの元の秘密鍵を恒久的に無効化できる SETSELFDELEGATE opcode を追加する。","ko":"EIP-7702를 확장해 SETSELFDELEGATE opcode를 추가한다. 지갑 코드가 스스로의 위임을 바꾸고 계정의 원래 개인 키를 영구적으로 비활성화할 수 있게 한다.","zh":"扩展 EIP-7702，新增 SETSELFDELEGATE opcode，使钱包代码能够更改自身的委托，并永久禁用该账户原来的私钥。"},"tags":["eip-7702","account-abstraction","eoa","opcode","security"],"explainers":{"en":{"lang":"en","tldr":"Extends EIP-7702 with a SETSELFDELEGATE opcode that lets wallet code change its own delegation and permanently disable the account's original private key.","tags":["eip-7702","account-abstraction","eoa","opcode","security"],"related":[7702,8151,7821],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-7851/","markdown":"## What problem does it solve?\n\n[EIP-7702](/eip-7702/) lets an EOA point to smart-contract code via a delegation indicator `0xef0100 || delegate_address`. The account can then use passkeys, multisig, social recovery or modules. But the original secp256k1 private key never loses its power: it can still sign transactions and re-delegate the account. If that key leaks, the smart-wallet protections are bypassed.\n\nEIP-7851 lets the wallet code itself take over the delegation lifecycle and, in the process, permanently switch off the original key.\n\n## How it works\n\n- **New indicator `0xef0101 || delegate_address`** = \"ECDSA-disabled delegation\". Code execution treats it exactly like `0xef0100`.\n- **`SETSELFDELEGATE(delegate_address)`** opcode (byte TBD, 9500 gas). It acts only on the current execution-context address (the account running the code):\n  1. if `delegate_address` is zero: push `0`, no change;\n  2. if the account's raw code is exactly 23 bytes starting with `0xef0100` or `0xef0101`: set it to `0xef0101 || delegate_address`, push `1`;\n  3. otherwise: push `0`, no change.\n  It halts exceptionally in a static context, and a revert rolls the change back.\n- **Validation rules.** Once an account has `0xef0101` code, any transaction signed by its ECDSA key is invalid and must be rejected by mempools, and any EIP-7702 authorization it signs is skipped.\n\nSo the first successful call permanently disables ECDSA authority; later calls can switch to a new delegate implementation, but the key never comes back. The gas cost is EIP-7702's per-authorization base cost minus the 3000 gas for signature recovery.\n\n## Sample code\n\nWallet code exposing the operation behind its own authorization (Solidity with a hypothetical opcode; no compiler supports it yet):\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\ncontract Wallet {\n    function upgradeAndLockKey(address newImpl) external {\n        require(msg.sender == address(this), \"only self\");     // e.g. via a 7821 batch\n        _requireUserConfirmed();                                // passkey / multisig check\n        bool ok;\n        assembly {\n            // ok := setselfdelegate(newImpl)   // SETSELFDELEGATE, opcode byte TBD\n        }\n        require(ok, \"not a 7702 delegated account\");\n    }\n\n    function _requireUserConfirmed() internal view { /* wallet-specific */ }\n}\n```\n\nAccount code before and after:\n\n```text\nbefore: 0xef0100 || \u003cold delegate\u003e   ; key can still sign txs\nafter:  0xef0101 || \u003cnew delegate\u003e   ; key can never sign protocol txs again\n```\n\n## Things to know\n\n- **Status: Draft.** The opcode byte is not yet assigned.\n- The switch is **irreversible**. Wallets should only expose it after explicit user confirmation and treat it as the highest privilege.\n- It only blocks protocol-level use of the key. Contracts that verify ECDSA signatures themselves (for example token `permit`) will still accept signatures from that key. The companion proposal [EIP-8151](/eip-8151/) addresses `ecrecover`.\n- Existing `0xef0100` delegations are unaffected.\n"},"ja":{"lang":"ja","tldr":"EIP-7702 を拡張し、ウォレットのコードが自身の委任を変更し、アカウントの元の秘密鍵を恒久的に無効化できる SETSELFDELEGATE opcode を追加する。","tags":["eip-7702","account-abstraction","eoa","opcode","security"],"related":[7702,8151,7821],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-7851/","markdown":"## 何を解決するのか\n\n[EIP-7702](/eip-7702/) では、委任インジケーター `0xef0100 || delegate_address` によって EOA がスマートコントラクトのコードを指すようにできます。これによりアカウントは、パスキー、マルチシグ、ソーシャルリカバリー、モジュールを使えるようになります。しかし、元の secp256k1 秘密鍵はその力を失いません。依然としてトランザクションに署名でき、アカウントを再委任できます。その鍵が漏えいすれば、スマートウォレットによる保護は迂回されます。\n\nEIP-7851 は、ウォレットのコード自身が委任のライフサイクルを引き継ぎ、その過程で元の鍵を恒久的に無効化できるようにします。\n\n## 仕組み\n\n- **新しいインジケーター `0xef0101 || delegate_address`** は「ECDSA 無効化委任」を意味します。コードの実行では `0xef0100` とまったく同じように扱われます。\n- **`SETSELFDELEGATE(delegate_address)`** opcode（バイトは未定、9500 ガス）。現在の実行コンテキストのアドレス（コードを実行しているアカウント）にのみ作用します。\n  1. `delegate_address` がゼロなら、`0` をプッシュし、変更なし。\n  2. アカウントの生のコードがちょうど 23 バイトで `0xef0100` または `0xef0101` で始まるなら、`0xef0101 || delegate_address` に設定し、`1` をプッシュ。\n  3. それ以外は、`0` をプッシュし、変更なし。\n  静的コンテキストでは異常終了し、revert すると変更は巻き戻されます。\n- **検証ルール。** アカウントが `0xef0101` のコードを持つと、その ECDSA 鍵で署名されたトランザクションはすべて無効となり、mempool はこれを拒否しなければなりません。また、その鍵が署名した EIP-7702 の authorization はスキップされます。\n\nしたがって、最初の呼び出しが成功した時点で ECDSA の権限は恒久的に無効になります。以降の呼び出しで新しい委任先の実装に切り替えることはできますが、鍵が元に戻ることはありません。ガスコストは、EIP-7702 の authorization あたりの基本コストから、署名復元の 3000 ガスを引いたものです。\n\n## サンプルコード\n\nウォレットが自身の認可の背後でこの操作を公開するコード（仮想の opcode を使った Solidity。まだどのコンパイラもサポートしていません）:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\ncontract Wallet {\n    function upgradeAndLockKey(address newImpl) external {\n        require(msg.sender == address(this), \"only self\");     // e.g. via a 7821 batch\n        _requireUserConfirmed();                                // passkey / multisig check\n        bool ok;\n        assembly {\n            // ok := setselfdelegate(newImpl)   // SETSELFDELEGATE, opcode byte TBD\n        }\n        require(ok, \"not a 7702 delegated account\");\n    }\n\n    function _requireUserConfirmed() internal view { /* wallet-specific */ }\n}\n```\n\n前後でのアカウントのコード:\n\n```text\nbefore: 0xef0100 || \u003cold delegate\u003e   ; key can still sign txs\nafter:  0xef0101 || \u003cnew delegate\u003e   ; key can never sign protocol txs again\n```\n\n## 知っておくべきこと\n\n- **ステータス: Draft。** opcode のバイトはまだ割り当てられていません。\n- この切り替えは**不可逆**です。ウォレットは、ユーザーの明示的な確認の後にのみ公開し、最高権限として扱うべきです。\n- ブロックされるのは、鍵のプロトコルレベルでの利用だけです。自分で ECDSA 署名を検証するコントラクト（たとえばトークンの `permit`）は、その鍵の署名を引き続き受け入れます。関連する提案 [EIP-8151](/eip-8151/) が `ecrecover` を扱っています。\n- 既存の `0xef0100` の委任には影響しません。\n"},"ko":{"lang":"ko","tldr":"EIP-7702를 확장해 SETSELFDELEGATE opcode를 추가한다. 지갑 코드가 스스로의 위임을 바꾸고 계정의 원래 개인 키를 영구적으로 비활성화할 수 있게 한다.","tags":["eip-7702","account-abstraction","eoa","opcode","security"],"related":[7702,8151,7821],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-7851/","markdown":"## 어떤 문제를 해결하나요?\n\n[EIP-7702](/eip-7702/)는 위임 표시자 `0xef0100 || delegate_address`를 통해 EOA가 스마트 컨트랙트 코드를 가리키게 해 줍니다. 그러면 계정은 패스키, 멀티시그, 소셜 복구, 모듈을 사용할 수 있습니다. 하지만 원래의 secp256k1 개인 키는 힘을 잃지 않습니다. 여전히 트랜잭션에 서명하고 계정을 다시 위임할 수 있습니다. 그 키가 유출되면 스마트 지갑의 보호는 우회됩니다.\n\nEIP-7851은 지갑 코드 자체가 위임의 생명주기를 넘겨받고, 그 과정에서 원래 키를 영구적으로 꺼 버릴 수 있게 합니다.\n\n## 어떻게 동작하나요?\n\n- **새 표시자 `0xef0101 || delegate_address`**는 \"ECDSA 비활성화 위임\"을 뜻합니다. 코드 실행에서는 `0xef0100`과 똑같이 취급됩니다.\n- **`SETSELFDELEGATE(delegate_address)`** opcode(바이트 미정, 9500 가스). 현재 실행 컨텍스트의 주소(코드를 실행 중인 계정)에만 작용합니다.\n  1. `delegate_address`가 0이면 `0`을 푸시하고 변경 없음.\n  2. 계정의 원본 코드가 정확히 23바이트이고 `0xef0100` 또는 `0xef0101`로 시작하면 `0xef0101 || delegate_address`로 설정하고 `1`을 푸시.\n  3. 그 외에는 `0`을 푸시하고 변경 없음.\n  정적 컨텍스트에서는 비정상 종료되며, revert되면 변경이 롤백됩니다.\n- **검증 규칙.** 계정이 `0xef0101` 코드를 가지게 되면, 그 ECDSA 키로 서명된 모든 트랜잭션은 무효이며 mempool이 거부해야 합니다. 그 키가 서명한 EIP-7702 authorization도 건너뜁니다.\n\n따라서 첫 번째 호출이 성공하면 ECDSA 권한이 영구적으로 비활성화됩니다. 이후 호출로 새 위임 구현으로 바꿀 수는 있지만 키는 돌아오지 않습니다. 가스 비용은 EIP-7702의 authorization당 기본 비용에서 서명 복구용 3000 가스를 뺀 값입니다.\n\n## 샘플 코드\n\n지갑 코드가 자체 인가 뒤에서 이 동작을 노출하는 예입니다(가상의 opcode를 쓴 Solidity이며, 아직 어떤 컴파일러도 지원하지 않습니다).\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\ncontract Wallet {\n    function upgradeAndLockKey(address newImpl) external {\n        require(msg.sender == address(this), \"only self\");     // e.g. via a 7821 batch\n        _requireUserConfirmed();                                // passkey / multisig check\n        bool ok;\n        assembly {\n            // ok := setselfdelegate(newImpl)   // SETSELFDELEGATE, opcode byte TBD\n        }\n        require(ok, \"not a 7702 delegated account\");\n    }\n\n    function _requireUserConfirmed() internal view { /* wallet-specific */ }\n}\n```\n\n전후의 계정 코드:\n\n```text\nbefore: 0xef0100 || \u003cold delegate\u003e   ; key can still sign txs\nafter:  0xef0101 || \u003cnew delegate\u003e   ; key can never sign protocol txs again\n```\n\n## 알아둘 점\n\n- **상태: Draft.** opcode 바이트는 아직 할당되지 않았습니다.\n- 이 전환은 **되돌릴 수 없습니다**. 지갑은 사용자의 명시적 확인 후에만 이를 노출해야 하며 최고 권한으로 취급해야 합니다.\n- 키의 프로토콜 수준 사용만 막습니다. ECDSA 서명을 직접 검증하는 컨트랙트(예: 토큰의 `permit`)는 그 키의 서명을 여전히 받아들입니다. 함께 제안된 [EIP-8151](/eip-8151/)이 `ecrecover`를 다룹니다.\n- 기존의 `0xef0100` 위임은 영향을 받지 않습니다.\n"},"zh":{"lang":"zh","tldr":"扩展 EIP-7702，新增 SETSELFDELEGATE opcode，使钱包代码能够更改自身的委托，并永久禁用该账户原来的私钥。","tags":["eip-7702","account-abstraction","eoa","opcode","security"],"related":[7702,8151,7821],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-7851/","markdown":"## 它解决什么问题？\n\n[EIP-7702](/eip-7702/) 允许 EOA 通过委托标识符 `0xef0100 || delegate_address` 指向智能合约代码。账户随后可以使用通行密钥（passkey）、多签、社交恢复或模块。但原来的 secp256k1 私钥从未失去效力：它仍然可以签署交易并重新委托账户。如果该密钥泄露，智能钱包的保护就会被绕过。\n\nEIP-7851 让钱包代码自己接管委托的生命周期，并在此过程中永久关闭原来的密钥。\n\n## 它如何运作\n\n- **新标识符 `0xef0101 || delegate_address`** 表示\"禁用 ECDSA 的委托\"。代码执行时对它的处理与 `0xef0100` 完全相同。\n- **`SETSELFDELEGATE(delegate_address)`** opcode（字节待定，9500 gas）。它只作用于当前执行上下文的地址（即正在运行该代码的账户）：\n  1. 如果 `delegate_address` 为零：压入 `0`，不做任何更改；\n  2. 如果账户的原始代码恰好是 23 字节，且以 `0xef0100` 或 `0xef0101` 开头：将其设置为 `0xef0101 || delegate_address`，压入 `1`；\n  3. 否则：压入 `0`，不做任何更改。\n  在静态上下文中它会异常终止，而 revert 会回滚该更改。\n- **验证规则。** 账户一旦拥有 `0xef0101` 代码，任何由其 ECDSA 密钥签署的交易都是无效的，mempool 必须拒绝；它签署的任何 EIP-7702 授权也会被跳过。\n\n因此，第一次成功调用就会永久禁用 ECDSA 权限；之后的调用可以切换到新的委托实现，但密钥再也不会恢复。其 gas 成本是 EIP-7702 中每个授权的基础成本减去用于签名恢复的 3000 gas。\n\n## 示例代码\n\n钱包代码在自身授权之后暴露该操作（使用一个假设的 opcode 的 Solidity；目前还没有编译器支持）：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\ncontract Wallet {\n    function upgradeAndLockKey(address newImpl) external {\n        require(msg.sender == address(this), \"only self\");     // e.g. via a 7821 batch\n        _requireUserConfirmed();                                // passkey / multisig check\n        bool ok;\n        assembly {\n            // ok := setselfdelegate(newImpl)   // SETSELFDELEGATE, opcode byte TBD\n        }\n        require(ok, \"not a 7702 delegated account\");\n    }\n\n    function _requireUserConfirmed() internal view { /* wallet-specific */ }\n}\n```\n\n账户代码前后对比：\n\n```text\nbefore: 0xef0100 || \u003cold delegate\u003e   ; key can still sign txs\nafter:  0xef0101 || \u003cnew delegate\u003e   ; key can never sign protocol txs again\n```\n\n## 需要注意\n\n- **状态：Draft。** opcode 字节尚未分配。\n- 这一切换是**不可逆的**。钱包只应在用户明确确认之后才暴露该功能，并将其视为最高权限。\n- 它只阻止密钥在协议层面的使用。自己验证 ECDSA 签名的合约（例如代币的 `permit`）仍会接受该密钥的签名。配套提案 [EIP-8151](/eip-8151/) 处理的是 `ecrecover`。\n- 现有的 `0xef0100` 委托不受影响。\n"}}}
