diff --git a/src/field/crandall_field.rs b/src/field/crandall_field.rs index 9180e1e1..fd1a178e 100644 --- a/src/field/crandall_field.rs +++ b/src/field/crandall_field.rs @@ -50,7 +50,7 @@ impl Field for CrandallField { *self * *self * *self } - fn inverse(&self) -> Self { + fn try_inverse(&self) -> Option { unimplemented!() } diff --git a/src/field/fft.rs b/src/field/fft.rs index 243b2767..a75f1de5 100644 --- a/src/field/fft.rs +++ b/src/field/fft.rs @@ -34,10 +34,10 @@ impl FftPrecomputation { } } -// pub fn fft(coefficients: &[F]) -> Vec { -// let precomputation = fft_precompute(coefficients.len()); -// fft_with_precomputation(coefficients, &precomputation) -// } +pub fn fft(coefficients: Vec) -> Vec { + let precomputation = fft_precompute(coefficients.len()); + fft_with_precomputation_power_of_2(coefficients, &precomputation) +} pub fn fft_precompute(degree: usize) -> FftPrecomputation { let degree_pow = log2_ceil(degree); @@ -54,11 +54,11 @@ pub fn fft_precompute(degree: usize) -> FftPrecomputation { } pub fn ifft_with_precomputation_power_of_2( - points: &[F], + points: Vec, precomputation: &FftPrecomputation, ) -> Vec { let n = points.len(); - let n_inv = Field(n as u64).multiplicative_inverse().unwrap(); + let n_inv = F::from_canonical_usize(n).try_inverse().unwrap(); let mut result = fft_with_precomputation_power_of_2(points, precomputation); // We reverse all values except the first, and divide each by n. diff --git a/src/field/field.rs b/src/field/field.rs index ecb70adc..34aa25af 100644 --- a/src/field/field.rs +++ b/src/field/field.rs @@ -25,7 +25,11 @@ pub trait Field: 'static fn cube(&self) -> Self; /// Compute the multiplicative inverse of this field element. - fn inverse(&self) -> Self; + fn try_inverse(&self) -> Option; + + fn inverse(&self) -> Self { + self.try_inverse().expect("Tried to invert zero") + } fn primitive_root_of_unity(n_power: usize) -> Self; diff --git a/src/fri.rs b/src/fri.rs new file mode 100644 index 00000000..d7ebfee5 --- /dev/null +++ b/src/fri.rs @@ -0,0 +1,21 @@ +/// Somewhat arbitrary. Smaller values will increase delta, but with diminishing returns, +/// while increasing L, potentially requiring more challenge points. +const EPSILON: f64 = 0.01; + +fn fri_delta(rate_log: usize, conjecture: bool) -> f64 { + let rate = (1 << rate_log) as f64; + if conjecture { + todo!() + } else { + return 1.0 - rate.sqrt() - EPSILON; + } +} + +fn fri_l(rate_log: usize, conjecture: bool) -> f64 { + let rate = (1 << rate_log) as f64; + if conjecture { + todo!() + } else { + return 1.0 / (2.0 * EPSILON * rate.sqrt()); + } +} diff --git a/src/main.rs b/src/main.rs index a790c66d..0fe2cf14 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,7 @@ use crate::util::log2_ceil; mod circuit_data; mod constraint_polynomial; mod field; +mod fri; mod gates; mod generator; mod gmimc;