Skip to content

feat(raiko): update r0 to v2.0.1 & sp1 to v4.1.7 #543

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

Merged
merged 19 commits into from
Apr 17, 2025
Merged
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
1,052 changes: 711 additions & 341 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,16 @@ reth-chainspec = { git = "https://github.com/taikoxyz/taiko-reth.git", branch =
reth-provider = { git = "https://github.com/taikoxyz/taiko-reth.git", branch = "v1.0.0-rc.2-taiko", default-features = false }

# risc zero
risc0-zkvm = { version = "=1.2.3", features = ["prove", "getrandom"] }
bonsai-sdk = { version = "=1.2.3" }
risc0-binfmt = { version = "=1.2.3" }
risc0-zkvm = { version = "=2.0.1", features = ["prove", "getrandom"] }
bonsai-sdk = { version = "=1.4.0" }
risc0-binfmt = { version = "=2.0.0" }
risc0-zkos-v1compat = { version = "=2.0.0" }

# SP1
sp1-sdk = { version = "=4.0.0-rc.8" }
sp1-prover = { version = "=4.0.0-rc.8" }
sp1-zkvm = { version = "=4.0.0-rc.8" }
sp1-helper = { version = "=4.0.0-rc.8" }
sp1-sdk = { version = "4.1.7" }
sp1-prover = { version = "4.1.7" }
sp1-zkvm = { version = "4.1.7" }
sp1-helper = { version = "4.1.7" }

# alloy
alloy-rlp = { version = "0.3.4", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.zk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.82.0 AS base-builder
FROM rust:1.85.0 AS base-builder

ENV DEBIAN_FRONTEND=noninteractive
ARG BUILD_FLAGS=""
Expand Down
8 changes: 2 additions & 6 deletions docker/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ HOLESKY_RPC=
HOLESKY_BEACON_RPC=
TAIKO_A7_RPC=
TAIKO_MAINNET_RPC=
BONSAI_API_KEY=
BONSAI_API_URL=
GROTH16_VERIFIER_RPC_URL=
GROTH16_VERIFIER_ADDRESS=
SP1_PRIVATE_KEY=
NETWORK_RPC_URL=
NETWORK_PRIVATE_KEY=
SP1_VERIFIER_RPC_URL=
SP1_VERIFIER_ADDRESS=
PROVER_NETWORK_RPC=
11 changes: 7 additions & 4 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,20 @@ services:
- TAIKO_MAINNET_RPC=${TAIKO_MAINNET_RPC}
- L1_NETWORK=${L1_NETWORK}
- NETWORK=${NETWORK}
- REDIS_URL=${REDIS_URL:-redis://redis:6379}
# risc0 service env
- BONSAI_API_KEY=${BONSAI_API_KEY}
- BONSAI_API_URL=${BONSAI_API_URL}
- MAX_BONSAI_GPU_NUM=300
# risc0 verifier
- GROTH16_VERIFIER_RPC_URL=${GROTH16_VERIFIER_RPC_URL}
- GROTH16_VERIFIER_ADDRESS=${GROTH16_VERIFIER_ADDRESS}
- SP1_PRIVATE_KEY=${SP1_PRIVATE_KEY}
# sp1 service env
- NETWORK_RPC_URL=${NETWORK_RPC_URL}
- NETWORK_PRIVATE_KEY=${NETWORK_PRIVATE_KEY}
- SKIP_SIMULATION=true
# sp1 verifier
- SP1_VERIFIER_RPC_URL=${SP1_VERIFIER_RPC_URL}
- SP1_VERIFIER_ADDRESS=${SP1_VERIFIER_ADDRESS}
- PROVER_NETWORK_RPC=${PROVER_NETWORK_RPC}
- REDIS_URL=${REDIS_URL:-redis://redis:6379}
depends_on:
- redis
profiles:
Expand Down
3 changes: 2 additions & 1 deletion pipeline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ once_cell = { workspace = true }
anyhow = { workspace = true }
dirs = { workspace = true }
risc0-binfmt = { workspace = true, optional = true }
risc0-zkos-v1compat = { workspace = true, optional = true }
pathdiff = { workspace = true, optional = true }
hex = { workspace = true, optional = true }
sp1-sdk = { workspace = true, optional = true }

[features]
risc0 = ["dep:risc0-binfmt", "dep:pathdiff", "dep:hex"]
risc0 = ["dep:risc0-binfmt", "dep:pathdiff", "dep:hex", "dep:risc0-zkos-v1compat"]
sp1 = ["dep:sp1-sdk"]
17 changes: 15 additions & 2 deletions pipeline/src/risc0_util.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use anyhow::Result;
use risc0_binfmt::ProgramBinary;
use risc0_zkos_v1compat::V1COMPAT_ELF;
use std::{
borrow::Cow,
fs,
path::{Path, PathBuf},
str::FromStr as _,
};

pub const DIGEST_WORDS: usize = 8;
Expand All @@ -22,12 +25,22 @@ pub struct GuestListEntry {
}

impl GuestListEntry {
/// Builds the [GuestListEntry] by reading the ELF from disk, and calculating the associated
/// Builds the [GuestListEntry] by reading the user ELF from disk, combines with V1COMPAT_ELF kernel, and calculating the associated
/// image ID.
pub fn build(name: &str, elf_path: &str) -> Result<Self> {
let elf = std::fs::read(elf_path)?;
let mut elf_path = elf_path.to_owned();
// Because the R0 build system isn't used, this does not include the kernel portion of the ELF
let user_elf = std::fs::read(&elf_path)?;

// Combines the user ELF with the kernel ELF
let elf = ProgramBinary::new(&user_elf, V1COMPAT_ELF).encode();

let image_id = risc0_binfmt::compute_image_id(&elf)?;

let combined_path = PathBuf::from_str(&(elf_path + ".bin"))?;
std::fs::write(&combined_path, &elf)?;
elf_path = combined_path.to_str().unwrap().to_owned();

println!("risc0 elf image id: {}", hex::encode(image_id.as_bytes()));
Ok(Self {
name: Cow::Owned(name.to_owned()),
Expand Down
1 change: 0 additions & 1 deletion provers/risc0/driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,3 @@ enable = [
cuda = ["risc0-zkvm?/cuda"]
metal = ["risc0-zkvm?/metal"]
bench = []
bonsai-auto-scaling = []
23 changes: 4 additions & 19 deletions provers/risc0/driver/src/bonsai.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::Risc0Param;
use crate::{
snarks::{stark2snark, verify_groth16_from_snark_receipt},
Risc0Response,
Expand All @@ -21,8 +22,6 @@ use std::{
};
use tokio::time::{sleep as tokio_async_sleep, Duration};

use crate::Risc0Param;

const MAX_REQUEST_RETRY: usize = 8;

#[derive(thiserror::Error, Debug)]
Expand All @@ -37,9 +36,6 @@ pub enum BonsaiExecutionError {
Fatal(String),
}

#[cfg(feature = "bonsai-auto-scaling")]
pub mod auto_scaling;

pub async fn verify_bonsai_receipt<O: Eq + Debug + DeserializeOwned>(
image_id: Digest,
expected_output: &O,
Expand Down Expand Up @@ -146,16 +142,6 @@ pub async fn maybe_prove<I: Serialize, O: Eq + Debug + Serialize + DeserializeOw
info!("Loaded locally cached stark receipt {receipt_label:?}");
(cached_data.0, cached_data.1, true)
} else if param.bonsai {
#[cfg(feature = "bonsai-auto-scaling")]
match auto_scaling::maxpower_bonsai().await {
Ok(_) => {}
Err(e) => {
error!("Failed to scale up bonsai: {e:?}");
return Err(ProverError::GuestError(
"Failed to scale up bonsai".to_string(),
));
}
}
// query bonsai service until it works
macro_rules! retry_with_backoff {
($max_retries:expr, $retry_delay:expr, $operation:expr, $err_transform:expr) => {{
Expand Down Expand Up @@ -257,8 +243,6 @@ pub async fn cancel_proof(uuid: String) -> anyhow::Result<()> {
let client = Client::from_env(risc0_zkvm::VERSION)?;
let session = SessionId { uuid };
session.stop(&client)?;
#[cfg(feature = "bonsai-auto-scaling")]
auto_scaling::shutdown_bonsai().await?;
Ok(())
}

Expand Down Expand Up @@ -365,8 +349,9 @@ pub fn prove_locally(
.write_slice(&encoded_input);

if profile {
info!("Profiling enabled.");
env_builder.enable_profiler("profile_r0_local.pb");
warn!("Profiling disabled. Currently not working in v2");
// info!("Profiling enabled.");
// env_builder.enable_profiler("profile_r0_local.pb");
}

for assumption in assumptions {
Expand Down
Loading
Loading