diff --git a/src/core/fri.rs b/src/core/fri.rs index 26a5b5ad7..38449b051 100644 --- a/src/core/fri.rs +++ b/src/core/fri.rs @@ -1,4 +1,5 @@ use std::cmp::Reverse; +use std::collections::BTreeMap; use std::fmt::Debug; use std::iter::zip; use std::ops::RangeInclusive; @@ -254,7 +255,7 @@ impl> FriProver { pub fn decommit( self, channel: &mut impl Channel, - ) -> (FriProof, Vec) { + ) -> (FriProof, BTreeMap) { let max_column_log_size = self.column_log_sizes[0]; let queries = Queries::generate(channel, max_column_log_size, self.config.n_queries); let positions = get_opening_positions(&queries, &self.column_log_sizes); @@ -502,7 +503,7 @@ impl> FriVerifier { pub fn column_opening_positions( &mut self, channel: &mut impl Channel, - ) -> Vec { + ) -> BTreeMap { let column_log_sizes = self .column_bounds .iter() @@ -519,19 +520,19 @@ impl> FriVerifier { /// Returns the column opening positions needed for verification. /// /// The domain log sizes must be unique and in descending order. -// TODO(AlonH): Consider returning a mapping instead of a vector. fn get_opening_positions( queries: &Queries, domain_log_sizes: &[u32], -) -> Vec { +) -> BTreeMap { let mut prev_log_size = domain_log_sizes[0]; assert!(prev_log_size == queries.log_domain_size); let mut prev_queries = queries.clone(); - let mut positions = vec![prev_queries.opening_positions(FOLD_STEP)]; + let mut positions = BTreeMap::new(); + positions.insert(prev_log_size, prev_queries.opening_positions(FOLD_STEP)); for log_size in domain_log_sizes.iter().skip(1) { let n_folds = prev_log_size - log_size; let queries = prev_queries.fold(n_folds); - positions.push(queries.opening_positions(FOLD_STEP)); + positions.insert(*log_size, queries.opening_positions(FOLD_STEP)); prev_log_size = *log_size; prev_queries = queries; } @@ -1038,7 +1039,7 @@ mod tests { let config = FriConfig::new(2, LOG_BLOWUP_FACTOR, 3); let prover = FriProver::commit(&mut test_channel(), config, &polynomials); let (proof, prover_opening_positions) = prover.decommit(&mut test_channel()); - let decommitment_values = zip(&polynomials, &prover_opening_positions) + let decommitment_values = zip(&polynomials, prover_opening_positions.values().rev()) .map(|(poly, positions)| open_polynomial(poly, positions)) .collect(); let bounds = LOG_DEGREES.map(CirclePolyDegreeBound::new).to_vec(); @@ -1233,11 +1234,10 @@ mod tests { polynomial: &CPUCircleEvaluation, queries: &Queries, ) -> SparseCircleEvaluation { - let positions = get_opening_positions( - queries, - &[queries.log_domain_size, polynomial.domain.log_size()], - ); - open_polynomial(polynomial, &positions[1]) + let polynomial_log_size = polynomial.domain.log_size(); + let positions = + get_opening_positions(queries, &[queries.log_domain_size, polynomial_log_size]); + open_polynomial(polynomial, &positions[&polynomial_log_size]) } fn open_polynomial>( diff --git a/src/fibonacci/mod.rs b/src/fibonacci/mod.rs index 9b8cbde5e..735175f06 100644 --- a/src/fibonacci/mod.rs +++ b/src/fibonacci/mod.rs @@ -153,8 +153,11 @@ impl Fibonacci { let proof_of_work = ProofOfWork::new(PROOF_OF_WORK_BITS).prove(channel); let (fri_proof, fri_opening_positions) = fri_prover.decommit(channel); - let composition_polynomial_decommitment_positions = fri_opening_positions[0].flatten(); - let trace_decommitment_positions = fri_opening_positions[1].flatten(); + let composition_polynomial_decommitment_positions = fri_opening_positions + [&self.composition_polynomial_commitment_domain.log_size()] + .flatten(); + let trace_decommitment_positions = + fri_opening_positions[&self.trace_commitment_domain.log_size()].flatten(); // Decommit and get the values in the opening positions. let composition_polynomial_opened_values = composition_polynomial_decommitment_positions @@ -217,16 +220,17 @@ pub fn verify_proof(proof: FibonacciProof) -> bool { ProofOfWork::new(PROOF_OF_WORK_BITS).verify(channel, &proof.proof_of_work); let opening_positions = fri_verifier.column_opening_positions(channel); - let composition_polynomial_opening_positions = &opening_positions[0]; - let trace_opening_positions = &opening_positions[1]; - assert!(trace_commitment_scheme.verify( - &proof.trace_decommitments[0], - &trace_opening_positions.flatten() - )); + let composition_polynomial_opening_positions = + &opening_positions[&fib.composition_polynomial_commitment_domain.log_size()]; + let trace_opening_positions = &opening_positions[&fib.trace_commitment_domain.log_size()]; assert!(composition_polynomial_commitment_scheme.verify( &proof.composition_polynomial_decommitment, &composition_polynomial_opening_positions.flatten() )); + assert!(trace_commitment_scheme.verify( + &proof.trace_decommitments[0], + &trace_opening_positions.flatten() + )); // An evaluation for each mask item and one for the composition_polynomial. let mut sparse_circle_evaluations = Vec::with_capacity(trace_oods_points.len() + 1);