diff --git a/air/src/air/context.rs b/air/src/air/context.rs index e643b5dcb..e9b2fe1a0 100644 --- a/air/src/air/context.rs +++ b/air/src/air/context.rs @@ -3,12 +3,11 @@ // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. -use alloc::vec::Vec; use core::cmp; use math::StarkField; -use crate::{air::TransitionConstraintDegree, ProofOptions, TraceInfo}; +use crate::{ProofOptions, TraceInfo}; // AIR CONTEXT // ================================================================================================ @@ -22,7 +21,7 @@ pub struct AirContext { pub(super) num_main_assertions: usize, pub(super) num_aux_assertions: usize, pub(super) lagrange_kernel_aux_column_idx: Option, - pub(super) ce_blowup_factor: usize, + pub(super) max_degree: usize, pub(super) trace_domain_generator: B, pub(super) lde_domain_generator: B, pub(super) num_transition_exemptions: usize, @@ -34,23 +33,17 @@ impl AirContext { /// Returns a new instance of [AirContext] instantiated for computations which require a single /// execution trace segment. /// - /// The list of transition constraint degrees defines the total number of transition - /// constraints and their expected degrees. Constraint evaluations computed by - /// [Air::evaluate_transition()](crate::Air::evaluate_transition) function are expected to be - /// in the order defined by this list. - /// /// # Panics /// Panics if - /// * `transition_constraint_degrees` is an empty vector. + /// * `num_main_transition_constraints` is zero. /// * `num_assertions` is zero. /// * Blowup factor specified by the provided `options` is too small to accommodate degrees /// of the specified transition constraints. /// * `trace_info` describes a multi-segment execution trace. pub fn new( trace_info: TraceInfo, - transition_constraint_degrees: Vec, + max_degree: usize, num_main_transition_constraints: usize, - num_aux_transition_constraints: usize, num_assertions: usize, options: ProofOptions, ) -> Self { @@ -60,10 +53,9 @@ impl AirContext { ); Self::new_multi_segment( trace_info, - transition_constraint_degrees, - Vec::new(), + max_degree, num_main_transition_constraints, - num_aux_transition_constraints, + 0, num_assertions, 0, None, @@ -74,29 +66,20 @@ impl AirContext { /// Returns a new instance of [AirContext] instantiated for computations which require multiple /// execution trace segments. /// - /// The lists of transition constraint degrees defines the total number of transition - /// constraints and their expected degrees. Constraint evaluations computed by - /// [Air::evaluate_transition()](crate::Air::evaluate_transition) function are expected to be - /// in the order defined by `main_transition_constraint_degrees` list. Constraint evaluations - /// computed by [Air::evaluate_aux_transition()](crate::Air::evaluate_aux_transition) function - /// are expected to be in the order defined by `aux_transition_constraint_degrees` list. - /// /// # Panics /// Panics if - /// * `main_transition_constraint_degrees` is an empty vector. /// * `num_main_assertions` is zero. /// * `trace_info.is_multi_segment() == true` but: - /// - `aux_transition_constraint_degrees` is an empty vector. + /// - `num_aux_transition_constraints` is zero. /// - `num_aux_assertions` is zero. /// * `trace_info.is_multi_segment() == false` but: - /// - `aux_transition_constraint_degrees` is a non-empty vector. + /// - `num_aux_transition_constraints` is non-zero. /// - `num_aux_assertions` is greater than zero. - /// * Blowup factor specified by the provided `options` is too small to accommodate degrees - /// of the specified transition constraints. + /// * Blowup factor specified by the provided `options` is too small to accommodate max degree + /// of the transition constraints. pub fn new_multi_segment( trace_info: TraceInfo, - main_transition_constraint_degrees: Vec, - aux_transition_constraint_degrees: Vec, + max_degree: usize, num_main_transition_constraints: usize, num_aux_transition_constraints: usize, num_main_assertions: usize, @@ -105,14 +88,14 @@ impl AirContext { options: ProofOptions, ) -> Self { assert!( - !main_transition_constraint_degrees.is_empty(), + num_main_transition_constraints > 0, "at least one transition constraint degree must be specified" ); assert!(num_main_assertions > 0, "at least one assertion must be specified"); if trace_info.is_multi_segment() { assert!( - !aux_transition_constraint_degrees.is_empty(), + num_aux_transition_constraints > 0, "at least one transition constraint degree must be specified for the auxiliary trace segment" ); assert!( @@ -121,7 +104,7 @@ impl AirContext { ); } else { assert!( - aux_transition_constraint_degrees.is_empty(), + num_aux_transition_constraints == 0, "auxiliary transition constraint degrees specified for a single-segment trace" ); assert!( @@ -139,25 +122,10 @@ impl AirContext { ); } - // determine minimum blowup factor needed to evaluate transition constraints by taking - // the blowup factor of the highest degree constraint - let mut ce_blowup_factor = 0; - for degree in main_transition_constraint_degrees.iter() { - if degree.min_blowup_factor() > ce_blowup_factor { - ce_blowup_factor = degree.min_blowup_factor(); - } - } - - for degree in aux_transition_constraint_degrees.iter() { - if degree.min_blowup_factor() > ce_blowup_factor { - ce_blowup_factor = degree.min_blowup_factor(); - } - } - assert!( - options.blowup_factor() >= ce_blowup_factor, + options.blowup_factor() >= max_degree, "blowup factor too small; expected at least {}, but was {}", - ce_blowup_factor, + max_degree, options.blowup_factor() ); @@ -170,7 +138,7 @@ impl AirContext { num_main_assertions, num_aux_assertions, lagrange_kernel_aux_column_idx, - ce_blowup_factor, + max_degree, 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, @@ -205,7 +173,7 @@ impl AirContext { /// /// This is guaranteed to be a power of two, and is equal to `trace_length * ce_blowup_factor`. pub fn ce_domain_size(&self) -> usize { - self.trace_info.length() * self.ce_blowup_factor + self.trace_info.length() * self.num_constraint_composition_columns() } /// Returns the size of the low-degree extension domain. @@ -288,18 +256,7 @@ impl AirContext { /// Hence, no matter what the degree of the divisor is for each, the degree of the fraction will /// be at most `trace_len - 1`. pub fn num_constraint_composition_columns(&self) -> usize { - let mut highest_constraint_degree = 0_usize; - - 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; - - let num_constraint_col = 1; - cmp::max(num_constraint_col, 1) + cmp::max(self.max_degree, 1) } // DATA MUTATORS diff --git a/air/src/air/mod.rs b/air/src/air/mod.rs index 6e3eaa9dd..5c10fe2fc 100644 --- a/air/src/air/mod.rs +++ b/air/src/air/mod.rs @@ -483,7 +483,7 @@ pub trait Air: Send + Sync { /// /// `ce_blowup_factor` is guaranteed to be smaller than or equal to the `lde_blowup_factor`. fn ce_blowup_factor(&self) -> usize { - self.context().ce_blowup_factor + self.context().max_degree } /// Returns size of the constraint evaluation domain. @@ -536,7 +536,7 @@ pub trait Air: Send + Sync { R: RandomCoin, { let mut t_coefficients = Vec::new(); - for _ in 0..10 { + for _ in 0..self.context().num_transition_constraints() { t_coefficients.push(public_coin.draw()?); } @@ -584,7 +584,7 @@ pub trait Air: Send + Sync { } let mut c_coefficients = Vec::new(); - for _ in 0..self.context().num_constraint_composition_columns() { + for _ in 0..self.ce_blowup_factor() { c_coefficients.push(public_coin.draw()?); } diff --git a/air/src/air/tests.rs b/air/src/air/tests.rs index 048296b6e..e89ca34f2 100644 --- a/air/src/air/tests.rs +++ b/air/src/air/tests.rs @@ -8,10 +8,7 @@ use alloc::{collections::BTreeMap, vec::Vec}; use crypto::{hashers::Blake3_256, DefaultRandomCoin, RandomCoin}; use math::{fields::f64::BaseElement, get_power_series, polynom, FieldElement, StarkField}; -use super::{ - Air, AirContext, Assertion, EvaluationFrame, ProofOptions, TraceInfo, - TransitionConstraintDegree, -}; +use super::{Air, AirContext, Assertion, EvaluationFrame, ProofOptions, TraceInfo}; use crate::FieldExtension; // PERIODIC COLUMNS @@ -268,9 +265,8 @@ pub fn build_context( num_assertions: usize, ) -> AirContext { 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, 1, 0, num_assertions, options) + AirContext::new(trace_info, 1, 1, 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 2d6a58e10..fbdb9ec73 100644 --- a/air/src/air/transition/mod.rs +++ b/air/src/air/transition/mod.rs @@ -45,7 +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 { - // build constraint divisor; the same divisor applies to all transition constraints let divisor = ConstraintDivisor::from_transition( context.trace_len(), diff --git a/examples/src/fibonacci/fib2/air.rs b/examples/src/fibonacci/fib2/air.rs index cf908ca9e..d88ca0970 100644 --- a/examples/src/fibonacci/fib2/air.rs +++ b/examples/src/fibonacci/fib2/air.rs @@ -3,9 +3,7 @@ // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. -use winterfell::{ - Air, AirContext, Assertion, EvaluationFrame, TraceInfo, TransitionConstraintDegree, -}; +use winterfell::{Air, AirContext, Assertion, EvaluationFrame, TraceInfo}; use super::{BaseElement, FieldElement, ProofOptions, TRACE_WIDTH}; use crate::utils::are_equal; @@ -27,10 +25,9 @@ impl Air for FibAir { // CONSTRUCTOR // -------------------------------------------------------------------------------------------- fn new(trace_info: TraceInfo, pub_inputs: Self::BaseField, options: ProofOptions) -> Self { - let degrees = vec![TransitionConstraintDegree::new(1), TransitionConstraintDegree::new(1)]; assert_eq!(TRACE_WIDTH, trace_info.width()); FibAir { - context: AirContext::new(trace_info, degrees, 2, 0, 3, options), + context: AirContext::new(trace_info, 2, 2, 3, options), result: pub_inputs, } } diff --git a/examples/src/fibonacci/fib8/air.rs b/examples/src/fibonacci/fib8/air.rs index a04b33e24..e21f5d7cc 100644 --- a/examples/src/fibonacci/fib8/air.rs +++ b/examples/src/fibonacci/fib8/air.rs @@ -3,10 +3,7 @@ // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. -use winterfell::{ - Air, AirContext, Assertion, EvaluationFrame, ProofOptions, TraceInfo, - TransitionConstraintDegree, -}; +use winterfell::{Air, AirContext, Assertion, EvaluationFrame, ProofOptions, TraceInfo}; use super::{BaseElement, FieldElement, TRACE_WIDTH}; use crate::utils::are_equal; @@ -28,10 +25,9 @@ impl Air for Fib8Air { // CONSTRUCTOR // -------------------------------------------------------------------------------------------- fn new(trace_info: TraceInfo, pub_inputs: Self::BaseField, options: ProofOptions) -> Self { - let degrees = vec![TransitionConstraintDegree::new(1), TransitionConstraintDegree::new(1)]; assert_eq!(TRACE_WIDTH, trace_info.width()); Fib8Air { - context: AirContext::new(trace_info, degrees, 2, 0, 3, options), + context: AirContext::new(trace_info, 2, 2, 3, options), result: pub_inputs, } } diff --git a/examples/src/fibonacci/fib_small/air.rs b/examples/src/fibonacci/fib_small/air.rs index c4752856e..bac28bb26 100644 --- a/examples/src/fibonacci/fib_small/air.rs +++ b/examples/src/fibonacci/fib_small/air.rs @@ -3,9 +3,7 @@ // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. -use winterfell::{ - Air, AirContext, Assertion, EvaluationFrame, TraceInfo, TransitionConstraintDegree, -}; +use winterfell::{Air, AirContext, Assertion, EvaluationFrame, TraceInfo}; use super::{BaseElement, FieldElement, ProofOptions, TRACE_WIDTH}; use crate::utils::are_equal; @@ -27,10 +25,9 @@ impl Air for FibSmall { // CONSTRUCTOR // -------------------------------------------------------------------------------------------- fn new(trace_info: TraceInfo, pub_inputs: Self::BaseField, options: ProofOptions) -> Self { - let degrees = vec![TransitionConstraintDegree::new(1), TransitionConstraintDegree::new(1)]; assert_eq!(TRACE_WIDTH, trace_info.width()); FibSmall { - context: AirContext::new(trace_info, degrees, 2, 0, 3, options), + context: AirContext::new(trace_info, 2, 2, 3, options), result: pub_inputs, } } diff --git a/examples/src/fibonacci/mulfib2/air.rs b/examples/src/fibonacci/mulfib2/air.rs index 8f6e99aea..9a913d6ba 100644 --- a/examples/src/fibonacci/mulfib2/air.rs +++ b/examples/src/fibonacci/mulfib2/air.rs @@ -6,7 +6,6 @@ use winterfell::{ math::{fields::f128::BaseElement, FieldElement}, Air, AirContext, Assertion, EvaluationFrame, ProofOptions, TraceInfo, - TransitionConstraintDegree, }; use super::TRACE_WIDTH; @@ -29,10 +28,9 @@ impl Air for MulFib2Air { // CONSTRUCTOR // -------------------------------------------------------------------------------------------- fn new(trace_info: TraceInfo, pub_inputs: Self::BaseField, options: ProofOptions) -> Self { - let degrees = vec![TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(2)]; assert_eq!(TRACE_WIDTH, trace_info.width()); MulFib2Air { - context: AirContext::new(trace_info, degrees, 2, 0, 3, options), + context: AirContext::new(trace_info, 2, 2, 3, options), result: pub_inputs, } } diff --git a/examples/src/fibonacci/mulfib8/air.rs b/examples/src/fibonacci/mulfib8/air.rs index 715f707ee..d0f3e9d32 100644 --- a/examples/src/fibonacci/mulfib8/air.rs +++ b/examples/src/fibonacci/mulfib8/air.rs @@ -6,7 +6,6 @@ use winterfell::{ math::{fields::f128::BaseElement, FieldElement}, Air, AirContext, Assertion, EvaluationFrame, ProofOptions, TraceInfo, - TransitionConstraintDegree, }; use super::TRACE_WIDTH; @@ -29,19 +28,9 @@ impl Air for MulFib8Air { // CONSTRUCTOR // -------------------------------------------------------------------------------------------- fn new(trace_info: TraceInfo, pub_inputs: Self::BaseField, options: ProofOptions) -> Self { - let degrees = vec![ - TransitionConstraintDegree::new(2), - TransitionConstraintDegree::new(2), - TransitionConstraintDegree::new(2), - TransitionConstraintDegree::new(2), - TransitionConstraintDegree::new(2), - TransitionConstraintDegree::new(2), - TransitionConstraintDegree::new(2), - TransitionConstraintDegree::new(2), - ]; assert_eq!(TRACE_WIDTH, trace_info.width()); MulFib8Air { - context: AirContext::new(trace_info, degrees, 8, 0, 3, options), + context: AirContext::new(trace_info, 2, 8, 3, options), result: pub_inputs, } } diff --git a/examples/src/lamport/aggregate/air.rs b/examples/src/lamport/aggregate/air.rs index 29b6e2372..de2d04281 100644 --- a/examples/src/lamport/aggregate/air.rs +++ b/examples/src/lamport/aggregate/air.rs @@ -7,7 +7,6 @@ use core_utils::flatten_slice_elements; use winterfell::{ math::{fields::f128::BaseElement, FieldElement, ToElements}, Air, AirContext, Assertion, EvaluationFrame, ProofOptions, TraceInfo, - TransitionConstraintDegree, }; use super::{ @@ -52,43 +51,9 @@ impl Air for LamportAggregateAir { // CONSTRUCTOR // -------------------------------------------------------------------------------------------- fn new(trace_info: TraceInfo, pub_inputs: PublicInputs, options: ProofOptions) -> Self { - // define degrees for all transition constraints - let degrees = vec![ - TransitionConstraintDegree::with_cycles(2, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), // m0 bit is binary - TransitionConstraintDegree::with_cycles(2, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), // m1 bit is binary - TransitionConstraintDegree::with_cycles( - 1, - vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN, SIG_CYCLE_LEN], - ), // m0 accumulation - TransitionConstraintDegree::with_cycles( - 1, - vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN, SIG_CYCLE_LEN], - ), // m1 accumulation - // secret key 1 hashing - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - // secret key 2 hashing - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - // public key hashing - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - ]; assert_eq!(TRACE_WIDTH, trace_info.width()); LamportAggregateAir { - context: AirContext::new(trace_info, degrees, 22, options), + context: AirContext::new(trace_info, 8, 21, 22, options), pub_keys: pub_inputs.pub_keys, messages: pub_inputs.messages, } diff --git a/examples/src/lamport/threshold/air.rs b/examples/src/lamport/threshold/air.rs index 41983c743..402c90d5f 100644 --- a/examples/src/lamport/threshold/air.rs +++ b/examples/src/lamport/threshold/air.rs @@ -6,7 +6,6 @@ use winterfell::{ math::{fields::f128::BaseElement, FieldElement, StarkField, ToElements}, Air, AirContext, Assertion, EvaluationFrame, ProofOptions, TraceInfo, - TransitionConstraintDegree, }; use super::{ @@ -58,48 +57,9 @@ impl Air for LamportThresholdAir { // -------------------------------------------------------------------------------------------- #[rustfmt::skip] fn new(trace_info: TraceInfo, pub_inputs: PublicInputs, options: ProofOptions) -> Self { - // define degrees for all transition constraints - let degrees = vec![ - // secret key 1 hashing - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - // secret key 2 hashing - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - // public key hashing - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - // merkle path verification - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), - // merkle path index - TransitionConstraintDegree::with_cycles(2, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN]), // index bit is binary - TransitionConstraintDegree::with_cycles(1, vec![HASH_CYCLE_LEN, SIG_CYCLE_LEN, SIG_CYCLE_LEN]), // index accumulator - // signature count - TransitionConstraintDegree::with_cycles(2, vec![SIG_CYCLE_LEN]), // sig flag is binary - TransitionConstraintDegree::with_cycles(1, vec![SIG_CYCLE_LEN]), // sig counter - TransitionConstraintDegree::with_cycles(2, vec![SIG_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(2, vec![SIG_CYCLE_LEN]), - ]; assert_eq!(TRACE_WIDTH, trace_info.width()); LamportThresholdAir { - context: AirContext::new(trace_info, degrees, 26, options), + context: AirContext::new(trace_info, 8, 30, 26, options), pub_key_root: pub_inputs.pub_key_root, num_pub_keys: pub_inputs.num_pub_keys, num_signatures: pub_inputs.num_signatures, diff --git a/examples/src/lib.rs b/examples/src/lib.rs index 43cb051db..33f733d7c 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 ef9c2e788..36c1e0c0d 100644 --- a/examples/src/main.rs +++ b/examples/src/main.rs @@ -5,10 +5,9 @@ use std::time::Instant; -//use examples::{fibonacci, rescue, vdf, ExampleOptions, ExampleType}; -//#[cfg(feature = "std")] -//use examples::{lamport, merkle, rescue_raps}; -use examples::{ fibonacci, ExampleOptions, ExampleType}; +use examples::{fibonacci, rescue, vdf, ExampleOptions, ExampleType}; +#[cfg(feature = "std")] +use examples::{lamport, merkle, rescue_raps}; use structopt::StructOpt; use tracing::info_span; #[cfg(feature = "tracing-forest")] @@ -66,26 +65,23 @@ fn main() { ExampleType::FibSmall { sequence_length } => { fibonacci::fib_small::get_example(&options, sequence_length) }, - - _ => 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) - //}, + 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/examples/src/merkle/air.rs b/examples/src/merkle/air.rs index e0c8b177c..a9b8cd18a 100644 --- a/examples/src/merkle/air.rs +++ b/examples/src/merkle/air.rs @@ -5,7 +5,6 @@ use winterfell::{ math::ToElements, Air, AirContext, Assertion, EvaluationFrame, ProofOptions, TraceInfo, - TransitionConstraintDegree, }; use super::{rescue, BaseElement, FieldElement, HASH_CYCLE_LEN, HASH_STATE_WIDTH, TRACE_WIDTH}; @@ -38,18 +37,9 @@ impl Air for MerkleAir { // CONSTRUCTOR // -------------------------------------------------------------------------------------------- fn new(trace_info: TraceInfo, pub_inputs: PublicInputs, options: ProofOptions) -> Self { - let degrees = vec![ - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN]), - TransitionConstraintDegree::with_cycles(5, vec![HASH_CYCLE_LEN]), - TransitionConstraintDegree::new(2), - ]; assert_eq!(TRACE_WIDTH, trace_info.width()); MerkleAir { - context: AirContext::new(trace_info, degrees, 4, options), + context: AirContext::new(trace_info, 8, 7, 4, options), tree_root: pub_inputs.tree_root, } } diff --git a/examples/src/rescue/air.rs b/examples/src/rescue/air.rs index a9d3d5ebb..4e56e9927 100644 --- a/examples/src/rescue/air.rs +++ b/examples/src/rescue/air.rs @@ -3,10 +3,7 @@ // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. -use winterfell::{ - math::ToElements, Air, AirContext, Assertion, EvaluationFrame, TraceInfo, - TransitionConstraintDegree, -}; +use winterfell::{math::ToElements, Air, AirContext, Assertion, EvaluationFrame, TraceInfo}; use super::{rescue, BaseElement, FieldElement, ProofOptions, CYCLE_LENGTH, TRACE_WIDTH}; use crate::utils::{are_equal, is_zero, not, EvaluationResult}; @@ -65,15 +62,9 @@ impl Air for RescueAir { // CONSTRUCTOR // -------------------------------------------------------------------------------------------- fn new(trace_info: TraceInfo, pub_inputs: PublicInputs, options: ProofOptions) -> Self { - let degrees = vec![ - TransitionConstraintDegree::with_cycles(3, vec![CYCLE_LENGTH]), - TransitionConstraintDegree::with_cycles(3, vec![CYCLE_LENGTH]), - TransitionConstraintDegree::with_cycles(3, vec![CYCLE_LENGTH]), - TransitionConstraintDegree::with_cycles(3, vec![CYCLE_LENGTH]), - ]; assert_eq!(TRACE_WIDTH, trace_info.width()); RescueAir { - context: AirContext::new(trace_info, degrees, 4, options), + context: AirContext::new(trace_info, 4, 4, 4, options), seed: pub_inputs.seed, result: pub_inputs.result, } diff --git a/examples/src/rescue_raps/air.rs b/examples/src/rescue_raps/air.rs index 6fb5321b1..383491586 100644 --- a/examples/src/rescue_raps/air.rs +++ b/examples/src/rescue_raps/air.rs @@ -6,7 +6,6 @@ use core_utils::flatten_slice_elements; use winterfell::{ math::ToElements, Air, AirContext, Assertion, AuxRandElements, EvaluationFrame, TraceInfo, - TransitionConstraintDegree, }; use super::{ @@ -65,19 +64,13 @@ impl Air for RescueRapsAir { // CONSTRUCTOR // -------------------------------------------------------------------------------------------- fn new(trace_info: TraceInfo, pub_inputs: PublicInputs, options: ProofOptions) -> Self { - let main_degrees = - vec![TransitionConstraintDegree::with_cycles(3, vec![CYCLE_LENGTH]); 2 * STATE_WIDTH]; - let aux_degrees = vec![ - TransitionConstraintDegree::with_cycles(1, vec![CYCLE_LENGTH]), - TransitionConstraintDegree::with_cycles(1, vec![CYCLE_LENGTH]), - TransitionConstraintDegree::new(2), - ]; assert_eq!(TRACE_WIDTH + 3, trace_info.width()); RescueRapsAir { context: AirContext::new_multi_segment( trace_info, - main_degrees, - aux_degrees, + 4, + 2 * STATE_WIDTH, + 3, 8, 2, None, diff --git a/examples/src/tests.rs b/examples/src/tests.rs index 704dbed0e..14756c0f4 100644 --- a/examples/src/tests.rs +++ b/examples/src/tests.rs @@ -8,6 +8,7 @@ use crate::Example; pub fn test_basic_proof_verification(e: Box) { let proof = e.prove(); assert!(e.verify(proof).is_ok()); + //println!("e.verify {:?}", e.verify(proof)) } pub fn test_basic_proof_verification_fail(e: Box) { diff --git a/examples/src/vdf/exempt/air.rs b/examples/src/vdf/exempt/air.rs index 9254e4e0a..b2f486716 100644 --- a/examples/src/vdf/exempt/air.rs +++ b/examples/src/vdf/exempt/air.rs @@ -3,10 +3,7 @@ // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. -use winterfell::{ - math::ToElements, Air, AirContext, Assertion, EvaluationFrame, TraceInfo, - TransitionConstraintDegree, -}; +use winterfell::{math::ToElements, Air, AirContext, Assertion, EvaluationFrame, TraceInfo}; use super::{BaseElement, FieldElement, ProofOptions, ALPHA, FORTY_TWO, TRACE_WIDTH}; @@ -41,12 +38,11 @@ impl Air for VdfAir { type GkrVerifier = (); fn new(trace_info: TraceInfo, pub_inputs: VdfInputs, options: ProofOptions) -> Self { - let degrees = vec![TransitionConstraintDegree::new(3)]; assert_eq!(TRACE_WIDTH, trace_info.width()); // make sure the last two rows are excluded from transition constraints as we populate // values in the last row with garbage let context = - AirContext::new(trace_info, degrees, 2, options).set_num_transition_exemptions(2); + AirContext::new(trace_info, 2, 1, 2, options).set_num_transition_exemptions(2); Self { context, seed: pub_inputs.seed, diff --git a/examples/src/vdf/regular/air.rs b/examples/src/vdf/regular/air.rs index b434c1478..794045c56 100644 --- a/examples/src/vdf/regular/air.rs +++ b/examples/src/vdf/regular/air.rs @@ -3,10 +3,7 @@ // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. -use winterfell::{ - math::ToElements, Air, AirContext, Assertion, EvaluationFrame, TraceInfo, - TransitionConstraintDegree, -}; +use winterfell::{math::ToElements, Air, AirContext, Assertion, EvaluationFrame, TraceInfo}; use super::{BaseElement, FieldElement, ProofOptions, ALPHA, FORTY_TWO, TRACE_WIDTH}; @@ -41,10 +38,9 @@ impl Air for VdfAir { type GkrVerifier = (); fn new(trace_info: TraceInfo, pub_inputs: VdfInputs, options: ProofOptions) -> Self { - let degrees = vec![TransitionConstraintDegree::new(3)]; assert_eq!(TRACE_WIDTH, trace_info.width()); Self { - context: AirContext::new(trace_info, degrees, 2, options), + context: AirContext::new(trace_info, 2, 1, 2, options), seed: pub_inputs.seed, result: pub_inputs.result, } diff --git a/prover/Cargo.toml b/prover/Cargo.toml index 36272766f..978c50b07 100644 --- a/prover/Cargo.toml +++ b/prover/Cargo.toml @@ -37,6 +37,7 @@ math = { version = "0.9", path = "../math", package = "winter-math", default-fea maybe_async = { path = "../utils/maybe_async" , package = "winter-maybe-async" } tracing = { version = "0.1", default-features = false, features = ["attributes"]} utils = { version = "0.9", path = "../utils/core", package = "winter-utils", default-features = false } +libc-print = "0.1.23" [dev-dependencies] criterion = "0.5" diff --git a/prover/benches/lagrange_kernel.rs b/prover/benches/lagrange_kernel.rs index 7ee8ab3c3..73a287401 100644 --- a/prover/benches/lagrange_kernel.rs +++ b/prover/benches/lagrange_kernel.rs @@ -8,7 +8,7 @@ use std::time::Duration; use air::{ Air, AirContext, Assertion, AuxRandElements, ConstraintCompositionCoefficients, EvaluationFrame, FieldExtension, GkrRandElements, LagrangeKernelRandElements, ProofOptions, - TraceInfo, TransitionConstraintDegree, + TraceInfo, }; use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion}; use crypto::{hashers::Blake3_256, DefaultRandomCoin, MerkleTree, RandomCoin}; @@ -106,15 +106,7 @@ impl Air for LagrangeKernelAir { fn new(trace_info: TraceInfo, _pub_inputs: Self::PublicInputs, options: ProofOptions) -> Self { Self { - context: AirContext::new_multi_segment( - trace_info, - vec![TransitionConstraintDegree::new(1)], - vec![TransitionConstraintDegree::new(1)], - 1, - 1, - Some(0), - options, - ), + context: AirContext::new_multi_segment(trace_info, 1, 1, 1, 1, 1, Some(0), options), } } diff --git a/prover/src/constraints/evaluation_table.rs b/prover/src/constraints/evaluation_table.rs index 55a006799..376ddeafb 100644 --- a/prover/src/constraints/evaluation_table.rs +++ b/prover/src/constraints/evaluation_table.rs @@ -184,7 +184,7 @@ 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 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 @@ -390,17 +390,6 @@ fn get_inv_evaluation( // DEBUG HELPERS // ================================================================================================ -/// Returns evaluation degrees of all transition constraints. -/// -/// An evaluation degree is defined as degree of transition constraints in the context of a given -/// execution trace accounting for constraint divisor degree. For most constraints, this degree is -/// computed as `([trace_length - 1] * [constraint degree]) - [divisor degree]`. However, for -/// constraints which rely on periodic columns this computation is slightly more complex. -/// -/// 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. - - /// Computes the actual degree of a transition polynomial described by the provided evaluations. /// /// The degree is computed as follows: diff --git a/prover/src/lib.rs b/prover/src/lib.rs index ac0e82be2..9701e5258 100644 --- a/prover/src/lib.rs +++ b/prover/src/lib.rs @@ -537,7 +537,6 @@ pub trait Prover { .in_scope(|| { CompositionPoly::new(composition_poly_trace, domain, num_constraint_composition_columns) }); - assert_eq!(composition_poly.num_columns(), num_constraint_composition_columns); assert_eq!(composition_poly.column_degree(), domain.trace_length() - 1); // then, evaluate composition polynomial columns over the LDE domain @@ -545,7 +544,6 @@ pub trait Prover { let composed_evaluations = info_span!("evaluate_composition_poly_columns").in_scope(|| { RowMatrix::evaluate_polys_over::(composition_poly.data(), domain) }); - assert_eq!(composed_evaluations.num_cols(), num_constraint_composition_columns); assert_eq!(composed_evaluations.num_rows(), domain_size); // finally, build constraint evaluation commitment diff --git a/prover/src/tests/mod.rs b/prover/src/tests/mod.rs index c19bd27b3..a7e1a20b9 100644 --- a/prover/src/tests/mod.rs +++ b/prover/src/tests/mod.rs @@ -5,10 +5,7 @@ use alloc::vec::Vec; -use air::{ - Air, AirContext, Assertion, EvaluationFrame, FieldExtension, ProofOptions, TraceInfo, - TransitionConstraintDegree, -}; +use air::{Air, AirContext, Assertion, EvaluationFrame, FieldExtension, ProofOptions, TraceInfo}; use math::{fields::f128::BaseElement, FieldElement, StarkField}; use crate::TraceTable; @@ -117,6 +114,5 @@ fn build_context( num_assertions: usize, ) -> 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, 1, 0, num_assertions, options) + AirContext::new(trace_info, 1, 1, num_assertions, options) } diff --git a/verifier/src/channel.rs b/verifier/src/channel.rs index c84f4ec2a..003fe54fa 100644 --- a/verifier/src/channel.rs +++ b/verifier/src/channel.rs @@ -78,7 +78,7 @@ where if E::BaseField::get_modulus_le_bytes() != context.field_modulus_bytes() { return Err(VerifierError::InconsistentBaseField); } - let constraint_frame_width = air.context().num_constraint_composition_columns(); + let constraint_frame_width = air.ce_blowup_factor(); let num_trace_segments = air.trace_info().num_segments(); let main_trace_width = air.trace_info().main_trace_width(); @@ -387,7 +387,7 @@ where air: &A, num_queries: usize, ) -> Result { - let constraint_frame_width = air.context().num_constraint_composition_columns(); + let constraint_frame_width = air.ce_blowup_factor(); let (query_proofs, evaluations) = queries .parse::(air.lde_domain_size(), num_queries, constraint_frame_width) diff --git a/winterfell/src/lib.rs b/winterfell/src/lib.rs index 86c5e0345..8711e2b05 100644 --- a/winterfell/src/lib.rs +++ b/winterfell/src/lib.rs @@ -195,10 +195,13 @@ //! //! // Our computation requires a single transition constraint. The constraint itself //! // is defined in the evaluate_transition() method below, but here we need to specify -//! // the expected degree of the constraint. If the expected and actual degrees of the -//! // constraints don't match, an error will be thrown in the debug mode, but in release -//! // mode, an invalid proof will be generated which will not be accepted by any verifier. -//! let degrees = vec![TransitionConstraintDegree::new(3)]; +//! // the number of transition constraints. +//! let num_transition_constraints = 1; +//! +//! // We also need to specify the maximum degree over the transition constraints. +//! // If the expected and actual max degrees of the constraints don't match, an invalid +//! // proof will be generated which will not be accepted by any verifier. +//! let max_degree = 2; //! //! // We also need to specify the exact number of assertions we will place against the //! // execution trace. This number must be the same as the number of items in a vector @@ -206,7 +209,7 @@ //! let num_assertions = 2; //! //! WorkAir { -//! context: AirContext::new(trace_info, degrees, num_assertions, options), +//! context: AirContext::new(trace_info, max_degree, num_transition_constraints, num_assertions, options), //! start: pub_inputs.start, //! result: pub_inputs.result, //! } @@ -294,9 +297,8 @@ //! # //! # fn new(trace_info: TraceInfo, pub_inputs: PublicInputs, options: ProofOptions) -> Self { //! # assert_eq!(1, trace_info.width()); -//! # let degrees = vec![TransitionConstraintDegree::new(3)]; //! # WorkAir { -//! # context: AirContext::new(trace_info, degrees, 2, options), +//! # context: AirContext::new(trace_info, 2, 1, 2, options), //! # start: pub_inputs.start, //! # result: pub_inputs.result, //! # } @@ -444,9 +446,8 @@ //! # //! # fn new(trace_info: TraceInfo, pub_inputs: PublicInputs, options: ProofOptions) -> Self { //! # assert_eq!(1, trace_info.width()); -//! # let degrees = vec![TransitionConstraintDegree::new(3)]; //! # WorkAir { -//! # context: AirContext::new(trace_info, degrees, 2, options), +//! # context: AirContext::new(trace_info, 2, 1, 2, options), //! # start: pub_inputs.start, //! # result: pub_inputs.result, //! # } diff --git a/winterfell/src/tests.rs b/winterfell/src/tests.rs index 1a1c15ad0..db8c9ede3 100644 --- a/winterfell/src/tests.rs +++ b/winterfell/src/tests.rs @@ -132,17 +132,7 @@ impl Air for LagrangeKernelComplexAir { fn new(trace_info: TraceInfo, _pub_inputs: Self::PublicInputs, options: ProofOptions) -> Self { Self { - context: AirContext::new_multi_segment( - trace_info, - vec![TransitionConstraintDegree::new(1)], - vec![TransitionConstraintDegree::new(1)], - 1, - 1, - 1, - 1, - Some(1), - options, - ), + context: AirContext::new_multi_segment(trace_info, 2, 1, 1, 1, 1, Some(1), options), } }