-
Notifications
You must be signed in to change notification settings - Fork 47
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
Conversation
@@ -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) |
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.
Is a length check on the proof's Vec needed here?
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.
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
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.
I have also added a test for this in cfc9572
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.
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 theblock_hash
field.