From f19f8b1dd68eb23999fbfb8c45b4169ad516996a Mon Sep 17 00:00:00 2001 From: Thor Kamphefner Date: Tue, 5 Sep 2023 13:53:41 -0700 Subject: [PATCH] fix: clippy --- halo2_gadgets/src/poseidon.rs | 4 +- halo2_gadgets/src/poseidon/pow5.rs | 39 ++++++++----------- halo2_gadgets/src/poseidon/primitives.rs | 6 +-- .../src/poseidon/primitives/grain.rs | 2 +- .../src/poseidon/primitives/p128pow5t3.rs | 2 +- .../table16/compression/compression_util.rs | 4 +- .../table16/message_schedule/schedule_util.rs | 6 +-- .../table16/message_schedule/subregion2.rs | 2 +- .../table16/message_schedule/subregion3.rs | 2 +- halo2_gadgets/src/sha256/table16/util.rs | 2 +- halo2_gadgets/src/sinsemilla.rs | 7 ++-- halo2_gadgets/src/utilities.rs | 8 ++-- .../src/utilities/lookup_range_check.rs | 2 +- halo2_proofs/src/dev.rs | 4 +- halo2_proofs/src/dev/cost.rs | 6 +-- halo2_proofs/src/plonk/circuit.rs | 4 +- halo2_proofs/src/poly.rs | 4 +- halo2_proofs/src/poly/ipa/multiopen/prover.rs | 2 +- halo2_proofs/tests/plonk_api.rs | 3 +- 19 files changed, 53 insertions(+), 56 deletions(-) diff --git a/halo2_gadgets/src/poseidon.rs b/halo2_gadgets/src/poseidon.rs index ffd745ad6d..bfd78f3dee 100644 --- a/halo2_gadgets/src/poseidon.rs +++ b/halo2_gadgets/src/poseidon.rs @@ -157,7 +157,7 @@ impl< .unwrap(), ), state, - _marker: PhantomData::default(), + _marker: PhantomData, }) } @@ -204,7 +204,7 @@ impl< chip: self.chip, mode, state: self.state, - _marker: PhantomData::default(), + _marker: PhantomData, }) } } diff --git a/halo2_gadgets/src/poseidon/pow5.rs b/halo2_gadgets/src/poseidon/pow5.rs index 0fb37994e5..51c1f059ca 100644 --- a/halo2_gadgets/src/poseidon/pow5.rs +++ b/halo2_gadgets/src/poseidon/pow5.rs @@ -240,30 +240,25 @@ impl, const WIDTH: usize, const RATE: usize> // Load the initial state into this region. let state = Pow5State::load(&mut region, config, initial_state)?; - let state = (0..config.half_full_rounds).fold(Ok(state), |res, r| { - res.and_then(|state| state.full_round(&mut region, config, r, r)) + let state = (0..config.half_full_rounds) + .try_fold(state, |res, r| res.full_round(&mut region, config, r, r))?; + + let state = (0..config.half_partial_rounds).try_fold(state, |res, r| { + res.partial_round( + &mut region, + config, + config.half_full_rounds + 2 * r, + config.half_full_rounds + r, + ) })?; - let state = (0..config.half_partial_rounds).fold(Ok(state), |res, r| { - res.and_then(|state| { - state.partial_round( - &mut region, - config, - config.half_full_rounds + 2 * r, - config.half_full_rounds + r, - ) - }) - })?; - - let state = (0..config.half_full_rounds).fold(Ok(state), |res, r| { - res.and_then(|state| { - state.full_round( - &mut region, - config, - config.half_full_rounds + 2 * config.half_partial_rounds + r, - config.half_full_rounds + config.half_partial_rounds + r, - ) - }) + let state = (0..config.half_full_rounds).try_fold(state, |res, r| { + res.full_round( + &mut region, + config, + config.half_full_rounds + 2 * config.half_partial_rounds + r, + config.half_full_rounds + config.half_partial_rounds + r, + ) })?; Ok(state.0) diff --git a/halo2_gadgets/src/poseidon/primitives.rs b/halo2_gadgets/src/poseidon/primitives.rs index 06f199f118..c456c87f54 100644 --- a/halo2_gadgets/src/poseidon/primitives.rs +++ b/halo2_gadgets/src/poseidon/primitives.rs @@ -220,7 +220,7 @@ impl, const T: usize, const RATE: usize> state, mds_matrix, round_constants, - _marker: PhantomData::default(), + _marker: PhantomData, } } @@ -257,7 +257,7 @@ impl, const T: usize, const RATE: usize> state: self.state, mds_matrix: self.mds_matrix, round_constants: self.round_constants, - _marker: PhantomData::default(), + _marker: PhantomData, } } } @@ -364,7 +364,7 @@ impl, D: Domain, const T: usize, const RA pub fn init() -> Self { Hash { sponge: Sponge::new(D::initial_capacity_element()), - _domain: PhantomData::default(), + _domain: PhantomData, } } } diff --git a/halo2_gadgets/src/poseidon/primitives/grain.rs b/halo2_gadgets/src/poseidon/primitives/grain.rs index 99711f97f3..1a780d5899 100644 --- a/halo2_gadgets/src/poseidon/primitives/grain.rs +++ b/halo2_gadgets/src/poseidon/primitives/grain.rs @@ -70,7 +70,7 @@ impl Grain { let mut grain = Grain { state, next_bit: STATE, - _field: PhantomData::default(), + _field: PhantomData, }; // Discard the first 160 bits. diff --git a/halo2_gadgets/src/poseidon/primitives/p128pow5t3.rs b/halo2_gadgets/src/poseidon/primitives/p128pow5t3.rs index e31ce04263..fdd4b22959 100644 --- a/halo2_gadgets/src/poseidon/primitives/p128pow5t3.rs +++ b/halo2_gadgets/src/poseidon/primitives/p128pow5t3.rs @@ -84,7 +84,7 @@ mod tests { impl P128Pow5T3Gen { pub fn new() -> Self { - P128Pow5T3Gen(PhantomData::default()) + P128Pow5T3Gen(PhantomData) } } diff --git a/halo2_gadgets/src/sha256/table16/compression/compression_util.rs b/halo2_gadgets/src/sha256/table16/compression/compression_util.rs index 324fe8f695..99706023df 100644 --- a/halo2_gadgets/src/sha256/table16/compression/compression_util.rs +++ b/halo2_gadgets/src/sha256/table16/compression/compression_util.rs @@ -111,7 +111,7 @@ pub fn get_round_row(round_idx: RoundIdx) -> usize { RoundIdx::Init => 0, RoundIdx::Main(MainRoundIdx(idx)) => { assert!(idx < 64); - (idx as usize) * SUBREGION_MAIN_WORD + idx * SUBREGION_MAIN_WORD } } } @@ -783,7 +783,7 @@ impl CompressionConfig { || "h_prime_carry", a_9, row + 1, - || h_prime_carry.map(|value| pallas::Base::from(value as u64)), + || h_prime_carry.map(pallas::Base::from), )?; let h_prime: Value<[bool; 32]> = h_prime.map(|w| i2lebsp(w.into())); diff --git a/halo2_gadgets/src/sha256/table16/message_schedule/schedule_util.rs b/halo2_gadgets/src/sha256/table16/message_schedule/schedule_util.rs index 79a9fa2621..d8bf48eeba 100644 --- a/halo2_gadgets/src/sha256/table16/message_schedule/schedule_util.rs +++ b/halo2_gadgets/src/sha256/table16/message_schedule/schedule_util.rs @@ -40,20 +40,20 @@ pub fn get_word_row(word_idx: usize) -> usize { if word_idx == 0 { 0 } else if (1..=13).contains(&word_idx) { - SUBREGION_0_ROWS + SUBREGION_1_WORD * (word_idx - 1) as usize + SUBREGION_0_ROWS + SUBREGION_1_WORD * (word_idx - 1) } else if (14..=48).contains(&word_idx) { SUBREGION_0_ROWS + SUBREGION_1_ROWS + SUBREGION_2_WORD * (word_idx - 14) + 1 } else if (49..=61).contains(&word_idx) { SUBREGION_0_ROWS + SUBREGION_1_ROWS + SUBREGION_2_ROWS - + SUBREGION_3_WORD * (word_idx - 49) as usize + + SUBREGION_3_WORD * (word_idx - 49) } else { SUBREGION_0_ROWS + SUBREGION_1_ROWS + SUBREGION_2_ROWS + SUBREGION_3_ROWS - + DECOMPOSE_0_ROWS * (word_idx - 62) as usize + + DECOMPOSE_0_ROWS * (word_idx - 62) } } diff --git a/halo2_gadgets/src/sha256/table16/message_schedule/subregion2.rs b/halo2_gadgets/src/sha256/table16/message_schedule/subregion2.rs index 43e96c934f..9733b46039 100644 --- a/halo2_gadgets/src/sha256/table16/message_schedule/subregion2.rs +++ b/halo2_gadgets/src/sha256/table16/message_schedule/subregion2.rs @@ -261,7 +261,7 @@ impl MessageScheduleConfig { || format!("carry_{}", new_word_idx), a_9, get_word_row(new_word_idx - 16) + 1, - || carry.map(|carry| pallas::Base::from(carry as u64)), + || carry.map(pallas::Base::from), )?; let (word, halves) = self.assign_word_and_halves(region, word, new_word_idx)?; w.push(MessageWord(word)); diff --git a/halo2_gadgets/src/sha256/table16/message_schedule/subregion3.rs b/halo2_gadgets/src/sha256/table16/message_schedule/subregion3.rs index b23046e42e..aebe1945d9 100644 --- a/halo2_gadgets/src/sha256/table16/message_schedule/subregion3.rs +++ b/halo2_gadgets/src/sha256/table16/message_schedule/subregion3.rs @@ -177,7 +177,7 @@ impl MessageScheduleConfig { || format!("carry_{}", new_word_idx), a_9, get_word_row(new_word_idx - 16) + 1, - || carry.map(|carry| pallas::Base::from(carry as u64)), + || carry.map(pallas::Base::from), )?; let (word, halves) = self.assign_word_and_halves(region, word, new_word_idx)?; w.push(MessageWord(word)); diff --git a/halo2_gadgets/src/sha256/table16/util.rs b/halo2_gadgets/src/sha256/table16/util.rs index 6a790d3797..d3da5317ca 100644 --- a/halo2_gadgets/src/sha256/table16/util.rs +++ b/halo2_gadgets/src/sha256/table16/util.rs @@ -110,7 +110,7 @@ pub fn sum_with_carry(words: Vec<(Value, Value)>) -> (Value, Valu sum_lo.zip(sum_hi).map(|(lo, hi)| lo + (1 << 16) * hi) }; - let carry = sum.map(|sum| (sum >> 32) as u64); + let carry = sum.map(|sum| (sum >> 32)); let sum = sum.map(|sum| sum as u32); (sum, carry) diff --git a/halo2_gadgets/src/sinsemilla.rs b/halo2_gadgets/src/sinsemilla.rs index 48b929cbeb..2f7110cc47 100644 --- a/halo2_gadgets/src/sinsemilla.rs +++ b/halo2_gadgets/src/sinsemilla.rs @@ -197,7 +197,7 @@ where // Each message piece must have at most `floor(C::Base::CAPACITY / K)` words. // This ensures that the all-ones bitstring is canonical in the field. let piece_max_num_words = C::Base::CAPACITY as usize / K; - assert!(num_words <= piece_max_num_words as usize); + assert!(num_words <= piece_max_num_words); // Closure to parse a bitstring (little-endian) into a base field element. let to_base_field = |bits: &[Value]| -> Value { @@ -496,6 +496,7 @@ pub(crate) mod tests { #[derive(Debug, Clone, Eq, PartialEq)] pub(crate) struct TestHashDomain; + #[allow(non_snake_case)] impl HashDomains for TestHashDomain { fn Q(&self) -> pallas::Affine { *Q @@ -656,8 +657,8 @@ pub(crate) mod tests { let point = merkle_crh .hash_to_point( l.into_iter() - .chain(left.into_iter()) - .chain(right.into_iter()), + .chain(left) + .chain(right), ) .unwrap(); point.to_affine() diff --git a/halo2_gadgets/src/utilities.rs b/halo2_gadgets/src/utilities.rs index 887ee92475..97dd323c58 100644 --- a/halo2_gadgets/src/utilities.rs +++ b/halo2_gadgets/src/utilities.rs @@ -99,7 +99,7 @@ impl RangeConstrained> { Self { inner: value.map(|value| bitrange_subset(value, bitrange)), num_bits, - _phantom: PhantomData::default(), + _phantom: PhantomData, } } } @@ -114,7 +114,7 @@ impl RangeConstrained> { Self { inner: cell, num_bits, - _phantom: PhantomData::default(), + _phantom: PhantomData, } } @@ -123,7 +123,7 @@ impl RangeConstrained> { RangeConstrained { inner: self.inner.value().copied(), num_bits: self.num_bits, - _phantom: PhantomData::default(), + _phantom: PhantomData, } } } @@ -339,6 +339,7 @@ mod tests { #[allow(clippy::assign_op_pattern)] #[allow(clippy::ptr_offset_with_cast)] + #[allow(clippy::single_range_in_vec_init)] #[test] fn test_bitrange_subset() { let rng = OsRng; @@ -405,7 +406,6 @@ mod tests { } assert_eq!(field_elem, sum); }; - decompose(pallas::Base::random(rng), &[0..255]); decompose(pallas::Base::random(rng), &[0..1, 1..255]); decompose(pallas::Base::random(rng), &[0..254, 254..255]); diff --git a/halo2_gadgets/src/utilities/lookup_range_check.rs b/halo2_gadgets/src/utilities/lookup_range_check.rs index 22a8bf2bf2..7312206970 100644 --- a/halo2_gadgets/src/utilities/lookup_range_check.rs +++ b/halo2_gadgets/src/utilities/lookup_range_check.rs @@ -49,7 +49,7 @@ impl RangeConstrained> { .map(|inner| Self { inner, num_bits, - _phantom: PhantomData::default(), + _phantom: PhantomData, }) } } diff --git a/halo2_proofs/src/dev.rs b/halo2_proofs/src/dev.rs index a1132c97a0..38c805b085 100644 --- a/halo2_proofs/src/dev.rs +++ b/halo2_proofs/src/dev.rs @@ -837,7 +837,7 @@ impl + Ord> MockProver { .flat_map(|(gate_index, gate)| { let blinding_rows = (self.n as usize - (self.cs.blinding_factors() + 1))..(self.n as usize); - (gate_row_ids.clone().chain(blinding_rows.into_iter())).flat_map(move |row| { + (gate_row_ids.clone().chain(blinding_rows)).flat_map(move |row| { let row = row as i32 + n; gate.polynomials().iter().enumerate().filter_map( move |(poly_index, poly)| match poly.evaluate_lazy( @@ -2028,7 +2028,7 @@ mod tests { || Value::known(Fp::from(2 * i as u64)), ) }) - .fold(Ok(()), |acc, res| acc.and(res)) + .try_fold((), |_, res| res) }, )?; diff --git a/halo2_proofs/src/dev/cost.rs b/halo2_proofs/src/dev/cost.rs index 5dd2842867..1f131a2d40 100644 --- a/halo2_proofs/src/dev/cost.rs +++ b/halo2_proofs/src/dev/cost.rs @@ -338,7 +338,6 @@ impl> CircuitCost> CircuitCost> CircuitCost> CircuitCost>, Iter: IntoIterator> IntoIterato fn into_iter(self) -> Self::IntoIter { std::iter::repeat(self.selector) - .zip(self.constraints.into_iter()) + .zip(self.constraints) .map(apply_selector_to_constraint) } } @@ -1967,7 +1967,7 @@ impl ConstraintSystem { let (polys, selector_assignment) = compress_selectors::process( selectors .into_iter() - .zip(degrees.into_iter()) + .zip(degrees) .enumerate() .map( |(i, (activations, max_degree))| compress_selectors::SelectorDescription { diff --git a/halo2_proofs/src/poly.rs b/halo2_proofs/src/poly.rs index 02779d0e79..9cb6b149bc 100644 --- a/halo2_proofs/src/poly.rs +++ b/halo2_proofs/src/poly.rs @@ -199,7 +199,7 @@ pub(crate) fn batch_invert_assigned( assigned .iter() - .zip(assigned_denominators.into_iter()) + .zip(assigned_denominators) .map(|(poly, inv_denoms)| poly.invert(inv_denoms.into_iter().map(|d| d.unwrap_or(F::ONE)))) .collect() } @@ -214,7 +214,7 @@ impl Polynomial, LagrangeCoeff> { values: self .values .iter() - .zip(inv_denoms.into_iter()) + .zip(inv_denoms) .map(|(a, inv_den)| a.numerator() * inv_den) .collect(), _marker: self._marker, diff --git a/halo2_proofs/src/poly/ipa/multiopen/prover.rs b/halo2_proofs/src/poly/ipa/multiopen/prover.rs index 8998f38723..2ae745d457 100644 --- a/halo2_proofs/src/poly/ipa/multiopen/prover.rs +++ b/halo2_proofs/src/poly/ipa/multiopen/prover.rs @@ -107,7 +107,7 @@ impl<'params, C: CurveAffine> Prover<'params, IPACommitmentScheme> for Prover let x_4: ChallengeX4<_> = transcript.squeeze_challenge_scalar(); - let (p_poly, p_poly_blind) = q_polys.into_iter().zip(q_blinds.into_iter()).fold( + let (p_poly, p_poly_blind) = q_polys.into_iter().zip(q_blinds).fold( (q_prime_poly, q_prime_blind), |(q_prime_poly, q_prime_blind), (poly, blind)| { ( diff --git a/halo2_proofs/tests/plonk_api.rs b/halo2_proofs/tests/plonk_api.rs index 36df18393e..039824f9d3 100644 --- a/halo2_proofs/tests/plonk_api.rs +++ b/halo2_proofs/tests/plonk_api.rs @@ -514,7 +514,7 @@ fn plonk_api() { Scheme::Scalar: Ord + WithSmallOrderMulGroup<3> + FromUniformBytes<64>, { let (_, instance, _) = common!(Scheme); - let pubinputs = vec![instance]; + let pubinputs = [instance]; let mut transcript = T::init(proof); @@ -589,6 +589,7 @@ fn plonk_api() { >(verifier_params, pk.get_vk(), &proof[..]); } + #[allow(clippy::needless_raw_string_hashes)] fn test_plonk_api_ipa() { use halo2_proofs::poly::ipa::commitment::{IPACommitmentScheme, ParamsIPA}; use halo2_proofs::poly::ipa::multiopen::{ProverIPA, VerifierIPA};