From 5c7563cb4d8de6f668756675b552f9cd0c958cdb Mon Sep 17 00:00:00 2001 From: Al-Kindi-0 <82364884+Al-Kindi-0@users.noreply.github.com> Date: Fri, 8 Nov 2024 08:27:29 +0100 Subject: [PATCH] chore: fix after merge --- air/Cargo.toml | 2 - air/src/air/context.rs | 14 ++---- air/src/air/transition/degree.rs | 2 +- air/src/options.rs | 2 +- crypto/Cargo.toml | 1 - crypto/src/commitment.rs | 1 - crypto/src/merkle/mod.rs | 31 +++++++------ examples/Cargo.toml | 2 +- examples/src/fibonacci/fib2/prover.rs | 11 +++-- examples/src/fibonacci/fib8/prover.rs | 11 +++-- examples/src/fibonacci/fib_small/prover.rs | 5 +- examples/src/fibonacci/mulfib2/prover.rs | 11 +++-- examples/src/fibonacci/mulfib8/prover.rs | 11 +++-- examples/src/lamport/aggregate/prover.rs | 5 +- examples/src/lamport/threshold/prover.rs | 11 +++-- examples/src/merkle/prover.rs | 11 +++-- examples/src/rescue/prover.rs | 11 +++-- examples/src/rescue_raps/prover.rs | 10 +++- examples/src/vdf/exempt/prover.rs | 11 +++-- examples/src/vdf/regular/prover.rs | 11 +++-- examples/src/vdf/regular/tests.rs | 2 +- prover/Cargo.toml | 9 ++-- prover/benches/lagrange_kernel.rs | 13 ++++-- prover/src/channel.rs | 2 +- prover/src/constraints/commitment.rs | 2 +- prover/src/constraints/composition_poly.rs | 6 +-- prover/src/lib.rs | 8 +--- prover/src/matrix/col_matrix.rs | 15 +++--- prover/src/trace/trace_lde/default/mod.rs | 54 +++++----------------- prover/src/trace/trace_lde/mod.rs | 2 - verifier/Cargo.toml | 2 - verifier/src/channel.rs | 7 --- winterfell/src/lib.rs | 3 +- winterfell/src/tests.rs | 12 +++-- 34 files changed, 157 insertions(+), 154 deletions(-) diff --git a/air/Cargo.toml b/air/Cargo.toml index 27836772c..12c56cd72 100644 --- a/air/Cargo.toml +++ b/air/Cargo.toml @@ -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" } diff --git a/air/src/air/context.rs b/air/src/air/context.rs index bc202748b..c7412aece 100644 --- a/air/src/air/context.rs +++ b/air/src/air/context.rs @@ -335,10 +335,8 @@ impl AirContext { 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 { @@ -351,8 +349,7 @@ impl AirContext { 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) } @@ -374,9 +371,6 @@ impl AirContext { 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 @@ -392,9 +386,7 @@ impl AirContext { 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() } diff --git a/air/src/air/transition/degree.rs b/air/src/air/transition/degree.rs index aadf1c27a..9f5b99f69 100644 --- a/air/src/air/transition/degree.rs +++ b/air/src/air/transition/degree.rs @@ -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) } diff --git a/air/src/options.rs b/air/src/options.rs index 299dc28d8..92295787c 100644 --- a/air/src/options.rs +++ b/air/src/options.rs @@ -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, } } diff --git a/crypto/Cargo.toml b/crypto/Cargo.toml index d54a02c27..b02b4d62b 100644 --- a/crypto/Cargo.toml +++ b/crypto/Cargo.toml @@ -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] diff --git a/crypto/src/commitment.rs b/crypto/src/commitment.rs index 8217f851c..72ec674e7 100644 --- a/crypto/src/commitment.rs +++ b/crypto/src/commitment.rs @@ -49,7 +49,6 @@ pub trait VectorCommitment: 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`. diff --git a/crypto/src/merkle/mod.rs b/crypto/src/merkle/mod.rs index 2c7cc2a19..bee8207f1 100644 --- a/crypto/src/merkle/mod.rs +++ b/crypto/src/merkle/mod.rs @@ -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}, @@ -18,8 +23,6 @@ use crate::{ mod proofs; pub use proofs::BatchMerkleProof; -use crate::{Hasher, MerkleTreeError, VectorCommitment}; - #[cfg(feature = "concurrent")] pub mod concurrent; @@ -103,6 +106,17 @@ pub struct MerkleTree { /// up to the root (excluding the root itself). pub type MerkleTreeOpening = (::Digest, Vec<::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 = + (::Digest, (::Digest, Vec<::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 = + (Vec<::Digest>, (Vec<::Digest>, BatchMerkleProof)); + // MERKLE TREE IMPLEMENTATION // ================================================================================================ @@ -422,7 +436,6 @@ impl VectorCommitment for MerkleTree { *self.root() } - fn domain_len(&self) -> usize { fn get_domain_len(&self) -> usize { 1 << self.depth() } @@ -468,11 +481,6 @@ impl VectorCommitment for MerkleTree { // SALTED MERKLE TREE // ================================================================================================ -use rand::{ - distributions::{Distribution, Standard}, - thread_rng, Rng, RngCore, -}; - pub struct SaltedMerkleTree { leaves: Vec, tree: MerkleTree, @@ -517,10 +525,7 @@ where self.tree.depth() } - pub fn prove( - &self, - index: usize, - ) -> Result<(H::Digest, (H::Digest, Vec)), MerkleTreeError> { + pub fn prove(&self, index: usize) -> Result, MerkleTreeError> { let (_, proof) = self.tree.prove(index)?; Ok((self.leaves[index], (self.salts[index], proof))) } @@ -528,7 +533,7 @@ where pub fn prove_batch( &self, indexes: &[usize], - ) -> Result<(Vec, (Vec, BatchMerkleProof)), MerkleTreeError> { + ) -> Result, 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(); diff --git a/examples/Cargo.toml b/examples/Cargo.toml index d6fcae6c0..179ba05b3 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -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 } diff --git a/examples/src/fibonacci/fib2/prover.rs b/examples/src/fibonacci/fib2/prover.rs index bbfa936b4..42a3ff270 100644 --- a/examples/src/fibonacci/fib2/prover.rs +++ b/examples/src/fibonacci/fib2/prover.rs @@ -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::{ @@ -85,7 +83,14 @@ where zk_parameters: Option, ) -> (Self::TraceLde, TracePolyTable) { 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>( diff --git a/examples/src/fibonacci/fib8/prover.rs b/examples/src/fibonacci/fib8/prover.rs index 32cc899ba..01f56103b 100644 --- a/examples/src/fibonacci/fib8/prover.rs +++ b/examples/src/fibonacci/fib8/prover.rs @@ -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::{ @@ -100,7 +98,14 @@ where zk_parameters: Option, ) -> (Self::TraceLde, TracePolyTable) { 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>( diff --git a/examples/src/fibonacci/fib_small/prover.rs b/examples/src/fibonacci/fib_small/prover.rs index 4843d4d85..be69faee8 100644 --- a/examples/src/fibonacci/fib_small/prover.rs +++ b/examples/src/fibonacci/fib_small/prover.rs @@ -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::{ diff --git a/examples/src/fibonacci/mulfib2/prover.rs b/examples/src/fibonacci/mulfib2/prover.rs index 776516b7a..15907a100 100644 --- a/examples/src/fibonacci/mulfib2/prover.rs +++ b/examples/src/fibonacci/mulfib2/prover.rs @@ -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::{ @@ -81,7 +79,14 @@ where zk_parameters: Option, ) -> (Self::TraceLde, TracePolyTable) { 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>( diff --git a/examples/src/fibonacci/mulfib8/prover.rs b/examples/src/fibonacci/mulfib8/prover.rs index 5ef5b2745..197a350c1 100644 --- a/examples/src/fibonacci/mulfib8/prover.rs +++ b/examples/src/fibonacci/mulfib8/prover.rs @@ -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::{ @@ -93,7 +91,14 @@ where zk_parameters: Option, ) -> (Self::TraceLde, TracePolyTable) { 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>( diff --git a/examples/src/lamport/aggregate/prover.rs b/examples/src/lamport/aggregate/prover.rs index 1962171d2..61af1b91b 100644 --- a/examples/src/lamport/aggregate/prover.rs +++ b/examples/src/lamport/aggregate/prover.rs @@ -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::{ diff --git a/examples/src/lamport/threshold/prover.rs b/examples/src/lamport/threshold/prover.rs index c12cc1947..f5cad228c 100644 --- a/examples/src/lamport/threshold/prover.rs +++ b/examples/src/lamport/threshold/prover.rs @@ -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::{ @@ -171,7 +169,14 @@ where zk_parameters: Option, ) -> (Self::TraceLde, TracePolyTable) { 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>( diff --git a/examples/src/merkle/prover.rs b/examples/src/merkle/prover.rs index f9ca1ef3c..57a21625b 100644 --- a/examples/src/merkle/prover.rs +++ b/examples/src/merkle/prover.rs @@ -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::{ @@ -136,7 +134,14 @@ where zk_parameters: Option, ) -> (Self::TraceLde, TracePolyTable) { 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>( diff --git a/examples/src/rescue/prover.rs b/examples/src/rescue/prover.rs index 9867c8d18..a2797d9ed 100644 --- a/examples/src/rescue/prover.rs +++ b/examples/src/rescue/prover.rs @@ -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::{ @@ -103,7 +101,14 @@ where zk_parameters: Option, ) -> (Self::TraceLde, TracePolyTable) { 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>( diff --git a/examples/src/rescue_raps/prover.rs b/examples/src/rescue_raps/prover.rs index f4703b973..7050626e9 100644 --- a/examples/src/rescue_raps/prover.rs +++ b/examples/src/rescue_raps/prover.rs @@ -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::{ @@ -134,7 +133,14 @@ where zk_parameters: Option, ) -> (Self::TraceLde, TracePolyTable) { 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>( diff --git a/examples/src/vdf/exempt/prover.rs b/examples/src/vdf/exempt/prover.rs index 6c3b5dc53..ed41c3799 100644 --- a/examples/src/vdf/exempt/prover.rs +++ b/examples/src/vdf/exempt/prover.rs @@ -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::{ @@ -86,7 +84,14 @@ where zk_parameters: Option, ) -> (Self::TraceLde, TracePolyTable) { 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>( diff --git a/examples/src/vdf/regular/prover.rs b/examples/src/vdf/regular/prover.rs index 8c56290f9..41dbac4f2 100644 --- a/examples/src/vdf/regular/prover.rs +++ b/examples/src/vdf/regular/prover.rs @@ -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::{ @@ -81,7 +79,14 @@ where zk_parameters: Option, ) -> (Self::TraceLde, TracePolyTable) { 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>( diff --git a/examples/src/vdf/regular/tests.rs b/examples/src/vdf/regular/tests.rs index 79d2a0ff5..93ed54e54 100644 --- a/examples/src/vdf/regular/tests.rs +++ b/examples/src/vdf/regular/tests.rs @@ -31,5 +31,5 @@ fn build_options(use_extension_field: bool) -> ProofOptions { } else { FieldExtension::None }; - ProofOptions::new(2, 4, 0, extension, 4, 31, false) + ProofOptions::new(2, 4, 0, extension, 2, 255, true) } diff --git a/prover/Cargo.toml b/prover/Cargo.toml index 1d9f67154..199bde2a7 100644 --- a/prover/Cargo.toml +++ b/prover/Cargo.toml @@ -35,14 +35,11 @@ crypto = { version = "0.10", path = "../crypto", package = "winter-crypto", defa fri = { version = "0.10", path = '../fri', package = "winter-fri", default-features = false } math = { version = "0.10", path = "../math", package = "winter-math", default-features = false } maybe_async = { version = "0.10", path = "../utils/maybe_async" , package = "winter-maybe-async" } -tracing = { version = "0.1", default-features = false, features = ["attributes"]} -utils = { version = "0.10", path = "../utils/core", package = "winter-utils", default-features = false } - rand_chacha = { version = "0.3", default-features = false } -rand-utils = { version = "0.9", path = "../utils/rand", package = "winter-rand-utils" } - -libc-print = "0.1.23" +rand-utils = { version = "0.10", path = "../utils/rand", package = "winter-rand-utils" } rand = { version = "0.8" } +tracing = { version = "0.1", default-features = false, features = ["attributes"]} +utils = { version = "0.10", path = "../utils/core", package = "winter-utils", default-features = false } [dev-dependencies] criterion = "0.5" diff --git a/prover/benches/lagrange_kernel.rs b/prover/benches/lagrange_kernel.rs index 3ea52ff96..82d3c00f0 100644 --- a/prover/benches/lagrange_kernel.rs +++ b/prover/benches/lagrange_kernel.rs @@ -8,9 +8,7 @@ use std::time::Duration; use air::{ Air, AirContext, Assertion, AuxRandElements, ConstraintCompositionCoefficients, EvaluationFrame, FieldExtension, GkrRandElements, LagrangeKernelRandElements, PartitionOptions, - ProofOptions, TraceInfo, TransitionConstraintDegree, - EvaluationFrame, FieldExtension, LagrangeKernelRandElements, ProofOptions, TraceInfo, - TransitionConstraintDegree, ZkParameters, + ProofOptions, TraceInfo, TransitionConstraintDegree, ZkParameters, }; use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion}; use crypto::{hashers::Blake3_256, DefaultRandomCoin, MerkleTree, RandomCoin}; @@ -213,7 +211,14 @@ impl Prover for LagrangeProver { E: math::FieldElement, { 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>( diff --git a/prover/src/channel.rs b/prover/src/channel.rs index 1d414d92a..f73b4f3b3 100644 --- a/prover/src/channel.rs +++ b/prover/src/channel.rs @@ -264,7 +264,7 @@ where // FRI PROVER CHANNEL IMPLEMENTATION // ================================================================================================ -impl<'a, A, E, H, R, V> fri::ProverChannel for ProverChannel<'a, A, E, H, R, V> +impl fri::ProverChannel for ProverChannel<'_, A, E, H, R, V> where A: Air, E: FieldElement, diff --git a/prover/src/constraints/commitment.rs b/prover/src/constraints/commitment.rs index ac71fdc94..d79e02d46 100644 --- a/prover/src/constraints/commitment.rs +++ b/prover/src/constraints/commitment.rs @@ -42,7 +42,7 @@ where pub fn new(evaluations: RowMatrix, commitment: V) -> ConstraintCommitment { assert_eq!( evaluations.num_rows(), - commitment.domain_len(), + commitment.get_domain_len(), "number of rows in constraint evaluation matrix must be the same as the size \ of the vector commitment domain" ); diff --git a/prover/src/constraints/composition_poly.rs b/prover/src/constraints/composition_poly.rs index 499abe4ea..a418a04c9 100644 --- a/prover/src/constraints/composition_poly.rs +++ b/prover/src/constraints/composition_poly.rs @@ -49,7 +49,7 @@ impl CompositionPolyTrace { /// /// For example, if the composition polynomial has degree 2N - 1, where N is the trace length, /// it will be stored as two columns of size N (each of degree N - 1). -/// +/// /// When zero-knowledge is enabled, the composition polynomial is split into segment polynomials /// such that each segment polynomial's degree is small enough to accommodate adding a randomizer /// polynomial without the degree of the resulting ranomized segment polynomial exceeding @@ -82,7 +82,7 @@ impl CompositionPoly { // compute the segment quotient polynomials let quotient_degree = polynom::degree_of(&trace); let degree_chunked_quotient = if zk_parameters.is_some() { - (quotient_degree + 1 + num_cols - 1) / num_cols + (quotient_degree + 1).div_ceil(num_cols) } else { domain.trace_length() }; @@ -145,7 +145,7 @@ impl CompositionPoly { /// Takes a vector of coefficients representing the segment polynomials of a given composition /// polynomial as input, and generates coefficients of their randomized version. -/// +/// /// The randomization technique is the one in section 4.1 in https://eprint.iacr.org/2024/1037.pdf. fn complement_to( polys: Vec>, diff --git a/prover/src/lib.rs b/prover/src/lib.rs index e431c893e..254364094 100644 --- a/prover/src/lib.rs +++ b/prover/src/lib.rs @@ -48,8 +48,7 @@ pub use air::{ EvaluationFrame, FieldExtension, LagrangeKernelRandElements, ProofOptions, TraceInfo, TransitionConstraintDegree, }; -use air::{AuxRandElements, GkrRandElements, PartitionOptions}; -use air::{AuxRandElements, ZkParameters}; +use air::{AuxRandElements, GkrRandElements, PartitionOptions, ZkParameters}; pub use crypto; use crypto::{ElementHasher, RandomCoin, VectorCommitment}; use fri::FriProver; @@ -59,7 +58,6 @@ use math::{ fields::{CubeExtension, QuadExtension}, ExtensibleField, FieldElement, StarkField, ToElements, }; -use maybe_async::{maybe_async, maybe_await}; use rand::{RngCore, SeedableRng}; use rand_chacha::ChaCha20Rng; use tracing::{event, info_span, instrument, Level}; @@ -301,7 +299,6 @@ pub trait Prover { ProverChannel::::new( &air, pub_inputs_elements, - ); air.context().zk_blowup_factor(), ); let mut prng = ChaCha20Rng::from_entropy(); @@ -600,7 +597,6 @@ pub trait Prover { .partition_options() .partition_size::(num_constraint_composition_columns), ); - let commitment = composed_evaluations.commit_to_rows::(); ConstraintCommitment::new(composed_evaluations, commitment) }); @@ -636,7 +632,6 @@ pub trait Prover { // commit to the LDE of the main trace by writing the the commitment string into // the channel - channel.commit_trace(main_trace_commitment); channel.commit_trace(main_trace_commitment, prng); (trace_lde, trace_polys) @@ -671,7 +666,6 @@ pub trait Prover { // then, commit to the evaluations of constraints by writing the commitment string of // the constraint commitment into the channel - channel.commit_constraints(constraint_commitment.commitment()); channel.commit_constraints(constraint_commitment.commitment(), prng); (constraint_commitment, composition_poly) diff --git a/prover/src/matrix/col_matrix.rs b/prover/src/matrix/col_matrix.rs index 7d922e877..62a953878 100644 --- a/prover/src/matrix/col_matrix.rs +++ b/prover/src/matrix/col_matrix.rs @@ -299,20 +299,21 @@ impl ColMatrix { } /// Randomizes the trace polynomials when zero-knowledge is enabled. - /// - /// Takes as input a factor that is a power of two which is used to determine the size (i.e., + /// + /// Takes as input a factor that is a power of two which is used to determine the size (i.e., /// the number of coefficients) of the randomized witness polynomial. - /// + /// /// The randomized witness polynomial has the form: - /// + /// + /// ```text /// \hat{w}(x) = w(x) + r(x) * Z_H(x) - /// + /// ``` /// where: - /// + /// /// 1. w(x) is the witness polynomial of degree trace length minus one. /// 2. \hat{w}(x) is the randomized witness polynomial. /// 3. r(x) is the randomizer polynomial and has degree `(zk_blowup - 1) * n`. - /// 4. Z_H(x) = (x^n - 1). + /// 4. Z_H(x) = (x^n - 1). pub(crate) fn randomize(&self, zk_blowup: usize, prng: &mut R) -> Self { let cur_len = self.num_rows(); let extended_len = zk_blowup * cur_len; diff --git a/prover/src/trace/trace_lde/default/mod.rs b/prover/src/trace/trace_lde/default/mod.rs index f4863d5fb..2f596aed7 100644 --- a/prover/src/trace/trace_lde/default/mod.rs +++ b/prover/src/trace/trace_lde/default/mod.rs @@ -6,9 +6,9 @@ use alloc::vec::Vec; use core::marker::PhantomData; -use air::{proof::Queries, LagrangeKernelEvaluationFrame, PartitionOptions, TraceInfo}; -use crypto::VectorCommitment; -use air::{proof::Queries, LagrangeKernelEvaluationFrame, TraceInfo, ZkParameters}; +use air::{ + proof::Queries, LagrangeKernelEvaluationFrame, PartitionOptions, TraceInfo, ZkParameters, +}; use crypto::VectorCommitment; use rand::RngCore; use tracing::info_span; @@ -47,13 +47,6 @@ pub struct DefaultTraceLde< blowup: usize, trace_info: TraceInfo, partition_option: PartitionOptions, - main_segment_vector_com: V, - // low-degree extensions of the auxiliary segment of the trace - aux_segment_lde: Option>, - // commitment to the auxiliary segment of the trace - aux_segment_vector_com: Option, - blowup: usize, - trace_info: TraceInfo, _h: PhantomData, } @@ -75,13 +68,6 @@ where main_trace: &ColMatrix, domain: &StarkDomain, partition_option: PartitionOptions, - ) -> (Self, TracePolyTable) { - // extend the main execution trace and build a commitment to the extended trace - let (main_segment_lde, main_segment_vector_com, main_segment_polys) = - build_trace_commitment::( - main_trace, - domain, - partition_option.partition_size::(main_trace.num_cols()), zk_parameters: Option, prng: &mut R, ) -> (Self, TracePolyTable) { @@ -90,6 +76,7 @@ where build_trace_commitment::( main_trace, domain, + partition_option.partition_size::(main_trace.num_cols()), zk_parameters, prng, ); @@ -100,14 +87,9 @@ where main_segment_oracles: main_segment_vector_com, aux_segment_lde: None, aux_segment_oracles: None, - blowup: domain.trace_to_lde_blowup(), trace_info: trace_info.clone(), partition_option, - main_segment_vector_com, - aux_segment_lde: None, - aux_segment_vector_com: None, blowup: domain.lde_domain_size() / trace_info.length(), - trace_info: trace_info.clone(), _h: PhantomData, }; @@ -170,20 +152,18 @@ where &mut self, aux_trace: &ColMatrix, domain: &StarkDomain, + zk_parameters: Option, + prng: &mut R, ) -> (ColMatrix, H::Digest) { // extend the auxiliary trace segment and build a commitment to the extended trace let (aux_segment_lde, aux_segment_oracles, aux_segment_polys) = - build_trace_commitment::( + build_trace_commitment::( aux_trace, domain, self.partition_option.partition_size::(aux_trace.num_cols()), + zk_parameters, + prng, ); - zk_parameters: Option, - prng: &mut R, - ) -> (ColMatrix, H::Digest) { - // extend the auxiliary trace segment and build a commitment to the extended trace - let (aux_segment_lde, aux_segment_vector_com, aux_segment_polys) = - build_trace_commitment::(aux_trace, domain, zk_parameters, prng); // check errors assert!( @@ -200,8 +180,6 @@ where self.aux_segment_lde = Some(aux_segment_lde); let commitment_string = aux_segment_oracles.commitment(); self.aux_segment_oracles = Some(aux_segment_oracles); - let commitment_string = aux_segment_vector_com.commitment(); - self.aux_segment_vector_com = Some(aux_segment_vector_com); (aux_segment_polys, commitment_string) } @@ -272,14 +250,6 @@ where let segment_lde = self.aux_segment_lde.as_ref().expect("expected aux segment to be present"); result.push(build_segment_queries::(segment_lde, segment_oracles, positions)); - if let Some(ref segment_vector_com) = self.aux_segment_vector_com { - let segment_lde = - self.aux_segment_lde.as_ref().expect("expected aux segment to be present"); - result.push(build_segment_queries::( - segment_lde, - segment_vector_com, - positions, - )); } result @@ -300,7 +270,6 @@ where &self.trace_info } } - // HELPER FUNCTIONS // ================================================================================================ @@ -315,7 +284,8 @@ where /// the extended execution trace, then building a vector commitment to the resulting vector. fn build_trace_commitment( trace: &ColMatrix, - domain: &StarkDomain,partition_size: usize, + domain: &StarkDomain, + partition_size: usize, zk_parameters: Option, prng: &mut R, ) -> (RowMatrix, V, ColMatrix) @@ -358,7 +328,7 @@ where let commitment_domain_size = trace_lde.num_rows(); let trace_vector_com = info_span!("compute_execution_trace_commitment", commitment_domain_size) .in_scope(|| trace_lde.commit_to_rows::(partition_size)); - assert_eq!(trace_vector_com.domain_len(), commitment_domain_size); + assert_eq!(trace_vector_com.get_domain_len(), commitment_domain_size); (trace_lde, trace_vector_com, trace_polys) } diff --git a/prover/src/trace/trace_lde/mod.rs b/prover/src/trace/trace_lde/mod.rs index 8a4800bdf..6abcf8b96 100644 --- a/prover/src/trace/trace_lde/mod.rs +++ b/prover/src/trace/trace_lde/mod.rs @@ -5,8 +5,6 @@ use alloc::vec::Vec; -use air::{proof::Queries, LagrangeKernelEvaluationFrame, TraceInfo}; -use crypto::{ElementHasher, Hasher, VectorCommitment}; use air::{proof::Queries, LagrangeKernelEvaluationFrame, TraceInfo, ZkParameters}; use crypto::{ElementHasher, Hasher, VectorCommitment}; use rand::RngCore; diff --git a/verifier/Cargo.toml b/verifier/Cargo.toml index c88af91cd..63d4b9c0f 100644 --- a/verifier/Cargo.toml +++ b/verifier/Cargo.toml @@ -26,8 +26,6 @@ fri = { version = "0.10", path = "../fri", package = "winter-fri", default-featu 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" - # Allow math in docs [package.metadata.docs.rs] rustdoc-args = ["--html-in-header", ".cargo/katex-header.html"] diff --git a/verifier/src/channel.rs b/verifier/src/channel.rs index 15d72f8e4..094bccd59 100644 --- a/verifier/src/channel.rs +++ b/verifier/src/channel.rs @@ -233,9 +233,6 @@ where .map(|row| hash_row::(row, self.partition_size_main)) .collect(); - - let items: Vec = - queries.main_states.rows().map(|row| H::hash_elements(row)).collect(); >::verify_many( self.trace_commitments[0], positions, @@ -250,8 +247,6 @@ where .map(|row| hash_row::(row, self.partition_size_aux)) .collect(); - let items: Vec = - aux_states.rows().map(|row| H::hash_elements(row)).collect(); >::verify_many( self.trace_commitments[1], positions, @@ -279,8 +274,6 @@ where .map(|row| hash_row::(row, self.partition_size_constraint)) .collect(); - let items: Vec = - queries.evaluations.rows().map(|row| H::hash_elements(row)).collect(); >::verify_many( self.constraint_commitment, positions, diff --git a/winterfell/src/lib.rs b/winterfell/src/lib.rs index 134cb9bc3..50b235aaf 100644 --- a/winterfell/src/lib.rs +++ b/winterfell/src/lib.rs @@ -601,8 +601,7 @@ #[cfg(test)] extern crate std; -pub use air::{AuxRandElements, GkrVerifier, PartitionOptions}; -pub use air::{AuxRandElements, GkrVerifier, ZkParameters}; +pub use air::{AuxRandElements, GkrVerifier, PartitionOptions, ZkParameters}; pub use prover::{ crypto, iterators, math, matrix, Air, AirContext, Assertion, AuxTraceWithMetadata, BoundaryConstraint, BoundaryConstraintGroup, CompositionPolyTrace, diff --git a/winterfell/src/tests.rs b/winterfell/src/tests.rs index fd81276ff..0bcb25566 100644 --- a/winterfell/src/tests.rs +++ b/winterfell/src/tests.rs @@ -5,8 +5,7 @@ use std::{vec, vec::Vec}; -use air::{GkrRandElements, LagrangeKernelRandElements}; -use air::{LagrangeKernelRandElements, ZkParameters}; +use air::{GkrRandElements, LagrangeKernelRandElements, ZkParameters}; use crypto::MerkleTree; use prover::{ crypto::{hashers::Blake3_256, DefaultRandomCoin, RandomCoin}, @@ -243,7 +242,14 @@ impl Prover for LagrangeComplexProver { E: math::FieldElement, { 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>(