From 775aedd3366f34286356ff1458439178e02feb2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=80a?= <76558220+rkdud007@users.noreply.github.com> Date: Thu, 26 Dec 2024 11:22:38 +0900 Subject: [PATCH] add: extensions on linting --- .github/workflows/lints.yml | 16 +++++++++++----- examples/i256/src/main.rs | 3 +-- examples/u256/src/main.rs | 3 +-- .../tests/programs/examples/book-example2.rs | 4 +++- .../programs/examples/matrix-power-signed.rs | 6 ++++-- .../programs/examples/matrix-power-unsigned.rs | 2 ++ extensions/ecc/tests/programs/examples/ec.rs | 2 +- extensions/ecc/tests/programs/examples/ecdsa.rs | 4 +--- .../keccak256/tests/programs/examples/keccak.rs | 2 +- .../pairing/tests/programs/examples/fp12_mul.rs | 1 - .../tests/programs/examples/pairing_check.rs | 2 -- .../rv32im/tests/programs/examples/read.rs | 1 + 12 files changed, 26 insertions(+), 20 deletions(-) diff --git a/.github/workflows/lints.yml b/.github/workflows/lints.yml index bb41ccc7e3..5fcc17b04d 100644 --- a/.github/workflows/lints.yml +++ b/.github/workflows/lints.yml @@ -40,14 +40,20 @@ jobs: - name: Run fmt, clippy for guest run: | - # List all guest program crate paths - for crate_path in benchmarks/programs/* examples/*; do + # Find all directories named "programs" and include additional static paths + for crate_path in $(find . -type d -name "programs" -exec find {} -mindepth 0 -maxdepth 0 -type d \;) benchmarks/programs/* examples/*; do # Check if Cargo.toml exists in the directory if [ -f "$crate_path/Cargo.toml" ]; then echo "Running cargo fmt, clippy for $crate_path" - cargo fmt --manifest-path "$crate_path/Cargo.toml" --all -- --check - cargo clippy --manifest-path "$crate_path/Cargo.toml" --all-targets --features std -- -D warnings + cargo fmt --manifest-path "$crate_path/Cargo.toml" --all -- --check + if [[ "$crate_path" == *"extensions/ecc/tests/programs"* ]]; then + echo "Running cargo clippy with k256 feature for $crate_path" + cargo clippy --manifest-path "$crate_path/Cargo.toml" --all-targets --features "std k256" -- -D warnings + else + echo "Running cargo clippy for $crate_path" + cargo clippy --manifest-path "$crate_path/Cargo.toml" --all-targets --features std -- -D warnings + fi else echo "Skipping $crate_path as it does not contain a Cargo.toml" fi - done + done \ No newline at end of file diff --git a/examples/i256/src/main.rs b/examples/i256/src/main.rs index ed46ecfd6d..96b46e67e9 100644 --- a/examples/i256/src/main.rs +++ b/examples/i256/src/main.rs @@ -1,5 +1,6 @@ #![cfg_attr(not(feature = "std"), no_main)] #![cfg_attr(not(feature = "std"), no_std)] +#![allow(clippy::needless_range_loop)] openvm::entry!(main); use core::array; @@ -13,7 +14,6 @@ pub fn get_matrix(val: i32) -> Matrix { array::from_fn(|_| array::from_fn(|_| I256::from_i32(val))) } -#[allow(clippy::needless_range_loop)] pub fn mult(a: &Matrix, b: &Matrix) -> Matrix { let mut c = get_matrix(0); for i in 0..N { @@ -26,7 +26,6 @@ pub fn mult(a: &Matrix, b: &Matrix) -> Matrix { c } -#[allow(clippy::needless_range_loop)] pub fn get_identity_matrix() -> Matrix { let mut res = get_matrix(0); for i in 0..N { diff --git a/examples/u256/src/main.rs b/examples/u256/src/main.rs index ed46ecfd6d..96b46e67e9 100644 --- a/examples/u256/src/main.rs +++ b/examples/u256/src/main.rs @@ -1,5 +1,6 @@ #![cfg_attr(not(feature = "std"), no_main)] #![cfg_attr(not(feature = "std"), no_std)] +#![allow(clippy::needless_range_loop)] openvm::entry!(main); use core::array; @@ -13,7 +14,6 @@ pub fn get_matrix(val: i32) -> Matrix { array::from_fn(|_| array::from_fn(|_| I256::from_i32(val))) } -#[allow(clippy::needless_range_loop)] pub fn mult(a: &Matrix, b: &Matrix) -> Matrix { let mut c = get_matrix(0); for i in 0..N { @@ -26,7 +26,6 @@ pub fn mult(a: &Matrix, b: &Matrix) -> Matrix { c } -#[allow(clippy::needless_range_loop)] pub fn get_identity_matrix() -> Matrix { let mut res = get_matrix(0); for i in 0..N { diff --git a/extensions/bigint/tests/programs/examples/book-example2.rs b/extensions/bigint/tests/programs/examples/book-example2.rs index 1331abbcc6..96b46e67e9 100644 --- a/extensions/bigint/tests/programs/examples/book-example2.rs +++ b/extensions/bigint/tests/programs/examples/book-example2.rs @@ -1,8 +1,10 @@ #![cfg_attr(not(feature = "std"), no_main)] #![cfg_attr(not(feature = "std"), no_std)] +#![allow(clippy::needless_range_loop)] openvm::entry!(main); use core::array; + use openvm_bigint_guest::I256; const N: usize = 16; @@ -37,4 +39,4 @@ pub fn main() { let b: Matrix = get_matrix(-28); let c: Matrix = mult(&a, &b); assert_eq!(c, b); -} \ No newline at end of file +} diff --git a/extensions/bigint/tests/programs/examples/matrix-power-signed.rs b/extensions/bigint/tests/programs/examples/matrix-power-signed.rs index c5bf42ae06..41fbd27655 100644 --- a/extensions/bigint/tests/programs/examples/matrix-power-signed.rs +++ b/extensions/bigint/tests/programs/examples/matrix-power-signed.rs @@ -1,6 +1,7 @@ #![cfg_attr(not(feature = "std"), no_main)] #![cfg_attr(not(feature = "std"), no_std)] - +#![allow(clippy::needless_range_loop)] +#![allow(clippy::eq_op)] use core::array; use openvm::io::print; @@ -100,6 +101,7 @@ pub fn main() { } // Or tests + if &one | &one != one { print("FAIL: 1 | 1 == 1 test failed"); panic!(); @@ -116,7 +118,7 @@ pub fn main() { panic!(); } - if &neg_one >= &zero { + if neg_one >= zero { print("FAIL: -1 <= 0 test failed"); panic!(); } diff --git a/extensions/bigint/tests/programs/examples/matrix-power-unsigned.rs b/extensions/bigint/tests/programs/examples/matrix-power-unsigned.rs index 78b897e056..c977725464 100644 --- a/extensions/bigint/tests/programs/examples/matrix-power-unsigned.rs +++ b/extensions/bigint/tests/programs/examples/matrix-power-unsigned.rs @@ -1,5 +1,7 @@ #![cfg_attr(not(feature = "std"), no_main)] #![cfg_attr(not(feature = "std"), no_std)] +#![allow(clippy::needless_range_loop)] +#![allow(clippy::eq_op)] openvm::entry!(main); use core::array; diff --git a/extensions/ecc/tests/programs/examples/ec.rs b/extensions/ecc/tests/programs/examples/ec.rs index d1ed93b09f..4b766af430 100644 --- a/extensions/ecc/tests/programs/examples/ec.rs +++ b/extensions/ecc/tests/programs/examples/ec.rs @@ -3,12 +3,12 @@ use core::hint::black_box; +use hex_literal::hex; use openvm_algebra_guest::IntMod; use openvm_ecc_guest::{ k256::{Secp256k1Coord, Secp256k1Point, Secp256k1Scalar}, msm, Group, }; -use hex_literal::hex; openvm::entry!(main); diff --git a/extensions/ecc/tests/programs/examples/ecdsa.rs b/extensions/ecc/tests/programs/examples/ecdsa.rs index 79378c4cc9..e2b407db43 100644 --- a/extensions/ecc/tests/programs/examples/ecdsa.rs +++ b/extensions/ecc/tests/programs/examples/ecdsa.rs @@ -8,9 +8,7 @@ use k256::{ ecdsa::{self, RecoveryId}, Secp256k1, }; -use openvm_ecc_guest::{ - algebra::IntMod, ecdsa::VerifyingKey, k256::Secp256k1Coord, weierstrass::WeierstrassPoint, -}; +use openvm_ecc_guest::{algebra::IntMod, ecdsa::VerifyingKey, weierstrass::WeierstrassPoint}; use openvm_keccak256_guest::keccak256; openvm::entry!(main); diff --git a/extensions/keccak256/tests/programs/examples/keccak.rs b/extensions/keccak256/tests/programs/examples/keccak.rs index 6e7f38893d..d850bfdab2 100644 --- a/extensions/keccak256/tests/programs/examples/keccak.rs +++ b/extensions/keccak256/tests/programs/examples/keccak.rs @@ -6,8 +6,8 @@ extern crate alloc; use alloc::vec::Vec; use core::hint::black_box; -use openvm_keccak256_guest::keccak256; use hex::FromHex; +use openvm_keccak256_guest::keccak256; openvm::entry!(main); diff --git a/extensions/pairing/tests/programs/examples/fp12_mul.rs b/extensions/pairing/tests/programs/examples/fp12_mul.rs index f7ef344801..887967af21 100644 --- a/extensions/pairing/tests/programs/examples/fp12_mul.rs +++ b/extensions/pairing/tests/programs/examples/fp12_mul.rs @@ -3,7 +3,6 @@ #![cfg_attr(not(feature = "std"), no_std)] use openvm::io::read_vec; -use openvm_algebra_guest::{field::FieldExtension, IntMod}; openvm::entry!(main); diff --git a/extensions/pairing/tests/programs/examples/pairing_check.rs b/extensions/pairing/tests/programs/examples/pairing_check.rs index b1fce22614..3135ef8d70 100644 --- a/extensions/pairing/tests/programs/examples/pairing_check.rs +++ b/extensions/pairing/tests/programs/examples/pairing_check.rs @@ -5,8 +5,6 @@ extern crate alloc; use openvm::io::read_vec; -use openvm_ecc_guest::AffinePoint; -use openvm_pairing_guest::pairing::PairingCheck; openvm::entry!(main); diff --git a/extensions/rv32im/tests/programs/examples/read.rs b/extensions/rv32im/tests/programs/examples/read.rs index 9568f664df..058cd02ce1 100644 --- a/extensions/rv32im/tests/programs/examples/read.rs +++ b/extensions/rv32im/tests/programs/examples/read.rs @@ -11,6 +11,7 @@ struct Foo { baz: alloc::vec::Vec, } +#[allow(clippy::disallowed_names)] pub fn main() { let foo: Foo = read(); if foo.baz.len() != 4 {