Skip to content

Commit

Permalink
add: extensions on linting
Browse files Browse the repository at this point in the history
  • Loading branch information
rkdud007 committed Dec 26, 2024
1 parent fa3e799 commit 775aedd
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 20 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/lints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions examples/i256/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions examples/u256/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion extensions/bigint/tests/programs/examples/book-example2.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -37,4 +39,4 @@ pub fn main() {
let b: Matrix = get_matrix(-28);
let c: Matrix = mult(&a, &b);
assert_eq!(c, b);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -100,6 +101,7 @@ pub fn main() {
}

// Or tests

if &one | &one != one {
print("FAIL: 1 | 1 == 1 test failed");
panic!();
Expand All @@ -116,7 +118,7 @@ pub fn main() {
panic!();
}

if &neg_one >= &zero {
if neg_one >= zero {
print("FAIL: -1 <= 0 test failed");
panic!();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion extensions/ecc/tests/programs/examples/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 1 addition & 3 deletions extensions/ecc/tests/programs/examples/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion extensions/keccak256/tests/programs/examples/keccak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion extensions/pairing/tests/programs/examples/fp12_mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 0 additions & 2 deletions extensions/pairing/tests/programs/examples/pairing_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions extensions/rv32im/tests/programs/examples/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct Foo {
baz: alloc::vec::Vec<u32>,
}

#[allow(clippy::disallowed_names)]
pub fn main() {
let foo: Foo = read();
if foo.baz.len() != 4 {
Expand Down

0 comments on commit 775aedd

Please sign in to comment.