Skip to content

Commit

Permalink
Create QuotientLogBoundsVisitor.
Browse files Browse the repository at this point in the history
  • Loading branch information
alonh5 committed Feb 26, 2024
1 parent 076759a commit a3ffbf4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 28 deletions.
3 changes: 2 additions & 1 deletion src/core/air/evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ impl<'a, B: Backend> ComponentVisitor<B> for ConstraintEvaluator<'a, B> {
}
}

/// Evaluates components' constraint polynomials and aggregates them into a composition polynomial.
/// Evaluates components' constraint polynomials at a single point and aggregates them into a
/// composition polynomial value.
pub struct ConstraintPointEvaluator<'a> {
point: CirclePoint<SecureField>,
mask_values: slice::Iter<'a, ColumnVec<Vec<SecureField>>>,
Expand Down
48 changes: 48 additions & 0 deletions src/core/air/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::slice;
use std::collections::BTreeSet;
use std::iter::zip;
use std::ops::Deref;

Expand All @@ -12,6 +13,7 @@ use super::backend::{Backend, CPUBackend};
use super::circle::CirclePoint;
use super::fields::m31::BaseField;
use super::fields::qm31::SecureField;
use super::fri::CirclePolyDegreeBound;
use super::poly::circle::{CanonicCoset, CirclePoly};
use super::{ColumnVec, ComponentVec};

Expand Down Expand Up @@ -85,6 +87,19 @@ pub trait AirExt: Air<CPUBackend> {
self.visit_components(&mut evaluator);
evaluator.finalize()
}

/// Returns the log degree bounds of the quotient polynomials in descending order.
fn quotient_log_bounds(&self) -> Vec<CirclePolyDegreeBound> {
let mut bounds_visitor = QuotientLogBoundsVisitor::new();
self.visit_components(&mut bounds_visitor);
let mut bounds = bounds_visitor.finalize();
bounds.push(self.max_constraint_log_degree_bound());
bounds
.into_iter()
.rev()
.map(CirclePolyDegreeBound::new)
.collect()
}
}

impl<A: Air<CPUBackend>> AirExt for A {}
Expand Down Expand Up @@ -180,6 +195,39 @@ impl<B: Backend> ComponentVisitor<B> for MaskPointsEvaluator {
}
}

struct QuotientLogBoundsVisitor {
bounds: BTreeSet<u32>,
}

impl QuotientLogBoundsVisitor {
pub fn new() -> Self {
Self {
bounds: BTreeSet::new(),
}
}

pub fn finalize(self) -> Vec<u32> {
self.bounds.into_iter().collect()
}
}

impl<B: Backend> ComponentVisitor<B> for QuotientLogBoundsVisitor {
fn visit<C: Component<B>>(&mut self, component: &C) {
let bounds = zip(
component.mask().iter(),
&component.trace_log_degree_bounds(),
)
.flat_map(|(trace_points, trace_bound)| {
trace_points
.iter()
.map(|_| *trace_bound)
.collect::<Vec<_>>()
})
.collect_vec();
self.bounds.extend(bounds);
}
}

/// Holds the mask offsets at each column.
/// Holds a vector with an entry for each column. Each entry holds the offsets
/// of the mask at that column.
Expand Down
19 changes: 0 additions & 19 deletions src/core/oods.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
use std::iter::zip;

use itertools::enumerate;

use super::air::Component;
use super::backend::cpu::CPUCircleEvaluation;
use super::backend::Backend;
use super::circle::CirclePoint;
use super::constraints::{complex_conjugate_line, pair_vanishing, point_vanishing};
use super::fields::m31::BaseField;
use super::fields::qm31::SecureField;
use super::fields::ComplexConjugate;
use super::fri::CirclePolyDegreeBound;
use super::poly::circle::CircleEvaluation;
use super::poly::{BitReversedOrder, NaturalOrder};
use super::utils::bit_reverse_index;
Expand Down Expand Up @@ -81,17 +76,3 @@ pub fn get_pair_oods_quotient(
}
CircleEvaluation::new(eval.domain, values)
}

pub fn quotient_log_bounds<B: Backend>(component: impl Component<B>) -> Vec<CirclePolyDegreeBound> {
zip(
component.mask().iter(),
&component.trace_log_degree_bounds(),
)
.flat_map(|(trace_points, trace_bound)| {
trace_points
.iter()
.map(|_| CirclePolyDegreeBound::new(*trace_bound))
.collect::<Vec<_>>()
})
.collect()
}
11 changes: 3 additions & 8 deletions src/fibonacci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ use crate::core::commitment_scheme::{CommitmentSchemeProver, CommitmentSchemeVer
use crate::core::fields::m31::BaseField;
use crate::core::fields::qm31::SecureField;
use crate::core::fields::{Field, IntoSlice};
use crate::core::fri::{
CirclePolyDegreeBound, FriConfig, FriProof, FriProver, FriVerifier, SparseCircleEvaluation,
};
use crate::core::oods::{get_oods_quotient, get_pair_oods_quotient, quotient_log_bounds};
use crate::core::fri::{FriConfig, FriProof, FriProver, FriVerifier, SparseCircleEvaluation};
use crate::core::oods::{get_oods_quotient, get_pair_oods_quotient};
use crate::core::poly::circle::{CanonicCoset, CircleEvaluation};
use crate::core::poly::BitReversedOrder;
use crate::core::proof_of_work::{ProofOfWork, ProofOfWorkProof};
Expand Down Expand Up @@ -213,10 +211,7 @@ pub fn verify_proof<const N_BITS: u32>(proof: FibonacciProof) -> bool {
);

// TODO(AlonH): Get bounds from air.
let mut bounds = vec![CirclePolyDegreeBound::new(
fib.air.max_constraint_log_degree_bound(),
)];
bounds.append(&mut quotient_log_bounds(fib.air.component));
let bounds = fib.air.quotient_log_bounds();
let fri_config = FriConfig::new(LOG_LAST_LAYER_DEGREE_BOUND, LOG_BLOWUP_FACTOR, N_QUERIES);
let mut fri_verifier =
FriVerifier::commit(channel, fri_config, proof.fri_proof, bounds).unwrap();
Expand Down

0 comments on commit a3ffbf4

Please sign in to comment.