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

chore: add standard linting setup to all crates #2900

Merged
merged 4 commits into from
Sep 29, 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
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion acvm-repo/acir/src/circuit/black_box_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
/// Verifies a Schnorr signature over a curve which is "pairing friendly" with the curve on which the ACIR circuit is defined.
///
/// The exact curve which this signature uses will vary based on the curve being used by ACIR.
/// For example, the BN254 curve supports Schnorr signatures over the [Grumpkin][grumpkin] curve.

Check warning on line 28 in acvm-repo/acir/src/circuit/black_box_functions.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (Grumpkin)

Check warning on line 28 in acvm-repo/acir/src/circuit/black_box_functions.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (grumpkin)
///
/// [grumpkin]: https://hackmd.io/@aztec-network/ByzgNxBfd#2-Grumpkin---A-curve-on-top-of-BN-254-for-SNARK-efficient-group-operations

Check warning on line 30 in acvm-repo/acir/src/circuit/black_box_functions.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (grumpkin)
SchnorrVerify,
/// Calculates a Pedersen commitment to the inputs.
Pedersen,
Expand Down Expand Up @@ -112,7 +112,7 @@
assert_eq!(
resolved_func, bb_func,
"BlackBoxFunc::lookup returns unexpected BlackBoxFunc"
)
);
}
}
}
4 changes: 2 additions & 2 deletions acvm-repo/acir/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use std::{io::prelude::*, num::ParseIntError, str::FromStr};

use flate2::Compression;

Check warning on line 12 in acvm-repo/acir/src/circuit/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (flate)

use serde::{Deserialize, Serialize};
use std::collections::BTreeSet;
Expand Down Expand Up @@ -126,7 +126,7 @@
}

pub fn write<W: std::io::Write>(&self, writer: W) -> std::io::Result<()> {
let buf = bincode::serialize(&self).unwrap();

Check warning on line 129 in acvm-repo/acir/src/circuit/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (bincode)
let mut encoder = flate2::write::GzEncoder::new(writer, Compression::default());
encoder.write_all(&buf).unwrap();
encoder.finish().unwrap();
Expand Down Expand Up @@ -167,7 +167,7 @@
write_public_inputs(f, &self.return_values)?;

for opcode in &self.opcodes {
writeln!(f, "{opcode}")?
writeln!(f, "{opcode}")?;
}
Ok(())
}
Expand Down Expand Up @@ -236,7 +236,7 @@
}

let (circ, got_circ) = read_write(circuit);
assert_eq!(circ, got_circ)
assert_eq!(circ, got_circ);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ fn get_inputs_string(inputs: &[FunctionInput]) -> String {
result += &format!("(_{}, num_bits: {})", inp.witness.witness_index(), inp.num_bits);
// Add a comma, unless it is the last entry
if index != inputs.len() - 1 {
result += ", "
result += ", ";
}
}
result
Expand Down Expand Up @@ -358,7 +358,7 @@ fn get_outputs_string(outputs: &[Witness]) -> String {
result += &format!("_{}", output.witness_index());
// Add a comma, unless it is the last entry
if index != outputs.len() - 1 {
result += ", "
result += ", ";
}
}
result
Expand Down
4 changes: 3 additions & 1 deletion acvm-repo/acir/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![warn(unused_crate_dependencies)]
#![forbid(unsafe_code)]
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]

// Arbitrary Circuit Intermediate Representation

Expand Down
6 changes: 3 additions & 3 deletions acvm-repo/acir/src/native_types/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Expression {

/// Adds a new linear term to the `Expression`.
pub fn push_addition_term(&mut self, coefficient: FieldElement, variable: Witness) {
self.linear_combinations.push((coefficient, variable))
self.linear_combinations.push((coefficient, variable));
}

/// Adds a new quadratic term to the `Expression`.
Expand All @@ -82,7 +82,7 @@ impl Expression {
lhs: Witness,
rhs: Witness,
) {
self.mul_terms.push((coefficient, lhs, rhs))
self.mul_terms.push((coefficient, lhs, rhs));
}

/// Returns `true` if the expression represents a constant polynomial.
Expand Down Expand Up @@ -394,5 +394,5 @@ fn add_mul_smoketest() {
linear_combinations: vec![(FieldElement::from(40u128), Witness(4))],
q_c: FieldElement::from(10u128)
}
)
);
}
8 changes: 4 additions & 4 deletions acvm-repo/acir_field/src/generic_ark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// Check if the negative version is smaller to represent
//
let minus_number = BigUint::from_bytes_be(&(self.neg()).to_be_bytes());
let (smaller_repr, is_negative) =

