EIP-7637 EOA EXTCODEHASH Optimization (Optimize EOA EXTCODEHASH)
No call decision · EVM & execution · EIP status Stagnant · created 2024-02-26
A proposal that changes EXTCODEHASH to return 0x instead of keccak256(empty string) for addresses with no code but a balance, fixing the unsafe usage problem in EIP-1052.
Why it is needed
EIP-1052 created the EXTCODEHASH operation, allowing contract existence to be checked at lower gas cost than EXTCODESIZE. In doing so, it was designed so that even for a codeless address, the EXTCODEHASH value would change from 0x to keccak256(empty string) if the address had a balance. However, if an address is precomputed with CREATE or CREATE2, simply sending ether to that address before the contract is deployed changes the value even though there is still no code. As a result, developers cannot safely determine the absence of code using EXTCODEHASH==0 alone, and end up having to fall back to more expensive checks like code.length==0. This erases the gas savings that EIP-1052 was meant to provide.
What changes
Today
- Address with no code and no balance: EXTCODEHASH value is 0x
- Address with no code but a balance: EXTCODEHASH value changes to keccak256(empty string)
- Due to confusion and security concerns, developers cannot trust the EXTCODEHASH==0 check and fall back to more expensive checks like code.length==0
After EIP-7637
- A codeless address keeps an EXTCODEHASH value of 0x even if it has a balance
- The absence of code can be safely determined with a single EXTCODEHASH==0 check
- Gas savings are possible in logic that checks contract existence via a stored address, as in Uniswap V2
Who is affected
- Wallet & app developers: You can go back to using cheaper logic that determines contract existence with EXTCODEHASH==0 alone.
- Client teams: The branching logic based on balance in the EXTCODEHASH opcode implementation must be removed.
- Contracts That Already Rely on the EIP-1052 Behavior: Logic that used the codehash value to distinguish whether an address held a balance can no longer be used.
In depth
The Original Rule Created by EIP-1052
EIP-1052 tried to layer a balance-check function on top of EXTCODEHASH. It was designed so that an address with no balance would have an EXTCODEHASH of 0x, while an address with a balance would get keccak256("") even without code. The intent was to save gas by folding the two pieces of information, code presence and balance presence, into a single value.
The Specific Change in This Proposal
Changes the behavior of the EXTCODEHASH operation so that the codehash of an address with a balance but no code also remains 0x. In other words, a codeless address always returns the same value (0x) regardless of whether it has a balance.
Reference Implementation Code
The proposed execution-specs patch still computes the keccak256 hash of account.code as before, but if that value equals the hash of the empty string (a fixed value given in the original code), it changes the result to 0 before pushing it onto the stack. If the account is EMPTY_ACCOUNT, it returns 0 as before.
Backward Compatibility: Usage Patterns That Break
After this change, it is no longer possible to tell whether a codeless address has a balance by looking at the codehash value alone. Code that used codehash==keccak256("") as a signal for balance presence, following the EIP-1052 approach, no longer works for that purpose.
Security considerations
The original text repeats the same point under security considerations. It states that determining whether a non-contract address holds a balance using codehash will no longer work, and explains that this is not a new risk but the result of removing the confusing behavior of the existing EIP-1052.
Current status
This proposal's current status is Stagnant, having stalled with no further discussion. There is no record of fork inclusion being discussed on a core developer call.