From 1181bd6b461ea258e2fcc875ffe6a1c7469db6fa Mon Sep 17 00:00:00 2001 From: Eli Margolin Date: Tue, 8 Oct 2024 15:50:39 -0400 Subject: [PATCH 1/4] removed unneeded permutes --- crypto-primitives/src/sponge/poseidon/constraints.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crypto-primitives/src/sponge/poseidon/constraints.rs b/crypto-primitives/src/sponge/poseidon/constraints.rs index fc0409a..746eae6 100644 --- a/crypto-primitives/src/sponge/poseidon/constraints.rs +++ b/crypto-primitives/src/sponge/poseidon/constraints.rs @@ -223,7 +223,6 @@ impl CryptographicSpongeVar> for PoseidonSpo DuplexSpongeMode::Squeezing { next_squeeze_index: _, } => { - self.permute()?; self.absorb_internal(0, input.as_slice())?; } }; @@ -279,8 +278,8 @@ impl CryptographicSpongeVar> for PoseidonSpo } DuplexSpongeMode::Squeezing { next_squeeze_index } => { let mut squeeze_index = next_squeeze_index; + self.permute()?; if squeeze_index == self.parameters.rate { - self.permute()?; squeeze_index = 0; } self.squeeze_internal(squeeze_index, &mut squeezed_elems)?; From 71053a13f10762d26d8b20df29984ecd7da250bf Mon Sep 17 00:00:00 2001 From: Eli Margolin Date: Tue, 15 Oct 2024 14:13:01 -0400 Subject: [PATCH 2/4] tests are consistent --- crypto-primitives/src/sponge/poseidon/constraints.rs | 3 ++- crypto-primitives/src/sponge/poseidon/mod.rs | 3 +-- crypto-primitives/src/sponge/poseidon/tests.rs | 5 +---- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/crypto-primitives/src/sponge/poseidon/constraints.rs b/crypto-primitives/src/sponge/poseidon/constraints.rs index be53260..52fc3e9 100644 --- a/crypto-primitives/src/sponge/poseidon/constraints.rs +++ b/crypto-primitives/src/sponge/poseidon/constraints.rs @@ -270,6 +270,7 @@ impl CryptographicSpongeVar> for PoseidonSpo ) -> Result>, SynthesisError> { let zero = FpVar::zero(); let mut squeezed_elems = vec![zero; num_elements]; + // self.permute()?; match self.mode { DuplexSpongeMode::Absorbing { next_absorb_index: _, @@ -279,8 +280,8 @@ impl CryptographicSpongeVar> for PoseidonSpo } DuplexSpongeMode::Squeezing { next_squeeze_index } => { let mut squeeze_index = next_squeeze_index; - self.permute()?; if squeeze_index == self.parameters.rate { + self.permute()?; squeeze_index = 0; } self.squeeze_internal(squeeze_index, &mut squeezed_elems)?; diff --git a/crypto-primitives/src/sponge/poseidon/mod.rs b/crypto-primitives/src/sponge/poseidon/mod.rs index 7740001..f94e999 100644 --- a/crypto-primitives/src/sponge/poseidon/mod.rs +++ b/crypto-primitives/src/sponge/poseidon/mod.rs @@ -238,7 +238,7 @@ impl CryptographicSponge for PoseidonSponge { if elems.is_empty() { return; } - + match self.mode { DuplexSpongeMode::Absorbing { next_absorb_index } => { let mut absorb_index = next_absorb_index; @@ -251,7 +251,6 @@ impl CryptographicSponge for PoseidonSponge { DuplexSpongeMode::Squeezing { next_squeeze_index: _, } => { - self.permute(); self.absorb_internal(0, elems.as_slice()); } }; diff --git a/crypto-primitives/src/sponge/poseidon/tests.rs b/crypto-primitives/src/sponge/poseidon/tests.rs index 73955d6..cedca09 100644 --- a/crypto-primitives/src/sponge/poseidon/tests.rs +++ b/crypto-primitives/src/sponge/poseidon/tests.rs @@ -111,9 +111,6 @@ fn run_cross_test(cfg: &PoseidonConfig) { match self.mode() { SpongeMode::Absorbing => self.absorbing.extend_from_slice(input), SpongeMode::Squeezing => { - // Wash the state as mode changes - // This is not appied in SAFE sponge - permute(&self.cfg, &mut self.state); // Append inputs to the absorbing line self.absorbing.extend_from_slice(input); // Change mode to absorbing @@ -1050,4 +1047,4 @@ pub(crate) fn poseidon_parameters_for_test() -> PoseidonConfig rate, capacity, } -} +} \ No newline at end of file From ef953d2214890a1d73de0dd288bfed026b197bce Mon Sep 17 00:00:00 2001 From: Pratyush Mishra Date: Wed, 16 Oct 2024 12:12:03 -0700 Subject: [PATCH 3/4] Apply suggestions from code review --- crypto-primitives/src/sponge/poseidon/constraints.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crypto-primitives/src/sponge/poseidon/constraints.rs b/crypto-primitives/src/sponge/poseidon/constraints.rs index 52fc3e9..c3023ba 100644 --- a/crypto-primitives/src/sponge/poseidon/constraints.rs +++ b/crypto-primitives/src/sponge/poseidon/constraints.rs @@ -270,7 +270,6 @@ impl CryptographicSpongeVar> for PoseidonSpo ) -> Result>, SynthesisError> { let zero = FpVar::zero(); let mut squeezed_elems = vec![zero; num_elements]; - // self.permute()?; match self.mode { DuplexSpongeMode::Absorbing { next_absorb_index: _, From b07ebabe6be824ff4402b41c9817af8f9f8fa96d Mon Sep 17 00:00:00 2001 From: Eli Margolin Date: Wed, 16 Oct 2024 15:13:29 -0400 Subject: [PATCH 4/4] formatting --- crypto-primitives/src/sponge/poseidon/mod.rs | 2 +- crypto-primitives/src/sponge/poseidon/tests.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto-primitives/src/sponge/poseidon/mod.rs b/crypto-primitives/src/sponge/poseidon/mod.rs index f94e999..471c162 100644 --- a/crypto-primitives/src/sponge/poseidon/mod.rs +++ b/crypto-primitives/src/sponge/poseidon/mod.rs @@ -238,7 +238,7 @@ impl CryptographicSponge for PoseidonSponge { if elems.is_empty() { return; } - + match self.mode { DuplexSpongeMode::Absorbing { next_absorb_index } => { let mut absorb_index = next_absorb_index; diff --git a/crypto-primitives/src/sponge/poseidon/tests.rs b/crypto-primitives/src/sponge/poseidon/tests.rs index cedca09..dd760d1 100644 --- a/crypto-primitives/src/sponge/poseidon/tests.rs +++ b/crypto-primitives/src/sponge/poseidon/tests.rs @@ -1047,4 +1047,4 @@ pub(crate) fn poseidon_parameters_for_test() -> PoseidonConfig rate, capacity, } -} \ No newline at end of file +}