diff --git a/src/field.rs b/src/field.rs index a6acda1..2d344c6 100644 --- a/src/field.rs +++ b/src/field.rs @@ -13,24 +13,34 @@ use crate::{fp2::GoldilocksExt2, Goldilocks, GoldilocksExt3}; pub trait SmallField: Serialize + SerdeObject + FromUniformBytes<64> + Hash { /// Base field type BaseField: SmallField + FromUniformBytes<64>; + /// Extension degree of the Field const DEGREE: usize; + /// Identifier string const NAME: &'static str; + /// Convert a byte string into a list of field elements fn bytes_to_field_elements(bytes: &[u8]) -> Vec; + /// Convert a field elements to a u64 vector fn to_canonical_u64_vec(&self) -> Vec; + /// Convert self to limbs of Goldilocks elements fn to_limbs(&self) -> Vec; + /// Convert limbs into self fn from_limbs(limbs: &[Self::BaseField]) -> Self; + /// Sample a random over the base field fn sample_base(rng: impl RngCore) -> Self; + /// Build a self from a base element; pad ext with 0s. fn from_base(b: &Self::BaseField) -> Self; + /// Mul-assign self by a base field element fn mul_assign_base(&mut self, rhs: &Self::BaseField); + /// Multiply self by a base field element fn mul_base(&self, rhs: &Self::BaseField) -> Self { let mut res = self.clone(); diff --git a/src/fp2.rs b/src/fp2.rs index 4bc60b2..26adc48 100644 --- a/src/fp2.rs +++ b/src/fp2.rs @@ -253,12 +253,12 @@ impl PrimeField for GoldilocksExt2 { const MODULUS: &'static str = "0xffffffff00000001"; /// How many bits are needed to represent an element of this field. - const NUM_BITS: u32 = 64; + const NUM_BITS: u32 = 128; /// How many bits of information can be reliably stored in the field element. /// /// This is usually `Self::NUM_BITS - 1`. - const CAPACITY: u32 = 63; + const CAPACITY: u32 = 126; /// An integer `s` satisfying the equation `2^s * t = modulus - 1` with `t` odd. /// diff --git a/src/fp3.rs b/src/fp3.rs index 25fbefb..9fa9a87 100644 --- a/src/fp3.rs +++ b/src/fp3.rs @@ -261,12 +261,12 @@ impl PrimeField for GoldilocksExt3 { const MODULUS: &'static str = "0xffffffff00000001"; /// How many bits are needed to represent an element of this field. - const NUM_BITS: u32 = 64; + const NUM_BITS: u32 = 192; /// How many bits of information can be reliably stored in the field element. /// /// This is usually `Self::NUM_BITS - 1`. - const CAPACITY: u32 = 63; + const CAPACITY: u32 = 189; /// An integer `s` satisfying the equation `2^s * t = modulus - 1` with `t` odd. ///