fn prove()

in crypto/src/merkle/tests.rs [95:131]


fn prove() {
    // depth 4
    let leaves = Digest256::bytes_as_digests(&LEAVES4).to_vec();
    let tree = MerkleTree::<Blake3_256>::new(leaves.clone()).unwrap();

    let proof = vec![leaves[1], leaves[0], hash_2x1(leaves[2], leaves[3])];
    assert_eq!(proof, tree.prove(1).unwrap());

    let proof = vec![leaves[2], leaves[3], hash_2x1(leaves[0], leaves[1])];
    assert_eq!(proof, tree.prove(2).unwrap());

    // depth 5
    let leaves = Digest256::bytes_as_digests(&LEAVES8).to_vec();
    let tree = MerkleTree::<Blake3_256>::new(leaves.clone()).unwrap();

    let proof = vec![
        leaves[1],
        leaves[0],
        hash_2x1(leaves[2], leaves[3]),
        hash_2x1(
            hash_2x1(leaves[4], leaves[5]),
            hash_2x1(leaves[6], leaves[7]),
        ),
    ];
    assert_eq!(proof, tree.prove(1).unwrap());

    let proof = vec![
        leaves[6],
        leaves[7],
        hash_2x1(leaves[4], leaves[5]),
        hash_2x1(
            hash_2x1(leaves[0], leaves[1]),
            hash_2x1(leaves[2], leaves[3]),
        ),
    ];
    assert_eq!(proof, tree.prove(6).unwrap());
}