EIP-2583 Account trie miss gas penalty (Penalty for account trie misses)
No call decision · Fees & gas · EIP status Stagnant · created 2020-02-21
An EIP that imposes an additional gas penalty on operations like BALANCE, EXTCODEHASH, and CALL when they look up a nonexistent account, to prevent DoS attacks that try to maximize disk lookups.
Why it is needed
As Ethereum's state trie grows larger, the disk lookup cost of querying a single account also grows. Nodes handle this with caching, but a cache is only useful on a hit and worthless on a miss. An attacker can keep specifying new nonexistent addresses to query, bypassing the cache and maximizing disk lookups. If gas costs are set to match average usage, this worst-case execution becomes relatively cheap and exploitable for attacks; conversely, if costs are set to match the worst case, all normal contract execution becomes expensive. Approaches like EIP-150 and EIP-1884, which raise the base cost of opcodes, have already been tried, but this dilemma was not resolved. This EIP proposes leaving the normal cost unchanged and imposing an extra penalty only when accessing a nonexistent account, selectively making just the attack path more expensive.
What changes
Today
- BALANCE, EXTCODEHASH, EXTCODECOPY, EXTCODESIZE, and the CALL family charge the same gas whether querying an existing account or a nonexistent one.
- If an attacker specifies a new nonexistent address each time, there is room to bypass the cache and maximize disk lookups.
- Because gas prices are set based on average usage, this worst-case execution is relatively cheap.
After EIP-2583
- An additional penalty (proposed value 2000) gas is deducted for BALANCE, EXTCODEHASH, EXTCODECOPY, and EXTCODESIZE calls targeting a nonexistent account.
- The same penalty is added for CALL, CALLCODE, DELEGATECALL, and STATICCALL calls that transfer no value and target a nonexistent destination.
- SELFDESTRUCT, CREATE, and CREATE2 are excluded from the penalty.
- The number of trie lookups a 10M-gas transaction can trigger drops from roughly 14,000 to about 3,700 (26%) under a penalty of 2000.
Who is affected
- Ordinary users: Gas costs rise only in rare cases such as zero-value transactions sent to nonexistent addresses; ordinary transfers and normal contract calls are unaffected.
- Wallet & app developers: Patterns like ERC223's that pre-check for contract existence via EXTCODESIZE see negligible impact as long as the penalty stays under 3000 gas.
- Client (node) teams: Disk-lookup-focused DoS can be mitigated without building extra data structures such as bloom filters or a separate flattened account DB.
- Contract operators: Contracts like Dentacoin that help onboard users by sending small amounts of ether to new accounts could see an additional 2000 to 3000 gas on top of the existing 34000 gas.
In depth
Opcodes subject to the penalty
The opcodes subject to the penalty are BALANCE, EXTCODEHASH, EXTCODECOPY, EXTCODESIZE, and CALL, CALLCODE, DELEGATECALL, STATICCALL. If the target address does not exist in the account trie, the penalty (proposed value 2000) gas is charged on every call. SELFDESTRUCT involves a trie lookup on the beneficiary but is excluded since it already costs 5000 gas. CREATE and CREATE2 are not covered because the created address cannot be directly specified and is already assumed not to exist. SELFBALANCE is unaffected regardless of whether the self address exists.
The second rule applied to CALL variants
CALL's base cost is 700 gas. The existing rules still apply: 9000 gas is added when transferring value, and 25000 gas when the destination is newly created. This EIP adds a second rule: the penalty is added only when there is no value transfer (!value), the destination does not exist, and it is not a precompile (!dest). Cases involving a value transfer or where the destination already exists see no change. Since DELEGATECALL and STATICCALL cannot transfer value, the value-related column is marked N/A.
Basis for the penalty value and its ceiling
A 10M-gas transaction can currently trigger roughly 14,000 trie lookups. Setting the penalty to 1000 reduces this to about 5,800 (41%); 2000 to about 3,700 (26%); 3000 to about 2,700 (20%); and 4000 to about 2,100 (15%). However, accounting for shielded relay attacks, there is a roofing function beyond which the effect does not keep growing. Because routing a lookup through a relay contract caps the attacker's effective cost at about 1500 gas, raising the penalty above roughly 800 yields little additional defensive benefit.
Storage tries are out of scope for this EIP
This EIP addresses only account trie access and does not touch storage trie access. Storage tries are generally small, and it is expensive for an attacker to build a dense storage trie. Additionally, even trying to exploit the storage of an existing dense token contract requires going through a CALL such as token.balanceOf(nonexistent), adding the base CALL cost of 700 gas plus argument-passing cost, which raises the difficulty of the attack.
Hard fork and compatibility with existing contracts
This change requires a hard fork. Ordinary EOA-to-EOA transfers with value are unaffected; only zero-value transactions sent to nonexistent addresses are affected, a case with little practical use. Solidity's remote calls use a pattern of pre-checking via EXTCODESIZE and reverting if it is zero; with this EIP, the normal path is unchanged and only the path to a nonexistent recipient becomes more expensive by the penalty amount. ERC223's isContract check (based on EXTCODESIZE) is also unaffected as long as the penalty does not exceed 3000 gas. The Dentacoin contract already spends 34000 gas on a nonexistent recipient; the penalty (doubled if it checks twice) adds to this, but is assessed as negligible compared to the 34000 gas.
Edge cases not yet settled
The specification leaves the following as TBD. The penalty should not apply to a call targeting self-address from within the constructor of a contract currently being created, though this is not finalized. How the penalty should apply when re-querying a SELFDESTRUCT'd account via EXTCODEHASH or CALL within the same call context, same transaction, or same block is also undecided. The impact on transactions with zero value sent to nonexistent accounts remains to be tested.
Current status and open items
This EIP is in Stagnant status, and even the core constant, the penalty itself, remains TBD (proposed value 2000). No implementation is yet available (Not yet available), and alternative designs such as Insta-refunds and Parent bail have also been proposed, with neither adopted yet. There is no record of a call decision on fork inclusion.