Skip to content

Commit 1a7cdae

Browse files
committed
First working version of SP1 Distributed Prover
1 parent 65c1758 commit 1a7cdae

File tree

10 files changed

+163
-72
lines changed

10 files changed

+163
-72
lines changed

Cargo.lock

+98-65
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+26-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,19 @@ risc0-build = { version = "1.0.1" }
5454
risc0-binfmt = { version = "1.0.1" }
5555

5656
# SP1
57-
sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", branch = "main" }
58-
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git", branch = "main" }
59-
sp1-helper = { git = "https://github.com/succinctlabs/sp1.git", branch = "main" }
57+
sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", rev = "14eb569d41d24721ffbd407d6060e202482d659c" }
58+
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git", rev = "14eb569d41d24721ffbd407d6060e202482d659c" }
59+
sp1-helper = { git = "https://github.com/succinctlabs/sp1.git", rev = "14eb569d41d24721ffbd407d6060e202482d659c" }
60+
sp1-core = { git = "https://github.com/succinctlabs/sp1.git", rev = "14eb569d41d24721ffbd407d6060e202482d659c" }
61+
62+
63+
# Plonky3
64+
p3-field = { git = "https://github.com/Plonky3/Plonky3.git", rev = "88ea2b866e41329817e4761429b4a5a2a9751c07" }
65+
p3-challenger = { git = "https://github.com/Plonky3/Plonky3.git", rev = "88ea2b866e41329817e4761429b4a5a2a9751c07" }
66+
p3-poseidon2 = { git = "https://github.com/Plonky3/Plonky3.git", rev = "88ea2b866e41329817e4761429b4a5a2a9751c07" }
67+
p3-baby-bear = { git = "https://github.com/Plonky3/Plonky3.git", rev = "88ea2b866e41329817e4761429b4a5a2a9751c07" }
68+
p3-symmetric = { git = "https://github.com/Plonky3/Plonky3.git", rev = "88ea2b866e41329817e4761429b4a5a2a9751c07" }
69+
6070

