diff --git a/.github/workflows/ci-build-test-reusable.yml b/.github/workflows/ci-build-test-reusable.yml index 539652dff..cc0a536b5 100644 --- a/.github/workflows/ci-build-test-reusable.yml +++ b/.github/workflows/ci-build-test-reusable.yml @@ -43,10 +43,16 @@ jobs: uses: risc0/risc0/.github/actions/sccache@release-0.19 - name: Install ${{ inputs.version_name }} + env: + TARGET: ${{ inputs.version_name }} run: make install - name: Build ${{ inputs.version_name }} prover + env: + TARGET: ${{ inputs.version_name }} run: make build - name: Test ${{ inputs.version_name }} prover + env: + TARGET: ${{ inputs.version_name }} run: make test diff --git a/.github/workflows/ci-lint.yml b/.github/workflows/ci-lint.yml index c42d8363e..3c565f80b 100644 --- a/.github/workflows/ci-lint.yml +++ b/.github/workflows/ci-lint.yml @@ -18,11 +18,23 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Run install script for all targets - run: make install - - - name: Run clippy check for all targets - run: make clippy + - name: Run clippy check host + run: cargo clippy -p raiko-host -p raiko-lib -p raiko-core -p harness -p raiko-tasks --all-features -- -D warnings + - name: Run clippy check risc0 + run: | + cargo clippy -p risc0-builder --all-features -- -D warnings + cargo clippy -p risc0-driver --features enable -- -D warnings + cd ./provers/risc0/guest + cargo clippy --all-features -- -D warnings + - name: Run clippy check sp1 + run: | + cargo clippy -p sp1-builder --all-features -- -D warnings + cargo clippy -p sp1-driver --features enable -- -D warnings + cd ./provers/sp1/guest + cargo clippy --all-features -- -D warnings + - name: Run clippy check sgx + run: | + cargo clippy -p sgx-guest -p sgx-prover -p raiko-setup --all-features -- -D warnings fmt: name: fmt @@ -33,4 +45,4 @@ jobs: - uses: actions/checkout@v4 - name: Run format script for all targets - run: make fmt + run: cargo fmt --all --check diff --git a/harness/macro/src/lib.rs b/harness/macro/src/lib.rs index 43c4092d8..0f7a404f6 100644 --- a/harness/macro/src/lib.rs +++ b/harness/macro/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(unused_variables)] extern crate proc_macro; use proc_macro::TokenStream; use quote::quote; diff --git a/host/Cargo.toml b/host/Cargo.toml index 32eb09207..56e2deeab 100644 --- a/host/Cargo.toml +++ b/host/Cargo.toml @@ -81,9 +81,6 @@ ethers-core = { workspace = true } [features] default = [] -sp1 = ["raiko-core/sp1"] -risc0 = ["raiko-core/risc0"] -sgx = ["raiko-core/sgx"] [[bin]] name = "raiko-host" diff --git a/lib/src/primitives/eip4844.rs b/lib/src/primitives/eip4844.rs index 9dd31ae9d..d62851da1 100644 --- a/lib/src/primitives/eip4844.rs +++ b/lib/src/primitives/eip4844.rs @@ -117,13 +117,13 @@ mod test { // The input is encoded as follows: // | versioned_hash | z | y | commitment | proof | // | 32 | 32 | 32 | 48 | 48 | - let version_hash = commitment_to_version_hash(&commitment); + let version_hash = commitment_to_version_hash(commitment); let mut input = [0u8; 192]; input[..32].copy_from_slice(&(*version_hash)); input[32..64].copy_from_slice(&z.to_bytes()); input[64..96].copy_from_slice(&y.to_bytes()); input[96..144].copy_from_slice(commitment); - input[144..192].copy_from_slice(&kzg_proof_to_bytes(&proof)); + input[144..192].copy_from_slice(&kzg_proof_to_bytes(proof)); Ok(reth_primitives::revm_precompile::kzg_point_evaluation::run( &Bytes::copy_from_slice(&input), diff --git a/makefile b/makefile index f59122e1d..11580df82 100644 --- a/makefile +++ b/makefile @@ -11,9 +11,3 @@ run: test: TEST=1 ./script/build.sh $(TARGET) TEST=1 RUN=1 ./script/build.sh $(TARGET) - -fmt: - @cargo fmt --all --check - -clippy: - CLIPPY=1 ./script/build.sh $(TARGET) diff --git a/provers/risc0/guest/src/mem.rs b/provers/risc0/guest/src/mem.rs index a151d19b7..401e0a212 100644 --- a/provers/risc0/guest/src/mem.rs +++ b/provers/risc0/guest/src/mem.rs @@ -2,7 +2,7 @@ use std::{ alloc::{alloc, handle_alloc_error, Layout}, ffi::c_void, }; - +/// # Safety /// This is a basic implementation of custom memory allocation functions that mimic C-style memory management. /// This implementation is designed to be used in ZkVM where we cross-compile Rust code with C /// due to the dependency of c-kzg. This modification also requires env var: @@ -10,6 +10,7 @@ use std::{ /// $ CC_riscv32im-risc0-zkvm-elf="/opt/riscv/bin/riscv32-unknown-elf-gcc" /// which is set in the build pipeline +/// # Safety #[no_mangle] // TODO ideally this is c_size_t, but not stabilized (not guaranteed to be usize on all archs) pub unsafe extern "C" fn malloc(size: usize) -> *mut c_void { @@ -22,13 +23,13 @@ pub unsafe extern "C" fn malloc(size: usize) -> *mut c_void { ptr as *mut c_void } - +/// # Safety #[no_mangle] // TODO shouldn't need to zero allocated bytes since the zkvm memory is zeroed, might want to zero anyway pub unsafe extern "C" fn calloc(nobj: usize, size: usize) -> *mut c_void { malloc(nobj * size) } - +/// # Safety #[no_mangle] pub unsafe extern "C" fn free(_size: *const c_void) { // Intentionally a no-op, since the zkvm allocator is a bump allocator diff --git a/provers/sp1/guest/src/mem.rs b/provers/sp1/guest/src/mem.rs index a151d19b7..452a13704 100644 --- a/provers/sp1/guest/src/mem.rs +++ b/provers/sp1/guest/src/mem.rs @@ -2,7 +2,7 @@ use std::{ alloc::{alloc, handle_alloc_error, Layout}, ffi::c_void, }; - +/// # Safety /// This is a basic implementation of custom memory allocation functions that mimic C-style memory management. /// This implementation is designed to be used in ZkVM where we cross-compile Rust code with C /// due to the dependency of c-kzg. This modification also requires env var: @@ -10,6 +10,7 @@ use std::{ /// $ CC_riscv32im-risc0-zkvm-elf="/opt/riscv/bin/riscv32-unknown-elf-gcc" /// which is set in the build pipeline +/// # Safety #[no_mangle] // TODO ideally this is c_size_t, but not stabilized (not guaranteed to be usize on all archs) pub unsafe extern "C" fn malloc(size: usize) -> *mut c_void { @@ -23,12 +24,14 @@ pub unsafe extern "C" fn malloc(size: usize) -> *mut c_void { ptr as *mut c_void } +/// # Safety #[no_mangle] // TODO shouldn't need to zero allocated bytes since the zkvm memory is zeroed, might want to zero anyway pub unsafe extern "C" fn calloc(nobj: usize, size: usize) -> *mut c_void { malloc(nobj * size) } +/// # Safety #[no_mangle] pub unsafe extern "C" fn free(_size: *const c_void) { // Intentionally a no-op, since the zkvm allocator is a bump allocator diff --git a/script/build.sh b/script/build.sh index 69eaafe56..474376857 100755 --- a/script/build.sh +++ b/script/build.sh @@ -28,7 +28,7 @@ check_toolchain() { } if [ -z "${DEBUG}" ]; then - FLAGS=--release + PROFILE=--release else echo "Warning: in debug mode" fi @@ -46,23 +46,21 @@ fi # NATIVE if [ -z "$1" ] || [ "$1" == "native" ]; then - if [ -n "${CLIPPY}" ]; then - cargo clippy -- -D warnings - elif [ -z "${RUN}" ]; then + if [ -z "${RUN}" ]; then if [ -z "${TEST}" ]; then echo "Building native prover" - cargo build ${FLAGS} + cargo build ${PROFILE} else echo "Building native tests" - cargo test ${FLAGS} --no-run + cargo test ${PROFILE} --no-run fi else if [ -z "${TEST}" ]; then echo "Running native prover" - cargo run ${FLAGS} + cargo run ${PROFILE} else echo "Running native tests" - cargo test ${FLAGS} + cargo test ${PROFILE} fi fi fi @@ -74,23 +72,21 @@ if [ -z "$1" ] || [ "$1" == "sgx" ]; then export SGX_DIRECT=1 echo "SGX_DIRECT is set to $SGX_DIRECT" fi - 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 "${RUN}" ]; then if [ -z "${TEST}" ]; then echo "Building SGX prover" - cargo ${TOOLCHAIN_SGX} build ${FLAGS} --features sgx + cargo ${TOOLCHAIN_SGX} build ${PROFILE} --features sgx else echo "Building SGX tests" - cargo ${TOOLCHAIN_SGX} test ${FLAGS} -p raiko-host -p sgx-prover --features "sgx enable" --no-run + cargo ${TOOLCHAIN_SGX} test ${PROFILE} -p raiko-host -p sgx-prover --features "sgx enable" --no-run fi else if [ -z "${TEST}" ]; then echo "Running SGX prover" - cargo ${TOOLCHAIN_SGX} run ${FLAGS} --features sgx + cargo ${TOOLCHAIN_SGX} run ${PROFILE} --features sgx else echo "Running SGX tests" - cargo ${TOOLCHAIN_SGX} test ${FLAGS} -p raiko-host -p sgx-prover --features "sgx enable" + cargo ${TOOLCHAIN_SGX} test ${PROFILE} -p raiko-host -p sgx-prover --features "sgx enable" fi fi fi @@ -103,13 +99,7 @@ if [ -z "$1" ] || [ "$1" == "risc0" ]; then export RISC0_DEV_MODE=1 echo "RISC0_DEV_MODE is set to $RISC0_DEV_MODE" fi - 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 "${RUN}" ]; then if [ -z "${TEST}" ]; then echo "Building Risc0 prover" cargo ${TOOLCHAIN_RISC0} run --bin risc0-builder @@ -117,15 +107,15 @@ if [ -z "$1" ] || [ "$1" == "risc0" ]; then echo "Building test elfs for Risc0 prover" cargo ${TOOLCHAIN_RISC0} run --bin risc0-builder --features test,bench fi - cargo ${TOOLCHAIN_RISC0} build ${FLAGS} --features risc0 + cargo ${TOOLCHAIN_RISC0} build ${PROFILE} --features risc0 else if [ -z "${TEST}" ]; then echo "Running Risc0 prover" - cargo ${TOOLCHAIN_RISC0} run ${FLAGS} --features risc0 + cargo ${TOOLCHAIN_RISC0} run ${PROFILE} --features risc0 else echo "Running Risc0 tests" - cargo ${TOOLCHAIN_RISC0} test ${FLAGS} --lib risc0-driver --features risc0 -- run_unittest_elf - cargo ${TOOLCHAIN_RISC0} test ${FLAGS} -p raiko-host -p risc0-driver --features "risc0 enable" + cargo ${TOOLCHAIN_RISC0} test ${PROFILE} --lib risc0-driver --features risc0 -- run_unittest_elf + cargo ${TOOLCHAIN_RISC0} test ${PROFILE} -p raiko-host -p risc0-driver --features "risc0 enable" fi fi fi @@ -137,9 +127,7 @@ if [ -z "$1" ] || [ "$1" == "sp1" ]; then export SP1_PROVER=mock echo "SP1_PROVER is set to $SP1_PROVER" fi - 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 "${RUN}" ]; then if [ -z "${TEST}" ]; then echo "Building Sp1 prover" cargo ${TOOLCHAIN_SP1} run --bin sp1-builder @@ -147,15 +135,15 @@ if [ -z "$1" ] || [ "$1" == "sp1" ]; then echo "Building test elfs for Sp1 prover" cargo ${TOOLCHAIN_SP1} run --bin sp1-builder --features test,bench fi - cargo ${TOOLCHAIN_SP1} build ${FLAGS} --features sp1 + cargo ${TOOLCHAIN_SP1} build ${PROFILE} --features sp1 else if [ -z "${TEST}" ]; then echo "Running Sp1 prover" - cargo ${TOOLCHAIN_SP1} run ${FLAGS} --features sp1 + cargo ${TOOLCHAIN_SP1} run ${PROFILE} --features sp1 else echo "Running Sp1 tests" - cargo ${TOOLCHAIN_SP1} test ${FLAGS} --lib sp1-driver --features sp1 -- run_unittest_elf - cargo ${TOOLCHAIN_SP1} test ${FLAGS} -p raiko-host -p sp1-driver --features "sp1 enable" + cargo ${TOOLCHAIN_SP1} test ${PROFILE} --lib sp1-driver --features sp1 -- run_unittest_elf + cargo ${TOOLCHAIN_SP1} test ${PROFILE} -p raiko-host -p sp1-driver --features "sp1 enable" fi fi fi