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 all commits
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
1,091 changes: 616 additions & 475 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 = "dd032eb23949828d244d1ad1f1569aa78155837c" }
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git", rev = "dd032eb23949828d244d1ad1f1569aa78155837c" }
sp1-helper = { git = "https://github.com/succinctlabs/sp1.git", rev = "dd032eb23949828d244d1ad1f1569aa78155837c" }
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 use the v1.0.1 tag instead of the commit hash, it would be easier for future maintenance as people won't try to hunt "what is the specific feature we depend on that was added in that commit?"

image

Copy link
Author

Choose a reason for hiding this comment

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

I'm waiting for taikoxyz/sp1#1 to be merged in the taiko branch and I'll use that particular revision as a source instead, as the tag v1.0.1 will be obsolete. Should we add our own versioning system on top of sp1's and refer to that ?

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe v1.0.1-taiko-1, you're the SP1 maintainer now ;). cc @smtmfft @Brechtpd @petarvujovic98



# 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
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 ? :)


# 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"]
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
4 changes: 2 additions & 2 deletions lib/src/protocol_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl ProtocolInstance {
.expect("no blob commitment");
let versioned_hash =
commitment_to_version_hash(&commitment.clone().try_into().unwrap());
match get_blob_proof_type(proof_type, input.taiko.blob_proof_type.clone()) {
/* match get_blob_proof_type(proof_type, input.taiko.blob_proof_type.clone()) {
crate::input::BlobProofType::ProofOfEquivalence => {
let points =
eip4844::proof_of_equivalence(&input.taiko.tx_data, &versioned_hash)?;
Expand All @@ -54,7 +54,7 @@ impl ProtocolInstance {
commitment == &eip4844::calc_kzg_proof_commitment(&input.taiko.tx_data)?
);
}
};
}; */
versioned_hash
} else {
TxHash::from(keccak(input.taiko.tx_data.as_slice()))
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
12 changes: 7 additions & 5 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 Expand Up @@ -50,8 +51,9 @@ impl Prover for Sp1Prover {
let local = true;
let proof = match local {
true => {
let proof = client
.prove(&pk, stdin)
let prove_action = client.prove(&pk, stdin);
let proof = prove_action
.run()
.map_err(|_| ProverError::GuestError("Sp1: proving failed".to_owned()))?;
Ok::<_, ProverError>(proof)
}
Expand Down Expand Up @@ -113,9 +115,9 @@ impl Prover for Sp1Prover {
}?;

// Verify proof.
client
.verify(&proof, &vk)
.map_err(|_| ProverError::GuestError("Sp1: verification failed".to_owned()))?;
client.verify(&proof, &vk).map_err(|e| {
ProverError::GuestError(format!("Sp1: verification failed: {:#?}", e).to_owned())
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
ProverError::GuestError(format!("Sp1: verification failed: {:#?}", e).to_owned())
ProverError::GuestError(format!("Sp1: verification failed: {e:#?}").to_owned())

})?;

// Save the proof.
let proof_dir =
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