diff --git a/EIPS/eip-2935.md b/EIPS/eip-2935.md index 8674a55b783895..198affb72399bf 100644 --- a/EIPS/eip-2935.md +++ b/EIPS/eip-2935.md @@ -26,10 +26,10 @@ A side benefit of this approach could be that it allows building/validating proo | Parameter | Value | | - | - | -| `BLOCKHASH_SERVE_WINDOW` | `256` | -| `HISTORY_SERVE_WINDOW` | `8192` | -| `SYSTEM_ADDRESS` | `0xfffffffffffffffffffffffffffffffffffffffe` | -| `HISTORY_STORAGE_ADDRESS` | `0x0aae40965e6800cd9b1f4b05ff21581047e3f91e`| +| `BLOCKHASH_SERVE_WINDOW` | `256` | +| `HISTORY_SERVE_WINDOW` | `8191` | +| `SYSTEM_ADDRESS` | `0xfffffffffffffffffffffffffffffffffffffffe` | +| `HISTORY_STORAGE_ADDRESS` | `0x0F792be4B0c0cb4DAE440Ef133E90C0eCD48CCCC` | This EIP specifies for storing last `HISTORY_SERVE_WINDOW` block hashes in a ring buffer storage of `HISTORY_SERVE_WINDOW` length. Note that `HISTORY_SERVE_WINDOW` > `BLOCKHASH_SERVE_WINDOW` (which remains unchanged). @@ -60,8 +60,8 @@ The history contract has two operations: `get` and `set`. The `set` operation is It is used from the EVM for looking up block hashes. * Callers provide the block number they are querying in a big-endian encoding. -* If calldata is bigger than 2^64-1, revert. -* For any output outside the range of [block.number-`HISTORY_SERVE_WINDOW`, block.number-1] return 0. +* If calldata is not 32 bytes, revert. +* For any request outside the range of [block.number-`HISTORY_SERVE_WINDOW`, block.number-1], revert. #### `set` @@ -73,89 +73,58 @@ It is used from the EVM for looking up block hashes. Exact evm assembly that can be used for the history contract: ``` -// if system call then jump to the set operation +// https://github.com/lightclient/sys-asm/blob/f1c13e285b6aeef2b19793995e00861bf0f32c9a/src/execution_hash/main.eas caller push20 0xfffffffffffffffffffffffffffffffffffffffe eq -push1 0x57 +push1 0x46 +jumpi +push1 0x20 +calldatasize +sub +push1 0x42 jumpi - -// check if input > 8 byte value and revert if this isn't the case -// the check is performed by comparing the biggest 8 byte number with -// the call data, which is a right-padded 32 byte number. -push8 0xffffffffffffffff push0 calldataload -gt -push1 0x53 -jumpi - -// check if input > blocknumber-1 then return 0 -push1 0x1 +push1 0x01 number sub -push0 -calldataload +dup2 gt -push1 0x4b +push1 0x42 jumpi - -// check if blocknumber > input + 8192 then return 0, no overflow expected for input of < max 8 byte value -push0 -calldataload -push2 0x2000 -add +push2 0x1fff +dup2 number +sub gt -push1 0x4b +push1 0x42 jumpi - -// mod 8192 and sload push2 0x1fff -push0 -calldataload -and +swap1 +mod sload - -// load into mem and return 32 bytes -push0 -mstore -push1 0x20 -push0 -return - -// 0x4b: return 0 -jumpdest -push0 push0 mstore push1 0x20 push0 return - -// 0x53: revert jumpdest push0 push0 revert - -// 0x57: set op - sstore the input to number-1 mod 8192 jumpdest push0 calldataload push2 0x1fff -push1 0x1 +push1 0x01 number sub -and +mod sstore - stop ``` -Corresponding bytecode: -`0x3373fffffffffffffffffffffffffffffffffffffffe1460575767ffffffffffffffff5f3511605357600143035f3511604b575f35612000014311604b57611fff5f3516545f5260205ff35b5f5f5260205ff35b5f5ffd5b5f35611fff60014303165500` - #### Deployment A special synthetic address is generated by working backwards from the desired deployment transaction: @@ -170,17 +139,17 @@ A special synthetic address is generated by working backwards from the desired d "maxPriorityFeePerGas": null, "maxFeePerGas": null, "value": "0x0", - "input": "0x60648060095f395ff33373fffffffffffffffffffffffffffffffffffffffe1460575767ffffffffffffffff5f3511605357600143035f3511604b575f35612000014311604b57611fff5f3516545f5260205ff35b5f5f5260205ff35b5f5ffd5b5f35611fff60014303165500", + "input": "0x60538060095f395ff33373fffffffffffffffffffffffffffffffffffffffe14604657602036036042575f35600143038111604257611fff81430311604257611fff9006545f5260205ff35b5f5ffd5b5f35611fff60014303065500", "v": "0x1b", "r": "0x539", - "s": "0x1b9b6eb1f0", - "hash": "0x3c769a03d6e2212f1d26ab59ba797dce0900df29ffd23c1dd391fd6b217973ad", + "s": "0xbaefe09f0109759", + "hash": "0x8c7bd2d3713a0b2bb693463d2a78c4d612ac47dd38ecb74f8996a4b6fc96f03c" } ``` Note, the input in the transaction has a simple constructor prefixing the desired runtime code. -The sender of the transaction can be calculated as `0xe473f7e92ba2490e9fcbbe8bb9c3be3adbb74efc`. The address of the first contract deployed from the account is `rlp([sender, 0])` which equals `0x0aae40965e6800cd9b1f4b05ff21581047e3f91e`. This is how `HISTORY_STORAGE_ADDRESS` is determined. Although this style of contract creation is not tied to any specific initcode like create2 is, the synthetic address is cryptographically bound to the input data of the transaction (e.g. the initcode). +The sender of the transaction can be calculated as `0xE9f0662359Bb2c8111840eFFD73B9AFA77CbDE10`. The address of the first contract deployed from the account is `rlp([sender, 0])` which equals `0x0F792be4B0c0cb4DAE440Ef133E90C0eCD48CCCC`. This is how `HISTORY_STORAGE_ADDRESS` is determined. Although this style of contract creation is not tied to any specific initcode like create2 is, the synthetic address is cryptographically bound to the input data of the transaction (e.g. the initcode). Some activation scenarios: @@ -233,6 +202,12 @@ def process_block_hash_history(block: Block, state: State): The first option is recommended until the Verkle fork, to stay consistent with [EIP-4788](./eip-4788.md) and to issues for misconfigured networks where this EIP is activated but history contract hasn't been deployed. The recommendation may be reconsidered at the Verkle fork if filtering the system contract code chunks is deemed too complex. +### Size of ring buffers + +The ring buffer data structure is sized to hold 8191 hashes. In other system contracts a prime ring buffer size is chosen in because using a prime as the modulus ensures that no value is overwritten until the entire ring buffer has been saturated and thereafter, each value will be updated once per iteration, regardless of if some slot are missing or the slot time changes. However, in this EIP the block number is the value in the modulo operation and it only ever increases by 1 each iteration. Which means we can be confident that the ring buffer will always remain saturated. + +For consistency with other system contracts, we have decided to retain the buffer size of 8191. Given the current mainnet values, 8191 roots provides about a day of coverage. This also gives users plenty of time to make a transaction with a verification against a specific hash and get the transaction included on-chain. + ## Backwards Compatibility This EIP introduces backwards incompatible changes to the block validation rule set. But neither of these changes break anything related to current user activity and experience.