Skip to content

Commit

Permalink
Merge pull request #217 from Al-Kindi-0/al-custom-constraint-evaluator
Browse files Browse the repository at this point in the history
Add ability for custom constraint evaluators
  • Loading branch information
irakliyk authored Sep 29, 2023
2 parents a2363b8 + 6fecb6a commit 19c0dcd
Show file tree
Hide file tree
Showing 28 changed files with 336 additions and 91 deletions.
3 changes: 2 additions & 1 deletion examples/src/fibonacci/fib2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 16 additions & 2 deletions examples/src/fibonacci/fib2/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -58,6 +58,8 @@ where
type HashFn = H;
type RandomCoin = DefaultRandomCoin<Self::HashFn>;
type TraceLde<E: FieldElement<BaseField = Self::BaseField>> = DefaultTraceLde<E, Self::HashFn>;
type ConstraintEvaluator<'a, E: FieldElement<BaseField = Self::BaseField>> =
DefaultConstraintEvaluator<'a, Self::Air, E>;

fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement {
let last_step = trace.length() - 1;
Expand All @@ -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<E>,
composition_coefficients: winterfell::ConstraintCompositionCoefficients<E>,
) -> Self::ConstraintEvaluator<'a, E>
where
E: FieldElement<BaseField = Self::BaseField>,
{
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
}
3 changes: 2 additions & 1 deletion examples/src/fibonacci/fib8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 16 additions & 2 deletions examples/src/fibonacci/fib8/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,6 +73,8 @@ where
type HashFn = H;
type RandomCoin = DefaultRandomCoin<Self::HashFn>;
type TraceLde<E: FieldElement<BaseField = Self::BaseField>> = DefaultTraceLde<E, Self::HashFn>;
type ConstraintEvaluator<'a, E: FieldElement<BaseField = Self::BaseField>> =
DefaultConstraintEvaluator<'a, Self::Air, E>;

fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement {
let last_step = trace.length() - 1;
Expand All @@ -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<E>,
composition_coefficients: winterfell::ConstraintCompositionCoefficients<E>,
) -> Self::ConstraintEvaluator<'a, E>
where
E: FieldElement<BaseField = Self::BaseField>,
{
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
}
3 changes: 2 additions & 1 deletion examples/src/fibonacci/fib_small/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 16 additions & 2 deletions examples/src/fibonacci/fib_small/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,6 +57,8 @@ where
type HashFn = H;
type RandomCoin = DefaultRandomCoin<Self::HashFn>;
type TraceLde<E: FieldElement<BaseField = Self::BaseField>> = DefaultTraceLde<E, Self::HashFn>;
type ConstraintEvaluator<'a, E: FieldElement<BaseField = Self::BaseField>> =
DefaultConstraintEvaluator<'a, Self::Air, E>;

fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement {
let last_step = trace.length() - 1;
Expand All @@ -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<E>,
composition_coefficients: winterfell::ConstraintCompositionCoefficients<E>,
) -> Self::ConstraintEvaluator<'a, E>
where
E: FieldElement<BaseField = Self::BaseField>,
{
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
}
3 changes: 2 additions & 1 deletion examples/src/fibonacci/mulfib2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 16 additions & 2 deletions examples/src/fibonacci/mulfib2/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -54,6 +54,8 @@ where
type HashFn = H;
type RandomCoin = DefaultRandomCoin<Self::HashFn>;
type TraceLde<E: FieldElement<BaseField = Self::BaseField>> = DefaultTraceLde<E, Self::HashFn>;
type ConstraintEvaluator<'a, E: FieldElement<BaseField = Self::BaseField>> =
DefaultConstraintEvaluator<'a, Self::Air, E>;

fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement {
let last_step = trace.length() - 1;
Expand All @@ -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<E>,
composition_coefficients: winterfell::ConstraintCompositionCoefficients<E>,
) -> Self::ConstraintEvaluator<'a, E>
where
E: FieldElement<BaseField = Self::BaseField>,
{
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
}
3 changes: 2 additions & 1 deletion examples/src/fibonacci/mulfib8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 16 additions & 2 deletions examples/src/fibonacci/mulfib8/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -66,6 +66,8 @@ where
type HashFn = H;
type RandomCoin = DefaultRandomCoin<Self::HashFn>;
type TraceLde<E: FieldElement<BaseField = Self::BaseField>> = DefaultTraceLde<E, Self::HashFn>;
type ConstraintEvaluator<'a, E: FieldElement<BaseField = Self::BaseField>> =
DefaultConstraintEvaluator<'a, Self::Air, E>;

fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement {
let last_step = trace.length() - 1;
Expand All @@ -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<E>,
composition_coefficients: winterfell::ConstraintCompositionCoefficients<E>,
) -> Self::ConstraintEvaluator<'a, E>
where
E: FieldElement<BaseField = Self::BaseField>,
{
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
}
3 changes: 2 additions & 1 deletion examples/src/lamport/aggregate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 18 additions & 3 deletions examples/src/lamport/aggregate/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -98,6 +99,8 @@ where
type HashFn = H;
type RandomCoin = DefaultRandomCoin<Self::HashFn>;
type TraceLde<E: FieldElement<BaseField = Self::BaseField>> = DefaultTraceLde<E, Self::HashFn>;
type ConstraintEvaluator<'a, E: FieldElement<BaseField = Self::BaseField>> =
DefaultConstraintEvaluator<'a, Self::Air, E>;

fn get_pub_inputs(&self, _trace: &Self::Trace) -> PublicInputs {
self.pub_inputs.clone()
Expand All @@ -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<E>,
composition_coefficients: winterfell::ConstraintCompositionCoefficients<E>,
) -> Self::ConstraintEvaluator<'a, E>
where
E: FieldElement<BaseField = Self::BaseField>,
{
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
}

// TRACE INITIALIZATION
Expand Down
3 changes: 2 additions & 1 deletion examples/src/lamport/threshold/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 18 additions & 4 deletions examples/src/lamport/threshold/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -140,6 +140,8 @@ where
type HashFn = H;
type RandomCoin = DefaultRandomCoin<Self::HashFn>;
type TraceLde<E: FieldElement<BaseField = Self::BaseField>> = DefaultTraceLde<E, Self::HashFn>;
type ConstraintEvaluator<'a, E: FieldElement<BaseField = Self::BaseField>> =
DefaultConstraintEvaluator<'a, Self::Air, E>;

fn get_pub_inputs(&self, _trace: &Self::Trace) -> PublicInputs {
self.pub_inputs.clone()
Expand All @@ -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<E>,
composition_coefficients: winterfell::ConstraintCompositionCoefficients<E>,
) -> Self::ConstraintEvaluator<'a, E>
where
E: FieldElement<BaseField = Self::BaseField>,
{
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
}

// TRACE INITIALIZATION
Expand Down
3 changes: 2 additions & 1 deletion examples/src/merkle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 17 additions & 3 deletions examples/src/merkle/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -104,6 +104,8 @@ where
type HashFn = H;
type RandomCoin = DefaultRandomCoin<Self::HashFn>;
type TraceLde<E: FieldElement<BaseField = Self::BaseField>> = DefaultTraceLde<E, Self::HashFn>;
type ConstraintEvaluator<'a, E: FieldElement<BaseField = Self::BaseField>> =
DefaultConstraintEvaluator<'a, Self::Air, E>;

fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs {
let last_step = trace.length() - 1;
Expand All @@ -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<E>,
composition_coefficients: winterfell::ConstraintCompositionCoefficients<E>,
) -> Self::ConstraintEvaluator<'a, E>
where
E: FieldElement<BaseField = Self::BaseField>,
{
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}
}
3 changes: 2 additions & 1 deletion examples/src/rescue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Loading

0 comments on commit 19c0dcd

Please sign in to comment.