EIP-3607 · Final · Core · 2021-06-10
EIP-3607: Reject transactions from senders with deployed code
Makes any transaction whose sender address already has contract code invalid, closing off an attack where someone who finds an EOA/contract address collision could drain the contract with a private key.
What problem does it solve?
Ethereum addresses are 160 bits. Finding some private key whose address equals some contract address (a birthday-style collision between a set of EOAs and a set of possible contract deployments) takes about 2^80 work. The spec estimates that as roughly a year of computation with about US$10 billion of hardware and electricity: very expensive, but not impossible.
The dangerous scenario: an attacker finds such a collision, deploys an innocent-looking contract at that address (say, a token wrapper or AMM), waits for users to deposit funds, and then signs ordinary transactions from the same address with the private key to take everything.
The Yellow Paper never said what should happen if a transaction's sender has code, presumably because the case was considered impossible, and clients generally allowed it. EIP-3607 makes the rule explicit.
How it works
One validity rule:
- If the sender's account has
codeHash != EMPTY_CODE_HASH(whereEMPTY_CODE_HASH = keccak256("") = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470), the transaction is invalid. - Clients must not include such a transaction, and a block containing one is invalid.
The check runs during transaction validation, right after the nonce check, using the address recovered from the signature. Because it only turns previously valid transactions into invalid ones, the spec notes it could be deployed as a soft fork, and frames it as a clarification of undefined behaviour rather than a new feature.
Sample code
The client-side check, in Go-like pseudocode based on the reference implementation:
var EmptyCodeHash = common.HexToHash(
"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")
func preCheck(st *StateTransition) error {
// ... nonce checks ...
if codeHash := st.state.GetCodeHash(st.msg.From); codeHash != EmptyCodeHash && codeHash != (common.Hash{}) {
return ErrSenderNoEOA // sender has deployed code: reject
}
return nil
}
(common.Hash{} covers accounts that do not exist yet, which have no code.)
Things to know
- Status: Final, and enforced by Ethereum clients.
- It does not remove every collision risk. The spec lists remaining, harder cases: funds sent to an address before a contract is deployed there (e.g. counterfactual addresses from
CREATE2, EIP-1014), a reorg that removes the deployment, and a contract that self-destructed. - Clients may skip the rule for
eth_callandeth_estimateGas, since some multisig tools simulate calls "from" the contract itself. - EIP-7702 (Pectra) lets EOAs set a delegation designator as their code. It amends this rule so that accounts whose code is a valid delegation designator can still send transactions.
- Private networks that put code at genesis on addresses also used as EOAs should check they are not affected.