-
Notifications
You must be signed in to change notification settings - Fork 6k
Update EIP-2935: bring up to date with sys contract impl #9144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
996724c
06493d5
7180020
d2e850e
1b07d41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Original file line | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,10 +26,10 @@ A side benefit of this approach could be that it allows building/validating proo | ||||||||||||||||||
|
|
|
||||||||||||||||||
| | Parameter | Value | | | Parameter | Value | | ||||||||||||||||||
| | - | - | | | - | - | | ||||||||||||||||||
| | `BLOCKHASH_SERVE_WINDOW` | `256` | | | `BLOCKHASH_SERVE_WINDOW` | `256` | | ||||||||||||||||||
| | `HISTORY_SERVE_WINDOW` | `8192` | | | `HISTORY_SERVE_WINDOW` | `8191` | | ||||||||||||||||||
| | `SYSTEM_ADDRESS` | `0xfffffffffffffffffffffffffffffffffffffffe` | | | `SYSTEM_ADDRESS` | `0xfffffffffffffffffffffffffffffffffffffffe` | | ||||||||||||||||||
| | `HISTORY_STORAGE_ADDRESS` | `0x0aae40965e6800cd9b1f4b05ff21581047e3f91e`| | | `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). | 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. | It is used from the EVM for looking up block hashes. | ||||||||||||||||||
|
|
|
||||||||||||||||||
| * Callers provide the block number they are querying in a big-endian encoding. | * Callers provide the block number they are querying in a big-endian encoding. | ||||||||||||||||||
| * If calldata is bigger than 2^64-1, revert. | * If calldata is not 32 bytes, revert. | ||||||||||||||||||
| * For any output outside the range of [block.number-`HISTORY_SERVE_WINDOW`, block.number-1] return 0. | * For any request outside the range of [block.number-`HISTORY_SERVE_WINDOW`, block.number-1], revert. | ||||||||||||||||||
|
|
|
||||||||||||||||||
| #### `set` | #### `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: | 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 | caller | ||||||||||||||||||
|
g11tech marked this conversation as resolved.
|
|||||||||||||||||||
| push20 0xfffffffffffffffffffffffffffffffffffffffe | push20 0xfffffffffffffffffffffffffffffffffffffffe | ||||||||||||||||||
| eq | eq | ||||||||||||||||||
| push1 0x57 | push1 0x46 | ||||||||||||||||||
| jumpi | |||||||||||||||||||
| push1 0x20 | |||||||||||||||||||
| calldatasize | |||||||||||||||||||
| sub | |||||||||||||||||||
| push1 0x42 | |||||||||||||||||||
| jumpi | 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 | push0 | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
|||||||||||||||||||
| calldataload | calldataload | ||||||||||||||||||
| gt | push1 0x01 | ||||||||||||||||||
| push1 0x53 | |||||||||||||||||||
| jumpi | |||||||||||||||||||
|
|
|||||||||||||||||||
| // check if input > blocknumber-1 then return 0 | |||||||||||||||||||
| push1 0x1 | |||||||||||||||||||
| number | number | ||||||||||||||||||
| sub | sub | ||||||||||||||||||
| push0 | dup2 | ||||||||||||||||||
| calldataload | |||||||||||||||||||
| gt | gt | ||||||||||||||||||
| push1 0x4b | push1 0x42 | ||||||||||||||||||
| jumpi | jumpi | ||||||||||||||||||
|
|
push2 0x1fff | ||||||||||||||||||
| // check if blocknumber > input + 8192 then return 0, no overflow expected for input of < max 8 byte value | dup2 | ||||||||||||||||||
|
Comment on lines
+96
to
+97
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
|||||||||||||||||||
| push0 | |||||||||||||||||||
| calldataload | |||||||||||||||||||
| push2 0x2000 | |||||||||||||||||||
| add | |||||||||||||||||||
| number | number | ||||||||||||||||||
| sub | |||||||||||||||||||
| gt | gt | ||||||||||||||||||
| push1 0x4b | push1 0x42 | ||||||||||||||||||
| jumpi | jumpi | ||||||||||||||||||
|
|
|||||||||||||||||||
| // mod 8192 and sload | |||||||||||||||||||
| push2 0x1fff | push2 0x1fff | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
|||||||||||||||||||
| push0 | swap1 | ||||||||||||||||||
| calldataload | mod | ||||||||||||||||||
| and | |||||||||||||||||||
| sload | sload | ||||||||||||||||||
|
|
|||||||||||||||||||
| // load into mem and return 32 bytes | |||||||||||||||||||
| push0 | |||||||||||||||||||
| mstore | |||||||||||||||||||
| push1 0x20 | |||||||||||||||||||
| push0 | |||||||||||||||||||
| return | |||||||||||||||||||
|
|
|||||||||||||||||||
| // 0x4b: return 0 | |||||||||||||||||||
| jumpdest | |||||||||||||||||||
| push0 | |||||||||||||||||||
| push0 | push0 | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
|||||||||||||||||||
| mstore | mstore | ||||||||||||||||||
| push1 0x20 | push1 0x20 | ||||||||||||||||||
| push0 | push0 | ||||||||||||||||||
| return | return | ||||||||||||||||||
|
|
|||||||||||||||||||
| // 0x53: revert | |||||||||||||||||||
| jumpdest | jumpdest | ||||||||||||||||||
| push0 | push0 | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
|||||||||||||||||||
| push0 | push0 | ||||||||||||||||||
| revert | revert | ||||||||||||||||||
|
|
|||||||||||||||||||
| // 0x57: set op - sstore the input to number-1 mod 8192 | |||||||||||||||||||
|
Comment on lines
-141
to
-142
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reason for removing the comments ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed all these comments because the assembled code comes from the command:
all the code info is in the sysasm: https://github.com/lightclient/sys-asm/blob/main/src/execution_hash/main.eas I'd probably hold off on code comments in the eip until this is going to last call. |
|||||||||||||||||||
| jumpdest | jumpdest | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
|||||||||||||||||||
| push0 | push0 | ||||||||||||||||||
| calldataload | calldataload | ||||||||||||||||||
| push2 0x1fff | push2 0x1fff | ||||||||||||||||||
| push1 0x1 | push1 0x01 | ||||||||||||||||||
| number | number | ||||||||||||||||||
| sub | sub | ||||||||||||||||||
| and | mod | ||||||||||||||||||
| sstore | sstore | ||||||||||||||||||
|
|
|||||||||||||||||||
| stop | stop | ||||||||||||||||||
| ``` | ``` | ||||||||||||||||||
|
|
|
||||||||||||||||||
| Corresponding bytecode: | |||||||||||||||||||
| `0x3373fffffffffffffffffffffffffffffffffffffffe1460575767ffffffffffffffff5f3511605357600143035f3511604b575f35612000014311604b57611fff5f3516545f5260205ff35b5f5f5260205ff35b5f5ffd5b5f35611fff60014303165500` | |||||||||||||||||||
|
|
|||||||||||||||||||
| #### Deployment | #### Deployment | ||||||||||||||||||
|
|
|
||||||||||||||||||
| A special synthetic address is generated by working backwards from the desired deployment transaction: | 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, | "maxPriorityFeePerGas": null, | ||||||||||||||||||
| "maxFeePerGas": null, | "maxFeePerGas": null, | ||||||||||||||||||
| "value": "0x0", | "value": "0x0", | ||||||||||||||||||
| "input": "0x60648060095f395ff33373fffffffffffffffffffffffffffffffffffffffe1460575767ffffffffffffffff5f3511605357600143035f3511604b575f35612000014311604b57611fff5f3516545f5260205ff35b5f5f5260205ff35b5f5ffd5b5f35611fff60014303165500", | "input": "0x60538060095f395ff33373fffffffffffffffffffffffffffffffffffffffe14604657602036036042575f35600143038111604257611fff81430311604257611fff9006545f5260205ff35b5f5ffd5b5f35611fff60014303065500", | ||||||||||||||||||
| "v": "0x1b", | "v": "0x1b", | ||||||||||||||||||
| "r": "0x539", | "r": "0x539", | ||||||||||||||||||
| "s": "0x1b9b6eb1f0", | "s": "0xbaefe09f0109759", | ||||||||||||||||||
| "hash": "0x3c769a03d6e2212f1d26ab59ba797dce0900df29ffd23c1dd391fd6b217973ad", | "hash": "0x8c7bd2d3713a0b2bb693463d2a78c4d612ac47dd38ecb74f8996a4b6fc96f03c" | ||||||||||||||||||
| } | } | ||||||||||||||||||
| ``` | ``` | ||||||||||||||||||
|
|
|
||||||||||||||||||
| Note, the input in the transaction has a simple constructor prefixing the desired runtime code. | 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: | 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. | 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. | |||||||||||||||||||
|
lightclient marked this conversation as resolved.
|
|||||||||||||||||||
|
|
|||||||||||||||||||
| 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. | |||||||||||||||||||
|
lightclient marked this conversation as resolved.
|
|||||||||||||||||||
|
|
|||||||||||||||||||
| ## Backwards Compatibility | ## 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. | 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. | ||||||||||||||||||
|
|
|||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not the current BLOCKHASH (with window 256) behavior so we are actually diverging from the behavior ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mentioned this elsewhere, but I think this divergence is okay because i) it matches other system contracts and ii) it is pretty straightforward to create an adapter around this system contract to mimic the BLOCKHASH behavior when it is used to back the actual op.