diff --git a/src/transcript.rs b/src/transcript.rs index ec09120..86052b6 100644 --- a/src/transcript.rs +++ b/src/transcript.rs @@ -19,6 +19,10 @@ pub trait Transcript { /// Writing the point to the transcript without writing it to the proof, /// treating it as a common input. fn common_point(&mut self, point: C) -> io::Result<()>; + + /// Writing the scalar to the transcript without writing it to the proof, + /// treating it as a common input. + fn common_scalar(&mut self, scalar: C::Scalar) -> io::Result<()>; } /// Transcript view from the perspective of a verifier that has access to an @@ -84,7 +88,7 @@ impl TranscriptRead for Blake2bRead { "invalid field element encoding in proof", ) })?; - self.state.update(&scalar.to_bytes()); + self.common_scalar(scalar)?; Ok(scalar) } @@ -104,6 +108,12 @@ impl Transcript for Blake2bRead { Ok(()) } + fn common_scalar(&mut self, scalar: C::Scalar) -> io::Result<()> { + self.state.update(&scalar.to_bytes()); + + Ok(()) + } + fn squeeze_challenge(&mut self) -> C::Base { let hasher = self.state.clone(); let result: [u8; 64] = hasher.finalize().as_bytes().try_into().unwrap(); @@ -147,7 +157,7 @@ impl TranscriptWrite for Blake2bWrite { self.writer.write_all(&compressed[..]) } fn write_scalar(&mut self, scalar: C::Scalar) -> io::Result<()> { - self.state.update(&scalar.to_bytes()); + self.common_scalar(scalar)?; let data = scalar.to_bytes(); self.writer.write_all(&data[..]) } @@ -167,6 +177,12 @@ impl Transcript for Blake2bWrite { Ok(()) } + fn common_scalar(&mut self, scalar: C::Scalar) -> io::Result<()> { + self.state.update(&scalar.to_bytes()); + + Ok(()) + } + fn squeeze_challenge(&mut self) -> C::Base { let hasher = self.state.clone(); let result: [u8; 64] = hasher.finalize().as_bytes().try_into().unwrap();