Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
jules committed Aug 9, 2023
1 parent 4902cd2 commit 4fc762a
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 58 deletions.
8 changes: 4 additions & 4 deletions plonk-core/src/constraint_system/composer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ where
let d = w_4[i];
let d_next = w_4[(i + 1) % self.n];

#[cfg(all(feature = "trace-print"))]
#[cfg(feature = "trace-print")]
std::println!(
"--------------------------------------------\n
#Gate Index = {}
Expand Down Expand Up @@ -801,9 +801,9 @@ where
+ (qo * c)
+ (q4 * d)
+ pi
+ q_hl * a.pow(&[SBOX_ALPHA])
+ q_hr * b.pow(&[SBOX_ALPHA])
+ q_h4 * d.pow(&[SBOX_ALPHA])
+ q_hl * a.pow([SBOX_ALPHA])
+ q_hr * b.pow([SBOX_ALPHA])
+ q_h4 * d.pow([SBOX_ALPHA])
+ qc)
+ qlogic
* (((delta(*a_next - four * a)
Expand Down
8 changes: 4 additions & 4 deletions plonk-core/src/constraint_system/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ where
selectors: &[F; 5],
) -> Variable {
let w4_val = (selectors[0]
* self.value_of_var(vars[0]).pow(&[SBOX_ALPHA])
+ selectors[1] * self.value_of_var(vars[1]).pow(&[SBOX_ALPHA])
+ selectors[2] * self.value_of_var(vars[2]).pow(&[SBOX_ALPHA])
* self.value_of_var(vars[0]).pow([SBOX_ALPHA])
+ selectors[1] * self.value_of_var(vars[1]).pow([SBOX_ALPHA])
+ selectors[2] * self.value_of_var(vars[2]).pow([SBOX_ALPHA])
+ selectors[3])
/ -selectors[4];
let w4_var = self.add_input(w4_val);
Expand Down Expand Up @@ -76,7 +76,7 @@ where
selectors: &[F; 5],
) -> Variable {
let w4_val = (selectors[0]
* self.value_of_var(vars[0]).pow(&[SBOX_ALPHA])
* self.value_of_var(vars[0]).pow([SBOX_ALPHA])
+ selectors[1] * self.value_of_var(vars[1])
+ selectors[2] * self.value_of_var(vars[2])
+ selectors[3])
Expand Down
4 changes: 2 additions & 2 deletions plonk-core/src/constraint_system/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ where
// in Big Endian form.
left_quad = {
let idx = i << 1;
((a_bits[idx] as u8) << 1) + (a_bits[idx + 1] as u8)
((a_bits[idx]) << 1) + a_bits[idx + 1]
};
right_quad = {
let idx = i << 1;
((b_bits[idx] as u8) << 1) + (b_bits[idx + 1] as u8)
((b_bits[idx]) << 1) + b_bits[idx + 1]
};
let left_quad_fr = F::from(left_quad as u64);
let right_quad_fr = F::from(right_quad as u64);
Expand Down
21 changes: 6 additions & 15 deletions plonk-core/src/lookup/lookup_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,15 @@ mod test {
// This way, we can also do the modulo operation, and properly
// check all results.
let mut i = 0;
let p = 2u64.pow(n as u32);
let p = 2u64.pow(n);
(0..p).for_each(|a| {
(0..p).for_each(|b| {
let c = (a + b) % p;
assert_eq!(F::from(c), table.0[i][2]);
i += 1;
})
});
assert_eq!(
table.0.len() as u64,
2u64.pow(n as u32) * 2u64.pow(n as u32)
);
assert_eq!(table.0.len() as u64, 2u64.pow(n) * 2u64.pow(n));
}

fn test_xor_table<F>()
Expand All @@ -242,18 +239,15 @@ mod test {
let n = 4;
let table = LookupTable::xor_table(0, n);
let mut i = 0;
let p = 2u64.pow(n as u32);
let p = 2u64.pow(n);
(0..p).for_each(|a| {
(0..p).for_each(|b| {
let c = a ^ b;
assert_eq!(F::from(c), table.0[i][2]);
i += 1;
})
});
assert_eq!(
table.0.len() as u64,
2u64.pow(n as u32) * 2u64.pow(n as u32)
);
assert_eq!(table.0.len() as u64, 2u64.pow(n) * 2u64.pow(n));
}

fn test_mul_table<F>()
Expand All @@ -263,18 +257,15 @@ mod test {
let n = 4;
let table = LookupTable::mul_table(0, n);
let mut i = 0;
let p = 2u64.pow(n as u32);
let p = 2u64.pow(n);
(0..p).for_each(|a| {
(0..p).for_each(|b| {
let c = (a * b) % p;
assert_eq!(F::from(c), table.0[i][2]);
i += 1;
})
});
assert_eq!(
table.0.len() as u64,
2u64.pow(n as u32) * 2u64.pow(n as u32)
);
assert_eq!(table.0.len() as u64, 2u64.pow(n) * 2u64.pow(n));
}

fn test_lookup_arity_3<F>()
Expand Down
1 change: 1 addition & 0 deletions plonk-core/src/lookup/preprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ mod test {

/// This function creates a table and preprocesses it. Then it checks that
/// all table columns are the same length.
#[allow(clippy::extra_unused_type_parameters)]
fn test_table_preprocessing<F, P, PC>()
where
F: PrimeField,
Expand Down
8 changes: 4 additions & 4 deletions plonk-core/src/permutation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,8 @@ mod test {
let domain =
GeneralEvaluationDomain::<F>::new(num_wire_mappings).unwrap();
let w = domain.group_gen();
let w_squared = w.pow(&[2, 0, 0, 0]);
let w_cubed = w.pow(&[3, 0, 0, 0]);
let w_squared = w.pow([2, 0, 0, 0]);
let w_cubed = w.pow([3, 0, 0, 0]);

// Check the left sigmas have been encoded properly
// Left_sigma = {R0, L2, L3, L0}
Expand Down Expand Up @@ -1167,8 +1167,8 @@ mod test {
let domain =
GeneralEvaluationDomain::<F>::new(num_wire_mappings).unwrap();
let w = domain.group_gen();
let w_squared = w.pow(&[2, 0, 0, 0]);
let w_cubed = w.pow(&[3, 0, 0, 0]);
let w_squared = w.pow([2, 0, 0, 0]);
let w_cubed = w.pow([3, 0, 0, 0]);
// check the left sigmas have been encoded properly
let encoded_left_sigma =
perm.compute_permutation_lagrange(left_sigma, &domain);
Expand Down
6 changes: 3 additions & 3 deletions plonk-core/src/proof_system/preprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ where
self.check_poly_same_len()?;

// 1. Pad circuit to a power of two
self.pad(domain.size() as usize - self.n);
self.pad(domain.size() - self.n);

let q_m_poly: DensePolynomial<F> =
DensePolynomial::from_coefficients_vec(domain.ifft(&self.q_m));
Expand Down Expand Up @@ -510,10 +510,10 @@ where
poly_degree
);
let group_gen = domain.element(1);
let coset_gen = F::multiplicative_generator().pow(&[poly_degree]);
let coset_gen = F::multiplicative_generator().pow([poly_degree]);
let v_h: Vec<_> = (0..domain.size())
.map(|i| {
(coset_gen * group_gen.pow(&[poly_degree * i as u64])) - F::one()
(coset_gen * group_gen.pow([poly_degree * i as u64])) - F::one()
})
.collect();
Evaluations::from_vec_and_domain(v_h, domain)
Expand Down
2 changes: 1 addition & 1 deletion plonk-core/src/proof_system/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ where
.map(|i| {
// index of non-zero evaluation
let index = non_zero_evaluations[i];
(group_gen_inv.pow(&[index as u64, 0, 0, 0]) * point) - F::one()
(group_gen_inv.pow([index as u64, 0, 0, 0]) * point) - F::one()
})
.collect::<Vec<_>>();
batch_inversion(&mut denominators);
Expand Down
18 changes: 9 additions & 9 deletions plonk-core/src/proof_system/widget/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ where
+ (wit_vals.b_val * self.q_r.1[index])
+ (wit_vals.c_val * self.q_o.1[index])
+ (wit_vals.d_val * self.q_4.1[index])
+ (wit_vals.a_val.pow(&[SBOX_ALPHA]) * self.q_hl.1[index])
+ (wit_vals.b_val.pow(&[SBOX_ALPHA]) * self.q_hr.1[index])
+ (wit_vals.d_val.pow(&[SBOX_ALPHA]) * self.q_h4.1[index])
+ (wit_vals.a_val.pow([SBOX_ALPHA]) * self.q_hl.1[index])
+ (wit_vals.b_val.pow([SBOX_ALPHA]) * self.q_hr.1[index])
+ (wit_vals.d_val.pow([SBOX_ALPHA]) * self.q_h4.1[index])
+ self.q_c.1[index])
* self.q_arith.1[index]
}
Expand All @@ -92,9 +92,9 @@ where
+ (&self.q_r.0 * b_eval)
+ (&self.q_o.0 * c_eval)
+ (&self.q_4.0 * d_eval)
+ (&self.q_hl.0 * a_eval.pow(&[SBOX_ALPHA]))
+ (&self.q_hr.0 * b_eval.pow(&[SBOX_ALPHA]))
+ (&self.q_h4.0 * d_eval.pow(&[SBOX_ALPHA])))
+ (&self.q_hl.0 * a_eval.pow([SBOX_ALPHA]))
+ (&self.q_hr.0 * b_eval.pow([SBOX_ALPHA]))
+ (&self.q_h4.0 * d_eval.pow([SBOX_ALPHA])))
+ &self.q_c.0)
* q_arith_eval
}
Expand Down Expand Up @@ -180,17 +180,17 @@ where
points.push(self.q_o.clone());

scalars.push(
evaluations.wire_evals.a_eval.pow(&[SBOX_ALPHA]) * q_arith_eval,
evaluations.wire_evals.a_eval.pow([SBOX_ALPHA]) * q_arith_eval,
);
points.push(self.q_hl.clone());

scalars.push(
evaluations.wire_evals.b_eval.pow(&[SBOX_ALPHA]) * q_arith_eval,
evaluations.wire_evals.b_eval.pow([SBOX_ALPHA]) * q_arith_eval,
);
points.push(self.q_hr.clone());

scalars.push(
evaluations.wire_evals.d_eval.pow(&[SBOX_ALPHA]) * q_arith_eval,
evaluations.wire_evals.d_eval.pow([SBOX_ALPHA]) * q_arith_eval,
);
points.push(self.q_h4.clone());

Expand Down
1 change: 1 addition & 0 deletions plonk-core/src/proof_system/widget/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ mod test {
assert_eq!(prover_key, obtained_pk);
}

#[allow(clippy::extra_unused_type_parameters)]
fn test_serialise_deserialise_verifier_key<F, P, PC>()
where
F: PrimeField,
Expand Down
8 changes: 4 additions & 4 deletions plonk-core/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ macro_rules! batch_test_kzg {
#[test]
#[allow(non_snake_case)]
fn [< $test_set _on_ $engine>]() {
$test_set::<<$engine as ark_ec::PairingEngine>::Fr, $params, crate::commitment::KZG10<$engine>>()
$test_set::<<$engine as ark_ec::PairingEngine>::Fr, $params, $crate::commitment::KZG10<$engine>>()
}
)*
$(
#[test]
#[should_panic]
#[allow(non_snake_case)]
fn [< $test_panic_set _on_ $engine>]() {
$test_panic_set::<<$engine as ark_ec::PairingEngine>::Fr, $params, crate::commitment::KZG10<$engine>>()
$test_panic_set::<<$engine as ark_ec::PairingEngine>::Fr, $params, $crate::commitment::KZG10<$engine>>()
}
)*
}
Expand All @@ -88,7 +88,7 @@ macro_rules! batch_test {
#[test]
#[allow(non_snake_case)]
fn [< $test_set _on_ $engine _kzg>]() {
$test_set::<<$engine as ark_ec::PairingEngine>::Fr, $params, crate::commitment::KZG10<$engine>>()
$test_set::<<$engine as ark_ec::PairingEngine>::Fr, $params, $crate::commitment::KZG10<$engine>>()
}
#[test]
#[allow(non_snake_case)]
Expand All @@ -101,7 +101,7 @@ macro_rules! batch_test {
#[should_panic]
#[allow(non_snake_case)]
fn [< $test_panic_set _on_ $engine _kzg>]() {
$test_panic_set::<<$engine as ark_ec::PairingEngine>::Fr, $params, crate::commitment::KZG10<$engine>>()
$test_panic_set::<<$engine as ark_ec::PairingEngine>::Fr, $params, $crate::commitment::KZG10<$engine>>()
}
#[test]
#[should_panic]
Expand Down
10 changes: 5 additions & 5 deletions plonk-hashing/src/poseidon/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<T: Clone> Matrix<T> {
}
}

pub fn iter_rows<'a>(&'a self) -> impl Iterator<Item = &'a Vec<T>> {
pub fn iter_rows(&self) -> impl Iterator<Item = &'_ Vec<T>> {
self.0.iter()
}

