mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-07 00:03:10 +00:00
Fix hash_or_noop in Merkle proof.
This commit is contained in:
parent
645d45f227
commit
1d013b95dd
@ -32,7 +32,7 @@ pub(crate) fn verify_merkle_proof<F: RichField, H: Hasher<F>>(
|
||||
proof: &MerkleProof<F, H>,
|
||||
) -> Result<()> {
|
||||
let mut index = leaf_index;
|
||||
let mut current_digest = H::hash_no_pad(&leaf_data);
|
||||
let mut current_digest = H::hash_or_noop(&leaf_data);
|
||||
for &sibling_digest in proof.siblings.iter() {
|
||||
let bit = index & 1;
|
||||
index >>= 1;
|
||||
|
||||
@ -46,6 +46,17 @@ pub trait Hasher<F: RichField>: Sized + Clone + Debug + Eq + PartialEq {
|
||||
Self::hash_no_pad(&padded_input)
|
||||
}
|
||||
|
||||
/// Hash the slice if necessary to reduce its length to ~256 bits. If it already fits, this is a
|
||||
/// no-op.
|
||||
fn hash_or_noop(inputs: &[F]) -> Self::Hash {
|
||||
if inputs.len() <= 4 {
|
||||
let inputs_bytes = HashOut::from_partial(inputs).to_bytes();
|
||||
Self::Hash::from_bytes(&inputs_bytes)
|
||||
} else {
|
||||
Self::hash_no_pad(inputs)
|
||||
}
|
||||
}
|
||||
|
||||
fn two_to_one(left: Self::Hash, right: Self::Hash) -> Self::Hash;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user