Check warning on line 22 in acvm-repo/acir_field/src/generic_ark.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (repr)
if minus_number.to_string().len() < number.to_string().len() {
(minus_number, true)
} else {
Expand All @@ -30,13 +30,13 @@
}

// Number of bits needed to represent the smaller representation
let num_bits = smaller_repr.bits();

Check warning on line 33 in acvm-repo/acir_field/src/generic_ark.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (repr)

// Check if the number represents a power of 2
if smaller_repr.count_ones() == 1 {

Check warning on line 36 in acvm-repo/acir_field/src/generic_ark.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (repr)
let mut bit_index = 0;
for i in 0..num_bits {
if smaller_repr.bit(i) {

Check warning on line 39 in acvm-repo/acir_field/src/generic_ark.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (repr)
bit_index = i;
break;
}
Expand All @@ -59,7 +59,7 @@
let mul_sign = "×";
for power in [64, 32, 16, 8, 4] {
let power_of_two = BigUint::from(2_u128).pow(power);
if &smaller_repr % &power_of_two == BigUint::zero() {

Check warning on line 62 in acvm-repo/acir_field/src/generic_ark.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (repr)
return write!(
f,
"2{}{}{}",
Expand All @@ -81,7 +81,7 @@

impl<F: PrimeField> std::hash::Hash for FieldElement<F> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
state.write(&self.to_be_bytes())
state.write(&self.to_be_bytes());
}
}

Expand Down Expand Up @@ -295,7 +295,7 @@
fn byte_to_bit(byte: u8) -> Vec<bool> {
let mut bits = Vec::with_capacity(8);
for index in (0..=7).rev() {
bits.push((byte & (1 << index)) >> index == 1)
bits.push((byte & (1 << index)) >> index == 1);
}
bits
}
Expand Down Expand Up @@ -433,13 +433,13 @@
for (i, string) in hex_strings.into_iter().enumerate() {
let minus_i_field_element =
-crate::generic_ark::FieldElement::<ark_bn254::Fr>::from(i as i128);
assert_eq!(minus_i_field_element.to_hex(), string)
assert_eq!(minus_i_field_element.to_hex(), string);
}
}
#[test]
fn max_num_bits_smoke() {
let max_num_bits_bn254 = crate::generic_ark::FieldElement::<ark_bn254::Fr>::max_num_bits();
assert_eq!(max_num_bits_bn254, 254)
assert_eq!(max_num_bits_bn254, 254);
}
}

Expand Down
4 changes: 3 additions & 1 deletion acvm-repo/acir_field/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![warn(unused_crate_dependencies)]
#![forbid(unsafe_code)]
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]

