Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create QuotientLogBoundsVisitor. #407

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/air/evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,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::BTreeMap;
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,20 @@ 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();
// Add the composition polynomial's log degree bound.
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 +196,38 @@ impl<B: Backend> ComponentVisitor<B> for MaskPointsEvaluator {
}
}

struct QuotientLogBoundsVisitor {
// Maps the log degree bound to the number of quotients with that bound.
bounds: BTreeMap<u32, usize>,
}

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

pub fn finalize(self) -> Vec<u32> {
self.bounds
.into_iter()
.flat_map(|(bound, n)| (0..n).map(|_| bound).collect_vec())
.collect()
}
}

impl<B: Backend> ComponentVisitor<B> for QuotientLogBoundsVisitor {
fn visit<C: Component<B>>(&mut self, component: &C) {
for (mask_points, trace_bound) in zip(
component.mask().iter(),
&component.trace_log_degree_bounds(),
) {
let n = self.bounds.entry(*trace_bound);
*n.or_default() += mask_points.len();
}
}
}

/// 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()
}
12 changes: 3 additions & 9 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 @@ -212,11 +210,7 @@ pub fn verify_proof<const N_BITS: u32>(proof: FibonacciProof) -> bool {
random_coeff,
);

// 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
Loading