diff --git a/Cargo.toml b/Cargo.toml index 67ffefde..495e8a67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,6 @@ rustdoc-args = ["--cfg", "docsrs", "--html-in-header", "katex-header.html"] aes = "0.8" bitvec = "1" blake2b_simd = "1" -bridgetree = { version = "0.2", optional = true } ff = "0.13" fpe = "0.6" group = { version = "0.13", features = ["wnaf-memuse"] } @@ -72,7 +71,7 @@ bench = false default = ["multicore"] multicore = ["halo2_proofs/multicore"] dev-graph = ["halo2_proofs/dev-graph", "image", "plotters"] -test-dependencies = ["bridgetree", "proptest"] +test-dependencies = ["proptest"] [[bench]] name = "note_decryption" @@ -93,5 +92,5 @@ debug = true debug = true [patch.crates-io] -bridgetree = { git = "https://github.com/zcash/incrementalmerkletree.git", rev = "ea1686e8f8f6c1e41aa97251a7eb4fadfd33df47" } -incrementalmerkletree = { git = "https://github.com/zcash/incrementalmerkletree.git", rev = "ea1686e8f8f6c1e41aa97251a7eb4fadfd33df47" } +bridgetree = { git = "https://github.com/zcash/incrementalmerkletree.git", rev = "62f0c9039b0bee94c16c40c272e19c5922290664" } +incrementalmerkletree = { git = "https://github.com/zcash/incrementalmerkletree.git", rev = "62f0c9039b0bee94c16c40c272e19c5922290664" } diff --git a/src/builder.rs b/src/builder.rs index 27628695..b2d747b7 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -759,8 +759,8 @@ impl OutputView for RecipientInfo { #[cfg(any(test, feature = "test-dependencies"))] #[cfg_attr(docsrs, doc(cfg(feature = "test-dependencies")))] pub mod testing { - use bridgetree::BridgeTree; use core::fmt::Debug; + use incrementalmerkletree::{frontier::Frontier, Hashable}; use rand::{rngs::StdRng, CryptoRng, SeedableRng}; use proptest::collection::vec; @@ -852,23 +852,26 @@ pub mod testing { ), rng_seed in prop::array::uniform32(prop::num::u8::ANY) ) -> ArbitraryBundleInputs { - const MERKLE_DEPTH_ORCHARD: u8 = crate::constants::MERKLE_DEPTH_ORCHARD as u8; - let mut tree = BridgeTree::::new(100, 0); + use crate::constants::MERKLE_DEPTH_ORCHARD; + let mut frontier = Frontier::::empty(); let mut notes_and_auth_paths: Vec<(Note, MerklePath)> = Vec::new(); for note in notes.iter() { let leaf = MerkleHashOrchard::from_cmx(¬e.commitment().into()); - tree.append(leaf); - let position = tree.mark().expect("tree is not empty"); + frontier.append(leaf); - let path = MerklePath::from((position, tree.witness(position, 0).expect("we just witnessed the path"))); - notes_and_auth_paths.push((*note, path)); + let path = frontier + .witness(|addr| Some(::empty_root(addr.level()))) + .ok() + .flatten() + .expect("we can always construct a correct Merkle path"); + notes_and_auth_paths.push((*note, path.into())); } ArbitraryBundleInputs { rng: StdRng::from_seed(rng_seed), sk, - anchor: tree.root(0).unwrap().into(), + anchor: frontier.root().into(), notes: notes_and_auth_paths, recipient_amounts } diff --git a/src/tree.rs b/src/tree.rs index 59adefdb..ba68265a 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -95,6 +95,16 @@ impl From<(incrementalmerkletree::Position, Vec)> for MerkleP } } +impl From> for MerklePath { + fn from(path: incrementalmerkletree::MerklePath) -> Self { + let position: u64 = path.position().into(); + Self { + position: position as u32, + auth_path: path.path_elems().try_into().unwrap(), + } + } +} + impl MerklePath { /// Generates a dummy Merkle path for use in dummy spent notes. pub(crate) fn dummy(mut rng: &mut impl RngCore) -> Self { @@ -243,11 +253,8 @@ impl<'de> Deserialize<'de> for MerkleHashOrchard { } } -/// Generators for property testing. -#[cfg(any(test, feature = "test-dependencies"))] -#[cfg_attr(docsrs, doc(cfg(feature = "test-dependencies")))] -pub mod testing { - #[cfg(test)] +#[cfg(test)] +mod tests { use { crate::tree::{MerkleHashOrchard, EMPTY_ROOTS}, bridgetree::{BridgeTree, Frontier as BridgeFrontier}, @@ -264,7 +271,7 @@ pub mod testing { assert_eq!(tv_empty_roots[height], root.to_bytes()); } - let mut tree = BridgeTree::::new(100, 0); + let mut tree = BridgeTree::::new(100); for (i, tv) in crate::test_vectors::merkle_path::test_vectors() .into_iter() .enumerate() @@ -272,7 +279,7 @@ pub mod testing { let cmx = MerkleHashOrchard::from_bytes(&tv.leaves[i]).unwrap(); tree.append(cmx); let position = tree.mark().expect("tree is not empty"); - assert_eq!(position, i.into()); + assert_eq!(position, (i as u64).into()); let root = tree.root(0).unwrap(); assert_eq!(root.0, pallas::Base::from_repr(tv.root).unwrap()); diff --git a/tests/builder.rs b/tests/builder.rs index eb181783..8cda6e70 100644 --- a/tests/builder.rs +++ b/tests/builder.rs @@ -71,7 +71,7 @@ fn bundle_chain() { // Use the tree with a single leaf. let cmx: ExtractedNoteCommitment = note.commitment().into(); let leaf = MerkleHashOrchard::from_cmx(&cmx); - let mut tree = BridgeTree::::new(100, 0); + let mut tree = BridgeTree::::new(100); tree.append(leaf); let position = tree.mark().unwrap(); let root = tree.root(0).unwrap();