cfg_if::cfg_if! {
if #[cfg(feature = "bn254")] {
Expand Down
8 changes: 4 additions & 4 deletions acvm-repo/acvm/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub fn compile(
for opcode in acir.opcodes {
match opcode {
Opcode::Arithmetic(arith_expr) => {
opcodes.push(Opcode::Arithmetic(GeneralOptimizer::optimize(arith_expr)))
opcodes.push(Opcode::Arithmetic(GeneralOptimizer::optimize(arith_expr)));
}
other_opcode => opcodes.push(other_opcode),
};
Expand Down Expand Up @@ -168,7 +168,7 @@ pub fn compile(
match func {
acir::circuit::opcodes::BlackBoxFuncCall::AND { output, .. }
| acir::circuit::opcodes::BlackBoxFuncCall::XOR { output, .. } => {
transformer.mark_solvable(*output)
transformer.mark_solvable(*output);
}
acir::circuit::opcodes::BlackBoxFuncCall::RANGE { .. } => (),
acir::circuit::opcodes::BlackBoxFuncCall::SHA256 { outputs, .. }
Expand All @@ -192,7 +192,7 @@ pub fn compile(
}
| acir::circuit::opcodes::BlackBoxFuncCall::Pedersen { outputs, .. } => {
transformer.mark_solvable(outputs.0);
transformer.mark_solvable(outputs.1)
transformer.mark_solvable(outputs.1);
}
acir::circuit::opcodes::BlackBoxFuncCall::HashToField128Security {
output,
Expand All @@ -201,7 +201,7 @@ pub fn compile(
| acir::circuit::opcodes::BlackBoxFuncCall::EcdsaSecp256k1 { output, .. }
| acir::circuit::opcodes::BlackBoxFuncCall::EcdsaSecp256r1 { output, .. }
| acir::circuit::opcodes::BlackBoxFuncCall::SchnorrVerify { output, .. } => {
transformer.mark_solvable(*output)
transformer.mark_solvable(*output);
}
}

Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm/src/compiler/optimizers/redundant_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,6 @@ mod tests {
let acir_opcode_positions = circuit.opcodes.iter().enumerate().map(|(i, _)| i).collect();
let optimizer = RangeOptimizer::new(circuit);
let (optimized_circuit, _) = optimizer.replace_redundant_ranges(acir_opcode_positions);
assert_eq!(optimized_circuit.opcodes.len(), 5)
assert_eq!(optimized_circuit.opcodes.len(), 5);
}
}
4 changes: 3 additions & 1 deletion acvm-repo/acvm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![warn(unused_crate_dependencies)]
#![forbid(unsafe_code)]
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]

pub mod compiler;
pub mod pwg;
Expand Down
4 changes: 2 additions & 2 deletions acvm-repo/acvm/src/pwg/brillig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ impl BrilligSolver {
for output in &brillig.outputs {
match output {
BrilligOutputs::Simple(witness) => {
insert_value(witness, FieldElement::zero(), initial_witness)?
insert_value(witness, FieldElement::zero(), initial_witness)?;
}
BrilligOutputs::Array(witness_arr) => {
for witness in witness_arr {
insert_value(witness, FieldElement::zero(), initial_witness)?
insert_value(witness, FieldElement::zero(), initial_witness)?;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm/src/pwg/directives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub(super) fn solve_directives(
None => FieldElement::zero(),
};

insert_value(witness, value, initial_witness)?
insert_value(witness, value, initial_witness)?;
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm/src/pwg/directives/sorting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ mod tests {
result.push(*out1.last().unwrap());
result.push(*out2.last().unwrap());
} else {
result.push(*out2.last().unwrap())
result.push(*out2.last().unwrap());
}
result
}
Expand Down
4 changes: 3 additions & 1 deletion acvm-repo/acvm_js/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// #![warn(unused_crate_dependencies, unused_extern_crates)]
#![forbid(unsafe_code)]
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]

// TODO: Absence of per package targets
// https://doc.rust-lang.org/cargo/reference/unstable.html#per-package-target
Expand Down
4 changes: 4 additions & 0 deletions acvm-repo/barretenberg_blackbox_solver/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]

use acir::{BlackBoxFunc, FieldElement};
use acvm_blackbox_solver::{BlackBoxFunctionSolver, BlackBoxResolutionError};

Expand Down
4 changes: 2 additions & 2 deletions acvm-repo/barretenberg_blackbox_solver/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl Barretenberg {
let store = self.store.borrow();
let memory_view = memory.view(&store);

memory_view.write(offset as u64, data).unwrap()
memory_view.write(offset as u64, data).unwrap();
}

// TODO: Consider making this Result-returning
Expand Down Expand Up @@ -231,7 +231,7 @@ impl Barretenberg {

let mut args: Vec<Value> = vec![];
for param in params.into_iter().cloned() {
args.push(param.try_into()?)
args.push(param.try_into()?);
}
let func = self
.instance
Expand Down
16 changes: 9 additions & 7 deletions acvm-repo/blackbox_solver/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![warn(unused_crate_dependencies)]
#![forbid(unsafe_code)]
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]

//! This crate provides the implementation of BlackBox functions of ACIR and Brillig.
//! For functions that are backend-dependent, it provides a Trait [BlackBoxFunctionSolver] that must be implemented by the backend.
Expand Down Expand Up @@ -269,7 +271,7 @@ mod secp256k1_tests {
let valid =
verify_secp256k1_ecdsa_signature(&HASHED_MESSAGE, &PUB_KEY_X, &PUB_KEY_Y, &SIGNATURE);

assert!(valid)
assert!(valid);
}

#[test]
Expand Down Expand Up @@ -298,7 +300,7 @@ mod secp256k1_tests {
&SIGNATURE,
);

assert!(!valid)
assert!(!valid);
}

#[test]
Expand All @@ -314,7 +316,7 @@ mod secp256k1_tests {
&SIGNATURE,
);

assert!(valid)
assert!(valid);
}
}

Expand Down Expand Up @@ -350,7 +352,7 @@ mod secp256r1_tests {
let valid =
verify_secp256r1_ecdsa_signature(&HASHED_MESSAGE, &PUB_KEY_X, &PUB_KEY_Y, &SIGNATURE);

assert!(valid)
assert!(valid);
}

#[test]
Expand Down Expand Up @@ -379,7 +381,7 @@ mod secp256r1_tests {
&SIGNATURE,
);

assert!(!valid)
assert!(!valid);
}

#[test]
Expand All @@ -395,6 +397,6 @@ mod secp256r1_tests {
&SIGNATURE,
);

assert!(valid)
assert!(valid);
}
}
4 changes: 3 additions & 1 deletion acvm-repo/brillig/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![warn(unused_crate_dependencies)]
#![forbid(unsafe_code)]
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]

