From e48c01ecc5c4bbea491289d19637c8ca57656532 Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Thu, 30 May 2024 23:53:49 -0700 Subject: [PATCH] feat: feature flag `alloy_sol_types` (#850) --- Cargo.lock | 1 - book/SUMMARY.md | 4 ++- book/developers/common-issues.md | 18 ++++++++++ sdk/Cargo.toml | 8 +++-- sdk/src/lib.rs | 34 +++++++++++++++---- sdk/src/{ => network}/auth.rs | 0 sdk/src/{ => network}/client.rs | 2 +- sdk/src/network/mod.rs | 3 ++ .../{provers/network.rs => network/prover.rs} | 4 +-- sdk/src/provers/mod.rs | 2 -- 10 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 book/developers/common-issues.md rename sdk/src/{ => network}/auth.rs (100%) rename sdk/src/{ => network}/client.rs (99%) create mode 100644 sdk/src/network/mod.rs rename sdk/src/{provers/network.rs => network/prover.rs} (98%) diff --git a/Cargo.lock b/Cargo.lock index b0a73531a..b75a8e566 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4896,7 +4896,6 @@ dependencies = [ name = "sp1-sdk" version = "0.1.0" dependencies = [ - "alloy-primitives", "alloy-sol-types", "anyhow", "async-trait", diff --git a/book/SUMMARY.md b/book/SUMMARY.md index 91624caa0..3728ed9b0 100644 --- a/book/SUMMARY.md +++ b/book/SUMMARY.md @@ -40,4 +40,6 @@ - [Recommended Settings](./developers/recommended-settings.md) -- [Building Plonk Bn254 Artifacts](./developers/building-plonk-artifacts.md) \ No newline at end of file +- [Building Plonk Bn254 Artifacts](./developers/building-plonk-artifacts.md) + +- [Common Issues](./developers/common-issues.md) \ No newline at end of file diff --git a/book/developers/common-issues.md b/book/developers/common-issues.md new file mode 100644 index 000000000..285f461a3 --- /dev/null +++ b/book/developers/common-issues.md @@ -0,0 +1,18 @@ +# Alloy Errors + +If you are using a library that depends on `alloy_sol_types`, and encounter an error like this: + +``` +perhaps two different versions of crate `alloy_sol_types` are being used? +``` + +This is likely due to two different versions of `alloy_sol_types` being used. To fix this, you can set `default-features` to `false` for the `sp1-sdk` dependency in your `Cargo.toml`. + +```toml +[dependencies] +sp1-sdk = { version = "0.1.0", default-features = false } +``` + +This will configure out the `network` feature which will remove the dependency on `alloy_sol_types` +and configure out the `NetworkProver`. + diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 95e2d6943..6f0e06ff4 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -29,8 +29,7 @@ tracing = "0.1.40" hex = "0.4.3" log = "0.4.21" axum = "=0.7.5" -alloy-primitives = "0.7.0" -alloy-sol-types = "0.7.0" +alloy-sol-types = { version = "0.7.0", optional = true } sha2 = "0.10.8" dirs = "5.0.1" tempfile = "3.10.1" @@ -41,8 +40,13 @@ strum_macros = "0.26.2" strum = "0.26.2" [features] +default = ["network"] + neon = ["sp1-core/neon"] plonk = ["sp1-prover/plonk"] +# TODO: Once alloy has a 1.* release, we can likely remove this feature flag, as there will be less +# dependency resolution issues. +network = ["dep:alloy-sol-types"] [build-dependencies] vergen = { version = "8", default-features = false, features = [ diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 7e4f2cb9f..a48ef5e24 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -10,17 +10,23 @@ pub mod proto { pub mod network; } pub mod artifacts; -pub mod auth; -pub mod client; +#[cfg(feature = "network")] +pub mod network; +#[cfg(feature = "network")] +pub use crate::network::prover::NetworkProver; + pub mod provers; pub mod utils { pub use sp1_core::utils::setup_logger; } +use cfg_if::cfg_if; use std::{env, fmt::Debug, fs::File, path::Path}; use anyhow::{Ok, Result}; -pub use provers::{LocalProver, MockProver, NetworkProver, Prover}; + +pub use provers::{LocalProver, MockProver, Prover}; + use serde::{de::DeserializeOwned, Deserialize, Serialize}; use sp1_core::{ runtime::ExecutionReport, @@ -86,8 +92,16 @@ impl ProverClient { "local" => Self { prover: Box::new(LocalProver::new()), }, - "network" => Self { - prover: Box::new(NetworkProver::new()), + "network" => { + cfg_if! { + if #[cfg(feature = "network")] { + Self { + prover: Box::new(NetworkProver::new()), + } + } else { + panic!("network feature is not enabled") + } + } }, _ => panic!( "invalid value for SP1_PROVER enviroment variable: expected 'local', 'mock', or 'network'" @@ -144,8 +158,14 @@ impl ProverClient { /// let client = ProverClient::network(); /// ``` pub fn network() -> Self { - Self { - prover: Box::new(NetworkProver::new()), + cfg_if! { + if #[cfg(feature = "network")] { + Self { + prover: Box::new(NetworkProver::new()), + } + } else { + panic!("network feature is not enabled") + } } } diff --git a/sdk/src/auth.rs b/sdk/src/network/auth.rs similarity index 100% rename from sdk/src/auth.rs rename to sdk/src/network/auth.rs diff --git a/sdk/src/client.rs b/sdk/src/network/client.rs similarity index 99% rename from sdk/src/client.rs rename to sdk/src/network/client.rs index 87403dbde..3a5e13ce6 100644 --- a/sdk/src/client.rs +++ b/sdk/src/network/client.rs @@ -1,7 +1,7 @@ use std::{env, time::Duration}; use crate::{ - auth::NetworkAuth, + network::auth::NetworkAuth, proto::network::{UnclaimProofRequest, UnclaimReason}, }; use anyhow::{Context, Ok, Result}; diff --git a/sdk/src/network/mod.rs b/sdk/src/network/mod.rs new file mode 100644 index 000000000..950aa1095 --- /dev/null +++ b/sdk/src/network/mod.rs @@ -0,0 +1,3 @@ +pub mod auth; +pub mod client; +pub mod prover; diff --git a/sdk/src/provers/network.rs b/sdk/src/network/prover.rs similarity index 98% rename from sdk/src/provers/network.rs rename to sdk/src/network/prover.rs index 34e5e6008..675c10696 100644 --- a/sdk/src/provers/network.rs +++ b/sdk/src/network/prover.rs @@ -2,7 +2,7 @@ use std::{env, time::Duration}; use crate::proto::network::ProofMode; use crate::{ - client::NetworkClient, + network::client::NetworkClient, proto::network::{ProofStatus, TransactionStatus}, Prover, }; @@ -13,7 +13,7 @@ use sp1_prover::utils::block_on; use sp1_prover::{SP1Prover, SP1Stdin}; use tokio::{runtime, time::sleep}; -use super::{LocalProver, ProverType}; +use crate::provers::{LocalProver, ProverType}; /// An implementation of [crate::ProverClient] that can generate proofs on a remote RPC server. pub struct NetworkProver { diff --git a/sdk/src/provers/mod.rs b/sdk/src/provers/mod.rs index 53c9e32fa..4c731c43d 100644 --- a/sdk/src/provers/mod.rs +++ b/sdk/src/provers/mod.rs @@ -1,12 +1,10 @@ mod local; mod mock; -mod network; use crate::{SP1CompressedProof, SP1PlonkBn254Proof, SP1Proof}; use anyhow::Result; pub use local::LocalProver; pub use mock::MockProver; -pub use network::NetworkProver; use sp1_core::stark::MachineVerificationError; use sp1_prover::CoreSC; use sp1_prover::SP1CoreProofData;