pub fn verify(root: &H256, datum: &H256, proof: &[H256], index: usize, leaf_size: usize) -> bool {
    let height = proof.len();
    let leaf_num = 2usize.pow(height as u32) - (2usize.pow(height as u32+1) - 1 - leaf_size);
    let mut cur_index = index;
    let mut sequence = 0;
    let mut ctx = digest::Context::new(&digest::SHA256);
    let mut trace = datum.clone();
    for i in 0..height {
        let group = (cur_index - sequence)/2;
        if cur_index % 2 == 1 {
            ctx.update(proof[i].as_ref());
            ctx.update(trace.as_ref());
        }
        else {
            ctx.update(trace.as_ref());
            ctx.update(proof[i].as_ref());
        }
        if i == 0 {
            sequence += leaf_num;
        }
        else {
            sequence += 2usize.pow(height as u32 - i as u32);
        }
        cur_index = sequence + group;
        trace = ctx.clone().finish().into();
    }
    return trace == *root;
}
/// Verify that the datum hash with a vector of proofs will produce the Merkle root. Also need the
/// index of datum and `leaf_size`, the total number of leaves.
Verify that the datum hash with a vector of proofs will produce the Merkle root. Also need the
index of datum and `leaf_size`, the total number of leaves.
Verify that the datum hash with a vector of proofs will produce the Merkle root . Also need the index of datum and ` leaf_size ` the total number of leaves .
pub fn verify(root: &H256, datum: &H256, proof: &[H256], index: usize, leaf_size: usize) -> bool {
    let height = proof.len();
    let leaf_num = 2usize.pow(height as u32) - (2usize.pow(height as u32+1) - 1 - leaf_size);
    let mut cur_index = index;
    let mut sequence = 0;
    let mut ctx = digest::Context::new(&digest::SHA256);
    let mut trace = datum.clone();
    for i in 0..height {
        let group = (cur_index - sequence)/2;
        if cur_index % 2 == 1 {
            ctx.update(proof[i].as_ref());
            ctx.update(trace.as_ref());
        }
        else {
            ctx.update(trace.as_ref());
            ctx.update(proof[i].as_ref());
        }
        if i == 0 {
            sequence += leaf_num;
        }
        else {
            sequence += 2usize.pow(height as u32 - i as u32);
        }
        cur_index = sequence + group;
        trace = ctx.clone().finish().into();
    }
    return trace == *root;
}
pub fn verify ( root : & H256 , datum : & H256 , proof : & [ H256 ] , index : usize , leaf_size : usize ) -> bool { let height = proof . len ( ) ; let leaf_num = 2usize . pow ( height as u32 ) - ( 2usize . pow ( height as u32 + 1 ) - 1 - leaf_size ) ; let mut cur_index = index ; let mut sequence = 0 ; let mut ctx = digest :: Context :: new ( & digest :: SHA256 ) ; let mut trace = datum . clone ( ) ; for i in 0 .. height { let group = ( cur_index - sequence ) / 2 ; if cur_index % 2 == 1 { ctx . update ( proof [ i ] . as_ref ( ) ) ; ctx . update ( trace . as_ref ( ) ) ; } else { ctx . update ( trace . as_ref ( ) ) ; ctx . update ( proof [ i ] . as_ref ( ) ) ; } if i == 0 { sequence += leaf_num ; } else { sequence += 2usize . pow ( height as u32 - i as u32 ) ; } cur_index = sequence + group ; trace = ctx . clone ( ) . finish ( ) . into ( ) ; } return trace == * root ; }
Verify that the datum hash with a vector of proofs will produce the Merkle root.
Verify that the datum hash with a vector of proofs will produce the Merkle root .
root
&H256
datum
&H256
proof
&[H256]
index
usize
leaf_size
usize