diff --git a/benches/ffts.rs b/benches/ffts.rs index 618d8b97..8492cfe9 100644 --- a/benches/ffts.rs +++ b/benches/ffts.rs @@ -1,6 +1,6 @@ use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; -use plonky2::field::crandall_field::CrandallField; use plonky2::field::field_types::Field; +use plonky2::field::goldilocks_field::GoldilocksField; use plonky2::polynomial::polynomial::PolynomialCoeffs; use tynm::type_name; @@ -36,8 +36,8 @@ pub(crate) fn bench_ldes(c: &mut Criterion) { } fn criterion_benchmark(c: &mut Criterion) { - bench_ffts::(c); - bench_ldes::(c); + bench_ffts::(c); + bench_ldes::(c); } criterion_group!(benches, criterion_benchmark); diff --git a/benches/field_arithmetic.rs b/benches/field_arithmetic.rs index e25a8382..ebecb871 100644 --- a/benches/field_arithmetic.rs +++ b/benches/field_arithmetic.rs @@ -1,7 +1,6 @@ #![feature(destructuring_assignment)] use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; -use plonky2::field::crandall_field::CrandallField; use plonky2::field::extension_field::quartic::QuarticExtension; use plonky2::field::field_types::Field; use plonky2::field::goldilocks_field::GoldilocksField; @@ -116,9 +115,7 @@ pub(crate) fn bench_field(c: &mut Criterion) { } fn criterion_benchmark(c: &mut Criterion) { - bench_field::(c); bench_field::(c); - bench_field::>(c); bench_field::>(c); } diff --git a/benches/hashing.rs b/benches/hashing.rs index fd8ef977..5669e50b 100644 --- a/benches/hashing.rs +++ b/benches/hashing.rs @@ -2,7 +2,6 @@ #![feature(generic_const_exprs)] use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; -use plonky2::field::crandall_field::CrandallField; use plonky2::field::goldilocks_field::GoldilocksField; use plonky2::hash::gmimc::GMiMC; use plonky2::hash::poseidon::Poseidon; @@ -32,8 +31,6 @@ where } fn criterion_benchmark(c: &mut Criterion) { - bench_gmimc::(c); - bench_poseidon::(c); bench_gmimc::(c); bench_poseidon::(c); } diff --git a/benches/transpose.rs b/benches/transpose.rs index b8ef43e0..0f20ca0f 100644 --- a/benches/transpose.rs +++ b/benches/transpose.rs @@ -1,10 +1,10 @@ use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; -use plonky2::field::crandall_field::CrandallField; use plonky2::field::field_types::Field; +use plonky2::field::goldilocks_field::GoldilocksField; use plonky2::util::transpose; fn criterion_benchmark(c: &mut Criterion) { - type F = CrandallField; + type F = GoldilocksField; // In practice, for the matrices we care about, each row is associated with a polynomial of // degree 2^13, and has been low-degree extended to a length of 2^16. diff --git a/src/bin/bench_ldes.rs b/src/bin/bench_ldes.rs index 732eabd3..d121831b 100644 --- a/src/bin/bench_ldes.rs +++ b/src/bin/bench_ldes.rs @@ -1,11 +1,11 @@ use std::time::Instant; -use plonky2::field::crandall_field::CrandallField; use plonky2::field::field_types::Field; +use plonky2::field::goldilocks_field::GoldilocksField; use plonky2::polynomial::polynomial::PolynomialValues; use rayon::prelude::*; -type F = CrandallField; +type F = GoldilocksField; // This is an estimate of how many LDEs the prover will compute. The biggest component, 86, comes // from wire polynomials which "store" the outputs of S-boxes in our Poseidon gate. diff --git a/src/bin/bench_recursion.rs b/src/bin/bench_recursion.rs index 5c082d86..f3cfcc23 100644 --- a/src/bin/bench_recursion.rs +++ b/src/bin/bench_recursion.rs @@ -1,9 +1,9 @@ use anyhow::Result; use env_logger::Env; use log::info; -use plonky2::field::crandall_field::CrandallField; use plonky2::field::extension_field::Extendable; use plonky2::field::field_types::RichField; +use plonky2::field::goldilocks_field::GoldilocksField; use plonky2::fri::reduction_strategies::FriReductionStrategy; use plonky2::fri::FriConfig; use plonky2::hash::hashing::SPONGE_WIDTH; @@ -18,7 +18,7 @@ fn main() -> Result<()> { // change this to info or warn later. env_logger::Builder::from_env(Env::default().default_filter_or("debug")).init(); - bench_prove::() + bench_prove::() } fn bench_prove, const D: usize>() -> Result<()> { diff --git a/src/bin/generate_constants.rs b/src/bin/generate_constants.rs index 261478aa..60028741 100644 --- a/src/bin/generate_constants.rs +++ b/src/bin/generate_constants.rs @@ -1,14 +1,13 @@ //! Generates random constants using ChaCha20, seeded with zero. -use plonky2::field::crandall_field::CrandallField; -use plonky2::field::field_types::{Field, PrimeField}; +use plonky2::field::field_types::PrimeField; use plonky2::field::goldilocks_field::GoldilocksField; -use rand::SeedableRng; +use rand::{Rng, SeedableRng}; use rand_chacha::ChaCha8Rng; -// We will sample from CrandallField, which is slightly larger than GoldilocksField, then verify -// that each constant also fits in GoldilocksField. -type F = CrandallField; +// For historical reasons, we sample from 0..0xffffffff70000001, which is slightly larger than the +// range of GoldilocksField, then verify that each constant also fits in GoldilocksField. +const SAMPLE_RANGE_END: u64 = 0xffffffff70000001; // const N: usize = 101; // For GMiMC // const N: usize = 8 * 30; // For Posiedon-8 @@ -16,19 +15,19 @@ const N: usize = 12 * 30; // For Posiedon-12 pub(crate) fn main() { let mut rng = ChaCha8Rng::seed_from_u64(0); - let mut constants = [F::ZERO; N]; + let mut constants = [0u64; N]; for i in 0..N { - constants[i] = F::rand_from_rng(&mut rng); - // Make sure the constant fits in the smaller field (Goldilocks) as well. If so, we also - // have random numbers in the smaller field. This may be viewed as rejection sampling, - // except that we never encounter a rejection in practice, so we don't bother handling it. - assert!(constants[i].to_canonical_u64() < GoldilocksField::ORDER); + constants[i] = rng.gen_range(0..SAMPLE_RANGE_END); + // Make sure the constant fits in Goldilocks. If so, we also have random numbers in + // GoldilocksField::ORDER. This may be viewed as rejection sampling, except that we never + // encounter a rejection in practice, so we don't bother handling it. + assert!(constants[i] < GoldilocksField::ORDER); } // Print the constants in the format we prefer in our code. for chunk in constants.chunks(4) { for (i, c) in chunk.iter().enumerate() { - print!("{:#018x},", c.to_canonical_u64()); + print!("{:#018x},", c); if i != chunk.len() - 1 { print!(" "); } diff --git a/src/field/cosets.rs b/src/field/cosets.rs index d0c1ce60..4ad9ba38 100644 --- a/src/field/cosets.rs +++ b/src/field/cosets.rs @@ -26,14 +26,14 @@ mod tests { use std::collections::HashSet; use crate::field::cosets::get_unique_coset_shifts; - use crate::field::crandall_field::CrandallField; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; #[test] fn distinct_cosets() { // TODO: Switch to a smaller test field so that collision rejection is likely to occur. - type F = CrandallField; + type F = GoldilocksField; const SUBGROUP_BITS: usize = 5; const NUM_SHIFTS: usize = 50; diff --git a/src/field/crandall_field.rs b/src/field/crandall_field.rs deleted file mode 100644 index 648830a4..00000000 --- a/src/field/crandall_field.rs +++ /dev/null @@ -1,404 +0,0 @@ -use std::fmt; -use std::fmt::{Debug, Display, Formatter}; -use std::hash::{Hash, Hasher}; -use std::iter::{Product, Sum}; -use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}; - -use num::bigint::BigUint; -use rand::Rng; -use serde::{Deserialize, Serialize}; - -use crate::field::extension_field::quadratic::QuadraticExtension; -use crate::field::extension_field::quartic::QuarticExtension; -use crate::field::extension_field::{Extendable, Frobenius}; -use crate::field::field_types::{Field, PrimeField, RichField}; -use crate::field::inversion::try_inverse_u64; - -/// EPSILON = 9 * 2**28 - 1 -const EPSILON: u64 = 2415919103; - -/// A field designed for use with the Crandall reduction algorithm. -/// -/// Its order is -/// ```ignore -/// P = 2**64 - EPSILON -/// = 2**64 - 9 * 2**28 + 1 -/// = 2**28 * (2**36 - 9) + 1 -/// ``` -#[derive(Copy, Clone, Serialize, Deserialize)] -#[repr(transparent)] // Must be compatible with PackedCrandallAVX2 -pub struct CrandallField(pub u64); - -impl Default for CrandallField { - fn default() -> Self { - Self::ZERO - } -} - -impl PartialEq for CrandallField { - fn eq(&self, other: &Self) -> bool { - self.to_canonical_u64() == other.to_canonical_u64() - } -} - -impl Eq for CrandallField {} - -impl Hash for CrandallField { - fn hash(&self, state: &mut H) { - state.write_u64(self.to_canonical_u64()) - } -} - -impl Display for CrandallField { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - Display::fmt(&self.to_canonical_u64(), f) - } -} - -impl Debug for CrandallField { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - Debug::fmt(&self.to_canonical_u64(), f) - } -} - -impl Field for CrandallField { - type PrimeField = Self; - - const ZERO: Self = Self(0); - const ONE: Self = Self(1); - const TWO: Self = Self(2); - const NEG_ONE: Self = Self(Self::ORDER - 1); - - const CHARACTERISTIC: u64 = Self::ORDER; - const TWO_ADICITY: usize = 28; - - const MULTIPLICATIVE_GROUP_GENERATOR: Self = Self(5); - const POWER_OF_TWO_GENERATOR: Self = Self(10281950781551402419); - - fn order() -> BigUint { - Self::ORDER.into() - } - - #[inline(always)] - fn try_inverse(&self) -> Option { - try_inverse_u64(self) - } - - #[inline] - fn from_canonical_u64(n: u64) -> Self { - debug_assert!(n < Self::ORDER); - Self(n) - } - - #[inline] - fn from_noncanonical_u128(n: u128) -> Self { - reduce128(n) - } - - #[inline] - fn from_noncanonical_u96(n: (u64, u32)) -> Self { - reduce96(n) - } - - fn rand_from_rng(rng: &mut R) -> Self { - Self::from_canonical_u64(rng.gen_range(0..Self::ORDER)) - } - - fn cube_root(&self) -> Self { - let x0 = *self; - let x1 = x0.square(); - let x2 = x1.square(); - let x3 = x2 * x0; - let x4 = x3.square(); - let x5 = x4.square(); - let x7 = x5.square(); - let x8 = x7.square(); - let x9 = x8.square(); - let x10 = x9.square(); - let x11 = x10 * x5; - let x12 = x11.square(); - let x13 = x12.square(); - let x14 = x13.square(); - let x16 = x14.square(); - let x17 = x16.square(); - let x18 = x17.square(); - let x19 = x18.square(); - let x20 = x19.square(); - let x21 = x20 * x11; - let x22 = x21.square(); - let x23 = x22.square(); - let x24 = x23.square(); - let x25 = x24.square(); - let x26 = x25.square(); - let x27 = x26.square(); - let x28 = x27.square(); - let x29 = x28.square(); - let x30 = x29.square(); - let x31 = x30.square(); - let x32 = x31.square(); - let x33 = x32 * x14; - let x34 = x33 * x3; - let x35 = x34.square(); - let x36 = x35 * x34; - let x37 = x36 * x5; - let x38 = x37 * x34; - let x39 = x38 * x37; - let x40 = x39.square(); - let x41 = x40.square(); - let x42 = x41 * x38; - let x43 = x42.square(); - let x44 = x43.square(); - let x45 = x44.square(); - let x46 = x45.square(); - let x47 = x46.square(); - let x48 = x47.square(); - let x49 = x48.square(); - let x50 = x49.square(); - let x51 = x50.square(); - let x52 = x51.square(); - let x53 = x52.square(); - let x54 = x53.square(); - let x55 = x54.square(); - let x56 = x55.square(); - let x57 = x56.square(); - let x58 = x57.square(); - let x59 = x58.square(); - let x60 = x59.square(); - let x61 = x60.square(); - let x62 = x61.square(); - let x63 = x62.square(); - let x64 = x63.square(); - let x65 = x64.square(); - let x66 = x65.square(); - let x67 = x66.square(); - let x68 = x67.square(); - let x69 = x68.square(); - let x70 = x69.square(); - let x71 = x70.square(); - let x72 = x71.square(); - let x73 = x72.square(); - let x74 = x73 * x39; - x74 - } - - #[inline] - fn multiply_accumulate(&self, x: Self, y: Self) -> Self { - // u64 + u64 * u64 cannot overflow. - reduce128((self.0 as u128) + (x.0 as u128) * (y.0 as u128)) - } -} - -impl PrimeField for CrandallField { - const ORDER: u64 = 18446744071293632513; - - #[inline] - fn to_canonical_u64(&self) -> u64 { - let mut c = self.0; - // We only need one condition subtraction, since 2 * ORDER would not fit in a u64. - if c >= Self::ORDER { - c -= Self::ORDER; - } - c - } - - #[inline] - fn to_noncanonical_u64(&self) -> u64 { - self.0 - } - - #[inline] - fn from_noncanonical_u64(n: u64) -> Self { - Self(n) - } - - #[inline] - /// Faster addition for when we know that rhs <= ORDER. If this is the case, then the - /// .to_canonical_u64() that addition usually performs is unnecessary. Omitting it saves three - /// instructions. This function is marked unsafe because it may yield incorrect results if the - /// condition is not satisfied. - unsafe fn add_canonical_u64(&self, rhs: u64) -> Self { - let (sum, over) = self.0.overflowing_add(rhs); - Self(sum.wrapping_sub((over as u64) * Self::ORDER)) - } - - #[inline] - unsafe fn sub_canonical_u64(&self, rhs: u64) -> Self { - let (sum, under) = self.0.overflowing_sub(rhs); - Self(sum.wrapping_add((under as u64) * Self::ORDER)) - } -} - -impl Neg for CrandallField { - type Output = Self; - - #[inline] - fn neg(self) -> Self { - if self.is_zero() { - Self::ZERO - } else { - Self(Self::ORDER - self.to_canonical_u64()) - } - } -} - -impl Add for CrandallField { - type Output = Self; - - #[inline] - #[allow(clippy::suspicious_arithmetic_impl)] - fn add(self, rhs: Self) -> Self { - let rhs_canonical = rhs.to_canonical_u64(); - // rhs_canonical is definitely canonical, so below is safe. - unsafe { self.add_canonical_u64(rhs_canonical) } - } -} - -impl AddAssign for CrandallField { - #[inline] - fn add_assign(&mut self, rhs: Self) { - *self = *self + rhs; - } -} - -impl Sum for CrandallField { - fn sum>(iter: I) -> Self { - iter.fold(Self::ZERO, |acc, x| acc + x) - } -} - -impl Sub for CrandallField { - type Output = Self; - - #[inline] - #[allow(clippy::suspicious_arithmetic_impl)] - fn sub(self, rhs: Self) -> Self { - let (diff, under) = self.0.overflowing_sub(rhs.to_canonical_u64()); - Self(diff.wrapping_add((under as u64) * Self::ORDER)) - } -} - -impl SubAssign for CrandallField { - #[inline] - fn sub_assign(&mut self, rhs: Self) { - *self = *self - rhs; - } -} - -impl Mul for CrandallField { - type Output = Self; - - #[inline] - fn mul(self, rhs: Self) -> Self { - reduce128((self.0 as u128) * (rhs.0 as u128)) - } -} - -impl MulAssign for CrandallField { - #[inline] - fn mul_assign(&mut self, rhs: Self) { - *self = *self * rhs; - } -} - -impl Product for CrandallField { - #[inline] - fn product>(iter: I) -> Self { - iter.reduce(|acc, x| acc * x).unwrap_or(Self::ONE) - } -} - -impl Div for CrandallField { - type Output = Self; - - #[allow(clippy::suspicious_arithmetic_impl)] - fn div(self, rhs: Self) -> Self::Output { - self * rhs.inverse() - } -} - -impl DivAssign for CrandallField { - fn div_assign(&mut self, rhs: Self) { - *self = *self / rhs; - } -} - -impl Extendable<2> for CrandallField { - type Extension = QuadraticExtension; - - // Verifiable in Sage with - // `R. = GF(p)[]; assert (x^2 - 3).is_irreducible()`. - const W: Self = Self(3); - - // DTH_ROOT = W^((ORDER - 1)/2) - const DTH_ROOT: Self = Self(18446744071293632512); - - const EXT_MULTIPLICATIVE_GROUP_GENERATOR: [Self; 2] = - [Self(6483724566312148654), Self(12194665049945415126)]; - - const EXT_POWER_OF_TWO_GENERATOR: [Self; 2] = [Self(0), Self(14420468973723774561)]; -} - -impl Extendable<4> for CrandallField { - type Extension = QuarticExtension; - - const W: Self = Self(3); - - // DTH_ROOT = W^((ORDER - 1)/4) - const DTH_ROOT: Self = Self(6183774639018825925); - - const EXT_MULTIPLICATIVE_GROUP_GENERATOR: [Self; 4] = [ - Self(12476589904174392631), - Self(896937834427772243), - Self(7795248119019507390), - Self(9005769437373554825), - ]; - - const EXT_POWER_OF_TWO_GENERATOR: [Self; 4] = - [Self(0), Self(0), Self(0), Self(15170983443234254033)]; -} - -impl RichField for CrandallField {} - -/// Reduces to a 64-bit value. The result might not be in canonical form; it could be in between the -/// field order and `2^64`. -#[inline] -fn reduce128(x: u128) -> CrandallField { - // This is Crandall's algorithm. When we have some high-order bits (i.e. with a weight of 2^64), - // we convert them to low-order bits by multiplying by EPSILON (the logic is a simple - // generalization of Mersenne prime reduction). The first time we do this, the product will take - // ~96 bits, so we still have some high-order bits. But when we repeat this another time, the - // product will fit in 64 bits. - let (lo_1, hi_1) = split(x); - let (lo_2, hi_2) = split((EPSILON as u128) * (hi_1 as u128) + (lo_1 as u128)); - reduce96((lo_2, hi_2 as u32)) // hi_2 will always fit in a u32. -} - -/// Reduces to a 64-bit value. The result might not be in canonical form; it could be in between the -/// field order and `2^64`. -#[inline] -fn reduce96((x_lo, x_hi): (u64, u32)) -> CrandallField { - // This is Crandall's algorithm. See reduce128. - let t = (x_hi as u64) * EPSILON; - - unsafe { - // This is safe to do because x_lo + t < 2^64 + Self::ORDER. Notice that x_hi <= 2^32 - 1. - // Then t = x_hi * EPSILON <= (2^32 - 1) * EPSILON < Self::ORDER. - // Use of standard addition here would make multiplication 20% more expensive. - CrandallField(x_lo).add_canonical_u64(t) - } -} - -#[inline] -fn split(x: u128) -> (u64, u64) { - (x as u64, (x >> 64) as u64) -} - -impl Frobenius<1> for CrandallField {} - -#[cfg(test)] -mod tests { - use crate::{test_field_arithmetic, test_prime_field_arithmetic}; - - test_prime_field_arithmetic!(crate::field::crandall_field::CrandallField); - test_field_arithmetic!(crate::field::crandall_field::CrandallField); -} diff --git a/src/field/extension_field/algebra.rs b/src/field/extension_field/algebra.rs index 78f787fe..21438262 100644 --- a/src/field/extension_field/algebra.rs +++ b/src/field/extension_field/algebra.rs @@ -172,10 +172,10 @@ impl, const D: usize> PolynomialCoeffsAlgebra { mod tests { use itertools::Itertools; - use crate::field::crandall_field::CrandallField; use crate::field::extension_field::algebra::ExtensionAlgebra; use crate::field::extension_field::{Extendable, FieldExtension}; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; /// Tests that the multiplication on the extension algebra lifts that of the field extension. fn test_extension_algebra, const D: usize>() { @@ -243,7 +243,7 @@ mod tests { #[test] fn test_algebra() { - test_extension_algebra::(); + test_extension_algebra::(); } } @@ -252,7 +252,7 @@ mod tests { #[test] fn test_algebra() { - test_extension_algebra::(); + test_extension_algebra::(); } } @@ -261,7 +261,7 @@ mod tests { #[test] fn test_algebra() { - test_extension_algebra::(); + test_extension_algebra::(); } } } diff --git a/src/field/extension_field/quadratic.rs b/src/field/extension_field/quadratic.rs index 24cb98cb..ebad5025 100644 --- a/src/field/extension_field/quadratic.rs +++ b/src/field/extension_field/quadratic.rs @@ -215,17 +215,6 @@ impl> DivAssign for QuadraticExtension { #[cfg(test)] mod tests { - mod crandall { - use crate::{test_field_arithmetic, test_field_extension}; - - test_field_extension!(crate::field::crandall_field::CrandallField, 2); - test_field_arithmetic!( - crate::field::extension_field::quadratic::QuadraticExtension< - crate::field::crandall_field::CrandallField, - > - ); - } - mod goldilocks { use crate::{test_field_arithmetic, test_field_extension}; diff --git a/src/field/extension_field/quartic.rs b/src/field/extension_field/quartic.rs index fcd398cd..001da821 100644 --- a/src/field/extension_field/quartic.rs +++ b/src/field/extension_field/quartic.rs @@ -241,17 +241,6 @@ impl> DivAssign for QuarticExtension { #[cfg(test)] mod tests { - mod crandall { - use crate::{test_field_arithmetic, test_field_extension}; - - test_field_extension!(crate::field::crandall_field::CrandallField, 4); - test_field_arithmetic!( - crate::field::extension_field::quartic::QuarticExtension< - crate::field::crandall_field::CrandallField, - > - ); - } - mod goldilocks { use crate::{test_field_arithmetic, test_field_extension}; diff --git a/src/field/fft.rs b/src/field/fft.rs index 30197ff9..96f19857 100644 --- a/src/field/fft.rs +++ b/src/field/fft.rs @@ -210,15 +210,15 @@ pub(crate) fn fft_classic(input: &[F], r: usize, root_table: &FftRootT #[cfg(test)] mod tests { - use crate::field::crandall_field::CrandallField; use crate::field::fft::{fft, fft_with_options, ifft}; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::polynomial::polynomial::{PolynomialCoeffs, PolynomialValues}; use crate::util::{log2_ceil, log2_strict}; #[test] fn fft_and_ifft() { - type F = CrandallField; + type F = GoldilocksField; let degree = 200; let degree_padded = log2_ceil(degree); let mut coefficients = Vec::new(); diff --git a/src/field/goldilocks_field.rs b/src/field/goldilocks_field.rs index 16f25037..45164506 100644 --- a/src/field/goldilocks_field.rs +++ b/src/field/goldilocks_field.rs @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize}; use crate::field::extension_field::quadratic::QuadraticExtension; use crate::field::extension_field::quartic::QuarticExtension; -use crate::field::extension_field::Extendable; +use crate::field::extension_field::{Extendable, Frobenius}; use crate::field::field_types::{Field, PrimeField, RichField}; use crate::field::inversion::try_inverse_u64; use crate::util::{assume, branch_hint}; @@ -394,6 +394,8 @@ fn split(x: u128) -> (u64, u64) { (x as u64, (x >> 64) as u64) } +impl Frobenius<1> for GoldilocksField {} + #[cfg(test)] mod tests { use crate::{test_field_arithmetic, test_prime_field_arithmetic}; diff --git a/src/field/interpolation.rs b/src/field/interpolation.rs index f4e7c600..c4a49fe1 100644 --- a/src/field/interpolation.rs +++ b/src/field/interpolation.rs @@ -77,14 +77,14 @@ pub fn interpolate2(points: [(F, F); 2], x: F) -> F { #[cfg(test)] mod tests { use super::*; - use crate::field::crandall_field::CrandallField; use crate::field::extension_field::quartic::QuarticExtension; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::polynomial::polynomial::PolynomialCoeffs; #[test] fn interpolant_random() { - type F = CrandallField; + type F = GoldilocksField; for deg in 0..10 { let domain = F::rand_vec(deg); @@ -98,7 +98,7 @@ mod tests { #[test] fn interpolant_random_roots_of_unity() { - type F = CrandallField; + type F = GoldilocksField; for deg_log in 0..4 { let deg = 1 << deg_log; @@ -113,7 +113,7 @@ mod tests { #[test] fn interpolant_random_overspecified() { - type F = CrandallField; + type F = GoldilocksField; for deg in 0..10 { let points = deg + 5; @@ -132,7 +132,7 @@ mod tests { #[test] fn test_interpolate2() { - type F = QuarticExtension; + type F = QuarticExtension; let points = [(F::rand(), F::rand()), (F::rand(), F::rand())]; let x = F::rand(); diff --git a/src/field/mod.rs b/src/field/mod.rs index cd8a53e2..5ed64a54 100644 --- a/src/field/mod.rs +++ b/src/field/mod.rs @@ -1,5 +1,4 @@ pub(crate) mod cosets; -pub mod crandall_field; pub mod extension_field; pub mod fft; pub mod field_types; @@ -13,9 +12,6 @@ pub mod secp256k1; #[cfg(target_feature = "avx2")] pub(crate) mod packed_avx2; -#[cfg(target_feature = "neon")] -pub(crate) mod packed_crandall_neon; - #[cfg(test)] mod field_testing; #[cfg(test)] diff --git a/src/field/packable.rs b/src/field/packable.rs index 6e3fccb0..94a9c056 100644 --- a/src/field/packable.rs +++ b/src/field/packable.rs @@ -12,11 +12,6 @@ impl Packable for F { default type PackedType = Singleton; } -#[cfg(target_feature = "avx2")] -impl Packable for crate::field::crandall_field::CrandallField { - type PackedType = crate::field::packed_avx2::PackedCrandallAVX2; -} - #[cfg(target_feature = "avx2")] impl Packable for crate::field::goldilocks_field::GoldilocksField { type PackedType = crate::field::packed_avx2::PackedGoldilocksAVX2; diff --git a/src/field/packed_avx2/crandall.rs b/src/field/packed_avx2/crandall.rs deleted file mode 100644 index 0f267f3f..00000000 --- a/src/field/packed_avx2/crandall.rs +++ /dev/null @@ -1,42 +0,0 @@ -use core::arch::x86_64::*; - -use crate::field::crandall_field::CrandallField; -use crate::field::packed_avx2::common::{add_no_canonicalize_64_64s_s, epsilon, ReducibleAVX2}; - -/// (u64 << 64) + u64 + u64 -> u128 addition with carry. The third argument is pre-shifted by 2^63. -/// The result is also shifted. -#[inline] -unsafe fn add_with_carry_hi_lo_los_s( - hi: __m256i, - lo0: __m256i, - lo1_s: __m256i, -) -> (__m256i, __m256i) { - let res_lo_s = _mm256_add_epi64(lo0, lo1_s); - // carry is -1 if overflow (res_lo < lo1) because cmpgt returns -1 on true and 0 on false. - let carry = _mm256_cmpgt_epi64(lo1_s, res_lo_s); - let res_hi = _mm256_sub_epi64(hi, carry); - (res_hi, res_lo_s) -} - -/// u64 * u32 + u64 fused multiply-add. The result is given as a tuple (u64, u64). The third -/// argument is assumed to be pre-shifted by 2^63. The result is similarly shifted. -#[inline] -unsafe fn fmadd_64_32_64s_s(x: __m256i, y: __m256i, z_s: __m256i) -> (__m256i, __m256i) { - let x_hi = _mm256_srli_epi64(x, 32); - let mul_lo = _mm256_mul_epu32(x, y); - let mul_hi = _mm256_mul_epu32(x_hi, y); - let (tmp_hi, tmp_lo_s) = add_with_carry_hi_lo_los_s(_mm256_srli_epi64(mul_hi, 32), mul_lo, z_s); - add_with_carry_hi_lo_los_s(tmp_hi, _mm256_slli_epi64(mul_hi, 32), tmp_lo_s) -} - -/// Reduce a u128 modulo FIELD_ORDER. The input is (u64, u64), pre-shifted by 2^63. The result is -/// similarly shifted. -impl ReducibleAVX2 for CrandallField { - #[inline] - unsafe fn reduce128s_s(x_s: (__m256i, __m256i)) -> __m256i { - let (hi0, lo0_s) = x_s; - let (hi1, lo1_s) = fmadd_64_32_64s_s(hi0, epsilon::(), lo0_s); - let lo2 = _mm256_mul_epu32(hi1, epsilon::()); - add_no_canonicalize_64_64s_s::(lo2, lo1_s) - } -} diff --git a/src/field/packed_avx2/mod.rs b/src/field/packed_avx2/mod.rs index 1aa7c870..eddbb5c9 100644 --- a/src/field/packed_avx2/mod.rs +++ b/src/field/packed_avx2/mod.rs @@ -1,19 +1,15 @@ mod common; -mod crandall; mod goldilocks; mod packed_prime_field; use packed_prime_field::PackedPrimeField; -use crate::field::crandall_field::CrandallField; use crate::field::goldilocks_field::GoldilocksField; -pub type PackedCrandallAVX2 = PackedPrimeField; pub type PackedGoldilocksAVX2 = PackedPrimeField; #[cfg(test)] mod tests { - use crate::field::crandall_field::CrandallField; use crate::field::goldilocks_field::GoldilocksField; use crate::field::packed_avx2::common::ReducibleAVX2; use crate::field::packed_avx2::packed_prime_field::PackedPrimeField; @@ -201,35 +197,6 @@ mod tests { } } - #[test] - fn test_add_crandall() { - test_add::(); - } - #[test] - fn test_mul_crandall() { - test_mul::(); - } - #[test] - fn test_square_crandall() { - test_square::(); - } - #[test] - fn test_neg_crandall() { - test_neg::(); - } - #[test] - fn test_sub_crandall() { - test_sub::(); - } - #[test] - fn test_interleave_is_involution_crandall() { - test_interleave_is_involution::(); - } - #[test] - fn test_interleave_crandall() { - test_interleave::(); - } - #[test] fn test_add_goldilocks() { test_add::(); diff --git a/src/field/packed_crandall_neon.rs b/src/field/packed_crandall_neon.rs deleted file mode 100644 index 4df9acaa..00000000 --- a/src/field/packed_crandall_neon.rs +++ /dev/null @@ -1,251 +0,0 @@ -use core::arch::aarch64::*; -use std::convert::TryInto; -use std::fmt; -use std::fmt::{Debug, Formatter}; -use std::iter::{Product, Sum}; -use std::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign}; - -use crate::field::crandall_field::CrandallField; -use crate::field::field_types::PrimeField; -use crate::field::packed_field::PackedField; - -/// PackedCrandallNeon wraps to ensure that Rust does not assume 16-byte alignment. Similar to -/// AVX2's PackedPrimeField. I don't think it matters as much on ARM but incorrectly-aligned -/// pointers are undefined behavior in Rust, so let's avoid them. -#[derive(Copy, Clone)] -#[repr(transparent)] -pub struct PackedCrandallNeon(pub [CrandallField; 2]); - -impl PackedCrandallNeon { - #[inline] - fn new(x: uint64x2_t) -> Self { - let x0 = unsafe { vgetq_lane_u64::<0>(x) }; - let x1 = unsafe { vgetq_lane_u64::<1>(x) }; - Self([CrandallField(x0), CrandallField(x1)]) - } - #[inline] - fn get(&self) -> uint64x2_t { - let x0 = self.0[0].0; - let x1 = self.0[1].0; - unsafe { vcombine_u64(vmov_n_u64(x0), vmov_n_u64(x1)) } - } - - /// Addition that assumes x + y < 2^64 + F::ORDER. May return incorrect results if this - /// condition is not met, hence it is marked unsafe. - #[inline] - pub unsafe fn add_canonical_u64(&self, rhs: uint64x2_t) -> Self { - Self::new(add_canonical_u64(self.get(), rhs)) - } -} - -impl Add for PackedCrandallNeon { - type Output = Self; - #[inline] - fn add(self, rhs: Self) -> Self { - Self::new(unsafe { add(self.get(), rhs.get()) }) - } -} -impl Add for PackedCrandallNeon { - type Output = Self; - #[inline] - fn add(self, rhs: CrandallField) -> Self { - self + Self::broadcast(rhs) - } -} -impl AddAssign for PackedCrandallNeon { - #[inline] - fn add_assign(&mut self, rhs: Self) { - *self = *self + rhs; - } -} -impl AddAssign for PackedCrandallNeon { - #[inline] - fn add_assign(&mut self, rhs: CrandallField) { - *self = *self + rhs; - } -} - -impl Debug for PackedCrandallNeon { - #[inline] - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - write!(f, "({:?})", self.get()) - } -} - -impl Default for PackedCrandallNeon { - #[inline] - fn default() -> Self { - Self::zero() - } -} - -impl Mul for PackedCrandallNeon { - type Output = Self; - #[inline] - fn mul(self, rhs: Self) -> Self { - // TODO: Implement. - // Do this in scalar for now. - Self([self.0[0] * rhs.0[0], self.0[1] * rhs.0[1]]) - } -} -impl Mul for PackedCrandallNeon { - type Output = Self; - #[inline] - fn mul(self, rhs: CrandallField) -> Self { - self * Self::broadcast(rhs) - } -} -impl MulAssign for PackedCrandallNeon { - #[inline] - fn mul_assign(&mut self, rhs: Self) { - *self = *self * rhs; - } -} -impl MulAssign for PackedCrandallNeon { - #[inline] - fn mul_assign(&mut self, rhs: CrandallField) { - *self = *self * rhs; - } -} - -impl Neg for PackedCrandallNeon { - type Output = Self; - #[inline] - fn neg(self) -> Self { - Self::new(unsafe { neg(self.get()) }) - } -} - -impl Product for PackedCrandallNeon { - #[inline] - fn product>(iter: I) -> Self { - iter.reduce(|x, y| x * y).unwrap_or(Self::one()) - } -} - -impl PackedField for PackedCrandallNeon { - const LOG2_WIDTH: usize = 1; - - type FieldType = CrandallField; - - #[inline] - fn broadcast(x: CrandallField) -> Self { - Self([x; 2]) - } - - #[inline] - fn from_arr(arr: [Self::FieldType; Self::WIDTH]) -> Self { - Self(arr) - } - - #[inline] - fn to_arr(&self) -> [Self::FieldType; Self::WIDTH] { - self.0 - } - - #[inline] - fn from_slice(slice: &[CrandallField]) -> Self { - Self(slice.try_into().unwrap()) - } - - #[inline] - fn to_vec(&self) -> Vec { - self.0.into() - } - - #[inline] - fn interleave(&self, other: Self, r: usize) -> (Self, Self) { - let (v0, v1) = (self.get(), other.get()); - let (res0, res1) = match r { - 0 => unsafe { interleave0(v0, v1) }, - 1 => (v0, v1), - _ => panic!("r cannot be more than LOG2_WIDTH"), - }; - (Self::new(res0), Self::new(res1)) - } -} - -impl Sub for PackedCrandallNeon { - type Output = Self; - #[inline] - fn sub(self, rhs: Self) -> Self { - Self::new(unsafe { sub(self.get(), rhs.get()) }) - } -} -impl Sub for PackedCrandallNeon { - type Output = Self; - #[inline] - fn sub(self, rhs: CrandallField) -> Self { - self - Self::broadcast(rhs) - } -} -impl SubAssign for PackedCrandallNeon { - #[inline] - fn sub_assign(&mut self, rhs: Self) { - *self = *self - rhs; - } -} -impl SubAssign for PackedCrandallNeon { - #[inline] - fn sub_assign(&mut self, rhs: CrandallField) { - *self = *self - rhs; - } -} - -impl Sum for PackedCrandallNeon { - #[inline] - fn sum>(iter: I) -> Self { - iter.reduce(|x, y| x + y).unwrap_or(Self::zero()) - } -} - -const FIELD_ORDER: u64 = CrandallField::ORDER; - -#[inline] -unsafe fn field_order() -> uint64x2_t { - vmovq_n_u64(FIELD_ORDER) -} - -#[inline] -unsafe fn canonicalize(x: uint64x2_t) -> uint64x2_t { - let mask = vcgeq_u64(x, field_order()); // Mask is -1 if x >= FIELD_ORDER. - let x_maybe_unwrapped = vsubq_u64(x, field_order()); - vbslq_u64(mask, x_maybe_unwrapped, x) // Bitwise select -} - -#[inline] -unsafe fn add_no_canonicalize_64_64(x: uint64x2_t, y: uint64x2_t) -> uint64x2_t { - let res_wrapped = vaddq_u64(x, y); - let mask = vcgtq_u64(y, res_wrapped); // Mask is -1 if overflow. - let res_maybe_unwrapped = vsubq_u64(res_wrapped, field_order()); - vbslq_u64(mask, res_maybe_unwrapped, res_wrapped) // Bitwise select -} - -#[inline] -unsafe fn add_canonical_u64(x: uint64x2_t, y: uint64x2_t) -> uint64x2_t { - add_no_canonicalize_64_64(x, y) -} - -#[inline] -unsafe fn add(x: uint64x2_t, y: uint64x2_t) -> uint64x2_t { - add_no_canonicalize_64_64(x, canonicalize(y)) -} - -#[inline] -unsafe fn sub(x: uint64x2_t, y: uint64x2_t) -> uint64x2_t { - let y = canonicalize(y); - let mask = vcgtq_u64(y, x); // Mask is -1 if overflow. - let res_wrapped = vsubq_u64(x, y); - let res_maybe_unwrapped = vaddq_u64(res_wrapped, field_order()); - vbslq_u64(mask, res_maybe_unwrapped, res_wrapped) // Bitwise select -} - -#[inline] -unsafe fn neg(y: uint64x2_t) -> uint64x2_t { - vsubq_u64(field_order(), canonicalize(y)) -} - -#[inline] -unsafe fn interleave0(x: uint64x2_t, y: uint64x2_t) -> (uint64x2_t, uint64x2_t) { - (vtrn1q_u64(x, y), vtrn2q_u64(x, y)) -} diff --git a/src/gadgets/arithmetic_extension.rs b/src/gadgets/arithmetic_extension.rs index 2a602f04..3f35663a 100644 --- a/src/gadgets/arithmetic_extension.rs +++ b/src/gadgets/arithmetic_extension.rs @@ -528,10 +528,10 @@ mod tests { use anyhow::Result; - use crate::field::crandall_field::CrandallField; use crate::field::extension_field::algebra::ExtensionAlgebra; use crate::field::extension_field::quartic::QuarticExtension; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::iop::witness::{PartialWitness, Witness}; use crate::plonk::circuit_builder::CircuitBuilder; use crate::plonk::circuit_data::CircuitConfig; @@ -539,8 +539,8 @@ mod tests { #[test] fn test_mul_many() -> Result<()> { - type F = CrandallField; - type FF = QuarticExtension; + type F = GoldilocksField; + type FF = QuarticExtension; const D: usize = 4; let config = CircuitConfig::large_config(); @@ -574,8 +574,8 @@ mod tests { #[test] fn test_div_extension() -> Result<()> { - type F = CrandallField; - type FF = QuarticExtension; + type F = GoldilocksField; + type FF = QuarticExtension; const D: usize = 4; let config = CircuitConfig::large_zk_config(); @@ -602,8 +602,8 @@ mod tests { #[test] fn test_mul_algebra() -> Result<()> { - type F = CrandallField; - type FF = QuarticExtension; + type F = GoldilocksField; + type FF = QuarticExtension; const D: usize = 4; let config = CircuitConfig::large_config(); diff --git a/src/gadgets/insert.rs b/src/gadgets/insert.rs index 2963d52f..0759fc40 100644 --- a/src/gadgets/insert.rs +++ b/src/gadgets/insert.rs @@ -43,9 +43,9 @@ mod tests { use anyhow::Result; use super::*; - use crate::field::crandall_field::CrandallField; use crate::field::extension_field::quartic::QuarticExtension; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::iop::witness::PartialWitness; use crate::plonk::circuit_data::CircuitConfig; use crate::plonk::verifier::verify; @@ -61,8 +61,8 @@ mod tests { } fn test_insert_given_len(len_log: usize) -> Result<()> { - type F = CrandallField; - type FF = QuarticExtension; + type F = GoldilocksField; + type FF = QuarticExtension; let len = 1 << len_log; let config = CircuitConfig::large_config(); let pw = PartialWitness::new(); diff --git a/src/gadgets/interpolation.rs b/src/gadgets/interpolation.rs index f5a90b0b..fadcfb4b 100644 --- a/src/gadgets/interpolation.rs +++ b/src/gadgets/interpolation.rs @@ -35,10 +35,10 @@ impl, const D: usize> CircuitBuilder { mod tests { use anyhow::Result; - use crate::field::crandall_field::CrandallField; use crate::field::extension_field::quartic::QuarticExtension; use crate::field::extension_field::FieldExtension; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::field::interpolation::interpolant; use crate::iop::witness::PartialWitness; use crate::plonk::circuit_builder::CircuitBuilder; @@ -47,8 +47,8 @@ mod tests { #[test] fn test_interpolate() -> Result<()> { - type F = CrandallField; - type FF = QuarticExtension; + type F = GoldilocksField; + type FF = QuarticExtension; let config = CircuitConfig::large_config(); let pw = PartialWitness::new(); let mut builder = CircuitBuilder::::new(config); diff --git a/src/gadgets/permutation.rs b/src/gadgets/permutation.rs index 4479ccb0..c4762946 100644 --- a/src/gadgets/permutation.rs +++ b/src/gadgets/permutation.rs @@ -387,14 +387,14 @@ mod tests { use rand::{seq::SliceRandom, thread_rng, Rng}; use super::*; - use crate::field::crandall_field::CrandallField; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::iop::witness::PartialWitness; use crate::plonk::circuit_data::CircuitConfig; use crate::plonk::verifier::verify; fn test_permutation_good(size: usize) -> Result<()> { - type F = CrandallField; + type F = GoldilocksField; const D: usize = 4; let config = CircuitConfig::large_config(); @@ -419,7 +419,7 @@ mod tests { } fn test_permutation_duplicates(size: usize) -> Result<()> { - type F = CrandallField; + type F = GoldilocksField; const D: usize = 4; let config = CircuitConfig::large_config(); @@ -448,7 +448,7 @@ mod tests { } fn test_permutation_bad(size: usize) -> Result<()> { - type F = CrandallField; + type F = GoldilocksField; const D: usize = 4; let config = CircuitConfig::large_config(); diff --git a/src/gadgets/random_access.rs b/src/gadgets/random_access.rs index 9875385f..3dc064ac 100644 --- a/src/gadgets/random_access.rs +++ b/src/gadgets/random_access.rs @@ -87,16 +87,16 @@ mod tests { use anyhow::Result; use super::*; - use crate::field::crandall_field::CrandallField; use crate::field::extension_field::quartic::QuarticExtension; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::iop::witness::PartialWitness; use crate::plonk::circuit_data::CircuitConfig; use crate::plonk::verifier::verify; fn test_random_access_given_len(len_log: usize) -> Result<()> { - type F = CrandallField; - type FF = QuarticExtension; + type F = GoldilocksField; + type FF = QuarticExtension; let len = 1 << len_log; let config = CircuitConfig::large_config(); let pw = PartialWitness::new(); diff --git a/src/gadgets/select.rs b/src/gadgets/select.rs index 2b906a61..65c2d0fd 100644 --- a/src/gadgets/select.rs +++ b/src/gadgets/select.rs @@ -41,9 +41,9 @@ impl, const D: usize> CircuitBuilder { mod tests { use anyhow::Result; - use crate::field::crandall_field::CrandallField; use crate::field::extension_field::quartic::QuarticExtension; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::iop::witness::{PartialWitness, Witness}; use crate::plonk::circuit_builder::CircuitBuilder; use crate::plonk::circuit_data::CircuitConfig; @@ -51,8 +51,8 @@ mod tests { #[test] fn test_select() -> Result<()> { - type F = CrandallField; - type FF = QuarticExtension; + type F = GoldilocksField; + type FF = QuarticExtension; let config = CircuitConfig::large_config(); let mut pw = PartialWitness::new(); let mut builder = CircuitBuilder::::new(config); diff --git a/src/gadgets/sorting.rs b/src/gadgets/sorting.rs index 641cd52a..8495e79d 100644 --- a/src/gadgets/sorting.rs +++ b/src/gadgets/sorting.rs @@ -176,14 +176,14 @@ mod tests { use rand::{thread_rng, Rng}; use super::*; - use crate::field::crandall_field::CrandallField; use crate::field::field_types::{Field, PrimeField}; + use crate::field::goldilocks_field::GoldilocksField; use crate::iop::witness::PartialWitness; use crate::plonk::circuit_data::CircuitConfig; use crate::plonk::verifier::verify; fn test_sorting(size: usize, address_bits: usize, timestamp_bits: usize) -> Result<()> { - type F = CrandallField; + type F = GoldilocksField; const D: usize = 4; let config = CircuitConfig::large_config(); diff --git a/src/gadgets/split_base.rs b/src/gadgets/split_base.rs index c900d1a8..121c5529 100644 --- a/src/gadgets/split_base.rs +++ b/src/gadgets/split_base.rs @@ -102,8 +102,8 @@ mod tests { use anyhow::Result; use rand::{thread_rng, Rng}; - use crate::field::crandall_field::CrandallField; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::iop::witness::PartialWitness; use crate::plonk::circuit_builder::CircuitBuilder; use crate::plonk::circuit_data::CircuitConfig; @@ -111,7 +111,7 @@ mod tests { #[test] fn test_split_base() -> Result<()> { - type F = CrandallField; + type F = GoldilocksField; let config = CircuitConfig::large_config(); let pw = PartialWitness::new(); let mut builder = CircuitBuilder::::new(config); @@ -137,7 +137,7 @@ mod tests { #[test] fn test_base_sum() -> Result<()> { - type F = CrandallField; + type F = GoldilocksField; let config = CircuitConfig::large_config(); let pw = PartialWitness::new(); let mut builder = CircuitBuilder::::new(config); diff --git a/src/gates/arithmetic.rs b/src/gates/arithmetic.rs index 7e4e0c96..19410358 100644 --- a/src/gates/arithmetic.rs +++ b/src/gates/arithmetic.rs @@ -206,7 +206,7 @@ impl, const D: usize> SimpleGenerator mod tests { use anyhow::Result; - use crate::field::crandall_field::CrandallField; + use crate::field::goldilocks_field::GoldilocksField; use crate::gates::arithmetic::ArithmeticExtensionGate; use crate::gates::gate_testing::{test_eval_fns, test_low_degree}; use crate::plonk::circuit_data::CircuitConfig; @@ -214,12 +214,12 @@ mod tests { #[test] fn low_degree() { let gate = ArithmeticExtensionGate::new_from_config(&CircuitConfig::large_config()); - test_low_degree::(gate); + test_low_degree::(gate); } #[test] fn eval_fns() -> Result<()> { let gate = ArithmeticExtensionGate::new_from_config(&CircuitConfig::large_config()); - test_eval_fns::(gate) + test_eval_fns::(gate) } } diff --git a/src/gates/arithmetic_u32.rs b/src/gates/arithmetic_u32.rs index af4d34e8..6564a876 100644 --- a/src/gates/arithmetic_u32.rs +++ b/src/gates/arithmetic_u32.rs @@ -330,9 +330,9 @@ mod tests { use anyhow::Result; use rand::Rng; - use crate::field::crandall_field::CrandallField; use crate::field::extension_field::quartic::QuarticExtension; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::gates::arithmetic_u32::{U32ArithmeticGate, NUM_U32_ARITHMETIC_OPS}; use crate::gates::gate::Gate; use crate::gates::gate_testing::{test_eval_fns, test_low_degree}; @@ -341,22 +341,22 @@ mod tests { #[test] fn low_degree() { - test_low_degree::(U32ArithmeticGate:: { + test_low_degree::(U32ArithmeticGate:: { _phantom: PhantomData, }) } #[test] fn eval_fns() -> Result<()> { - test_eval_fns::(U32ArithmeticGate:: { + test_eval_fns::(U32ArithmeticGate:: { _phantom: PhantomData, }) } #[test] fn test_gate_constraint() { - type F = CrandallField; - type FF = QuarticExtension; + type F = GoldilocksField; + type FF = QuarticExtension; const D: usize = 4; fn get_wires( diff --git a/src/gates/base_sum.rs b/src/gates/base_sum.rs index 3249821b..99ee05eb 100644 --- a/src/gates/base_sum.rs +++ b/src/gates/base_sum.rs @@ -176,17 +176,17 @@ impl SimpleGenerator for BaseSplitGenerator mod tests { use anyhow::Result; - use crate::field::crandall_field::CrandallField; + use crate::field::goldilocks_field::GoldilocksField; use crate::gates::base_sum::BaseSumGate; use crate::gates::gate_testing::{test_eval_fns, test_low_degree}; #[test] fn low_degree() { - test_low_degree::(BaseSumGate::<6>::new(11)) + test_low_degree::(BaseSumGate::<6>::new(11)) } #[test] fn eval_fns() -> Result<()> { - test_eval_fns::(BaseSumGate::<6>::new(11)) + test_eval_fns::(BaseSumGate::<6>::new(11)) } } diff --git a/src/gates/comparison.rs b/src/gates/comparison.rs index 0715b066..988086d0 100644 --- a/src/gates/comparison.rs +++ b/src/gates/comparison.rs @@ -430,9 +430,9 @@ mod tests { use anyhow::Result; use rand::Rng; - use crate::field::crandall_field::CrandallField; use crate::field::extension_field::quartic::QuarticExtension; use crate::field::field_types::{Field, PrimeField}; + use crate::field::goldilocks_field::GoldilocksField; use crate::gates::comparison::ComparisonGate; use crate::gates::gate::Gate; use crate::gates::gate_testing::{test_eval_fns, test_low_degree}; @@ -441,7 +441,7 @@ mod tests { #[test] fn wire_indices() { - type CG = ComparisonGate; + type CG = ComparisonGate; let num_bits = 40; let num_chunks = 5; @@ -471,7 +471,7 @@ mod tests { let num_bits = 40; let num_chunks = 5; - test_low_degree::(ComparisonGate::<_, 4>::new(num_bits, num_chunks)) + test_low_degree::(ComparisonGate::<_, 4>::new(num_bits, num_chunks)) } #[test] @@ -479,13 +479,13 @@ mod tests { let num_bits = 40; let num_chunks = 5; - test_eval_fns::(ComparisonGate::<_, 4>::new(num_bits, num_chunks)) + test_eval_fns::(ComparisonGate::<_, 4>::new(num_bits, num_chunks)) } #[test] fn test_gate_constraint() { - type F = CrandallField; - type FF = QuarticExtension; + type F = GoldilocksField; + type FF = QuarticExtension; const D: usize = 4; let num_bits = 40; diff --git a/src/gates/constant.rs b/src/gates/constant.rs index 7b2a8f34..b9cea895 100644 --- a/src/gates/constant.rs +++ b/src/gates/constant.rs @@ -98,17 +98,17 @@ impl SimpleGenerator for ConstantGenerator { mod tests { use anyhow::Result; - use crate::field::crandall_field::CrandallField; + use crate::field::goldilocks_field::GoldilocksField; use crate::gates::constant::ConstantGate; use crate::gates::gate_testing::{test_eval_fns, test_low_degree}; #[test] fn low_degree() { - test_low_degree::(ConstantGate) + test_low_degree::(ConstantGate) } #[test] fn eval_fns() -> Result<()> { - test_eval_fns::(ConstantGate) + test_eval_fns::(ConstantGate) } } diff --git a/src/gates/exponentiation.rs b/src/gates/exponentiation.rs index 5df09d1c..86dd9fb1 100644 --- a/src/gates/exponentiation.rs +++ b/src/gates/exponentiation.rs @@ -266,9 +266,9 @@ mod tests { use anyhow::Result; use rand::Rng; - use crate::field::crandall_field::CrandallField; use crate::field::extension_field::quartic::QuarticExtension; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::gates::exponentiation::ExponentiationGate; use crate::gates::gate::Gate; use crate::gates::gate_testing::{test_eval_fns, test_low_degree}; @@ -281,7 +281,7 @@ mod tests { #[test] fn wire_indices() { - let gate = ExponentiationGate:: { + let gate = ExponentiationGate:: { num_power_bits: 5, _phantom: PhantomData, }; @@ -302,20 +302,20 @@ mod tests { ..CircuitConfig::large_config() }; - test_low_degree::(ExponentiationGate::new_from_config(&config)); + test_low_degree::(ExponentiationGate::new_from_config(&config)); } #[test] fn eval_fns() -> Result<()> { - test_eval_fns::(ExponentiationGate::new_from_config( + test_eval_fns::(ExponentiationGate::new_from_config( &CircuitConfig::large_config(), )) } #[test] fn test_gate_constraint() { - type F = CrandallField; - type FF = QuarticExtension; + type F = GoldilocksField; + type FF = QuarticExtension; const D: usize = 4; /// Returns the local wires for an exponentiation gate given the base, power, and power bit diff --git a/src/gates/gate_tree.rs b/src/gates/gate_tree.rs index 10acc9e2..93081074 100644 --- a/src/gates/gate_tree.rs +++ b/src/gates/gate_tree.rs @@ -222,7 +222,7 @@ impl, const D: usize> Tree> { #[cfg(test)] mod tests { use super::*; - use crate::field::crandall_field::CrandallField; + use crate::field::goldilocks_field::GoldilocksField; use crate::gates::arithmetic::ArithmeticExtensionGate; use crate::gates::base_sum::BaseSumGate; use crate::gates::constant::ConstantGate; @@ -233,7 +233,7 @@ mod tests { #[test] fn test_prefix_generation() { env_logger::init(); - type F = CrandallField; + type F = GoldilocksField; const D: usize = 4; let gates = vec![ diff --git a/src/gates/gmimc.rs b/src/gates/gmimc.rs index 716da5bd..4f5b971b 100644 --- a/src/gates/gmimc.rs +++ b/src/gates/gmimc.rs @@ -332,8 +332,8 @@ mod tests { use anyhow::Result; - use crate::field::crandall_field::CrandallField; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::gates::gate_testing::{test_eval_fns, test_low_degree}; use crate::gates::gmimc::GMiMCGate; use crate::hash::gmimc::GMiMC; @@ -345,7 +345,7 @@ mod tests { #[test] fn generated_output() { - type F = CrandallField; + type F = GoldilocksField; const WIDTH: usize = 12; let config = CircuitConfig::large_config(); @@ -390,7 +390,7 @@ mod tests { #[test] fn low_degree() { - type F = CrandallField; + type F = GoldilocksField; const WIDTH: usize = 12; let gate = GMiMCGate::::new(); test_low_degree(gate) @@ -398,7 +398,7 @@ mod tests { #[test] fn eval_fns() -> Result<()> { - type F = CrandallField; + type F = GoldilocksField; const WIDTH: usize = 12; let gate = GMiMCGate::::new(); test_eval_fns(gate) diff --git a/src/gates/insertion.rs b/src/gates/insertion.rs index fc33307f..dcc79f05 100644 --- a/src/gates/insertion.rs +++ b/src/gates/insertion.rs @@ -324,9 +324,9 @@ mod tests { use anyhow::Result; - use crate::field::crandall_field::CrandallField; use crate::field::extension_field::quartic::QuarticExtension; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::gates::gate::Gate; use crate::gates::gate_testing::{test_eval_fns, test_low_degree}; use crate::gates::insertion::InsertionGate; @@ -335,7 +335,7 @@ mod tests { #[test] fn wire_indices() { - let gate = InsertionGate:: { + let gate = InsertionGate:: { vec_size: 3, _phantom: PhantomData, }; @@ -354,18 +354,18 @@ mod tests { #[test] fn low_degree() { - test_low_degree::(InsertionGate::new(4)); + test_low_degree::(InsertionGate::new(4)); } #[test] fn eval_fns() -> Result<()> { - test_eval_fns::(InsertionGate::new(4)) + test_eval_fns::(InsertionGate::new(4)) } #[test] fn test_gate_constraint() { - type F = CrandallField; - type FF = QuarticExtension; + type F = GoldilocksField; + type FF = QuarticExtension; const D: usize = 4; /// Returns the local wires for an insertion gate given the original vector, element to diff --git a/src/gates/interpolation.rs b/src/gates/interpolation.rs index 952f26b3..24b755d0 100644 --- a/src/gates/interpolation.rs +++ b/src/gates/interpolation.rs @@ -295,9 +295,9 @@ mod tests { use anyhow::Result; - use crate::field::crandall_field::CrandallField; use crate::field::extension_field::quartic::QuarticExtension; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::gates::gate::Gate; use crate::gates::gate_testing::{test_eval_fns, test_low_degree}; use crate::gates::interpolation::InterpolationGate; @@ -307,7 +307,7 @@ mod tests { #[test] fn wire_indices() { - let gate = InterpolationGate:: { + let gate = InterpolationGate:: { num_points: 2, _phantom: PhantomData, }; @@ -327,18 +327,18 @@ mod tests { #[test] fn low_degree() { - test_low_degree::(InterpolationGate::new(4)); + test_low_degree::(InterpolationGate::new(4)); } #[test] fn eval_fns() -> Result<()> { - test_eval_fns::(InterpolationGate::new(4)) + test_eval_fns::(InterpolationGate::new(4)) } #[test] fn test_gate_constraint() { - type F = CrandallField; - type FF = QuarticExtension; + type F = GoldilocksField; + type FF = QuarticExtension; const D: usize = 4; /// Returns the local wires for an interpolation gate for given coeffs, points and eval point. diff --git a/src/gates/noop.rs b/src/gates/noop.rs index e0c9d803..e615366b 100644 --- a/src/gates/noop.rs +++ b/src/gates/noop.rs @@ -57,17 +57,17 @@ impl, const D: usize> Gate for NoopGate { #[cfg(test)] mod tests { - use crate::field::crandall_field::CrandallField; + use crate::field::goldilocks_field::GoldilocksField; use crate::gates::gate_testing::{test_eval_fns, test_low_degree}; use crate::gates::noop::NoopGate; #[test] fn low_degree() { - test_low_degree::(NoopGate) + test_low_degree::(NoopGate) } #[test] fn eval_fns() -> anyhow::Result<()> { - test_eval_fns::(NoopGate) + test_eval_fns::(NoopGate) } } diff --git a/src/gates/poseidon.rs b/src/gates/poseidon.rs index 39fe0e98..40b987c8 100644 --- a/src/gates/poseidon.rs +++ b/src/gates/poseidon.rs @@ -510,8 +510,8 @@ mod tests { use anyhow::Result; - use crate::field::crandall_field::CrandallField; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::gates::gate_testing::{test_eval_fns, test_low_degree}; use crate::gates::poseidon::PoseidonGate; use crate::hash::hashing::SPONGE_WIDTH; @@ -524,7 +524,7 @@ mod tests { #[test] fn generated_output() { - type F = CrandallField; + type F = GoldilocksField; const WIDTH: usize = 12; let config = CircuitConfig { @@ -571,14 +571,14 @@ mod tests { #[test] fn low_degree() { - type F = CrandallField; + type F = GoldilocksField; let gate = PoseidonGate::::new(); test_low_degree(gate) } #[test] fn eval_fns() -> Result<()> { - type F = CrandallField; + type F = GoldilocksField; let gate = PoseidonGate::::new(); test_eval_fns(gate) } diff --git a/src/gates/public_input.rs b/src/gates/public_input.rs index 2c0899dd..4001cf2a 100644 --- a/src/gates/public_input.rs +++ b/src/gates/public_input.rs @@ -77,17 +77,17 @@ impl, const D: usize> Gate for PublicInputGat #[cfg(test)] mod tests { - use crate::field::crandall_field::CrandallField; + use crate::field::goldilocks_field::GoldilocksField; use crate::gates::gate_testing::{test_eval_fns, test_low_degree}; use crate::gates::public_input::PublicInputGate; #[test] fn low_degree() { - test_low_degree::(PublicInputGate) + test_low_degree::(PublicInputGate) } #[test] fn eval_fns() -> anyhow::Result<()> { - test_eval_fns::(PublicInputGate) + test_eval_fns::(PublicInputGate) } } diff --git a/src/gates/random_access.rs b/src/gates/random_access.rs index 71851725..bdbff667 100644 --- a/src/gates/random_access.rs +++ b/src/gates/random_access.rs @@ -292,9 +292,9 @@ mod tests { use anyhow::Result; use rand::{thread_rng, Rng}; - use crate::field::crandall_field::CrandallField; use crate::field::extension_field::quartic::QuarticExtension; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::gates::gate::Gate; use crate::gates::gate_testing::{test_eval_fns, test_low_degree}; use crate::gates::random_access::RandomAccessGate; @@ -303,18 +303,18 @@ mod tests { #[test] fn low_degree() { - test_low_degree::(RandomAccessGate::new(4, 4)); + test_low_degree::(RandomAccessGate::new(4, 4)); } #[test] fn eval_fns() -> Result<()> { - test_eval_fns::(RandomAccessGate::new(4, 4)) + test_eval_fns::(RandomAccessGate::new(4, 4)) } #[test] fn test_gate_constraint() { - type F = CrandallField; - type FF = QuarticExtension; + type F = GoldilocksField; + type FF = QuarticExtension; const D: usize = 4; /// Returns the local wires for a random access gate given the vectors, elements to compare, diff --git a/src/gates/reducing.rs b/src/gates/reducing.rs index 013f3e27..56d8f590 100644 --- a/src/gates/reducing.rs +++ b/src/gates/reducing.rs @@ -213,17 +213,17 @@ impl, const D: usize> SimpleGenerator for ReducingGenerator< mod tests { use anyhow::Result; - use crate::field::crandall_field::CrandallField; + use crate::field::goldilocks_field::GoldilocksField; use crate::gates::gate_testing::{test_eval_fns, test_low_degree}; use crate::gates::reducing::ReducingGate; #[test] fn low_degree() { - test_low_degree::(ReducingGate::new(22)); + test_low_degree::(ReducingGate::new(22)); } #[test] fn eval_fns() -> Result<()> { - test_eval_fns::(ReducingGate::new(22)) + test_eval_fns::(ReducingGate::new(22)) } } diff --git a/src/gates/switch.rs b/src/gates/switch.rs index ca453f98..480905fa 100644 --- a/src/gates/switch.rs +++ b/src/gates/switch.rs @@ -312,9 +312,9 @@ mod tests { use anyhow::Result; - use crate::field::crandall_field::CrandallField; use crate::field::extension_field::quartic::QuarticExtension; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::gates::gate::Gate; use crate::gates::gate_testing::{test_eval_fns, test_low_degree}; use crate::gates::switch::SwitchGate; @@ -324,7 +324,7 @@ mod tests { #[test] fn wire_indices() { - type SG = SwitchGate; + type SG = SwitchGate; let num_copies = 3; let chunk_size = 3; @@ -351,7 +351,7 @@ mod tests { #[test] fn low_degree() { - test_low_degree::(SwitchGate::<_, 4>::new_from_config( + test_low_degree::(SwitchGate::<_, 4>::new_from_config( &CircuitConfig::large_config(), 3, )); @@ -359,7 +359,7 @@ mod tests { #[test] fn eval_fns() -> Result<()> { - test_eval_fns::(SwitchGate::<_, 4>::new_from_config( + test_eval_fns::(SwitchGate::<_, 4>::new_from_config( &CircuitConfig::large_config(), 3, )) @@ -367,8 +367,8 @@ mod tests { #[test] fn test_gate_constraint() { - type F = CrandallField; - type FF = QuarticExtension; + type F = GoldilocksField; + type FF = QuarticExtension; const D: usize = 4; const CHUNK_SIZE: usize = 4; let num_copies = 3; diff --git a/src/hash/gmimc.rs b/src/hash/gmimc.rs index e64c940f..c559dd2f 100644 --- a/src/hash/gmimc.rs +++ b/src/hash/gmimc.rs @@ -1,6 +1,5 @@ use unroll::unroll_for_loops; -use crate::field::crandall_field::CrandallField; use crate::field::field_types::Field; use crate::field::goldilocks_field::GoldilocksField; @@ -50,7 +49,7 @@ where /// See `generate_constants` about how these were generated. #[rustfmt::skip] -const CRANDALL_AND_GOLDILOCKS_ROUND_CONSTANTS: [u64; NUM_ROUNDS] = [ +const GOLDILOCKS_ROUND_CONSTANTS: [u64; NUM_ROUNDS] = [ 0xb585f767417ee042, 0x7746a55f77c10331, 0xb2fb0d321d356f7a, 0x0f6760a486f1621f, 0xe10d6666b36abcdf, 0x8cae14cb455cc50b, 0xd438539cf2cee334, 0xef781c7d4c1fd8b4, 0xcdc4a23a0aca4b1f, 0x277fa208d07b52e3, 0xe17653a300493d38, 0xc54302f27c287dc1, @@ -79,25 +78,17 @@ const CRANDALL_AND_GOLDILOCKS_ROUND_CONSTANTS: [u64; NUM_ROUNDS] = [ 0x780f22441e8dbc04, ]; -impl GMiMC<8> for CrandallField { - const ROUND_CONSTANTS: [u64; NUM_ROUNDS] = CRANDALL_AND_GOLDILOCKS_ROUND_CONSTANTS; -} - -impl GMiMC<12> for CrandallField { - const ROUND_CONSTANTS: [u64; NUM_ROUNDS] = CRANDALL_AND_GOLDILOCKS_ROUND_CONSTANTS; -} - impl GMiMC<8> for GoldilocksField { - const ROUND_CONSTANTS: [u64; NUM_ROUNDS] = CRANDALL_AND_GOLDILOCKS_ROUND_CONSTANTS; + const ROUND_CONSTANTS: [u64; NUM_ROUNDS] = GOLDILOCKS_ROUND_CONSTANTS; } impl GMiMC<12> for GoldilocksField { - const ROUND_CONSTANTS: [u64; NUM_ROUNDS] = CRANDALL_AND_GOLDILOCKS_ROUND_CONSTANTS; + const ROUND_CONSTANTS: [u64; NUM_ROUNDS] = GOLDILOCKS_ROUND_CONSTANTS; } #[cfg(test)] mod tests { - use crate::field::crandall_field::CrandallField; + use crate::field::goldilocks_field::GoldilocksField; use crate::hash::gmimc::GMiMC; fn check_consistency, const WIDTH: usize>() { @@ -109,6 +100,6 @@ mod tests { #[test] fn consistency() { - check_consistency::(); + check_consistency::(); } } diff --git a/src/hash/merkle_proofs.rs b/src/hash/merkle_proofs.rs index ac40ffef..0a4e999e 100644 --- a/src/hash/merkle_proofs.rs +++ b/src/hash/merkle_proofs.rs @@ -128,7 +128,7 @@ mod tests { use rand::{thread_rng, Rng}; use super::*; - use crate::field::crandall_field::CrandallField; + use crate::field::goldilocks_field::GoldilocksField; use crate::hash::merkle_tree::MerkleTree; use crate::iop::witness::{PartialWitness, Witness}; use crate::plonk::circuit_builder::CircuitBuilder; @@ -141,7 +141,7 @@ mod tests { #[test] fn test_recursive_merkle_proof() -> Result<()> { - type F = CrandallField; + type F = GoldilocksField; let config = CircuitConfig::large_config(); let mut pw = PartialWitness::new(); let mut builder = CircuitBuilder::::new(config); diff --git a/src/hash/merkle_tree.rs b/src/hash/merkle_tree.rs index 9b9ffe7e..2a33a143 100644 --- a/src/hash/merkle_tree.rs +++ b/src/hash/merkle_tree.rs @@ -83,7 +83,7 @@ mod tests { use anyhow::Result; use super::*; - use crate::field::crandall_field::CrandallField; + use crate::field::goldilocks_field::GoldilocksField; use crate::hash::merkle_proofs::verify_merkle_proof; fn random_data(n: usize, k: usize) -> Vec> { @@ -101,7 +101,7 @@ mod tests { #[test] fn test_merkle_trees() -> Result<()> { - type F = CrandallField; + type F = GoldilocksField; let log_n = 8; let n = 1 << log_n; diff --git a/src/hash/mod.rs b/src/hash/mod.rs index ba84d5bf..d6846de8 100644 --- a/src/hash/mod.rs +++ b/src/hash/mod.rs @@ -6,6 +6,5 @@ pub mod merkle_proofs; pub mod merkle_tree; pub mod path_compression; pub mod poseidon; -pub mod poseidon_crandall; pub mod poseidon_goldilocks; pub mod rescue; diff --git a/src/hash/path_compression.rs b/src/hash/path_compression.rs index 481eb163..8b86baac 100644 --- a/src/hash/path_compression.rs +++ b/src/hash/path_compression.rs @@ -115,13 +115,13 @@ mod tests { use rand::{thread_rng, Rng}; use super::*; - use crate::field::crandall_field::CrandallField; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::hash::merkle_tree::MerkleTree; #[test] fn test_path_compression() { - type F = CrandallField; + type F = GoldilocksField; let h = 10; let cap_height = 3; let vs = (0..1 << h).map(|_| vec![F::rand()]).collect::>(); diff --git a/src/hash/poseidon.rs b/src/hash/poseidon.rs index 193ef2c3..616d2a9f 100644 --- a/src/hash/poseidon.rs +++ b/src/hash/poseidon.rs @@ -40,23 +40,18 @@ fn reduce_u160((n_lo, n_hi): (u128, u32)) -> F { F::from_noncanonical_u128(reduced128) } -/// Note that these work for the Crandall and Goldilocks fields, but not necessarily others. See +/// Note that these work for the Goldilocks field, but not necessarily others. See /// `generate_constants` about how these were generated. We include enough for a WIDTH of 12; /// smaller widths just use a subset. #[rustfmt::skip] pub const ALL_ROUND_CONSTANTS: [u64; MAX_WIDTH * N_ROUNDS] = [ - // WARNING: These must be in 0..CrandallField::ORDER (i.e. canonical form). If this condition is - // not met, some platform-specific implementation of constant_layer may return incorrect - // results. - // // WARNING: The AVX2 Goldilocks specialization relies on all round constants being in // 0..0xfffeeac900011537. If these constants are randomly regenerated, there is a ~.6% chance // that this condition will no longer hold. // // WARNING: If these are changed in any way, then all the // implementations of Poseidon must be regenerated. See comments - // in `poseidon_goldilocks.rs` and `poseidon_crandall.rs` for - // instructions. + // in `poseidon_goldilocks.rs`. 0xb585f767417ee042, 0x7746a55f77c10331, 0xb2fb0d321d356f7a, 0x0f6760a486f1621f, 0xe10d6666b36abcdf, 0x8cae14cb455cc50b, 0xd438539cf2cee334, 0xef781c7d4c1fd8b4, 0xcdc4a23a0aca4b1f, 0x277fa208d07b52e3, 0xe17653a300493d38, 0xc54302f27c287dc1, diff --git a/src/hash/poseidon_crandall.rs b/src/hash/poseidon_crandall.rs deleted file mode 100644 index 31116461..00000000 --- a/src/hash/poseidon_crandall.rs +++ /dev/null @@ -1,424 +0,0 @@ -//! Implementations for Poseidon over Crandall field of widths 8 and 12. -//! -//! These contents of the implementations *must* be generated using the -//! `poseidon_constants.sage` script in the `mir-protocol/hash-constants` -//! repository. - -use crate::field::crandall_field::CrandallField; -use crate::hash::poseidon::{Poseidon, N_PARTIAL_ROUNDS}; - -#[rustfmt::skip] -impl Poseidon<8> for CrandallField { - // The MDS matrix we use is the circulant matrix with first row given by the vector - // [ 2^x for x in MDS_MATRIX_EXPS] = [4, 1, 2, 256, 16, 8, 1, 1] - // - // WARNING: If the MDS matrix is changed, then the following - // constants need to be updated accordingly: - // - FAST_PARTIAL_ROUND_CONSTANTS - // - FAST_PARTIAL_ROUND_VS - // - FAST_PARTIAL_ROUND_W_HATS - // - FAST_PARTIAL_ROUND_INITIAL_MATRIX - const MDS_MATRIX_EXPS: [u64; 8] = [2, 0, 1, 8, 4, 3, 0, 0]; - - const FAST_PARTIAL_FIRST_ROUND_CONSTANT: [u64; 8] = [ - 0x66bbd30e99d311da, 0x1d6beb91f1441299, 0x1dfb41ac10a5bda8, 0xcbe9eb8f6bfd79fb, - 0x2c943b9a8d9ee4f4, 0x6d70fcb874f05f57, 0xf48e800880a87878, 0x24b1eb418f3994c3, - ]; - - const FAST_PARTIAL_ROUND_CONSTANTS: [u64; N_PARTIAL_ROUNDS] = [ - 0x6d69d39f98b01c69, 0x7694ae5bbd92de89, 0x0b9bfb9fbb252451, 0xf547651a6893f655, - 0x44f4e70e9f77cd03, 0xd8e2801a322a6f39, 0xbd0f7e1bc9649171, 0x2eda14ffc32245e4, - 0x296e04e8222b9265, 0x9aa740fd9cf504ea, 0xe5e868a6d4315bcc, 0x7d430efe75c6ece5, - 0x37ca54f0b49f6214, 0xde83a9f01bfa62d2, 0xb0831b529dbb5b9c, 0xa1d590c3b2b945b5, - 0xa130846268961080, 0x79e6e27330006b7a, 0xba12695bd255613b, 0x0091d7aaf86c0e15, - 0xe9028a7b418aa9f2, 0x0000000000000000, - ]; - - const FAST_PARTIAL_ROUND_VS: [[u64; 8 - 1]; N_PARTIAL_ROUNDS] = [ - [0xa22ff49d0671165e, 0x90333ff5780b9eec, 0x919457d220ebe522, 0xd4d8b0a8abc35c6e, - 0x1eca5e0b617850b2, 0x0baa903332edef19, 0x09f1096d496c30f1, ], - [0x1eb2711afa8d6426, 0x533628d26840e36f, 0xde3f8282ae0806b9, 0x5b96c6c0b7997a68, - 0xec6a242a596b9076, 0x739b857159e03511, 0x1d6bd33258b57d6d, ], - [0x3603d13c3b01d6c6, 0xc0f959147dc91ee1, 0x7d3b89b472d64db2, 0x49e58d37e29f4c85, - 0xc718800efb8b1033, 0x73b0ca72c31e03fd, 0x9697330fea22a70e, ], - [0x978123b0febeabd5, 0x8efbca443cb8bfca, 0x9f24c447f2d051bb, 0x45ee906ad9703d20, - 0x9ec6215940d574a8, 0x42b4738de9fed9a9, 0x1a23d296f0228cc0, ], - [0xbf9c7b22a247969f, 0xf45041b94b8fac96, 0xce23d5f90c9f2a39, 0x64524dbaaef7a56d, - 0xc9b92c71390db85c, 0xd622ef228ef8a6df, 0x697f4e5dc08c2716, ], - [0x1116bcc5722efae3, 0xfbb5345317c9d731, 0xf696a78eb4b4b9ed, 0xaa08800cfdb59ad3, - 0xf6e9c007ec8900aa, 0xdb35e3b5c9ac6745, 0x4193d903dcca4903, ], - [0x44b28ca6cb051164, 0xa63264849056f8e7, 0x0cc5dd14b73e4b34, 0xb0c213ed14737e89, - 0xde4ba41535b7cd0f, 0x31de7a36cb4f7f3a, 0x08cc6af0fdcfd306, ], - [0x97f04080745484ff, 0x40b15e2cd05957bb, 0x27f5279de5eb0729, 0x7b19caab04109b68, - 0xd326745e4bfb87bf, 0xd7e15457e6d7c2d0, 0x4919494236719d7d, ], - [0x21e9432cc31e919c, 0x837603b01af94b56, 0xe6067467c4e0480a, 0x9dd36e1da07e354e, - 0xe529a3d3f271beb2, 0xa5acad30d3c3fb59, 0x6d5a82823faf4ff1, ], - [0x88b05b29984e6429, 0x2635decc12d3e510, 0x823fe6152336d209, 0xe7cb76fca3c4fa32, - 0x30443c9279dafcb9, 0x6734acbbe14ba020, 0xcb11ff5d7b9c7a38, ], - [0x82cdd90e134c2173, 0xff5acf3f7c55d923, 0x63220d8165dcf1a2, 0xe0ce19b67f54977b, - 0x9fbf941303d8b998, 0xf8eda0fc08ccd441, 0x265a0c94ca846c64, ], - [0x2d43cc534ce9a518, 0x7e78354cb4fdb780, 0x7f33160cefcdb183, 0x33390d373007e718, - 0xe463fb62f8c5e845, 0x454ac64497ad7b5f, 0xa73d26ae995afb8b, ], - [0x9482c8097651113c, 0x24764722d2be2d59, 0x65b49db52c50cf30, 0x54298f2c474c206f, - 0x13a426fc7958905f, 0xe876f9b953c377f0, 0x43cfbf90c880605f, ], - [0xdb016a76619ed366, 0x92a1be5140bdb3d3, 0xd399da81f92fb81a, 0xd7a41636505c38bd, - 0x40358caf39317262, 0x8fbc20933dd7d4e9, 0xc957a47b7eaa161b, ], - [0x11d39c39e8228a7a, 0x071b598d448b6c05, 0x211f8baa562a3196, 0x0cc5b375756650c5, - 0x059feb689a554440, 0x3ee782c2a0c19619, 0x336a46904e832094, ], - [0x0034133810f09fc5, 0x0021fada430e3c09, 0x010540e301677234, 0x000db9ed138d5010, - 0x000331ce727cd24c, 0x001c07a12edb566a, 0x00098bb5328b02e5, ], - [0x000016d34ac3c4e3, 0x000005c883b88ffe, 0x00001054167214c0, 0x00002a5a393b8713, - 0x000010d7401feb08, 0x000103f43d476cf3, 0x00000a2b0d83a7a3, ], - [0x00000102d65ebdaa, 0x0000000663cf5317, 0x00000009aedd7f7a, 0x00000011fad0f867, - 0x00000002a1022998, 0x0000000ceff381ff, 0x00000021cf076bb8, ], - [0x0000000008679bb3, 0x000000001567aab3, 0x0000000040a61838, 0x0000000101ac6a94, - 0x0000000002ec5178, 0x0000000006b2488e, 0x000000000d4a83cb, ], - [0x0000000000043801, 0x0000000000089d36, 0x000000000003d5c0, 0x0000000000052021, - 0x00000000000a24e8, 0x0000000000306095, 0x000000000100fed1, ], - [0x0000000000002026, 0x0000000000010055, 0x0000000000000442, 0x0000000000000255, - 0x0000000000000434, 0x0000000000000269, 0x0000000000000308, ], - [0x0000000000000001, 0x0000000000000001, 0x0000000000000008, 0x0000000000000010, - 0x0000000000000100, 0x0000000000000002, 0x0000000000000001, ], - ]; - - const FAST_PARTIAL_ROUND_W_HATS: [[u64; 8 - 1]; N_PARTIAL_ROUNDS] = [ - [0xa243d101153eb562, 0x1f670d5d8c14c000, 0xced8026856dd6a07, 0x1b7c4f1704047b8e, - 0x41ea3a3855c2d39e, 0x066101717cef6c02, 0xee96a3b009f99df7, ], - [0xb00328edb79d53bd, 0x1639f163c71eee14, 0x192788e832e46178, 0x7c68b41f104d68ec, - 0x41174fa1485efe00, 0x618f488d942ec9f2, 0x4bdb7e3318926ebe, ], - [0x0b28434790c294ef, 0x9ba864afff9e233c, 0x629092442534bdc0, 0x3be9b41110ccdb7d, - 0x9aa3bdeb8d16ac39, 0x17429e3995825d63, 0x702b4284837a4846, ], - [0xd75842068900c798, 0x8cce741a1060389b, 0xcf91c066d7913b3e, 0xe50be3cbf8a4ace7, - 0x4df095d852da37da, 0x84078b181ce8bbcf, 0x085fc2670b73de72, ], - [0xd97455be3e610261, 0xceef7dfe63f37fd2, 0x52faf29e9aa95f11, 0xea9672f8f70dde6c, - 0x8c51444bebd1b0ee, 0x49f00564527f62e3, 0x8433762d9a2fcba3, ], - [0x99eff4ff916d648e, 0x87c459e036359734, 0xd763393ed532616b, 0x0766745aef99a96a, - 0x16b83fbe31e685fb, 0xc2fee2ab39b9e5b3, 0x8a72cfd149535052, ], - [0x8167512548df88b2, 0xf04b045f4d32a8a1, 0xf673ef6ce25e4806, 0x21c85f4ab3a3b118, - 0xc1d8c8d07113367d, 0x6af20849e27ac1b5, 0xcef5545ab2bdd1b3, ], - [0xa81eb29c319d5be8, 0x0e0ad7ad11c3a5ab, 0xf770147f2cd4ea74, 0x69f20eddd45794e6, - 0xb174303b7286d9a2, 0x04013980dd7245c7, 0x5dd6a119eba2db57, ], - [0xc9aff46079c3bea7, 0xe40268bb580ef209, 0x54e2aba7d4f0596f, 0x7e2b0e6fcc266ad5, - 0x0d3daa4a7ead5ad6, 0x84eb64836ab1a2d2, 0x5fc9b471a5a97c6a, ], - [0xcfcfeaa93d0d1462, 0xaf1f5dd31517b872, 0x7a4c24137a5077e0, 0x55feca2820116ffc, - 0xdf0429c64c459ac5, 0xed5ce47466d0bc8e, 0x8189efb2fe5e0478, ], - [0x68dc6e8fc5fa43f7, 0xb47798ff890af473, 0xf078d6404130f753, 0xd9213de357e084ef, - 0x51eb0ba5b3814334, 0x7e9885e240657b0c, 0x9de439a115165582, ], - [0x046b28c7d8e50ccf, 0x616f43798beeddb8, 0x4627e1d7b9b6523c, 0x5a00ee6489a654d1, - 0x239bc16f685c02a3, 0xa3a71de01b6747a9, 0xcf6402218da7a24a, ], - [0x08ed374a2ec320d1, 0xe5a31270acf40388, 0x13fadd610c48f98e, 0x1e95da99ae3a8c7e, - 0x9dc0de1504c07254, 0x97cd6d98b355eadb, 0x9bc070176cd3c501, ], - [0xf2fdfc56a1b76de8, 0xfd581b091c3df5a0, 0x7e321d7d5684d10c, 0x5a61834a90f088bc, - 0x2302d1337a2d8cec, 0x725afc4089b3c89f, 0x4ddf24c735a5374d, ], - [0x4175e1cb9310a009, 0xdddd1e503c04dc25, 0xca4b0ca8bccfe503, 0xe4bbab954b3bd636, - 0x2b05f339af75dbe1, 0x8e9ffe84ceeeccd5, 0x124129078120a6e6, ], - [0x48bd19a1b761d33d, 0xeb499cf8a6725e0d, 0x32c937fe09983757, 0xda84fd5479d2dec3, - 0xbac726cfd8a8a826, 0x75cc0a190b812741, 0xbe6bbdc6be692697, ], - [0x0a832806a4ace872, 0xa1e96219bb14acfb, 0x7251019780ae0c31, 0x547b2847470eaf47, - 0x34da63bb720b7bbc, 0xc927a26df327fab7, 0x39a42518adce0d14, ], - [0xcab13a56ab3a6144, 0x366737df19a4f4db, 0xed08a988f6618092, 0x565b9c84939e7446, - 0xa0e71c6ce10a3fdf, 0xffc45cb3ff5515fa, 0xd373981245598077, ], - [0x7ac75a736a509479, 0x5ec9215122f1fe35, 0xac8b72753e8924f5, 0xa0c81c2f8db1d81c, - 0x998cdabdb1d3fa4e, 0xe4ca3a836097e99e, 0x39730c86a3bdee63, ], - [0xd2a127e3d4f1549e, 0xcf5673508860595f, 0xfe5d3387e1dbc076, 0xfe8812fecc245152, - 0xf3e6abb09d715f64, 0xf5f868062e1ebabe, 0xff93de5aff828886, ], - [0x42735ce753f9bb15, 0x9f7a7533b471f7c6, 0x097d75da8c661359, 0x1ed051078c26b3eb, - 0x40ef3e78b2b13b0d, 0xb0104cc90708254d, 0x97503325810d1378, ], - [0xf728fe2c1747bad4, 0x415cdecd416e0602, 0x9f9c2e9615e80c24, 0xe291b04af1c1e362, - 0x1e93b91509607640, 0x5ed95be1c52cf97e, 0x359f0220d53d82f4, ], - ]; - - // NB: This is in ROW-major order to support cache-friendly pre-multiplication. - const FAST_PARTIAL_ROUND_INITIAL_MATRIX: [[u64; 8 - 1]; 8 - 1] = [ - [0x3fc702a71c42c8df, 0xda6cfb436cf6973e, 0x800fc4e2c9f585d8, 0x3864e0e53027baf7, - 0x44ae739518db1d10, 0x1d46b66c2ad3ef0c, 0xbc75b7bb6f92fb6b, ], - [0xdc5d5c2cec372bd8, 0x5ed3accc77ae85d0, 0xc768961eecdcb554, 0x95af3551b40289ce, - 0xa3ae8c5444f37d9a, 0x53c070eae0ad0c38, 0x1d46b66c2ad3ef0c, ], - [0x61e9415bfc0d135a, 0xd63481d84fa12429, 0xc8e4a9f96ab57c10, 0x29d0d07fd9b6e9ea, - 0xa5aac4ccc8b791cc, 0xa3ae8c5444f37d9a, 0x44ae739518db1d10, ], - [0x9b7a25991a49b57f, 0x38d80c86e3eb1887, 0xeae1feb52d6eb09a, 0xda20f5c812c60b4e, - 0x29d0d07fd9b6e9ea, 0x95af3551b40289ce, 0x3864e0e53027baf7, ], - [0xaaee943e6eccf7b8, 0xf8ad1187508f709c, 0x7ffbbc7ce8823d72, 0xeae1feb52d6eb09a, - 0xc8e4a9f96ab57c10, 0xc768961eecdcb554, 0x800fc4e2c9f585d8, ], - [0x2be97f5416341131, 0xd0b8c098bdcf7407, 0xf8ad1187508f709c, 0x38d80c86e3eb1887, - 0xd63481d84fa12429, 0x5ed3accc77ae85d0, 0xda6cfb436cf6973e, ], - [0x3f3fd62d28872386, 0x2be97f5416341131, 0xaaee943e6eccf7b8, 0x9b7a25991a49b57f, - 0x61e9415bfc0d135a, 0xdc5d5c2cec372bd8, 0x3fc702a71c42c8df, ], - ]; -} - -#[rustfmt::skip] -impl Poseidon<12> for CrandallField { - // The MDS matrix we use is the circulant matrix with first row given by the vector - // [ 2^x for x in MDS_MATRIX_EXPS] = [1024, 8192, 4, 1, 16, 2, 256, 128, 32768, 32, 1, 1] - // - // WARNING: If the MDS matrix is changed, then the following - // constants need to be updated accordingly: - // - FAST_PARTIAL_ROUND_CONSTANTS - // - FAST_PARTIAL_ROUND_VS - // - FAST_PARTIAL_ROUND_W_HATS - // - FAST_PARTIAL_ROUND_INITIAL_MATRIX - const MDS_MATRIX_EXPS: [u64; 12] = [10, 13, 2, 0, 4, 1, 8, 7, 15, 5, 0, 0]; - - const FAST_PARTIAL_FIRST_ROUND_CONSTANT: [u64; 12] = [ - 0x3cc3f89232e3b0c8, 0x62fbbf978e28f47d, 0x39fdb188ec8547ef, 0x39df2d6d45a69859, - 0x8f0728b06d02b8ef, 0xaef06dc095c5e82a, 0xbca538714a7b9590, 0xbac7d7e5a0dd105c, - 0x6b92ff930094a160, 0xdaf229f00331101e, 0xd39b0be8a5c868c6, 0x47b0452c32f4fddb, - ]; - - - const FAST_PARTIAL_ROUND_CONSTANTS: [u64; N_PARTIAL_ROUNDS] = [ - 0xa00e150786abac6c, 0xe71901e012a81740, 0x8c4517d65a4d4813, 0x62b1661b06dafd6b, - 0x25b991b65a886452, 0x51bcd73c6aaabd6e, 0xb8956d71320d9266, 0x62e603408b7b7092, - 0x9839210869008dc0, 0xc6b3ebc672dd2b86, 0x816bd6d0838e9e05, 0x0e80e96e5f3cc3fd, - 0x4c8ea37c218378c9, 0x21a24a8087e0e306, 0x30c877124f60bdfa, 0x8e92578bf67f43f3, - 0x79089cd2893d3cfa, 0x4a2da1f7351fe5b1, 0x7941de449fea07f0, 0x9f9fe970f90fe0b9, - 0x8aff5500f81c1181, 0x0000000000000000, - ]; - - const FAST_PARTIAL_ROUND_VS: [[u64; 12 - 1]; N_PARTIAL_ROUNDS] = [ - [0xe67f4c76dd37e266, 0x3787d63a462ddaba, 0x6a541a0fad3032c7, 0xff665c7a10448d53, - 0xd1cdb53d9ddb8a88, 0x36b8c12048426352, 0x4e9a00b9a8972548, 0xa371c3fc71ddba26, - 0xf42eacd3b91465b5, 0x13bbf44566e89fdd, 0x17d35dfc4057799b, ], - [0x74d80822f5ac105b, 0xd236707412f3a047, 0xc1b3828a69443f42, 0xe92487f111b47bd4, - 0x8b544fcd845e00f6, 0xe6ae4706f80dbf42, 0x47f1b8a0545fe1fa, 0xde2ddf83cf7b9217, - 0x1b9fe67073a9d147, 0x2658f0e2dd45c018, 0x7ebd50cedd2631da, ], - [0x4bc36dcb20e574a3, 0xabda0ed71b34deb0, 0x3005b75fa2cc2425, 0xf3e90f0501cc6f0f, - 0xefc00ccd7b68da02, 0x42c105686461b611, 0x9bd4213d99925ac2, 0xa4994f529e2a94c4, - 0xb46ef4cd4db7cfc2, 0x175044110fde562f, 0x6a8ae415ec65007a, ], - [0x7e682d3a5ef73e41, 0xcf32352159d13a33, 0x49f474977e36f6c3, 0x7bb0effe3bd426ea, - 0x64eed711604ee775, 0x0b524f42edaf84fb, 0xdfd97a4aa5d8567d, 0x5fe9c9824d43521d, - 0xaf61e76b9cdbb138, 0xc01b70f1adebfeab, 0x95d24d00678da148, ], - [0x3549287475671e52, 0x9ca854efc14122dd, 0xcd886b543c9beb77, 0xa409843ee3ce4f6a, - 0x9f1bea833646efa2, 0xbfe3c09f70220e1e, 0xe0b6a8f93e036acf, 0x554733da74d2c9da, - 0xeb510c6f857aa212, 0x53626d71ca4a38dd, 0xb6ae627bfc11f637, ], - [0xce18b963c797243d, 0x51eb1f1ce97f2a80, 0x104cc3f8c10457b9, 0x12d3c8cee6ec5c16, - 0xd43e1f577234fb55, 0x54c8c76901c7524c, 0x960af4ea5ef01c1c, 0xef6e7bc29cc45dd1, - 0x3a5987955b6574a4, 0x1dc302592713e124, 0xeea7c20882911833, ], - [0xd9c21ebfb1c2ae8f, 0x0b4b6b7afcc68799, 0xdbe081d54b0cadfc, 0x961c7b785812f275, - 0xbeaa33b9cd98553a, 0x0aeae6ff5dd491c1, 0x15eec8aebadf9834, 0x16ca6296360389fe, - 0x008bb53e94c1041a, 0x368bf0dae439b072, 0x51ff6c0c07d56ac4, ], - [0x1cb8fba2362a103f, 0x897b392d5912b66d, 0x7fa38fe8471e4ebf, 0x4ffa98336474e161, - 0xadf92c983e466ee6, 0x43b22e3794bdd8b8, 0xe7fd4b4c2e3c8713, 0xe4f8b07872deed65, - 0x9e152c9cb7e0b7c4, 0x1b26081e35432ccc, 0x647acdb0f39e597a, ], - [0xf31c02888392b995, 0x0207c944c27fe9f8, 0x62767aea825841d2, 0x6ca016ce1667e093, - 0xd4aa4062188ca548, 0x80ad041f7bc66390, 0x7e8b2bdf628bc084, 0x0edcf7a59d112492, - 0xe26437b6e13326cb, 0x78f2c6f4b9257f3a, 0x3d31ecb8b17cfa69, ], - [0x452046f066aaa834, 0x1ee5a5891493eb3f, 0x72a59ce75aad55e1, 0x086b6f5ddbe5d4ea, - 0x72964667982c1e80, 0x4edabf2f250d80d6, 0x9d34853dc92eff2b, 0xba0bf1d6dfd4a83c, - 0xd8257069ba15d122, 0x344f8bbc786dd0c3, 0xa68e988d58740429, ], - [0x82e4d8c6dc1ae6ed, 0xe0957181ddfef5de, 0x592e8187280bf64d, 0x5b41e7d00fb09752, - 0x8feddb14c160201e, 0x1c9ad02b3d10f701, 0x16f5a869b59b6c31, 0x4c3d6f04136d7771, - 0xc7727996396e15ea, 0x97e39df842444fbd, 0xbdde9f7586a874df, ], - [0x9512d3c4d7cb437c, 0x6c45b0d267f28b4c, 0x4c0f2ca87c29175f, 0xa51335204643a8f8, - 0x500c3ad025688091, 0x0354b59cd97eb531, 0xf7776cf7c6e35c1b, 0xbd4438971095dba5, - 0xfc2be1c80ac8bcc9, 0x760db2349cbda06b, 0xd89a987e88d41186, ], - [0x4f6a3f5ee2763bb2, 0x03297a357f2da20c, 0x76c05507038c84aa, 0x1a5043d142781537, - 0x397542d78dadb3a1, 0x887dd81d3c3f27d0, 0xe5d2879bf760629c, 0xf9211873dbe5e068, - 0x9d2d37dff8301264, 0x68c59f77a6dbe6ed, 0x077543cffe95edfc, ], - [0xadd787768284cdee, 0x82585abf32a3020d, 0xfe20edcb9f6a2cea, 0x844cbf79ffef7d45, - 0xa62bf3ca3eb80b1c, 0x4dfbcd2cd29117f4, 0xf1d1028bc0c8839c, 0x62a0e817e8d77ef5, - 0xb5eb84c0789a93ed, 0xcf41f39f2e2fd6d1, 0x9e57aadb4c8dcfc2, ], - [0xd772005559fcdfaa, 0x66c9a95222385666, 0x410f26abdd94c446, 0xec36cb430f46924e, - 0x575482bd3706c282, 0x9ead1e1880d6f587, 0xe45eebbac54ebaad, 0xb4acdc141bc29117, - 0xce305bf5696d5c6f, 0xf0ed1597cf810813, 0x0c9eaf677e2a6d2e, ], - [0xcb1519b8f35e7515, 0xd7cb72656790acd0, 0x3d3c4972cfcb4cf7, 0xaac6c7c54cefb31d, - 0xf61b30c24c112777, 0x6129996980a9a26f, 0xf405b608d78fdd10, 0xfc411ea75de454df, - 0x808a5dcf02559826, 0xee69df55c1fb93e8, 0x2e97449d2e7f4bef, ], - [0xc646d3807e3f63f8, 0x8b75f8ab8a670c0e, 0xa3463ae487b2eff1, 0xe9cbfbd0f1032068, - 0x9775e58aeb04e069, 0x06cb23d6d06603f9, 0x0474bc743bd2a597, 0xc709561ece9d291b, - 0x718100080c964a41, 0x3a5beca6171c74be, 0x2feed444497af7eb, ], - [0x617c452b85c9d0a2, 0x9e97e4d7eae91a20, 0x83beea96a57ed657, 0x07f068abd6193935, - 0xa9a10751aab874d9, 0x1a2e6bfa534064c9, 0xdd1802545bf7a4b2, 0x8e3e06e8a89b8a7f, - 0xf6627102ecaf8f7e, 0x4ebfbf20512cf09a, 0xabbe52e572d5bf4a, ], - [0x01653b4f4a999932, 0x0053f2a963638e1a, 0x001922cbf2c59efc, 0x00015fc3f40ff355, - 0x003531822ee190e8, 0x06612a21c3a9cafe, 0x012e62120d30bbf0, 0x0039ded9f9a7df37, - 0x000bc8d6c5739e4a, 0x001000e0be5d2a9e, 0x0c018651e998d5b8, ], - [0x00000063775cfe99, 0x000006c0c4b6e7e4, 0x000001090a1416ee, 0x0000001a438450db, - 0x000000036280cbdf, 0x0000000ffea8b49d, 0x00001801427a72e3, 0x0000023059280d1b, - 0x000000e4e2f6fbee, 0x00000029ebd5c20c, 0x0000001e61472f75, ], - [0x0000000000015900, 0x00000000000c2505, 0x0000000020008642, 0x0000000002200945, - 0x0000000000430070, 0x0000000000058581, 0x0000000000240b08, 0x000000004000a214, - 0x0000000000814424, 0x00000000050050a2, 0x000000000083040a, ], - [0x0000000000000001, 0x0000000000000001, 0x0000000000000020, 0x0000000000008000, - 0x0000000000000080, 0x0000000000000100, 0x0000000000000002, 0x0000000000000010, - 0x0000000000000001, 0x0000000000000004, 0x0000000000002000, ], - ]; - - const FAST_PARTIAL_ROUND_W_HATS: [[u64; 12 - 1]; N_PARTIAL_ROUNDS] = [ - [0xf8c08a4101e2a5e4, 0x1d59fd32df7c1369, 0x22c9f355ee2603e9, 0x088f5c6c47afac6f, - 0xea0a086f009303c0, 0x2a04f88abd6341a3, 0x4893220de1d91824, 0xf153c2a717c08a1f, - 0x84f81d7b79459079, 0x6fb4ffed9b78d9f0, 0x1eaafffe5e1becf6, ], - [0x0a98f6ce528a5af6, 0x235bae28135c7475, 0x7ace29ef814a2255, 0x6030aeaac50421f4, - 0x7987fd365fbf2539, 0x0f79e921a3239a77, 0xb11997d5f12b36a3, 0x984368cd38362bbf, - 0xa14e59e13570c297, 0x83a0cda0d47fadfa, 0x1dcfd6ba0e54133c, ], - [0x1d8f384f837f49e2, 0xf8cfde4f45967d4c, 0xc1fee8f19fe21c43, 0x04363b9307aebeea, - 0x841cea2f6247b41a, 0xefad3917abc7a53c, 0x0f6d8258511ac0e6, 0x77c86f3704bbfe57, - 0x6c1b85ac9ef87dbf, 0x2b0ee517bdd38773, 0xd274576d9d7952c1, ], - [0x5dd7aebeedd0eacb, 0xe7abcd4b0857dddc, 0x29f1a2e1a32ec8d5, 0x1181eed8c3a8e08b, - 0xcba331414a192658, 0xa47ccc727964ddbb, 0x8414892c9096aaef, 0x596b12214645218d, - 0xf41f19984365e6c3, 0x4719f61fdebf31a4, 0x9075d2ad73964a38, ], - [0x09df8b108094522a, 0x1aca572b4c76988a, 0xd31c8fc7fd51eccf, 0xfeceefdcdc38770d, - 0x1d1b235a0eb031f4, 0x971bbc1112c36b29, 0x8c021c051da48779, 0xe89ec828cfbdd96f, - 0xe72956d332e2dc52, 0xc0b14ea64ab04ee5, 0x53233fda2a3c29ad, ], - [0xb8a98dff72a17a51, 0x3a7860f384f03806, 0x1e58886bef1446c6, 0xc7910598dad5a1f4, - 0xae0642adc54989b0, 0xf4d768f139f5f4f9, 0xbff59ba7765b3e6b, 0x91b2d8424617ef7b, - 0x6fecea5e1ea32471, 0xe26667436d718c56, 0x581b8f91d7d7c6e4, ], - [0xd8d9cc4462e55b75, 0x7a707e9faf86c8de, 0x3c1afbb7083058ce, 0x1274f5e1aaf581c1, - 0x274bb4597bd29568, 0x0c1ed5200aa0ca93, 0x5d73e0a4ee921248, 0xd8e88f02d831f72e, - 0x0920a407b6fc1d2f, 0x423dde535b3c0f86, 0x9046fb30c35098ef, ], - [0x910871bda1a4dc66, 0x06ff1f4e195e1916, 0xaaeee5346ab403dd, 0x0e10c7d3172cc6ae, - 0x04999dd075d58fa9, 0x3da251b3ee6bf0e5, 0x9184e34946712416, 0x473fbaf135f61868, - 0xbbe66160875bc6fe, 0x4ad958365708aad9, 0xef9287c594553868, ], - [0x10cb59cb3613bb08, 0x96e3ca98eb380cf9, 0x3153cc874088d97a, 0xc8c9d31008862ae9, - 0x29b662d09e3ce873, 0xfd25aa286a33c577, 0xe5cd6822fea38b6b, 0x49cb042f7e30d9ef, - 0x5c14b08062acf75c, 0xebeb59c698831c5d, 0xc51a7bfddcd53406, ], - [0xf5b5132c50230980, 0xee13fdc497fc7ff7, 0x7aaaf371f4027bbe, 0xefbf9646d3eab1d4, - 0x0192b0c878f88990, 0x33a13ab409a95afb, 0xca3147bb5652e935, 0x1b6e0d178d166ea1, - 0x983a5eb800745372, 0xadc3b9f092da6ee9, 0xd53d2d9ae9b0b8b7, ], - [0x4c823667ece9492b, 0x9515e5811fcf086f, 0xac71ccac616dbf01, 0x1818c85ae69d9610, - 0x2b97efe5cd0a9f61, 0x49d1a2ec7c1d8a9e, 0x215787a8272ef1c3, 0x7ebde6076499a32a, - 0xc1b81122cb7b43f6, 0x6fb37a243559d827, 0x970cd9b0339d2d05, ], - [0x6aaa2e6a8c31c207, 0x26c0676a25426ea6, 0x5edda44cc885f665, 0x8e8b97c979ad532a, - 0xb9d9bf57b3eeafd0, 0x5656c6bb02989fd1, 0x70313b79197821d4, 0x7fe33766f7226b1f, - 0x7499a04a6b030f6b, 0x4c69391a8ed5c0f2, 0x4b4e96c68d1eb19d, ], - [0xff199cee489a97d1, 0xca544f9410e9ea31, 0xb819ecc35beab037, 0xe746955c01f58adc, - 0x3d1812758140549f, 0x348e03c3750cff4a, 0xc648b624683bb31f, 0xae4ab9656117e784, - 0x8c02225fe885b95f, 0xf07f35e38b527e04, 0x97f2475a77d1fa3b, ], - [0xd7a767d6f78d263c, 0xf01f29bc13f8d52e, 0x86df93d4be47e46e, 0xc7f42508cef87d3a, - 0xd68b87bb951a1eee, 0xbbf7aa5ea42f1936, 0x5cbd3e1051cdccbc, 0x917fd26537f1cb47, - 0xe872defb4073d680, 0x7a23790b9c2fcf11, 0x57372f64f1ba571e, ], - [0x1141ce95e4f36268, 0x07dc03c4438b93ff, 0x1923d97cc980b788, 0x79e776a98bc81418, - 0x39ed107b4fc226ae, 0xfc49245486022c81, 0x581a344b413f1491, 0x36d13d5bd609823c, - 0x61c51cf0a912bdf3, 0x3e035096932c0675, 0xedfef9ed5176bcfa, ], - [0xac20ba71ed5fffe1, 0x7ccf77683dd3c134, 0x35b660c9248693f6, 0xe3c3db8cd17abf36, - 0xe145283d080d4b94, 0xd6fdb1a4a101f81f, 0xa8b316f332519218, 0x63e25815404423d1, - 0x5099cd7de648979d, 0xae2a5fc0f336bb2e, 0x78624fe97e6727d7, ], - [0xd50ec4091bee8eda, 0xa83d33121e0b98c6, 0x169f674d12527a05, 0xdda18a72ef29b26b, - 0x0001e1849d2ec83f, 0x06a4bdef8093bdeb, 0x02e55a872c5c16fd, 0xbc07fd6489c5e5ec, - 0xa9bf440c06ed9ad9, 0xa50a7c091a869b12, 0x52387f502106d171, ], - [0xd88a917ecaec9164, 0x91cbd172c1c60db4, 0x089901176d11cbbe, 0xd9aa7a4e25d85fd2, - 0x76c8de23f4e46584, 0xdb58d95b54563760, 0x1ac4ec96160b0b5d, 0x47a18a07a663bd37, - 0xe1a0c0e1f1ad360c, 0xee9efd9bb2ff331b, 0x332516435912bb4e, ], - [0x3ee7f239b3f72cb8, 0x8dd9a15c6b2cdf2c, 0xf34be27eb6089094, 0x2f316b9dfe26c6a2, - 0x6ef0a376d699d966, 0x6416ebfa513b7048, 0xa3a8b269c35bc569, 0xf9bd882d51a186f9, - 0x04016d660c8e9a04, 0x94a8d01bf1185c32, 0xd5dd630701e8e2f1, ], - [0x2cb013d7fdda0dd1, 0x95aa522094977e0b, 0x40e3490b6d03abe2, 0x19c3390a981c8563, - 0x6178af85fdd6d8e2, 0xefede56f5ba88274, 0xe7fd4de4966ffcab, 0x8759e5befc06ecf9, - 0x933864bbe83a02b2, 0xd5c2f21adaf0fc0e, 0x10c0e6410a3a632a, ], - [0x7648769e7d9a5a37, 0x14256df209909079, 0x46ffa1ea96331c95, 0xbdf534c6f8372297, - 0x45fd78f68986f2f5, 0xd960926124b727ae, 0x8139aca5f725e73f, 0xd3f23433928e0c54, - 0xa221614eb4379297, 0xe445f5b133e491f8, 0x7694bcd4a0245609, ], - [0x6aaab9a9e8117836, 0x40a1c716c884730b, 0xd81303b2c9d46838, 0x346c1ba0cdc21317, - 0x726821a9c9aa0db6, 0x7db3ed5312178744, 0x0ce23bf6f9eed082, 0xb9e01dfc6bb98a90, - 0x2e97f1cb8689f623, 0xa2a9961db0d614d8, 0xf87c2101134b253c, ], - ]; - - // NB: This is in ROW-major order to support cache-friendly pre-multiplication. - const FAST_PARTIAL_ROUND_INITIAL_MATRIX: [[u64; 12 - 1]; 12 - 1] = [ - [0x8a041eb885fb24f5, 0xb5d5efb12203ef9a, 0xe7ad8152c5d50bed, 0x685ef5a6b9e241d3, - 0x7e60116e98d5e20c, 0xfdb6ca0a6d5cc865, 0x857f31827fb3fe60, 0xe31988229a5fcb6e, - 0xc06fefcd7cea8405, 0x05adcaa7427c172c, 0x4ff536f518f675c7, ], - [0xeb159cc540fb5e78, 0xe2afdb22f2e0801a, 0x2b68f22b6b414b24, 0x9e085548eeb422b1, - 0xb561d1111e413cce, 0xe351dee9a4f90434, 0x6aa96c0125bddef7, 0x06f4e7db60b9d3b3, - 0xa7b2498836972dc4, 0xdc59b1fe6c753a07, 0x05adcaa7427c172c, ], - [0xf2bc5f8a1eb47c5f, 0xac34f93c00842bef, 0x397f9c162cea9170, 0x3fd7af7763f724a2, - 0xeb3a58c29ba7f596, 0x9fedefd5f6653e80, 0xe629261862a9a8e1, 0x4e093de640582a4f, - 0x4e3662cf34ca1a70, 0xa7b2498836972dc4, 0xc06fefcd7cea8405, ], - [0x029914d117a17af3, 0xb908389bbeee3c9d, 0x33ab6239c8b237f3, 0x337d2955b1c463ae, - 0xb2ec0e3facb37f22, 0xb7f57d2afbb79622, 0xf285b4aa369079a1, 0xa3a167ee9469e711, - 0x4e093de640582a4f, 0x06f4e7db60b9d3b3, 0xe31988229a5fcb6e, ], - [0xf2bfc6a0100f3c6d, 0xf88cbe5484d71f29, 0x110365276c97b11f, 0x1927309728b02b2c, - 0x95dc8a5e61463c07, 0xa84c2200dfb57d3e, 0x01838a8c1d92d250, 0xf285b4aa369079a1, - 0xe629261862a9a8e1, 0x6aa96c0125bddef7, 0x857f31827fb3fe60, ], - [0x2d506a5bb5b7480c, 0x3e815f5ac59316cf, 0x68bc309864072be8, 0x56a37505b7b907a7, - 0xecd49c2975d75106, 0x0cdf9734cbbc0e07, 0xa84c2200dfb57d3e, 0xb7f57d2afbb79622, - 0x9fedefd5f6653e80, 0xe351dee9a4f90434, 0xfdb6ca0a6d5cc865, ], - [0xda5e708c57dfe9f9, 0xaa5a5bcedc8ce58c, 0xc0e1cb8013a75747, 0xfd7c623553723df6, - 0x7b298b0fc4b796ab, 0xecd49c2975d75106, 0x95dc8a5e61463c07, 0xb2ec0e3facb37f22, - 0xeb3a58c29ba7f596, 0xb561d1111e413cce, 0x7e60116e98d5e20c, ], - [0xd7b5feb73cd3a335, 0x2f1dcb0b29bcce64, 0x10a1b57ff824d1f1, 0x35b7afed907102a9, - 0xfd7c623553723df6, 0x56a37505b7b907a7, 0x1927309728b02b2c, 0x337d2955b1c463ae, - 0x3fd7af7763f724a2, 0x9e085548eeb422b1, 0x685ef5a6b9e241d3, ], - [0xeab0a50ac0fa5244, 0x22f96387ab3046d8, 0x45a7029a0a30d66f, 0x10a1b57ff824d1f1, - 0xc0e1cb8013a75747, 0x68bc309864072be8, 0x110365276c97b11f, 0x33ab6239c8b237f3, - 0x397f9c162cea9170, 0x2b68f22b6b414b24, 0xe7ad8152c5d50bed, ], - [0xad929b347785656d, 0x87b1d6bd50b96399, 0x22f96387ab3046d8, 0x2f1dcb0b29bcce64, - 0xaa5a5bcedc8ce58c, 0x3e815f5ac59316cf, 0xf88cbe5484d71f29, 0xb908389bbeee3c9d, - 0xac34f93c00842bef, 0xe2afdb22f2e0801a, 0xb5d5efb12203ef9a, ], - [0xa344593dadcaf3de, 0xad929b347785656d, 0xeab0a50ac0fa5244, 0xd7b5feb73cd3a335, - 0xda5e708c57dfe9f9, 0x2d506a5bb5b7480c, 0xf2bfc6a0100f3c6d, 0x029914d117a17af3, - 0xf2bc5f8a1eb47c5f, 0xeb159cc540fb5e78, 0x8a041eb885fb24f5, ], - ]; -} - -#[cfg(test)] -mod tests { - use crate::field::crandall_field::CrandallField as F; - use crate::field::field_types::{Field, PrimeField}; - use crate::hash::poseidon::test_helpers::{check_consistency, check_test_vectors}; - - #[test] - fn test_vectors() { - // Test inputs are: - // 1. all zeros - // 2. range 0..WIDTH - // 3. all -1's - // 4. random elements of CrandallField. - // expected output calculated with (modified) hadeshash reference implementation. - - let neg_one: u64 = F::NEG_ONE.to_canonical_u64(); - - #[rustfmt::skip] - let test_vectors8: Vec<([u64; 8], [u64; 8])> = vec![ - ([0, 0, 0, 0, 0, 0, 0, 0, ], - [0x0751cebf68b361b0, 0x35d3c97c66539351, 0xd8658ef4a6240e92, 0x6781ebb9bbbb4e9f, - 0x274e5747ffc945ab, 0xf145287440599e51, 0xb193e521a83175a1, 0xcc133eb594e53a80, ]), - ([0, 1, 2, 3, 4, 5, 6, 7, ], - [0x1183fb3b5cbb3c6c, 0xa4ac49f197402036, 0xd752a2f6b9f1e6a2, 0x508da1afbebd9538, - 0xd32e183335ea3b8a, 0x79eb2ab985665a18, 0xa6a43cefcee4bfc2, 0x50521374c3cf82e1, ]), - ([neg_one, neg_one, neg_one, neg_one, - neg_one, neg_one, neg_one, neg_one, ], - [0x17c02c3f41202683, 0x26c7dcdc08616731, 0xb8b3ef710f9d7a22, 0x71700d868f4b5fc4, - 0x1e55cebeb105081a, 0xbdc0566d7296c89a, 0xfff584fe30b62c67, 0x02ad66312a3d2d5b, ]), - ([0xb69ed321abbeffbb, 0xfb496d8c39b64e42, 0x274f1cfbb925c789, 0x9e846d2b9a56b834, - 0xc7f297c0d48bc3b6, 0xb859ab1e45850a0a, 0x3244fe3bcb1244cb, 0xb98e1cfa647575de, ], - [0xa7369ab44b1aadd2, 0x884abb3db138372d, 0x9fc2e4ee64df8608, 0x12a205150a1dbe5a, - 0x934ab794bd534b3c, 0xb39ef937e8caa038, 0x9e5fe73f4b03983c, 0x9539e39e93c28978, ]), - ]; - - check_test_vectors::(test_vectors8); - - #[rustfmt::skip] - let test_vectors12: Vec<([u64; 12], [u64; 12])> = vec![ - ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], - [0x3e7b141d38447d8e, 0x66c245618877844a, 0xb8e1c45f458b0f13, 0x2f1d4710145a8698, - 0x7af9686a09b78693, 0xc0e5b9a1c728d4ea, 0x25a8a20844491890, 0x8e9d1b1b58ae2019, - 0x593286e9cfdd9e55, 0x131ac26134caca32, 0xc1c6e880dc77f0a6, 0x94db15af6ad9527b, ]), - ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ], - [0x8ca83bb7e510aff5, 0x68a7a9441166cc2c, 0xa1ba50df7e5d9f68, 0xbd14765ff1725536, - 0xcea83c5e2680f3da, 0xa7782c56559f6d32, 0x03d5cb8d13adf174, 0x298de89026c219a6, - 0x481f50c421e19bf7, 0x3ea5672a17888b27, 0x2f223e603dd1cd7e, 0x05826e3e65f9d4e7, ]), - ([neg_one, neg_one, neg_one, neg_one, - neg_one, neg_one, neg_one, neg_one, - neg_one, neg_one, neg_one, neg_one, ], - [0xa0e14c1abda5c4e8, 0xbbfdd7920046e853, 0x85aca557e1acba0b, 0x4c8eabc161c0816a, - 0x0fcd160bb7b3d704, 0x349d7ecf9c8fda0a, 0x213fad880d8f6d2e, 0x3e91e5904a53a164, - 0x45434fe525586063, 0x2c4d0cbf12ab7a82, 0xe814fdb7f45befe0, 0x42598ec14df67188, ]), - ([0xb69ed321abbeffbb, 0xfb496d8c39b64e42, 0x274f1cfbb925c789, 0x9e846d2b9a56b834, - 0xc7f297c0d48bc3b6, 0xb859ab1e45850a0a, 0x3244fe3bcb1244cb, 0xb98e1cfa647575de, - 0x3c9ed8013b0b366b, 0x6a242cb943c91b16, 0x404794ad562239f1, 0x209363e20945adf6, ], - [0x402cd8c7a11a682a, 0xc25b92012a2ad940, 0x64a26e5d349a800d, 0x78fcf2d5fe54bd74, - 0x0724f91d1abd3154, 0xb1fa8e7a8853fe41, 0x0b82a2b53fa007f0, 0x226f2dbe1bae032f, - 0x8c86ef4f325ff4ce, 0xce2fe2273aed3f7a, 0x3f67b6b298ae64a6, 0xaaf13b4630e53e41, ]), - ]; - - check_test_vectors::(test_vectors12); - } - - #[test] - fn consistency() { - check_consistency::(); - check_consistency::(); - } -} diff --git a/src/iop/challenger.rs b/src/iop/challenger.rs index afecb1b2..4bd170f0 100644 --- a/src/iop/challenger.rs +++ b/src/iop/challenger.rs @@ -325,8 +325,8 @@ impl RecursiveChallenger { #[cfg(test)] mod tests { - use crate::field::crandall_field::CrandallField; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::iop::challenger::{Challenger, RecursiveChallenger}; use crate::iop::generator::generate_partial_witness; use crate::iop::target::Target; @@ -336,7 +336,7 @@ mod tests { #[test] fn no_duplicate_challenges() { - type F = CrandallField; + type F = GoldilocksField; let mut challenger = Challenger::new(); let mut challenges = Vec::new(); @@ -356,7 +356,7 @@ mod tests { /// Tests for consistency between `Challenger` and `RecursiveChallenger`. #[test] fn test_consistency() { - type F = CrandallField; + type F = GoldilocksField; // These are mostly arbitrary, but we want to test some rounds with enough inputs/outputs to // trigger multiple absorptions/squeezes. diff --git a/src/plonk/proof.rs b/src/plonk/proof.rs index a10ae2d9..92316f74 100644 --- a/src/plonk/proof.rs +++ b/src/plonk/proof.rs @@ -307,8 +307,8 @@ pub struct OpeningSetTarget { mod tests { use anyhow::Result; - use crate::field::crandall_field::CrandallField; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::fri::reduction_strategies::FriReductionStrategy; use crate::iop::witness::PartialWitness; use crate::plonk::circuit_builder::CircuitBuilder; @@ -317,7 +317,7 @@ mod tests { #[test] fn test_proof_compression() -> Result<()> { - type F = CrandallField; + type F = GoldilocksField; const D: usize = 4; let mut config = CircuitConfig::large_config(); diff --git a/src/polynomial/division.rs b/src/polynomial/division.rs index 0410bec1..6ac38676 100644 --- a/src/polynomial/division.rs +++ b/src/polynomial/division.rs @@ -184,14 +184,14 @@ impl PolynomialCoeffs { mod tests { use std::time::Instant; - use crate::field::crandall_field::CrandallField; use crate::field::extension_field::quartic::QuarticExtension; use crate::field::field_types::Field; + use crate::field::goldilocks_field::GoldilocksField; use crate::polynomial::polynomial::PolynomialCoeffs; #[test] fn zero_div_z_h() { - type F = CrandallField; + type F = GoldilocksField; let zero = PolynomialCoeffs::::zero(16); let quotient = zero.divide_by_z_h(4); assert_eq!(quotient, zero); @@ -199,7 +199,7 @@ mod tests { #[test] fn division_by_z_h() { - type F = CrandallField; + type F = GoldilocksField; let zero = F::ZERO; let three = F::from_canonical_u64(3); let four = F::from_canonical_u64(4); @@ -220,7 +220,7 @@ mod tests { #[test] #[ignore] fn test_division_by_linear() { - type F = QuarticExtension; + type F = QuarticExtension; let n = 1_000_000; let poly = PolynomialCoeffs::new(F::rand_vec(n)); let z = F::rand(); @@ -245,7 +245,7 @@ mod tests { #[test] #[ignore] fn test_division_by_quadratic() { - type F = QuarticExtension; + type F = QuarticExtension; let n = 1_000_000; let poly = PolynomialCoeffs::new(F::rand_vec(n)); let quad = PolynomialCoeffs::new(F::rand_vec(2)); diff --git a/src/polynomial/polynomial.rs b/src/polynomial/polynomial.rs index eb1529aa..107d7a7b 100644 --- a/src/polynomial/polynomial.rs +++ b/src/polynomial/polynomial.rs @@ -388,11 +388,11 @@ mod tests { use rand::{thread_rng, Rng}; use super::*; - use crate::field::crandall_field::CrandallField; + use crate::field::goldilocks_field::GoldilocksField; #[test] fn test_trimmed() { - type F = CrandallField; + type F = GoldilocksField; assert_eq!( PolynomialCoeffs:: { coeffs: vec![] }.trimmed(), @@ -418,7 +418,7 @@ mod tests { #[test] fn test_coset_fft() { - type F = CrandallField; + type F = GoldilocksField; let k = 8; let n = 1 << k; @@ -439,7 +439,7 @@ mod tests { #[test] fn test_coset_ifft() { - type F = CrandallField; + type F = GoldilocksField; let k = 8; let n = 1 << k; @@ -460,7 +460,7 @@ mod tests { #[test] fn test_polynomial_multiplication() { - type F = CrandallField; + type F = GoldilocksField; let mut rng = thread_rng(); let (a_deg, b_deg) = (rng.gen_range(1..10_000), rng.gen_range(1..10_000)); let a = PolynomialCoeffs::new(F::rand_vec(a_deg)); @@ -476,7 +476,7 @@ mod tests { #[test] fn test_inv_mod_xn() { - type F = CrandallField; + type F = GoldilocksField; let mut rng = thread_rng(); let a_deg = rng.gen_range(1..1_000); let n = rng.gen_range(1..1_000); @@ -498,7 +498,7 @@ mod tests { #[test] fn test_polynomial_long_division() { - type F = CrandallField; + type F = GoldilocksField; let mut rng = thread_rng(); let (a_deg, b_deg) = (rng.gen_range(1..10_000), rng.gen_range(1..10_000)); let a = PolynomialCoeffs::new(F::rand_vec(a_deg)); @@ -512,7 +512,7 @@ mod tests { #[test] fn test_polynomial_division() { - type F = CrandallField; + type F = GoldilocksField; let mut rng = thread_rng(); let (a_deg, b_deg) = (rng.gen_range(1..10_000), rng.gen_range(1..10_000)); let a = PolynomialCoeffs::new(F::rand_vec(a_deg)); @@ -526,7 +526,7 @@ mod tests { #[test] fn test_polynomial_division_by_constant() { - type F = CrandallField; + type F = GoldilocksField; let mut rng = thread_rng(); let a_deg = rng.gen_range(1..10_000); let a = PolynomialCoeffs::new(F::rand_vec(a_deg)); @@ -540,7 +540,7 @@ mod tests { #[test] fn test_division_by_z_h() { - type F = CrandallField; + type F = GoldilocksField; let mut rng = thread_rng(); let a_deg = rng.gen_range(1..10_000); let n = rng.gen_range(1..a_deg); @@ -562,7 +562,7 @@ mod tests { #[test] fn divide_zero_poly_by_z_h() { - let zero_poly = PolynomialCoeffs::::empty(); + let zero_poly = PolynomialCoeffs::::empty(); zero_poly.divide_by_z_h(16); } @@ -570,7 +570,7 @@ mod tests { // `(X^n - 1)/(X - a) #[test] fn test_division_linear() { - type F = CrandallField; + type F = GoldilocksField; let mut rng = thread_rng(); let l = 14; let n = 1 << l; @@ -594,7 +594,7 @@ mod tests { #[test] fn eq() { - type F = CrandallField; + type F = GoldilocksField; assert_eq!( PolynomialCoeffs::::new(vec![]), PolynomialCoeffs::new(vec![]) diff --git a/src/util/reducing.rs b/src/util/reducing.rs index a729662a..25dc88cc 100644 --- a/src/util/reducing.rs +++ b/src/util/reducing.rs @@ -181,15 +181,15 @@ mod tests { use anyhow::Result; use super::*; - use crate::field::crandall_field::CrandallField; use crate::field::extension_field::quartic::QuarticExtension; + use crate::field::goldilocks_field::GoldilocksField; use crate::iop::witness::PartialWitness; use crate::plonk::circuit_data::CircuitConfig; use crate::plonk::verifier::verify; fn test_reduce_gadget_base(n: usize) -> Result<()> { - type F = CrandallField; - type FF = QuarticExtension; + type F = GoldilocksField; + type FF = QuarticExtension; const D: usize = 4; let config = CircuitConfig::large_config(); @@ -216,8 +216,8 @@ mod tests { } fn test_reduce_gadget(n: usize) -> Result<()> { - type F = CrandallField; - type FF = QuarticExtension; + type F = GoldilocksField; + type FF = QuarticExtension; const D: usize = 4; let config = CircuitConfig::large_config();