Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clippy #203

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions halo2_gadgets/src/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl<
.unwrap(),
),
state,
_marker: PhantomData::default(),
_marker: PhantomData,
})
}

Expand Down Expand Up @@ -204,7 +204,7 @@ impl<
chip: self.chip,
mode,
state: self.state,
_marker: PhantomData::default(),
_marker: PhantomData,
})
}
}
Expand Down
39 changes: 17 additions & 22 deletions halo2_gadgets/src/poseidon/pow5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,30 +240,25 @@ impl<F: Field, S: Spec<F, WIDTH, RATE>, 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)
Expand Down
6 changes: 3 additions & 3 deletions halo2_gadgets/src/poseidon/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl<F: Field, S: Spec<F, T, RATE>, const T: usize, const RATE: usize>
state,
mds_matrix,
round_constants,
_marker: PhantomData::default(),
_marker: PhantomData,
}
}

Expand Down Expand Up @@ -257,7 +257,7 @@ impl<F: Field, S: Spec<F, T, RATE>, const T: usize, const RATE: usize>
state: self.state,
mds_matrix: self.mds_matrix,
round_constants: self.round_constants,
_marker: PhantomData::default(),
_marker: PhantomData,
}
}
}
Expand Down Expand Up @@ -364,7 +364,7 @@ impl<F: Field, S: Spec<F, T, RATE>, D: Domain<F, RATE>, const T: usize, const RA
pub fn init() -> Self {
Hash {
sponge: Sponge::new(D::initial_capacity_element()),
_domain: PhantomData::default(),
_domain: PhantomData,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion halo2_gadgets/src/poseidon/primitives/grain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<F: PrimeField> Grain<F> {
let mut grain = Grain {
state,
next_bit: STATE,
_field: PhantomData::default(),
_field: PhantomData,
};

// Discard the first 160 bits.
Expand Down
2 changes: 1 addition & 1 deletion halo2_gadgets/src/poseidon/primitives/p128pow5t3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ mod tests {

impl<F: Field, const SECURE_MDS: usize> P128Pow5T3Gen<F, SECURE_MDS> {
pub fn new() -> Self {
P128Pow5T3Gen(PhantomData::default())
P128Pow5T3Gen(PhantomData)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,17 @@ 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_0_ROWS + SUBREGION_1_ROWS + SUBREGION_2_ROWS + 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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion halo2_gadgets/src/sha256/table16/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn sum_with_carry(words: Vec<(Value<u16>, Value<u16>)>) -> (Value<u32>, 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)
Expand Down
9 changes: 3 additions & 6 deletions halo2_gadgets/src/sinsemilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>]| -> Value<C::Base> {
Expand Down Expand Up @@ -496,6 +496,7 @@ pub(crate) mod tests {

#[derive(Debug, Clone, Eq, PartialEq)]
pub(crate) struct TestHashDomain;
#[allow(non_snake_case)]
impl HashDomains<pallas::Affine> for TestHashDomain {
fn Q(&self) -> pallas::Affine {
*Q
Expand Down Expand Up @@ -654,11 +655,7 @@ pub(crate) mod tests {
|(l, (left, right))| {
let merkle_crh = sinsemilla::HashDomain::from_Q((*Q).into());
let point = merkle_crh
.hash_to_point(
l.into_iter()
.chain(left.into_iter())
.chain(right.into_iter()),
)
.hash_to_point(l.into_iter().chain(left).chain(right))
.unwrap();
point.to_affine()
},
Expand Down
7 changes: 3 additions & 4 deletions halo2_gadgets/src/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<F: PrimeFieldBits> RangeConstrained<F, Value<F>> {
Self {
inner: value.map(|value| bitrange_subset(value, bitrange)),
num_bits,
_phantom: PhantomData::default(),
_phantom: PhantomData,
}
}
}
Expand All @@ -114,7 +114,7 @@ impl<F: Field> RangeConstrained<F, AssignedCell<F, F>> {
Self {
inner: cell,
num_bits,
_phantom: PhantomData::default(),
_phantom: PhantomData,
}
}

Expand All @@ -123,7 +123,7 @@ impl<F: Field> RangeConstrained<F, AssignedCell<F, F>> {
RangeConstrained {
inner: self.inner.value().copied(),
num_bits: self.num_bits,
_phantom: PhantomData::default(),
_phantom: PhantomData,
}
}
}
Expand Down Expand Up @@ -405,7 +405,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]);
Expand Down
2 changes: 1 addition & 1 deletion halo2_gadgets/src/utilities/lookup_range_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<F: PrimeFieldBits> RangeConstrained<F, AssignedCell<F, F>> {
.map(|inner| Self {
inner,
num_bits,
_phantom: PhantomData::default(),
_phantom: PhantomData,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/benches/commit_zk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn rand_poly_serial(mut rng: ChaCha20Rng, domain: usize) -> Vec<Scalar> {

fn rand_poly_par(mut rng: ChaCha20Rng, domain: usize) -> Vec<Scalar> {
// Sample a random polynomial of degree n - 1
let n = 1usize << domain as usize;
let n = 1usize << domain;
let mut random_poly = vec![Scalar::ZERO; n];

let num_threads = current_num_threads();
Expand Down
4 changes: 2 additions & 2 deletions halo2_proofs/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ impl<F: FromUniformBytes<64> + Ord> MockProver<F> {
.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(
Expand Down Expand Up @@ -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)
},
)?;

Expand Down
6 changes: 3 additions & 3 deletions halo2_proofs/src/dev/cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ impl<G: PrimeGroup, ConcreteCircuit: Circuit<G::Scalar>> CircuitCost<G, Concrete
lookups: cs.lookups.len(),
permutation_cols,
point_sets: point_sets.len(),
_marker: PhantomData::default(),
max_rows: layout.total_rows,
max_advice_rows: layout.total_advice_rows,
max_fixed_rows: layout.total_fixed_rows,
Expand All @@ -348,6 +347,7 @@ impl<G: PrimeGroup, ConcreteCircuit: Circuit<G::Scalar>> CircuitCost<G, Concrete
num_total_columns: cs.num_instance_columns
+ cs.num_advice_columns
+ cs.num_fixed_columns,
_marker: PhantomData,
}
}

Expand Down Expand Up @@ -381,7 +381,7 @@ impl<G: PrimeGroup, ConcreteCircuit: Circuit<G::Scalar>> CircuitCost<G, Concrete
if chunks == 0 { chunks } else { 3 * chunks - 1 },
),

_marker: PhantomData::default(),
_marker: PhantomData,
}
}

Expand Down Expand Up @@ -424,7 +424,7 @@ impl<G: PrimeGroup, ConcreteCircuit: Circuit<G::Scalar>> CircuitCost<G, Concrete
// - xi
polycomm: ProofContribution::new((1 + 2 * self.k).try_into().unwrap(), 2),

_marker: PhantomData::default(),
_marker: PhantomData,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions halo2_proofs/src/plonk/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ impl<F: Field, C: Into<Constraint<F>>, Iter: IntoIterator<Item = C>> 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)
}
}
Expand Down Expand Up @@ -1967,7 +1967,7 @@ impl<F: Field> ConstraintSystem<F> {
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 {
Expand Down
4 changes: 2 additions & 2 deletions halo2_proofs/src/poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ pub(crate) fn batch_invert_assigned<F: Field>(

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()
}
Expand All @@ -214,7 +214,7 @@ impl<F: Field> Polynomial<Assigned<F>, 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,
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/poly/ipa/multiopen/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<'params, C: CurveAffine> Prover<'params, IPACommitmentScheme<C>> 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)| {
(
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/tests/plonk_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading