Skip to content

Commit

Permalink
chore: fix after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Kindi-0 committed Nov 8, 2024
1 parent d11f56a commit 5c7563c
Show file tree
Hide file tree
Showing 34 changed files with 157 additions and 154 deletions.
2 changes: 0 additions & 2 deletions air/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ libm = "0.2"
math = { version = "0.10", path = "../math", package = "winter-math", default-features = false }
utils = { version = "0.10", path = "../utils/core", package = "winter-utils", default-features = false }

libc-print = "0.1.23"

[dev-dependencies]
rand-utils = { version = "0.10", path = "../utils/rand", package = "winter-rand-utils" }

Expand Down
14 changes: 3 additions & 11 deletions air/src/air/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,8 @@ impl<B: StarkField> AirContext<B> {
let trace_length_ext = self.trace_length_ext();
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_ext - 1)
/ trace_length_ext;
(highest_constraint_degree - transition_divisior_degree).div_ceil(trace_length_ext);

if self.zk_parameters.is_some() {
let quotient_degree = if highest_constraint_degree < trace_length_ext {
Expand All @@ -351,8 +349,7 @@ impl<B: StarkField> AirContext<B> {
let n_q = self.options.num_queries();
let den = self.trace_length_ext() - (n_q + 1);

// we use the identity: ceil(a/b) = (a + b - 1)/b
(quotient_degree + 1 + den - 1) / den
(quotient_degree + 1).div_ceil(den)
} else {
cmp::max(num_constraint_col, 1)
}
Expand All @@ -374,9 +371,6 @@ impl<B: StarkField> AirContext<B> {
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).div_ceil(trace_length);
// highest_constraint_degree - transition_divisior_degree
if highest_constraint_degree < self.trace_length_ext {
// This means that our transition constraints have degree 1 and hence the boundary
Expand All @@ -392,9 +386,7 @@ impl<B: StarkField> AirContext<B> {
let num_constraint_composition_cols = self.num_constraint_composition_columns();
let quotient_degree = self.constraint_composition_degree();

// we use the identity: ceil(a/b) = (a + b - 1)/b
(quotient_degree + 1 + num_constraint_composition_cols - 1)
/ num_constraint_composition_cols
(quotient_degree + 1).div_ceil(num_constraint_composition_cols)
} else {
self.trace_len()
}
Expand Down
2 changes: 1 addition & 1 deletion air/src/air/transition/degree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl TransitionConstraintDegree {
// TODO: update documentation
let degree_bound = self.base + self.cycles.len();
let q_deg = degree_bound * (trace_length_ext - 1) - (trace_length - 1);
let blowup_factor = (q_deg + trace_length_ext - 1) / trace_length_ext;
let blowup_factor = q_deg.div_ceil(trace_length_ext);

cmp::max(blowup_factor.next_power_of_two(), ProofOptions::MIN_BLOWUP_FACTOR)
}
Expand Down
2 changes: 1 addition & 1 deletion air/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl ProofOptions {
fri_folding_factor: fri_folding_factor as u8,
fri_remainder_max_degree: fri_remainder_max_degree as u8,
partition_options: PartitionOptions::new(1, 1),
is_zk
is_zk,
}
}

Expand Down
1 change: 0 additions & 1 deletion crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ blake3 = { version = "1.5", default-features = false }
math = { version = "0.10", path = "../math", package = "winter-math", default-features = false }
sha3 = { version = "0.10", default-features = false }
utils = { version = "0.10", path = "../utils/core", package = "winter-utils", default-features = false }
utils = { version = "0.9", path = "../utils/core", package = "winter-utils", default-features = false }
rand = { version = "0.8" }

[dev-dependencies]
Expand Down
1 change: 0 additions & 1 deletion crypto/src/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub trait VectorCommitment<H: Hasher>: Sized {
fn commitment(&self) -> H::Digest;

/// Returns the length of the vector committed to for `Self`.
fn domain_len(&self) -> usize;
fn get_domain_len(&self) -> usize;

/// Returns the length of the vector committed to for `Self::Proof`.
Expand Down
31 changes: 18 additions & 13 deletions crypto/src/merkle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ use alloc::{
};
use core::slice;

use rand::{
distributions::{Distribution, Standard},
thread_rng, Rng, RngCore,
};

use crate::{
errors::MerkleTreeError,
hash::{ByteDigest, Hasher},
Expand All @@ -18,8 +23,6 @@ use crate::{
mod proofs;
pub use proofs::BatchMerkleProof;

use crate::{Hasher, MerkleTreeError, VectorCommitment};

#[cfg(feature = "concurrent")]
pub mod concurrent;

Expand Down Expand Up @@ -103,6 +106,17 @@ pub struct MerkleTree<H: Hasher> {
/// up to the root (excluding the root itself).
pub type MerkleTreeOpening<H> = (<H as Hasher>::Digest, Vec<<H as Hasher>::Digest>);

/// Salted Merkle tree opening consisting of a leaf value, a salt, and a Merkle path leading
/// from this leaf up to the root (excluding the root itself).
pub type SaltedMerkleTreeOpening<H> =
(<H as Hasher>::Digest, (<H as Hasher>::Digest, Vec<<H as Hasher>::Digest>));

/// Salted Merkle tree multi opening consisting of a vector of leaves, a vector of corresponding salts,
/// and a collection of corresponding Merkle paths leading from these leaves up to the root
/// (excluding the root itself). The collection of Merkle paths is stored as a [BatchMerkleProof].
pub type SaltedMerkleTreeMultiOpening<H> =
(Vec<<H as Hasher>::Digest>, (Vec<<H as Hasher>::Digest>, BatchMerkleProof<H>));

// MERKLE TREE IMPLEMENTATION
// ================================================================================================

Expand Down Expand Up @@ -422,7 +436,6 @@ impl<H: Hasher> VectorCommitment<H> for MerkleTree<H> {
*self.root()
}

fn domain_len(&self) -> usize {
fn get_domain_len(&self) -> usize {
1 << self.depth()
}
Expand Down Expand Up @@ -468,11 +481,6 @@ impl<H: Hasher> VectorCommitment<H> for MerkleTree<H> {
// SALTED MERKLE TREE
// ================================================================================================

use rand::{
distributions::{Distribution, Standard},
thread_rng, Rng, RngCore,
};

pub struct SaltedMerkleTree<H: Hasher> {
leaves: Vec<H::Digest>,
tree: MerkleTree<H>,
Expand Down Expand Up @@ -517,18 +525,15 @@ where
self.tree.depth()
}

pub fn prove(
&self,
index: usize,
) -> Result<(H::Digest, (H::Digest, Vec<H::Digest>)), MerkleTreeError> {
pub fn prove(&self, index: usize) -> Result<SaltedMerkleTreeOpening<H>, MerkleTreeError> {
let (_, proof) = self.tree.prove(index)?;
Ok((self.leaves[index], (self.salts[index], proof)))
}

pub fn prove_batch(
&self,
indexes: &[usize],
) -> Result<(Vec<H::Digest>, (Vec<H::Digest>, BatchMerkleProof<H>)), MerkleTreeError> {
) -> Result<SaltedMerkleTreeMultiOpening<H>, MerkleTreeError> {
let (_, proof) = self.tree.prove_batch(indexes)?;
let leaves_at_indices = indexes.iter().map(|index| self.leaves[*index]).collect();
let salts_at_indices = indexes.iter().map(|index| self.salts[*index]).collect();
Expand Down
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ default = ["std"]
std = ["core-utils/std", "hex/std", "rand-utils", "winterfell/std"]

[dependencies]
air = { version = "0.9", path = "../air", package = "winter-air", default-features = false }
air = { version = "0.10", path = "../air", package = "winter-air", default-features = false }
blake3 = { version = "1.5", default-features = false }
core-utils = { version = "0.10", path = "../utils/core", package = "winter-utils", default-features = false }
hex = { version = "0.4", optional = true }
Expand Down
11 changes: 8 additions & 3 deletions examples/src/fibonacci/fib2/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use winterfell::{
crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo,
TracePolyTable, TraceTable,
DefaultConstraintEvaluator, DefaultTraceLde, StarkDomain, Trace, TraceInfo, TracePolyTable,
TraceTable,
};

use super::{
Expand Down Expand Up @@ -85,7 +83,14 @@ where
zk_parameters: Option<ZkParameters>,
) -> (Self::TraceLde<E>, TracePolyTable<E>) {
let mut prng = ChaCha20Rng::from_entropy();
DefaultTraceLde::new(trace_info, main_trace, domain, partition_option, zk_parameters, &mut prng)
DefaultTraceLde::new(
trace_info,
main_trace,
domain,
partition_option,
zk_parameters,
&mut prng,
)
}

fn new_evaluator<'a, E: FieldElement<BaseField = Self::BaseField>>(
Expand Down
11 changes: 8 additions & 3 deletions examples/src/fibonacci/fib8/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use winterfell::{
crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo,
TracePolyTable, TraceTable,
DefaultConstraintEvaluator, DefaultTraceLde, StarkDomain, Trace, TraceInfo, TracePolyTable,
TraceTable,
};

use super::{
Expand Down Expand Up @@ -100,7 +98,14 @@ where
zk_parameters: Option<ZkParameters>,
) -> (Self::TraceLde<E>, TracePolyTable<E>) {
let mut prng = ChaCha20Rng::from_entropy();
DefaultTraceLde::new(trace_info, main_trace, domain, partition_option, zk_parameters, &mut prng)
DefaultTraceLde::new(
trace_info,
main_trace,
domain,
partition_option,
zk_parameters,
&mut prng,
)
}

fn new_evaluator<'a, E: FieldElement<BaseField = Self::BaseField>>(
Expand Down
5 changes: 2 additions & 3 deletions examples/src/fibonacci/fib_small/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use air::ZkParameters;
use rand_chacha::{rand_core::SeedableRng, ChaCha20Rng};
use winterfell::{
crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
DefaultConstraintEvaluator, DefaultConstraintEvaluator, DefaultTraceLde, DefaultTraceLde,
PartitionOptions, StarkDomain, StarkDomain, Trace, Trace, TraceInfo, TraceInfo, TracePolyTable,
TracePolyTable, TraceTable, TraceTable,
DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo,
TracePolyTable, TraceTable,
};

use super::{
Expand Down
11 changes: 8 additions & 3 deletions examples/src/fibonacci/mulfib2/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use winterfell::{
crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo,
TracePolyTable, TraceTable,
DefaultConstraintEvaluator, DefaultTraceLde, StarkDomain, Trace, TraceInfo, TracePolyTable,
TraceTable,
};

use super::{
Expand Down Expand Up @@ -81,7 +79,14 @@ where
zk_parameters: Option<ZkParameters>,
) -> (Self::TraceLde<E>, TracePolyTable<E>) {
let mut prng = ChaCha20Rng::from_entropy();
DefaultTraceLde::new(trace_info, main_trace, domain, partition_option, zk_parameters, &mut prng)
DefaultTraceLde::new(
trace_info,
main_trace,
domain,
partition_option,
zk_parameters,
&mut prng,
)
}

fn new_evaluator<'a, E: FieldElement<BaseField = Self::BaseField>>(
Expand Down
11 changes: 8 additions & 3 deletions examples/src/fibonacci/mulfib8/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use winterfell::{
crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo,
TracePolyTable, TraceTable,
DefaultConstraintEvaluator, DefaultTraceLde, StarkDomain, Trace, TraceInfo, TracePolyTable,
TraceTable,
};

use super::{
Expand Down Expand Up @@ -93,7 +91,14 @@ where
zk_parameters: Option<ZkParameters>,
) -> (Self::TraceLde<E>, TracePolyTable<E>) {
let mut prng = ChaCha20Rng::from_entropy();
DefaultTraceLde::new(trace_info, main_trace, domain, partition_option, zk_parameters, &mut prng)
DefaultTraceLde::new(
trace_info,
main_trace,
domain,
partition_option,
zk_parameters,
&mut prng,
)
}

fn new_evaluator<'a, E: FieldElement<BaseField = Self::BaseField>>(
Expand Down
5 changes: 2 additions & 3 deletions examples/src/lamport/aggregate/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ use rand_chacha::{rand_core::SeedableRng, ChaCha20Rng};
use winterfell::iterators::*;
use winterfell::{
crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
DefaultConstraintEvaluator, DefaultConstraintEvaluator, DefaultTraceLde, DefaultTraceLde,
PartitionOptions, StarkDomain, StarkDomain, TraceInfo, TraceInfo, TracePolyTable,
TracePolyTable, TraceTable, TraceTable,
DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, TraceInfo,
TracePolyTable, TraceTable,
};

use super::{
Expand Down
11 changes: 8 additions & 3 deletions examples/src/lamport/threshold/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ use winterfell::{
crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, TraceInfo,
TracePolyTable, TraceTable,
DefaultConstraintEvaluator, DefaultTraceLde, StarkDomain, TraceInfo, TracePolyTable,
TraceTable,
};

use super::{
Expand Down Expand Up @@ -171,7 +169,14 @@ where
zk_parameters: Option<ZkParameters>,
) -> (Self::TraceLde<E>, TracePolyTable<E>) {
let mut prng = ChaCha20Rng::from_entropy();
DefaultTraceLde::new(trace_info, main_trace, domain, partition_option, zk_parameters, &mut prng)
DefaultTraceLde::new(
trace_info,
main_trace,
domain,
partition_option,
zk_parameters,
&mut prng,
)
}

fn new_evaluator<'a, E: FieldElement<BaseField = Self::BaseField>>(
Expand Down
11 changes: 8 additions & 3 deletions examples/src/merkle/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use winterfell::{
crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo,
TracePolyTable, TraceTable,
DefaultConstraintEvaluator, DefaultTraceLde, StarkDomain, Trace, TraceInfo, TracePolyTable,
TraceTable,
};

use super::{
Expand Down Expand Up @@ -136,7 +134,14 @@ where
zk_parameters: Option<ZkParameters>,
) -> (Self::TraceLde<E>, TracePolyTable<E>) {
let mut prng = ChaCha20Rng::from_entropy();
DefaultTraceLde::new(trace_info, main_trace, domain, partition_option, zk_parameters, &mut prng)
DefaultTraceLde::new(
trace_info,
main_trace,
domain,
partition_option,
zk_parameters,
&mut prng,
)
}

fn new_evaluator<'a, E: FieldElement<BaseField = Self::BaseField>>(
Expand Down
11 changes: 8 additions & 3 deletions examples/src/rescue/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use winterfell::{
crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo,
TracePolyTable, TraceTable,
DefaultConstraintEvaluator, DefaultTraceLde, StarkDomain, Trace, TraceInfo, TracePolyTable,
TraceTable,
};

use super::{
Expand Down Expand Up @@ -103,7 +101,14 @@ where
zk_parameters: Option<ZkParameters>,
) -> (Self::TraceLde<E>, TracePolyTable<E>) {
let mut prng = ChaCha20Rng::from_entropy();
DefaultTraceLde::new(trace_info, main_trace, domain, partition_option, zk_parameters, &mut prng)
DefaultTraceLde::new(
trace_info,
main_trace,
domain,
partition_option,
zk_parameters,
&mut prng,
)
}

fn new_evaluator<'a, E: FieldElement<BaseField = Self::BaseField>>(
Expand Down
10 changes: 8 additions & 2 deletions examples/src/rescue_raps/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use winterfell::{
crypto::MerkleTree, matrix::ColMatrix, AuxRandElements, ConstraintCompositionCoefficients,
DefaultConstraintEvaluator, DefaultTraceLde, PartitionOptions, StarkDomain, Trace, TraceInfo,
TracePolyTable,
DefaultConstraintEvaluator, DefaultTraceLde, StarkDomain, Trace, TraceInfo, TracePolyTable,
};

use super::{
Expand Down Expand Up @@ -134,7 +133,14 @@ where
zk_parameters: Option<ZkParameters>,
) -> (Self::TraceLde<E>, TracePolyTable<E>) {
let mut prng = ChaCha20Rng::from_entropy();
DefaultTraceLde::new(trace_info, main_trace, domain, partition_option, zk_parameters, &mut prng)
DefaultTraceLde::new(
trace_info,
main_trace,
domain,
partition_option,
zk_parameters,
&mut prng,
)
}

fn new_evaluator<'a, E: FieldElement<BaseField = Self::BaseField>>(
Expand Down
Loading

0 comments on commit 5c7563c

Please sign in to comment.