Skip to content

Commit

Permalink
fix: pacify clippy
Browse files Browse the repository at this point in the history
Signed-off-by: 0xKanekiKen <[email protected]>
  • Loading branch information
0xkanekiken committed Aug 28, 2023
1 parent a3be6b0 commit 8c32bcd
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 117 deletions.
4 changes: 2 additions & 2 deletions air/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl ProofOptions {
},
FoldingSchedule::Dynamic { schedule} => {
assert!(schedule.iter().all(|factor| factor.is_power_of_two()), "FRI folding factors must be powers of 2");
assert!(schedule.len() > 0, "FRI folding schedule cannot be empty");
assert!(!schedule.is_empty(), "FRI folding schedule cannot be empty");
},
}

Expand Down Expand Up @@ -345,7 +345,7 @@ mod tests {
]);
let expected = vec![
BaseElement::from(ext_fri),
BaseElement::from(grinding_factor as u32),
BaseElement::from(grinding_factor),
BaseElement::from(blowup_factor as u32),
BaseElement::from(num_queries as u32),
];
Expand Down
2 changes: 1 addition & 1 deletion air/src/proof/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ mod tests {
BaseElement::from(1_u32), // lower bits of field modulus
BaseElement::from(u32::MAX), // upper bits of field modulus
BaseElement::from(ext_fri),
BaseElement::from(grinding_factor as u32),
BaseElement::from(grinding_factor),
BaseElement::from(blowup_factor as u32),
BaseElement::from(num_queries as u32),
BaseElement::from(trace_length as u32),
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/hash/griffin/griffin64_256_jive/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ proptest! {
for i in 0..STATE_WIDTH {
v1[i] = BaseElement::new(a[i]);
}
v2 = v1.clone();
v2 = v1;

apply_mds_naive(&mut v1);
GriffinJive64_256::apply_linear(&mut v2);
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/hash/rescue/rp64_256/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ proptest! {
for i in 0..STATE_WIDTH {
v1[i] = BaseElement::new(a[i]);
}
v2 = v1.clone();
v2 = v1;

apply_mds_naive(&mut v1);
Rp64_256::apply_mds(&mut v2);
Expand Down
4 changes: 2 additions & 2 deletions crypto/src/hash/rescue/rp64_256_jive/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn mds_inv_test() {
#[test]
fn test_alphas() {
let e: BaseElement = rand_value();
let e_exp = e.exp(ALPHA.into());
let e_exp = e.exp(ALPHA);
assert_eq!(e, e_exp.exp(INV_ALPHA));
}

Expand Down Expand Up @@ -197,7 +197,7 @@ proptest! {
for i in 0..STATE_WIDTH {
v1[i] = BaseElement::new(a[i]);
}
v2 = v1.clone();
v2 = v1;

apply_mds_naive(&mut v1);
RpJive64_256::apply_mds(&mut v2);
Expand Down
4 changes: 3 additions & 1 deletion fri/src/fri_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +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 utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable};
use utils::{
collections::Vec, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
};

/// Enumerates the possible schedules for the FRI folding process.
///
Expand Down
4 changes: 2 additions & 2 deletions fri/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl FriOptions {
schedule.iter().all(|factor| factor.is_power_of_two()),
"FRI folding factors must be powers of 2"
);
assert!(schedule.len() > 0, "FRI folding schedule cannot be empty");
assert!(!schedule.is_empty(), "FRI folding schedule cannot be empty");
}
}

Expand Down Expand Up @@ -124,7 +124,7 @@ impl FriOptions {
domain_size /= *fri_folding_factor as usize;
result += 1;
}
return result;
result
}
FoldingSchedule::Dynamic { schedule } => schedule.len(),
}
Expand Down
1 change: 1 addition & 0 deletions fri/src/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ where
FoldingSchedule::Dynamic { schedule } => {
// for all FRI layers, except the last one, record tree root, determine a set of query
// positions, and query the layer at these positions.
#[allow(clippy::needless_range_loop)]
for i in 0..self.layers.len() {
let fri_folding_factor = schedule[i];

Expand Down
112 changes: 5 additions & 107 deletions fri/src/verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ where
}
}

// verify remainder
self.verify_remainder(
channel,
&evaluations,
Expand All @@ -367,111 +368,8 @@ where
)
}

// /// This is the actual implementation of the verification procedure described above, but it
// /// also takes folding factor as a generic parameter N.
// fn verify_generic<const N: usize>(
// &self,
// channel: &mut C,
// evaluations: &[E],
// positions: &[usize],
// ) -> Result<(), VerifierError> {
// // pre-compute roots of unity used in computing x coordinates in the folded domain
// let folding_roots = (0..N)
// .map(|i| {
// self.domain_generator
// .exp_vartime(((self.domain_size / N * i) as u64).into())
// })
// .collect::<Vec<_>>();

