EIP-5478 CREATE2COPY opcode

No call decision · EVM & execution · EIP status Stagnant · created 2022-08-17

A proposal that adds a new opcode (CREATE2COPY) to greatly reduce gas costs by referencing existing code instead of re-uploading it in full, when creating a contract with code identical to code already stored on chain.

Why it is needed

A large portion of the cost of creating a new smart contract is the data gas for writing the code to the chain byte by byte. In cases like account abstraction (AA) wallets, where each user deploys an individual contract with identical code, gas must be paid again for the full byte count every time, even if another user has already uploaded the same code. In the original example, 10,000 bytes of code costs 2,000,000 data gas, and if the code content is identical, this is an unnecessary duplicate cost. CREATE2COPY aims to lower this duplicate cost to the level of a cold/warm account access cost by allowing proof that it reuses code already stored on chain.

What changes

Today

After EIP-5478

Who is affected

In depth

Stack arguments for the new opcode CREATE2COPY

Starting from the block after FORK_BLKNUM, CREATE2COPY is added at opcode 0xf6. The arguments popped from the stack are endowment, memory_start, memory_length, salt, and existing_contract_address, five in total, with existing_contract_address added to the four arguments of the existing CREATE2 (0xf5, EIP-1014). The address calculation and creation behavior itself are identical to CREATE2.

Code hash match verification and failure handling

For CREATE2COPY to succeed, the code hash of the newly created contract must match the hash of the code stored at existing_contract_address. If the code produced by executing the initcode differs from the code at existing_contract_address, creation fails with a 'mismatched contract creation code with existing code' error, and in this case all gas allocated to the contract creation is burned.

Gas schema: replacing data gas with EXTCODEHASH cost

CREATE2 requires paying data gas equal to CONTRACT_BYTES * CREATE_DATA_GAS_PER_BYTE (200 gas per byte). CREATE2COPY replaces this data gas item with the access cost of the EXTCODEHASH opcode. If existing_contract_address is accessed for the first time in the transaction (cold), only EIP-2929's COLD_ACCOUNT_ACCESS_COST of 2600 gas is charged; if it is already in the access list (warm), only WARM_ACCOUNT_ACCESS_COST of 100 gas is charged. The rest of the gas schema is identical to CREATE2.

Prerequisites: EIP-1014, EIP-2929

CREATE2COPY reuses as is the address calculation and creation logic of CREATE2 defined by EIP-1014, and directly pulls in the cold/warm access list and cost scheme defined by EIP-2929 for its gas calculation. In other words, CREATE2COPY does not create a new gas model itself, but is designed to combine the mechanisms of two existing EIPs to cut only the cost of deploying duplicate code.

Open items and current status

In the original text, the Rationale is only noted as 'TBD' and Security Considerations as 'needs discussion,' so the design rationale and security implications have not yet been documented. The FORK_BLKNUM value is also undetermined. This EIP's status is Stagnant, having stalled since it was written on 2022-08-17 with no further discussion or fork-inclusion decision.

Original EIP · ← EIPs