From 133afae13f40418f395e19ba2a18924c05f9f0db Mon Sep 17 00:00:00 2001 From: Sergio Chouhy <41742639+schouhy@users.noreply.github.com> Date: Fri, 22 Sep 2023 13:42:12 -0300 Subject: [PATCH] Change generator in the Stark252PrimeField to one of maximal order $2^{192}$ (#572) * use a generator of the 2-Sylow subgroup in the Stark252PrimeField * use square --- .../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 c9baf79b00..abea28907b 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 7953e8b040..50a2298c87 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.square()); + Ok(root) } }