/// Compute Merkle root and path
///
/// Leaves list argument unusable
Compute Merkle root and path
Leaves list argument unusable
Compute Merkle root and path Leaves list argument unusable
fn merkleize<A: 'static + PoseidonArity>(
    depth: usize,
    mut list: &mut [bls12_381::Scalar],
    mut index: usize,
    mut f: impl FnMut(CopathPoint<A>) -> (),
) -> bls12_381::Scalar {
    assert!( list.len() > 0 );
    // let mut tail = 0usize;
    // if list.len().count_ones() != 1 {
    //    let s = 0usize.leadng_zeros() - list.len().leading_zeros() - 1;
    //     tail = (1usize << s) - list.len();
    // }
    use typenum::marker_traits::Unsigned;
    let arity = A::to_usize();
    for depth_to_bottom in 0..depth {
        let chunk_index = index / arity;
        let index_within_chunk = index % arity;
        let chunk = list
            .chunks(arity)
            .nth(chunk_index)
            .expect("leaf index out of range");
        assert!(index_within_chunk < chunk.len()); // last chunk may not be exact
        let remainder_len = arity - chunk.len();
        let siblings: Vec<_> = chunk
            .into_iter()
            .enumerate()
            .filter(|(i, _)| *i != index_within_chunk)
            .map(|(_, x)| Some(x.clone()))
            .chain(std::iter::repeat(None).take(remainder_len)) // last chunk may not be exact
            .collect();
        assert!(siblings.len() == arity - 1); // element at index is excluded
        f(CopathPoint {
            current_selection: Some(index_within_chunk),
            siblings,
            _a: Default::default()
        });
        let list =  &mut list.chunks(arity).map(|chunk| {
            let remainder_len = arity - chunk.len();
            let chunk: Vec<_> = chunk.iter()
                .map(|x| Some(x.clone()))
                .chain(std::iter::repeat(None).take(remainder_len)) // last chunk may not be exact
                .collect();
            auth_hash::<A>(&chunk)
        }).collect::<Vec<_>>();
        index /= arity;
    }
    list[0].clone()
}
fn merkleize < A : ' static + PoseidonArity > ( depth : usize , mut list : & mut [ bls12_381 :: Scalar ] , mut index : usize , mut f : impl FnMut ( CopathPoint < A > ) -> ( ) , ) -> bls12_381 :: Scalar { assert ! ( list len ( ) 0 ) ; // let mut tail = 0usize; // if list.len().count_ones() != 1 { //    let s = 0usize.leadng_zeros() - list.len().leading_zeros() - 1; //     tail = (1usize << s) - list.len(); // } use typenum :: marker_traits :: Unsigned ; let arity = A :: to_usize ( ) ; for depth_to_bottom in 0 .. depth { let chunk_index = index / arity ; let index_within_chunk = index % arity ; let chunk = list . chunks ( arity ) . nth ( chunk_index ) . expect ( " " ) ; assert ! ( index_within_chunk chunk len ( ) ) ; // last chunk may not be exact let remainder_len = arity - chunk . len ( ) ; let siblings : Vec < _ > = chunk . into_iter ( ) . enumerate ( ) . filter ( | ( i , _ ) | * i != index_within_chunk ) . map ( | ( _ , x ) | Some ( x . clone ( ) ) ) . chain ( std :: iter :: repeat ( None ) . take ( remainder_len ) ) // last chunk may not be exact . collect ( ) ; assert ! ( siblings len ( ) arity 1 ) ; // element at index is excluded f ( CopathPoint { current_selection : Some ( index_within_chunk ) , siblings , _a : Default :: default ( ) } ) ; let list = & mut list . chunks ( arity ) . map ( | chunk | { let remainder_len = arity - chunk . len ( ) ; let chunk : Vec < _ > = chunk . iter ( ) . map ( | x | Some ( x . clone ( ) ) ) . chain ( std :: iter :: repeat ( None ) . take ( remainder_len ) ) // last chunk may not be exact . collect ( ) ; auth_hash :: < A > ( & chunk ) } ) . collect :: < Vec < _ > > ( ) ; index /= arity ; } list [ 0 ] . clone ( ) }
Compute Merkle root and path
Leaves list argument unusable
Compute Merkle root and path Leaves list argument unusable
depth
usize
list
&mut [bls12_381::Scalar]
index
usize
f
impl FnMut(CopathPoint<A>) -> ()