risc0 / risc0-ethereum

Integration of the RISC Zero verifiable compute platform with Ethereum and EVM chains.
https://risczero.com
Apache License 2.0
84 stars 17 forks source link

Determine step size in Steel history commitments #309

Open Wollac opened 2 days ago

Wollac commented 2 days ago

The Beacon roots contract in Ethereum stores the historical roots of the last 8191 slots. When building the chain of state_commits, we need to pinpoint the latest (or near-latest) block within each 8191 slot window. Simply incrementing the block number by 8191 works if no slots are missed, but this approach fails when slots are skipped. To guarantee accuracy, we need a more sophisticated mechanism to identify the correct block within the time window, accounting for potential missed slots.

linear[bot] commented 2 days ago

WEB3-201 Determine step size in Steel history commitments

Wollac commented 2 days ago

Possible Solution 1: Adaptive Block Increment

One approach is to assume a maximum percentage (x%) of missed blocks within an 8191 slot window. The block number increment would then be adjusted to 8191 * (1 - x).

Drawbacks:

Wollac commented 1 day ago

Possible Solution 2: Timestamp-based Lookup

If the block time is known (since this commitment pattern only works on Ethereum and not L2, it might be reasonable to always assume 12 seconds), we could determine the target block by calculating its timestamp: current_timestamp + (8191 * 12).

Drawbacks:

Wollac commented 1 day ago

Possible Solution 3: Beacon API

Leverage the Beacon API to directly query consensus blocks by slot number. This allows us to identify the last block within the 8191 slot window by iteratively decrementing the slot number until a valid block is found. The corresponding execution block can then be extracted from the returned consensus block's ExecutionPayload.

Drawbacks: