Skip to content

Commit

Permalink
meta: Fixup clippy lints and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joeykraut committed Oct 10, 2023
1 parent c0b8842 commit 576ba6d
Show file tree
Hide file tree
Showing 20 changed files with 36 additions and 114 deletions.
30 changes: 0 additions & 30 deletions .github/pull_request_template.md

This file was deleted.

24 changes: 0 additions & 24 deletions .github/workflows/combine-prs.yml

This file was deleted.

17 changes: 0 additions & 17 deletions .github/workflows/commit-title.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion plonk/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ macro_rules! plonk_batch_verify_bench {
.unwrap();

let vks = vec![&vk; $num_proofs];
let pub_input = vec![];
let pub_input = [];
let public_inputs_ref = vec![&pub_input[..]; $num_proofs];
let proofs_ref = vec![&proof; $num_proofs];

Expand Down
6 changes: 2 additions & 4 deletions plonk/examples/proof_of_exp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use ark_bls12_381::Bls12_381;
use ark_ec::{
pairing::Pairing,
twisted_edwards::{Affine as TEAffine, TECurveConfig},
AffineRepr, CurveConfig, CurveGroup,
};
Expand Down Expand Up @@ -44,7 +43,7 @@ fn main() -> Result<(), PlonkError> {
// - public group element `X := xG`
// This circuit does not need to have real inputs.
// We can simply use a dummy data set.
let circuit = proof_of_exponent_circuit::<EdwardsConfig, Bls12_381>(x, X)?;
let circuit = proof_of_exponent_circuit::<EdwardsConfig>(x, X)?;

// Knowing the circuit size, we are able to simulate the universal
// setup and obtain the structured reference string (SRS).
Expand Down Expand Up @@ -95,14 +94,13 @@ fn main() -> Result<(), PlonkError> {
// - a pairing engine
// - the native field F for the prove system
#[allow(non_snake_case)]
fn proof_of_exponent_circuit<EmbedCurve, PairingCurve>(
fn proof_of_exponent_circuit<EmbedCurve>(
x: EmbedCurve::ScalarField,
X: TEAffine<EmbedCurve>,
) -> Result<PlonkCircuit<EmbedCurve::BaseField>, PlonkError>
where
EmbedCurve: TECurveConfig,
<EmbedCurve as CurveConfig>::BaseField: PrimeField,
PairingCurve: Pairing,
{
// Let's check that the inputs are indeed correct before we build a circuit.
let G = TEAffine::<EmbedCurve>::generator();
Expand Down
4 changes: 2 additions & 2 deletions plonk/src/proof_system/snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ pub mod test {
for i in a0..(a0 + 4 * m) {
a.push(cs.create_variable(F::from(i as u64))?);
}
let b = vec![
let b = [
cs.create_public_variable(F::from(m as u64 * 2))?,
cs.create_public_variable(F::from(a0 as u64 * 2 + m as u64 * 4 - 1))?,
];
Expand Down Expand Up @@ -1733,7 +1733,7 @@ pub mod test {
for i in a0..(a0 + 4 * m) {
a.push(cs.create_variable(F::from(i as u64))?);
}
let b = vec![
let b = [
cs.create_public_variable(F::from(m as u64 * 2))?,
cs.create_public_variable(F::from(a0 as u64 * 2 + m as u64 * 4 - 1))?,
];
Expand Down
24 changes: 11 additions & 13 deletions plonk/src/testing_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,17 @@ where
) -> Result<E::ScalarField, PlonkError> {
let tmp: verifier::Verifier<E> = (*self).clone().into();
let challenges: structs::Challenges<E::ScalarField> = (*challenges).into();
Ok(tmp
.compute_lin_poly_constant_term(
&challenges,
verify_keys,
public_inputs,
batch_proof,
vanish_eval,
lagrange_1_eval,
lagrange_n_eval,
alpha_powers,
alpha_bases,
)?
.into())
tmp.compute_lin_poly_constant_term(
&challenges,
verify_keys,
public_inputs,
batch_proof,
vanish_eval,
lagrange_1_eval,
lagrange_n_eval,
alpha_powers,
alpha_bases,
)
}

/// Aggregate polynomial commitments into a single commitment (in the
Expand Down
1 change: 1 addition & 0 deletions primitives/benches/advz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ where
// play with these items
const RATE: usize = 4; // ratio of num_storage_nodes : polynomial_degree
let storage_node_counts = [600, 700, 800, 900, 1000];
#[allow(clippy::identity_op)]
let payload_byte_lens = [1 * MB];

// more items as a function of the above
Expand Down
8 changes: 5 additions & 3 deletions primitives/benches/bls_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fn bench_aggregate<S: AggregateableSignatureSchemes, T: criterion::measurement::
);
}

#[allow(clippy::let_unit_value)]
fn bench_bls12381(c: &mut Criterion) {
let mut benchmark_group = c.benchmark_group("BLS Over BLS12-381");
benchmark_group.sample_size(500);
Expand All @@ -70,6 +71,7 @@ fn bench_bls12381(c: &mut Criterion) {
benchmark_group.finish();
}

#[allow(clippy::let_unit_value)]
fn bench_bn254(c: &mut Criterion) {
let mut benchmark_group = c.benchmark_group("BLS Over Bn254");
benchmark_group.sample_size(100);
Expand All @@ -79,13 +81,13 @@ fn bench_bn254(c: &mut Criterion) {
let (sk, vk) = BLSOverBN254CurveSignatureScheme::key_gen(&pp, rng).unwrap();
let msg = vec![12u8; 1000];
let msgs = vec![msg.as_slice(); 1000];
let sig = BLSOverBN254CurveSignatureScheme::sign(&pp, &sk, &msgs[0], rng).unwrap();
let sig = BLSOverBN254CurveSignatureScheme::sign(&pp, &sk, msgs[0], rng).unwrap();

benchmark_group.bench_function("Sign", |b| {
b.iter(|| BLSOverBN254CurveSignatureScheme::sign(&pp, &sk, &msgs[0], rng).unwrap())
b.iter(|| BLSOverBN254CurveSignatureScheme::sign(&pp, &sk, msgs[0], rng).unwrap())
});
benchmark_group.bench_function("Verification", |b| {
b.iter(|| BLSOverBN254CurveSignatureScheme::verify(&pp, &vk, &msgs[0], &sig).unwrap())
b.iter(|| BLSOverBN254CurveSignatureScheme::verify(&pp, &vk, msgs[0], &sig).unwrap())
});

bench_aggregate::<BLSOverBN254CurveSignatureScheme, _>(
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/circuit/rescue/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ mod tests {

// bad path: incorrect number of inputs
let mut circuit = PlonkCircuit::new_turbo_plonk();
let input_vec = vec![
let input_vec = [
F::from(11_u32),
F::from(144_u32),
F::from(87_u32),
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/elgamal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ mod test {
($param: tt, $base_field:tt, $scalar_field: tt) => {
let mut rng = jf_utils::test_rng();
let keypair = KeyPair::<$param>::generate(&mut rng);
let msg = vec![$base_field::rand(&mut rng)];
let msg = [$base_field::rand(&mut rng)];
let ct = keypair.enc_key().encrypt(&mut rng, &msg[..]);

let mut ser_bytes: Vec<u8> = Vec::new();
Expand Down
5 changes: 1 addition & 4 deletions primitives/src/merkle_tree/append_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ where
}
}

// TODO(Chengyu): extract a merkle frontier

// TODO(Chengyu): unit tests
#[cfg(test)]
mod mt_tests {
use crate::{
Expand Down Expand Up @@ -172,7 +169,7 @@ mod mt_tests {
let mut mt = RescueMerkleTree::<F>::from_elems(2, &[F::from(3u64), F::from(1u64)]).unwrap();
let root = mt.commitment().digest();
let (lookup_elem, lookup_proof) = mt.lookup(0).expect_ok().unwrap();
let lookup_elem = lookup_elem.clone();
let lookup_elem = *lookup_elem;
let (elem, proof) = mt.forget(0).expect_ok().unwrap();
assert_eq!(lookup_elem, elem);
assert_eq!(lookup_proof, proof);
Expand Down
4 changes: 0 additions & 4 deletions primitives/src/merkle_tree/hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
//! Use [`GenericHasherMerkleTree`] if you prefer to specify your own `Arity`
//! and node [`Index`] types.
// clippy is freaking out about `HasherNode` and this is the only thing I
// could do to stop it
#![allow(clippy::incorrect_partial_ord_impl_on_ord_type)]

use crate::errors::PrimitivesError;

use super::{append_only::MerkleTree, DigestAlgorithm, Element, Index};
Expand Down
1 change: 1 addition & 0 deletions primitives/src/merkle_tree/namespaced_merkle_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ mod nmt_tests {
Extend,
}

#[allow(clippy::needless_borrow)]
fn build_tree(leaves: &[Leaf], build_type: BuildType) -> TestNMT {
match build_type {
BuildType::FromElems => TestNMT::from_elems(3, leaves).unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/merkle_tree/universal_merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ mod mt_tests {
.universal_lookup(BigUint::from(0u64))
.expect_ok()
.unwrap();
let lookup_elem = lookup_elem.clone();
let lookup_elem = *lookup_elem;
let (elem, mem_proof) = mt.universal_forget(0u64.into()).expect_ok().unwrap();
assert_eq!(lookup_elem, elem);
assert_eq!(lookup_mem_proof, mem_proof);
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/pcs/multilinear_kzg/srs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ mod tests {
let scalar_bits = E::ScalarField::MODULUS_BIT_SIZE as usize;

let mut eq: LinkedList<DenseMultilinearExtension<E::ScalarField>> =
LinkedList::from_iter(eq_extension(&t).into_iter());
LinkedList::from_iter(eq_extension(&t));
let mut eq_arr = LinkedList::new();
let mut base = eq.pop_back().unwrap().evaluations;

Expand Down
8 changes: 4 additions & 4 deletions primitives/src/signatures/bls_over_bn254.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,10 @@ mod tests {

#[test]
fn test_agg_sig_trait() {
let m1 = vec![87u8, 32u8];
let m2 = vec![12u8, 2u8, 7u8];
let m3 = vec![3u8, 6u8];
let m4 = vec![72u8];
let m1 = [87u8, 32u8];
let m2 = [12u8, 2u8, 7u8];
let m3 = [3u8, 6u8];
let m4 = [72u8];
let messages = vec![&m1[..], &m2[..], &m3[..], &m4[..]];
let wrong_message = vec![255u8];
agg_sign_and_verify::<BLSOverBN254CurveSignatureScheme>(
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/toeplitz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ mod tests {

// bad path
// mismatched matrix.col.len() and msgs.len() should fail
let bad_msg = vec![msgs.to_vec(), vec![G1Projective::rand(&mut rng)]].concat();
let bad_msg = [msgs.to_vec(), vec![G1Projective::rand(&mut rng)]].concat();
assert!(cir_matrix.fast_vec_mul(&bad_msg).is_err());

// non power-of-two matrix fast mul should fail
Expand Down
4 changes: 2 additions & 2 deletions primitives/src/vid/advz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ mod tests {
#[test]
fn sad_path_verify_share_corrupt_commit() {
let (advz, bytes_random) = avdz_init();
let disperse = advz.disperse(&bytes_random).unwrap();
let disperse = advz.disperse(bytes_random).unwrap();
let (shares, common) = (disperse.shares, disperse.common);

// missing commit
Expand Down Expand Up @@ -696,7 +696,7 @@ mod tests {
#[test]
fn sad_path_verify_share_corrupt_share_and_commit() {
let (advz, bytes_random) = avdz_init();
let disperse = advz.disperse(&bytes_random).unwrap();
let disperse = advz.disperse(bytes_random).unwrap();
let (mut shares, mut common) = (disperse.shares, disperse.common);

common.poly_commits.pop();
Expand Down
2 changes: 1 addition & 1 deletion utilities/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ mod tests {

// empty input -> empty output
let bytes = Vec::new();
assert!(bytes.iter().next().is_none());
assert!(bytes.first().is_none());
let mut elems_iter = bytes_to_field::<_, F>(bytes.iter());
assert!(elems_iter.next().is_none());

Expand Down

0 comments on commit 576ba6d

Please sign in to comment.