// // 1 ----- verify the recursive components of the FRI proof -----------------------------------
// let mut domain_generator = self.domain_generator;
// let mut domain_size = self.domain_size;
// let mut max_degree_plus_1 = self.max_poly_degree + 1;
// let mut positions = positions.to_vec();
// let mut evaluations = evaluations.to_vec();

// for depth in 0..self.options.num_fri_layers(self.domain_size) {
// // determine which evaluations were queried in the folded layer
// let mut folded_positions =
// fold_positions(&positions, domain_size, self.options.folding_factor());
// // determine where these evaluations are in the commitment Merkle tree
// let position_indexes = map_positions_to_indexes(
// &folded_positions,
// domain_size,
// self.options.folding_factor(),
// self.num_partitions,
// );
// // read query values from the specified indexes in the Merkle tree
// let layer_commitment = self.layer_commitments[depth];
// // TODO: add layer depth to the potential error message
// let layer_values = channel.read_layer_queries(&position_indexes, &layer_commitment)?;
// let query_values =
// get_query_values::<E, N>(&layer_values, &positions, &folded_positions, domain_size);
// if evaluations != query_values {
// return Err(VerifierError::InvalidLayerFolding(depth));
// }

// // build a set of x coordinates for each row polynomial
// #[rustfmt::skip]
// let xs = folded_positions.iter().map(|&i| {
// let xe = domain_generator.exp_vartime((i as u64).into()) * self.options.domain_offset();
// folding_roots.iter()
// .map(|&r| E::from(xe * r))
// .collect::<Vec<_>>().try_into().unwrap()
// })
// .collect::<Vec<_>>();

// // interpolate x and y values into row polynomials
// let row_polys = polynom::interpolate_batch(&xs, &layer_values);

// // calculate the pseudo-random value used for linear combination in layer folding
// let alpha = self.layer_alphas[depth];

// // check that when the polynomials are evaluated at alpha, the result is equal to
// // the corresponding column value
// evaluations = row_polys.iter().map(|p| polynom::eval(p, alpha)).collect();

// // make sure next degree reduction does not result in degree truncation
// if max_degree_plus_1 % N != 0 {
// return Err(VerifierError::DegreeTruncation(
// max_degree_plus_1 - 1,
// N,
// depth,
// ));
// }

// // update variables for the next iteration of the loop
// domain_generator = domain_generator.exp_vartime((N as u32).into());
// max_degree_plus_1 /= N;
// domain_size /= N;
// mem::swap(&mut positions, &mut folded_positions);
// }

// // 2 ----- verify the remainder polynomial of the FRI proof -------------------------------

// // read the remainder polynomial from the channel and make sure it agrees with the evaluations
// // from the previous layer.
// let remainder_poly = channel.read_remainder()?;
// if remainder_poly.len() > max_degree_plus_1 {
// return Err(VerifierError::RemainderDegreeMismatch(
// max_degree_plus_1 - 1,
// ));
// }
// let offset: E::BaseField = self.options().domain_offset();

// for (&position, evaluation) in positions.iter().zip(evaluations) {
// let comp_eval = eval_horner::<E>(
// &remainder_poly,
// offset * domain_generator.exp_vartime((position as u64).into()),
// );
// if comp_eval != evaluation {
// return Err(VerifierError::InvalidRemainderFolding);
// }
// }

// Ok(())
// }

/// Executes the query phase of the FRI protocol.
#[allow(clippy::too_many_arguments)]
fn verify_layer<const N: usize>(
&self,
channel: &mut C,
Expand All @@ -483,7 +381,7 @@ where
max_degree_plus_1: usize,
) -> Result<(Vec<E>, Vec<usize>), VerifierError> {
// 1. Determining which evaluations were queried in the folded layer.
let folded_positions = fold_positions(&positions, domain_size, N);
let folded_positions = fold_positions(positions, domain_size, N);

// 2. Finding these evaluations in the commitment Merkle tree.
let position_indexes =
Expand All @@ -494,7 +392,7 @@ where
let layer_values: Vec<[E; N]> =
channel.read_layer_queries(&position_indexes, &layer_commitment)?;
let query_values =
get_query_values(&layer_values, &positions, &folded_positions, domain_size);
get_query_values(&layer_values, positions, &folded_positions, domain_size);

if evaluations != query_values {
return Err(VerifierError::InvalidLayerFolding(depth));
Expand Down

0 comments on commit 8c32bcd

Please sign in to comment.