Skip to content

Commit 62158a0

Browse files
feat(ci): fix make clippy script and clippy CI job (#220)
* feat(ci): Fix make clippy script and clippy CI job * fix: Install toolchain required for clippy * fix: Fix clippy lints * chore(clippy): fix lints and improve clippy script * chore(clippy): build risc0 guest to compile driver and host * chore(clippy): add env vars * chore(clippy): fix lints * chore(clippy): do not specify projects for risc0 command * chore(clippy): install tools before running clippy * chore(ci): remove unused file * refactor(clippy): use build script instead of separate clippy script * refactor(clippy): move install script to separate step in job
1 parent fd474e3 commit 62158a0

File tree

14 files changed

+167
-119
lines changed

14 files changed

+167
-119
lines changed

Diff for: .github/workflows/ci-build-test-reusable.yml

+47-47
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
11
name: CI Build and Test - Reusable
22

33
on:
4-
workflow_call:
5-
inputs:
6-
version_name:
7-
type: string
8-
required: true
9-
version_toolchain:
10-
type: string
11-
required: true
4+
workflow_call:
5+
inputs:
6+
version_name:
7+
type: string
8+
required: true
9+
version_toolchain:
10+
type: string
11+
required: true
1212

1313
env:
1414
CARGO_TERM_COLOR: always
1515
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1616

1717
jobs:
18-
build-test:
19-
name: Build and test
20-
runs-on: [taiko-runner]
21-
timeout-minutes: 120
22-
23-
env:
24-
TARGET: ${{ inputs.version_name}}
25-
CI: 1
26-
MOCK: 1
27-
28-
steps:
29-
- uses: actions/checkout@v4
30-
with:
31-
submodules: recursive
32-
33-
- uses: actions-rs/toolchain@v1
34-
with:
35-
toolchain: ${{ inputs.version_toolchain }}
36-
profile: minimal
37-
38-
- name: Install cargo-binstall
39-
uses: cargo-bins/[email protected]
40-
41-
- name: Setup sccache
42-
if: ${{ inputs.version_name }} == risc0
43-
uses: risc0/risc0/.github/actions/[email protected]
44-
45-
- name: Install ${{ inputs.version_name }}
46-
run: make install
47-
48-
- name: Build ${{ inputs.version_name }} prover
49-
run: make build
50-
51-
- name: Test ${{ inputs.version_name }} prover
52-
run: make test
53-
54-
- name: Build with tracer
55-
if: ${{ inputs.version_name }} == native
56-
run: cargo build -F tracer
18+
build-test:
19+
name: Build and test
20+
runs-on: [taiko-runner]
21+
timeout-minutes: 120
22+
23+
env:
24+
TARGET: ${{ inputs.version_name }}
25+
CI: 1
26+
MOCK: 1
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
with:
31+
submodules: recursive
32+
33+
- uses: actions-rs/toolchain@v1
34+
with:
35+
toolchain: ${{ inputs.version_toolchain }}
36+
profile: minimal
37+
38+
- name: Install cargo-binstall
39+
uses: cargo-bins/[email protected]
40+
41+
- name: Setup sccache
42+
if: ${{ inputs.version_name }} == risc0
43+
uses: risc0/risc0/.github/actions/[email protected]
44+
45+
- name: Install ${{ inputs.version_name }}
46+
run: make install
47+
48+
- name: Build ${{ inputs.version_name }} prover
49+
run: make build
50+
51+
- name: Test ${{ inputs.version_name }} prover
52+
run: make test
53+
54+
- name: Build with tracer
55+
if: ${{ inputs.version_name }} == native
56+
run: cargo build -F tracer

Diff for: .github/workflows/ci-lint.yml

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: CI - Lint
22

33
on:
4-
pull_request:
5-
types: [opened, reopened, edited, synchronize]
4+
pull_request:
5+
types: [opened, reopened, edited, synchronize]
66

77
env:
88
CARGO_TERM_COLOR: always
@@ -17,15 +17,11 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v4
1919

20-
- uses: risc0/risc0/.github/actions/[email protected]
20+
- name: Run install script for all targets
21+
run: make install
2122

22-
- uses: risc0/risc0/.github/actions/[email protected]
23-
24-
- uses: risc0/clippy-action@main
25-
with:
26-
reporter: 'github-pr-check'
27-
fail_on_error: true
28-
clippy_flags: --workspace --all-targets --all-features -- -D warnings
23+
- name: Run clippy check for all targets
24+
run: make clippy
2925

3026
fmt:
3127
name: fmt
@@ -35,6 +31,5 @@ jobs:
3531
steps:
3632
- uses: actions/checkout@v4
3733

38-
- uses: risc0/risc0/.github/actions/[email protected]
39-
40-
- run: make fmt
34+
- name: Run format script for all targets
35+
run: make fmt

Diff for: core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub fn merge(a: &mut Value, b: &Value) {
169169
merge(a.entry(k).or_insert(Value::Null), v);
170170
}
171171
}
172-
(a, b) if !b.is_null() => *a = b.to_owned(),
172+
(a, b) if !b.is_null() => b.clone_into(a),
173173
// If b is null, just keep a (which means do nothing).
174174
_ => {}
175175
}

