diff --git a/.github/workflows/ci-build-test-reusable.yml b/.github/workflows/ci-build-test-reusable.yml index 6f706bea6..09a91f670 100644 --- a/.github/workflows/ci-build-test-reusable.yml +++ b/.github/workflows/ci-build-test-reusable.yml @@ -1,56 +1,56 @@ name: CI Build and Test - Reusable on: - workflow_call: - inputs: - version_name: - type: string - required: true - version_toolchain: - type: string - required: true + workflow_call: + inputs: + version_name: + type: string + required: true + version_toolchain: + type: string + required: true env: CARGO_TERM_COLOR: always GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: - build-test: - name: Build and test - runs-on: [taiko-runner] - timeout-minutes: 120 - - env: - TARGET: ${{ inputs.version_name}} - CI: 1 - MOCK: 1 - - steps: - - uses: actions/checkout@v4 - with: - submodules: recursive - - - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ inputs.version_toolchain }} - profile: minimal - - - name: Install cargo-binstall - uses: cargo-bins/cargo-binstall@v1.6.4 - - - name: Setup sccache - if: ${{ inputs.version_name }} == risc0 - uses: risc0/risc0/.github/actions/sccache@release-0.19 - - - name: Install ${{ inputs.version_name }} - run: make install - - - name: Build ${{ inputs.version_name }} prover - run: make build - - - name: Test ${{ inputs.version_name }} prover - run: make test - - - name: Build with tracer - if: ${{ inputs.version_name }} == native - run: cargo build -F tracer + build-test: + name: Build and test + runs-on: [taiko-runner] + timeout-minutes: 120 + + env: + TARGET: ${{ inputs.version_name }} + CI: 1 + MOCK: 1 + + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ inputs.version_toolchain }} + profile: minimal + + - name: Install cargo-binstall + uses: cargo-bins/cargo-binstall@v1.6.4 + + - name: Setup sccache + if: ${{ inputs.version_name }} == risc0 + uses: risc0/risc0/.github/actions/sccache@release-0.19 + + - name: Install ${{ inputs.version_name }} + run: make install + + - name: Build ${{ inputs.version_name }} prover + run: make build + + - name: Test ${{ inputs.version_name }} prover + run: make test + + - name: Build with tracer + if: ${{ inputs.version_name }} == native + run: cargo build -F tracer diff --git a/.github/workflows/ci-lint.yml b/.github/workflows/ci-lint.yml index 6be18df08..0bc43b6cb 100644 --- a/.github/workflows/ci-lint.yml +++ b/.github/workflows/ci-lint.yml @@ -1,8 +1,8 @@ name: CI - Lint on: - pull_request: - types: [opened, reopened, edited, synchronize] + pull_request: + types: [opened, reopened, edited, synchronize] env: CARGO_TERM_COLOR: always @@ -17,15 +17,11 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: risc0/risc0/.github/actions/rustup@release-0.19 + - name: Run install script for all targets + run: make install - - uses: risc0/risc0/.github/actions/sccache@release-0.19 - - - uses: risc0/clippy-action@main - with: - reporter: 'github-pr-check' - fail_on_error: true - clippy_flags: --workspace --all-targets --all-features -- -D warnings + - name: Run clippy check for all targets + run: make clippy fmt: name: fmt @@ -35,6 +31,5 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: risc0/risc0/.github/actions/rustup@release-0.19 - - - run: make fmt + - name: Run format script for all targets + run: make fmt diff --git a/core/src/lib.rs b/core/src/lib.rs index 403cfaf4c..716bf23d5 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -169,7 +169,7 @@ pub fn merge(a: &mut Value, b: &Value) { merge(a.entry(k).or_insert(Value::Null), v); } } - (a, b) if !b.is_null() => *a = b.to_owned(), + (a, b) if !b.is_null() => b.clone_into(a), // If b is null, just keep a (which means do nothing). _ => {} } diff --git a/harness/core/src/assert.rs b/harness/core/src/assert.rs index a583b8556..e9100e2c6 100644 --- a/harness/core/src/assert.rs +++ b/harness/core/src/assert.rs @@ -60,6 +60,10 @@ impl AssertionLog { self.assertions.len() } + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + pub fn display_failures(&self, start: usize, end: usize) { for i in start..end { if let Some(assertion) = self.assertions.get(i) { diff --git a/harness/macro/src/lib.rs b/harness/macro/src/lib.rs index e9d9fe591..c5fdf7bcb 100644 --- a/harness/macro/src/lib.rs +++ b/harness/macro/src/lib.rs @@ -1,9 +1,39 @@ extern crate proc_macro; use proc_macro::TokenStream; use quote::quote; -use syn::{parse_macro_input, punctuated::Punctuated, Ident, Item, ItemFn, ItemMod, Path, Token}; +use syn::{parse_macro_input, Item, ItemFn, ItemMod}; + +#[cfg(any(feature = "sp1", feature = "risc0"))] +use syn::{punctuated::Punctuated, Ident, Path, Token}; + +// Helper struct to parse input +#[cfg(any(feature = "sp1", feature = "risc0"))] +struct EntryArgs { + main_entry: Ident, + test_modules: Option>, +} + +#[cfg(any(feature = "sp1", feature = "risc0"))] +impl syn::parse::Parse for EntryArgs { + fn parse(input: syn::parse::ParseStream) -> syn::Result { + let main_entry: Ident = input.parse()?; + let test_modules: Option> = if input.peek(Token![,]) { + input.parse::()?; // Parse and consume the comma + // Now parse a list of module paths if they are present + Some(input.parse_terminated(Path::parse)?) + } else { + None + }; + + Ok(EntryArgs { + main_entry, + test_modules, + }) + } +} #[proc_macro] +#[cfg(any(feature = "sp1", feature = "risc0"))] pub fn entrypoint(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as EntryArgs); let main_entry = input.main_entry; @@ -70,41 +100,21 @@ pub fn entrypoint(input: TokenStream) -> TokenStream { } }; - #[cfg(all(not(feature = "sp1"), not(feature = "risc0")))] - let output = quote! { + output.into() +} + +#[proc_macro] +#[cfg(not(any(feature = "sp1", feature = "risc0")))] +pub fn entrypoint(_input: TokenStream) -> TokenStream { + quote! { mod generated_main { #[no_mangle] fn main() { super::ENTRY() } } - }; - - output.into() -} - -// Helper struct to parse input -struct EntryArgs { - main_entry: Ident, - test_modules: Option>, -} - -impl syn::parse::Parse for EntryArgs { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - let main_entry: Ident = input.parse()?; - let test_modules: Option> = if input.peek(Token![,]) { - input.parse::()?; // Parse and consume the comma - // Now parse a list of module paths if they are present - Some(input.parse_terminated(Path::parse)?) - } else { - None - }; - - Ok(EntryArgs { - main_entry, - test_modules, - }) } + .into() } #[proc_macro] diff --git a/lib/src/builder/finalize.rs b/lib/src/builder/finalize.rs index 86a1259ca..c59c3ffc9 100644 --- a/lib/src/builder/finalize.rs +++ b/lib/src/builder/finalize.rs @@ -42,8 +42,11 @@ impl BlockFinalizeStrategy for MemDbBlockFinalizeStrategy { fn finalize(mut block_builder: BlockBuilder) -> Result<(AlloyConsensusHeader, MptNode)> { let db: MemDb = block_builder.db.take().expect("DB not initialized"); - let mut account_touched = 0; - let mut storage_touched = 0; + #[cfg(feature = "sp1-cycle-tracker")] + { + let mut account_touched = 0; + let mut storage_touched = 0; + } // apply state updates let mut state_trie = mem::take(&mut block_builder.input.parent_state_trie); @@ -62,7 +65,10 @@ impl BlockFinalizeStrategy for MemDbBlockFinalizeStrategy { continue; } - account_touched += 1; + #[cfg(feature = "sp1-cycle-tracker")] + { + account_touched += 1; + } // otherwise, compute the updated storage root for that account let state_storage = &account.storage; @@ -88,7 +94,10 @@ impl BlockFinalizeStrategy for MemDbBlockFinalizeStrategy { storage_trie.insert_rlp(&storage_trie_index, *value)?; } - storage_touched += 1; + #[cfg(feature = "sp1-cycle-tracker")] + { + storage_touched += 1; + } } storage_trie.hash() diff --git a/lib/src/builder/initialize.rs b/lib/src/builder/initialize.rs index 90b40d4ac..11fbd1ddc 100644 --- a/lib/src/builder/initialize.rs +++ b/lib/src/builder/initialize.rs @@ -62,8 +62,14 @@ impl DbInitStrategy for MemDbInitStrategy { .map(|bytes| (keccak(&bytes).into(), bytes)) .collect(); - let mut account_touched = 0; - let mut storage_touched = 0; + #[cfg(all( + all(target_os = "zkvm", target_vendor = "succinct"), + feature = "sp1-cycle-tracker" + ))] + { + let mut account_touched = 0; + let mut storage_touched = 0; + } // Load account data into db let mut accounts = HashMap::with_capacity(block_builder.input.parent_storage.len()); @@ -85,7 +91,13 @@ impl DbInitStrategy for MemDbInitStrategy { storage_trie.hash() ); } - account_touched += 1; + #[cfg(all( + all(target_os = "zkvm", target_vendor = "succinct"), + feature = "sp1-cycle-tracker" + ))] + { + account_touched += 1; + } // load the corresponding code let code_hash = state_account.code_hash; @@ -106,7 +118,13 @@ impl DbInitStrategy for MemDbInitStrategy { .get_rlp(&keccak(slot.to_be_bytes::<32>()))? .unwrap_or_default(); storage.insert(slot, value); - storage_touched += 1; + #[cfg(all( + all(target_os = "zkvm", target_vendor = "succinct"), + feature = "sp1-cycle-tracker" + ))] + { + storage_touched += 1; + } } let mem_account = DbAccount { @@ -129,8 +147,8 @@ impl DbInitStrategy for MemDbInitStrategy { feature = "sp1-cycle-tracker" ))] { - println!("initialize_db Account touch {:?}", account_touched); - println!("initialize_db Storage touch {:?}", storage_touched); + println!("initialize_db Account touch {account_touched:?}"); + println!("initialize_db Storage touch {storage_touched:?}"); } // prepare block hash history diff --git a/lib/src/consts.rs b/lib/src/consts.rs index 987821b94..7db4f6342 100644 --- a/lib/src/consts.rs +++ b/lib/src/consts.rs @@ -250,14 +250,14 @@ pub enum Network { TaikoMainnet, } -impl ToString for Network { - fn to_string(&self) -> String { - match self { - Network::Ethereum => "ethereum".to_string(), - Network::Holesky => "holesky".to_string(), - Network::TaikoA7 => "taiko_a7".to_string(), - Network::TaikoMainnet => "taiko_mainnet".to_string(), - } +impl std::fmt::Display for Network { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str(match self { + Network::Ethereum => "ethereum", + Network::Holesky => "holesky", + Network::TaikoA7 => "taiko_a7", + Network::TaikoMainnet => "taiko_mainnet", + }) } } diff --git a/lib/src/lib.rs b/lib/src/lib.rs index dd745d79f..79925dc6b 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -86,6 +86,7 @@ mod time { } pub struct CycleTracker { + #[allow(dead_code)] title: String, } diff --git a/lib/src/protocol_instance.rs b/lib/src/protocol_instance.rs index 2a0595f43..94e21b3db 100644 --- a/lib/src/protocol_instance.rs +++ b/lib/src/protocol_instance.rs @@ -45,7 +45,7 @@ impl ProtocolInstance { let aligned_data_size = (data_size + 3) / 4 * 4; let layout = Layout::from_size_align(aligned_data_size, 4).unwrap(); // Allocate aligned memory - let raw_ptr = unsafe { alloc(layout) as *mut u8 }; + let raw_ptr = unsafe { alloc(layout) }; if raw_ptr.is_null() { panic!("Failed to allocate memory with aligned pointer"); } diff --git a/makefile b/makefile index e4ee05d11..f59122e1d 100644 --- a/makefile +++ b/makefile @@ -16,5 +16,4 @@ fmt: @cargo fmt --all --check clippy: - @cargo +nightly-2024-04-18 check --features "sgx,sp1,risc0" - @cargo +nightly-2024-04-18 clippy --workspace --features "sgx,sp1,risc0" --all-targets -- -Dwarnings + CLIPPY=1 ./script/build.sh $(TARGET) diff --git a/provers/risc0/builder/src/main.rs b/provers/risc0/builder/src/main.rs index 81803a214..b0de9edb1 100644 --- a/provers/risc0/builder/src/main.rs +++ b/provers/risc0/builder/src/main.rs @@ -62,7 +62,7 @@ impl Pipeline for Risc0Pipeline { .execute() .expect("Execution failed") .risc0_placement(dest) - .expect("Failed to export Sp1 artifacts"); + .expect("Failed to export Risc0 artifacts"); } fn tests(&self, names: &[&str], dest: &str) { @@ -81,6 +81,6 @@ impl Pipeline for Risc0Pipeline { .execute() .expect("Execution failed") .risc0_placement(dest) - .expect("Failed to export Sp1 artifacts"); + .expect("Failed to export Risc0 artifacts"); } } diff --git a/provers/sgx/guest/src/signature.rs b/provers/sgx/guest/src/signature.rs index ff0765297..262797ac6 100644 --- a/provers/sgx/guest/src/signature.rs +++ b/provers/sgx/guest/src/signature.rs @@ -25,7 +25,7 @@ pub fn recover_signer_unchecked(sig: &[u8; 65], msg: &[u8; 32]) -> Result Result Result<[u8; 65], Error> { let secret = B256::from_slice(&secret_key.secret_bytes()[..]); let sec = SecretKey::from_slice(secret.as_ref())?; - let s = SECP256K1.sign_ecdsa_recoverable(&Message::from_slice(&message[..])?, &sec); + let s = SECP256K1.sign_ecdsa_recoverable(&Message::from_digest_slice(&message[..])?, &sec); let (rec_id, data) = s.serialize_compact(); let signature = Signature::from_bytes_and_parity(&data, (rec_id.to_i32() != 0) as u64).unwrap(); Ok(signature.as_bytes()) diff --git a/script/build.sh b/script/build.sh index 3142ecced..69eaafe56 100755 --- a/script/build.sh +++ b/script/build.sh @@ -46,7 +46,9 @@ fi # NATIVE if [ -z "$1" ] || [ "$1" == "native" ]; then - if [ -z "${RUN}" ]; then + if [ -n "${CLIPPY}" ]; then + cargo clippy -- -D warnings + elif [ -z "${RUN}" ]; then if [ -z "${TEST}" ]; then echo "Building native prover" cargo build ${FLAGS} @@ -72,7 +74,9 @@ if [ -z "$1" ] || [ "$1" == "sgx" ]; then export SGX_DIRECT=1 echo "SGX_DIRECT is set to $SGX_DIRECT" fi - if [ -z "${RUN}" ]; then + if [ -n "${CLIPPY}" ]; then + cargo ${TOOLCHAIN_SGX} clippy -p raiko-host -p sgx-prover -F "sgx enable" -- -D warnings + elif [ -z "${RUN}" ]; then if [ -z "${TEST}" ]; then echo "Building SGX prover" cargo ${TOOLCHAIN_SGX} build ${FLAGS} --features sgx @@ -99,7 +103,13 @@ if [ -z "$1" ] || [ "$1" == "risc0" ]; then export RISC0_DEV_MODE=1 echo "RISC0_DEV_MODE is set to $RISC0_DEV_MODE" fi - if [ -z "${RUN}" ]; then + if [ -n "${CLIPPY}" ]; then + MOCK=1 + RISC0_DEV_MODE=1 + CI=1 + cargo ${TOOLCHAIN_RISC0} run --bin risc0-builder + cargo ${TOOLCHAIN_RISC0} clippy -F risc0 + elif [ -z "${RUN}" ]; then if [ -z "${TEST}" ]; then echo "Building Risc0 prover" cargo ${TOOLCHAIN_RISC0} run --bin risc0-builder @@ -127,7 +137,9 @@ if [ -z "$1" ] || [ "$1" == "sp1" ]; then export SP1_PROVER=mock echo "SP1_PROVER is set to $SP1_PROVER" fi - if [ -z "${RUN}" ]; then + if [ -n "${CLIPPY}" ]; then + cargo ${TOOLCHAIN_SP1} clippy -p raiko-host -p sp1-builder -p sp1-driver -F "sp1 enable" + elif [ -z "${RUN}" ]; then if [ -z "${TEST}" ]; then echo "Building Sp1 prover" cargo ${TOOLCHAIN_SP1} run --bin sp1-builder