EIPs Explained

EIP-5478 · Stagnant · Core · 2022-08-17

EIP-5478: CREATE2COPY Opcode

Proposed a CREATE2COPY opcode that deploys a contract whose code matches an existing one and charges an account access (2,600 or 100 gas) instead of the per-byte code deposit fee.

What problem does it solve?

With account abstraction, every user gets their own smart-contract wallet, and most of them run identical code. Deploying a contract still charges the code deposit cost of 200 gas per byte of runtime code. The spec's example: a 10,000-byte wallet costs 2,000,000 gas in code deposit alone, every time, even though nodes already store that exact code.

EIP-5478 proposes paying only for looking up the existing code instead of re-paying for storing it.

How it works

A new opcode CREATE2COPY (proposed at 0xf6) behaves like CREATE2 (EIP-1014) with one extra stack argument:

CREATE2COPY(endowment, memory_start, memory_length, salt, existing_contract_address)
  • Initcode runs exactly as with CREATE2, and the address is derived the same way.
  • The runtime code returned by the initcode MUST have the same code hash as existing_contract_address. If it does not, creation fails ("mismatched contract creation code with existing code") and all gas for the creation is burned.
  • Gas is the same as CREATE2, except the code-deposit term 200 * code_size is replaced by the cost of an EXTCODEHASH on the existing contract: 2,600 if cold, 100 if warm (EIP-2929).
Constant Value
CREATE_DATA_GAS_PER_BYTE 200
COLD_ACCOUNT_ACCESS_COST 2600
WARM_ACCOUNT_ACCESS_COST 100

Sample code

How a wallet factory might use it (hypothetical; no compiler or chain supports this opcode):

# Pseudocode: CREATE2COPY does not exist on mainnet.
def deploy_wallet(factory, initcode: bytes, salt: bytes, template: str) -> str:
    # Same as CREATE2(endowment=0, initcode, salt) ...
    # ... but the runtime code must hash-match `template`, and the
    # 200 gas/byte code deposit is replaced by an EXTCODEHASH-priced access.
    wallet = factory.CREATE2COPY(0, initcode, salt, template)
    assert wallet != ZERO_ADDRESS, "deploy failed"
    return wallet

# Gas for a 10,000-byte wallet code deposit:
#   CREATE2:      200 * 10_000 = 2_000_000
#   CREATE2COPY:  2_600 (template cold) or 100 (template warm)

Things to know

  • Status: Stagnant. The fork block is "TBD", and the Rationale and Security Considerations sections were never completed.
  • It only discounts the code deposit. Initcode execution, the base CREATE2 cost and hashing still apply.
  • Today the usual way to make cheap per-user deployments is a proxy such as ERC-1167, which deploys a few dozen bytes that DELEGATECALL into shared logic. That is the pattern ERC-4337 wallet factories commonly use.
  • Unlike a proxy, CREATE2COPY would give each account a full, independent copy of the code with no delegatecall overhead.

#evm #opcodes #deployment #account-abstraction #gas

Details

Authors
Qi Zhou (@qizhou)
Status
Stagnant
Type
Standards Track / Core
Created
2022-08-17
Requires

Machine-readable: Markdown · JSON