EIP-8298 · Draft · Core · 2026-06-11
EIP-8298: SETCODEFROM Code Reuse Instruction
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). Minimal proxies (ERC-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 delegation, but a delegation leaves the old ECDSA key able to send transactions and redelegate. If the account instead holds regular code, 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,
EXTCODEHASHand 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 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 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 aspermit) still accept the old key unless a companion change like EIP-8151 is adopted. - Any code that can reach
SETCODEFROM, including modules run viaDELEGATECALL, 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 validation) must treat contracts that can call
SETCODEFROMas having mutable code. - Earlier, more permissive code-replacement ideas include EIP-6913 (
SETCODE, Withdrawn).