From 210023b06044e1f8e1b7b4d0d4004d89dc97bcf6 Mon Sep 17 00:00:00 2001 From: CeciliaZ030 Date: Sun, 21 Jul 2024 06:02:32 +0000 Subject: [PATCH 1/6] init --- .github/workflows/ci-lint.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci-lint.yml b/.github/workflows/ci-lint.yml index c42d8363e..addececec 100644 --- a/.github/workflows/ci-lint.yml +++ b/.github/workflows/ci-lint.yml @@ -18,9 +18,6 @@ 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 From 4027310fe8036e600e23595be75a5debf41f097d Mon Sep 17 00:00:00 2001 From: CeciliaZ030 Date: Sun, 21 Jul 2024 06:56:55 +0000 Subject: [PATCH 2/6] clippy & fmt --- .github/workflows/ci-lint.yml | 19 ++++++++++++++++--- harness/macro/src/lib.rs | 1 + host/Cargo.toml | 3 --- lib/src/primitives/eip4844.rs | 4 ++-- makefile | 6 ------ 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci-lint.yml b/.github/workflows/ci-lint.yml index addececec..dec348a53 100644 --- a/.github/workflows/ci-lint.yml +++ b/.github/workflows/ci-lint.yml @@ -18,8 +18,21 @@ jobs: steps: - uses: actions/checkout@v4 - - 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 + - name: Run clippy check sgx + run: | + cargo clippy -p sgx-guest -p sgx-prover -p raiko-setup --all-features -- -D warnings fmt: name: fmt @@ -30,4 +43,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) From 8ddc7aa0b39691bdb6e3e2765dd32516b47e7794 Mon Sep 17 00:00:00 2001 From: CeciliaZ030 Date: Sun, 21 Jul 2024 07:01:57 +0000 Subject: [PATCH 3/6] /// # Safety in guests --- .github/workflows/ci-lint.yml | 6 ++++-- provers/risc0/guest/src/mem.rs | 7 ++++--- provers/sp1/guest/src/mem.rs | 5 ++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-lint.yml b/.github/workflows/ci-lint.yml index dec348a53..3c565f80b 100644 --- a/.github/workflows/ci-lint.yml +++ b/.github/workflows/ci-lint.yml @@ -24,12 +24,14 @@ jobs: 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 + 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 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 From 3f84a22373f7857d22fe8502c14bd03efc2433ce Mon Sep 17 00:00:00 2001 From: CeciliaZ030 Date: Sun, 21 Jul 2024 07:03:20 +0000 Subject: [PATCH 4/6] no clippy in build.sh --- script/build.sh | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/script/build.sh b/script/build.sh index 69eaafe56..2d25ac87c 100755 --- a/script/build.sh +++ b/script/build.sh @@ -46,9 +46,7 @@ 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} @@ -74,8 +72,6 @@ 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 "${TEST}" ]; then echo "Building SGX prover" @@ -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 @@ -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 From b4c70ca3d9656ba71269b33dfec0baa6740cd30c Mon Sep 17 00:00:00 2001 From: CeciliaZ030 Date: Sun, 21 Jul 2024 07:16:02 +0000 Subject: [PATCH 5/6] TARGET: ${{ inputs.version_name }} --- .github/workflows/ci-build-test-reusable.yml | 6 ++++++ 1 file changed, 6 insertions(+) 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 From a6eadd43c3b3239efea81e43a670d5da468da400 Mon Sep 17 00:00:00 2001 From: CeciliaZ030 Date: Sun, 21 Jul 2024 15:50:22 +0000 Subject: [PATCH 6/6] fix --- script/build.sh | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/script/build.sh b/script/build.sh index 2d25ac87c..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 @@ -49,18 +49,18 @@ if [ -z "$1" ] || [ "$1" == "native" ]; 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 @@ -72,21 +72,21 @@ if [ -z "$1" ] || [ "$1" == "sgx" ]; then export SGX_DIRECT=1 echo "SGX_DIRECT is set to $SGX_DIRECT" fi - 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 @@ -107,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 @@ -135,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