Skip to content

Commit

Permalink
small improvements + run standard tests with native prover
Browse files Browse the repository at this point in the history
  • Loading branch information
Brechtpd committed May 8, 2024
1 parent 4565135 commit 222c5dc
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 31 deletions.
43 changes: 34 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@ concurrency:
cancel-in-progress: true

jobs:
build-test:
name: Build and test native
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2024-04-17
profile: minimal
- name: Install cargo-binstall
uses: cargo-bins/[email protected]
- run: export TARGET=native CI=1 MOCK=1
- name: Install native
run: make install
- name: Build native prover
run: make build
- name: Test native prover
run: make test

build-test-risc0:
name: Build and test risc0
runs-on: ubuntu-latest
Expand All @@ -31,12 +53,13 @@ jobs:
- name: Install cargo-binstall
uses: cargo-bins/[email protected]
- uses: risc0/risc0/.github/actions/[email protected]
- run: export TARGET=risc0 CI=1 MOCK=1
- name: Install risc0
run: TARGET="risc0" CI=1 make install
run: make install
- name: Build risc0 prover
run: TARGET="risc0" make build
run: make build
- name: Test risc0 prover
run: MOCK=1 TARGET="risc0" make test
run: make test

build-test-sp1:
name: Build and test sp1
Expand All @@ -52,12 +75,13 @@ jobs:
profile: minimal
- name: Install cargo-binstall
uses: cargo-bins/[email protected]
- run: export TARGET=sp1 CI=1 MOCK=1
- name: Install sp1
run: TARGET="sp1" CI=1 make install
run: make install
- name: Build sp1 prover
run: TARGET="sp1" make build
run: make build
- name: Test sp1 prover
run: MOCK=1 TARGET="sp1" make test
run: make test

build-test-sgx:
name: Build and test sgx
Expand All @@ -73,12 +97,13 @@ jobs:
profile: minimal
- name: Install cargo-binstall
uses: cargo-bins/[email protected]
- run: export TARGET=sgx CI=1 MOCK=1 SGX_DIRECT=1
- name: Install sgx
run: TARGET="sgx" CI=1 make install
run: make install
- name: Build sgx prover
run: TARGET="sgx" make build
run: make build
- name: Test sgx prover
run: TARGET="sgx" SGX_DIRECT=1 make test
run: make test

build-test-sgx-with-docker:
name: Build and test sgx with Docker
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ $ make install
You can also download all required dependencies for each prover separately, for example to install SP1:

```console
$ TARGET="sp1" make install
$ TARGET=sp1 make install
```
### Building

After installing dependencies of selected prover, the following command internally calls cargo to build the prover's guest target with the `--release` profile by default, for example:
```console
$ TARGET="sp1" make build
$ TARGET=sp1 make build
```
If you set `DEBUG=1` then the target will be compiled without optimization (not recomended for ZkVM elfs).

### Running

