From 4a2c9d634ac7ec2865658c549d546fa4c28217f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michele=20Orr=C3=B9?= Date: Tue, 30 Jan 2024 14:10:17 +0100 Subject: [PATCH] More uniform API --- src/arthur.rs | 6 +++--- src/lib.rs | 2 +- src/merlin.rs | 12 ++++++------ src/plugins/ark/reader.rs | 4 ++-- src/tests.rs | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/arthur.rs b/src/arthur.rs index 73713d5..2f3ce33 100644 --- a/src/arthur.rs +++ b/src/arthur.rs @@ -105,7 +105,7 @@ where R: RngCore + CryptoRng, { #[inline(always)] - pub fn add(&mut self, input: &[U]) -> Result<(), IOPatternError> { + pub fn add_units(&mut self, input: &[U]) -> Result<(), IOPatternError> { // let serialized = bincode::serialize(input).unwrap(); // self.arthur.sponge.absorb_unchecked(&serialized); let old_len = self.transcript.len(); @@ -142,7 +142,7 @@ where { fn public_units(&mut self, input: &[U]) -> Result<(), IOPatternError> { let len = self.transcript.len(); - self.add(input)?; + self.add_units(input)?; self.transcript.truncate(len); Ok(()) } @@ -172,6 +172,6 @@ where { #[inline(always)] fn add_bytes(&mut self, input: &[u8]) -> Result<(), IOPatternError> { - self.add(input) + self.add_units(input) } } diff --git a/src/lib.rs b/src/lib.rs index c618f9a..fabb4ae 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,7 +69,7 @@ //! let io = IOPattern::::new("example-protocol").absorb(1, "send").squeeze(16, "receive"); //! let mut arthur = io.to_arthur(); //! // the prover sends the byte 0x42. -//! arthur.add(&[0x42]).expect("Absorbing one byte"); +//! arthur.add_bytes(&[0x42]).expect("Absorbing one byte"); //! // the prover receive a 128-bit challenge. //! let mut chal = [0u8; 16]; //! arthur.fill_challenge_bytes(&mut chal).expect("Squeezing 128 bits"); diff --git a/src/merlin.rs b/src/merlin.rs index 5e30cc7..3d0a78a 100644 --- a/src/merlin.rs +++ b/src/merlin.rs @@ -27,21 +27,21 @@ impl<'a, U: Unit, H: DuplexHash> Merlin<'a, H, U> { } /// Read `input.len()` elements from the transcript. - #[inline(always)] - pub fn fill_next(&mut self, input: &mut [U]) -> Result<(), IOPatternError> { + #[inline] + pub fn fill_next_units(&mut self, input: &mut [U]) -> Result<(), IOPatternError> { U::read(&mut self.transcript, input)?; self.safe.absorb(input)?; Ok(()) } /// Signals the end of the statement. - #[inline(always)] + #[inline] pub fn ratchet(&mut self) -> Result<(), IOPatternError> { self.safe.ratchet() } /// Signals the end of the statement and returns the (compressed) sponge state. - #[inline(always)] + #[inline] pub fn preprocess(self) -> Result<&'static [U], IOPatternError> { self.safe.preprocess() } @@ -67,8 +67,8 @@ impl<'a, H: DuplexHash, U: Unit> core::fmt::Debug for Merlin<'a, H, U> { } impl<'a, H: DuplexHash> ByteReader for Merlin<'a, H, u8> { - #[inline(always)] + #[inline] fn fill_next_bytes(&mut self, input: &mut [u8]) -> Result<(), IOPatternError> { - self.fill_next(input) + self.fill_next_units(input) } } diff --git a/src/plugins/ark/reader.rs b/src/plugins/ark/reader.rs index 236dae1..2ed04c2 100644 --- a/src/plugins/ark/reader.rs +++ b/src/plugins/ark/reader.rs @@ -35,7 +35,7 @@ where let mut buf = vec![0u8; point_size]; for o in output.iter_mut() { - self.fill_next(&mut buf)?; + self.fill_next_units(&mut buf)?; *o = G::deserialize_compressed(buf.as_slice())?; } Ok(()) @@ -48,7 +48,7 @@ where H: DuplexHash>, { fn fill_next_scalars(&mut self, output: &mut [Fp]) -> crate::ProofResult<()> { - self.fill_next(output)?; + self.fill_next_units(output)?; Ok(()) } } diff --git a/src/tests.rs b/src/tests.rs index 1c2f78b..862c877 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -76,14 +76,14 @@ fn test_merlin() { .squeeze(10, "bye bye"); let mut arthur = Arthur::::from(&io); - arthur.add(&[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]).unwrap(); + arthur.add_units(&[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]).unwrap(); arthur.fill_challenge_bytes(&mut [0u8; 10]).unwrap(); let transcript = arthur.transcript(); let mut merlin = Merlin::::new(&io, transcript); let mut input = [0u8; 5]; - merlin.fill_next(&mut input).unwrap(); + merlin.fill_next_units(&mut input).unwrap(); assert_eq!(input, [0, 1, 2, 3, 4]); - merlin.fill_next(&mut input).unwrap(); + merlin.fill_next_units(&mut input).unwrap(); assert_eq!(input, [5, 6, 7, 8, 9]); }