Diff for: harness/core/src/assert.rs

+4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ impl AssertionLog {
6060
self.assertions.len()
6161
}
6262

63+
pub fn is_empty(&self) -> bool {
64+
self.len() == 0
65+
}
66+
6367
pub fn display_failures(&self, start: usize, end: usize) {
6468
for i in start..end {
6569
if let Some(assertion) = self.assertions.get(i) {

Diff for: harness/macro/src/lib.rs

+39-29
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,39 @@
11
extern crate proc_macro;
22
use proc_macro::TokenStream;
33
use quote::quote;
4-
use syn::{parse_macro_input, punctuated::Punctuated, Ident, Item, ItemFn, ItemMod, Path, Token};
4+
use syn::{parse_macro_input, Item, ItemFn, ItemMod};
5+
6+
#[cfg(any(feature = "sp1", feature = "risc0"))]
7+
use syn::{punctuated::Punctuated, Ident, Path, Token};
8+
9+
// Helper struct to parse input
10+
#[cfg(any(feature = "sp1", feature = "risc0"))]
11+
struct EntryArgs {
12+
main_entry: Ident,
13+
test_modules: Option<Punctuated<Path, Token![,]>>,
14+
}
15+
16+
#[cfg(any(feature = "sp1", feature = "risc0"))]
17+
impl syn::parse::Parse for EntryArgs {
18+
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
19+
let main_entry: Ident = input.parse()?;
20+
let test_modules: Option<Punctuated<Path, Token![,]>> = if input.peek(Token![,]) {
21+
input.parse::<Token![,]>()?; // Parse and consume the comma
22+
// Now parse a list of module paths if they are present
23+
Some(input.parse_terminated(Path::parse)?)
24+
} else {
25+
None
26+
};
27+
28+
Ok(EntryArgs {
29+
main_entry,
30+
test_modules,
31+
})
32+
}
33+
}
534

635
#[proc_macro]
36+
#[cfg(any(feature = "sp1", feature = "risc0"))]
737
pub fn entrypoint(input: TokenStream) -> TokenStream {
838
let input = parse_macro_input!(input as EntryArgs);
939
let main_entry = input.main_entry;
@@ -70,41 +100,21 @@ pub fn entrypoint(input: TokenStream) -> TokenStream {
70100
}
71101
};
72102

73-
#[cfg(all(not(feature = "sp1"), not(feature = "risc0")))]
74-
let output = quote! {
103+
output.into()
104+
}
105+
106+
#[proc_macro]
107+
#[cfg(not(any(feature = "sp1", feature = "risc0")))]
108+
pub fn entrypoint(_input: TokenStream) -> TokenStream {
109+
quote! {
75110
mod generated_main {
76111
#[no_mangle]
77112
fn main() {
78113
super::ENTRY()
79114
}
80115
}
81-
};
82-
83-
output.into()
84-
}
85-
86-
// Helper struct to parse input
87-
struct EntryArgs {
88-
main_entry: Ident,
89-
test_modules: Option<Punctuated<Path, Token![,]>>,
90-
}
91-
92-
impl syn::parse::Parse for EntryArgs {
93-
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
94-
let main_entry: Ident = input.parse()?;
95-
let test_modules: Option<Punctuated<Path, Token![,]>> = if input.peek(Token![,]) {
96-
input.parse::<Token![,]>()?; // Parse and consume the comma
97-
// Now parse a list of module paths if they are present
98-
Some(input.parse_terminated(Path::parse)?)
99-
} else {
100-
None
101-
};
102-
103-
Ok(EntryArgs {
104-
main_entry,
105-
test_modules,
106-
})
107116
}
117+
.into()
108118
}
109119

110120
#[proc_macro]

Diff for: lib/src/builder/finalize.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ impl BlockFinalizeStrategy<MemDb> for MemDbBlockFinalizeStrategy {
4242
fn finalize(mut block_builder: BlockBuilder<MemDb>) -> Result<(AlloyConsensusHeader, MptNode)> {
4343
let db: MemDb = block_builder.db.take().expect("DB not initialized");
4444

45-
let mut account_touched = 0;
46-
let mut storage_touched = 0;
45+
#[cfg(feature = "sp1-cycle-tracker")]
46+
{
47+
let mut account_touched = 0;
48+
let mut storage_touched = 0;
49+
}
4750

4851
// apply state updates
4952
let mut state_trie = mem::take(&mut block_builder.input.parent_state_trie);
@@ -62,7 +65,10 @@ impl BlockFinalizeStrategy<MemDb> for MemDbBlockFinalizeStrategy {
6265
continue;
6366
}
6467

65-
account_touched += 1;
68+
#[cfg(feature = "sp1-cycle-tracker")]
69+
{
70+
account_touched += 1;
71+
}
6672

6773
// otherwise, compute the updated storage root for that account
6874
let state_storage = &account.storage;
@@ -88,7 +94,10 @@ impl BlockFinalizeStrategy<MemDb> for MemDbBlockFinalizeStrategy {
8894
storage_trie.insert_rlp(&storage_trie_index, *value)?;
8995
}
9096

91-
storage_touched += 1;
97+
#[cfg(feature = "sp1-cycle-tracker")]
98+
{
99+
storage_touched += 1;
100+
}
92101
}
93102

94103
storage_trie.hash()

Diff for: lib/src/builder/initialize.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ impl DbInitStrategy<MemDb> for MemDbInitStrategy {
6262
.map(|bytes| (keccak(&bytes).into(), bytes))
6363
.collect();
6464

65-
let mut account_touched = 0;
66-
let mut storage_touched = 0;
65+
#[cfg(all(
66+
all(target_os = "zkvm", target_vendor = "succinct"),
67+
feature = "sp1-cycle-tracker"
68+
))]
69+
{
70+
let mut account_touched = 0;
71+
let mut storage_touched = 0;
72+
}
6773

