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(sdk): network-v2 #1607

Merged
merged 18 commits into from
Oct 8, 2024
1,167 changes: 1,123 additions & 44 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 23 additions & 1 deletion crates/sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords = { workspace = true }
categories = { workspace = true }

[dependencies]
prost = "0.13"
prost = { version = "0.13", optional = true }
serde = { version = "1.0.204", features = ["derive"] }
serde_json = "1.0.121"
twirp = { package = "twirp-rs", version = "0.13.0-succinct", optional = true }
Expand Down Expand Up @@ -55,6 +55,12 @@ sp1-stark = { workspace = true }
sp1-primitives = { workspace = true }
getrandom = { version = "0.2.15", features = ["custom", "js"] }
itertools = "0.13.0"
tonic = { version = "0.12", features = ["tls", "tls-roots"], optional = true }
alloy-signer = { version = "0.3.6", optional = true }
alloy-signer-local = { version = "0.3.6", optional = true }
alloy-primitives = { version = "0.8.3", optional = true }
aws-sdk-s3 = { version = "1.53.0", optional = true }
aws-config = { version = "1.5.7", optional = true }

[features]
default = ["network"]
Expand All @@ -63,13 +69,29 @@ native-gnark = ["sp1-prover/native-gnark"]
# TODO: Once alloy has a 1.* release, we can likely remove this feature flag, as there will be less
# dependency resolution issues.
network = [
"dep:prost",
"dep:alloy-sol-types",
"dep:tokio",
"dep:ethers",
"dep:reqwest",
"dep:twirp",
"dep:reqwest-middleware",
]
network-v2 = [
"dep:prost",
"dep:alloy-sol-types",
"dep:alloy-signer",
"dep:alloy-signer-local",
"dep:alloy-primitives",
"dep:tokio",
"dep:ethers",
"dep:reqwest",
"dep:twirp",
"dep:reqwest-middleware",
"dep:tonic",
"dep:aws-sdk-s3",
"dep:aws-config",
]
cuda = ["sp1-cuda"]

[build-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions crates/sdk/src/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::PathBuf;

use anyhow::{Context, Result};

#[cfg(feature = "network")]
#[cfg(any(feature = "network", feature = "network-v2"))]
use {
futures::StreamExt,
indicatif::{ProgressBar, ProgressStyle},
Expand Down Expand Up @@ -72,7 +72,7 @@ pub fn export_solidity_groth16_bn254_verifier(output_dir: impl Into<PathBuf>) ->
Ok(())
}

#[cfg(feature = "network")]
#[cfg(any(feature = "network", feature = "network-v2"))]
pub async fn download_file(
client: &Client,
url: &str,
Expand Down
8 changes: 4 additions & 4 deletions crates/sdk/src/install.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cfg_if::cfg_if;
use std::path::PathBuf;

#[cfg(feature = "network")]
#[cfg(any(feature = "network", feature = "network-v2"))]
use {
crate::block_on,
futures::StreamExt,
Expand Down Expand Up @@ -31,7 +31,7 @@ pub fn try_install_circuit_artifacts() -> PathBuf {
);
} else {
cfg_if! {
if #[cfg(feature = "network")] {
if #[cfg(any(feature = "network", feature = "network-v2"))] {
println!(
"[sp1] circuit artifacts for version {} do not exist at {}. downloading...",
SP1_CIRCUIT_VERSION,
Expand All @@ -48,7 +48,7 @@ pub fn try_install_circuit_artifacts() -> PathBuf {
///
/// This function will download the latest circuit artifacts from the S3 bucket and extract them
/// to the directory specified by [plonk_bn254_artifacts_dir()].
#[cfg(feature = "network")]
#[cfg(any(feature = "network", feature = "network-v2"))]
pub fn install_circuit_artifacts(build_dir: PathBuf) {
// Create the build directory.
std::fs::create_dir_all(&build_dir).expect("failed to create build directory");
Expand Down Expand Up @@ -77,7 +77,7 @@ pub fn install_circuit_artifacts(build_dir: PathBuf) {
}

/// Download the file with a progress bar that indicates the progress.
#[cfg(feature = "network")]
#[cfg(any(feature = "network", feature = "network-v2"))]
pub async fn download_file(
client: &Client,
url: &str,
Expand Down
32 changes: 20 additions & 12 deletions crates/sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
//! Visit the [Getting Started](https://succinctlabs.github.io/sp1/getting-started.html) section
//! in the official SP1 documentation for a quick start guide.

#[rustfmt::skip]
#[cfg(feature = "network")]
pub mod proto {
pub mod network;
}
pub mod action;
pub mod artifacts;
pub mod install;
#[cfg(feature = "network")]
pub mod network;
#[cfg(feature = "network-v2")]
#[path = "network-v2/mod.rs"]
pub mod network_v2;
#[cfg(feature = "network")]
pub use crate::network::prover::NetworkProver;
pub use crate::network::prover::NetworkProver as NetworkProverV1;
#[cfg(feature = "network-v2")]
pub use crate::network_v2::prover::NetworkProver as NetworkProverV2;
#[cfg(feature = "cuda")]
pub use crate::provers::CudaProver;

Expand All @@ -33,7 +33,7 @@ use sp1_prover::components::DefaultProverComponents;

use std::env;

#[cfg(feature = "network")]
#[cfg(any(feature = "network", feature = "network-v2"))]
use {std::future::Future, tokio::task::block_in_place};

pub use provers::{CpuProver, MockProver, Prover};
Expand Down Expand Up @@ -84,9 +84,13 @@ impl ProverClient {
},
"network" => {
cfg_if! {
if #[cfg(feature = "network")] {
if #[cfg(feature = "network-v2")] {
Self {
prover: Box::new(NetworkProverV2::new()),
}
} else if #[cfg(feature = "network")] {
Self {
prover: Box::new(NetworkProver::new()),
prover: Box::new(NetworkProverV1::new()),
}
} else {
panic!("network feature is not enabled")
Expand Down Expand Up @@ -145,9 +149,13 @@ impl ProverClient {
/// ```
pub fn network() -> Self {
cfg_if! {
if #[cfg(feature = "network")] {
if #[cfg(feature = "network-v2")] {
Self {
prover: Box::new(NetworkProverV2::new()),
}
} else if #[cfg(feature = "network")] {
Self {
prover: Box::new(NetworkProver::new()),
prover: Box::new(NetworkProverV1::new()),
}
} else {
panic!("network feature is not enabled")
Expand Down Expand Up @@ -277,7 +285,7 @@ impl Default for ProverClient {
///
/// If we're already in a tokio runtime, we'll block in place. Otherwise, we'll create a new
/// runtime.
#[cfg(feature = "network")]
#[cfg(any(feature = "network", feature = "network-v2"))]
pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
// Handle case if we're already in an tokio runtime.
if let Ok(handle) = tokio::runtime::Handle::try_current() {
Expand Down
Loading
Loading