From 6425c3a0c03e690956945c5f35924a9ff4f25249 Mon Sep 17 00:00:00 2001 From: Ray Gao Date: Tue, 26 Nov 2024 16:19:14 -0500 Subject: [PATCH] Code improvement --- spartan_parallel/src/lib.rs | 8 +++----- spartan_parallel/src/scalar/fp.rs | 7 ------- spartan_parallel/src/scalar/fp2.rs | 7 ------- spartan_parallel/src/scalar/mod.rs | 19 ------------------- 4 files changed, 3 insertions(+), 38 deletions(-) diff --git a/spartan_parallel/src/lib.rs b/spartan_parallel/src/lib.rs index ff473aac..74727605 100644 --- a/spartan_parallel/src/lib.rs +++ b/spartan_parallel/src/lib.rs @@ -126,7 +126,7 @@ fn write_bytes(mut f: &File, bytes: &[u8; 32]) -> std::io::Result<()> { for i in 0..size { write!(&mut f, "{} ", bytes[i])?; } - writeln!(&mut f, "")?; + writeln!(&mut f)?; Ok(()) } @@ -285,7 +285,7 @@ impl IOProofs { input_indices = input_indices[..live_input.len()].to_vec(); // batch verify all proofs - let _ = PolyEvalProof::verify_plain_batched_points( + PolyEvalProof::verify_plain_batched_points( &self.proofs, transcript, [ @@ -313,9 +313,7 @@ impl IOProofs { live_input, ] .concat(), - )?; - - Ok(()) + ) } } diff --git a/spartan_parallel/src/scalar/fp.rs b/spartan_parallel/src/scalar/fp.rs index 91205be9..008be665 100644 --- a/spartan_parallel/src/scalar/fp.rs +++ b/spartan_parallel/src/scalar/fp.rs @@ -120,13 +120,11 @@ impl Zeroize for Scalar { impl Neg for Scalar { type Output = Scalar; - #[inline] fn neg(self) -> Scalar { self.0.neg().into() } } impl Default for Scalar { - #[inline] fn default() -> Self { Self::zero() } @@ -138,13 +136,11 @@ impl From for Scalar { } impl Scalar { /// Returns zero, the additive identity. - #[inline] pub const fn zero() -> Self { Self(Goldilocks(0u64)) } /// Returns one, the multiplicative identity. - #[inline] pub const fn one() -> Self { Self(Goldilocks(1u64)) } @@ -153,7 +149,6 @@ impl Scalar { impl<'a, 'b> Add<&'b Scalar> for &'a Scalar { type Output = Scalar; - #[inline] fn add(self, rhs: &'b Scalar) -> Scalar { self.inner().add(rhs.inner()).into() } @@ -162,7 +157,6 @@ impl<'a, 'b> Add<&'b Scalar> for &'a Scalar { impl<'a, 'b> Sub<&'b Scalar> for &'a Scalar { type Output = Scalar; - #[inline] fn sub(self, rhs: &'b Scalar) -> Scalar { self.inner().sub(rhs.inner()).into() } @@ -171,7 +165,6 @@ impl<'a, 'b> Sub<&'b Scalar> for &'a Scalar { impl<'a, 'b> Mul<&'b Scalar> for &'a Scalar { type Output = Scalar; - #[inline] fn mul(self, rhs: &'b Scalar) -> Scalar { self.inner().mul(rhs.inner()).into() } diff --git a/spartan_parallel/src/scalar/fp2.rs b/spartan_parallel/src/scalar/fp2.rs index b7e8b7b5..1ba7cd32 100644 --- a/spartan_parallel/src/scalar/fp2.rs +++ b/spartan_parallel/src/scalar/fp2.rs @@ -117,26 +117,22 @@ impl Zeroize for ScalarExt2 { impl Neg for ScalarExt2 { type Output = Self; - #[inline] fn neg(self) -> Self { self.0.neg().into() } } impl Default for ScalarExt2 { - #[inline] fn default() -> Self { Self::zero() } } impl ScalarExt2 { /// Returns zero, the additive identity. - #[inline] pub const fn zero() -> Self { Self(GoldilocksExt2::ZERO) } /// Returns one, the multiplicative identity. - #[inline] pub const fn one() -> Self { Self(GoldilocksExt2::ONE) } @@ -145,7 +141,6 @@ impl ScalarExt2 { impl<'a, 'b> Add<&'b ScalarExt2> for &'a ScalarExt2 { type Output = ScalarExt2; - #[inline] fn add(self, rhs: &'b ScalarExt2) -> ScalarExt2 { self.inner().add(rhs.inner()).into() } @@ -154,7 +149,6 @@ impl<'a, 'b> Add<&'b ScalarExt2> for &'a ScalarExt2 { impl<'a, 'b> Sub<&'b ScalarExt2> for &'a ScalarExt2 { type Output = ScalarExt2; - #[inline] fn sub(self, rhs: &'b ScalarExt2) -> ScalarExt2 { self.inner().sub(rhs.inner()).into() } @@ -163,7 +157,6 @@ impl<'a, 'b> Sub<&'b ScalarExt2> for &'a ScalarExt2 { impl<'a, 'b> Mul<&'b ScalarExt2> for &'a ScalarExt2 { type Output = ScalarExt2; - #[inline] fn mul(self, rhs: &'b ScalarExt2) -> ScalarExt2 { let a = self.inner(); let b = rhs.inner(); diff --git a/spartan_parallel/src/scalar/mod.rs b/spartan_parallel/src/scalar/mod.rs index 2c96679d..31795b58 100644 --- a/spartan_parallel/src/scalar/mod.rs +++ b/spartan_parallel/src/scalar/mod.rs @@ -80,25 +80,21 @@ pub trait SpartanExtensionField: ); /// Return the neg of field element - #[inline] fn negate(&self) -> Self { self.inner().neg().into() } /// Doubles this field element. - #[inline] fn double(&self) -> Self { self.add(*self) } /// Squares this element. - #[inline] fn square(&self) -> Self { self.mul(*self) } /// Negates `self`. - #[inline] fn neg(&self) -> Self { self.inner().neg().into() } @@ -186,7 +182,6 @@ macro_rules! impl_add_binop_specify_output { impl<'b> Add<&'b $rhs> for $lhs { type Output = $output; - #[inline] fn add(self, rhs: &'b $rhs) -> $output { &self + rhs } @@ -195,7 +190,6 @@ macro_rules! impl_add_binop_specify_output { impl<'a> Add<$rhs> for &'a $lhs { type Output = $output; - #[inline] fn add(self, rhs: $rhs) -> $output { self + &rhs } @@ -204,7 +198,6 @@ macro_rules! impl_add_binop_specify_output { impl Add<$rhs> for $lhs { type Output = $output; - #[inline] fn add(self, rhs: $rhs) -> $output { &self + &rhs } @@ -219,7 +212,6 @@ macro_rules! impl_sub_binop_specify_output { impl<'b> Sub<&'b $rhs> for $lhs { type Output = $output; - #[inline] fn sub(self, rhs: &'b $rhs) -> $output { &self - rhs } @@ -228,7 +220,6 @@ macro_rules! impl_sub_binop_specify_output { impl<'a> Sub<$rhs> for &'a $lhs { type Output = $output; - #[inline] fn sub(self, rhs: $rhs) -> $output { self - &rhs } @@ -237,7 +228,6 @@ macro_rules! impl_sub_binop_specify_output { impl Sub<$rhs> for $lhs { type Output = $output; - #[inline] fn sub(self, rhs: $rhs) -> $output { &self - &rhs } @@ -261,7 +251,6 @@ macro_rules! impl_binops_multiplicative_mixed { impl<'b> Mul<&'b $rhs> for $lhs { type Output = $output; - #[inline] fn mul(self, rhs: &'b $rhs) -> $output { &self * rhs } @@ -270,7 +259,6 @@ macro_rules! impl_binops_multiplicative_mixed { impl<'a> Mul<$rhs> for &'a $lhs { type Output = $output; - #[inline] fn mul(self, rhs: $rhs) -> $output { self * &rhs } @@ -279,7 +267,6 @@ macro_rules! impl_binops_multiplicative_mixed { impl Mul<$rhs> for $lhs { type Output = $output; - #[inline] fn mul(self, rhs: $rhs) -> $output { &self * &rhs } @@ -294,28 +281,24 @@ macro_rules! impl_binops_additive { crate::impl_binops_additive_specify_output!($lhs, $rhs, $lhs); impl SubAssign<$rhs> for $lhs { - #[inline] fn sub_assign(&mut self, rhs: $rhs) { *self = &*self - &rhs; } } impl AddAssign<$rhs> for $lhs { - #[inline] fn add_assign(&mut self, rhs: $rhs) { *self = &*self + &rhs; } } impl<'b> SubAssign<&'b $rhs> for $lhs { - #[inline] fn sub_assign(&mut self, rhs: &'b $rhs) { *self = &*self - rhs; } } impl<'b> AddAssign<&'b $rhs> for $lhs { - #[inline] fn add_assign(&mut self, rhs: &'b $rhs) { *self = &*self + rhs; } @@ -330,14 +313,12 @@ macro_rules! impl_binops_multiplicative { crate::impl_binops_multiplicative_mixed!($lhs, $rhs, $lhs); impl MulAssign<$rhs> for $lhs { - #[inline] fn mul_assign(&mut self, rhs: $rhs) { *self = &*self * &rhs; } } impl<'b> MulAssign<&'b $rhs> for $lhs { - #[inline] fn mul_assign(&mut self, rhs: &'b $rhs) { *self = &*self * rhs; }