Expand Down Expand Up @@ -197,7 +197,7 @@ impl<F: PrimeField> Matrix<F> {
other_t
.iter_rows()
.map(|transposed_column| {
inner_product(&input_row, &transposed_column)
inner_product(input_row, transposed_column)
})
.collect()
})
Expand Down Expand Up @@ -269,7 +269,7 @@ impl<F: PrimeField> Matrix<F> {
result.push(row.to_vec());
} else {
let factor = val * inv_pivot;
let scaled_pivot = scalar_vec_mul(factor, &pivot);
let scaled_pivot = scalar_vec_mul(factor, pivot);
let eliminated = vec_sub(row, &scaled_pivot);
result.push(eliminated);

Expand Down Expand Up @@ -334,8 +334,8 @@ impl<F: PrimeField> Matrix<F> {
let val = row[idx];
let inv = val.inverse()?;

let mut normalized = scalar_vec_mul(inv, &row);
let mut shadow_normalized = scalar_vec_mul(inv, &shadow_row);
let mut normalized = scalar_vec_mul(inv, row);
let mut shadow_normalized = scalar_vec_mul(inv, shadow_row);

for j in 0..i {
let idx = size - j - 1;
Expand Down
2 changes: 1 addition & 1 deletion plonk-hashing/src/poseidon/mds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ mod tests {
x
};
let y = {
let mut y = base.clone();
let mut y = base;
y[0] = Fr::rand(&mut rng);
y
};
Expand Down
2 changes: 1 addition & 1 deletion plonk-hashing/src/poseidon/poseidon_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub trait PoseidonRefSpec<COM, const WIDTH: usize> {
.map(Some);

state.iter_mut().zip(pre_round_keys).for_each(|(l, pre)| {
*l = Self::quintic_s_box(c, l.clone(), pre.map(|x| *x), None);
*l = Self::quintic_s_box(c, l.clone(), pre.copied(), None);
});

*constants_offset += WIDTH;
Expand Down
4 changes: 2 additions & 2 deletions plonk-hashing/src/poseidon/preprocessing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) fn compress_round_constants<F: PrimeField>(
width: usize,
full_rounds: usize,
partial_rounds: usize,
round_constants: &Vec<F>,
round_constants: &[F],
mds_matrices: &MdsMatrices<F>,
) -> Vec<F> {
let inverse_matrix = &mds_matrices.m_inv;
Expand Down Expand Up @@ -66,7 +66,7 @@ pub(crate) fn compress_round_constants<F: PrimeField>(
partial_keys.push(inverted[0]);
inverted[0] = F::zero();

vec_add(&previous_round_keys, &inverted)
vec_add(previous_round_keys, &inverted)
});

res.extend(inverse_matrix.right_apply(&round_acc));
Expand Down
2 changes: 1 addition & 1 deletion plonk-hashing/src/poseidon/round_constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn generate_constants<F: PrimeField>(
}

fn append_bits<T: Into<u128>>(vec: &mut VecDeque<bool>, n: usize, from: T) {
let val = from.into() as u128;
let val = from.into();
for i in (0..n).rev() {
vec.push_back((val >> i) & 1 != 0);
}
Expand Down
4 changes: 2 additions & 2 deletions plonk-hashing/src/poseidon/zprize_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl<
.skip(*constants_offset)
.collect::<Vec<_>>();

let mut res = state.clone();
let mut res = *state;
if *constants_offset == 0 {
// first round
res[0] = <Self as PoseidonRefSpec<_, WIDTH>>::addi(
Expand Down Expand Up @@ -225,7 +225,7 @@ impl<
.skip(*constants_offset)
.collect::<Vec<_>>();

let res = state.clone();
let res = *state;
let matrix = &constants.mds_matrices.m.iter_rows().collect::<Vec<_>>();

state[0] = c.partial_affine_transform_gate(
Expand Down

0 comments on commit 4fc762a

Please sign in to comment.