fix bugs in bit length

This commit is contained in:
zhenfei
2024-01-15 17:36:34 -05:00
parent dac2627b7b
commit a74c883715
3 changed files with 14 additions and 4 deletions

View File

@@ -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<Self>;
/// Convert a field elements to a u64 vector
fn to_canonical_u64_vec(&self) -> Vec<u64>;
/// Convert self to limbs of Goldilocks elements
fn to_limbs(&self) -> Vec<Self::BaseField>;
/// 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();

View File

@@ -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.
///

View File

@@ -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.
///