fn verify_proof<T>(
    element_index: u64,
    element: T,
    hasher: PedersenHasher<Engine>,
    merkle_proof: Vec<(Fr, bool)>,
    expected_root: Fr,
) where
    T: GetBits,
{
    // To check the proof, we fold it starting from the hash of the value
    // and updating with the hashes from the proof.
    // We should obtain the root hash at the end if the proof is correct.
    let mut proof_index = 0;
    let mut aggregated_hash = hasher.hash_bits(element.get_bits_le());
    for (level, (hash, dir)) in merkle_proof.into_iter().enumerate() {
        let (lhs, rhs) = if dir {
            proof_index |= 1 << level;
            (hash, aggregated_hash)
        } else {
            (aggregated_hash, hash)
        };

        aggregated_hash = hasher.compress(&lhs, &rhs, level);
    }

    assert_eq!(
        proof_index, element_index,
        "Got unexpected element index while verifying the proof"
    );
    assert_eq!(
        aggregated_hash, expected_root,
        "Got unexpected root hash while verifying the proof"
    );
}
/// Applies the proof for the element and compares it against the expected
/// root hash.
Applies the proof for the element and compares it against the expected
root hash.
Applies the proof for the element and compares it against the expected root hash .
fn verify_proof<T>(
    element_index: u64,
    element: T,
    hasher: PedersenHasher<Engine>,
    merkle_proof: Vec<(Fr, bool)>,
    expected_root: Fr,
) where
    T: GetBits,
{
    // To check the proof, we fold it starting from the hash of the value
    // and updating with the hashes from the proof.
    // We should obtain the root hash at the end if the proof is correct.
    let mut proof_index = 0;
    let mut aggregated_hash = hasher.hash_bits(element.get_bits_le());
    for (level, (hash, dir)) in merkle_proof.into_iter().enumerate() {
        let (lhs, rhs) = if dir {
            proof_index |= 1 << level;
            (hash, aggregated_hash)
        } else {
            (aggregated_hash, hash)
        };
        aggregated_hash = hasher.compress(&lhs, &rhs, level);
    }
    assert_eq!(
        proof_index, element_index,
        "Got unexpected element index while verifying the proof"
    );
    assert_eq!(
        aggregated_hash, expected_root,
        "Got unexpected root hash while verifying the proof"
    );
}
fn verify_proof < T > ( element_index : u64 , element : T , hasher : PedersenHasher < Engine > , merkle_proof : Vec < ( Fr , bool ) > , expected_root : Fr , ) where T : GetBits , { // To check the proof, we fold it starting from the hash of the value // and updating with the hashes from the proof. // We should obtain the root hash at the end if the proof is correct. let mut proof_index = 0 ; let mut aggregated_hash = hasher . hash_bits ( element . get_bits_le ( ) ) ; for ( level , ( hash , dir ) ) in merkle_proof . into_iter ( ) . enumerate ( ) { let ( lhs , rhs ) = if dir { proof_index |= 1 << level ; ( hash , aggregated_hash ) } else { ( aggregated_hash , hash ) } ; aggregated_hash = hasher . compress ( & lhs , & rhs , level ) ; } assert_eq ! ( proof_index element_index " " ) ; assert_eq ! ( aggregated_hash expected_root " " ) ; }
Applies the proof for the element and compares it against the expected
root hash.
Applies the proof for the element and compares it against the expected root hash .
element_index
u64
element
T
hasher
PedersenHasher<Engine>
merkle_proof
Vec<(Fr, bool)>
expected_root
Fr