Skip to content

Commit

Permalink
feat(raiko): run general tests on all targets (#164)
Browse files Browse the repository at this point in the history
* Run general tests on all targets

* fix risc0

* fix SGX + temp disable driver tests

* typo

* increase timeout on ci for SP1

* disable slow test on SP1 so ci can handle it

* decrease sp1 timeout again on ci

* temp disable sp1 driver test

* use more recent taiko a7 block

* small improvements + run standard tests with native prover

* update prove_block with working holesky endpoint

* increase timeout

* fix ci env vars

* more fixes to features

* Fix build error propegation

* skip kzg check on SP1 because out of memory problems

* fix sgx compile error

* fix default skip value
  • Loading branch information
Brechtpd authored May 8, 2024
1 parent a9fd25f commit 27b0bee
Show file tree
Hide file tree
Showing 12 changed files with 211 additions and 95 deletions.
63 changes: 49 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,45 @@ on:
env:
CARGO_TERM_COLOR: always
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RISC0_VERSION: 0.20.1
RISC0_TOOLCHAIN_VERSION: test-release-2

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build-test:
name: Build and test native
runs-on: ubuntu-latest
timeout-minutes: 120
env:
TARGET: native
CI: 1
MOCK: 1
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]
- 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
timeout-minutes: 60
timeout-minutes: 120
env:
TARGET: risc0
CI: 1
MOCK: 1
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -32,16 +59,20 @@ jobs:
uses: cargo-bins/[email protected]
- uses: risc0/risc0/.github/actions/[email protected]
- 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
runs-on: ubuntu-latest
timeout-minutes: 60
timeout-minutes: 120
env:
TARGET: sp1
CI: 1
MOCK: 1
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -53,16 +84,20 @@ jobs:
- name: Install cargo-binstall
uses: cargo-bins/[email protected]
- 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
runs-on: ubuntu-latest
timeout-minutes: 60
timeout-minutes: 120
env:
TARGET: sgx
CI: 1
MOCK: 1
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -74,11 +109,11 @@ jobs:
- name: Install cargo-binstall
uses: cargo-bins/[email protected]
- 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" 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
$ MOCK=1 TARGET=sgx make run
```
1 change: 1 addition & 0 deletions host/src/preflight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pub async fn preflight<BDP: BlockDataProvider>(
tx_blob_hash,
block_proposed: proposal_event,
prover_data,
skip_verify_blob: false,
}
} else {
// For Ethereum blocks we just convert the block transactions in a tx_list
Expand Down
108 changes: 74 additions & 34 deletions host/src/raiko.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,74 +210,114 @@ fn check_eq<T: std::cmp::PartialEq + std::fmt::Debug>(expected: T, actual: T, me

#[cfg(test)]
mod tests {
use crate::raiko::{ChainSpec, NativeResponse, Raiko};
use crate::raiko::{ChainSpec, Raiko};
use crate::request::{ProofRequest, ProofType};
use crate::rpc_provider::RpcBlockDataProvider;
use alloy_primitives::Address;
use raiko_lib::{
consts::{get_network_spec, Network},
input::GuestOutput,
};
use clap::ValueEnum;
use raiko_lib::consts::{get_network_spec, Network};
use raiko_primitives::B256;
use serde_json::{json, Value};
use std::collections::HashMap;
use std::env;

fn get_proof_type_from_env() -> ProofType {
let proof_type = env::var("TARGET").unwrap_or("native".to_string());
ProofType::from_str(&proof_type, true).unwrap()
}

fn is_ci() -> bool {
let ci = env::var("CI").unwrap_or("0".to_string());
ci == "1"
}

fn test_proof_params() -> HashMap<String, Value> {
let mut prover_args = HashMap::new();
prover_args.insert(
"risc0".to_string(),
json! {
{
"bonsai": false,
"snark": false,
"profile": true,
"execution_po2": 18
}
},
);
prover_args.insert(
"sgx".to_string(),
json! {
{
"instance_id": 121,
"setup": true,
"bootstrap": true,
"prove": true,
}
},
);
prover_args
}

async fn prove_block(chain_spec: ChainSpec, proof_request: ProofRequest) {
let provider =
RpcBlockDataProvider::new(&proof_request.rpc.clone(), proof_request.block_number - 1);
let raiko = Raiko::new(chain_spec, proof_request);
let input = raiko
let raiko = Raiko::new(chain_spec, proof_request.clone());
let mut input = raiko
.generate_input(provider)
.await
.expect("input generation failed");
if is_ci() && proof_request.proof_type == ProofType::Sp1 {
input.taiko.skip_verify_blob = true;
}
let output = raiko.get_output(&input).expect("output generation failed");
let proof = raiko
let _proof = raiko
.prove(input, &output)
.await
.expect("proof generation failed");
let response: NativeResponse = serde_json::from_value(proof).unwrap();
match response.output {
GuestOutput::Success(_) => {}
GuestOutput::Failure => unreachable!(),
};
}

#[tokio::test(flavor = "multi_thread")]
async fn test_prove_block_taiko_a7() {
let proof_type = get_proof_type_from_env();
let network = Network::TaikoA7;
let block_number = 39367;
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,
prover: Address::ZERO,
l1_network: Network::Ethereum.to_string(),
proof_type: ProofType::Native,
prover_args: HashMap::new(),
proof_type,
prover_args: test_proof_params(),
};
prove_block(chain_spec, proof_request).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_prove_block_ethereum() {
let network = Network::Ethereum;
let block_number = 19707175;
let chain_spec = get_network_spec(network);
let proof_request = ProofRequest {
block_number,
rpc: "https://rpc.ankr.com/eth".to_string(),
l1_rpc: String::new(),
beacon_rpc: String::new(),
network,
graffiti: B256::ZERO,
prover: Address::ZERO,
l1_network: Network::Ethereum.to_string(),
proof_type: ProofType::Native,
prover_args: HashMap::new(),
};
prove_block(chain_spec, proof_request).await;
let proof_type = get_proof_type_from_env();
// Skip test on SP1 for now because it's too slow on CI
if proof_type != ProofType::Sp1 {
let network = Network::Ethereum;
let block_number = 19707175;
let chain_spec = get_network_spec(network);
let proof_request = ProofRequest {
block_number,
rpc: "https://rpc.ankr.com/eth".to_string(),
l1_rpc: String::new(),
beacon_rpc: String::new(),
network,
graffiti: B256::ZERO,
prover: Address::ZERO,
l1_network: Network::Ethereum.to_string(),
proof_type,
prover_args: test_proof_params(),
};
prove_block(chain_spec, proof_request).await;
}
}
}
1 change: 1 addition & 0 deletions lib/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ pub struct TaikoGuestInput {
pub block_proposed: BlockProposed,
pub prover_data: TaikoProverData,
pub tx_blob_hash: Option<B256>,
pub skip_verify_blob: bool,
}

#[derive(Clone, Default, Debug, Serialize, Deserialize)]
Expand Down
26 changes: 16 additions & 10 deletions lib/src/protocol_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,22 @@ pub fn assemble_protocol_instance(
) -> Result<ProtocolInstance> {
let blob_used = input.taiko.block_proposed.meta.blobUsed;
let tx_list_hash = if blob_used {
let mut data = Vec::from(KZG_TRUST_SETUP_DATA);
let kzg_settings = KzgSettings::from_u8_slice(&mut data);
let kzg_commit = KzgCommitment::blob_to_kzg_commitment(
&Blob::from_bytes(&input.taiko.tx_data.as_slice()).unwrap(),
&kzg_settings,
)
.unwrap();
let versioned_hash = kzg_to_versioned_hash(kzg_commit);
assert_eq!(versioned_hash, input.taiko.tx_blob_hash.unwrap());
versioned_hash
if !input.taiko.skip_verify_blob {
println!("kzg check enabled!");
let mut data = Vec::from(KZG_TRUST_SETUP_DATA);
let kzg_settings = KzgSettings::from_u8_slice(&mut data);
let kzg_commit = KzgCommitment::blob_to_kzg_commitment(
&Blob::from_bytes(&input.taiko.tx_data.as_slice()).unwrap(),
&kzg_settings,
)
.unwrap();
let versioned_hash = kzg_to_versioned_hash(kzg_commit);
assert_eq!(versioned_hash, input.taiko.tx_blob_hash.unwrap());
versioned_hash
} else {
println!("kzg check disabled!");
input.taiko.tx_blob_hash.unwrap()
}
} else {
TxHash::from(keccak(input.taiko.tx_data.as_slice()))
};
Expand Down
Loading

0 comments on commit 27b0bee

Please sign in to comment.