diff --git a/src/circuit/gadget/poseidon.rs b/src/circuit/gadget/poseidon.rs index 8bd109e5..135dfccb 100644 --- a/src/circuit/gadget/poseidon.rs +++ b/src/circuit/gadget/poseidon.rs @@ -13,7 +13,7 @@ use halo2::{ mod pow5; pub use pow5::{Pow5Chip, Pow5Config, StateWord}; -use crate::primitives::poseidon::{ConstantLength, Domain, Spec, Sponge, SpongeState, State}; +use crate::primitives::poseidon::{ConstantLength, Domain, Spec, Sponge, SpongeRate, State}; /// The set of circuit instructions required to use the Poseidon permutation. pub trait PoseidonInstructions, const T: usize, const RATE: usize>: @@ -53,11 +53,11 @@ pub trait PoseidonDuplexInstructions< layouter: &mut impl Layouter, domain: &impl Domain, initial_state: &State, - input: &SpongeState, + input: &SpongeRate, ) -> Result, Error>; /// Extracts sponge output from the given state. - fn get_output(state: &State) -> SpongeState; + fn get_output(state: &State) -> SpongeRate; } /// A word over which the Poseidon permutation operates. @@ -103,8 +103,8 @@ fn poseidon_duplex< mut layouter: impl Layouter, domain: &D, state: &mut State, - input: &SpongeState, -) -> Result, Error> { + input: &SpongeRate, +) -> Result, Error> { *state = chip.pad_and_add(&mut layouter, domain, state, input)?; *state = chip.permute(&mut layouter, state)?; Ok(PoseidonChip::get_output(state)) diff --git a/src/circuit/gadget/poseidon/pow5.rs b/src/circuit/gadget/poseidon/pow5.rs index de6d4aa6..0c509352 100644 --- a/src/circuit/gadget/poseidon/pow5.rs +++ b/src/circuit/gadget/poseidon/pow5.rs @@ -10,7 +10,7 @@ use halo2::{ use super::{PoseidonDuplexInstructions, PoseidonInstructions}; use crate::circuit::gadget::utilities::Var; -use crate::primitives::poseidon::{Domain, Mds, Spec, SpongeState, State}; +use crate::primitives::poseidon::{Domain, Mds, Spec, SpongeRate, State}; /// Configuration for a [`Pow5Chip`]. #[derive(Clone, Debug)] @@ -310,7 +310,7 @@ impl, const WIDTH: usize, const RATE: usize layouter: &mut impl Layouter, domain: &impl Domain, initial_state: &State, - input: &SpongeState, + input: &SpongeRate, ) -> Result, Error> { let config = self.config(); layouter.assign_region( @@ -386,7 +386,7 @@ impl, const WIDTH: usize, const RATE: usize ) } - fn get_output(state: &State) -> SpongeState { + fn get_output(state: &State) -> SpongeRate { state[..RATE] .iter() .map(|word| Some(word.clone())) diff --git a/src/primitives/poseidon.rs b/src/primitives/poseidon.rs index 1afe5cbe..df54d2c0 100644 --- a/src/primitives/poseidon.rs +++ b/src/primitives/poseidon.rs @@ -25,7 +25,7 @@ use grain::SboxType; pub(crate) type State = [F; T]; /// The type used to hold duplex sponge state. -pub(crate) type SpongeState = [Option; RATE]; +pub(crate) type SpongeRate = [Option; RATE]; /// The type used to hold the MDS matrix and its inverse. pub(crate) type Mds = [[F; T]; T]; @@ -126,11 +126,11 @@ pub(crate) fn permute, const T: usize, const RA fn poseidon_duplex, const T: usize, const RATE: usize>( state: &mut State, - input: &SpongeState, - pad_and_add: &dyn Fn(&mut State, &SpongeState), + input: &SpongeRate, + pad_and_add: &dyn Fn(&mut State, &SpongeRate), mds_matrix: &Mds, round_constants: &[[F; T]], -) -> SpongeState { +) -> SpongeRate { pad_and_add(state, input); permute::(state, mds_matrix, round_constants); @@ -144,8 +144,8 @@ fn poseidon_duplex, const T: usize, const RATE: #[derive(Debug)] pub(crate) enum Sponge { - Absorbing(SpongeState), - Squeezing(SpongeState), + Absorbing(SpongeRate), + Squeezing(SpongeRate), } impl Sponge { @@ -164,7 +164,7 @@ impl Sponge { pub(crate) struct Duplex, const T: usize, const RATE: usize> { sponge: Sponge, state: State, - pad_and_add: Box, &SpongeState)>, + pad_and_add: Box, &SpongeRate)>, mds_matrix: Mds, round_constants: Vec<[F; T]>, _marker: PhantomData, @@ -174,7 +174,7 @@ impl, const T: usize, const RATE: usize> Duplex /// Constructs a new duplex sponge for the given Poseidon specification. pub(crate) fn new( initial_capacity_element: F, - pad_and_add: Box, &SpongeState)>, + pad_and_add: Box, &SpongeRate)>, ) -> Self { let (round_constants, mds_matrix, _) = S::constants(); @@ -254,11 +254,11 @@ pub trait Domain: Copy + fmt::De fn initial_capacity_element(&self) -> F; /// The padding that will be added to each state word by [`Domain::pad_and_add`]. - fn padding(&self) -> SpongeState; + fn padding(&self) -> SpongeRate; /// Returns a function that will update the given state with the given input to a /// duplex permutation round, applying padding according to this domain specification. - fn pad_and_add(&self) -> Box, &SpongeState)>; + fn pad_and_add(&self) -> Box, &SpongeRate)>; } /// A Poseidon hash function used with constant input length. @@ -276,7 +276,7 @@ impl Domain SpongeState { + fn padding(&self) -> SpongeRate { // For constant-input-length hashing, padding consists of the field elements being // zero. let mut padding = [None; RATE]; @@ -286,7 +286,7 @@ impl Domain Box, &SpongeState)> { + fn pad_and_add(&self) -> Box, &SpongeRate)> { Box::new(|state, input| { // `Iterator::zip` short-circuits when one iterator completes, so this will only // mutate the rate portion of the state.