Skip to content

Commit

Permalink
ff: refactor cubic extension (#881)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored Nov 19, 2024
1 parent 7ab833a commit 93fc31e
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions ff/src/fields/models/cubic_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ impl<P: CubicExtConfig> CanonicalDeserializeWithFlags for CubicExtField<P> {
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))
}
}

Expand All @@ -651,13 +651,10 @@ impl<P: CubicExtConfig> CanonicalDeserialize for CubicExtField<P> {
compress: Compress,
validate: Validate,
) -> Result<Self, SerializationError> {
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))
}
}

Expand All @@ -666,15 +663,9 @@ where
P::BaseField: ToConstraintField<P::BasePrimeField>,
{
fn to_field_elements(&self) -> Option<Vec<P::BasePrimeField>> {
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)
}
}
Expand Down

0 comments on commit 93fc31e

Please sign in to comment.