From ac3fe087782cd22f8c691dc0c88264229890675d Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Thu, 21 Sep 2023 22:19:32 -0300 Subject: [PATCH 1/2] use a generator of the 2-Sylow subgroup in the Stark252PrimeField --- .../fields/fft_friendly/stark_252_prime_field.rs | 13 ++++--------- math/src/field/traits.rs | 5 +++-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/math/src/field/fields/fft_friendly/stark_252_prime_field.rs b/math/src/field/fields/fft_friendly/stark_252_prime_field.rs index c9baf79b0..abea28907 100644 --- a/math/src/field/fields/fft_friendly/stark_252_prime_field.rs +++ b/math/src/field/fields/fft_friendly/stark_252_prime_field.rs @@ -17,16 +17,11 @@ impl IsModulus for MontgomeryConfigStark252PrimeField { pub type Stark252PrimeField = U256PrimeField; impl IsFFTField for Stark252PrimeField { - const TWO_ADICITY: u64 = 48; + const TWO_ADICITY: u64 = 192; // Change this line for a new function like `from_limbs`. - const TWO_ADIC_PRIMITVE_ROOT_OF_UNITY: U256 = UnsignedInteger { - limbs: [ - 219038664817244121, - 2879838607450979157, - 15244050560987562958, - 16338897044258952332, - ], - }; + const TWO_ADIC_PRIMITVE_ROOT_OF_UNITY: U256 = UnsignedInteger::from_hex_unchecked( + "5282db87529cfa3f0464519c8b0fa5ad187148e11a61616070024f42f8ef94", + ); fn field_name() -> &'static str { "stark256" diff --git a/math/src/field/traits.rs b/math/src/field/traits.rs index 7953e8b04..31d58dff3 100644 --- a/math/src/field/traits.rs +++ b/math/src/field/traits.rs @@ -42,8 +42,9 @@ pub trait IsFFTField: IsPrimeField { if order > F::TWO_ADICITY { return Err(FieldError::RootOfUnityError(order)); } - let power = 1u64 << (F::TWO_ADICITY - order); - Ok(two_adic_primitive_root_of_unity.pow(power)) + let log_power = F::TWO_ADICITY - order; + let root = (0..log_power).fold(two_adic_primitive_root_of_unity, |acc, _| &acc * &acc); + Ok(root) } } From afbcc8272a354fb298cbaccb4c09adb5044f3162 Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Fri, 22 Sep 2023 10:59:07 -0300 Subject: [PATCH 2/2] use square --- math/src/field/traits.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/src/field/traits.rs b/math/src/field/traits.rs index 31d58dff3..50a2298c8 100644 --- a/math/src/field/traits.rs +++ b/math/src/field/traits.rs @@ -43,7 +43,7 @@ pub trait IsFFTField: IsPrimeField { return Err(FieldError::RootOfUnityError(order)); } let log_power = F::TWO_ADICITY - order; - let root = (0..log_power).fold(two_adic_primitive_root_of_unity, |acc, _| &acc * &acc); + let root = (0..log_power).fold(two_adic_primitive_root_of_unity, |acc, _| acc.square()); Ok(root) } }