6874
// Load account data into db
6975
let mut accounts = HashMap::with_capacity(block_builder.input.parent_storage.len());
@@ -85,7 +91,13 @@ impl DbInitStrategy<MemDb> for MemDbInitStrategy {
8591
storage_trie.hash()
8692
);
8793
}
88-
account_touched += 1;
94+
#[cfg(all(
95+
all(target_os = "zkvm", target_vendor = "succinct"),
96+
feature = "sp1-cycle-tracker"
97+
))]
98+
{
99+
account_touched += 1;
100+
}
89101

90102
// load the corresponding code
91103
let code_hash = state_account.code_hash;
@@ -106,7 +118,13 @@ impl DbInitStrategy<MemDb> for MemDbInitStrategy {
106118
.get_rlp(&keccak(slot.to_be_bytes::<32>()))?
107119
.unwrap_or_default();
108120
storage.insert(slot, value);
109-
storage_touched += 1;
121+
#[cfg(all(
122+
all(target_os = "zkvm", target_vendor = "succinct"),
123+
feature = "sp1-cycle-tracker"
124+
))]
125+
{
126+
storage_touched += 1;
127+
}
110128
}
111129

112130
let mem_account = DbAccount {
@@ -129,8 +147,8 @@ impl DbInitStrategy<MemDb> for MemDbInitStrategy {
129147
feature = "sp1-cycle-tracker"
130148
))]
131149
{
132-
println!("initialize_db Account touch {:?}", account_touched);
133-
println!("initialize_db Storage touch {:?}", storage_touched);
150+
println!("initialize_db Account touch {account_touched:?}");
151+
println!("initialize_db Storage touch {storage_touched:?}");
134152
}
135153

136154
// prepare block hash history

Diff for: lib/src/consts.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,14 @@ pub enum Network {
250250
TaikoMainnet,
251251
}
252252

253-
impl ToString for Network {
254-
fn to_string(&self) -> String {
255-
match self {
256-
Network::Ethereum => "ethereum".to_string(),
257-
Network::Holesky => "holesky".to_string(),
258-
Network::TaikoA7 => "taiko_a7".to_string(),
259-
Network::TaikoMainnet => "taiko_mainnet".to_string(),
260-
}
253+
impl std::fmt::Display for Network {
254+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
255+
f.write_str(match self {
256+
Network::Ethereum => "ethereum",
257+
Network::Holesky => "holesky",
258+
Network::TaikoA7 => "taiko_a7",
259+
Network::TaikoMainnet => "taiko_mainnet",
260+
})
261261
}
262262
}
263263

Diff for: lib/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ mod time {
8686
}
8787

8888
pub struct CycleTracker {
89+
#[allow(dead_code)]
8990
title: String,
9091
}
9192

Diff for: lib/src/protocol_instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl ProtocolInstance {
4545
let aligned_data_size = (data_size + 3) / 4 * 4;
4646
let layout = Layout::from_size_align(aligned_data_size, 4).unwrap();
4747
// Allocate aligned memory
48-
let raw_ptr = unsafe { alloc(layout) as *mut u8 };
48+
let raw_ptr = unsafe { alloc(layout) };
4949
if raw_ptr.is_null() {
5050
panic!("Failed to allocate memory with aligned pointer");
5151
}

Diff for: makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@ fmt:
1616
@cargo fmt --all --check
1717

1818
clippy:
19-
@cargo +nightly-2024-04-18 check --features "sgx,sp1,risc0"
20-
@cargo +nightly-2024-04-18 clippy --workspace --features "sgx,sp1,risc0" --all-targets -- -Dwarnings
19+
CLIPPY=1 ./script/build.sh $(TARGET)

0 commit comments

Comments
 (0)