From 98a31dbb67d9fe27ed12424d81e36fa74c931dd7 Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Fri, 15 Nov 2024 22:37:10 +0100 Subject: [PATCH] ff: refactor cubic extension --- ff/src/fields/models/cubic_extension.rs | 39 ++++++++++--------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/ff/src/fields/models/cubic_extension.rs b/ff/src/fields/models/cubic_extension.rs index 1049908bf..99f4c55ea 100644 --- a/ff/src/fields/models/cubic_extension.rs +++ b/ff/src/fields/models/cubic_extension.rs @@ -548,18 +548,18 @@ impl_multiplicative_ops_from_ref!(CubicExtField, CubicExtConfig); impl<'a, P: CubicExtConfig> AddAssign<&'a Self> for CubicExtField

{ #[inline] fn add_assign(&mut self, other: &Self) { - self.c0.add_assign(&other.c0); - self.c1.add_assign(&other.c1); - self.c2.add_assign(&other.c2); + self.c0 += &other.c0; + self.c1 += &other.c1; + self.c2 += &other.c2; } } impl<'a, P: CubicExtConfig> SubAssign<&'a Self> for CubicExtField

{ #[inline] fn sub_assign(&mut self, other: &Self) { - self.c0.sub_assign(&other.c0); - self.c1.sub_assign(&other.c1); - self.c2.sub_assign(&other.c2); + self.c0 -= &other.c0; + self.c1 -= &other.c1; + self.c2 -= &other.c2; } } @@ -596,7 +596,7 @@ impl<'a, P: CubicExtConfig> MulAssign<&'a Self> for CubicExtField

{ impl<'a, P: CubicExtConfig> DivAssign<&'a Self> for CubicExtField

{ #[inline] fn div_assign(&mut self, other: &Self) { - self.mul_assign(&other.inverse().unwrap()); + *self *= &other.inverse().unwrap(); } } @@ -651,7 +651,7 @@ impl CanonicalDeserializeWithFlags for CubicExtField

{ let c0 = CanonicalDeserialize::deserialize_compressed(&mut reader)?; let c1 = CanonicalDeserialize::deserialize_compressed(&mut reader)?; let (c2, flags) = CanonicalDeserializeWithFlags::deserialize_with_flags(&mut reader)?; - Ok((CubicExtField::new(c0, c1, c2), flags)) + Ok((Self::new(c0, c1, c2), flags)) } } @@ -670,13 +670,10 @@ impl CanonicalDeserialize for CubicExtField

{ compress: Compress, validate: Validate, ) -> Result { - let c0: P::BaseField = - CanonicalDeserialize::deserialize_with_mode(&mut reader, compress, validate)?; - let c1: P::BaseField = - CanonicalDeserialize::deserialize_with_mode(&mut reader, compress, validate)?; - let c2: P::BaseField = - CanonicalDeserialize::deserialize_with_mode(&mut reader, compress, validate)?; - Ok(CubicExtField::new(c0, c1, c2)) + let c0 = CanonicalDeserialize::deserialize_with_mode(&mut reader, compress, validate)?; + let c1 = CanonicalDeserialize::deserialize_with_mode(&mut reader, compress, validate)?; + let c2 = CanonicalDeserialize::deserialize_with_mode(&mut reader, compress, validate)?; + Ok(Self::new(c0, c1, c2)) } } @@ -685,15 +682,9 @@ where P::BaseField: ToConstraintField, { fn to_field_elements(&self) -> Option> { - let mut res = Vec::new(); - let mut c0_elems = self.c0.to_field_elements()?; - let mut c1_elems = self.c1.to_field_elements()?; - let mut c2_elems = self.c2.to_field_elements()?; - - res.append(&mut c0_elems); - res.append(&mut c1_elems); - res.append(&mut c2_elems); - + let mut res = self.c0.to_field_elements()?; + res.extend(self.c1.to_field_elements()?); + res.extend(self.c2.to_field_elements()?); Some(res) } }