Skip to content

Commit

Permalink
Evaluation oods once (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
spapinistarkware authored Apr 16, 2024
1 parent f988f99 commit 249695d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 61 deletions.
20 changes: 0 additions & 20 deletions src/core/air/air_ext.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::iter::zip;

use itertools::Itertools;
use tracing::{span, Level};

use super::accumulation::{DomainEvaluationAccumulator, PointEvaluationAccumulator};
use super::{Air, ComponentTrace};
Expand Down Expand Up @@ -47,25 +46,6 @@ pub trait AirExt<B: Backend>: Air<B> {
accumulator.finalize()
}

fn mask_points_and_values(
&self,
point: CirclePoint<SecureField>,
component_traces: &[ComponentTrace<'_, 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)| {
let (points, values) = component.mask_points_and_values(point, trace);
component_points.push(points);
component_values.push(values);
});
(component_points, component_values)
}

fn mask_points(
&self,
point: CirclePoint<SecureField>,
Expand Down
27 changes: 0 additions & 27 deletions src/core/air/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::iter::zip;

use self::accumulation::{DomainEvaluationAccumulator, PointEvaluationAccumulator};
use super::backend::Backend;
use super::circle::CirclePoint;
Expand Down Expand Up @@ -49,31 +47,6 @@ pub trait Component<B: Backend> {
point: CirclePoint<SecureField>,
) -> ColumnVec<Vec<CirclePoint<SecureField>>>;

/// Calculates the mask points and evaluates them at each column.
/// The mask values are used to evaluate the composition polynomial at a certain point.
/// Returns two vectors with an entry for each column. Each entry holds the points/values
/// of the mask at that column.
fn mask_points_and_values(
&self,
point: CirclePoint<SecureField>,
trace: &ComponentTrace<'_, B>,
) -> (
ColumnVec<Vec<CirclePoint<SecureField>>>,
ColumnVec<Vec<SecureField>>,
) {
let points = self.mask_points(point);
let values = zip(&points, &trace.polys)
.map(|(col_points, col)| {
col_points
.iter()
.map(|point| col.eval_at_point(*point))
.collect()
})
.collect();

(points, values)
}

/// Evaluates the constraint quotients combination of the component, given the mask values.
fn evaluate_constraint_quotients_at_point(
&self,
Expand Down
4 changes: 3 additions & 1 deletion src/core/commitment_scheme/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ impl<B: Backend + MerkleOps<MerkleHasher>> CommitmentSchemeProver<B> {
channel: &mut ProofChannel,
twiddles: &TwiddleTree<B>,
) -> CommitmentSchemeProof {
// Evaluate polynomials on samples points.
// Evaluate polynomials on open points.
let span = span!(Level::INFO, "Evaluate columns out of domain").entered();
let samples = self
.polynomials()
.zip_cols(&sampled_points)
Expand All @@ -89,6 +90,7 @@ impl<B: Backend + MerkleOps<MerkleHasher>> CommitmentSchemeProver<B> {
})
.collect_vec()
});
span.exit();
let sampled_values = samples
.as_cols_ref()
.map_cols(|x| x.iter().map(|o| o.value).collect());
Expand Down
5 changes: 1 addition & 4 deletions src/core/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,7 @@ pub fn prove<B: Backend + MerkleOps<MerkleHasher>>(
// Second tree - composition polynomial.
sample_points.push(vec![vec![oods_point]; 4]);

// TODO(spapini): Precompute twiddles outside.
let twiddles = B::precompute_twiddles(
CanonicCoset::new(composition_polynomial_log_degree_bound + 1).half_coset(),
);
// Prove the trace and composition OODS values, and retrieve them.
let commitment_scheme_proof = commitment_scheme.prove_values(sample_points, channel, &twiddles);

// Evaluate composition polynomial at OODS point and check that it matches the trace OODS
Expand Down
15 changes: 11 additions & 4 deletions src/examples/fibonacci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ impl MultiFibonacci {
#[cfg(test)]
mod tests {
use std::assert_matches::assert_matches;
use std::iter::zip;

use itertools::Itertools;
use num_traits::One;
Expand Down Expand Up @@ -159,10 +160,16 @@ mod tests {
// what we expect.
let point = CirclePoint::<SecureField>::get_point(98989892);

let (_, mask_values) = fib
.air
.component
.mask_points_and_values(point, &component_traces[0]);
let points = fib.air.mask_points(point);
let mask_values = zip(&component_traces[0].polys, &points[0])
.map(|(poly, points)| {
points
.iter()
.map(|point| poly.eval_at_point(*point))
.collect_vec()
})
.collect_vec();

let mut evaluation_accumulator = PointEvaluationAccumulator::new(random_coeff);
fib.air.component.evaluate_constraint_quotients_at_point(
point,
Expand Down
6 changes: 1 addition & 5 deletions src/examples/wide_fibonacci/constraint_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ impl Component<CPUBackend> for WideFibComponent {
) {
let max_constraint_degree = Component::<CPUBackend>::max_constraint_log_degree_bound(self);
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.polys[poly_index];
trace_evals.push(poly.evaluate(trace_eval_domain));
}
let trace_evals = &trace.evals;
let zero_domain = CanonicCoset::new(self.log_size).coset;
let mut denoms = vec![];
for point in trace_eval_domain.iter() {
Expand Down

0 comments on commit 249695d

Please sign in to comment.