---
eip: 7819
label: EIP-7819
title: SETDELEGATE instruction
status: Draft
type: Standards Track
category: Core
created: 2024-11-18
requires: 7702
official: https://eips.ethereum.org/EIPS/eip-7819
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7819.md
canonical: https://eips.huatuo.xyz/eip-7819/
lang: en
tldr: Draft opcode that lets a contract create or update EIP-7702 style delegation accounts at deterministic addresses, a protocol-level alternative to minimal proxies and upgradeable proxies.
tags: [evm, opcode, proxies, clones, account-abstraction]
---

# EIP-7819: SETDELEGATE instruction

> Introduce a new instruction allowing contracts to create clones using EIP-7702 delegation designations

**TL;DR:** Draft opcode that lets a contract create or update EIP-7702 style delegation accounts at deterministic addresses, a protocol-level alternative to minimal proxies and upgradeable proxies.

## What problem does it solve?

Many apps deploy the same code over and over: smart-account wallets, vaults, per-user contracts. To save gas they deploy small proxies:

- [ERC-1167](/eip-1167/) clones hard-code the implementation address. Cheap, but never upgradable.
- Upgradeable proxies such as [ERC-1967](/eip-1967/) read the implementation from storage. Flexible, but every call pays for a storage read and the proxy is larger (~708 bytes for OpenZeppelin's).

Both forward calls in EVM code, copying calldata to memory and calling `DELEGATECALL`. [EIP-7702](/eip-7702/) already added a protocol-native redirect for EOAs: a 23-byte **delegation indicator** (`0xef0100 ++ address`). EIP-7819 lets contracts create the same object for new addresses.

## How it works

A new instruction `SETDELEGATE` at `0xf6`:

1. Charges `EMPTY_ACCOUNT_COST` (25,000 gas); fails in a static call.
2. Pops `salt` and `target`.
3. Computes `location = keccak256(0xef0100 ++ caller ++ salt)[12:]`, so each caller and salt pair always maps to the same address.
4. Fails if `location` already has code that is not a delegation indicator.
5. Writes `0xef0100 ++ target` as the code at `location`. If `target` is zero, the code is cleared instead.
6. Sets the nonce to 1 if it was 0, so the account never counts as empty.
7. Refunds `EMPTY_ACCOUNT_COST - BASE_COST` (12,500) if the account already existed, and pushes `location`.

The result behaves exactly like an EIP-7702 delegated account: calls to `location` run `target`'s code in `location`'s storage context. The calling factory can call `SETDELEGATE` again with the same salt to point to a new target (upgrade) or to zero (remove). Whether that is allowed is up to the factory's own logic. The 55-byte preimage cannot collide with `CREATE` or `CREATE2` addresses.

## Sample code

A factory written against the proposed opcode. Solidity has no built-in for it yet, so this is illustrative:

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

contract AccountFactory {
    address public owner = msg.sender;
    mapping(bytes32 => bool) public locked;

    function deploy(bytes32 salt, address impl, bytes calldata init) external returns (address acct) {
        // acct = setdelegate(salt, impl)   // hypothetical opcode 0xf6
        // Initialise atomically in the same call to avoid front-running:
        // (bool ok,) = acct.call(init); require(ok);
    }

    function upgrade(bytes32 salt, address newImpl) external {
        require(msg.sender == owner && !locked[salt], "not allowed");
        // setdelegate(salt, newImpl)       // same salt => same address, new target
    }

    function lock(bytes32 salt) external {
        require(msg.sender == owner);
        locked[salt] = true;                // factory-level immutability
    }
}
```

## Things to know

- Status is **Draft**; it requires [EIP-7702](/eip-7702/) and is not scheduled for a fork.
- Gas parameters are copied from EIP-7702 for simplicity; the authors note the real cost could be lower.
- Delegation chains are not followed (as in 7702). A factory should check that `target` is not itself a delegation indicator.
- These accounts cannot be removed with `SELFDESTRUCT`; only the creating contract can clear them via a zero target.
- Changing the target several times inside one transaction means the same address can run different code within that transaction, much like an upgradeable proxy changing its implementation slot.
- Motivation includes [ERC-4337](/eip-4337/) smart accounts and the account deployments implied by [EIP-8141](/eip-8141/).


---

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