diff --git a/src/transcript/keccak.rs b/src/transcript/keccak.rs index 4591402a..db3f517f 100644 --- a/src/transcript/keccak.rs +++ b/src/transcript/keccak.rs @@ -41,7 +41,6 @@ impl Transcript for KeccakTranscript { fn get_challenge(&mut self) -> C::ScalarField { let mut output = [0u8; 32]; self.sponge.clone().finalize(&mut output); - self.sponge.update(&[output[0]]); C::ScalarField::from_le_bytes_mod_order(&[output[0]]) } fn get_challenge_nbits(&mut self, nbits: usize) -> Vec { @@ -51,7 +50,6 @@ impl Transcript for KeccakTranscript { fn get_challenges(&mut self, n: usize) -> Vec { let mut output = [0u8; 32]; self.sponge.clone().finalize(&mut output); - self.sponge.update(&[output[0]]); let c: Vec = output .iter() @@ -77,7 +75,7 @@ pub mod tests { } #[test] - fn test_transcript_get_challenge() { + fn test_transcript_get_challenges_len() { let mut rng = ark_std::test_rng(); const n: usize = 10; @@ -89,4 +87,15 @@ pub mod tests { let challenges = transcript.get_challenges(v.len()); assert_eq!(challenges.len(), n); } + + #[test] + fn test_transcript_get_challenge() { + let config = keccak_test_config::(); + // init transcript + let mut transcript = KeccakTranscript::::new(&config); + transcript.absorb(&Fr::from(42_u32)); + let c = transcript.get_challenge(); + let c_2 = transcript.get_challenge(); + assert_eq!(c, c_2); + } } diff --git a/src/transcript/sha3.rs b/src/transcript/sha3.rs index 8ae8ec4a..09b7fd52 100644 --- a/src/transcript/sha3.rs +++ b/src/transcript/sha3.rs @@ -40,7 +40,6 @@ impl Transcript for SHA3Transcript { } fn get_challenge(&mut self) -> C::ScalarField { let output = self.sponge.clone().finalize_boxed(200); - self.sponge.update(&[output[0]]); C::ScalarField::from_le_bytes_mod_order(&[output[0]]) } fn get_challenge_nbits(&mut self, nbits: usize) -> Vec { @@ -50,7 +49,6 @@ impl Transcript for SHA3Transcript { } fn get_challenges(&mut self, n: usize) -> Vec { let output = self.sponge.clone().finalize_boxed(n); - self.sponge.update(&[output[0]]); let c = output .iter() @@ -76,7 +74,7 @@ pub mod tests { } #[test] - fn test_transcript_get_challenge() { + fn test_transcript_get_challenges_len() { let mut rng = ark_std::test_rng(); const n: usize = 10; @@ -88,4 +86,15 @@ pub mod tests { let challenges = transcript.get_challenges(v.len()); assert_eq!(challenges.len(), n); } + + #[test] + fn test_transcript_get_challenge() { + let config = sha3_test_config::(); + // init transcript + let mut transcript = SHA3Transcript::::new(&config); + transcript.absorb(&Fr::from(42_u32)); + let c = transcript.get_challenge(); + let c_2 = transcript.get_challenge(); + assert_eq!(c, c_2); + } }