Skip to content

Commit

Permalink
Reuse commitment evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
spapinistarkware committed Mar 28, 2024
1 parent 34378d1 commit 04dfbe3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 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 @@ -48,6 +51,7 @@ pub trait AirExt<B: Backend>: Air<B> {
ComponentVec<Vec<CirclePoint<SecureField>>>,
ComponentVec<Vec<SecureField>>,
) {
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)| {
Expand Down Expand Up @@ -102,14 +106,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
18 changes: 12 additions & 6 deletions src/core/air/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,12 +89,12 @@ pub trait Component<B: Backend> {
ColumnVec<Vec<SecureField>>,
) {
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()
Expand All @@ -116,11 +118,15 @@ pub trait Component<B: Backend> {
}

pub struct ComponentTrace<'a, B: Backend> {
pub columns: Vec<&'a CirclePoly<B>>,
pub polys: Vec<&'a CirclePoly<B>>,
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 @@ -96,7 +96,10 @@ pub fn prove<B: Backend + MerkleOps<MerkleHasher>>(
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();
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 @@ -84,7 +84,7 @@ impl Component<CPUBackend> for FibonacciComponent {
evaluation_accumulator: &mut DomainEvaluationAccumulator<CPUBackend>,
) {
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();
Expand Down
2 changes: 1 addition & 1 deletion src/examples/fibonacci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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 @@ -68,16 +68,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;

let _span = span!(Level::INFO, "Constraint eval evaluation").entered();
let random_coeff = PackedQM31::broadcast(evaluation_accumulator.random_coeff);
Expand Down

0 comments on commit 04dfbe3

Please sign in to comment.