From 04dfbe384b1e5a48c9eea7e1af8f7bb4f6750706 Mon Sep 17 00:00:00 2001 From: Shahar Papini Date: Sat, 16 Mar 2024 11:04:08 +0200 Subject: [PATCH] Reuse commitment evaluation --- src/core/air/air_ext.rs | 13 ++++++++++--- src/core/air/mod.rs | 18 ++++++++++++------ src/core/prover/mod.rs | 5 ++++- src/examples/fibonacci/component.rs | 2 +- src/examples/fibonacci/mod.rs | 2 +- src/examples/wide_fibonacci/avx.rs | 10 ++-------- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/core/air/air_ext.rs b/src/core/air/air_ext.rs index 16396dac1..fd2d223e0 100644 --- a/src/core/air/air_ext.rs +++ b/src/core/air/air_ext.rs @@ -1,13 +1,16 @@ use std::iter::zip; use itertools::Itertools; +use tracing::{span, Level}; use super::accumulation::{DomainEvaluationAccumulator, PointEvaluationAccumulator}; use super::{Air, ComponentTrace}; use crate::core::backend::Backend; use crate::core::circle::CirclePoint; +use crate::core::fields::m31::BaseField; use crate::core::fields::qm31::SecureField; -use crate::core::poly::circle::{CanonicCoset, CirclePoly, SecureCirclePoly}; +use crate::core::poly::circle::{CanonicCoset, CircleEvaluation, CirclePoly, SecureCirclePoly}; +use crate::core::poly::BitReversedOrder; use crate::core::prover::LOG_BLOWUP_FACTOR; use crate::core::ComponentVec; @@ -48,6 +51,7 @@ pub trait AirExt: Air { ComponentVec>>, ComponentVec>, ) { + let _span = span!(Level::INFO, "Eval columns ood").entered(); let mut component_points = ComponentVec(Vec::new()); let mut component_values = ComponentVec(Vec::new()); zip(self.components(), component_traces).for_each(|(component, trace)| { @@ -102,14 +106,17 @@ pub trait AirExt: Air { fn component_traces<'a>( &'a self, polynomials: &'a [CirclePoly], + evals: &'a [CircleEvaluation], ) -> Vec> { let poly_iter = &mut polynomials.iter(); + let eval_iter = &mut evals.iter(); self.components() .iter() .map(|component| { let n_columns = component.trace_log_degree_bounds().len(); - let columns = poly_iter.take(n_columns).collect(); - ComponentTrace::new(columns) + let polys = poly_iter.take(n_columns).collect(); + let evals = eval_iter.take(n_columns).collect(); + ComponentTrace::new(polys, evals) }) .collect() } diff --git a/src/core/air/mod.rs b/src/core/air/mod.rs index 7e99d4fc5..d925b9990 100644 --- a/src/core/air/mod.rs +++ b/src/core/air/mod.rs @@ -6,8 +6,10 @@ use itertools::Itertools; use self::accumulation::{DomainEvaluationAccumulator, PointEvaluationAccumulator}; use super::backend::Backend; use super::circle::CirclePoint; +use super::fields::m31::BaseField; use super::fields::qm31::SecureField; -use super::poly::circle::{CanonicCoset, CirclePoly}; +use super::poly::circle::{CanonicCoset, CircleEvaluation, CirclePoly}; +use super::poly::BitReversedOrder; use super::ColumnVec; pub mod accumulation; @@ -87,12 +89,12 @@ pub trait Component { ColumnVec>, ) { let domains = trace - .columns + .polys .iter() .map(|col| CanonicCoset::new(col.log_size())) .collect_vec(); let points = self.mask().to_points(&domains, point); - let values = zip(&points, &trace.columns) + let values = zip(&points, &trace.polys) .map(|(col_points, col)| { col_points .iter() @@ -116,11 +118,15 @@ pub trait Component { } pub struct ComponentTrace<'a, B: Backend> { - pub columns: Vec<&'a CirclePoly>, + pub polys: Vec<&'a CirclePoly>, + pub evals: Vec<&'a CircleEvaluation>, } impl<'a, B: Backend> ComponentTrace<'a, B> { - pub fn new(columns: Vec<&'a CirclePoly>) -> Self { - Self { columns } + pub fn new( + polys: Vec<&'a CirclePoly>, + evals: Vec<&'a CircleEvaluation>, + ) -> Self { + Self { polys, evals } } } diff --git a/src/core/prover/mod.rs b/src/core/prover/mod.rs index c1e6321fc..b0e177a45 100644 --- a/src/core/prover/mod.rs +++ b/src/core/prover/mod.rs @@ -96,7 +96,10 @@ pub fn prove>( let random_coeff = channel.draw_felt(); let composition_polynomial_poly = air.compute_composition_polynomial( random_coeff, - &air.component_traces(&commitment_scheme.trees[0].polynomials), + &air.component_traces( + &commitment_scheme.trees[0].polynomials, + &commitment_scheme.trees[0].evaluations, + ), ); let span = span!(Level::INFO, "Composition commitment").entered(); diff --git a/src/examples/fibonacci/component.rs b/src/examples/fibonacci/component.rs index 885319fe1..757e23565 100644 --- a/src/examples/fibonacci/component.rs +++ b/src/examples/fibonacci/component.rs @@ -84,7 +84,7 @@ impl Component for FibonacciComponent { evaluation_accumulator: &mut DomainEvaluationAccumulator, ) { let random_coeff = evaluation_accumulator.random_coeff; - let poly = &trace.columns[0]; + let poly = &trace.polys[0]; let trace_domain = CanonicCoset::new(self.log_size); let trace_eval_domain = CanonicCoset::new(self.log_size + 1).circle_domain(); let trace_eval = poly.evaluate(trace_eval_domain).bit_reverse(); diff --git a/src/examples/fibonacci/mod.rs b/src/examples/fibonacci/mod.rs index ab577b594..b1df6aa20 100644 --- a/src/examples/fibonacci/mod.rs +++ b/src/examples/fibonacci/mod.rs @@ -141,7 +141,7 @@ mod tests { let fib = Fibonacci::new(5, m31!(443693538)); let trace = fib.get_trace(); let trace_poly = trace.interpolate(); - let trace = ComponentTrace::new(vec![&trace_poly]); + let trace = ComponentTrace::new(vec![&trace_poly], vec![]); // TODO(ShaharS), Change to a channel implementation to retrieve the random // coefficients from extension field. diff --git a/src/examples/wide_fibonacci/avx.rs b/src/examples/wide_fibonacci/avx.rs index 31d61217b..a8a1c016b 100644 --- a/src/examples/wide_fibonacci/avx.rs +++ b/src/examples/wide_fibonacci/avx.rs @@ -68,16 +68,10 @@ impl Component for WideFibComponent { trace: &ComponentTrace<'_, AVX512Backend>, evaluation_accumulator: &mut DomainEvaluationAccumulator, ) { - let span = span!(Level::INFO, "Constraint eval extension").entered(); - assert_eq!(trace.columns.len(), N_COLS); + assert_eq!(trace.polys.len(), N_COLS); // TODO(spapini): Steal evaluation from commitment. let eval_domain = CanonicCoset::new(self.log_size + 1).circle_domain(); - let trace_eval = trace - .columns - .iter() - .map(|poly| poly.evaluate(eval_domain)) - .collect_vec(); - span.exit(); + let trace_eval = &trace.evals; let _span = span!(Level::INFO, "Constraint eval evaluation").entered(); let random_coeff = PackedQM31::broadcast(evaluation_accumulator.random_coeff);