Skip to content

Commit

Permalink
Merge pull request #2399 from o1-labs/dw/bench-poseidon-master
Browse files Browse the repository at this point in the history
mina_poseidon: bench poseidon block cipher [master]
  • Loading branch information
volhovm authored Jul 9, 2024
2 parents 834c31c + b563f2a commit bb0c15f
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 3 deletions.
80 changes: 77 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions poseidon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ ocaml = { workspace = true, optional = true }
ocaml-gen = { workspace = true, optional = true }

[dev-dependencies]
criterion = "0.3"
serde_json.workspace = true
hex.workspace = true
ark-serialize.workspace = true

[features]
default = []
ocaml_types = [ "ocaml", "ocaml-gen", ]

[[bench]]
name = "poseidon"
harness = false
37 changes: 37 additions & 0 deletions poseidon/benches/poseidon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use mina_poseidon::{
constants::{PlonkSpongeConstantsKimchi, PlonkSpongeConstantsLegacy},
pasta::{fp_kimchi as SpongeParametersKimchi, fp_legacy as SpongeParametersLegacy},
permutation::poseidon_block_cipher,
};
use rand::{rngs::StdRng, thread_rng, Rng, SeedableRng};

use ark_ff::UniformRand;
use criterion::{criterion_group, criterion_main, Criterion};
use mina_curves::pasta::Fp;

pub fn bench_poseidon_absorb_permutation_pasta_fp(c: &mut Criterion) {
// FIXME: use o1_utils test rng
let seed = thread_rng().gen();
eprintln!("Seed: {seed:?}");
let mut rng = StdRng::from_seed(seed);

let input: [Fp; 3] = std::array::from_fn(|_| Fp::rand(&mut rng));
let mut input: Vec<Fp> = Vec::from(input);

let params = SpongeParametersKimchi::static_params();
c.bench_function("poseidon_absorb_permutation kimchi", |b| {
b.iter(|| {
poseidon_block_cipher::<Fp, PlonkSpongeConstantsKimchi>(params, &mut input);
})
});

let params = SpongeParametersLegacy::static_params();
c.bench_function("poseidon_absorb_permutation legacy", |b| {
b.iter(|| {
poseidon_block_cipher::<Fp, PlonkSpongeConstantsLegacy>(params, &mut input);
})
});
}

criterion_group!(benches, bench_poseidon_absorb_permutation_pasta_fp);
criterion_main!(benches);

0 comments on commit bb0c15f

Please sign in to comment.