diff --git a/Cargo.lock b/Cargo.lock index b5dfebcd..685093a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8237,7 +8237,6 @@ dependencies = [ [[package]] name = "sp1-core" version = "0.1.0" -source = "git+https://github.com/succinctlabs/sp1.git?branch=main#14eb569d41d24721ffbd407d6060e202482d659c" dependencies = [ "anyhow", "arrayref", @@ -8297,7 +8296,6 @@ dependencies = [ [[package]] name = "sp1-derive" version = "0.1.0" -source = "git+https://github.com/succinctlabs/sp1.git?branch=main#14eb569d41d24721ffbd407d6060e202482d659c" dependencies = [ "proc-macro2", "quote", @@ -8323,7 +8321,6 @@ dependencies = [ [[package]] name = "sp1-primitives" version = "0.1.0" -source = "git+https://github.com/succinctlabs/sp1.git?branch=main#14eb569d41d24721ffbd407d6060e202482d659c" dependencies = [ "itertools 0.13.0", "lazy_static", @@ -8336,7 +8333,6 @@ dependencies = [ [[package]] name = "sp1-prover" version = "0.1.0" -source = "git+https://github.com/succinctlabs/sp1.git?branch=main#14eb569d41d24721ffbd407d6060e202482d659c" dependencies = [ "anyhow", "backtrace", @@ -8381,7 +8377,6 @@ dependencies = [ [[package]] name = "sp1-recursion-circuit" version = "0.1.0" -source = "git+https://github.com/succinctlabs/sp1.git?branch=main#14eb569d41d24721ffbd407d6060e202482d659c" dependencies = [ "bincode", "itertools 0.13.0", @@ -8404,7 +8399,6 @@ dependencies = [ [[package]] name = "sp1-recursion-compiler" version = "0.1.0" -source = "git+https://github.com/succinctlabs/sp1.git?branch=main#14eb569d41d24721ffbd407d6060e202482d659c" dependencies = [ "backtrace", "itertools 0.13.0", @@ -8428,7 +8422,6 @@ dependencies = [ [[package]] name = "sp1-recursion-core" version = "0.1.0" -source = "git+https://github.com/succinctlabs/sp1.git?branch=main#14eb569d41d24721ffbd407d6060e202482d659c" dependencies = [ "arrayref", "backtrace", @@ -8462,7 +8455,6 @@ dependencies = [ [[package]] name = "sp1-recursion-derive" version = "0.1.0" -source = "git+https://github.com/succinctlabs/sp1.git?branch=main#14eb569d41d24721ffbd407d6060e202482d659c" dependencies = [ "proc-macro2", "quote", @@ -8472,7 +8464,6 @@ dependencies = [ [[package]] name = "sp1-recursion-gnark-ffi" version = "0.1.0" -source = "git+https://github.com/succinctlabs/sp1.git?branch=main#14eb569d41d24721ffbd407d6060e202482d659c" dependencies = [ "anyhow", "bincode", @@ -8497,7 +8488,6 @@ dependencies = [ [[package]] name = "sp1-recursion-program" version = "0.1.0" -source = "git+https://github.com/succinctlabs/sp1.git?branch=main#14eb569d41d24721ffbd407d6060e202482d659c" dependencies = [ "itertools 0.13.0", "p3-air", @@ -8524,7 +8514,6 @@ dependencies = [ [[package]] name = "sp1-sdk" version = "0.1.0" -source = "git+https://github.com/succinctlabs/sp1.git?branch=main#14eb569d41d24721ffbd407d6060e202482d659c" dependencies = [ "alloy-sol-types", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 4d31db36..2b199f06 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,9 +57,10 @@ risc0-build = { version = "1.0.1" } risc0-binfmt = { version = "1.0.1" } # SP1 -sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", branch = "main" } -sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git", branch = "main" } -sp1-helper = { git = "https://github.com/succinctlabs/sp1.git", branch = "main" } +sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", rev = "14eb569d41d24721ffbd407d6060e202482d659c" } +sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git", rev = "14eb569d41d24721ffbd407d6060e202482d659c" } +sp1-helper = { git = "https://github.com/succinctlabs/sp1.git", rev = "14eb569d41d24721ffbd407d6060e202482d659c" } + # alloy alloy-rlp = { version = "0.3.4", default-features = false } @@ -189,3 +190,8 @@ revm-primitives = { git = "https://github.com/taikoxyz/revm.git", branch = "v36- revm-precompile = { git = "https://github.com/taikoxyz/revm.git", branch = "v36-taiko" } secp256k1 = { git = "https://github.com/CeciliaZ030/rust-secp256k1", branch = "sp1-patch" } blst = { git = "https://github.com/CeciliaZ030/blst.git", branch = "v0.3.12-serialize" } + +# Patch Plonky3 for Serialize and Deserialize of DuplexChallenger +[patch."https://github.com/succinctlabs/sp1.git"] +sp1-sdk = { path = "../sp1/sdk" } + diff --git a/host/Cargo.toml b/host/Cargo.toml index 6222369e..2011a7ef 100644 --- a/host/Cargo.toml +++ b/host/Cargo.toml @@ -82,7 +82,7 @@ ethers-core = { workspace = true } [features] default = [] -sp1 = ["raiko-core/sp1"] +sp1 = ["raiko-core/sp1", "sp1-driver"] risc0 = ["raiko-core/risc0"] sgx = ["raiko-core/sgx"] diff --git a/host/src/lib.rs b/host/src/lib.rs index d46a4849..281ff8e9 100644 --- a/host/src/lib.rs +++ b/host/src/lib.rs @@ -35,6 +35,21 @@ pub struct Opts { /// [default: 0.0.0.0:8080] address: String, + #[arg(long, require_equals = true, default_value = "0.0.0.0:8081")] + #[serde(default = "Opts::default_sp1_worker_address")] + /// Distributed SP1 worker listening address + /// [default: 0.0.0.0:8081] + sp1_worker_address: String, + + #[arg(long, default_value = None)] + /// Distributed SP1 worker orchestrator address + /// + /// Setting this will enable the worker and restrict it to only accept requests from + /// this orchestrator + /// + /// [default: None] + sp1_orchestrator_address: Option, + #[arg(long, require_equals = true, default_value = "16")] #[serde(default = "Opts::default_concurrency_limit")] /// Limit the max number of in-flight requests @@ -88,6 +103,10 @@ impl Opts { "0.0.0.0:8080".to_string() } + fn default_sp1_worker_address() -> String { + "0.0.0.0:8081".to_string() + } + fn default_concurrency_limit() -> usize { 16 } diff --git a/host/src/server/mod.rs b/host/src/server/mod.rs index bec5e691..a8763aa5 100644 --- a/host/src/server/mod.rs +++ b/host/src/server/mod.rs @@ -8,6 +8,15 @@ pub mod api; /// Starts the proverd server. pub async fn serve(state: ProverState) -> anyhow::Result<()> { + #[cfg(feature = "sp1")] + if let Some(orchestrator_addr) = state.opts.sp1_orchestrator_address.as_ref() { + sp1_driver::serve( + state.opts.sp1_worker_address.clone(), + orchestrator_addr.clone(), + ) + .await; + } + let addr = SocketAddr::from_str(&state.opts.address) .map_err(|_| HostError::InvalidAddress(state.opts.address.clone()))?; let listener = TcpListener::bind(addr).await?; diff --git a/provers/sp1/driver/Cargo.toml b/provers/sp1/driver/Cargo.toml index 848bfcc4..ebcd9647 100644 --- a/provers/sp1/driver/Cargo.toml +++ b/provers/sp1/driver/Cargo.toml @@ -21,7 +21,6 @@ once_cell = { workspace = true, optional = true } sha3 = { workspace = true, optional = true, default-features = false } tracing = { workspace = true, optional = true } - [features] enable = [ "serde", diff --git a/provers/sp1/driver/src/lib.rs b/provers/sp1/driver/src/lib.rs index a8dc96f3..d4ee813e 100644 --- a/provers/sp1/driver/src/lib.rs +++ b/provers/sp1/driver/src/lib.rs @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize}; use sp1_sdk::{ network::client::NetworkClient, proto::network::{ProofMode, ProofStatus, UnclaimReason}, - ProverClient, SP1Stdin, + serve, ProverClient, SP1Stdin, }; use std::{env, thread::sleep, time::Duration}; use tracing::info as tracing_info; diff --git a/provers/sp1/guest/elf/sp1-guest b/provers/sp1/guest/elf/sp1-guest old mode 100755 new mode 100644 diff --git a/script/build.sh b/script/build.sh index 69eaafe5..4ecf0f93 100755 --- a/script/build.sh +++ b/script/build.sh @@ -150,8 +150,13 @@ if [ -z "$1" ] || [ "$1" == "sp1" ]; then cargo ${TOOLCHAIN_SP1} build ${FLAGS} --features sp1 else if [ -z "${TEST}" ]; then + if [ -n "$ORCHESTRATOR" ]; then + export ARGS="--sp1-orchestrator-address $ORCHESTRATOR" + echo "Running in worker mode with orchestrator address $ORCHESTRATOR" + fi + echo "Running Sp1 prover" - cargo ${TOOLCHAIN_SP1} run ${FLAGS} --features sp1 + cargo ${TOOLCHAIN_SP1} run ${FLAGS} --features sp1 -- ${ARGS} else echo "Running Sp1 tests" cargo ${TOOLCHAIN_SP1} test ${FLAGS} --lib sp1-driver --features sp1 -- run_unittest_elf