From 1ae69a699727baa258f154b6d51b7e5fad422c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michele=20Orr=C3=B9?= Date: Sun, 14 Jan 2024 12:51:47 +0100 Subject: [PATCH] Remove plugins::arkworks::safe --- src/plugins/arkworks/mod.rs | 14 +++--- src/plugins/arkworks/safe.rs | 96 ------------------------------------ 2 files changed, 7 insertions(+), 103 deletions(-) delete mode 100644 src/plugins/arkworks/safe.rs diff --git a/src/plugins/arkworks/mod.rs b/src/plugins/arkworks/mod.rs index 46b9f46..bfe551c 100644 --- a/src/plugins/arkworks/mod.rs +++ b/src/plugins/arkworks/mod.rs @@ -1,16 +1,16 @@ -use crate::hash::Unit; +mod arthur; +mod iopattern; +mod merlin; +pub mod prelude; use ark_ff::{Fp, FpConfig, PrimeField}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use std::io; -pub mod prelude; - -mod arthur; -mod iopattern; -mod merlin; -// mod safe; +pub use prelude::*; +/// Compute the bits needed in order to obtain a +/// (pseudo-random) uniform distribution in F. const fn f_bytes() -> usize { (F::MODULUS_BIT_SIZE as usize + 128) / 8 } diff --git a/src/plugins/arkworks/safe.rs b/src/plugins/arkworks/safe.rs deleted file mode 100644 index a559bf4..0000000 --- a/src/plugins/arkworks/safe.rs +++ /dev/null @@ -1,96 +0,0 @@ -use super::prelude::*; -use ark_ec::{AffineRepr, CurveGroup}; -use ark_ff::{Fp, FpConfig, PrimeField}; -use ark_serialize::CanonicalSerialize; - -impl> Safe { - /// This function absorbs `count` object of size `S::default().compressed()`. - /// It's not meant to be used publicly because it will not work properly for - /// object whose size cannot be determined at compile time. - fn absorb_serializable( - &mut self, - input: &[S], - ) -> Result<(), InvalidTag> { - let mut u8input = Vec::new(); - input - .iter() - .map(|s| s.serialize_compressed(&mut u8input)) - .collect::>() - .map_err(|e| InvalidTag::from(e.to_string()))?; - self.absorb(&u8input) - } -} - -impl ArkGGSafe for Safe -where - H: DuplexHash, - G: CurveGroup, - G::ScalarField: PrimeField, - G::BaseField: PrimeField, -{ - fn absorb_points(&mut self, input: &[G]) -> Result<(), InvalidTag> { - input - .iter() - .map(|i| self.absorb_serializable(&[i.into_affine()])) - .collect() - } -} - -impl ArkFFSafe for Safe -where - H: DuplexHash, - F: PrimeField, -{ - #[inline(always)] - fn absorb_scalars(&mut self, input: &[F]) -> Result<(), InvalidTag> { - self.absorb_serializable(input) - } - - fn squeeze_scalars(&mut self, output: &mut [F]) -> Result<(), InvalidTag> { - for o in output.iter_mut() { - let mut buf = vec![0u8; super::f_bytes::()]; - self.squeeze(&mut buf)?; - *o = F::from_le_bytes_mod_order(&buf); - } - Ok(()) - } -} - - - -impl ArkGGSafe> for Safe -where - H: DuplexHash>, - G: CurveGroup>, - C: FpConfig, -{ - - fn absorb_points(&mut self, input: &[G]) -> Result<(), InvalidTag> { - input - .iter() - .map(|i| { - self.absorb( - &i.into_affine() - .xy() - .map(|(x, y)| [x.clone(), y.clone()]) - .expect("No points at infinity"), - ) - }) - .collect() - } -} - -impl ArkFFSafe, Fp> for Safe> -where - H: DuplexHash>, - C: FpConfig, -{ - fn absorb_scalars(&mut self, _input: &[Fp]) -> Result<(), InvalidTag> { - // what's the correct way to map a scalar element in the field? - unimplemented!() - } - - fn squeeze_scalars(&mut self, _output: &mut [Fp]) -> Result<(), InvalidTag> { - unimplemented!() - } -}