Skip to content

Commit

Permalink
feat: feature flag alloy_sol_types (#850)
Browse files Browse the repository at this point in the history
  • Loading branch information
ratankaliani authored May 31, 2024
1 parent 8ef12a5 commit e48c01e
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 16 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

4 changes: 3 additions & 1 deletion book/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@

- [Recommended Settings](./developers/recommended-settings.md)

- [Building Plonk Bn254 Artifacts](./developers/building-plonk-artifacts.md)
- [Building Plonk Bn254 Artifacts](./developers/building-plonk-artifacts.md)

- [Common Issues](./developers/common-issues.md)
18 changes: 18 additions & 0 deletions book/developers/common-issues.md
Original file line number Diff line number Diff line change
@@ -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`.

8 changes: 6 additions & 2 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 = [
Expand Down
34 changes: 27 additions & 7 deletions sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'"
Expand Down Expand Up @@ -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")
}
}
}

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion sdk/src/client.rs → sdk/src/network/client.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
3 changes: 3 additions & 0 deletions sdk/src/network/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod auth;
pub mod client;
pub mod prover;
4 changes: 2 additions & 2 deletions sdk/src/provers/network.rs → sdk/src/network/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions sdk/src/provers/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit e48c01e

Please sign in to comment.