---
eip: 7851
label: EIP-7851
title: Code-Controlled EOA Delegation
status: Draft
type: Standards Track
category: Core
created: 2024-12-27
requires: 7702
official: https://eips.ethereum.org/EIPS/eip-7851
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7851.md
canonical: https://eips.huatuo.xyz/eip-7851/
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]
---

# EIP-7851: Code-Controlled EOA Delegation

> Allow EIP-7702 delegated EOAs to update delegation through code while permanently disabling residual ECDSA authority.

**TL;DR:** Extends EIP-7702 with a SETSELFDELEGATE opcode that lets wallet code change its own delegation and permanently disable the account's original private key.

## What problem does it solve?

[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.

EIP-7851 lets the wallet code itself take over the delegation lifecycle and, in the process, permanently switch off the original key.

## How it works

- **New indicator `0xef0101 || delegate_address`** = "ECDSA-disabled delegation". Code execution treats it exactly like `0xef0100`.
- **`SETSELFDELEGATE(delegate_address)`** opcode (byte TBD, 9500 gas). It acts only on the current execution-context address (the account running the code):
  1. if `delegate_address` is zero: push `0`, no change;
  2. if the account's raw code is exactly 23 bytes starting with `0xef0100` or `0xef0101`: set it to `0xef0101 || delegate_address`, push `1`;
  3. otherwise: push `0`, no change.
  It halts exceptionally in a static context, and a revert rolls the change back.
- **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.

So 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.

## Sample code

Wallet code exposing the operation behind its own authorization (Solidity with a hypothetical opcode; no compiler supports it yet):

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract Wallet {
    function upgradeAndLockKey(address newImpl) external {
        require(msg.sender == address(this), "only self");     // e.g. via a 7821 batch
        _requireUserConfirmed();                                // passkey / multisig check
        bool ok;
        assembly {
            // ok := setselfdelegate(newImpl)   // SETSELFDELEGATE, opcode byte TBD
        }
        require(ok, "not a 7702 delegated account");
    }

    function _requireUserConfirmed() internal view { /* wallet-specific */ }
}
```

Account code before and after:

```text
before: 0xef0100 || <old delegate>   ; key can still sign txs
after:  0xef0101 || <new delegate>   ; key can never sign protocol txs again
```

## Things to know

- **Status: Draft.** The opcode byte is not yet assigned.
- The switch is **irreversible**. Wallets should only expose it after explicit user confirmation and treat it as the highest privilege.
- 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`.
- Existing `0xef0100` delegations are unaffected.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-7851
