Skip to content

Commit

Permalink
First working version of SP1 Distributed Prover
Browse files Browse the repository at this point in the history
  • Loading branch information
Champii committed Jul 24, 2024
1 parent 36a5614 commit 0c4a1ea
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 18 deletions.
11 changes: 0 additions & 11 deletions Cargo.lock

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

12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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" }

2 changes: 1 addition & 1 deletion host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
19 changes: 19 additions & 0 deletions host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

#[arg(long, require_equals = true, default_value = "16")]
#[serde(default = "Opts::default_concurrency_limit")]
/// Limit the max number of in-flight requests
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions host/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
1 change: 0 additions & 1 deletion provers/sp1/driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion provers/sp1/driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Empty file modified provers/sp1/guest/elf/sp1-guest
100755 → 100644
Empty file.
7 changes: 6 additions & 1 deletion script/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0c4a1ea

Please sign in to comment.