Skip to content

Commit

Permalink
wip: remove constraint degrees
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Kindi-0 committed Sep 4, 2024
1 parent a0a597e commit 536a5be
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 141 deletions.
53 changes: 19 additions & 34 deletions air/src/air/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use crate::{air::TransitionConstraintDegree, ProofOptions, TraceInfo};
pub struct AirContext<B: StarkField> {
pub(super) options: ProofOptions,
pub(super) trace_info: TraceInfo,
pub(super) main_transition_constraint_degrees: Vec<TransitionConstraintDegree>,
pub(super) aux_transition_constraint_degrees: Vec<TransitionConstraintDegree>,
pub(super) num_main_transition_constraints: usize,
pub(super) num_aux_transition_constraints: usize,
pub(super) num_main_assertions: usize,
pub(super) num_aux_assertions: usize,
pub(super) lagrange_kernel_aux_column_idx: Option<usize>,
Expand Down Expand Up @@ -49,6 +49,8 @@ impl<B: StarkField> AirContext<B> {
pub fn new(
trace_info: TraceInfo,
transition_constraint_degrees: Vec<TransitionConstraintDegree>,
num_main_transition_constraints: usize,
num_aux_transition_constraints: usize,
num_assertions: usize,
options: ProofOptions,
) -> Self {
Expand All @@ -60,6 +62,8 @@ impl<B: StarkField> AirContext<B> {
trace_info,
transition_constraint_degrees,
Vec::new(),
num_main_transition_constraints,
num_aux_transition_constraints,
num_assertions,
0,
None,
Expand Down Expand Up @@ -93,6 +97,8 @@ impl<B: StarkField> AirContext<B> {
trace_info: TraceInfo,
main_transition_constraint_degrees: Vec<TransitionConstraintDegree>,
aux_transition_constraint_degrees: Vec<TransitionConstraintDegree>,
num_main_transition_constraints: usize,
num_aux_transition_constraints: usize,
num_main_assertions: usize,
num_aux_assertions: usize,
lagrange_kernel_aux_column_idx: Option<usize>,
Expand Down Expand Up @@ -161,15 +167,15 @@ impl<B: StarkField> AirContext<B> {
AirContext {
options,
trace_info,
main_transition_constraint_degrees,
aux_transition_constraint_degrees,
num_main_assertions,
num_aux_assertions,
lagrange_kernel_aux_column_idx,
ce_blowup_factor,
trace_domain_generator: B::get_root_of_unity(trace_length.ilog2()),
lde_domain_generator: B::get_root_of_unity(lde_domain_size.ilog2()),
num_transition_exemptions: 1,
num_main_transition_constraints,
num_aux_transition_constraints,
}
}

Expand Down Expand Up @@ -217,17 +223,17 @@ impl<B: StarkField> AirContext<B> {
/// used to determine how many transition constraint coefficients need to be generated for
/// merging transition constraints into a constraint composition polynomial.
pub fn num_transition_constraints(&self) -> usize {
self.main_transition_constraint_degrees.len() + self.aux_transition_constraint_degrees.len()
self.num_main_transition_constraints + self.num_aux_transition_constraints
}

/// Returns the number of transition constraints placed against the main trace segment.
pub fn num_main_transition_constraints(&self) -> usize {
self.main_transition_constraint_degrees.len()
self.num_main_transition_constraints
}

/// Returns the number of transition constraints placed against the auxiliary trace segment.
pub fn num_aux_transition_constraints(&self) -> usize {
self.aux_transition_constraint_degrees.len()
self.num_aux_transition_constraints
}

/// Returns the index of the auxiliary column which implements the Lagrange kernel, if any
Expand Down Expand Up @@ -283,24 +289,16 @@ impl<B: StarkField> AirContext<B> {
/// be at most `trace_len - 1`.
pub fn num_constraint_composition_columns(&self) -> usize {
let mut highest_constraint_degree = 0_usize;
for degree in self
.main_transition_constraint_degrees
.iter()
.chain(self.aux_transition_constraint_degrees.iter())
{
let eval_degree = degree.get_evaluation_degree(self.trace_len());
if eval_degree > highest_constraint_degree {
highest_constraint_degree = eval_degree
}
}

let trace_length = self.trace_len();
let transition_divisior_degree = trace_length - self.num_transition_exemptions();

// we use the identity: ceil(a/b) = (a + b - 1)/b
let num_constraint_col =
(highest_constraint_degree - transition_divisior_degree + trace_length - 1)
/ trace_length;
//// we use the identity: ceil(a/b) = (a + b - 1)/b
//let num_constraint_col =
//(highest_constraint_degree - transition_divisior_degree + trace_length - 1)
/// trace_length;

let num_constraint_col = 1;
cmp::max(num_constraint_col, 1)
}

Expand Down Expand Up @@ -332,19 +330,6 @@ impl<B: StarkField> AirContext<B> {
// degree of the divisor which results in an increase of the resulting constraint composition
// polynomial.Thus we need to check that the number of exemption points is not too large
// given the above.
for degree in self
.main_transition_constraint_degrees
.iter()
.chain(self.aux_transition_constraint_degrees.iter())
{
let eval_degree = degree.get_evaluation_degree(self.trace_len());
let max_constraint_composition_degree = self.ce_domain_size() - 1;
let max_exemptions = max_constraint_composition_degree + self.trace_len() - eval_degree;
assert!(
n <= max_exemptions,
"number of transition exemptions cannot exceed: {max_exemptions}, but was {n}"
)
}

self.num_transition_exemptions = n;
self
Expand Down
2 changes: 1 addition & 1 deletion air/src/air/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ pub trait Air: Send + Sync {
R: RandomCoin<BaseField = Self::BaseField>,
{
let mut t_coefficients = Vec::new();
for _ in 0..self.context().num_transition_constraints() {
for _ in 0..10 {
t_coefficients.push(public_coin.draw()?);
}

Expand Down
2 changes: 1 addition & 1 deletion air/src/air/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ pub fn build_context<B: StarkField>(
let options = ProofOptions::new(32, 8, 0, FieldExtension::None, 4, 31);
let t_degrees = vec![TransitionConstraintDegree::new(2)];
let trace_info = TraceInfo::new(trace_width, trace_length);
AirContext::new(trace_info, t_degrees, num_assertions, options)
AirContext::new(trace_info, t_degrees, 1, 0, num_assertions, options)
}

pub fn build_prng() -> DefaultRandomCoin<Blake3_256<BaseElement>> {
Expand Down
37 changes: 3 additions & 34 deletions air/src/air/transition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ const MIN_CYCLE_LENGTH: usize = 2;
/// - Divisor of transition constraints for a computation.
pub struct TransitionConstraints<E: FieldElement> {
main_constraint_coef: Vec<E>,
main_constraint_degrees: Vec<TransitionConstraintDegree>,
aux_constraint_coef: Vec<E>,
aux_constraint_degrees: Vec<TransitionConstraintDegree>,
divisor: ConstraintDivisor<E::BaseField>,
}

Expand All @@ -47,48 +45,28 @@ impl<E: FieldElement> TransitionConstraints<E> {
/// Panics if the number of transition constraints in the context does not match the number of
/// provided composition coefficients.
pub fn new(context: &AirContext<E::BaseField>, composition_coefficients: &[E]) -> Self {
assert_eq!(
context.num_transition_constraints(),
composition_coefficients.len(),
"number of transition constraints must match the number of composition coefficient tuples"
);

// build constraint divisor; the same divisor applies to all transition constraints
let divisor = ConstraintDivisor::from_transition(
context.trace_len(),
context.num_transition_exemptions(),
);

let main_constraint_degrees = context.main_transition_constraint_degrees.clone();
let aux_constraint_degrees = context.aux_transition_constraint_degrees.clone();

let (main_constraint_coef, aux_constraint_coef) =
composition_coefficients.split_at(context.main_transition_constraint_degrees.len());
composition_coefficients.split_at(context.num_main_transition_constraints);
Self {
main_constraint_coef: main_constraint_coef.to_vec(),
main_constraint_degrees,
aux_constraint_coef: aux_constraint_coef.to_vec(),
aux_constraint_degrees,
divisor,
}
}

// PUBLIC ACCESSORS
// --------------------------------------------------------------------------------------------

/// Returns a list of transition constraint degree descriptors for the main trace segment of
/// a computation.
///
/// This list will be identical to the list passed into the [AirContext::new()] method as
/// the `transition_constraint_degrees` parameter, or into [AirContext::new_multi_segment()]
/// as the `main_transition_constraint_degrees` parameter.
pub fn main_constraint_degrees(&self) -> &[TransitionConstraintDegree] {
&self.main_constraint_degrees
}

/// Returns the number of constraints applied against the main trace segment of a computation.
pub fn num_main_constraints(&self) -> usize {
self.main_constraint_degrees.len()
self.main_constraint_coef.len()
}

/// Returns the random coefficients for constraints applied against main trace segment of a
Expand All @@ -97,19 +75,10 @@ impl<E: FieldElement> TransitionConstraints<E> {
self.main_constraint_coef.clone()
}

/// Returns a list of transition constraint degree descriptors for the auxiliary trace segment of
/// a computation.
///
/// This list will be identical to the list passed into [AirContext::new_multi_segment()]
/// as the `aux_transition_constraint_degrees` parameter.
pub fn aux_constraint_degrees(&self) -> &[TransitionConstraintDegree] {
&self.aux_constraint_degrees
}

/// Returns the number of constraints applied against the auxiliary trace segment of a
/// computation.
pub fn num_aux_constraints(&self) -> usize {
self.aux_constraint_degrees.len()
self.aux_constraint_coef.len()
}

/// Returns the random coefficients for constraints applied against the auxiliary trace segment of a
Expand Down
2 changes: 1 addition & 1 deletion examples/src/fibonacci/fib2/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Air for FibAir {
let degrees = vec![TransitionConstraintDegree::new(1), TransitionConstraintDegree::new(1)];
assert_eq!(TRACE_WIDTH, trace_info.width());
FibAir {
context: AirContext::new(trace_info, degrees, 3, options),
context: AirContext::new(trace_info, degrees, 2, 0, 3, options),
result: pub_inputs,
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/src/fibonacci/fib8/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Air for Fib8Air {
let degrees = vec![TransitionConstraintDegree::new(1), TransitionConstraintDegree::new(1)];
assert_eq!(TRACE_WIDTH, trace_info.width());
Fib8Air {
context: AirContext::new(trace_info, degrees, 3, options),
context: AirContext::new(trace_info, degrees, 2, 0, 3, options),
result: pub_inputs,
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/src/fibonacci/fib_small/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Air for FibSmall {
let degrees = vec![TransitionConstraintDegree::new(1), TransitionConstraintDegree::new(1)];
assert_eq!(TRACE_WIDTH, trace_info.width());
FibSmall {
context: AirContext::new(trace_info, degrees, 3, options),
context: AirContext::new(trace_info, degrees, 2, 0, 3, options),
result: pub_inputs,
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/src/fibonacci/mulfib2/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Air for MulFib2Air {
let degrees = vec![TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(2)];
assert_eq!(TRACE_WIDTH, trace_info.width());
MulFib2Air {
context: AirContext::new(trace_info, degrees, 3, options),
context: AirContext::new(trace_info, degrees, 2, 0, 3, options),
result: pub_inputs,
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/src/fibonacci/mulfib8/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Air for MulFib8Air {
];
assert_eq!(TRACE_WIDTH, trace_info.width());
MulFib8Air {
context: AirContext::new(trace_info, degrees, 3, options),
context: AirContext::new(trace_info, degrees, 8, 0, 3, options),
result: pub_inputs,
}
}
Expand Down
16 changes: 8 additions & 8 deletions examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use winterfell::{
};

pub mod fibonacci;
#[cfg(feature = "std")]
pub mod lamport;
#[cfg(feature = "std")]
pub mod merkle;
pub mod rescue;
#[cfg(feature = "std")]
pub mod rescue_raps;
//#[cfg(feature = "std")]
//pub mod lamport;
//#[cfg(feature = "std")]
//pub mod merkle;
//pub mod rescue;
//#[cfg(feature = "std")]
//pub mod rescue_raps;
pub mod utils;
pub mod vdf;
//pub mod vdf;

#[cfg(test)]
mod tests;
Expand Down
44 changes: 24 additions & 20 deletions examples/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

use std::time::Instant;

use examples::{fibonacci, rescue, vdf, ExampleOptions, ExampleType};
#[cfg(feature = "std")]
use examples::{lamport, merkle, rescue_raps};
//use examples::{fibonacci, rescue, vdf, ExampleOptions, ExampleType};
//#[cfg(feature = "std")]
//use examples::{lamport, merkle, rescue_raps};
use examples::{ fibonacci, ExampleOptions, ExampleType};
use structopt::StructOpt;
use tracing::info_span;
#[cfg(feature = "tracing-forest")]
Expand Down Expand Up @@ -65,23 +66,26 @@ fn main() {
ExampleType::FibSmall { sequence_length } => {
fibonacci::fib_small::get_example(&options, sequence_length)
},
ExampleType::Vdf { num_steps } => vdf::regular::get_example(&options, num_steps),
ExampleType::VdfExempt { num_steps } => vdf::exempt::get_example(&options, num_steps),
ExampleType::Rescue { chain_length } => rescue::get_example(&options, chain_length),
#[cfg(feature = "std")]
ExampleType::RescueRaps { chain_length } => {
rescue_raps::get_example(&options, chain_length)
},
#[cfg(feature = "std")]
ExampleType::Merkle { tree_depth } => merkle::get_example(&options, tree_depth),
#[cfg(feature = "std")]
ExampleType::LamportA { num_signatures } => {
lamport::aggregate::get_example(&options, num_signatures)
},
#[cfg(feature = "std")]
ExampleType::LamportT { num_signers } => {
lamport::threshold::get_example(&options, num_signers)
},

_ => todo!()

//ExampleType::Vdf { num_steps } => vdf::regular::get_example(&options, num_steps),
//ExampleType::VdfExempt { num_steps } => vdf::exempt::get_example(&options, num_steps),
//ExampleType::Rescue { chain_length } => rescue::get_example(&options, chain_length),
//#[cfg(feature = "std")]
//ExampleType::RescueRaps { chain_length } => {
//rescue_raps::get_example(&options, chain_length)
//},
//#[cfg(feature = "std")]
//ExampleType::Merkle { tree_depth } => merkle::get_example(&options, tree_depth),
//#[cfg(feature = "std")]
//ExampleType::LamportA { num_signatures } => {
//lamport::aggregate::get_example(&options, num_signatures)
//},
//#[cfg(feature = "std")]
//ExampleType::LamportT { num_signers } => {
//lamport::threshold::get_example(&options, num_signers)
//},
}
.expect("The example failed to initialize.");

Expand Down
Loading

0 comments on commit 536a5be

Please sign in to comment.