Merge pull request #198 from zcash/merkle-path-test-vectors

Add Merkle path test vectors
This commit is contained in:
Kris Nuttycombe 2021-09-14 07:22:28 -06:00 committed by GitHub
commit 4488288ac0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7131 additions and 1 deletions

View File

@ -1,3 +1,4 @@
pub(crate) mod commitment_tree;
pub(crate) mod keys;
pub(crate) mod merkle_path;
pub(crate) mod note_encryption;

File diff suppressed because it is too large Load Diff

View File

@ -277,7 +277,8 @@ impl<'de> Deserialize<'de> for MerkleCrhOrchardOutput {
pub mod testing {
#[cfg(test)]
use incrementalmerkletree::{
bridgetree::Frontier as BridgeFrontier, Altitude, Frontier, Hashable,
bridgetree::{BridgeTree, Frontier as BridgeFrontier},
Altitude, Frontier, Hashable, Tree,
};
use std::convert::TryInto;
@ -305,6 +306,35 @@ pub mod testing {
for (height, root) in EMPTY_ROOTS.iter().enumerate() {
assert_eq!(tv_empty_roots[height], root.to_bytes());
}
let mut tree = BridgeTree::<MerkleCrhOrchardOutput, 4>::new(100);
for (i, tv) in crate::test_vectors::merkle_path::test_vectors()
.into_iter()
.enumerate()
{
let cmx = MerkleCrhOrchardOutput::from_bytes(&tv.leaves[i]).unwrap();
tree.append(&cmx);
tree.witness();
assert_eq!(tree.root().0, pallas::Base::from_bytes(&tv.root).unwrap());
// Check paths for all leaves up to this point. The test vectors include paths
// for not-yet-appended leaves (using UNCOMMITTED_ORCHARD as the leaf value),
// but BridgeTree doesn't encode these.
for j in 0..=i {
let leaf = MerkleCrhOrchardOutput::from_bytes(&tv.leaves[j]).unwrap();
assert_eq!(
tree.authentication_path(&leaf),
Some((
j.try_into().unwrap(),
tv.paths[j]
.iter()
.map(|v| MerkleCrhOrchardOutput::from_bytes(v).unwrap())
.collect()
))
);
}
}
}
prop_compose! {