Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dusk-merkle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ authors = [
]

edition = "2021"
rust-version = "1.85"
license = "MPL-2.0"

[dependencies]
Expand Down
2 changes: 0 additions & 2 deletions dusk-merkle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dusk-merkle/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ where
}
}

pub(crate) fn item(&self) -> Ref<T> {
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.
Expand Down
6 changes: 3 additions & 3 deletions dusk-merkle/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,20 @@ 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<W>(&self, walker: W) -> Walk<T, W, H, A>
pub fn walk<W>(&self, walker: W) -> Walk<'_, T, W, H, A>
where
W: Fn(&T) -> bool,
{
Walk::new(self, walker)
}

/// Get the root of the merkle tree.
pub fn root(&self) -> Ref<T> {
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<T>, usize) {
pub fn smallest_subtree(&self) -> (Ref<'_, T>, usize) {
let mut smallest_node = &self.root;
let mut height = H;
loop {
Expand Down
5 changes: 2 additions & 3 deletions dusk-merkle/src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions poseidon-merkle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
15 changes: 10 additions & 5 deletions poseidon-merkle/benches/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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));
})
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-11-10"
channel = "stable"
components = ["rustfmt", "clippy"]
1 change: 0 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
wrap_comments = true
max_width = 80