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(distributed_sp1): first working version of sp1 distributed prover #302

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
162 changes: 97 additions & 65 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 16 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,15 @@ 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" }

# Patch Plonky3 for Serialize and Deserialize of DuplexChallenger
[patch."https://github.com/Plonky3/Plonky3.git"]
p3-field = { git = "https://github.com/Champii/Plonky3.git", branch = "serde_patch" }
p3-challenger = { git = "https://github.com/Champii/Plonky3.git", branch = "serde_patch" }
p3-poseidon2 = { git = "https://github.com/Champii/Plonky3.git", branch = "serde_patch" }
p3-baby-bear = { git = "https://github.com/Champii/Plonky3.git", branch = "serde_patch" }
p3-symmetric = { git = "https://github.com/Champii/Plonky3.git", branch = "serde_patch" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be added to the taikoxyz org, or maybe a taikoxyz-patches special org to avoid pollution if across Raiko and Gwyneth we expect lots of long-term patches. cc @Brechtpd

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Could anybody fork Plonky3 so that I can make a PR for that too ? :)

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"]
Champii marked this conversation as resolved.
Show resolved Hide resolved
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)]
Champii marked this conversation as resolved.
Show resolved Hide resolved
/// 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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"0.0.0.0:8081".to_string()
// Placeholder address
"0.0.0.0:8081".to_string()

AFAIK in some cases 0.0.0.0 is/was use for broadcasting so I think it should be clarified it's a placeholder until we have a valid address.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the listening address of the worker socket, I always saw this format to indicate to listen on every interfaces. I'll do some more research but that's a sensible default in my opinion.

}

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_worker(
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
1 change: 1 addition & 0 deletions provers/sp1/driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use raiko_lib::{
prover::{IdStore, IdWrite, Proof, ProofKey, Prover, ProverConfig, ProverError, ProverResult},
};
use serde::{Deserialize, Serialize};
pub use sp1_sdk::serve_worker;
use sp1_sdk::{
network::client::NetworkClient,
proto::network::{ProofMode, ProofStatus, UnclaimReason},
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
Loading