Skip to content

Commit

Permalink
add test and benchmark for MT with PoseidonBN128Hash
Browse files Browse the repository at this point in the history
  • Loading branch information
dloghin committed Feb 28, 2024
1 parent 065b6f6 commit 822029c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions plonky2/benches/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use plonky2::hash::hash_types::RichField;
use plonky2::hash::keccak::KeccakHash;
use plonky2::hash::merkle_tree::MerkleTree;
use plonky2::hash::poseidon::PoseidonHash;
use plonky2::hash::poseidon_bn128::PoseidonBN128Hash;
use plonky2::plonk::config::Hasher;
use tynm::type_name;

Expand All @@ -31,6 +32,7 @@ pub(crate) fn bench_merkle_tree<F: RichField, H: Hasher<F>>(c: &mut Criterion) {
fn criterion_benchmark(c: &mut Criterion) {
bench_merkle_tree::<GoldilocksField, PoseidonHash>(c);
bench_merkle_tree::<GoldilocksField, KeccakHash<25>>(c);
bench_merkle_tree::<GoldilocksField, PoseidonBN128Hash>(c);
}

criterion_group!(benches, criterion_benchmark);
Expand Down
16 changes: 16 additions & 0 deletions plonky2/src/hash/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ mod tests {
use super::*;
use crate::field::extension::Extendable;
use crate::hash::merkle_proofs::verify_merkle_proof_to_cap;
use crate::hash::poseidon_bn128::PoseidonBN128GoldilocksConfig;
use crate::plonk::config::{GenericConfig, KeccakGoldilocksConfig, PoseidonGoldilocksConfig};

fn random_data<F: RichField>(n: usize, k: usize) -> Vec<Vec<F>> {
Expand Down Expand Up @@ -669,4 +670,19 @@ mod tests {

Ok(())
}

#[test]
fn test_merkle_trees_poseidonbn128() -> Result<()> {
const D: usize = 2;
type C = PoseidonBN128GoldilocksConfig;
type F = <C as GenericConfig<D>>::F;

let log_n = 12;
let n = 1 << log_n;
let leaves = random_data::<F>(n, 7);

verify_all_leaves::<F, C, D>(leaves, 1)?;

Ok(())
}
}

0 comments on commit 822029c

Please sign in to comment.