Skip to content

Commit

Permalink
prover type
Browse files Browse the repository at this point in the history
  • Loading branch information
ratankaliani committed May 30, 2024
1 parent 3cc3cc6 commit 712f765
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ tempfile = "3.10.1"
num-bigint = "0.4.5"
cfg-if = "1.0"
ethers = { version = "2", default-features = false }
strum_macros = "0.26.2"
strum = "0.26.2"

[features]
neon = ["sp1-core/neon"]
Expand Down
29 changes: 28 additions & 1 deletion sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ pub mod utils {
pub use sp1_core::utils::setup_logger;
}

use std::{env, fmt::Debug, fs::File, path::Path};
use std::{
any::{Any, TypeId},
env,
fmt::Debug,
fs::File,
path::Path,
};

use anyhow::{Ok, Result};
pub use provers::{LocalProver, MockProver, NetworkProver, Prover};
Expand All @@ -29,13 +35,21 @@ pub use sp1_prover::{
CoreSC, HashableKey, InnerSC, OuterSC, PlonkBn254Proof, SP1Prover, SP1ProvingKey,
SP1PublicValues, SP1Stdin, SP1VerifyingKey,
};
use strum_macros::EnumString;

/// A client for interacting with SP1.
pub struct ProverClient {
/// The underlying prover implementation.
pub prover: Box<dyn Prover>,
}

#[derive(Debug, PartialEq, EnumString)]
pub enum ProverType {
Local,
Mock,
Network,
}

/// A proof generated with SP1.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(bound(serialize = "P: Serialize + Debug + Clone"))]
Expand Down Expand Up @@ -147,6 +161,19 @@ impl ProverClient {
}
}

pub fn prover_type(&self) -> ProverType {
let prover_type_id = (*self.prover).type_id();
if prover_type_id == TypeId::of::<LocalProver>() {
ProverType::Local
} else if prover_type_id == TypeId::of::<MockProver>() {
ProverType::Mock
} else if prover_type_id == TypeId::of::<NetworkProver>() {
ProverType::Network
} else {
panic!("invalid prover type")
}
}

/// Executes the given program on the given input (without generating a proof).
///
/// Returns the public values of the program after it has been executed.
Expand Down

0 comments on commit 712f765

Please sign in to comment.