-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Update EIP-2935: bring up to date with sys contract impl #9144
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -26,11 +26,11 @@ A side benefit of this approach could be that it allows building/validating proo | |||||
|
||||||
| Parameter | Value | | ||||||
| - | - | | ||||||
| `FORK_TIMESTAMP` | TBD | | ||||||
| `BLOCKHASH_SERVE_WINDOW` | `256` | | ||||||
| `HISTORY_SERVE_WINDOW` | `8192` | | ||||||
| `SYSTEM_ADDRESS` | `0xfffffffffffffffffffffffffffffffffffffffe` | | ||||||
| `HISTORY_STORAGE_ADDRESS` | `0x0aae40965e6800cd9b1f4b05ff21581047e3f91e`| | ||||||
| `FORK_TIMESTAMP` | TBD | | ||||||
| `BLOCKHASH_SERVE_WINDOW` | `256` | | ||||||
| `HISTORY_SERVE_WINDOW` | `8192` | | ||||||
| `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). | ||||||
|
||||||
|
@@ -61,8 +61,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. | ||||||
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. this is not the current BLOCKHASH (with window 256) behavior so we are actually diverging from the behavior ? |
||||||
|
||||||
#### `set` | ||||||
|
||||||
|
@@ -74,89 +74,57 @@ 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 | ||||||
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 | ||||||
Comment on lines
-142
to
-143
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 ? |
||||||
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: | ||||||
|
@@ -171,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: | ||||||
|
@@ -234,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. | ||||||
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
|
||||||
|
||||||
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. | ||||||
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
|
||||||
|
||||||
## 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. | ||||||
|
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.
Update according to PR description, but I have not verified this value.