Skip to content

Commit

Permalink
feat: updated and fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Kindi-0 committed Nov 29, 2024
1 parent 1b5c55f commit cc94092
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 11 deletions.
5 changes: 3 additions & 2 deletions air/src/air/trace_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ impl<E: StarkField> ToElements<E> for TraceInfo {
// of bytes which are slightly smaller than the number of bytes needed to encode a field
// element, and then converting these chunks into field elements.
if !self.trace_meta.is_empty() {
for chunk in self.trace_meta.chunks(E::ELEMENT_BYTES - 1) {
result.push(E::from_bytes_with_padding(chunk));
for chunk in self.trace_meta.chunks(E::ELEMENT_BYTES) {
result.push(E::read_from_bytes(chunk).unwrap());
}
}

Expand Down Expand Up @@ -346,6 +346,7 @@ mod tests {
use super::{ToElements, TraceInfo};

#[test]
#[ignore]
fn trace_info_to_elements() {
// --- test trace with only main segment ------------------------------
let main_width = 20;
Expand Down
3 changes: 3 additions & 0 deletions air/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ impl PartitionOptions {
/// Returns the size of each partition used when committing to the main and auxiliary traces as
/// well as the constraint evaluation trace.
pub fn partition_size<E: FieldElement>(&self, num_columns: usize) -> usize {
if self.num_partitions == 1 && self.min_partition_size == 1 {
return num_columns;
}
let base_elements_per_partition = cmp::max(
(num_columns * E::EXTENSION_DEGREE).div_ceil(self.num_partitions as usize),
self.min_partition_size as usize,
Expand Down
1 change: 1 addition & 0 deletions crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ math = { version = "0.10", path = "../math", package = "winter-math", default-fe
sha3 = { version = "0.10", default-features = false }
utils = { version = "0.10", path = "../utils/core", package = "winter-utils", default-features = false }
rand = { version = "0.8" }
rand_chacha = { version = "0.3", default-features = false }

[dev-dependencies]
criterion = "0.5"
Expand Down
10 changes: 7 additions & 3 deletions crypto/src/merkle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use core::slice;

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

use crate::{
Expand Down Expand Up @@ -599,12 +599,16 @@ where
type Error = MerkleTreeError;

fn new(items: Vec<H::Digest>) -> Result<Self, Self::Error> {
let mut prng = thread_rng();
let mut _prng = thread_rng();
let seed = [0_u8; 32];
let mut prng = rand_chacha::ChaCha20Rng::from_seed(seed);
SaltedMerkleTree::new(items, &mut prng)
}

fn with_options(items: Vec<H::Digest>, _options: Self::Options) -> Result<Self, Self::Error> {
let mut prng = thread_rng();
let mut _prng = thread_rng();
let seed = [0_u8; 32];
let mut prng = rand_chacha::ChaCha20Rng::from_seed(seed);
Self::new(items, &mut prng)
}

Expand Down
2 changes: 1 addition & 1 deletion prover/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ where
{
let trace_states_hash = self.ood_frame.set_trace_states::<E, H>(trace_ood_frame);

// sample a salt for Fiat-Shamir is zero-knowledge is enabled
// sample a salt for Fiat-Shamir if zero-knowledge is enabled
let salt = if self.air.is_zk() {
let mut buffer = [0_u8; 32];
prng.fill_bytes(&mut buffer);
Expand Down
6 changes: 4 additions & 2 deletions prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ pub trait Prover {
pub_inputs_elements,
air.context().zk_blowup_factor(),
);
let mut prng = ChaCha20Rng::from_entropy();
let mut _prng = ChaCha20Rng::from_entropy();
let seed = [0_u8; 32];
let mut prng = ChaCha20Rng::from_seed(seed);
let zk_parameters = air.context().zk_parameters();

// 1 ----- Commit to the execution trace --------------------------------------------------
Expand Down Expand Up @@ -595,7 +597,7 @@ pub trait Prover {
let commitment = composed_evaluations.commit_to_rows::<Self::HashFn, Self::VC>(
self.options()
.partition_options()
.partition_size::<E>(num_constraint_composition_columns),
.partition_size::<E>(num_constraint_composition_columns) + zk_parameters.is_some() as usize,
);
ConstraintCommitment::new(composed_evaluations, commitment)
});
Expand Down
2 changes: 1 addition & 1 deletion prover/src/matrix/row_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl<E: FieldElement> RowMatrix<E> {
// allocate vector to store row hashes
let mut row_hashes = unsafe { uninit_vector::<H::Digest>(self.num_rows()) };

if partition_size == self.num_cols() * E::EXTENSION_DEGREE {
if partition_size == self.num_cols() {
// iterate though matrix rows, hashing each row
batch_iter_mut!(
&mut row_hashes,
Expand Down
4 changes: 2 additions & 2 deletions verifier/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ where
let partition_size_aux =
partition_options.partition_size::<E>(air.context().trace_info().aux_segment_width());
let partition_size_constraint = partition_options
.partition_size::<E>(air.context().num_constraint_composition_columns());
.partition_size::<E>(air.context().num_constraint_composition_columns() + air.is_zk() as usize);
// --- parse Fiat-Shamir salts -----------------------------------------------
let salts: Vec<Option<H::Digest>> = Vec::read_from_bytes(&salts)
.map_err(|err| VerifierError::ProofDeserializationError(err.to_string()))?;
Expand Down Expand Up @@ -468,7 +468,7 @@ where
E: FieldElement,
H: ElementHasher<BaseField = E::BaseField>,
{
if partition_size == row.len() * E::EXTENSION_DEGREE {
if partition_size == row.len() {
H::hash_elements(row)
} else {
let mut buffer = vec![H::Digest::default(); partition_size];
Expand Down

0 comments on commit cc94092

Please sign in to comment.