Skip to content

Commit f73386e

Browse files
authored
chore: code clippy (#83)
* chore: remove dead code * chore: add clippty * fix: clippy * fix: clippy
1 parent fa3eb0b commit f73386e

40 files changed

+278
-781
lines changed

.github/workflows/ci.yml

+13
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,16 @@ jobs:
4343
with:
4444
command: fmt
4545
args: --all -- --check
46+
clippy:
47+
name: Clippy
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v2
51+
- uses: actions-rs/toolchain@v1
52+
with:
53+
profile: minimal
54+
toolchain: nightly
55+
override: true
56+
- run: rustup component add clippy
57+
- run: cargo clippy --all-targets -- -D warnings
58+

Cargo.toml

+4-6
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,20 @@ edition = "2021"
77

88

99
[dependencies]
10-
#plonky2 = { git = "https://github.com/0xPolygonZero/plonky2", branch = "main" }
1110
plonky2 = { git = "https://github.com/zkMIPS/plonky2.git", branch = "zkm_dev" }
12-
plonky2x = { git = "https://github.com/zkMIPS/succinctx.git", package = "plonky2x", branch = "zkm" }
1311
starky = { git = "https://github.com/zkMIPS/plonky2.git", branch = "zkm_dev" }
1412
plonky2_util = { git = "https://github.com/zkMIPS/plonky2.git", branch = "zkm_dev" }
1513
plonky2_maybe_rayon = { git = "https://github.com/zkMIPS/plonky2.git", branch = "zkm_dev" }
16-
curta = { git ="https://github.com/zkMIPS/curta.git", branch = "zkm" }
1714
tokio = { version = "1", features = ["full"] }
1815
backtrace = "0.3"
1916
array-macro = "2.1.5"
2017
#curve25519-dalek = "4.1.1"
2118
sha2 = "0.10.7"
22-
plonky2x-derive = { git = "https://github.com/zkMIPS/succinctx.git", package = "plonky2x-derive", branch = "zkm" }
2319
reqwest = { version = "0.11.4", features = ["blocking", "json"] }
2420
uuid = { version = "1.4.1", features = ["serde"] }
2521
async-trait = "0.1.73"
2622
futures = "0.3.28"
2723
serde_with = "3.3.0"
28-
env_logger = "0.10.0"
2924
bincode = "1.3.3"
3025

3126
itertools = "0.11.0"
@@ -57,5 +52,8 @@ dotenv = "0.15.0"
5752
prettytable-rs = "^0.8"
5853

5954
[dev-dependencies]
60-
#env_logger = { version = "0.9.0", default-features = false }
55+
env_logger = "0.10.0"
6156
keccak-hash = "0.10.0"
57+
plonky2x = { git = "https://github.com/zkMIPS/succinctx.git", package = "plonky2x", branch = "zkm" }
58+
plonky2x-derive = { git = "https://github.com/zkMIPS/succinctx.git", package = "plonky2x-derive", branch = "zkm" }
59+
curta = { git ="https://github.com/zkMIPS/curta.git", branch = "zkm" }

Makefile

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
CARGO = cargo
2+
3+
UNAME_S := $(shell uname -s)
4+
ifeq ($(UNAME_S),Darwin)
5+
CARGO += --config 'build.rustdocflags = ["-C", "link-args=-framework CoreFoundation -framework Security"]'
6+
endif
7+
8+
help: ## Display this help screen
9+
@grep -h \
10+
-E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
11+
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
12+
13+
clippy: ## Run clippy checks over all workspace members and formatted correctly
14+
@cargo check
15+
@cargo fmt --all -- --check
16+
@cargo clippy --all-targets -- -D warnings
17+
18+
fix: ## Automatically apply lint suggestions. This flag implies `--no-deps` and `--all-targets`
19+
@cargo clippy --fix
20+
21+
test: ## Run tests for all the workspace members
22+
@cargo test --release --all
23+
24+
.PHONY: clippy fmt test

clippy.toml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
large-error-threshold = 1000

examples/zkmips.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,10 @@ fn prove_single_seg() {
8282
let allproof: proof::AllProof<GoldilocksField, C, D> =
8383
prove(&allstark, &kernel, &config, &mut timing).unwrap();
8484
let mut count_bytes = 0;
85-
let mut row = 0;
86-
for proof in allproof.stark_proofs.clone() {
85+
for (row, proof) in allproof.stark_proofs.clone().iter().enumerate() {
8786
let proof_str = serde_json::to_string(&proof.proof).unwrap();
8887
log::info!("row:{} proof bytes:{}", row, proof_str.len());
89-
row = row + 1;
90-
count_bytes = count_bytes + proof_str.len();
88+
count_bytes += proof_str.len();
9189
}
9290
log::info!("total proof bytes:{}KB", count_bytes / 1024);
9391
verify_proof(&allstark, allproof, &config).unwrap();
@@ -139,7 +137,7 @@ fn aggregate_proof() -> anyhow::Result<()> {
139137
// Preprocess all circuits.
140138
let all_circuits = AllRecursiveCircuits::<F, C, D>::new(
141139
&all_stark,
142-
&[10..20, 15..22, 14..20, 9..20, 12..20, 15..23],
140+
&[10..21, 15..22, 14..21, 9..21, 12..21, 15..23],
143141
&config,
144142
);
145143

src/all_stark.rs

-8
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,6 @@ pub(crate) fn ctl_logic<F: Field>() -> CrossTableLookup<F> {
168168
}
169169

170170
fn ctl_memory<F: Field>() -> CrossTableLookup<F> {
171-
/*
172-
let cpu_memory_code_read = TableWithColumns::new(
173-
Table::Cpu,
174-
cpu_stark::ctl_data_code_memory::<F>(),
175-
Some(cpu_stark::ctl_filter_code_memory()),
176-
);
177-
*/
178171
let cpu_memory_gp_ops = (0..NUM_GP_CHANNELS).map(|channel| {
179172
TableWithColumns::new(
180173
Table::Cpu,
@@ -197,7 +190,6 @@ fn ctl_memory<F: Field>() -> CrossTableLookup<F> {
197190
Some(keccak_sponge_stark::ctl_looking_memory_filter(i)),
198191
)
199192
});
200-
//let all_lookers = iter::once(cpu_memory_code_read)
201193
let all_lookers = []
202194
.into_iter()
203195
.chain(cpu_memory_gp_ops)

src/arithmetic/addcy.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,11 @@ pub fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
254254
#[cfg(test)]
255255
mod tests {
256256
use plonky2::field::goldilocks_field::GoldilocksField;
257-
use plonky2::field::types::{Field, Sample};
257+
use plonky2::field::types::Sample;
258258
use rand::{Rng, SeedableRng};
259259
use rand_chacha::ChaCha8Rng;
260260

261261
use super::*;
262-
use crate::arithmetic::columns::NUM_ARITH_COLUMNS;
263-
use crate::constraint_consumer::ConstraintConsumer;
264262

265263
// TODO: Should be able to refactor this test to apply to all operations.
266264
#[test]

src/arithmetic/arithmetic_stark.rs

+19-20
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,32 @@ pub fn ctl_arithmetic_rows<F: Field>() -> TableWithColumns<F> {
6666
// from the opcode bits matches.
6767
// FIXME: opcode = op + 2^6 * func
6868
const COMBINED_OPS: [(usize, u32); 18] = [
69-
(columns::IS_ADD, 0b000000 + 0b100000 * (1 << 6)),
70-
(columns::IS_ADDU, 0b000000 + 0b100001 * (1 << 6)),
69+
(columns::IS_ADD, 0b100000 * (1 << 6)),
70+
(columns::IS_ADDU, 0b100001 * (1 << 6)),
7171
//(columns::IS_ADDI, 0b001000 + 0b000000 * (1 << 6)),
7272
//(columns::IS_ADDIU, 0b001001 + 0b000000 * (1 << 6)),
73-
(columns::IS_SUB, 0b000000 + 0b100010 * (1 << 6)),
74-
(columns::IS_SUBU, 0b000000 + 0b100011 * (1 << 6)),
75-
(columns::IS_MULT, 0b000000 + 0b011000 * (1 << 6)),
76-
(columns::IS_MULTU, 0b000000 + 0b011001 * (1 << 6)),
73+
(columns::IS_SUB, 0b100010 * (1 << 6)),
74+
(columns::IS_SUBU, 0b100011 * (1 << 6)),
75+
(columns::IS_MULT, 0b011000 * (1 << 6)),
76+
(columns::IS_MULTU, 0b011001 * (1 << 6)),
7777
(columns::IS_MUL, 0b011100 + 0b000010 * (1 << 6)),
78-
(columns::IS_DIV, 0b000000 + 0b011010 * (1 << 6)),
79-
(columns::IS_DIVU, 0b000000 + 0b011011 * (1 << 6)),
80-
(columns::IS_SLLV, 0b000000 + 0b000100 * (1 << 6)),
81-
(columns::IS_SRLV, 0b000000 + 0b000110 * (1 << 6)),
82-
(columns::IS_SRAV, 0b000000 + 0b000111 * (1 << 6)),
78+
(columns::IS_DIV, 0b011010 * (1 << 6)),
79+
(columns::IS_DIVU, 0b011011 * (1 << 6)),
80+
(columns::IS_SLLV, 0b000100 * (1 << 6)),
81+
(columns::IS_SRLV, 0b000110 * (1 << 6)),
82+
(columns::IS_SRAV, 0b000111 * (1 << 6)),
8383
//(columns::IS_SLL, 0b000000 + 0b000000 * (1 << 6)),
8484
//(columns::IS_SRL, 0b000000 + 0b000010 * (1 << 6)),
8585
//(columns::IS_SRA, 0b000000 + 0b000011 * (1 << 6)),
86-
(columns::IS_SLT, 0b000000 + 0b101010 * (1 << 6)),
87-
(columns::IS_SLTU, 0b000000 + 0b101011 * (1 << 6)),
86+
(columns::IS_SLT, 0b101010 * (1 << 6)),
87+
(columns::IS_SLTU, 0b101011 * (1 << 6)),
8888
// (columns::IS_SLTI, 0b001010 + 0b000000 * (1 << 6)),
8989
// (columns::IS_SLTIU, 0b001011 + 0b000000 * (1 << 6)),
9090
// (columns::IS_LUI, 0b001111 + 0b000000 * (1 << 6)),
91-
(columns::IS_MFHI, 0b000000 + 0b010000 * (1 << 6)),
92-
(columns::IS_MTHI, 0b000000 + 0b010001 * (1 << 6)),
93-
(columns::IS_MFLO, 0b000000 + 0b010010 * (1 << 6)),
94-
(columns::IS_MTLO, 0b000000 + 0b010011 * (1 << 6)),
91+
(columns::IS_MFHI, 0b010000 * (1 << 6)),
92+
(columns::IS_MTHI, 0b010001 * (1 << 6)),
93+
(columns::IS_MFLO, 0b010010 * (1 << 6)),
94+
(columns::IS_MTLO, 0b010011 * (1 << 6)),
9595
];
9696

9797
const REGISTER_MAP: [Range<usize>; 3] = [
@@ -123,7 +123,7 @@ const RANGE_MAX: usize = 1usize << 16; // Range check strict upper bound
123123

124124
impl<F: RichField, const D: usize> ArithmeticStark<F, D> {
125125
/// Expects input in *column*-major layout
126-
fn generate_range_checks(&self, cols: &mut Vec<Vec<F>>) {
126+
fn generate_range_checks(&self, cols: &mut [Vec<F>]) {
127127
debug_assert!(cols.len() == columns::NUM_ARITH_COLUMNS);
128128

129129
let n_rows = cols[0].len();
@@ -286,12 +286,11 @@ impl<F: RichField + Extendable<D>, const D: usize> Stark<F, D> for ArithmeticSta
286286
mod tests {
287287
use anyhow::Result;
288288
use itertools::Itertools;
289-
use plonky2::field::types::PrimeField64;
290289
use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
291290
use rand::{Rng, SeedableRng};
292291
use rand_chacha::ChaCha8Rng;
293292

294-
use super::{columns, ArithmeticStark};
293+
use crate::arithmetic::arithmetic_stark::ArithmeticStark;
295294
use crate::arithmetic::columns::OUTPUT_REGISTER;
296295
use crate::arithmetic::*;
297296
use crate::stark_testing::{test_stark_circuit_constraints, test_stark_low_degree};

src/arithmetic/div.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub(crate) fn generate_div<F: PrimeField64>(
8282

8383
debug_assert_eq!(abs_idx.len(), N_LIMBS);
8484

85-
u32_to_array(&mut lv[abs_idx], (input as i32).abs() as u32);
85+
u32_to_array(&mut lv[abs_idx], (input as i32).unsigned_abs());
8686

8787
is_neg
8888
};
@@ -938,13 +938,11 @@ pub(crate) fn eval_div_ext_circuit<F: RichField + Extendable<D>, const D: usize>
938938
#[cfg(test)]
939939
mod tests {
940940
use plonky2::field::goldilocks_field::GoldilocksField;
941-
use plonky2::field::types::{Field, Sample};
941+
use plonky2::field::types::Sample;
942942
use rand::{Rng, SeedableRng};
943943
use rand_chacha::ChaCha8Rng;
944944

945945
use super::*;
946-
use crate::arithmetic::columns::NUM_ARITH_COLUMNS;
947-
use crate::constraint_consumer::ConstraintConsumer;
948946

949947
const N_RND_TESTS: usize = 1000;
950948
const MODULAR_OPS: [usize; 2] = [IS_DIV, IS_DIVU];

src/arithmetic/lo_hi.rs

-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ mod tests {
5959
use rand_chacha::ChaCha8Rng;
6060

6161
use super::*;
62-
use crate::arithmetic::columns::NUM_ARITH_COLUMNS;
63-
use crate::constraint_consumer::ConstraintConsumer;
6462

6563
const OPS: [usize; 4] = [IS_MFHI, IS_MTHI, IS_MFLO, IS_MTLO];
6664
#[test]

src/arithmetic/mul.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,11 @@ pub fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
246246
#[cfg(test)]
247247
mod tests {
248248
use plonky2::field::goldilocks_field::GoldilocksField;
249-
use plonky2::field::types::{Field, Sample};
249+
use plonky2::field::types::Sample;
250250
use rand::{Rng, SeedableRng};
251251
use rand_chacha::ChaCha8Rng;
252252

253253
use super::*;
254-
use crate::arithmetic::columns::NUM_ARITH_COLUMNS;
255-
use crate::constraint_consumer::ConstraintConsumer;
256254

257255
const N_RND_TESTS: usize = 1000;
258256

src/arithmetic/mult.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,11 @@ pub fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
499499
#[cfg(test)]
500500
mod tests {
501501
use plonky2::field::goldilocks_field::GoldilocksField;
502-
use plonky2::field::types::{Field, Sample};
502+
use plonky2::field::types::Sample;
503503
use rand::{Rng, SeedableRng};
504504
use rand_chacha::ChaCha8Rng;
505505

506506
use super::*;
507-
use crate::arithmetic::columns::NUM_ARITH_COLUMNS;
508-
use crate::constraint_consumer::ConstraintConsumer;
509507

510508
const N_RND_TESTS: usize = 100000;
511509
const OPS: [usize; 2] = [IS_MULT, IS_MULTU];

src/arithmetic/shift.rs

-2
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,6 @@ pub fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
188188
#[cfg(test)]
189189
mod tests {
190190
use super::*;
191-
use crate::arithmetic::columns::{IS_SLL, IS_SLLV, IS_SRL, IS_SRLV, NUM_ARITH_COLUMNS};
192-
use crate::constraint_consumer::ConstraintConsumer;
193191
use plonky2::field::goldilocks_field::GoldilocksField;
194192
use plonky2::field::types::{Field, Sample};
195193
use rand::{Rng, SeedableRng};

src/arithmetic/slt.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
use crate::arithmetic::columns::*;
2-
use crate::arithmetic::columns::{
3-
INPUT_REGISTER_0, INPUT_REGISTER_1, IS_SLT, LIMB_BITS, NUM_ARITH_COLUMNS, OUTPUT_REGISTER,
4-
};
52
use crate::arithmetic::utils::u32_to_array;
63
use crate::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer};
74

src/arithmetic/sra.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub fn eval_packed_generic<P: PackedField>(
154154
let output = &lv[OUTPUT_REGISTER];
155155
for (x, (y, z)) in logic_shifted_input
156156
.iter()
157-
.zip((vec![acc_lo, acc_hi].iter()).zip(output.iter()))
157+
.zip(([acc_lo, acc_hi].iter()).zip(output.iter()))
158158
{
159159
yield_constr.constraint_transition(filter * (*x + *y * is_neg - *z));
160160
}
@@ -259,7 +259,7 @@ pub fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
259259
let output = &lv[OUTPUT_REGISTER];
260260
for (x, (y, z)) in logic_shifted_input
261261
.iter()
262-
.zip((vec![acc_lo, acc_hi].iter()).zip(output.iter()))
262+
.zip(([acc_lo, acc_hi].iter()).zip(output.iter()))
263263
{
264264
let t0 = builder.sub_extension(*x, *z);
265265
let t1 = builder.mul_add_extension(*y, is_neg, t0);
@@ -288,7 +288,7 @@ fn eval_poly<F: Field>(poly: PolynomialCoeffs<F>, x: F) -> Vec<F> {
288288
let mut results = vec![];
289289
let mut acc = F::ZERO;
290290
for chunks in poly.coeffs.chunks(2).rev() {
291-
let inter_coeff = chunks.iter().chain([acc].iter()).map(|x| *x).collect_vec();
291+
let inter_coeff = chunks.iter().chain([acc].iter()).copied().collect_vec();
292292
let inter_poly = PolynomialCoeffs::new(inter_coeff);
293293
acc = inter_poly.eval(x);
294294
results.push(acc);

src/cpu/bootstrap_kernel.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ pub(crate) fn generate_bootstrap_kernel<F: Field>(state: &mut GenerationState<F>
5151
state.traces.push_cpu(cpu_row);
5252
}
5353

54-
for (_i, addr) in page_addr.iter().enumerate() {
55-
check_memory_page_hash(state, kernel, *addr);
54+
for addr in page_addr {
55+
check_memory_page_hash(state, kernel, addr);
5656
}
5757

5858
check_image_id(state, kernel);
@@ -244,7 +244,7 @@ pub(crate) fn eval_bootstrap_kernel_packed<F: Field, P: PackedField<Scalar = F>>
244244
// If this is a bootloading row and the i'th memory channel is used, it must have the right
245245
// address, name context = 0, segment = Code, virt + 4 = next_virt
246246
let code_segment = F::from_canonical_usize(Segment::Code as usize);
247-
for (_i, channel) in local_values.mem_channels.iter().enumerate() {
247+
for channel in local_values.mem_channels.iter() {
248248
let filter = local_is_bootstrap * channel.used;
249249
yield_constr.constraint(filter * channel.addr_context);
250250
yield_constr.constraint(filter * (channel.addr_segment - code_segment));
@@ -298,7 +298,7 @@ pub(crate) fn eval_bootstrap_kernel_ext_circuit<F: RichField + Extendable<D>, co
298298
// address, name context = 0, segment = Code, virt + 4 = next_virt
299299
let code_segment =
300300
builder.constant_extension(F::Extension::from_canonical_usize(Segment::Code as usize));
301-
for (_i, channel) in local_values.mem_channels.iter().enumerate() {
301+
for channel in local_values.mem_channels {
302302
let filter = builder.mul_extension(local_is_bootstrap, channel.used);
303303
let constraint = builder.mul_extension(filter, channel.addr_context);
304304
yield_constr.constraint(builder, constraint);

0 commit comments

Comments
 (0)