//! The Brillig bytecode is distinct from regular [ACIR][acir] in that it does not generate constraints.
//! This is a generalization over the fixed directives that exists within in the ACVM.
Expand Down
12 changes: 7 additions & 5 deletions acvm-repo/brillig_vm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![warn(unused_crate_dependencies)]
#![forbid(unsafe_code)]
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]

//! The Brillig VM is a specialized VM which allows the [ACVM][acvm] to perform custom non-determinism.
//!
Expand Down Expand Up @@ -209,7 +211,7 @@ impl<'bb_solver, B: BlackBoxFunctionSolver> VM<'bb_solver, B> {
match destination {
RegisterOrMemory::RegisterIndex(value_index) => match output {
ForeignCallOutput::Single(value) => {
self.registers.set(*value_index, *value)
self.registers.set(*value_index, *value);
}
_ => unreachable!(
"Function result size does not match brillig bytecode (expected 1 result)"
Expand Down Expand Up @@ -363,7 +365,7 @@ impl<'bb_solver, B: BlackBoxFunctionSolver> VM<'bb_solver, B> {
let result_value =
evaluate_binary_field_op(&op, lhs_value.to_field(), rhs_value.to_field());

self.registers.set(result, result_value.into())
self.registers.set(result, result_value.into());
}

/// Process a binary operation.
Expand Down Expand Up @@ -453,7 +455,7 @@ mod tests {
let VM { registers, .. } = vm;
let output_value = registers.get(RegisterIndex::from(2));

assert_eq!(output_value, Value::from(3u128))
assert_eq!(output_value, Value::from(3u128));
}

#[test]
Expand Down Expand Up @@ -893,7 +895,7 @@ mod tests {
if matches!(status, VMStatus::Finished | VMStatus::ForeignCallWait { .. }) {
break;
}
assert_eq!(status, VMStatus::InProgress)
assert_eq!(status, VMStatus::InProgress);
}
}

Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/stdlib/src/blackbox_fallbacks/blake2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn blake2s_compress(
UInt32::from_witnesses(&mi_bytes, num_witness);
new_opcodes.extend(extra_opcodes);
m.push(mi[0]);
num_witness = updated_witness_counter
num_witness = updated_witness_counter;
}

for i in 0..8 {
Expand Down
Loading