-
Notifications
You must be signed in to change notification settings - Fork 6k
Description
Summary
Allows blocks to be directly aware of block hashes much older than the current hash.
Parameters
BLOCKHASH_CONTRACT_ADDR: 0xf0 (ie. 240)
Specification
At the start of processing any block, run the following algorithm, where store(x, y) stores value y in key x of BLOCKHASH_CONTRACT_ADDR:
i = 0
while (not (block.number-1) & 2**i) and i < 32:
store(i, block.prevhash)
i += 1Extends the BLOCKHASH opcode so that if a given block height's hash is available in one of these storage keys, then this value is returned (ie. so sometimes block hashes with heights more than 256 blocks ago can be returned). That is, if BLOCKHASH is called with height equal to block.number - (block.number % 2**k) for some k < 32, then sload(k) is returned.
Explanation
Storage key 0 always stores the last blockhash, storage key 1 stores the last blockhash with an even blockheight, storage key 2 stores the last blockhash with a blockheight of 0 mod 4, etc etc.
Use cases
- Some contracts may want to use block hashes as a source of randomness, with an inclusion window larger than 256 blocks for safety. With this EIP, an application would be able to use a block hash with a 2^k window during which that hash could be called, at the cost of a [0...2^k] block delay until the hash is accessible.
- This EIP ensures that it's possible to prove the hash of block N to the chain at height N2 with
~log2(N2 - N) - 8Merkle branches. It should not be too hard to use existing libraries to write a utility contract and library that produces and verifies these proofs. - The above makes it possible to make trustless light clients, as one can make a subchain of the main chain that contains all of its lowest-hash-value blocks, proving to a client that some particular checkpoint actually is the best available checkpoint in O(log(n)) space/time.