Skip to content

Commit

Permalink
Merge pull request #1 from mdvillagra/mdvillagra/issue539
Browse files Browse the repository at this point in the history
Mdvillagra/issue539
  • Loading branch information
mdvillagra authored Sep 8, 2023
2 parents 80fbf1d + 19f209e commit ba436e6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
24 changes: 19 additions & 5 deletions math/src/field/fields/fft_friendly/babybear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ use crate::{
field::{
element::FieldElement,
fields::montgomery_backed_prime_fields::{IsModulus, MontgomeryBackendPrimeField},
//traits::IsFFTField,
traits::IsFFTField,
},
unsigned_integer::element::UnsignedInteger,
unsigned_integer::element::{U64, UnsignedInteger},
};

pub type U64 = UnsignedInteger<1>;
pub type U64PrimeField<T> = MontgomeryBackendPrimeField<T, 1>;
pub type U64MontgomeryBackendPrimeField<T> = MontgomeryBackendPrimeField<T, 1>;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MontgomeryConfigBabybear31PrimeField;
Expand All @@ -17,7 +16,21 @@ impl IsModulus<U64> for MontgomeryConfigBabybear31PrimeField {
const MODULUS: U64 = U64::from_u64(2013265921);
}

pub type Babybear31PrimeField = U64PrimeField<MontgomeryConfigBabybear31PrimeField>;
pub type Babybear31PrimeField = U64MontgomeryBackendPrimeField<MontgomeryConfigBabybear31PrimeField>;

// 21^(2^24)=1 mod 2013265921
// 2^27(2^4-1)+1 where n=27 (two-adicity) and k=2^4+1
impl IsFFTField for Babybear31PrimeField {
const TWO_ADICITY: u64 = 27;

const TWO_ADIC_PRIMITVE_ROOT_OF_UNITY: Self::BaseType = UnsignedInteger{
limbs: [21],
};

fn field_name() -> &'static str {
"babybear31"
}
}

impl FieldElement<Babybear31PrimeField> {
pub fn to_bytes_le(&self) -> [u8; 8] {
Expand Down Expand Up @@ -99,4 +112,5 @@ mod test_babybear_31_bytes_ops {
let from_bytes = FieldElement::<Babybear31PrimeField>::from_bytes_be(&bytes).unwrap();
assert_eq!(element, from_bytes);
}

}
2 changes: 1 addition & 1 deletion math/src/field/fields/fft_friendly/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Implemenation of the Babybear Prime field p = 2^31 - 2^27 + 1
pub mod babybear;
/// Implementation of two-adic prime field over 256 bit unsigned integers.
pub mod stark_252_prime_field;
pub mod stark_252_prime_field;
1 change: 1 addition & 0 deletions math/src/unsigned_integer/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use core::fmt::{self, Debug, Display};
pub type U384 = UnsignedInteger<6>;
pub type U256 = UnsignedInteger<4>;
pub type U128 = UnsignedInteger<2>;
pub type U64 = UnsignedInteger<1>;

/// A big unsigned integer in base 2^{64} represented
/// as fixed-size array `limbs` of `u64` components.
Expand Down

0 comments on commit ba436e6

Please sign in to comment.