Skip to content

Commit

Permalink
Move max_constraint_log_degree_bound to AirExt trait.
Browse files Browse the repository at this point in the history
  • Loading branch information
alonh5 committed Feb 21, 2024
1 parent fa0ee8d commit 48e82ad
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
29 changes: 27 additions & 2 deletions src/core/air/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ pub mod evaluation;
// TODO(spapini): consider renaming this struct.
pub trait Air {
fn visit_components<V: ComponentVisitor>(&self, v: &mut V);

fn max_constraint_log_degree_bound(&self) -> u32;
}

pub trait AirExt: Air {
fn max_constraint_log_degree_bound(&self) -> u32 {
let mut visitor = MaxConstraintLogDegreeBoundVisitor::new();
self.visit_components(&mut visitor);
visitor.finalize()
}

fn compute_composition_polynomial(
&self,
random_coeff: SecureField,
Expand All @@ -46,6 +50,27 @@ pub trait ComponentVisitor {
fn visit<C: Component>(&mut self, component: &C);
}

struct MaxConstraintLogDegreeBoundVisitor(u32);

impl MaxConstraintLogDegreeBoundVisitor {
pub fn new() -> Self {
Self(0)
}

pub fn finalize(self) -> u32 {
self.0
}
}

impl ComponentVisitor for MaxConstraintLogDegreeBoundVisitor {
fn visit<C: Component>(&mut self, component: &C) {
let bound = component.max_constraint_log_degree_bound();
if bound > self.0 {
self.0 = bound;
}
}
}

/// 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
6 changes: 1 addition & 5 deletions src/fibonacci/air.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::component::FibonacciComponent;
use crate::core::air::{Air, Component, ComponentVisitor};
use crate::core::air::{Air, ComponentVisitor};

pub struct FibonacciAir {
pub component: FibonacciComponent,
Expand All @@ -15,8 +15,4 @@ impl Air for FibonacciAir {
fn visit_components<V: ComponentVisitor>(&self, v: &mut V) {
v.visit(&self.component);
}

fn max_constraint_log_degree_bound(&self) -> u32 {
self.component.max_constraint_log_degree_bound()
}
}
4 changes: 2 additions & 2 deletions src/fibonacci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::commitment_scheme::blake2_hash::Blake2sHasher;
use crate::commitment_scheme::hasher::Hasher;
use crate::commitment_scheme::merkle_decommitment::MerkleDecommitment;
use crate::core::air::evaluation::PointEvaluationAccumulator;
use crate::core::air::{Air, AirExt, Component, ComponentTrace};
use crate::core::air::{AirExt, Component, ComponentTrace};
use crate::core::channel::{Blake2sChannel, Channel as ChannelTrait};
use crate::core::circle::CirclePoint;
use crate::core::commitment_scheme::{CommitmentSchemeProver, CommitmentSchemeVerifier};
Expand Down Expand Up @@ -300,7 +300,7 @@ mod tests {
use super::Fibonacci;
use crate::commitment_scheme::utils::tests::generate_test_queries;
use crate::core::air::evaluation::PointEvaluationAccumulator;
use crate::core::air::{Air, AirExt, Component, ComponentTrace};
use crate::core::air::{AirExt, Component, ComponentTrace};
use crate::core::circle::CirclePoint;
use crate::core::fields::m31::{BaseField, M31};
use crate::core::fields::qm31::SecureField;
Expand Down

0 comments on commit 48e82ad

Please sign in to comment.