diff --git a/examples/src/fibonacci/fib2/mod.rs b/examples/src/fibonacci/fib2/mod.rs index 3b1cce210..4360cc2d7 100644 --- a/examples/src/fibonacci/fib2/mod.rs +++ b/examples/src/fibonacci/fib2/mod.rs @@ -11,7 +11,8 @@ use std::time::Instant; use winterfell::{ crypto::{DefaultRandomCoin, ElementHasher}, math::{fields::f128::BaseElement, FieldElement}, - DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, TraceTable, VerifierError, + DefaultConstraintEvaluator, DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, + TraceTable, VerifierError, }; mod air; diff --git a/examples/src/fibonacci/fib2/prover.rs b/examples/src/fibonacci/fib2/prover.rs index d14079758..2fbc3047b 100644 --- a/examples/src/fibonacci/fib2/prover.rs +++ b/examples/src/fibonacci/fib2/prover.rs @@ -4,8 +4,8 @@ // LICENSE file in the root directory of this source tree. use super::{ - BaseElement, DefaultRandomCoin, DefaultTraceLde, ElementHasher, FibAir, FieldElement, - PhantomData, ProofOptions, Prover, Trace, TraceTable, TRACE_WIDTH, + BaseElement, DefaultConstraintEvaluator, DefaultRandomCoin, DefaultTraceLde, ElementHasher, + FibAir, FieldElement, PhantomData, ProofOptions, Prover, Trace, TraceTable, TRACE_WIDTH, }; // FIBONACCI PROVER @@ -58,6 +58,8 @@ where type HashFn = H; type RandomCoin = DefaultRandomCoin; type TraceLde> = DefaultTraceLde; + type ConstraintEvaluator<'a, E: FieldElement> = + DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { let last_step = trace.length() - 1; @@ -67,4 +69,16 @@ where fn options(&self) -> &ProofOptions { &self.options } + + fn new_evaluator<'a, E>( + &self, + air: &'a Self::Air, + aux_rand_elements: winterfell::AuxTraceRandElements, + composition_coefficients: winterfell::ConstraintCompositionCoefficients, + ) -> Self::ConstraintEvaluator<'a, E> + where + E: FieldElement, + { + DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients) + } } diff --git a/examples/src/fibonacci/fib8/mod.rs b/examples/src/fibonacci/fib8/mod.rs index 9cfdfa052..366411ec8 100644 --- a/examples/src/fibonacci/fib8/mod.rs +++ b/examples/src/fibonacci/fib8/mod.rs @@ -11,7 +11,8 @@ use std::time::Instant; use winterfell::{ crypto::{DefaultRandomCoin, ElementHasher}, math::{fields::f128::BaseElement, FieldElement}, - DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, TraceTable, VerifierError, + DefaultConstraintEvaluator, DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, + TraceTable, VerifierError, }; mod air; diff --git a/examples/src/fibonacci/fib8/prover.rs b/examples/src/fibonacci/fib8/prover.rs index 5c07e7c0b..fc2cc0763 100644 --- a/examples/src/fibonacci/fib8/prover.rs +++ b/examples/src/fibonacci/fib8/prover.rs @@ -4,8 +4,8 @@ // LICENSE file in the root directory of this source tree. use super::{ - BaseElement, DefaultRandomCoin, DefaultTraceLde, ElementHasher, Fib8Air, FieldElement, - PhantomData, ProofOptions, Prover, Trace, TraceTable, + BaseElement, DefaultConstraintEvaluator, DefaultRandomCoin, DefaultTraceLde, ElementHasher, + Fib8Air, FieldElement, PhantomData, ProofOptions, Prover, Trace, TraceTable, }; // FIBONACCI PROVER @@ -73,6 +73,8 @@ where type HashFn = H; type RandomCoin = DefaultRandomCoin; type TraceLde> = DefaultTraceLde; + type ConstraintEvaluator<'a, E: FieldElement> = + DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { let last_step = trace.length() - 1; @@ -82,4 +84,16 @@ where fn options(&self) -> &ProofOptions { &self.options } + + fn new_evaluator<'a, E>( + &self, + air: &'a Self::Air, + aux_rand_elements: winterfell::AuxTraceRandElements, + composition_coefficients: winterfell::ConstraintCompositionCoefficients, + ) -> Self::ConstraintEvaluator<'a, E> + where + E: FieldElement, + { + DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients) + } } diff --git a/examples/src/fibonacci/fib_small/mod.rs b/examples/src/fibonacci/fib_small/mod.rs index b5b9d990c..0f319adb9 100644 --- a/examples/src/fibonacci/fib_small/mod.rs +++ b/examples/src/fibonacci/fib_small/mod.rs @@ -11,7 +11,8 @@ use std::time::Instant; use winterfell::{ crypto::{DefaultRandomCoin, ElementHasher}, math::{fields::f64::BaseElement, FieldElement}, - DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, TraceTable, VerifierError, + DefaultConstraintEvaluator, DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, + TraceTable, VerifierError, }; mod air; diff --git a/examples/src/fibonacci/fib_small/prover.rs b/examples/src/fibonacci/fib_small/prover.rs index 12df3c2eb..5a28bb579 100644 --- a/examples/src/fibonacci/fib_small/prover.rs +++ b/examples/src/fibonacci/fib_small/prover.rs @@ -3,8 +3,8 @@ // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. use super::{ - air::FibSmall, BaseElement, DefaultRandomCoin, DefaultTraceLde, ElementHasher, FieldElement, - PhantomData, ProofOptions, Prover, Trace, TraceTable, TRACE_WIDTH, + air::FibSmall, BaseElement, DefaultConstraintEvaluator, DefaultRandomCoin, DefaultTraceLde, + ElementHasher, FieldElement, PhantomData, ProofOptions, Prover, Trace, TraceTable, TRACE_WIDTH, }; // FIBONACCI PROVER @@ -57,6 +57,8 @@ where type HashFn = H; type RandomCoin = DefaultRandomCoin; type TraceLde> = DefaultTraceLde; + type ConstraintEvaluator<'a, E: FieldElement> = + DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { let last_step = trace.length() - 1; @@ -66,4 +68,16 @@ where fn options(&self) -> &ProofOptions { &self.options } + + fn new_evaluator<'a, E>( + &self, + air: &'a Self::Air, + aux_rand_elements: winterfell::AuxTraceRandElements, + composition_coefficients: winterfell::ConstraintCompositionCoefficients, + ) -> Self::ConstraintEvaluator<'a, E> + where + E: FieldElement, + { + DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients) + } } diff --git a/examples/src/fibonacci/mulfib2/mod.rs b/examples/src/fibonacci/mulfib2/mod.rs index 94e219454..eb3083d01 100644 --- a/examples/src/fibonacci/mulfib2/mod.rs +++ b/examples/src/fibonacci/mulfib2/mod.rs @@ -11,7 +11,8 @@ use std::time::Instant; use winterfell::{ crypto::{DefaultRandomCoin, ElementHasher}, math::{fields::f128::BaseElement, FieldElement}, - DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, TraceTable, VerifierError, + DefaultConstraintEvaluator, DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, + TraceTable, VerifierError, }; mod air; diff --git a/examples/src/fibonacci/mulfib2/prover.rs b/examples/src/fibonacci/mulfib2/prover.rs index 72e7fb74c..86448ed22 100644 --- a/examples/src/fibonacci/mulfib2/prover.rs +++ b/examples/src/fibonacci/mulfib2/prover.rs @@ -4,8 +4,8 @@ // LICENSE file in the root directory of this source tree. use super::{ - BaseElement, DefaultRandomCoin, DefaultTraceLde, ElementHasher, FieldElement, MulFib2Air, - PhantomData, ProofOptions, Prover, Trace, TraceTable, + BaseElement, DefaultConstraintEvaluator, DefaultRandomCoin, DefaultTraceLde, ElementHasher, + FieldElement, MulFib2Air, PhantomData, ProofOptions, Prover, Trace, TraceTable, }; // FIBONACCI PROVER @@ -54,6 +54,8 @@ where type HashFn = H; type RandomCoin = DefaultRandomCoin; type TraceLde> = DefaultTraceLde; + type ConstraintEvaluator<'a, E: FieldElement> = + DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { let last_step = trace.length() - 1; @@ -63,4 +65,16 @@ where fn options(&self) -> &ProofOptions { &self.options } + + fn new_evaluator<'a, E>( + &self, + air: &'a Self::Air, + aux_rand_elements: winterfell::AuxTraceRandElements, + composition_coefficients: winterfell::ConstraintCompositionCoefficients, + ) -> Self::ConstraintEvaluator<'a, E> + where + E: FieldElement, + { + DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients) + } } diff --git a/examples/src/fibonacci/mulfib8/mod.rs b/examples/src/fibonacci/mulfib8/mod.rs index 1274538b4..264b568e0 100644 --- a/examples/src/fibonacci/mulfib8/mod.rs +++ b/examples/src/fibonacci/mulfib8/mod.rs @@ -11,7 +11,8 @@ use std::time::Instant; use winterfell::{ crypto::{DefaultRandomCoin, ElementHasher}, math::{fields::f128::BaseElement, FieldElement}, - DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, TraceTable, VerifierError, + DefaultConstraintEvaluator, DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, + TraceTable, VerifierError, }; mod air; diff --git a/examples/src/fibonacci/mulfib8/prover.rs b/examples/src/fibonacci/mulfib8/prover.rs index 9fe4b9852..0c38126b2 100644 --- a/examples/src/fibonacci/mulfib8/prover.rs +++ b/examples/src/fibonacci/mulfib8/prover.rs @@ -4,8 +4,8 @@ // LICENSE file in the root directory of this source tree. use super::{ - BaseElement, DefaultRandomCoin, DefaultTraceLde, ElementHasher, FieldElement, MulFib8Air, - PhantomData, ProofOptions, Prover, Trace, TraceTable, + BaseElement, DefaultConstraintEvaluator, DefaultRandomCoin, DefaultTraceLde, ElementHasher, + FieldElement, MulFib8Air, PhantomData, ProofOptions, Prover, Trace, TraceTable, }; // FIBONACCI PROVER @@ -66,6 +66,8 @@ where type HashFn = H; type RandomCoin = DefaultRandomCoin; type TraceLde> = DefaultTraceLde; + type ConstraintEvaluator<'a, E: FieldElement> = + DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement { let last_step = trace.length() - 1; @@ -75,4 +77,16 @@ where fn options(&self) -> &ProofOptions { &self.options } + + fn new_evaluator<'a, E>( + &self, + air: &'a Self::Air, + aux_rand_elements: winterfell::AuxTraceRandElements, + composition_coefficients: winterfell::ConstraintCompositionCoefficients, + ) -> Self::ConstraintEvaluator<'a, E> + where + E: FieldElement, + { + DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients) + } } diff --git a/examples/src/lamport/aggregate/mod.rs b/examples/src/lamport/aggregate/mod.rs index d81191fc8..2246617fc 100644 --- a/examples/src/lamport/aggregate/mod.rs +++ b/examples/src/lamport/aggregate/mod.rs @@ -13,7 +13,8 @@ use std::time::Instant; use winterfell::{ crypto::{DefaultRandomCoin, ElementHasher}, math::{fields::f128::BaseElement, get_power_series, FieldElement, StarkField}, - DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, TraceTable, VerifierError, + DefaultConstraintEvaluator, DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, + TraceTable, VerifierError, }; mod air; diff --git a/examples/src/lamport/aggregate/prover.rs b/examples/src/lamport/aggregate/prover.rs index 49a3c0d48..9c715b677 100644 --- a/examples/src/lamport/aggregate/prover.rs +++ b/examples/src/lamport/aggregate/prover.rs @@ -4,9 +4,10 @@ // LICENSE file in the root directory of this source tree. use super::{ - get_power_series, rescue, BaseElement, DefaultRandomCoin, DefaultTraceLde, ElementHasher, - FieldElement, LamportAggregateAir, PhantomData, ProofOptions, Prover, PublicInputs, Signature, - StarkField, TraceTable, CYCLE_LENGTH, NUM_HASH_ROUNDS, SIG_CYCLE_LENGTH, TRACE_WIDTH, + get_power_series, rescue, BaseElement, DefaultConstraintEvaluator, DefaultRandomCoin, + DefaultTraceLde, ElementHasher, FieldElement, LamportAggregateAir, PhantomData, ProofOptions, + Prover, PublicInputs, Signature, StarkField, TraceTable, CYCLE_LENGTH, NUM_HASH_ROUNDS, + SIG_CYCLE_LENGTH, TRACE_WIDTH, }; #[cfg(feature = "concurrent")] @@ -98,6 +99,8 @@ where type HashFn = H; type RandomCoin = DefaultRandomCoin; type TraceLde> = DefaultTraceLde; + type ConstraintEvaluator<'a, E: FieldElement> = + DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, _trace: &Self::Trace) -> PublicInputs { self.pub_inputs.clone() @@ -106,6 +109,18 @@ where fn options(&self) -> &ProofOptions { &self.options } + + fn new_evaluator<'a, E>( + &self, + air: &'a Self::Air, + aux_rand_elements: winterfell::AuxTraceRandElements, + composition_coefficients: winterfell::ConstraintCompositionCoefficients, + ) -> Self::ConstraintEvaluator<'a, E> + where + E: FieldElement, + { + DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients) + } } // TRACE INITIALIZATION diff --git a/examples/src/lamport/threshold/mod.rs b/examples/src/lamport/threshold/mod.rs index 84ffcab59..d98570919 100644 --- a/examples/src/lamport/threshold/mod.rs +++ b/examples/src/lamport/threshold/mod.rs @@ -14,7 +14,8 @@ use std::time::Instant; use winterfell::{ crypto::{DefaultRandomCoin, ElementHasher}, math::{fields::f128::BaseElement, get_power_series, FieldElement, StarkField}, - DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, TraceTable, VerifierError, + DefaultConstraintEvaluator, DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, + TraceTable, VerifierError, }; mod signature; diff --git a/examples/src/lamport/threshold/prover.rs b/examples/src/lamport/threshold/prover.rs index 88ce906cb..2df4c13c7 100644 --- a/examples/src/lamport/threshold/prover.rs +++ b/examples/src/lamport/threshold/prover.rs @@ -4,10 +4,10 @@ // LICENSE file in the root directory of this source tree. use super::{ - get_power_series, rescue, AggPublicKey, BaseElement, DefaultRandomCoin, DefaultTraceLde, - ElementHasher, FieldElement, LamportThresholdAir, PhantomData, ProofOptions, Prover, - PublicInputs, Signature, StarkField, TraceTable, HASH_CYCLE_LENGTH, NUM_HASH_ROUNDS, - SIG_CYCLE_LENGTH, TRACE_WIDTH, + get_power_series, rescue, AggPublicKey, BaseElement, DefaultConstraintEvaluator, + DefaultRandomCoin, DefaultTraceLde, ElementHasher, FieldElement, LamportThresholdAir, + PhantomData, ProofOptions, Prover, PublicInputs, Signature, StarkField, TraceTable, + HASH_CYCLE_LENGTH, NUM_HASH_ROUNDS, SIG_CYCLE_LENGTH, TRACE_WIDTH, }; use std::collections::HashMap; @@ -140,6 +140,8 @@ where type HashFn = H; type RandomCoin = DefaultRandomCoin; type TraceLde> = DefaultTraceLde; + type ConstraintEvaluator<'a, E: FieldElement> = + DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, _trace: &Self::Trace) -> PublicInputs { self.pub_inputs.clone() @@ -148,6 +150,18 @@ where fn options(&self) -> &ProofOptions { &self.options } + + fn new_evaluator<'a, E>( + &self, + air: &'a Self::Air, + aux_rand_elements: winterfell::AuxTraceRandElements, + composition_coefficients: winterfell::ConstraintCompositionCoefficients, + ) -> Self::ConstraintEvaluator<'a, E> + where + E: FieldElement, + { + DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients) + } } // TRACE INITIALIZATION diff --git a/examples/src/merkle/mod.rs b/examples/src/merkle/mod.rs index 384363bfc..bdc10afbc 100644 --- a/examples/src/merkle/mod.rs +++ b/examples/src/merkle/mod.rs @@ -18,7 +18,8 @@ use std::time::Instant; use winterfell::{ crypto::{DefaultRandomCoin, Digest, ElementHasher, MerkleTree}, math::{fields::f128::BaseElement, FieldElement, StarkField}, - DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, TraceTable, VerifierError, + DefaultConstraintEvaluator, DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, + TraceTable, VerifierError, }; mod air; diff --git a/examples/src/merkle/prover.rs b/examples/src/merkle/prover.rs index 86b0874d0..e2b0f4f90 100644 --- a/examples/src/merkle/prover.rs +++ b/examples/src/merkle/prover.rs @@ -4,9 +4,9 @@ // LICENSE file in the root directory of this source tree. use super::{ - rescue, BaseElement, DefaultRandomCoin, DefaultTraceLde, ElementHasher, FieldElement, - MerkleAir, PhantomData, ProofOptions, Prover, PublicInputs, Trace, TraceTable, HASH_CYCLE_LEN, - HASH_STATE_WIDTH, NUM_HASH_ROUNDS, TRACE_WIDTH, + rescue, BaseElement, DefaultConstraintEvaluator, DefaultRandomCoin, DefaultTraceLde, + ElementHasher, FieldElement, MerkleAir, PhantomData, ProofOptions, Prover, PublicInputs, Trace, + TraceTable, HASH_CYCLE_LEN, HASH_STATE_WIDTH, NUM_HASH_ROUNDS, TRACE_WIDTH, }; // MERKLE PROVER @@ -104,6 +104,8 @@ where type HashFn = H; type RandomCoin = DefaultRandomCoin; type TraceLde> = DefaultTraceLde; + type ConstraintEvaluator<'a, E: FieldElement> = + DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { let last_step = trace.length() - 1; @@ -115,4 +117,16 @@ where fn options(&self) -> &ProofOptions { &self.options } + + fn new_evaluator<'a, E>( + &self, + air: &'a Self::Air, + aux_rand_elements: winterfell::AuxTraceRandElements, + composition_coefficients: winterfell::ConstraintCompositionCoefficients, + ) -> Self::ConstraintEvaluator<'a, E> + where + E: FieldElement, + { + DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients) + } } diff --git a/examples/src/rescue/mod.rs b/examples/src/rescue/mod.rs index e704304b6..506e83347 100644 --- a/examples/src/rescue/mod.rs +++ b/examples/src/rescue/mod.rs @@ -10,7 +10,8 @@ use std::time::Instant; use winterfell::{ crypto::{DefaultRandomCoin, ElementHasher}, math::{fields::f128::BaseElement, FieldElement}, - DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, TraceTable, VerifierError, + DefaultConstraintEvaluator, DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, + TraceTable, VerifierError, }; #[allow(clippy::module_inception)] diff --git a/examples/src/rescue/prover.rs b/examples/src/rescue/prover.rs index 29acbdad2..2ef11ea37 100644 --- a/examples/src/rescue/prover.rs +++ b/examples/src/rescue/prover.rs @@ -4,9 +4,9 @@ // LICENSE file in the root directory of this source tree. use super::{ - rescue, BaseElement, DefaultRandomCoin, DefaultTraceLde, ElementHasher, FieldElement, - PhantomData, ProofOptions, Prover, PublicInputs, RescueAir, Trace, TraceTable, CYCLE_LENGTH, - NUM_HASH_ROUNDS, + rescue, BaseElement, DefaultConstraintEvaluator, DefaultRandomCoin, DefaultTraceLde, + ElementHasher, FieldElement, PhantomData, ProofOptions, Prover, PublicInputs, RescueAir, Trace, + TraceTable, CYCLE_LENGTH, NUM_HASH_ROUNDS, }; // RESCUE PROVER @@ -71,6 +71,8 @@ where type HashFn = H; type RandomCoin = DefaultRandomCoin; type TraceLde> = DefaultTraceLde; + type ConstraintEvaluator<'a, E: FieldElement> = + DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { let last_step = trace.length() - 1; @@ -83,4 +85,16 @@ where fn options(&self) -> &ProofOptions { &self.options } + + fn new_evaluator<'a, E>( + &self, + air: &'a Self::Air, + aux_rand_elements: winterfell::AuxTraceRandElements, + composition_coefficients: winterfell::ConstraintCompositionCoefficients, + ) -> Self::ConstraintEvaluator<'a, E> + where + E: FieldElement, + { + DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients) + } } diff --git a/examples/src/rescue_raps/mod.rs b/examples/src/rescue_raps/mod.rs index 4152d2bac..3e796d651 100644 --- a/examples/src/rescue_raps/mod.rs +++ b/examples/src/rescue_raps/mod.rs @@ -11,7 +11,8 @@ use std::time::Instant; use winterfell::{ crypto::{DefaultRandomCoin, ElementHasher}, math::{fields::f128::BaseElement, ExtensionOf, FieldElement}, - DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, VerifierError, + DefaultConstraintEvaluator, DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, + VerifierError, }; mod custom_trace_table; diff --git a/examples/src/rescue_raps/prover.rs b/examples/src/rescue_raps/prover.rs index e6ab7c0eb..4968d66a9 100644 --- a/examples/src/rescue_raps/prover.rs +++ b/examples/src/rescue_raps/prover.rs @@ -4,9 +4,9 @@ // LICENSE file in the root directory of this source tree. use super::{ - apply_rescue_round_parallel, rescue::STATE_WIDTH, BaseElement, DefaultRandomCoin, - DefaultTraceLde, ElementHasher, FieldElement, PhantomData, ProofOptions, Prover, PublicInputs, - RapTraceTable, RescueRapsAir, Trace, CYCLE_LENGTH, NUM_HASH_ROUNDS, + apply_rescue_round_parallel, rescue::STATE_WIDTH, BaseElement, DefaultConstraintEvaluator, + DefaultRandomCoin, DefaultTraceLde, ElementHasher, FieldElement, PhantomData, ProofOptions, + Prover, PublicInputs, RapTraceTable, RescueRapsAir, Trace, CYCLE_LENGTH, NUM_HASH_ROUNDS, }; // RESCUE PROVER @@ -99,6 +99,8 @@ where type HashFn = H; type RandomCoin = DefaultRandomCoin; type TraceLde> = DefaultTraceLde; + type ConstraintEvaluator<'a, E: FieldElement> = + DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { let last_step = trace.length() - 1; @@ -113,4 +115,16 @@ where fn options(&self) -> &ProofOptions { &self.options } + + fn new_evaluator<'a, E>( + &self, + air: &'a Self::Air, + aux_rand_elements: winterfell::AuxTraceRandElements, + composition_coefficients: winterfell::ConstraintCompositionCoefficients, + ) -> Self::ConstraintEvaluator<'a, E> + where + E: FieldElement, + { + DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients) + } } diff --git a/examples/src/vdf/exempt/mod.rs b/examples/src/vdf/exempt/mod.rs index d19dab8fd..bb6e7a096 100644 --- a/examples/src/vdf/exempt/mod.rs +++ b/examples/src/vdf/exempt/mod.rs @@ -10,7 +10,8 @@ use std::time::Instant; use winterfell::{ crypto::{DefaultRandomCoin, ElementHasher}, math::{fields::f128::BaseElement, FieldElement}, - DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, TraceTable, VerifierError, + DefaultConstraintEvaluator, DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, + TraceTable, VerifierError, }; mod air; diff --git a/examples/src/vdf/exempt/prover.rs b/examples/src/vdf/exempt/prover.rs index bcd80e7c9..8d6b17a59 100644 --- a/examples/src/vdf/exempt/prover.rs +++ b/examples/src/vdf/exempt/prover.rs @@ -4,8 +4,9 @@ // LICENSE file in the root directory of this source tree. use super::{ - BaseElement, DefaultRandomCoin, DefaultTraceLde, ElementHasher, FieldElement, PhantomData, - ProofOptions, Prover, Trace, TraceTable, VdfAir, VdfInputs, FORTY_TWO, INV_ALPHA, + BaseElement, DefaultConstraintEvaluator, DefaultRandomCoin, DefaultTraceLde, ElementHasher, + FieldElement, PhantomData, ProofOptions, Prover, Trace, TraceTable, VdfAir, VdfInputs, + FORTY_TWO, INV_ALPHA, }; // VDF PROVER @@ -51,6 +52,8 @@ where type HashFn = H; type RandomCoin = DefaultRandomCoin; type TraceLde> = DefaultTraceLde; + type ConstraintEvaluator<'a, E: FieldElement> = + DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> VdfInputs { // the result is read from the second to last step because the last last step contains @@ -65,4 +68,16 @@ where fn options(&self) -> &ProofOptions { &self.options } + + fn new_evaluator<'a, E>( + &self, + air: &'a Self::Air, + aux_rand_elements: winterfell::AuxTraceRandElements, + composition_coefficients: winterfell::ConstraintCompositionCoefficients, + ) -> Self::ConstraintEvaluator<'a, E> + where + E: FieldElement, + { + DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients) + } } diff --git a/examples/src/vdf/regular/mod.rs b/examples/src/vdf/regular/mod.rs index 12875afa6..bc47e5201 100644 --- a/examples/src/vdf/regular/mod.rs +++ b/examples/src/vdf/regular/mod.rs @@ -10,7 +10,8 @@ use std::time::Instant; use winterfell::{ crypto::{DefaultRandomCoin, ElementHasher}, math::{fields::f128::BaseElement, FieldElement}, - DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, TraceTable, VerifierError, + DefaultConstraintEvaluator, DefaultTraceLde, ProofOptions, Prover, StarkProof, Trace, + TraceTable, VerifierError, }; mod air; diff --git a/examples/src/vdf/regular/prover.rs b/examples/src/vdf/regular/prover.rs index 99462a753..457952223 100644 --- a/examples/src/vdf/regular/prover.rs +++ b/examples/src/vdf/regular/prover.rs @@ -4,8 +4,9 @@ // LICENSE file in the root directory of this source tree. use super::{ - BaseElement, DefaultRandomCoin, DefaultTraceLde, ElementHasher, FieldElement, PhantomData, - ProofOptions, Prover, Trace, TraceTable, VdfAir, VdfInputs, FORTY_TWO, INV_ALPHA, + BaseElement, DefaultConstraintEvaluator, DefaultRandomCoin, DefaultTraceLde, ElementHasher, + FieldElement, PhantomData, ProofOptions, Prover, Trace, TraceTable, VdfAir, VdfInputs, + FORTY_TWO, INV_ALPHA, }; // VDF PROVER @@ -48,6 +49,8 @@ where type HashFn = H; type RandomCoin = DefaultRandomCoin; type TraceLde> = DefaultTraceLde; + type ConstraintEvaluator<'a, E: FieldElement> = + DefaultConstraintEvaluator<'a, Self::Air, E>; fn get_pub_inputs(&self, trace: &Self::Trace) -> VdfInputs { let last_step = trace.length() - 1; @@ -60,4 +63,16 @@ where fn options(&self) -> &ProofOptions { &self.options } + + fn new_evaluator<'a, E>( + &self, + air: &'a Self::Air, + aux_rand_elements: winterfell::AuxTraceRandElements, + composition_coefficients: winterfell::ConstraintCompositionCoefficients, + ) -> Self::ConstraintEvaluator<'a, E> + where + E: FieldElement, + { + DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients) + } } diff --git a/prover/src/constraints/evaluator.rs b/prover/src/constraints/evaluator.rs index f5a324c98..83061ad6b 100644 --- a/prover/src/constraints/evaluator.rs +++ b/prover/src/constraints/evaluator.rs @@ -11,6 +11,7 @@ use air::{ Air, AuxTraceRandElements, ConstraintCompositionCoefficients, EvaluationFrame, TransitionConstraints, }; + use math::FieldElement; use utils::iter_mut; @@ -23,10 +24,23 @@ use utils::{iterators::*, rayon}; #[cfg(feature = "concurrent")] const MIN_CONCURRENT_DOMAIN_SIZE: usize = 8192; -// CONSTRAINT EVALUATOR +// CONSTRAINT EVALUATOR TRAIT +// ================================================================================================ + +pub trait ConstraintEvaluator<'a, E: FieldElement> { + type Air: Air; + + fn evaluate>( + self, + trace: &T, + domain: &'a StarkDomain, + ) -> ConstraintEvaluationTable<'a, E>; +} + +// CONSTRAINT EVALUATOR DEFAULT IMPLEMENTATION // ================================================================================================ -pub struct ConstraintEvaluator<'a, A: Air, E: FieldElement> { +pub struct DefaultConstraintEvaluator<'a, A: Air, E: FieldElement> { air: &'a A, boundary_constraints: BoundaryConstraints, transition_constraints: TransitionConstraints, @@ -34,47 +48,18 @@ pub struct ConstraintEvaluator<'a, A: Air, E: FieldElement, } -impl<'a, A: Air, E: FieldElement> ConstraintEvaluator<'a, A, E> { - // CONSTRUCTOR - // -------------------------------------------------------------------------------------------- - /// Returns a new evaluator which can be used to evaluate transition and boundary constraints - /// over extended execution trace. - pub fn new( - air: &'a A, - aux_rand_elements: AuxTraceRandElements, - composition_coefficients: ConstraintCompositionCoefficients, - ) -> Self { - // build transition constraint groups; these will be used to compose transition constraint - // evaluations - let transition_constraints = - air.get_transition_constraints(&composition_coefficients.transition); - - // build periodic value table - let periodic_values = PeriodicValueTable::new(air); - - // build boundary constraint groups; these will be used to evaluate and compose boundary - // constraint evaluations. - let boundary_constraints = - BoundaryConstraints::new(air, &aux_rand_elements, &composition_coefficients.boundary); - - ConstraintEvaluator { - air, - boundary_constraints, - transition_constraints, - aux_rand_elements, - periodic_values, - } - } +impl<'a, A: Air, E: FieldElement> ConstraintEvaluator<'a, E> + for DefaultConstraintEvaluator<'a, A, E> +{ + type Air = A; - // EVALUATOR - // -------------------------------------------------------------------------------------------- /// Evaluates constraints against the provided extended execution trace. Constraints are /// evaluated over a constraint evaluation domain. This is an optimization because constraint /// evaluation domain can be many times smaller than the full LDE domain. - pub fn evaluate>( + fn evaluate>( self, trace: &T, - domain: &'a StarkDomain, + domain: &'a StarkDomain<::BaseField>, ) -> ConstraintEvaluationTable<'a, E> { assert_eq!( trace.trace_len(), @@ -130,6 +115,38 @@ impl<'a, A: Air, E: FieldElement> ConstraintEvaluator< evaluation_table } +} +impl<'a, A: Air, E: FieldElement> DefaultConstraintEvaluator<'a, A, E> { + // CONSTRUCTOR + // -------------------------------------------------------------------------------------------- + /// Returns a new evaluator which can be used to evaluate transition and boundary constraints + /// over extended execution trace. + pub fn new( + air: &'a A, + aux_rand_elements: AuxTraceRandElements, + composition_coefficients: ConstraintCompositionCoefficients, + ) -> Self { + // build transition constraint groups; these will be used to compose transition constraint + // evaluations + let transition_constraints = + air.get_transition_constraints(&composition_coefficients.transition); + + // build periodic value table + let periodic_values = PeriodicValueTable::new(air); + + // build boundary constraint groups; these will be used to evaluate and compose boundary + // constraint evaluations. + let boundary_constraints = + BoundaryConstraints::new(air, &aux_rand_elements, &composition_coefficients.boundary); + + DefaultConstraintEvaluator { + air, + boundary_constraints, + transition_constraints, + aux_rand_elements, + periodic_values, + } + } // EVALUATION HELPERS // -------------------------------------------------------------------------------------------- diff --git a/prover/src/constraints/mod.rs b/prover/src/constraints/mod.rs index c8e18c296..e9348ea67 100644 --- a/prover/src/constraints/mod.rs +++ b/prover/src/constraints/mod.rs @@ -12,7 +12,7 @@ mod periodic_table; use periodic_table::PeriodicValueTable; mod evaluator; -pub use evaluator::ConstraintEvaluator; +pub use evaluator::{ConstraintEvaluator, DefaultConstraintEvaluator}; mod composition_poly; pub use composition_poly::CompositionPoly; diff --git a/prover/src/lib.rs b/prover/src/lib.rs index c3ce3c3bf..bcfca3fd1 100644 --- a/prover/src/lib.rs +++ b/prover/src/lib.rs @@ -79,8 +79,9 @@ pub mod matrix; pub use matrix::{ColMatrix, RowMatrix}; mod constraints; -use constraints::ConstraintEvaluator; -pub use constraints::{CompositionPoly, ConstraintCommitment}; +pub use constraints::{ + CompositionPoly, ConstraintCommitment, ConstraintEvaluator, DefaultConstraintEvaluator, +}; mod composer; use composer::DeepCompositionPoly; @@ -135,13 +136,18 @@ pub trait Prover { /// PRNG to be used for generating random field elements. type RandomCoin: RandomCoin; - // Trace low-degree extension for building the LDEs of trace segments and their commitments. + /// Trace low-degree extension for building the LDEs of trace segments and their commitments. type TraceLde>: TraceLde< BaseField = Self::BaseField, ExtensionField = E, HashFn = Self::HashFn, >; + /// Constraints evaluator used to evaluate AIR constraints over the extended execution trace. + type ConstraintEvaluator<'a, E>: ConstraintEvaluator<'a, E, Air = Self::Air> + where + E: FieldElement; + // REQUIRED METHODS // -------------------------------------------------------------------------------------------- @@ -158,6 +164,17 @@ pub trait Prover { /// proof size, and proof security level. fn options(&self) -> &ProofOptions; + /// Returns a new constraint evaluator which can be used to evaluate transition and boundary + /// constraints over the extended execution trace. + fn new_evaluator<'a, E>( + &self, + air: &'a Self::Air, + aux_rand_elements: AuxTraceRandElements, + composition_coefficients: ConstraintCompositionCoefficients, + ) -> Self::ConstraintEvaluator<'a, E> + where + E: FieldElement; + // PROVIDED METHODS // -------------------------------------------------------------------------------------------- @@ -295,7 +312,7 @@ pub trait Prover { #[cfg(feature = "std")] let now = Instant::now(); let constraint_coeffs = channel.get_constraint_composition_coeffs(); - let evaluator = ConstraintEvaluator::new(&air, aux_trace_rand_elements, constraint_coeffs); + let evaluator = self.new_evaluator(&air, aux_trace_rand_elements, constraint_coeffs); let constraint_evaluations = evaluator.evaluate(&trace_lde, &domain); #[cfg(feature = "std")] debug!( diff --git a/winterfell/src/lib.rs b/winterfell/src/lib.rs index d580e5510..341fb7215 100644 --- a/winterfell/src/lib.rs +++ b/winterfell/src/lib.rs @@ -261,7 +261,7 @@ //! }; //! //! # use winterfell::{ -//! # Air, AirContext, Assertion, ByteWriter, EvaluationFrame, TraceInfo, +//! # Air, AirContext, Assertion, ByteWriter, DefaultConstraintEvaluator, EvaluationFrame, TraceInfo, //! # TransitionConstraintDegree, //! # }; //! # @@ -342,7 +342,8 @@ //! type HashFn = Blake3_256; //! type RandomCoin = DefaultRandomCoin; //! type TraceLde> = DefaultTraceLde; -//! +//! type ConstraintEvaluator<'a, E: FieldElement> = DefaultConstraintEvaluator<'a, Self::Air, E>; +//! //! // Our public inputs consist of the first and last value in the execution trace. //! fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { //! let last_step = trace.length() - 1; @@ -355,6 +356,18 @@ //! fn options(&self) -> &ProofOptions { //! &self.options //! } +//! +//! fn new_evaluator<'a, E>( +//! &self, +//! air: &'a Self::Air, +//! aux_rand_elements: winterfell::AuxTraceRandElements, +//! composition_coefficients: winterfell::ConstraintCompositionCoefficients, +//! ) -> Self::ConstraintEvaluator<'a, E> +//! where +//! E: FieldElement, +//! { +//! DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients) +//! } //! } //! ``` //! @@ -368,7 +381,7 @@ //! ``` //! # use winterfell::{ //! # math::{fields::f128::BaseElement, FieldElement, ToElements}, -//! # Air, AirContext, Assertion, ByteWriter, DefaultTraceLde, EvaluationFrame, TraceInfo, +//! # Air, AirContext, Assertion, ByteWriter, DefaultConstraintEvaluator, DefaultTraceLde, EvaluationFrame, TraceInfo, //! # TransitionConstraintDegree, TraceTable, FieldExtension, Prover, ProofOptions, //! # StarkProof, Trace, crypto::{hashers::Blake3_256, DefaultRandomCoin}, //! # }; @@ -460,6 +473,7 @@ //! # type HashFn = Blake3_256; //! # type RandomCoin = DefaultRandomCoin; //! # type TraceLde> = DefaultTraceLde; +//! # type ConstraintEvaluator<'a, E: FieldElement> = DefaultConstraintEvaluator<'a, Self::Air, E>; //! # //! # fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs { //! # let last_step = trace.length() - 1; @@ -472,6 +486,19 @@ //! # fn options(&self) -> &ProofOptions { //! # &self.options //! # } +//! # +//! # fn new_evaluator<'a, E>( +//! # &self, +//! # air: &'a Self::Air, +//! # aux_rand_elements: winterfell::AuxTraceRandElements, +//! # composition_coefficients: winterfell::ConstraintCompositionCoefficients, +//! # ) -> Self::ConstraintEvaluator<'a, E> +//! # where +//! # E: FieldElement, +//! # { +//! # DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients) +//! # } +//! # //! # } //! # //! // We'll just hard-code the parameters here for this example. We'll also just run the @@ -534,9 +561,10 @@ pub use prover::{ crypto, iterators, math, Air, AirContext, Assertion, AuxTraceRandElements, BoundaryConstraint, BoundaryConstraintGroup, ByteReader, ByteWriter, ColMatrix, ConstraintCompositionCoefficients, - ConstraintDivisor, DeepCompositionCoefficients, DefaultTraceLde, Deserializable, - DeserializationError, EvaluationFrame, FieldExtension, ProofOptions, Prover, ProverError, - Serializable, SliceReader, StarkProof, Trace, TraceInfo, TraceLayout, TraceLde, TraceTable, - TraceTableFragment, TransitionConstraintDegree, + ConstraintDivisor, ConstraintEvaluator, DeepCompositionCoefficients, + DefaultConstraintEvaluator, DefaultTraceLde, Deserializable, DeserializationError, + EvaluationFrame, FieldExtension, ProofOptions, Prover, ProverError, Serializable, SliceReader, + StarkProof, Trace, TraceInfo, TraceLayout, TraceLde, TraceTable, TraceTableFragment, + TransitionConstraintDegree, }; pub use verifier::{verify, VerifierError};