Note that you have to `make build` first before running ZkVM provers, otherwise the guest elf may not be up to date and can result in poof failures.
```console
$ TARGET="sp1" make run
$ TARGET=sp1 make run
```
Just for development with the native prover which runs through the block execution without producing any ZK/SGX proof:
```
Expand All @@ -49,12 +49,12 @@ Look into `prove-block.sh` for the available options or run the script without i
### Risc zero
To install, build, and run in one step:
```console
$ export TARGET="risc0"
$ export TARGET=risc0
$ make install && make build && make run
```
To build and run test on Risc0 Zkvm:
```console
$ TARGET="risc0" make test
$ TARGET=risc0 make test
```
#### Bonsai
If you are using Bonsai service, edit `run-bonsai.sh` to setup your API key, endpoint and on-chain verifier address.
Expand All @@ -74,29 +74,29 @@ $ cargo run -F metal --release --features risc0

Note that CUDA needs to be installed when using `cuda`: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html

### SP1
### SP1
To install, build, and run in one step:
```console
$ export TARGET="sp1"
$ export TARGET=sp1
$ make install && make build && make run
```
To build and run test on Sp1 Zkvm:
```console
$ TARGET="sp1" make test
$ TARGET=sp1 make test
```

### SGX:
To install, build, and run in one step:
```console
$ export TARGET="sgx"
$ export TARGET=sgx
$ make install && make build && make run
```
To build and run test related SGX provers:
```console
$ TARGET="sgx" make test
$ TARGET=sgx make test
```
If your CPU doesn't support SGX, you can still run the SGX code through gramine like it would on an SGX machine:

```console
$ SGX_DIRECT=1 TARGET="sgx" make run
$ SGX_DIRECT=1 TARGET=sgx make run
```
6 changes: 3 additions & 3 deletions host/src/raiko.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,12 @@ mod tests {
async fn test_prove_block_taiko_a7() {
let proof_type = get_proof_type_from_env();
let network = Network::TaikoA7;
let block_number = 101368;
let block_number = 105987;
let chain_spec = get_network_spec(network);
let proof_request = ProofRequest {
block_number,
rpc: "https://rpc.hekla.taiko.xyz/".to_string(),
l1_rpc: "https://l1rpc.hekla.taiko.xyz/".to_string(),
rpc: "https://rpc.hekla.taiko.xyz".to_string(),
l1_rpc: "https://ethereum-holesky-rpc.publicnode.com".to_string(),
beacon_rpc: "https://l1beacon.hekla.taiko.xyz".to_string(),
network,
graffiti: B256::ZERO,
Expand Down
1 change: 0 additions & 1 deletion provers/sp1/driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ impl Prover for Sp1Prover {
}
}

#[ignore]
#[test]
fn test_example() {
// TODO(Cecilia): imple GuestInput::mock() for unit test
Expand Down
1 change: 0 additions & 1 deletion provers/sp1/guest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ pub fn main() {
harness::zk_suits!(test_example);
}

#[ignore]
#[test]
pub fn test_example() {
use harness::*;
Expand Down
38 changes: 32 additions & 6 deletions script/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ check_toolchain() {
echo "Installing Rust toolchain: $TOOLCHAIN"
rustup install "$TOOLCHAIN"
fi
}
}

if [ -z "${DEBUG}" ]; then
FLAGS=--release
else
else
echo "Warning: in debug mode"
fi

Expand All @@ -37,23 +37,49 @@ else
COMMAND=run
fi

# NATIVE
if [ -z "$1" ] || [ "$1" == "native" ]; then
if [ -z "${RUN}" ]; then
if [ -z "${TEST}" ]; then
echo "Building native prover"
cargo build ${FLAGS}
else
echo "Building native tests"
cargo test --no-run
fi
else
if [ -z "${TEST}" ]; then
echo "Running native prover"
cargo run ${FLAGS}
else
echo "Running native tests"
cargo test ${FLAGS}
fi
fi
fi

# SGX
if [ -z "$1" ] || [ "$1" == "sgx" ]; then
check_toolchain $TOOLCHAIN_SGX
if [ -z "${RUN}" ]; then
if [ -z "${TEST}" ]; then
echo "Building SGX prover"
cargo ${TOOLCHAIN_SGX} build ${FLAGS} --features sgx
else
cargo ${TOOLCHAIN_SGX} test ${FLAGS} -p sgx-prover --features enable --no-run
echo "Building SGX tests"
cargo ${TOOLCHAIN_SGX} test ${FLAGS} -p host -p sgx-prover --features enable --no-run
fi
else
if [ -z "${TEST}" ]; then
echo "Running SGX prover"
cargo ${TOOLCHAIN_SGX} run ${FLAGS} --features sgx
else
cargo ${TOOLCHAIN_SGX} test ${FLAGS} -p sgx-prover --features enable
echo "Running SGX tests"
cargo ${TOOLCHAIN_SGX} test ${FLAGS} -p host -p sgx-prover --features enable
fi
fi
fi

# RISC0
if [ -z "$1" ] || [ "$1" == "risc0" ]; then
check_toolchain $TOOLCHAIN_RISC0
Expand All @@ -77,7 +103,7 @@ if [ -z "$1" ] || [ "$1" == "risc0" ]; then
cargo ${TOOLCHAIN_RISC0} run ${FLAGS} --features risc0
else
echo "Running Sp1 tests"
RISC0_DEV_MODE=1 cargo ${TOOLCHAIN_RISC0} test ${FLAGS} -p risc0-driver --features enable
cargo ${TOOLCHAIN_RISC0} test ${FLAGS} -p host -p risc0-driver --features enable
fi
fi
fi
Expand All @@ -104,7 +130,7 @@ if [ -z "$1" ] || [ "$1" == "sp1" ]; then
cargo ${TOOLCHAIN_SP1} run ${FLAGS} --features sp1
else
echo "Running Sp1 tests"
cargo ${TOOLCHAIN_SP1} test ${FLAGS} -p sp1-driver --features enable
cargo ${TOOLCHAIN_SP1} test ${FLAGS} -p host -p sp1-driver --features enable
fi
fi
fi

0 comments on commit 222c5dc

Please sign in to comment.