6171
# alloy
6272
alloy-rlp = { version = "0.3.4", default-features = false }
@@ -187,3 +197,16 @@ revm-primitives = { git = "https://github.com/taikoxyz/revm.git", branch = "v36-
187197
revm-precompile = { git = "https://github.com/taikoxyz/revm.git", branch = "v36-taiko" }
188198
secp256k1 = { git = "https://github.com/CeciliaZ030/rust-secp256k1", branch = "sp1-patch" }
189199
blst = { git = "https://github.com/CeciliaZ030/blst.git", branch = "v0.3.12-serialize" }
200+
201+
# Patch Plonky3 for Serialize and Deserialize of DuplexChallenger
202+
[patch."https://github.com/succinctlabs/sp1.git"]
203+
sp1-sdk = { path = "../sp1/sdk" }
204+
sp1-core = { path = "../sp1/core" }
205+
206+
# Patch Plonky3 for Serialize and Deserialize of DuplexChallenger
207+
[patch."https://github.com/Plonky3/Plonky3.git"]
208+
p3-field = { git = "https://github.com/Champii/Plonky3.git", branch = "serde_patch" }
209+
p3-challenger = { git = "https://github.com/Champii/Plonky3.git", branch = "serde_patch" }
210+
p3-poseidon2 = { git = "https://github.com/Champii/Plonky3.git", branch = "serde_patch" }
211+
p3-baby-bear = { git = "https://github.com/Champii/Plonky3.git", branch = "serde_patch" }
212+
p3-symmetric = { git = "https://github.com/Champii/Plonky3.git", branch = "serde_patch" }

host/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ ethers-core = { workspace = true }
8181

8282
[features]
8383
default = []
84-
sp1 = ["raiko-core/sp1"]
84+
sp1 = ["raiko-core/sp1", "sp1-driver"]
8585
risc0 = ["raiko-core/risc0"]
8686
sgx = ["raiko-core/sgx"]
8787

host/src/lib.rs

+19
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ pub struct Opts {
3434
/// [default: 0.0.0.0:8080]
3535
address: String,
3636

37+
#[arg(long, require_equals = true, default_value = "0.0.0.0:8081")]
38+
#[serde(default = "Opts::default_sp1_worker_address")]
39+
/// Distributed SP1 worker listening address
40+
/// [default: 0.0.0.0:8081]
41+
sp1_worker_address: String,
42+
43+
#[arg(long, default_value = None)]
44+
/// Distributed SP1 worker orchestrator address
45+
///
46+
/// Setting this will enable the worker and restrict it to only accept requests from
47+
/// this orchestrator
48+
///
49+
/// [default: None]
50+
sp1_orchestrator_address: Option<String>,
51+
3752
#[arg(long, require_equals = true, default_value = "16")]
3853
#[serde(default = "Opts::default_concurrency_limit")]
3954
/// Limit the max number of in-flight requests
@@ -87,6 +102,10 @@ impl Opts {
87102
"0.0.0.0:8080".to_string()
88103
}
89104

105+
fn default_sp1_worker_address() -> String {
106+
"0.0.0.0:8081".to_string()
107+
}
108+
90109
fn default_concurrency_limit() -> usize {
91110
16
92111
}

host/src/server/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ pub mod api;
88

99
/// Starts the proverd server.
1010
pub async fn serve(state: ProverState) -> anyhow::Result<()> {
11+
#[cfg(feature = "sp1")]
12+
if let Some(orchestrator_addr) = state.opts.sp1_orchestrator_address.as_ref() {
13+
sp1_driver::serve(
14+
state.opts.sp1_worker_address.clone(),
15+
orchestrator_addr.clone(),
16+
)
17+
.await;
18+
}
19+
1120
let addr = SocketAddr::from_str(&state.opts.address)
1221
.map_err(|_| HostError::InvalidAddress(state.opts.address.clone()))?;
1322
let listener = TcpListener::bind(addr).await?;

lib/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ std = [
7171
sgx = []
7272
sp1 = []
7373
risc0 = []
74-
sp1-cycle-tracker = []
74+
sp1-cycle-tracker = []

provers/sp1/driver/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@ alloy-sol-types = { workspace = true }
1616
serde = { workspace = true, optional = true }
1717
serde_json = { workspace = true, optional = true }
1818
sp1-sdk = { workspace = true, optional = true }
19+
sp1-core = { workspace = true, optional = true }
1920
anyhow = { workspace = true, optional = true }
2021
once_cell = { workspace = true, optional = true }
2122
sha3 = { workspace = true, optional = true, default-features = false }
2223
tracing = { workspace = true, optional = true }
2324

24-
2525
[features]
2626
enable = [
2727
"serde",
2828
"serde_json",
2929
"raiko-lib",
3030
"sp1-sdk",
31+
"sp1-core",
3132
"anyhow",
3233
"alloy-primitives",
3334
"once_cell",

provers/sp1/driver/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use raiko_lib::{
44
prover::{to_proof, Proof, Prover, ProverConfig, ProverError, ProverResult},
55
};
66
use serde::{Deserialize, Serialize};
7+
pub use sp1_sdk::serve;
78
use sp1_sdk::{ProverClient, SP1Stdin};
89
use std::env;
910
use tracing::info as tracing_info;

provers/sp1/guest/elf/sp1-guest

-1.36 MB
Binary file not shown.

script/build.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,13 @@ if [ -z "$1" ] || [ "$1" == "sp1" ]; then
150150
cargo ${TOOLCHAIN_SP1} build ${FLAGS} --features sp1
151151
else
152152
if [ -z "${TEST}" ]; then
153+
if [ -n "$ORCHESTRATOR" ]; then
154+
export ARGS="--sp1-orchestrator-address $ORCHESTRATOR"
155+
echo "Running in worker mode with orchestrator address $ORCHESTRATOR"
156+
fi
157+
153158
echo "Running Sp1 prover"
154-
cargo ${TOOLCHAIN_SP1} run ${FLAGS} --features sp1
159+
cargo ${TOOLCHAIN_SP1} run ${FLAGS} --features sp1 -- ${ARGS}
155160
else
156161
echo "Running Sp1 tests"
157162
cargo ${TOOLCHAIN_SP1} test ${FLAGS} --lib sp1-driver --features sp1 -- run_unittest_elf

0 commit comments

Comments
 (0)