diff --git a/dusk-merkle/Cargo.toml b/dusk-merkle/Cargo.toml index cdefd28..b33f7d6 100644 --- a/dusk-merkle/Cargo.toml +++ b/dusk-merkle/Cargo.toml @@ -12,6 +12,7 @@ authors = [ ] edition = "2021" +rust-version = "1.85" license = "MPL-2.0" [dependencies] diff --git a/dusk-merkle/README.md b/dusk-merkle/README.md index 4408cf1..9755c93 100644 --- a/dusk-merkle/README.md +++ b/dusk-merkle/README.md @@ -90,8 +90,6 @@ For the opening proof creation in zero-knowledge: cargo bench -p poseidon-merkle --features zk ``` -This requires a nightly toolchain. - ## Implementations A merkle tree using the poseidon hash function for aggregation and plonk to diff --git a/dusk-merkle/src/node.rs b/dusk-merkle/src/node.rs index dcc6fe1..c6cdaf1 100644 --- a/dusk-merkle/src/node.rs +++ b/dusk-merkle/src/node.rs @@ -32,7 +32,7 @@ where } } - pub(crate) fn item(&self) -> Ref { + pub(crate) fn item(&self) -> Ref<'_, T> { // a leaf will always have a computed item, so we never go into it if self.item.borrow().is_none() { // compute our item, recursing into the children. diff --git a/dusk-merkle/src/tree.rs b/dusk-merkle/src/tree.rs index d01439c..d2c2a35 100644 --- a/dusk-merkle/src/tree.rs +++ b/dusk-merkle/src/tree.rs @@ -91,7 +91,7 @@ where /// the output of the walker function. The function should return `true` or /// `false`, indicating whether the iterator should continue along the /// tree's path. - pub fn walk(&self, walker: W) -> Walk + pub fn walk(&self, walker: W) -> Walk<'_, T, W, H, A> where W: Fn(&T) -> bool, { @@ -99,12 +99,12 @@ where } /// Get the root of the merkle tree. - pub fn root(&self) -> Ref { + pub fn root(&self) -> Ref<'_, T> { self.root.item() } /// Returns the root of the smallest sub-tree that holds all the leaves. - pub fn smallest_subtree(&self) -> (Ref, usize) { + pub fn smallest_subtree(&self) -> (Ref<'_, T>, usize) { let mut smallest_node = &self.root; let mut height = H; loop { diff --git a/dusk-merkle/src/walk.rs b/dusk-merkle/src/walk.rs index 80d7c6f..ec59d9c 100644 --- a/dusk-merkle/src/walk.rs +++ b/dusk-merkle/src/walk.rs @@ -96,9 +96,8 @@ where let child = child.as_ref(); if (self.walker)(&*child.item()) { self.path[h] = Some(child); - match self.advance(child, h + 1) { - Some(item) => return Some(item), - None => continue, + if let Some(item) = self.advance(child, h + 1) { + return Some(item); } } } diff --git a/poseidon-merkle/Cargo.toml b/poseidon-merkle/Cargo.toml index 7ed75a4..48f5a28 100644 --- a/poseidon-merkle/Cargo.toml +++ b/poseidon-merkle/Cargo.toml @@ -12,14 +12,15 @@ authors = [ ] edition = "2021" +rust-version = "1.85" license = "MPL-2.0" [dependencies] dusk-bytes = "0.1" dusk-merkle = "0.5" -dusk-poseidon = "0.41" +dusk-poseidon = "0.42.0-rc.0" dusk-bls12_381 = { version = "0.14", default-features = false } -dusk-plonk = { version = "0.21", optional = true, default-features = false } +dusk-plonk = { version = "0.22.0-rc.0", optional = true, default-features = false } rkyv = { version = "0.7", optional = true, default-features = false } bytecheck = { version = "0.6", optional = true, default-features = false } diff --git a/poseidon-merkle/benches/poseidon.rs b/poseidon-merkle/benches/poseidon.rs index 62a930b..947eb2d 100644 --- a/poseidon-merkle/benches/poseidon.rs +++ b/poseidon-merkle/benches/poseidon.rs @@ -7,16 +7,14 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; use dusk_bls12_381::BlsScalar; -use dusk_poseidon::sponge::hash as poseidon_hash; +use dusk_poseidon::{Domain, Hash}; use poseidon_merkle::{Item, Tree}; use rand::{RngCore, SeedableRng}; -// set height and arity of the poseidon merkle tree const HEIGHT: usize = 17; -const ARITY: usize = 4; -type PoseidonTree = Tree<(), HEIGHT, ARITY>; +type PoseidonTree = Tree<(), HEIGHT>; type PoseidonItem = Item<()>; fn bench_poseidon(c: &mut Criterion) { @@ -26,7 +24,14 @@ fn bench_poseidon(c: &mut Criterion) { c.bench_function("poseidon insertion", |b| { b.iter(|| { let pos = rng.next_u64() % u32::MAX as u64; - let hash = poseidon_hash(&[BlsScalar::from(pos)]); + + let hash = Hash::digest(Domain::Other, &[BlsScalar::from(pos)]) + .into_iter() + .next() + .expect( + "Poseidon hash output must contain at least one element", + ); + let item = PoseidonItem { hash, data: () }; tree.insert(black_box(pos), black_box(item)); }) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index e4ada99..73cb934 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-11-10" +channel = "stable" components = ["rustfmt", "clippy"] diff --git a/rustfmt.toml b/rustfmt.toml index 043b7dc..df99c69 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,2 +1 @@ -wrap_comments = true max_width = 80