From df2b6e76b70d8b0f3dde1cbecd1b537d604835a9 Mon Sep 17 00:00:00 2001 From: wborgeaud Date: Wed, 29 Dec 2021 16:54:27 +0100 Subject: [PATCH] Move permutations to their specific files --- plonky2/src/hash/gmimc.rs | 9 ++++++++- plonky2/src/hash/hashing.rs | 13 ------------- plonky2/src/hash/poseidon.rs | 9 ++++++++- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/plonky2/src/hash/gmimc.rs b/plonky2/src/hash/gmimc.rs index ffe31fbd..3492e08f 100644 --- a/plonky2/src/hash/gmimc.rs +++ b/plonky2/src/hash/gmimc.rs @@ -5,7 +5,7 @@ use unroll::unroll_for_loops; use crate::gates::gmimc::GMiMCGate; use crate::hash::hash_types::{HashOut, RichField}; -use crate::hash::hashing::{compress, hash_n_to_hash, GMiMCPermutation, SPONGE_WIDTH}; +use crate::hash::hashing::{compress, hash_n_to_hash, PlonkyPermutation, SPONGE_WIDTH}; use crate::iop::target::{BoolTarget, Target}; use crate::plonk::circuit_builder::CircuitBuilder; use crate::plonk::config::{AlgebraicHasher, Hasher}; @@ -93,6 +93,13 @@ impl GMiMC<12> for GoldilocksField { const ROUND_CONSTANTS: [u64; NUM_ROUNDS] = GOLDILOCKS_ROUND_CONSTANTS; } +pub struct GMiMCPermutation; +impl PlonkyPermutation for GMiMCPermutation { + fn permute(input: [F; SPONGE_WIDTH]) -> [F; SPONGE_WIDTH] { + F::gmimc_permute(input) + } +} + #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct GMiMCHash; impl Hasher for GMiMCHash { diff --git a/plonky2/src/hash/hashing.rs b/plonky2/src/hash/hashing.rs index 45ae01dd..2f6a725c 100644 --- a/plonky2/src/hash/hashing.rs +++ b/plonky2/src/hash/hashing.rs @@ -97,19 +97,6 @@ pub trait PlonkyPermutation { fn permute(input: [F; SPONGE_WIDTH]) -> [F; SPONGE_WIDTH]; } -pub struct PoseidonPermutation; -impl PlonkyPermutation for PoseidonPermutation { - fn permute(input: [F; SPONGE_WIDTH]) -> [F; SPONGE_WIDTH] { - F::poseidon(input) - } -} -pub struct GMiMCPermutation; -impl PlonkyPermutation for GMiMCPermutation { - fn permute(input: [F; SPONGE_WIDTH]) -> [F; SPONGE_WIDTH] { - F::gmimc_permute(input) - } -} - /// If `pad` is enabled, the message is padded using the pad10*1 rule. In general this is required /// for the hash to be secure, but it can safely be disabled in certain cases, like if the input /// length is fixed. diff --git a/plonky2/src/hash/poseidon.rs b/plonky2/src/hash/poseidon.rs index bacb966b..606dfd13 100644 --- a/plonky2/src/hash/poseidon.rs +++ b/plonky2/src/hash/poseidon.rs @@ -9,7 +9,7 @@ use crate::gates::gate::Gate; use crate::gates::poseidon::PoseidonGate; use crate::gates::poseidon_mds::PoseidonMdsGate; use crate::hash::hash_types::{HashOut, RichField}; -use crate::hash::hashing::{compress, hash_n_to_hash, PoseidonPermutation, SPONGE_WIDTH}; +use crate::hash::hashing::{compress, hash_n_to_hash, PlonkyPermutation, SPONGE_WIDTH}; use crate::iop::ext_target::ExtensionTarget; use crate::iop::target::{BoolTarget, Target}; use crate::plonk::circuit_builder::CircuitBuilder; @@ -618,6 +618,13 @@ pub trait Poseidon: PrimeField { } } +pub struct PoseidonPermutation; +impl PlonkyPermutation for PoseidonPermutation { + fn permute(input: [F; SPONGE_WIDTH]) -> [F; SPONGE_WIDTH] { + F::poseidon(input) + } +} + /// Poseidon hash function. #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct PoseidonHash;