diff --git a/crates/boojum/src/gadgets/mersenne_field/fourth_ext.rs b/crates/boojum/src/gadgets/mersenne_field/fourth_ext.rs index bbcf072..f034e99 100644 --- a/crates/boojum/src/gadgets/mersenne_field/fourth_ext.rs +++ b/crates/boojum/src/gadgets/mersenne_field/fourth_ext.rs @@ -2,7 +2,6 @@ use mersenne_field::{Mersenne31Complex, Mersenne31Quartic}; use super::*; use super::second_ext::*; -use crate::gadgets::impls::limbs_decompose::decompose_into_limbs; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct MersenneQuartic { @@ -51,7 +50,7 @@ impl MersenneQuartic { [self.x.x.into_num(), self.x.y.into_num(), self.y.x.into_num(), self.y.y.into_num()] } - pub fn into_coeffs(&self) -> [MersenneFiled; 4] { + pub fn into_coeffs(&self) -> [MersenneField; 4] { [self.x.x, self.x.y, self.y.x, self.y.y] } @@ -87,7 +86,7 @@ impl MersenneQuartic { self.y.enforce_reduced(cs); } - pub fn from_base>(cs: &mut CS, value: MersenneFiled) -> Self { + pub fn from_base>(cs: &mut CS, value: MersenneField) -> Self { Self { x: MersenneComplex::from_base(cs, value), y: MersenneComplex::zero(cs), @@ -432,14 +431,14 @@ impl MersenneQuartic { } } - pub fn mul_by_base>(&self, cs: &mut CS, other: &MersenneFiled) -> Self { + pub fn mul_by_base>(&self, cs: &mut CS, other: &MersenneField) -> Self { Self { x: self.x.mul_by_base(cs, other), y: self.y.mul_by_base(cs, other), } } - pub fn mul_by_base_and_add>(&self, cs: &mut CS, coeff: &MersenneFiled, other: &Self) -> Self { + pub fn mul_by_base_and_add>(&self, cs: &mut CS, coeff: &MersenneField, other: &Self) -> Self { Self { x: self.x.mul_by_base_and_add(cs, coeff, &other.x), y: self.y.mul_by_base_and_add(cs, coeff, &other.y), @@ -728,7 +727,7 @@ mod tests { let cs = &mut owned_cs; let rand_base_witness = [0; 2].map(|_| Mersenne31Field::new(rand::random::() % M31_MODULUS as u32)); - let rand_base_vars = rand_base_witness.map(|w| MersenneFiled::::allocate_checked(cs, w, false)); + let rand_base_vars = rand_base_witness.map(|w| MersenneField::::allocate_checked(cs, w, false)); let rand_witness = [0; 3].map(|_| Mersenne31Quartic { diff --git a/crates/boojum/src/gadgets/mersenne_field/mod.rs b/crates/boojum/src/gadgets/mersenne_field/mod.rs index 2dda597..d55ac9b 100644 --- a/crates/boojum/src/gadgets/mersenne_field/mod.rs +++ b/crates/boojum/src/gadgets/mersenne_field/mod.rs @@ -30,7 +30,7 @@ const M31_MODULUS: u64 = (1 << 31) - 1; // #[derive(Derivative, serde::Serialize, serde::Deserialize)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -pub struct MersenneFiled { +pub struct MersenneField { // the inner witness value is always reduced with the modulus // if reduced is true, then the reduction is proved and max possible value is 2^31 - 2 // if reduced is false, then only 31-bit check is proved and max possible value is 2^31 - 1 @@ -40,7 +40,7 @@ pub struct MersenneFiled { pub(crate) _marker: std::marker::PhantomData, } -impl MersenneFiled { +impl MersenneField { pub fn allocated_constant>(cs: &mut CS, value: Mersenne31Field) -> Self { let variable = cs.allocate_constant(F::from_u64_unchecked(value.to_reduced_u32() as u64)); @@ -1222,8 +1222,8 @@ pub fn get_15_bits_range_check_table>( pub fn reduce_mersenne31>( cs: &mut CS, unreduced_a: Variable, -) -> (MersenneFiled, Variable) { - let a = MersenneFiled::allocate_checked_without_value(cs, false); +) -> (MersenneField, Variable) { + let a = MersenneField::allocate_checked_without_value(cs, false); let reduce_a = cs.alloc_variable_without_value(); if ::WitnessConfig::EVALUATE_WITNESS { @@ -1272,7 +1272,7 @@ pub fn reduce_mersenne31>( (a, reduce_a) } -impl CSAllocatable for MersenneFiled { +impl CSAllocatable for MersenneField { type Witness = Mersenne31Field; fn placeholder_witness() -> Self::Witness { @@ -1298,7 +1298,7 @@ impl WitnessCastable for Mersenne31Field { } } -impl CSWitnessable for MersenneFiled { +impl CSWitnessable for MersenneField { type ConversionFunction = Convertor; fn witness_from_set_of_values(values: [F; 1]) -> Self::Witness { @@ -1310,7 +1310,7 @@ impl CSWitnessable for MersenneFiled { } } -impl WitnessHookable for MersenneFiled { +impl WitnessHookable for MersenneField { fn witness_hook>( &self, cs: &CS, @@ -1320,7 +1320,7 @@ impl WitnessHookable for MersenneFiled { } } -impl Selectable for MersenneFiled { +impl Selectable for MersenneField { #[must_use] fn conditionally_select>( cs: &mut CS, @@ -1461,7 +1461,7 @@ mod tests { let cs = &mut owned_cs; let rand_witness = [0; 4].map(|_| Mersenne31Field::new(rand::random::() % M31_MODULUS as u32)); - let mut rand_vars = rand_witness.map(|w| MersenneFiled::::allocate_checked(cs, w, false)); + let mut rand_vars = rand_witness.map(|w| MersenneField::::allocate_checked(cs, w, false)); // enforce reduced for var in rand_vars.iter_mut() { diff --git a/crates/boojum/src/gadgets/mersenne_field/second_ext.rs b/crates/boojum/src/gadgets/mersenne_field/second_ext.rs index da9dd66..86adc8a 100644 --- a/crates/boojum/src/gadgets/mersenne_field/second_ext.rs +++ b/crates/boojum/src/gadgets/mersenne_field/second_ext.rs @@ -5,36 +5,36 @@ use super::*; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct MersenneComplex { - pub x: MersenneFiled, - pub y: MersenneFiled, + pub x: MersenneField, + pub y: MersenneField, } impl MersenneComplex { pub fn allocated_constant>(cs: &mut CS, value: Mersenne31Complex) -> Self { Self { - x: MersenneFiled::allocated_constant(cs, value.c0), - y: MersenneFiled::allocated_constant(cs, value.c1), + x: MersenneField::allocated_constant(cs, value.c0), + y: MersenneField::allocated_constant(cs, value.c1), } } pub fn zero>(cs: &mut CS) -> Self { Self { - x: MersenneFiled::zero(cs), - y: MersenneFiled::zero(cs), + x: MersenneField::zero(cs), + y: MersenneField::zero(cs), } } pub fn one>(cs: &mut CS) -> Self { Self { - x: MersenneFiled::one(cs), - y: MersenneFiled::zero(cs), + x: MersenneField::one(cs), + y: MersenneField::zero(cs), } } pub fn minus_one>(cs: &mut CS) -> Self { Self { - x: MersenneFiled::minus_one(cs), - y: MersenneFiled::zero(cs), + x: MersenneField::minus_one(cs), + y: MersenneField::zero(cs), } } @@ -58,16 +58,16 @@ impl MersenneComplex { /// The coordinate values should be in range [0, 2^31 - 2] pub fn from_variables_checked>(cs: &mut CS, variables: [Variable; 2], reduced: bool) -> Self { Self { - x: MersenneFiled::from_variable_checked(cs, variables[0], reduced), - y: MersenneFiled::from_variable_checked(cs, variables[1], reduced), + x: MersenneField::from_variable_checked(cs, variables[0], reduced), + y: MersenneField::from_variable_checked(cs, variables[1], reduced), } } /// The coordinate values should be in range [0, 2^31 - 2] pub fn allocate_checked_without_value>(cs: &mut CS, reduced: bool) -> Self { Self { - x: MersenneFiled::allocate_checked_without_value(cs, reduced), - y: MersenneFiled::allocate_checked_without_value(cs, reduced), + x: MersenneField::allocate_checked_without_value(cs, reduced), + y: MersenneField::allocate_checked_without_value(cs, reduced), } } @@ -77,8 +77,8 @@ impl MersenneComplex { reduced: bool, ) -> Self { Self { - x: MersenneFiled::allocate_checked(cs, witness.c0, reduced), - y: MersenneFiled::allocate_checked(cs, witness.c1, reduced), + x: MersenneField::allocate_checked(cs, witness.c0, reduced), + y: MersenneField::allocate_checked(cs, witness.c1, reduced), } } @@ -87,10 +87,10 @@ impl MersenneComplex { self.y.enforce_reduced(cs); } - pub fn from_base>(cs: &mut CS, value: MersenneFiled) -> Self { + pub fn from_base>(cs: &mut CS, value: MersenneField) -> Self { Self { x: value, - y: MersenneFiled::zero(cs), + y: MersenneField::zero(cs), } } @@ -146,14 +146,14 @@ impl MersenneComplex { } } - pub fn mul_by_base>(&self, cs: &mut CS, other: &MersenneFiled) -> Self { + pub fn mul_by_base>(&self, cs: &mut CS, other: &MersenneField) -> Self { Self { x: self.x.mul(cs, other), y: self.y.mul(cs, other), } } - pub fn mul_by_base_and_add>(&self, cs: &mut CS, coeff: &MersenneFiled, other: &Self) -> Self { + pub fn mul_by_base_and_add>(&self, cs: &mut CS, coeff: &MersenneField, other: &Self) -> Self { Self { x: self.x.mul_and_add(cs, coeff, &other.x), y: self.y.mul_and_add(cs, coeff, &other.y), @@ -185,8 +185,8 @@ impl MersenneComplex { let reduce1 = Num::allocate_without_value(cs); let reduce2 = Num::allocate_without_value(cs); crate::gadgets::u8::range_check_u8_pair(cs, &[reduce1.get_variable(), reduce2.get_variable()]); // 6th constraint - let result_x = MersenneFiled::allocate_checked_without_value(cs, false); // 7th constraint - let result_y = MersenneFiled::allocate_checked_without_value(cs, false); // 8th constraint + let result_x = MersenneField::allocate_checked_without_value(cs, false); // 7th constraint + let result_y = MersenneField::allocate_checked_without_value(cs, false); // 8th constraint if ::WitnessConfig::EVALUATE_WITNESS { let value_fn = move |inputs: [F; 2]| { @@ -415,8 +415,8 @@ impl Selectable for MersenneComplex { b: &Self, ) -> Self { Self { - x: MersenneFiled::conditionally_select(cs, flag, &a.x, &b.x), - y: MersenneFiled::conditionally_select(cs, flag, &a.y, &b.y), + x: MersenneField::conditionally_select(cs, flag, &a.x, &b.x), + y: MersenneField::conditionally_select(cs, flag, &a.y, &b.y), } } const SUPPORTS_PARALLEL_SELECT: bool = true; @@ -545,7 +545,7 @@ mod tests { let cs = &mut owned_cs; let rand_base_witness = [0; 2].map(|_| Mersenne31Field::new(rand::random::() % M31_MODULUS as u32)); - let rand_base_vars = rand_base_witness.map(|w| MersenneFiled::::allocate_checked(cs, w, false)); + let rand_base_vars = rand_base_witness.map(|w| MersenneField::::allocate_checked(cs, w, false)); let rand_witness = [0; 2].map(|_| Mersenne31Complex {