Skip to content

Commit

Permalink
Reuse commitment evaluation (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
spapinistarkware authored Apr 15, 2024
1 parent ae2aa27 commit f988f99
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 21 deletions.
13 changes: 10 additions & 3 deletions src/core/air/air_ext.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -52,6 +55,7 @@ pub trait AirExt<B: Backend>: Air<B> {
ComponentVec<Vec<CirclePoint<SecureField>>>,
ComponentVec<Vec<SecureField>>,
) {
let _span = span!(Level::INFO, "Evaluate columns out of domain").entered();
let mut component_points = ComponentVec(Vec::new());
let mut component_values = ComponentVec(Vec::new());
zip(self.components(), component_traces).for_each(|(component, trace)| {
Expand Down Expand Up @@ -101,14 +105,17 @@ pub trait AirExt<B: Backend>: Air<B> {
fn component_traces<'a>(
&'a self,
polynomials: &'a [CirclePoly<B>],
evals: &'a [CircleEvaluation<B, BaseField, BitReversedOrder>],
) -> Vec<ComponentTrace<'_, B>> {
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()
}
Expand Down
21 changes: 16 additions & 5 deletions src/core/air/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use std::iter::zip;
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::CirclePoly;
use super::poly::circle::{CircleEvaluation, CirclePoly};
use super::poly::BitReversedOrder;
use super::ColumnVec;

pub mod accumulation;
Expand Down Expand Up @@ -60,7 +62,7 @@ pub trait Component<B: Backend> {
ColumnVec<Vec<SecureField>>,
) {
let points = self.mask_points(point);
let values = zip(&points, &trace.columns)
let values = zip(&points, &trace.polys)
.map(|(col_points, col)| {
col_points
.iter()
Expand All @@ -83,12 +85,21 @@ pub trait Component<B: Backend> {
// TODO(spapini): Extra functions for FRI and decommitment.
}

/// A component trace is a set of polynomials for each column on that component.
/// Each polynomial is stored both in a coefficients, and evaluations form (for efficiency)
pub struct ComponentTrace<'a, B: Backend> {
pub columns: Vec<&'a CirclePoly<B>>,
/// Polynomials for each column.
pub polys: Vec<&'a CirclePoly<B>>,
/// Evaluations for each column. The evaluation domain is the commitment domain for that column
/// obtained from [AirExt::trace_commitment_domains()].
pub evals: Vec<&'a CircleEvaluation<B, BaseField, BitReversedOrder>>,
}

impl<'a, B: Backend> ComponentTrace<'a, B> {
pub fn new(columns: Vec<&'a CirclePoly<B>>) -> Self {
Self { columns }
pub fn new(
polys: Vec<&'a CirclePoly<B>>,
evals: Vec<&'a CircleEvaluation<B, BaseField, BitReversedOrder>>,
) -> Self {
Self { polys, evals }
}
}
5 changes: 4 additions & 1 deletion src/core/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ pub fn prove<B: Backend + MerkleOps<MerkleHasher>>(
let span = span!(Level::INFO, "Composition generation").entered();
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,
),
);
span.exit();

Expand Down
2 changes: 1 addition & 1 deletion src/examples/fibonacci/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Component<CPUBackend> for FibonacciComponent {
trace: &ComponentTrace<'_, CPUBackend>,
evaluation_accumulator: &mut DomainEvaluationAccumulator<CPUBackend>,
) {
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();
Expand Down
4 changes: 3 additions & 1 deletion src/examples/fibonacci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ 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_eval =
trace_poly.evaluate(CanonicCoset::new(trace_poly.log_size() + 1).circle_domain());
let trace = ComponentTrace::new(vec![&trace_poly], vec![&trace_eval]);

// TODO(ShaharS), Change to a channel implementation to retrieve the random
// coefficients from extension field.
Expand Down
10 changes: 2 additions & 8 deletions src/examples/wide_fibonacci/avx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,10 @@ impl Component<AVX512Backend> for WideFibComponent {
trace: &ComponentTrace<'_, AVX512Backend>,
evaluation_accumulator: &mut DomainEvaluationAccumulator<AVX512Backend>,
) {
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;

// Denoms.
let span = span!(Level::INFO, "Constraint eval denominators").entered();
Expand Down
2 changes: 1 addition & 1 deletion src/examples/wide_fibonacci/constraint_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Component<CPUBackend> for WideFibComponent {
let trace_eval_domain = CanonicCoset::new(max_constraint_degree).circle_domain();
let mut trace_evals = vec![];
for poly_index in 0..256 {
let poly = &trace.columns[poly_index];
let poly = &trace.polys[poly_index];
trace_evals.push(poly.evaluate(trace_eval_domain));
}
let zero_domain = CanonicCoset::new(self.log_size).coset;
Expand Down
8 changes: 7 additions & 1 deletion src/examples/wide_fibonacci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,15 @@ mod tests {
.into_iter()
.map(|eval| eval.interpolate())
.collect_vec();
let eval_domain = CanonicCoset::new(wide_fib.log_size + 1).circle_domain();
let trace_evals = trace_polys
.iter()
.map(|poly| poly.evaluate(eval_domain))
.collect_vec();

let trace = ComponentTrace {
columns: trace_polys.iter().collect(),
polys: trace_polys.iter().collect(),
evals: trace_evals.iter().collect(),
};

wide_fib.evaluate_constraint_quotients_on_domain(&trace, &mut acc);
Expand Down

0 comments on commit f988f99

Please sign in to comment.