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(raiko): upgrade both rust toolchain and sp1/risc0 sdk. #445

Merged
merged 20 commits into from
Jan 11, 2025
Merged
2,862 changes: 1,478 additions & 1,384 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 @@ -53,14 +53,15 @@ 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.1.2", features = ["prove", "getrandom"] }
bonsai-sdk = { version = "=1.1.2" }
risc0-binfmt = { version = "=1.1.2" }
risc0-zkvm = { version = "=1.2.0", features = ["prove", "getrandom"] }
bonsai-sdk = { version = "=1.2.0" }
risc0-binfmt = { version = "=1.2.0" }

# SP1
sp1-sdk = { version = "=3.3.0" }
sp1-zkvm = { version = "=3.3.0" }
sp1-helper = { version = "=3.3.0" }
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" }

# alloy
alloy-rlp = { version = "0.3.4", default-features = false }
Expand Down Expand Up @@ -129,7 +130,7 @@ cap = { git = "https://github.com/brechtpd/cap", branch = "more-stats", features
# async, server, http queries
axum = { version = "0.7.4", features = ["macros"] }
tower-http = { version = "0.5.2", features = ["full"] }
tower = { version = "0.4.13", features = ["full"] }
tower = { version = "0.5.2", features = ["full"] }
utoipa-swagger-ui = { version = "7.1.0", features = ["axum"] }
utoipa-scalar = { version = "0.1.0", features = ["axum"] }
utoipa = { version = "4.2.0", features = ["axum_extras"] }
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.75.0 AS builder
FROM rust:1.81.0 AS builder

ENV DEBIAN_FRONTEND=noninteractive
ARG BUILD_FLAGS=""
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.79.0 AS base-builder
FROM rust:1.81.0 AS base-builder

ENV DEBIAN_FRONTEND=noninteractive
ARG BUILD_FLAGS=""
Expand Down
6 changes: 1 addition & 5 deletions docs/README_Sp1.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ To enable CPU acceleration, you can use the `RUSTFLAGS` environment variable to
RUSTFLAGS='-C target-cpu=native' cargo run --release
```

Currently there is support for AVX512 and NEON SIMD instructions. For NEON, you must also enable the `sp1-driver` feature `neon`.

```bash
cargo run --features sp1,neon --release
```
Currently there is support for AVX512 SIMD instructions.

## Performance

Expand Down
13 changes: 10 additions & 3 deletions host/src/bin/gen_kzg_settings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(slice_flatten)]
use std::{fs, path::PathBuf};

use kzg::kzg_proofs::KZGSettings;
Expand All @@ -7,8 +6,16 @@ static FILE_NAME: &str = "zkcrypto_kzg_settings.bin";

fn main() {
let kzg_setting: KZGSettings = kzg_traits::eip_4844::load_trusted_setup_rust(
G1Points::as_ref(G1_POINTS).flatten(),
G2Points::as_ref(G2_POINTS).flatten(),
&G1Points::as_ref(G1_POINTS)
.into_iter()
.flatten()
.cloned()
.collect::<Vec<_>>(),
&G2Points::as_ref(G2_POINTS)
.into_iter()
.flatten()
.cloned()
.collect::<Vec<_>>(),
)
.expect("failed to load trusted setup");

Expand Down
12 changes: 8 additions & 4 deletions host/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,10 +717,14 @@ mod tests {
let result = actor.handle_system_pause().await;

// Verify error contains all accumulated errors
assert!(matches!(
result,
Err(HostError::Core(RaikoError::FeatureNotSupportedError(..)))
));
#[cfg(not(feature = "risc0"))]
assert!(
matches!(
result,
Err(HostError::Core(RaikoError::FeatureNotSupportedError(..)))
),
"Unexpected result: {result:?}",
);
assert!(good_running_task_token.is_cancelled());
assert!(good_aggregation_task_token.is_cancelled());
assert!(actor.pending_tasks.lock().await.is_empty());
Expand Down
8 changes: 3 additions & 5 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#![cfg_attr(any(not(feature = "std")), no_std)]
#![feature(slice_flatten)]
#![feature(result_flattening)]
#[cfg(feature = "std")]
use std::io::{self, Write};

Expand Down Expand Up @@ -84,7 +82,7 @@ impl CycleTracker {
title: title.to_string(),
};
#[cfg(all(
all(target_os = "zkvm", target_vendor = "succinct"),
all(target_os = "zkvm", not(target_vendor = "risc0")),
feature = "sp1-cycle-tracker"
))]
println!("cycle-tracker-start: {0}", title);
Expand All @@ -93,15 +91,15 @@ impl CycleTracker {

pub fn end(&self) {
#[cfg(all(
all(target_os = "zkvm", target_vendor = "succinct"),
all(target_os = "zkvm", not(target_vendor = "risc0")),
feature = "sp1-cycle-tracker"
))]
println!("cycle-tracker-end: {0}", self.title);
}

pub fn println(_inner: impl Fn()) {
#[cfg(all(
all(target_os = "zkvm", target_vendor = "succinct"),
all(target_os = "zkvm", not(target_vendor = "risc0")),
feature = "sp1-cycle-tracker"
))]
_inner()
Expand Down
12 changes: 10 additions & 2 deletions lib/src/primitives/eip4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,16 @@ mod test {
#[test]
fn test_kzg_settings_equivalence() {
let kzg_settings: KZGSettings = kzg_traits::eip_4844::load_trusted_setup_rust(
G1Points::as_ref(G1_POINTS).flatten(),
G2Points::as_ref(G2_POINTS).flatten(),
&G1Points::as_ref(G1_POINTS)
.into_iter()
.flatten()
.cloned()
.collect::<Vec<_>>(),
&G2Points::as_ref(G2_POINTS)
.into_iter()
.flatten()
.cloned()
.collect::<Vec<_>>(),
)
.expect("failed to load trusted setup");
assert_eq!(KZG_SETTINGS.clone().secret_g1, kzg_settings.secret_g1);
Expand Down
2 changes: 1 addition & 1 deletion provers/risc0/driver/src/methods/risc0_aggregation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub const RISC0_AGGREGATION_ELF: &[u8] =
include_bytes!("../../../guest/target/riscv32im-risc0-zkvm-elf/release/risc0-aggregation");
pub const RISC0_AGGREGATION_ID: [u32; 8] = [
1011950429, 2998663226, 1723944064, 1742472798, 1225419420, 1333504266, 3595009277, 3228775676,
1132337184, 861215425, 2474295562, 3812987433, 1104601167, 1875139555, 1619752567, 983201767,
];
2 changes: 1 addition & 1 deletion provers/risc0/driver/src/methods/risc0_guest.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub const RISC0_GUEST_ELF: &[u8] =
include_bytes!("../../../guest/target/riscv32im-risc0-zkvm-elf/release/risc0-guest");
pub const RISC0_GUEST_ID: [u32; 8] = [
1848002361, 3447634449, 2932177819, 2827220601, 4284138344, 2572487667, 1602600202, 3769687346,
2915820976, 1641740336, 1994238336, 1088773515, 373888610, 185287152, 956320274, 2549679061,
];
78 changes: 60 additions & 18 deletions provers/risc0/guest/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions provers/risc0/guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ path = "src/benchmark/ecdsa.rs"

[dependencies]
raiko-lib = { path = "../../../lib", features = ["std", "risc0"] }
risc0-zkvm = { version = "=1.1.2", default-features = false, features = [
risc0-zkvm = { version = "=1.2.0", default-features = false, features = [
'std',
"getrandom",
"heap-embedded-alloc"
"heap-embedded-alloc",
] }
risc0-zkvm-platform = { version = "=1.2.0", default-features = false, features = [
"sys-getenv",
] }
k256 = { git = "https://github.com/risc0/RustCrypto-elliptic-curves", tag = "k256/v0.13.3-risczero.0" }
sha2 = { git = "https://github.com/risc0/RustCrypto-hashes", tag = "sha2-v0.10.6-risczero.0" }
Expand All @@ -47,4 +50,4 @@ c-kzg = { git = "https://github.com/brechtpd/c-kzg-4844", branch = "for-alpha7"
blst = { git = "https://github.com/CeciliaZ030/blst.git", branch = "v0.3.12-serialize" }
crypto-bigint = { git = "https://github.com/risc0/RustCrypto-crypto-bigint", tag = "v0.5.2-risczero.0" }
k256 = { git = "https://github.com/risc0/RustCrypto-elliptic-curves", tag = "k256/v0.13.3-risczero.0" }
sha2 = { git = "https://github.com/risc0/RustCrypto-hashes", tag = "sha2-v0.10.6-risczero.0" }
sha2 = { git = "https://github.com/risc0/RustCrypto-hashes", tag = "sha2-v0.10.6-risczero.0" }
2 changes: 1 addition & 1 deletion provers/sp1/contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The contract and proof is generated by [./provers/sp1/driver/src/gen_verifier.rs
RUST_LOG=debug
```
- generate proof given `GuestInput` in [input.json](../contracts/src/fixtures/input.json) either remotely or locally
- serealize the proof into [fixture.json](../contracts/src/fixtures/fixture.json) to be tested in `RaikoVerifier.sol`
- serialize the proof into [fixture.json](../contracts/src/fixtures/fixture.json) to be tested in `RaikoVerifier.sol`

### To verify a different block
You can either start Raiko and run [prove-block.sh](../../../script/prove-block.sh) to get the block you want from certain network and then run the `run-verifier` to prove. Make sure the prover is not in `mock` mode. Finally, you can verify with smart contract test.
Expand Down
Loading