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

feat(ci): improve ci #327

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions .github/workflows/ci-build-test-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@ jobs:
uses: risc0/risc0/.github/actions/[email protected]

- 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 }}
Comment on lines +46 to +57
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this env passed when it is already present at line 24?

run: make test
24 changes: 18 additions & 6 deletions .github/workflows/ci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +21 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There needs to be an install step because clippy will still compile the projects so they can't actually compile without the tooling present


fmt:
name: fmt
Expand All @@ -33,4 +45,4 @@ jobs:
- uses: actions/checkout@v4

- name: Run format script for all targets
run: make fmt
run: cargo fmt --all --check
1 change: 1 addition & 0 deletions harness/macro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(unused_variables)]
extern crate proc_macro;
use proc_macro::TokenStream;
use quote::quote;
Expand Down
3 changes: 0 additions & 3 deletions host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions lib/src/primitives/eip4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 0 additions & 6 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 4 additions & 3 deletions provers/risc0/guest/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ 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:
/// $ CC="gcc"
/// $ 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 {
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion provers/sp1/guest/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ 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:
/// $ CC="gcc"
/// $ 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 {
Expand All @@ -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
Expand Down
54 changes: 21 additions & 33 deletions script/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ check_toolchain() {
}

if [ -z "${DEBUG}" ]; then
FLAGS=--release
PROFILE=--release
else
echo "Warning: in debug mode"
fi
Expand All @@ -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
Expand All @@ -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
Expand All @@ -103,29 +99,23 @@ 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
else
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
Expand All @@ -137,25 +127,23 @@ 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
else
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
Loading