mirror of
https://github.com/logos-storage/rust-bn254-hash.git
synced 2026-01-02 13:53:09 +00:00
add benchmarks
This commit is contained in:
parent
88a662f034
commit
f9fb82ee39
@ -27,8 +27,10 @@ Single core, unoptimized, MacBook Pro M2.
|
||||
|
||||
- 1000 Poseidon2 permutations: 5.24 msec (approx 12MB/sec linear hashing)
|
||||
- 1000 Griffin permutations: 76.8 msec (appox 800k/sec linear hashing)
|
||||
- 1000 Skyscraper permutations: 207.45 µs (width=2)
|
||||
|
||||
10000 permutations:
|
||||
|
||||
- 10000 Poseidon2 permutations: 53 msec
|
||||
- 10000 Griffin permutations: 762 sec
|
||||
- 10000 Griffin permutations: 762 msec
|
||||
- 10000 Skyscraper permutations: 2.2 msec (width=2)
|
||||
|
||||
@ -22,8 +22,9 @@ fn bench_iterated_perm(c: &mut Criterion , h: Hash, n: usize) {
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
fn bench_permutations(c: &mut Criterion) {
|
||||
bench_iterated_perm(c, Hash::Poseidon2, 1000);
|
||||
bench_iterated_perm(c, Hash::Griffin , 1000);
|
||||
bench_iterated_perm(c, Hash::Poseidon2, 10000);
|
||||
bench_iterated_perm(c, Hash::Griffin , 10000);
|
||||
bench_iterated_perm(c, Hash::Skyscraper , 10000);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@ -12,6 +12,7 @@ use crate::griffin;
|
||||
pub enum Hash {
|
||||
Poseidon2,
|
||||
Griffin,
|
||||
Skyscraper
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -20,6 +21,7 @@ pub fn permute(h: Hash, s: State) -> State {
|
||||
match h {
|
||||
Hash::Poseidon2 => poseidon2::permutation::permute(s),
|
||||
Hash::Griffin => griffin::permutation::permute(s),
|
||||
Hash::Skyscraper => skyscraper::permutation::permute_state(s),
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,6 +29,7 @@ pub fn permute_inplace(h: Hash, s: &mut State){
|
||||
match h {
|
||||
Hash::Poseidon2 => poseidon2::permutation::permute_inplace(s),
|
||||
Hash::Griffin => griffin::permutation::permute_inplace(s),
|
||||
Hash::Skyscraper => skyscraper::permutation::permute_state_inplace(s),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
use ark_bn254::{Fr as F};
|
||||
use ark_ff::{BigInteger256, Field, One, PrimeField};
|
||||
use core::str::FromStr;
|
||||
use std::os::macos::raw::stat;
|
||||
use crate::skyscraper::constants::{FunctionBlock, RF1, RC, RC_RAW};
|
||||
use crate::state::State;
|
||||
|
||||
pub fn bars_inplace_mont(x: &mut F) {
|
||||
// x → two 128‐bit chunks.
|
||||
@ -118,6 +120,21 @@ pub fn permute(input: [F; 2]) -> [F; 2] {
|
||||
current_state
|
||||
}
|
||||
|
||||
/// WARNING: this ignores the z element of the state
|
||||
/// TODO: extension field
|
||||
pub fn permute_state_inplace(u: &mut State) {
|
||||
let ns = permute([u.x,u.y]);
|
||||
u.x = ns[0];
|
||||
u.y = ns[1];
|
||||
}
|
||||
|
||||
/// WARNING: this ignores the z element of the state
|
||||
/// TODO: extension field
|
||||
pub fn permute_state(mut u: State) -> State{
|
||||
permute_state_inplace(&mut u);
|
||||
u
|
||||
}
|
||||
|
||||
pub fn compress(x: F, y: F) -> F {
|
||||
let p_out = permute([x, y]);
|
||||
let out = x + p_out[0];
|
||||
@ -129,7 +146,7 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_k_permutation() {
|
||||
fn test_permutation() {
|
||||
let init = [F::from(1234u64), F::from(5678u64)];
|
||||
let init_mont = [F::new_unchecked(init[0].into_bigint()), F::new_unchecked(init[1].into_bigint())];
|
||||
let out = permute(init_mont);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user