From 172fdd3d89ea32c9f3ee0b9dd4b91e7e8d753c92 Mon Sep 17 00:00:00 2001 From: wborgeaud Date: Mon, 22 Nov 2021 21:20:44 +0100 Subject: [PATCH] Comments --- src/field/extension_field/algebra.rs | 2 ++ src/fri/recursive_verifier.rs | 27 +++++++++++++++++++-------- src/gadgets/interpolation.rs | 3 +++ src/gadgets/polynomial.rs | 7 ++----- src/gates/interpolation.rs | 5 ++--- src/gates/low_degree_interpolation.rs | 7 +++---- src/plonk/prover.rs | 11 ----------- src/polynomial/polynomial.rs | 2 ++ 8 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/field/extension_field/algebra.rs b/src/field/extension_field/algebra.rs index 37f70f52..93d25de4 100644 --- a/src/field/extension_field/algebra.rs +++ b/src/field/extension_field/algebra.rs @@ -160,6 +160,7 @@ impl, const D: usize> PolynomialCoeffsAlgebra { .fold(ExtensionAlgebra::ZERO, |acc, &c| acc * x + c) } + /// Evaluate the polynomial at a point given its powers. The first power is the point itself, not 1. pub fn eval_with_powers(&self, powers: &[ExtensionAlgebra]) -> ExtensionAlgebra { debug_assert_eq!(self.coeffs.len(), powers.len() + 1); let acc = self.coeffs[0]; @@ -176,6 +177,7 @@ impl, const D: usize> PolynomialCoeffsAlgebra { .fold(ExtensionAlgebra::ZERO, |acc, &c| acc.scalar_mul(x) + c) } + /// Evaluate the polynomial at a point given its powers. The first power is the point itself, not 1. pub fn eval_base_with_powers(&self, powers: &[F]) -> ExtensionAlgebra { debug_assert_eq!(self.coeffs.len(), powers.len() + 1); let acc = self.coeffs[0]; diff --git a/src/fri/recursive_verifier.rs b/src/fri/recursive_verifier.rs index f543b12b..b31e01a8 100644 --- a/src/fri/recursive_verifier.rs +++ b/src/fri/recursive_verifier.rs @@ -46,7 +46,9 @@ impl, const D: usize> CircuitBuilder { let coset_start = self.mul(start, x); // The answer is gotten by interpolating {(x*g^i, P(x*g^i))} and evaluating at beta. - if 1 << arity_bits > common_data.quotient_degree_factor { + // `HighDegreeInterpolationGate` has degree `arity`, so we use the low-degree gate if + // the arity is too large. + if arity > common_data.quotient_degree_factor { self.interpolate_coset::>( arity_bits, coset_start, @@ -66,19 +68,28 @@ impl, const D: usize> CircuitBuilder { /// Make sure we have enough wires and routed wires to do the FRI checks efficiently. This check /// isn't required -- without it we'd get errors elsewhere in the stack -- but just gives more /// helpful errors. - fn check_recursion_config(&self, max_fri_arity_bits: usize) { + fn check_recursion_config( + &self, + max_fri_arity_bits: usize, + common_data: &CommonCircuitData, + ) { let random_access = RandomAccessGate::::new_from_config( &self.config, max_fri_arity_bits.max(self.config.cap_height), ); - let interpolation_gate = HighDegreeInterpolationGate::::new(max_fri_arity_bits); + let (interpolation_wires, interpolation_routed_wires) = + if 1 << max_fri_arity_bits > common_data.quotient_degree_factor { + let gate = LowDegreeInterpolationGate::::new(max_fri_arity_bits); + (gate.num_wires(), gate.num_routed_wires()) + } else { + let gate = HighDegreeInterpolationGate::::new(max_fri_arity_bits); + (gate.num_wires(), gate.num_routed_wires()) + }; - let min_wires = random_access - .num_wires() - .max(interpolation_gate.num_wires()); + let min_wires = random_access.num_wires().max(interpolation_wires); let min_routed_wires = random_access .num_routed_wires() - .max(interpolation_gate.num_routed_wires()); + .max(interpolation_routed_wires); assert!( self.config.num_wires >= min_wires, @@ -125,7 +136,7 @@ impl, const D: usize> CircuitBuilder { let config = &common_data.config; if let Some(max_arity_bits) = common_data.fri_params.max_arity_bits() { - self.check_recursion_config(max_arity_bits); + self.check_recursion_config(max_arity_bits, common_data); } debug_assert_eq!( diff --git a/src/gadgets/interpolation.rs b/src/gadgets/interpolation.rs index 9167e771..7f6f98f3 100644 --- a/src/gadgets/interpolation.rs +++ b/src/gadgets/interpolation.rs @@ -7,6 +7,9 @@ use crate::gates::gate::Gate; use crate::iop::target::Target; use crate::plonk::circuit_builder::CircuitBuilder; +/// Trait for gates which interpolate a polynomial, whose points are a (base field) coset of the multiplicative subgroup +/// with the given size, and whose values are extension field elements, given by input wires. +/// Outputs the evaluation of the interpolant at a given (extension field) evaluation point. pub(crate) trait InterpolationGate, const D: usize>: Gate + Copy { diff --git a/src/gadgets/polynomial.rs b/src/gadgets/polynomial.rs index 48a5f8b7..ff7fffd7 100644 --- a/src/gadgets/polynomial.rs +++ b/src/gadgets/polynomial.rs @@ -64,6 +64,8 @@ impl PolynomialCoeffsExtAlgebraTarget { } acc } + + /// Evaluate the polynomial at a point given its powers. The first power is the point itself, not 1. pub fn eval_with_powers( &self, builder: &mut CircuitBuilder, @@ -78,10 +80,5 @@ impl PolynomialCoeffsExtAlgebraTarget { .iter() .zip(powers) .fold(acc, |acc, (&x, &c)| builder.mul_add_ext_algebra(c, x, acc)) - // let mut acc = builder.zero_ext_algebra(); - // for &c in self.0.iter().rev() { - // acc = builder.mul_add_ext_algebra(point, acc, c); - // } - // acc } } diff --git a/src/gates/interpolation.rs b/src/gates/interpolation.rs index 58288bba..f7934b71 100644 --- a/src/gates/interpolation.rs +++ b/src/gates/interpolation.rs @@ -17,9 +17,8 @@ use crate::plonk::circuit_builder::CircuitBuilder; use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase}; use crate::polynomial::polynomial::PolynomialCoeffs; -/// Interpolates a polynomial, whose points are a (base field) coset of the multiplicative subgroup -/// with the given size, and whose values are extension field elements, given by input wires. -/// Outputs the evaluation of the interpolant at a given (extension field) evaluation point. +/// Interpolation gate with constraints of degree at most `1<, const D: usize> { pub subgroup_bits: usize, diff --git a/src/gates/low_degree_interpolation.rs b/src/gates/low_degree_interpolation.rs index 245c6d17..abbdb00e 100644 --- a/src/gates/low_degree_interpolation.rs +++ b/src/gates/low_degree_interpolation.rs @@ -17,9 +17,8 @@ use crate::plonk::circuit_builder::CircuitBuilder; use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase}; use crate::polynomial::polynomial::PolynomialCoeffs; -/// Interpolates a polynomial, whose points are a (base field) coset of the multiplicative subgroup -/// with the given size, and whose values are extension field elements, given by input wires. -/// Outputs the evaluation of the interpolant at a given (extension field) evaluation point. +/// Interpolation gate with constraints of degree 2. +/// `eval_unfiltered_recursively` uses more gates than `HighDegreeInterpolationGate`. #[derive(Copy, Clone, Debug)] pub(crate) struct LowDegreeInterpolationGate, const D: usize> { pub subgroup_bits: usize, @@ -344,7 +343,7 @@ impl, const D: usize> Gate for LowDegreeInter fn num_constraints(&self) -> usize { // `num_points * D` constraints to check for consistency between the coefficients and the // point-value pairs, plus `D` constraints for the evaluation value, plus `(D+1)*(num_points-2)` - // to check power constraints for evaluation point and wire shift. + // to check power constraints for evaluation point and shift. self.num_points() * D + D + (D + 1) * (self.num_points() - 2) } } diff --git a/src/plonk/prover.rs b/src/plonk/prover.rs index b5175f02..3f8e607d 100644 --- a/src/plonk/prover.rs +++ b/src/plonk/prover.rs @@ -66,17 +66,6 @@ pub(crate) fn prove, const D: usize>( .collect() ); - // let rows = (0..degree) - // .map(|i| wires_values.iter().map(|w| w.values[i]).collect::>()) - // .collect::>(); - // for (i, r) in rows.iter().enumerate() { - // let c = rows.iter().filter(|&x| x == r).count(); - // let s = prover_data.instances[i].gate_ref.0.id(); - // if c > 1 && !s.starts_with("Noop") { - // println!("{} {} {}", prover_data.instances[i].gate_ref.0.id(), i, c); - // } - // } - let wires_commitment = timed!( timing, "compute wires commitment", diff --git a/src/polynomial/polynomial.rs b/src/polynomial/polynomial.rs index 3c732208..b5a7fabd 100644 --- a/src/polynomial/polynomial.rs +++ b/src/polynomial/polynomial.rs @@ -120,6 +120,7 @@ impl PolynomialCoeffs { .fold(F::ZERO, |acc, &c| acc * x + c) } + /// Evaluate the polynomial at a point given its powers. The first power is the point itself, not 1. pub fn eval_with_powers(&self, powers: &[F]) -> F { debug_assert_eq!(self.coeffs.len(), powers.len() + 1); let acc = self.coeffs[0]; @@ -139,6 +140,7 @@ impl PolynomialCoeffs { .fold(F::ZERO, |acc, &c| acc.scalar_mul(x) + c) } + /// Evaluate the polynomial at a point given its powers. The first power is the point itself, not 1. pub fn eval_base_with_powers(&self, powers: &[F::BaseField]) -> F where F: FieldExtension,