Skip to content

Commit 0ad2cc7

Browse files
Wollacnategraf
andauthored
WEB3-22: chore: Expand documentation on how to handle linking Steel proofs to verified block hashes (#244)
This PR integrates the README improvements from #194 . closes #181 closes WEB3-22 --------- Co-authored-by: Victor Graf <[email protected]>
1 parent ed5601d commit 0ad2cc7

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

steel/README.md

+27-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ In the realm of Ethereum and smart contracts, obtaining data directly from the b
1010
Traditionally, these operations, especially when it comes to proving and verifying off-chain computations, involve a degree of complexity: either via proof of storage mechanisms requiring detailed knowledge of slot indexes, or via query-specific circuit development.
1111

1212
In contrast, this library abstracts away these complexities, allowing developers to query Ethereum's state by just defining the Solidity method they wish to call.
13-
To demonstrate a simple instance of using the view call library, let's consider possibly the most common view call: querying the balance of an ERC-20 token for a specific address.
13+
To demonstrate a simple instance of using this library, let's consider possibly the most common view call: querying the balance of an ERC-20 token for a specific address.
1414
You can find the full example [here](../examples/erc20/README.md).
1515

1616
## Guest code
@@ -114,19 +114,37 @@ let journal = Journal {
114114
env::commit_slice(&journal.abi_encode());
115115
```
116116

117-
We also provide an example, [erc20-counter], showcasing such integration.
117+
We provide several examples showcasing such integration, including [erc20-counter] and [token-stats].
118118

119-
### Block hash validation
119+
### Block commitment validation
120120

121-
Since internally the `blockhash` opcode is used for validation, the commitment must not be older than 256 blocks.
122-
Given a block time of 12 seconds, this allows just over 50 minutes to create the proof and ensure that the validating transaction is included in a block.
123-
In many cases, this will work just fine: even very large computations such as proving an entire Ethereum block can be done in well under 50 minutes with sufficient resources.
121+
Validating the block committed by a Steel proof is essential to ensure that the proof accurately reflects the correct blockchain state.
122+
Steel supports two methods for block validation (see the `validateCommitment` function in [Steel.sol](../contracts/src/steel/Steel.sol)).
124123

125-
For scenarios needing a verified block hash older than 256 blocks:
124+
#### 1. Block hash Commitment
126125

127-
* Save the required block hash to the contract state if known in advance (e.g., when initiating a governance proposal).
128-
* Use RISC Zero to prove the hash chain from the queried block up to a block within the most recent 256.
126+
This method uses the `blockhash` opcode to commit to a block hash that is no more than 256 blocks old.
127+
With Ethereum's 12-second block time, this provides a window of about 50 minutes to generate the proof and ensure that the validating transaction is contained in a block.
128+
This approach is ideal for most scenarios, including complex computations, as it typically provides sufficient time to generate the proof.
129+
130+
#### 2. Beacon Block Root Commitment
131+
132+
The second method allows validation using the [EIP-4788] beacon roots contract.
133+
This technique extends the time window in which the proof can be validated on-chain to just over a day, making it suitable for scenarios requiring more extensive computation.
134+
It requires access to a beacon API endpoint and can be enabled by calling `EvmEnv::into_beacon_input`.
135+
However, this approach is specific to Ethereum Steel proofs and depends on the implementation of EIP-4788.
136+
137+
Note that EIP-4788 only provides access to the parent beacon root, requiring iterative queries in Solidity to retrieve the target beacon root for validation.
138+
This iterative process can result in slightly higher gas costs compared to using the `blockhash` opcode. Overall, it is suitable for environments where longer proof generation times are required.
139+
140+
#### Bookmarking
141+
142+
A *bookmarking* validation technique can also be built on top of either block commitment approach.
143+
The idea is to store the target block commitment in the contract state before generating a Steel proof that targets that specific block.
144+
Once the block hash (or beacon root) has been bookmarked, it can be used later for validation, ensuring that the proof corresponds to the correct blockchain state.
129145

130146
[erc20-counter]: ../examples/erc20-counter/README.md
147+
[token-stats]: ../examples/token-stats/README.md
131148
[Bonsai Foundry Template]: https://github.com/risc0/bonsai-foundry-template
132149
[Steel library]: ../contracts/src/steel/Steel.sol
150+
[EIP-4788]: https://eips.ethereum.org/EIPS/eip-4788

0 commit comments

Comments
 (0)