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

fix: lints to guest programs #1131

Merged
merged 12 commits into from
Dec 27, 2024
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
23 changes: 23 additions & 0 deletions .github/workflows/lints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,26 @@ jobs:
# echo -e "\033[1;32mAll unique features across workspace:\033[0m" && cargo metadata --format-version=1 --no-deps | jq -r '.packages[].features | to_entries[] | .key' | sort -u | sed 's/^/• /'
cargo clippy --all-targets --all --tests --features "aggregation bench-metrics bls12_381 bn254 default entrypoint export-getrandom export-libm function-span getrandom halo2-compiler halo2curves heap-embedded-alloc k256 mimalloc nightly-features panic-handler parallel rust-runtime static-verifier std test-utils unstable" -- -D warnings
cargo clippy --all-targets --all --tests --no-default-features --features "jemalloc jemalloc-prof" -- -D warnings

- name: Run fmt, clippy for guest
run: |
# 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
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
elif [[ "$crate_path" == *"extensions/pairing/tests/programs"* ]]; then
echo "Running cargo clippy with openvm_pairing_guest::bn254 feature for $crate_path"
cargo clippy --manifest-path "$crate_path/Cargo.toml" --all-targets --features "std bn254" -- -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
3 changes: 2 additions & 1 deletion benchmarks/programs/base64_json/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#![cfg_attr(not(feature = "std"), no_std)]

use serde::Deserialize;
use core::fmt::Debug;

use serde::Deserialize;

#[derive(Deserialize, Debug)]
#[allow(unused)]
pub struct UserProfile<'a> {
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/programs/base64_json/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

use core::result::Result;

use openvm_json_program::UserProfile;
use base64::engine::{general_purpose, Engine};
use openvm_json_program::UserProfile;
use serde_json_core::de::from_str;

openvm::entry!(main);
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/programs/bincode/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ fn main() {

let data = openvm::io::read_vec();

let deser: (Players, usize) = decode_from_slice(&data, config).expect("Failed to deserialize");
let _deser: (Players, usize) = decode_from_slice(&data, config).expect("Failed to deserialize");
}
9 changes: 4 additions & 5 deletions examples/algebra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ openvm-platform = { git = "https://github.com/openvm-org/openvm.git" }
openvm-algebra-guest = { git = "https://github.com/openvm-org/openvm.git" }
openvm-algebra-complex-macros = { git = "https://github.com/openvm-org/openvm.git" }
serde = { version = "1.0.216", default-features = false }
num-bigint-dig = { version = "0.8.4", default-features = false, features = [
"serde",
] }

[features]
default = []
std = [
"serde/std",
"openvm/std",
"openvm-algebra-guest/std",
]
std = ["serde/std", "openvm/std", "openvm-algebra-guest/std"]
6 changes: 3 additions & 3 deletions examples/algebra/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg_attr(not(feature = "std"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

use openvm_algebra_guest::{IntMod, moduli_setup::*};
use openvm_algebra_guest::{moduli_setup::*, DivUnsafe, IntMod};

openvm::entry!(main);

Expand Down Expand Up @@ -41,5 +41,5 @@ pub fn main() {
let b = Complex2::new(Mod2::ZERO, Mod2::from_u32(1000000006)); // b = -i in the corresponding field
assert_eq!(a.clone() * &a * &a * &a * &a, a); // a^5 = a
assert_eq!(b.clone() * &b * &b * &b * &b, b); // b^5 = b
// Note that these assertions would fail, have we provided the `mod_idx` parameters wrongly.
}
// Note that these assertions would fail, have we provided the `mod_idx` parameters wrongly.
}
4 changes: 3 additions & 1 deletion examples/i256/src/main.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);
}
}
14 changes: 10 additions & 4 deletions examples/keccak/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ 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);

pub fn main() {
let test_vectors = [
("", "C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470"),
("CC", "EEAD6DBFC7340A56CAEDC044696A168870549A6A7F6F56961E84A54BD9970B8A"),
(
"",
"C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470",
),
(
"CC",
"EEAD6DBFC7340A56CAEDC044696A168870549A6A7F6F56961E84A54BD9970B8A",
),
];
for (input, expected_output) in test_vectors.iter() {
let input = Vec::from_hex(input).unwrap();
Expand All @@ -24,4 +30,4 @@ pub fn main() {
panic!();
}
}
}
}
4 changes: 3 additions & 1 deletion examples/u256/src/main.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);
}
}
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
1 change: 1 addition & 0 deletions extensions/ecc/tests/programs/examples/ecdsa.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(unused_imports)]

use core::hint::black_box;

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: 1 addition & 0 deletions extensions/pairing/tests/programs/examples/fp12_mul.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![feature(cfg_match)]
#![cfg_attr(not(feature = "std"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(unused_imports)]

use openvm::io::read_vec;
use openvm_algebra_guest::{field::FieldExtension, IntMod};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![feature(cfg_match)]
#![cfg_attr(not(feature = "std"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(unused_imports)]

extern crate alloc;

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