EIPs Explained

EIP-7709 · Draft · Core · 2024-05-18

EIP-7709: Read BLOCKHASH from Storage and Update Cost

Makes the BLOCKHASH opcode read recent block hashes from the EIP-2935 history contract's storage and charge normal SLOAD gas for it, so it stops being a special case for stateless clients.

What problem does it solve?

BLOCKHASH returns the hash of one of the last 256 blocks. To answer it, a client must keep recent block history outside of the state. That makes it a special case: it reads chain history, yet it is not priced or recorded like other state reads. For stateless clients, which need a witness of every piece of data a block touches, that is awkward.

EIP-2935 already stores recent block hashes in a system contract's storage. EIP-7709 makes BLOCKHASH treat those hashes as ordinary storage reads.

How it works

  • The return value does not change. Requests for the current block, a future block, or one more than 256 blocks back (BLOCKHASH_SERVE_WINDOW) still return 0.
  • For an in-window block number arg, the result is defined as storage slot arg % 8191 (HISTORY_SERVE_WINDOW) of the EIP-2935 contract at 0x0000F90827F1C53a10cb7A02335B175320002935.
  • Gas: on top of the usual BLOCKHASH base cost, the opcode now charges the full SLOAD effects of that slot under the active fork: cold or warm cost (as in EIP-2929), slot warming, and any state-access recording the fork needs.
  • Clients may get the value however they like (a direct storage read, an internal call to the EIP-2935 get path, or their own in-memory history). Whatever method they use, they charge only the SLOAD effects, not the cost of running the system contract.
  • EIP-2935 should have been live for at least 256 blocks before this activates (or both at genesis on a testnet), so the ring buffer is already full.

Sample code

Resolution logic, from the spec:

BLOCKHASH_SERVE_WINDOW = 256
HISTORY_SERVE_WINDOW   = 8191
HISTORY_STORAGE_ADDRESS = 0x0000F90827F1C53a10cb7A02335B175320002935

def resolve_blockhash(block, state, arg):
    if arg >= block.number or arg + BLOCKHASH_SERVE_WINDOW < block.number:
        return 0                      # no extra storage cost
    # charges cold/warm SLOAD, warms the slot, records the access
    return state.load_slot(HISTORY_STORAGE_ADDRESS, arg % HISTORY_SERVE_WINDOW)

Solidity code is unchanged; only its gas cost goes up:

bytes32 h = blockhash(block.number - 1); // now also pays SLOAD (cold first time)

Things to know

  • Status is Draft; the fork timestamp is TBD.
  • In-window BLOCKHASH calls become noticeably more expensive. The first lookup of a slot in a transaction pays the cold SLOAD price, later lookups the warm price. Contracts tuned to the old cost may break.
  • BLOCKHASH still serves only 256 blocks, even though the EIP-2935 contract holds 8191. For older hashes, call the EIP-2935 contract directly and pay normal call costs.
  • This fits the wider statelessness work (see EIP-4762), where every state access must show up in the block witness.

#evm #opcode #blockhash #gas #statelessness #core

Details

Authors
Vitalik Buterin (@vbuterin), Tomasz Stanczak (@tkstanczak), Guillaume Ballet (@gballet), Gajinder Singh (@g11tech), Tanishq Jasoria (@tanishqjasoria), Ignacio Hagopian (@jsign), Jochem Brouwer (@jochem-brouwer), Gabriel Rocheleau (@gabrocheleau)
Status
Draft
Type
Standards Track / Core
Created
2024-05-18
Requires

Machine-readable: Markdown · JSON