diff --git a/air/src/air/context.rs b/air/src/air/context.rs index f97e231da..e643b5dcb 100644 --- a/air/src/air/context.rs +++ b/air/src/air/context.rs @@ -17,8 +17,8 @@ use crate::{air::TransitionConstraintDegree, ProofOptions, TraceInfo}; pub struct AirContext { pub(super) options: ProofOptions, pub(super) trace_info: TraceInfo, - pub(super) main_transition_constraint_degrees: Vec, - pub(super) aux_transition_constraint_degrees: Vec, + 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, @@ -49,6 +49,8 @@ impl AirContext { pub fn new( trace_info: TraceInfo, transition_constraint_degrees: Vec, + num_main_transition_constraints: usize, + num_aux_transition_constraints: usize, num_assertions: usize, options: ProofOptions, ) -> Self { @@ -60,6 +62,8 @@ impl AirContext { trace_info, transition_constraint_degrees, Vec::new(), + num_main_transition_constraints, + num_aux_transition_constraints, num_assertions, 0, None, @@ -93,6 +97,8 @@ impl AirContext { trace_info: TraceInfo, main_transition_constraint_degrees: Vec, aux_transition_constraint_degrees: Vec, + num_main_transition_constraints: usize, + num_aux_transition_constraints: usize, num_main_assertions: usize, num_aux_assertions: usize, lagrange_kernel_aux_column_idx: Option, @@ -161,8 +167,6 @@ impl AirContext { AirContext { options, trace_info, - main_transition_constraint_degrees, - aux_transition_constraint_degrees, num_main_assertions, num_aux_assertions, lagrange_kernel_aux_column_idx, @@ -170,6 +174,8 @@ impl AirContext { 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, } } @@ -217,17 +223,17 @@ impl AirContext { /// 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 @@ -283,24 +289,16 @@ impl AirContext { /// 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) } @@ -332,19 +330,6 @@ impl AirContext { // 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 diff --git a/air/src/air/mod.rs b/air/src/air/mod.rs index 53a59fa5a..6e3eaa9dd 100644 --- a/air/src/air/mod.rs +++ b/air/src/air/mod.rs @@ -536,7 +536,7 @@ pub trait Air: Send + Sync { R: RandomCoin, { let mut t_coefficients = Vec::new(); - for _ in 0..self.context().num_transition_constraints() { + for _ in 0..10 { t_coefficients.push(public_coin.draw()?); } diff --git a/air/src/air/tests.rs b/air/src/air/tests.rs index e0063ed3b..048296b6e 100644 --- a/air/src/air/tests.rs +++ b/air/src/air/tests.rs @@ -270,7 +270,7 @@ pub fn build_context( 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> { diff --git a/air/src/air/transition/mod.rs b/air/src/air/transition/mod.rs index 60e641817..2d6a58e10 100644 --- a/air/src/air/transition/mod.rs +++ b/air/src/air/transition/mod.rs @@ -31,9 +31,7 @@ const MIN_CYCLE_LENGTH: usize = 2; /// - Divisor of transition constraints for a computation. pub struct TransitionConstraints { main_constraint_coef: Vec, - main_constraint_degrees: Vec, aux_constraint_coef: Vec, - aux_constraint_degrees: Vec, divisor: ConstraintDivisor, } @@ -47,11 +45,6 @@ impl TransitionConstraints { /// Panics if the number of transition constraints in the context does not match the number of /// provided composition coefficients. pub fn new(context: &AirContext, 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( @@ -59,16 +52,11 @@ impl TransitionConstraints { 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, } } @@ -76,19 +64,9 @@ impl TransitionConstraints { // 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 @@ -97,19 +75,10 @@ impl TransitionConstraints { 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 diff --git a/examples/src/fibonacci/fib2/air.rs b/examples/src/fibonacci/fib2/air.rs index 9e5d75a48..cf908ca9e 100644 --- a/examples/src/fibonacci/fib2/air.rs +++ b/examples/src/fibonacci/fib2/air.rs @@ -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, } } diff --git a/examples/src/fibonacci/fib8/air.rs b/examples/src/fibonacci/fib8/air.rs index 4d7aef9ba..a04b33e24 100644 --- a/examples/src/fibonacci/fib8/air.rs +++ b/examples/src/fibonacci/fib8/air.rs @@ -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, } } diff --git a/examples/src/fibonacci/fib_small/air.rs b/examples/src/fibonacci/fib_small/air.rs index 66580c872..c4752856e 100644 --- a/examples/src/fibonacci/fib_small/air.rs +++ b/examples/src/fibonacci/fib_small/air.rs @@ -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, } } diff --git a/examples/src/fibonacci/mulfib2/air.rs b/examples/src/fibonacci/mulfib2/air.rs index 3190d2e41..8f6e99aea 100644 --- a/examples/src/fibonacci/mulfib2/air.rs +++ b/examples/src/fibonacci/mulfib2/air.rs @@ -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, } } diff --git a/examples/src/fibonacci/mulfib8/air.rs b/examples/src/fibonacci/mulfib8/air.rs index bbbe1dea0..715f707ee 100644 --- a/examples/src/fibonacci/mulfib8/air.rs +++ b/examples/src/fibonacci/mulfib8/air.rs @@ -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, } } diff --git a/examples/src/lib.rs b/examples/src/lib.rs index 33f733d7c..43cb051db 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -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; diff --git a/examples/src/main.rs b/examples/src/main.rs index 36c1e0c0d..ef9c2e788 100644 --- a/examples/src/main.rs +++ b/examples/src/main.rs @@ -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")] @@ -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."); diff --git a/prover/src/constraints/evaluation_table.rs b/prover/src/constraints/evaluation_table.rs index 08c9167f2..55a006799 100644 --- a/prover/src/constraints/evaluation_table.rs +++ b/prover/src/constraints/evaluation_table.rs @@ -33,8 +33,6 @@ pub struct ConstraintEvaluationTable<'a, E: FieldElement> { main_transition_evaluations: Vec>, #[cfg(debug_assertions)] aux_transition_evaluations: Vec>, - #[cfg(debug_assertions)] - expected_transition_degrees: Vec, } impl<'a, E: FieldElement> ConstraintEvaluationTable<'a, E> { @@ -70,18 +68,12 @@ impl<'a, E: FieldElement> ConstraintEvaluationTable<'a, E> { let num_tm_columns = transition_constraints.num_main_constraints(); let num_ta_columns = transition_constraints.num_aux_constraints(); - // collect expected degrees for all transition constraints to compare them against actual - // degrees; we do this in debug mode only because this comparison is expensive - let expected_transition_degrees = - build_transition_constraint_degrees(transition_constraints, domain.trace_length()); - ConstraintEvaluationTable { evaluations: uninit_matrix(num_columns, num_rows), divisors, domain, main_transition_evaluations: uninit_matrix(num_tm_columns, num_rows), aux_transition_evaluations: uninit_matrix(num_ta_columns, num_rows), - expected_transition_degrees, } } @@ -192,33 +184,21 @@ impl<'a, E: FieldElement> ConstraintEvaluationTable<'a, E> { // collect actual degrees for all transition constraints by interpolating saved // constraint evaluations into polynomials and checking their degree; also // determine max transition constraint degree - let mut actual_degrees = Vec::with_capacity(self.expected_transition_degrees.len()); - let mut max_degree = 0; + let mut max_degree = 0; let inv_twiddles = fft::get_inv_twiddles::(self.num_rows()); // first process transition constraint evaluations for the main trace segment for evaluations in self.main_transition_evaluations.iter() { let degree = get_transition_poly_degree(evaluations, &inv_twiddles, &div_values); - actual_degrees.push(degree); max_degree = core::cmp::max(max_degree, degree); } // then process transition constraint evaluations for the auxiliary trace segment for evaluations in self.aux_transition_evaluations.iter() { let degree = get_transition_poly_degree(evaluations, &inv_twiddles, &div_values); - actual_degrees.push(degree); max_degree = core::cmp::max(max_degree, degree); } - // make sure the actual degrees are less than or equal to the expected degree bounds - assert!( - self.expected_transition_degrees >= actual_degrees, - "transition constraint degrees do not satisfy the expected degree bounds - \nexpected degree bounds: {:>3?}\nactual degrees: {:>3?}", - self.expected_transition_degrees, - actual_degrees - ); - // make sure evaluation domain size does not exceed the size required by max degree let expected_domain_size = core::cmp::max(max_degree, self.domain.trace_length() + 1).next_power_of_two(); @@ -419,23 +399,7 @@ fn get_inv_evaluation( /// /// The general idea is that evaluation degree is the degree of rational function `C(x) / z(x)`, /// where `C(x)` is the constraint polynomial and `z(x)` is the divisor polynomial. -#[cfg(debug_assertions)] -fn build_transition_constraint_degrees( - constraints: &TransitionConstraints, - trace_length: usize, -) -> Vec { - let mut result = Vec::new(); - - for degree in constraints.main_constraint_degrees() { - result.push(degree.get_evaluation_degree(trace_length) - constraints.divisor().degree()) - } - - for degree in constraints.aux_constraint_degrees() { - result.push(degree.get_evaluation_degree(trace_length) - constraints.divisor().degree()) - } - result -} /// Computes the actual degree of a transition polynomial described by the provided evaluations. /// diff --git a/prover/src/tests/mod.rs b/prover/src/tests/mod.rs index 6b44fa0e9..c19bd27b3 100644 --- a/prover/src/tests/mod.rs +++ b/prover/src/tests/mod.rs @@ -118,5 +118,5 @@ fn build_context( ) -> AirContext { let options = ProofOptions::new(32, blowup_factor, 0, FieldExtension::None, 4, 31); let t_degrees = vec![TransitionConstraintDegree::new(2)]; - AirContext::new(trace_info, t_degrees, num_assertions, options) + AirContext::new(trace_info, t_degrees, 1, 0, num_assertions, options) } diff --git a/winterfell/src/tests.rs b/winterfell/src/tests.rs index 3757e2010..1a1c15ad0 100644 --- a/winterfell/src/tests.rs +++ b/winterfell/src/tests.rs @@ -138,6 +138,8 @@ impl Air for LagrangeKernelComplexAir { vec![TransitionConstraintDegree::new(1)], 1, 1, + 1, + 1, Some(1), options, ),