Skip to content

Commit

Permalink
removes unnecessary Merkle proof sanity check in erasure recovery (#4589
Browse files Browse the repository at this point in the history
)

We already verify that the signatures are the same:
https://github.com/anza-xyz/agave/blob/ce8b81aa8/ledger/src/shred/merkle.rs#L842-L847

which confirms Merkle roots are the same and we cannot obtain the same
Merkle root with different Merkle trees.
  • Loading branch information
behzadnouri authored Jan 23, 2025
1 parent 4f98820 commit 1dd5b6b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ledger/src/shred/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ impl ShredCode {
macro_rules! impl_merkle_shred {
($variant:ident) => {
// proof_size is the number of merkle proof entries.
#[inline]
fn proof_size(&self) -> Result<u8, Error> {
match self.common_header.shred_variant {
ShredVariant::$variant { proof_size, .. } => Ok(proof_size),
Expand Down Expand Up @@ -905,13 +906,14 @@ pub(super) fn recover(
return Err(Error::InvalidMerkleRoot);
}
let set_merkle_proof = move |(index, (mut shred, mask)): (_, (Shred, _))| {
let proof = make_merkle_proof(index, num_shards, &tree);
if mask {
if shred.merkle_proof()?.map(Some).ne(proof.map(Result::ok)) {
return Err(Error::InvalidMerkleProof);
}
debug_assert!({
let proof = make_merkle_proof(index, num_shards, &tree);
shred.merkle_proof()?.map(Some).eq(proof.map(Result::ok))
});
Ok(None)
} else {
let proof = make_merkle_proof(index, num_shards, &tree);
shred.set_merkle_proof(proof)?;
// Already sanitized after reconstruct.
debug_assert_matches!(shred.sanitize(), Ok(()));
Expand Down

0 comments on commit 1dd5b6b

Please sign in to comment.