Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 34 additions & 59 deletions EIPS/eip-2935.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down Expand Up @@ -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.
Copy link
Copy Markdown
Contributor

@g11tech g11tech Dec 17, 2024

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 ?

Copy link
Copy Markdown
Member Author

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.


#### `set`

Expand All @@ -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
Comment thread
g11tech marked this conversation as resolved.
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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
push0
// Check if input is requesting a block hash greater than current block number
// minus 1.
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
Comment on lines +96 to +97
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
push2 0x1fff
dup2
// Check if the input is requesting a block hash before the earliest available
// hash currently. Since we've verified that input <= number - 1, we know
// there will be no overflow during the subtraction of number - input.
push2 0x1fff
dup2

number
sub
gt
push1 0x4b
push1 0x42
jumpi

// mod 8192 and sload
push2 0x1fff
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
push2 0x1fff
// Load the hash.
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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
push0
// Load into memory and return.
push0

mstore
push1 0x20
push0
return

// 0x53: revert
jumpdest
push0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
push0
// Reverts current execution with no return data.
push0

push0
revert

// 0x57: set op - sstore the input to number-1 mod 8192
Comment on lines -141 to -142
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for removing the comments ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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:

disease --code 0x$(geas src/consolidations/main.eas) | sed -E '/^[[:space:]]*$/d; s/^[[:space:]]*[0-9a-fA-F]+:[[:space:]]+//; s/[[:space:]]*# selector\(.*\)$//'

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
jumpdest
// sstore block hash
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:
Expand All @@ -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:
Expand Down Expand Up @@ -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.
Comment thread
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.
Comment thread
lightclient marked this conversation as resolved.

## 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.
Expand Down