From 431bde2c72311d5437e03bd84e613540e66ae40a Mon Sep 17 00:00:00 2001 From: wborgeaud Date: Fri, 4 Feb 2022 17:04:07 +0100 Subject: [PATCH] Fix number of quotient polys --- starky/src/fibonacci_stark.rs | 2 +- starky/src/prover.rs | 6 +++--- starky/src/stark.rs | 6 ++++-- starky/src/stark_testing.rs | 6 +++--- starky/src/verifier.rs | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/starky/src/fibonacci_stark.rs b/starky/src/fibonacci_stark.rs index ce50dfd5..c77775e8 100644 --- a/starky/src/fibonacci_stark.rs +++ b/starky/src/fibonacci_stark.rs @@ -82,7 +82,7 @@ impl, const D: usize> Stark for FibonacciStar todo!() } - fn degree(&self) -> usize { + fn constraint_degree(&self) -> usize { 2 } } diff --git a/starky/src/prover.rs b/starky/src/prover.rs index 2bea24ff..171ea92a 100644 --- a/starky/src/prover.rs +++ b/starky/src/prover.rs @@ -82,7 +82,7 @@ where .flat_map(|mut quotient_poly| { quotient_poly.trim(); quotient_poly - .pad(degree << rate_bits) + .pad(degree * (stark.constraint_degree() - 1)) .expect("Quotient has failed, the vanishing polynomial is not divisible by `Z_H"); // Split quotient into degree-n chunks. quotient_poly.chunks(degree) @@ -123,7 +123,7 @@ where timing, "compute openings proof", PolynomialBatch::prove_openings( - &S::fri_instance(zeta, g, rate_bits, config.num_challenges), + &stark.fri_instance(zeta, g, rate_bits, config.num_challenges), initial_merkle_trees, &mut challenger, &fri_params, @@ -162,7 +162,7 @@ where { let degree = 1 << degree_bits; - let max_degree_bits = log2_ceil(stark.degree() - 1); + let max_degree_bits = log2_ceil(stark.constraint_degree() - 1); assert!( max_degree_bits <= rate_bits, "Having constraints of degree higher than the rate is not supported yet." diff --git a/starky/src/stark.rs b/starky/src/stark.rs index 9721c203..8f112939 100644 --- a/starky/src/stark.rs +++ b/starky/src/stark.rs @@ -63,11 +63,12 @@ pub trait Stark, const D: usize>: Sync { ); /// The maximum constraint degree. - fn degree(&self) -> usize; + fn constraint_degree(&self) -> usize; /// Computes the FRI instance used to prove this Stark. // TODO: Permutation polynomials. fn fri_instance( + &self, zeta: F::Extension, g: F::Extension, rate_bits: usize, @@ -75,7 +76,8 @@ pub trait Stark, const D: usize>: Sync { ) -> FriInstanceInfo { let no_blinding_oracle = FriOracleInfo { blinding: false }; let trace_info = FriPolynomialInfo::from_range(0, 0..Self::COLUMNS); - let quotient_info = FriPolynomialInfo::from_range(1, 0..(1 << rate_bits) * num_challenges); + let quotient_info = + FriPolynomialInfo::from_range(1, 0..(self.constraint_degree() - 1) * num_challenges); let zeta_batch = FriBatchInfo { point: zeta, polynomials: [trace_info.clone(), quotient_info].concat(), diff --git a/starky/src/stark_testing.rs b/starky/src/stark_testing.rs index b8b31cf9..b28a206e 100644 --- a/starky/src/stark_testing.rs +++ b/starky/src/stark_testing.rs @@ -22,7 +22,7 @@ where [(); S::COLUMNS]:, [(); S::PUBLIC_INPUTS]:, { - let rate_bits = log2_ceil(stark.degree() + 1); + let rate_bits = log2_ceil(stark.constraint_degree() + 1); let wire_ldes = random_low_degree_matrix::(S::COLUMNS, rate_bits); let size = wire_ldes.len(); @@ -68,13 +68,13 @@ where .collect::>(); let constraint_eval_degree = PolynomialValues::new(constraint_evals).degree(); - let maximum_degree = WITNESS_SIZE * stark.degree() - 1; + let maximum_degree = WITNESS_SIZE * stark.constraint_degree() - 1; ensure!( constraint_eval_degree <= maximum_degree, "Expected degrees at most {} * {} - 1 = {}, actual {:?}", WITNESS_SIZE, - stark.degree(), + stark.constraint_degree(), maximum_degree, constraint_eval_degree ); diff --git a/starky/src/verifier.rs b/starky/src/verifier.rs index b91fe457..b04ec684 100644 --- a/starky/src/verifier.rs +++ b/starky/src/verifier.rs @@ -98,7 +98,7 @@ where // So to reconstruct `t(zeta)` we can compute `reduce_with_powers(chunk, zeta^n)` for each // `quotient_degree_factor`-sized chunk of the original evaluations. for (i, chunk) in quotient_polys_zeta - .chunks(1 << config.fri_config.rate_bits) + .chunks(stark.constraint_degree() - 1) .enumerate() { ensure!(vanishing_polys_zeta[i] == z_h_zeta * reduce_with_powers(chunk, zeta_pow_deg)); @@ -108,7 +108,7 @@ where let merkle_caps = &[proof.trace_cap, proof.quotient_polys_cap]; verify_fri_proof::( - &S::fri_instance( + &stark.fri_instance( challenges.stark_zeta, F::primitive_root_of_unity(degree_bits).into(), config.fri_config.rate_bits,