Skip to content

Commit

Permalink
fix: simplify constraint eval trait + misc nits
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Kindi-0 committed Sep 27, 2023
1 parent af8385e commit 41e29c6
Show file tree
Hide file tree
Showing 26 changed files with 102 additions and 137 deletions.
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -91,7 +92,7 @@ impl<H: ElementHasher> FibExample<H> {

impl<H: ElementHasher> Example for FibExample<H>
where
H: ElementHasher<BaseField = BaseElement> + std::marker::Sync,
H: ElementHasher<BaseField = BaseElement>,
{
fn prove(&self) -> StarkProof {
debug!(
Expand Down
10 changes: 4 additions & 6 deletions examples/src/fibonacci/fib2/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

use winterfell::DefaultConstraintEvaluator;

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 @@ -52,7 +50,7 @@ impl<H: ElementHasher> FibProver<H> {

impl<H: ElementHasher> Prover for FibProver<H>
where
H: ElementHasher<BaseField = BaseElement> + std::marker::Sync,
H: ElementHasher<BaseField = BaseElement>,
{
type BaseField = BaseElement;
type Air = FibAir;
Expand All @@ -61,7 +59,7 @@ where
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, Self::HashFn>;
DefaultConstraintEvaluator<'a, Self::Air, E>;

fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement {
let last_step = trace.length() - 1;
Expand Down
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -91,7 +92,7 @@ impl<H: ElementHasher> Fib8Example<H> {

impl<H: ElementHasher> Example for Fib8Example<H>
where
H: ElementHasher<BaseField = BaseElement> + std::marker::Sync,
H: ElementHasher<BaseField = BaseElement>,
{
fn prove(&self) -> StarkProof {
debug!(
Expand Down
10 changes: 4 additions & 6 deletions examples/src/fibonacci/fib8/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

use winterfell::DefaultConstraintEvaluator;

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 @@ -67,7 +65,7 @@ impl<H: ElementHasher> Fib8Prover<H> {

impl<H: ElementHasher> Prover for Fib8Prover<H>
where
H: ElementHasher<BaseField = BaseElement> + std::marker::Sync,
H: ElementHasher<BaseField = BaseElement>,
{
type BaseField = BaseElement;
type Air = Fib8Air;
Expand All @@ -76,7 +74,7 @@ where
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, Self::HashFn>;
DefaultConstraintEvaluator<'a, Self::Air, E>;

fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement {
let last_step = trace.length() - 1;
Expand Down
2 changes: 1 addition & 1 deletion examples/src/fibonacci/fib_small/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl<H: ElementHasher> FibExample<H> {

impl<H: ElementHasher> Example for FibExample<H>
where
H: ElementHasher<BaseField = BaseElement> + std::marker::Sync,
H: ElementHasher<BaseField = BaseElement>,
{
fn prove(&self) -> StarkProof {
debug!(
Expand Down
4 changes: 2 additions & 2 deletions examples/src/fibonacci/fib_small/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<H: ElementHasher> FibSmallProver<H> {

impl<H: ElementHasher> Prover for FibSmallProver<H>
where
H: ElementHasher<BaseField = BaseElement> + std::marker::Sync,
H: ElementHasher<BaseField = BaseElement>,
{
type BaseField = BaseElement;
type Air = FibSmall;
Expand All @@ -58,7 +58,7 @@ where
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, Self::HashFn>;
DefaultConstraintEvaluator<'a, Self::Air, E>;

fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement {
let last_step = trace.length() - 1;
Expand Down
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -85,7 +86,7 @@ impl<H: ElementHasher> MulFib2Example<H> {

impl<H: ElementHasher> Example for MulFib2Example<H>
where
H: ElementHasher<BaseField = BaseElement> + std::marker::Sync,
H: ElementHasher<BaseField = BaseElement>,
{
fn prove(&self) -> StarkProof {
let sequence_length = self.sequence_length;
Expand Down
10 changes: 4 additions & 6 deletions examples/src/fibonacci/mulfib2/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

use winterfell::DefaultConstraintEvaluator;

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 @@ -48,7 +46,7 @@ impl<H: ElementHasher> MulFib2Prover<H> {

impl<H: ElementHasher> Prover for MulFib2Prover<H>
where
H: ElementHasher<BaseField = BaseElement> + std::marker::Sync,
H: ElementHasher<BaseField = BaseElement>,
{
type BaseField = BaseElement;
type Air = MulFib2Air;
Expand All @@ -57,7 +55,7 @@ where
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, Self::HashFn>;
DefaultConstraintEvaluator<'a, Self::Air, E>;

fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement {
let last_step = trace.length() - 1;
Expand Down
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -86,7 +87,7 @@ impl<H: ElementHasher> MulFib8Example<H> {

impl<H: ElementHasher> Example for MulFib8Example<H>
where
H: ElementHasher<BaseField = BaseElement> + std::marker::Sync,
H: ElementHasher<BaseField = BaseElement>,
{
fn prove(&self) -> StarkProof {
let sequence_length = self.sequence_length;
Expand Down
10 changes: 4 additions & 6 deletions examples/src/fibonacci/mulfib8/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

use winterfell::DefaultConstraintEvaluator;

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 @@ -60,7 +58,7 @@ impl<H: ElementHasher> MulFib8Prover<H> {

impl<H: ElementHasher> Prover for MulFib8Prover<H>
where
H: ElementHasher<BaseField = BaseElement> + std::marker::Sync,
H: ElementHasher<BaseField = BaseElement>,
{
type BaseField = BaseElement;
type Air = MulFib8Air;
Expand All @@ -69,7 +67,7 @@ where
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, Self::HashFn>;
DefaultConstraintEvaluator<'a, Self::Air, E>;

fn get_pub_inputs(&self, trace: &Self::Trace) -> BaseElement {
let last_step = trace.length() - 1;
Expand Down
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -126,7 +127,7 @@ impl<H: ElementHasher> LamportAggregateExample<H> {

impl<H: ElementHasher> Example for LamportAggregateExample<H>
where
H: ElementHasher<BaseField = BaseElement> + std::marker::Sync,
H: ElementHasher<BaseField = BaseElement>,
{
fn prove(&self) -> StarkProof {
// generate the execution trace
Expand Down
12 changes: 6 additions & 6 deletions examples/src/lamport/aggregate/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
// 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")]
use winterfell::iterators::*;
use winterfell::DefaultConstraintEvaluator;

// CONSTANTS
// ================================================================================================
Expand Down Expand Up @@ -91,7 +91,7 @@ impl<H: ElementHasher> LamportAggregateProver<H> {

impl<H: ElementHasher> Prover for LamportAggregateProver<H>
where
H: ElementHasher<BaseField = BaseElement> + std::marker::Sync,
H: ElementHasher<BaseField = BaseElement>,
{
type BaseField = BaseElement;
type Air = LamportAggregateAir;
Expand All @@ -100,7 +100,7 @@ where
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, Self::HashFn>;
DefaultConstraintEvaluator<'a, Self::Air, E>;

fn get_pub_inputs(&self, _trace: &Self::Trace) -> PublicInputs {
self.pub_inputs.clone()
Expand Down
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -116,7 +117,7 @@ impl<H: ElementHasher> LamportThresholdExample<H> {

impl<H: ElementHasher> Example for LamportThresholdExample<H>
where
H: ElementHasher<BaseField = BaseElement> + std::marker::Sync,
H: ElementHasher<BaseField = BaseElement>,
{
fn prove(&self) -> StarkProof {
// generate the execution trace
Expand Down
13 changes: 6 additions & 7 deletions examples/src/lamport/threshold/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
// 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;

#[cfg(feature = "concurrent")]
use winterfell::iterators::*;
use winterfell::DefaultConstraintEvaluator;

// CONSTANTS
// ================================================================================================
Expand Down Expand Up @@ -133,7 +132,7 @@ impl<H: ElementHasher> LamportThresholdProver<H> {

impl<H: ElementHasher> Prover for LamportThresholdProver<H>
where
H: ElementHasher<BaseField = BaseElement> + std::marker::Sync,
H: ElementHasher<BaseField = BaseElement>,
{
type BaseField = BaseElement;
type Air = LamportThresholdAir;
Expand All @@ -142,7 +141,7 @@ where
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, Self::HashFn>;
DefaultConstraintEvaluator<'a, Self::Air, E>;

fn get_pub_inputs(&self, _trace: &Self::Trace) -> PublicInputs {
self.pub_inputs.clone()
Expand Down
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -111,7 +112,7 @@ impl<H: ElementHasher> MerkleExample<H> {

impl<H: ElementHasher> Example for MerkleExample<H>
where
H: ElementHasher<BaseField = BaseElement> + std::marker::Sync,
H: ElementHasher<BaseField = BaseElement>,
{
fn prove(&self) -> StarkProof {
// generate the execution trace
Expand Down
12 changes: 5 additions & 7 deletions examples/src/merkle/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

use winterfell::DefaultConstraintEvaluator;

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 @@ -98,7 +96,7 @@ impl<H: ElementHasher> MerkleProver<H> {

impl<H: ElementHasher> Prover for MerkleProver<H>
where
H: ElementHasher<BaseField = BaseElement> + std::marker::Sync,
H: ElementHasher<BaseField = BaseElement>,
{
type BaseField = BaseElement;
type Air = MerkleAir;
Expand All @@ -107,7 +105,7 @@ where
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, Self::HashFn>;
DefaultConstraintEvaluator<'a, Self::Air, E>;

fn get_pub_inputs(&self, trace: &Self::Trace) -> PublicInputs {
let last_step = trace.length() - 1;
Expand Down
Loading

0 comments on commit 41e29c6

Please sign in to comment.