---
eip: 8298
label: EIP-8298
title: SETCODEFROM Code Reuse Instruction
status: Draft
type: Standards Track
category: Core
created: 2026-06-11
requires: 3607, 6780, 7702, 7928, 8037, 8038
official: https://eips.ethereum.org/EIPS/eip-8298
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-8298.md
canonical: https://eips.huatuo.xyz/eip-8298/
lang: en
tldr: "Proposes a SETCODEFROM opcode that lets an account adopt another contract's already-deployed code by copying its code hash, making clones cheap and giving EOAs a one-way path to retire their ECDSA key."
tags: [evm, opcode, code-reuse, account-migration, post-quantum]
---

# EIP-8298: SETCODEFROM Code Reuse Instruction

> Adds an instruction that sets an account's code hash from an existing deployed contract.

**TL;DR:** Proposes a SETCODEFROM opcode that lets an account adopt another contract's already-deployed code by copying its code hash, making clones cheap and giving EOAs a one-way path to retire their ECDSA key.

## What problem does it solve?

**Cheaper clones.** Factories often deploy thousands of contracts with identical runtime code (tokens, wallets, vaults). Each deployment pays code-deposit gas for the same bytes, and that cost rises if state growth is repriced (e.g. [EIP-8037](/eip-8037/)). Minimal proxies ([ERC-1167](/eip-1167/)) avoid this but add a `DELEGATECALL` hop on every call.

**Retiring an EOA's key.** An EOA that wants to move to post-quantum or other wallet logic can use [EIP-7702](/eip-7702/) delegation, but a delegation leaves the old ECDSA key able to send transactions and redelegate. If the account instead holds *regular* code, [EIP-3607](/eip-3607/) makes ECDSA-signed transactions from it invalid and 7702 can no longer redelegate it.

`SETCODEFROM` handles both: initialize your own storage, then adopt shared code that already exists on chain.

## How it works

`SETCODEFROM(source)` (proposed opcode `0xA7`) pops an address and pushes `1` on success or `0` on failure. On success it sets the *current* account's `codeHash` (the one `ADDRESS` returns, even under delegated execution) to `source.codeHash`. A source is valid only if it exists, has non-empty code that does not start with `0xEF`, and was not created in the current transaction.

- It works only on the executing account, never on others. It halts in a static context or when the current account is a system contract.
- The running frame keeps executing the code it already loaded; later calls, `EXTCODEHASH` and so on see the new code. Reverts undo the change.
- In initcode, if the account adopted code, the returned bytes are ignored and **no code-deposit gas** is charged. One creation transaction can write per-instance storage, adopt the template and finish.

Gas (with [EIP-8038](/eip-8038/) parameters) does not depend on code size:

| Result | Cold source | Warm source |
| --- | ---: | ---: |
| Invalid source | 3,100 | 200 |
| Same code hash already | 3,200 | 300 |
| Code hash updated | 12,200 | 9,300 |

In [EIP-7928](/eip-7928/) block access lists the change is recorded as a 32-byte hash, not the bytecode.

## Sample code

Account migration, from the spec's pseudocode:

```
SSTORE(pq_pubkey_slot, userPubkey)
SSTORE(recovery_slot, recoveryConfig)
if SETCODEFROM(PQ_WALLET_TEMPLATE) == 0: REVERT()
STOP
```

A clone initializer run via `CREATE2`:

```
SSTORE(name_slot, "MyToken")
SSTORE(symbol_slot, "MYT")
SSTORE(owner_slot, msg.sender)
if SETCODEFROM(ERC20_TEMPLATE) == 0: REVERT()
STOP
```

## Things to know

- **Status: Draft.** Test cases are still TODO; the opcode number and gas may change.
- Adopting regular code permanently disables protocol-level ECDSA transactions for that EOA. Contracts that check signatures with `ecRecover` (such as `permit`) still accept the old key unless a companion change like [EIP-8151](/eip-8151/) is adopted.
- Any code that can reach `SETCODEFROM`, including modules run via `DELEGATECALL`, is effectively upgrade authority. Restrict who can trigger it.
- Accounts delegated via 7702 to an EOA will execute whatever code that EOA later adopts.
- A template can't be adopted in the same transaction that deploys it.
- Public mempool rules (and [ERC-7562](/eip-7562/) validation) must treat contracts that can call `SETCODEFROM` as having mutable code.
- Earlier, more permissive code-replacement ideas include [EIP-6913](/eip-6913/) (`SETCODE`, Withdrawn).


---

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