EIPs Explained

EIP-2583 · Stagnant · Core · 2020-02-21

EIP-2583: Penalty for account trie misses

Proposed an extra gas penalty when an opcode looks up an account that does not exist, to blunt DoS attacks that deliberately miss node caches.

What problem does it solve?

Nodes rely heavily on caches to read state quickly. A cache hit is cheap, but a lookup for an address that is not in the state trie usually misses every cache and goes to disk. An attacker can exploit this by touching a fresh non-existent address every time, maximising disk reads per unit of gas. Caching "non-existence" does not help much, because the attacker never repeats an address and the junk entries evict useful ones.

Raising the base price of every state-access opcode (as EIP-150 and EIP-1884 did) punishes all contracts for the worst case. EIP-2583 instead keeps normal prices for normal use and charges extra only on the "miss" path.

How it works

  • A constant penalty (left as TBD, suggested 2000 gas) is charged whenever an opcode that reads the account trie targets an address that does not exist.
  • Affected: BALANCE, EXTCODEHASH, EXTCODECOPY, EXTCODESIZE, and the call family (CALL, CALLCODE, DELEGATECALL, STATICCALL).
  • Not affected: SELFDESTRUCT (already costs 5000), CREATE/CREATE2 (target is expected not to exist), SELFBALANCE, and base opcode costs in general.
  • For calls, the penalty applies only when no value is sent and the destination does not exist (and is not a precompile). Value-transferring calls to new accounts already pay the 25,000 new-account charge.
Op value, dest value, !dest !value, dest !value, !dest
CALL / CALLCODE no change no change no change penalty
DELEGATECALL / STATICCALL N/A N/A no change penalty

The author estimated that a 10M-gas transaction could cause about 14K trie lookups at the time, and that a 2000-gas penalty would cut that to about 3700. The spec also notes a ceiling: an attacker can route lookups through a relay contract, so a penalty much above about 800 gas may not add protection.

Sample code

Pseudocode for the extra charge on BALANCE:

PENALTY = 2000  # suggested value; TBD in the spec

def op_balance(evm, address):
    evm.charge_gas(BALANCE_BASE_COST)
    if not evm.state.account_exists(address):
        evm.charge_gas(PENALTY)          # trie miss
        evm.stack.push(0)
    else:
        evm.stack.push(evm.state.get_balance(address))

Solidity code paths that would pay it: the pre-call EXTCODESIZE check that Solidity performs on a high-level call to a non-existent recipient, and addr.balance on an empty address.

Things to know

  • Status: Stagnant. It was never adopted. Ethereum addressed the same class of DoS differently with EIP-2929, which made the first access to any address or slot in a transaction expensive ("cold") and later accesses cheap ("warm").
  • Several parts of the spec were left open: the exact penalty value, whether it applies to plain zero-value transactions, and how it should interact with self-destructed accounts.
  • The backwards compatibility section examines real contracts, such as ERC-223-style isContract checks, and concludes most would be unaffected as long as the penalty stays below roughly 3000 gas.

#gas #dos #state #opcodes #core

Details

Authors
Martin Holst Swende (@holiman)
Status
Stagnant
Type
Standards Track / Core
Created
2020-02-21

Machine-readable: Markdown · JSON