Skip to content

Commit

Permalink
feat: add prover_type (#838)
Browse files Browse the repository at this point in the history
  • Loading branch information
ratankaliani authored May 30, 2024
2 parents 3cc3cc6 + d1ca91f commit 5f46fb0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
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
6 changes: 4 additions & 2 deletions sdk/src/provers/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use crate::{
SP1ProvingKey, SP1VerifyingKey,
};

use super::ProverType;

/// An implementation of [crate::ProverClient] that can generate end-to-end proofs locally.
pub struct LocalProver {
prover: SP1Prover,
Expand All @@ -21,8 +23,8 @@ impl LocalProver {
}

impl Prover for LocalProver {
fn id(&self) -> String {
"local".to_string()
fn id(&self) -> ProverType {
ProverType::Local
}

fn setup(&self, elf: &[u8]) -> (SP1ProvingKey, SP1VerifyingKey) {
Expand Down
6 changes: 4 additions & 2 deletions sdk/src/provers/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use sp1_prover::{
verify::verify_plonk_bn254_public_inputs, HashableKey, PlonkBn254Proof, SP1Prover, SP1Stdin,
};

use super::ProverType;

/// An implementation of [crate::ProverClient] that can generate mock proofs.
pub struct MockProver {
pub(crate) prover: SP1Prover,
Expand All @@ -23,8 +25,8 @@ impl MockProver {
}

impl Prover for MockProver {
fn id(&self) -> String {
"mock".to_string()
fn id(&self) -> ProverType {
ProverType::Mock
}

fn setup(&self, elf: &[u8]) -> (SP1ProvingKey, SP1VerifyingKey) {
Expand Down
11 changes: 10 additions & 1 deletion sdk/src/provers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@ use sp1_prover::SP1CoreProofData;
use sp1_prover::SP1Prover;
use sp1_prover::SP1ReduceProof;
use sp1_prover::{SP1ProvingKey, SP1Stdin, SP1VerifyingKey};
use strum_macros::EnumString;

/// The type of prover.
#[derive(Debug, PartialEq, EnumString)]
pub enum ProverType {
Local,
Mock,
Network,
}

/// An implementation of [crate::ProverClient].
pub trait Prover: Send + Sync {
fn id(&self) -> String;
fn id(&self) -> ProverType;

fn sp1_prover(&self) -> &SP1Prover;

Expand Down
6 changes: 3 additions & 3 deletions sdk/src/provers/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use sp1_prover::utils::block_on;
use sp1_prover::{SP1Prover, SP1Stdin};
use tokio::{runtime, time::sleep};

use super::LocalProver;
use super::{LocalProver, ProverType};

/// An implementation of [crate::ProverClient] that can generate proofs on a remote RPC server.
pub struct NetworkProver {
Expand Down Expand Up @@ -151,8 +151,8 @@ impl NetworkProver {
}

impl Prover for NetworkProver {
fn id(&self) -> String {
"remote".to_string()
fn id(&self) -> ProverType {
ProverType::Network
}

fn setup(&self, elf: &[u8]) -> (SP1ProvingKey, SP1VerifyingKey) {
Expand Down

0 comments on commit 5f46fb0

Please sign in to comment.