EIPs Explained

EIP-210 · Stagnant · Core · 2017-02-10

EIP-210: Blockhash refactoring

Proposed storing past block hashes in a system contract so BLOCKHASH could be served from state and reach far beyond 256 blocks; it stalled, but the idea returned in EIP-2935.

What problem does it solve?

The BLOCKHASH opcode returns the hash of one of the last 256 blocks. Clients answer it from data that is not part of the state trie, a kind of "implied state". That is extra machinery every client must carry, it cannot be proven with a state proof, and contracts cannot see anything older than 256 blocks.

EIP-210 proposes putting block hashes into the state itself, inside a special contract, so the protocol becomes simpler and light clients can jump directly between distant blocks.

How it works

The proposal was aimed at the Constantinople fork:

  • At the fork block, code is installed at address 0xf0 (BLOCKHASH_CONTRACT_ADDR).
  • At the start of every block, before any transactions, the protocol calls that contract from a special sender SUPER_USER (2**160 - 2, i.e. 0xff…fe) with the parent block hash as input and 1,000,000 gas.
  • The contract stores the hash in a layered layout. Every block's hash goes into a 256-slot ring buffer. Every 256th block's hash also goes into a second buffer, every 65,536th into a third, and so on. This lets the contract answer queries for very old blocks at coarser granularity.
  • Starting 256 blocks after the fork, BLOCKHASH would become a normal call into this contract instead of a client lookup.
  • The BLOCKHASH gas cost would rise from 20 to 800 to pay for running contract code.

Sample code

Storage logic from the spec's Serpent source, simplified to pseudocode:

# called once per block by SUPER_USER with prevhash
def store(prevhash):
    bn, offset = block.number - 1, 0
    while bn:
        sstore(offset + bn % 256, prevhash)
        if bn % 256:          # stop unless bn is a multiple of 256
            return
        bn //= 256
        offset += 256

# called by BLOCKHASH(n)
def lookup(n):
    dist = block.number - n - 1
    offset = 0
    while dist >= 256 and n % 256 == 0:
        offset += 256
        n //= 256
        dist //= 256
    return sload(offset + n % 256) if dist < 256 else 0

Things to know

  • This proposal is Stagnant and was never adopted. Constantinople (EIP-1013) shipped without it, and BLOCKHASH still works as before.
  • The core idea came back years later as EIP-2935, which stores the last 8,191 block hashes in a system contract. Unlike EIP-210, EIP-2935 leaves the BLOCKHASH opcode unchanged and simply makes the history readable from state.
  • The "system call before transactions from 0xff…fe" pattern introduced here is the same convention later used by EIP-4788 for beacon block roots.
  • Because the parameters (fork block, contract address) were never finalized, do not rely on address 0xf0 holding any block hash contract.

#core #blockhash #state #stagnant

Details

Authors
Vitalik Buterin (@vbuterin)
Status
Stagnant
Type
Standards Track / Core
Created
2017-02-10

Machine-readable: Markdown · JSON