Skip to content
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

WEB3-132: fix: verify beacon inclusion proof against node index #249

Merged
merged 5 commits into from
Sep 21, 2024

Conversation

Wollac
Copy link
Contributor

@Wollac Wollac commented Sep 20, 2024

Previously, the node index of the block_hash was part of the input. With this PR the Merkle proof is checked with respect to the (generalized) index of the block_hash field.

@Wollac Wollac requested a review from capossele as a code owner September 20, 2024 16:39
@github-actions github-actions bot changed the title fix: verify beacon inclusion proof against node index WEB3-132: fix: verify beacon inclusion proof against node index Sep 20, 2024
@@ -33,7 +37,9 @@ impl<H: EvmBlockHeader> BeaconInput<H> {
pub fn into_env(self) -> GuestEvmEnv<H> {
let mut env = self.input.into_env();

let beacon_root = self.proof.process(env.header.seal());
let beacon_root =
merkle::process_proof(env.header.seal(), &self.proof, BLOCK_HASH_LEAF_INDEX)
Copy link
Member

Choose a reason for hiding this comment

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

Is a length check on the proof's Vec needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are actually using the generalized Merkle tree index which is defined as 2**depth + index. So the BLOCK_HASH_LEAF_INDEX also encodes the depth and it is verified here: https://github.com/risc0/risc0-ethereum/blob/fix/beacon-inclusion-proof/steel/src/merkle.rs#L71-L74

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have also added a test for this in cfc9572

@Wollac Wollac merged commit ac4a73f into main Sep 21, 2024
11 checks passed
@Wollac Wollac deleted the fix/beacon-inclusion-proof branch September 21, 2024 14:42
Wollac added a commit that referenced this pull request Oct 7, 2024
Previously, the node index of the `block_hash` was part of the input.
With this PR the Merkle proof is checked with respect to the
(generalized) index of the `block_hash` field.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants