EIP-684 · Final · Core · 2023-03-20
EIP-684: Revert creation in case of collision
Makes contract creation fail if the target address already has code or a nonzero nonce, so deployed code can never be silently replaced by a second "creation" at the same address.
What problem does it solve?
A basic promise of smart contracts is that the code at an address does not change. Contract addresses come from a hash: the sender and nonce for CREATE, or the deployer, salt and init code hash for CREATE2. If two different creations could land on the same address and the second one overwrote the first, an attacker with enough computing power could find such a collision. They could then deploy harmless-looking code, win users' trust and funds, and later swap in malicious code.
EIP-684 closes that door: an address that is already "in use" cannot be created again.
How it works
For every kind of contract creation (a creation transaction, CREATE, CREATE2, or anything else):
- if the destination address has a nonzero nonce, or
- if the destination address has nonzero code length,
the creation fails exactly as if the first byte of the init code were an invalid opcode. All gas given to the creation is used up, the caller gets 0 (the zero address) on the stack, and no state changes.
The rule applies retroactively from genesis. It is not a new behaviour: it began as GitHub issue #684, and EIP-1014 (2018) already quotes it as the rule for collisions. The EIP document itself was written up in 2023 to record it formally.
An account that only has a balance (nonce 0, no code) is not a collision. ETH sent to a future CREATE2 address in advance does not block deployment.
Sample code
Deploying twice with the same CREATE2 salt. The second attempt hits the EIP-684 rule:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract Child {}
contract Factory {
function deploy(bytes32 salt) external returns (address) {
return address(new Child{salt: salt}());
}
}
// factory.deploy(0x01) -> succeeds, returns 0xAbC...
// factory.deploy(0x01) -> reverts: address already has code and nonce 1
The same check written as client pseudocode:
def can_create_at(state, addr) -> bool:
acct = state.get(addr)
return acct.nonce == 0 and len(acct.code) == 0
Things to know
- Because a newly created contract's nonce starts at 1 (EIP-161), a second creation at the same address in the same transaction always fails, even before any code is stored.
SELFDESTRUCTused to clear the account, which allowed "metamorphic" contracts: destroy, thenCREATE2again with the same salt and different code. EIP-6780 removed this, except when both happen in the same transaction.- EIP-7610 (in Last Call) extends the rule to addresses that have non-empty storage.
- The opposite case, where a transaction is sent from an address that has code, is handled by EIP-3607.