diff --git a/README.md b/README.md index a152c94..9b1efd6 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/benches/iterated_perm.rs b/benches/iterated_perm.rs index 9da216f..210dd69 100644 --- a/benches/iterated_perm.rs +++ b/benches/iterated_perm.rs @@ -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); } //------------------------------------------------------------------------------ diff --git a/src/hash.rs b/src/hash.rs index 80911a3..de72bb0 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -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), }; } diff --git a/src/skyscraper/permutation.rs b/src/skyscraper/permutation.rs index 30cb9dd..a7dd194 100644 --- a/src/skyscraper/permutation.rs +++ b/src/skyscraper/permutation.rs @@ -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);