-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
351 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
use crate::{ | ||
local::{LocalProver, LocalProverBuilder}, | ||
prover::Prover, | ||
}; | ||
|
||
#[cfg(feature = "network-v2")] | ||
use crate::network_v2::{NetworkProver, NetworkProverBuilder}; | ||
|
||
use super::ProverClient; | ||
|
||
pub struct None; | ||
|
||
pub struct ProverClientBuilder<T> { | ||
inner_builder: T, | ||
} | ||
|
||
|
||
impl Default for ProverClientBuilder<None> { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl ProverClientBuilder<None> { | ||
pub fn new() -> Self { | ||
ProverClientBuilder { inner_builder: None } | ||
} | ||
|
||
pub fn local(self) -> ProverClientBuilder<LocalProverBuilder> { | ||
ProverClientBuilder { inner_builder: LocalProver::builder() } | ||
} | ||
|
||
#[cfg(feature = "network-v2")] | ||
pub fn network(self) -> ProverClientBuilder<NetworkProverBuilder> { | ||
ProverClientBuilder { inner_builder: NetworkProver::builder() } | ||
} | ||
|
||
pub fn from_env(self) -> ProverClient { | ||
ProverClient::create_from_env() | ||
} | ||
} | ||
|
||
impl<T: BuildableProver> ProverClientBuilder<T> { | ||
pub fn build(self) -> ProverClient { | ||
ProverClient { inner: self.inner_builder.build_prover() } | ||
} | ||
|
||
pub fn with_default_timeout(mut self, timeout: u64) -> Self { | ||
self.inner_builder = self.inner_builder.with_default_timeout(timeout); | ||
self | ||
} | ||
|
||
pub fn with_default_cycle_limit(mut self, cycle_limit: u64) -> Self { | ||
self.inner_builder = self.inner_builder.with_default_cycle_limit(cycle_limit); | ||
self | ||
} | ||
} | ||
|
||
#[cfg(feature = "network-v2")] | ||
impl ProverClientBuilder<NetworkProverBuilder> { | ||
pub fn rpc_url(mut self, url: String) -> Self { | ||
self.inner_builder = self.inner_builder.rpc_url(url); | ||
self | ||
} | ||
|
||
pub fn private_key(mut self, key: String) -> Self { | ||
self.inner_builder = self.inner_builder.private_key(key); | ||
self | ||
} | ||
} | ||
|
||
pub trait BuildableProver: Sized { | ||
fn build_prover(self) -> Box<dyn Prover>; | ||
|
||
fn with_default_timeout(self, timeout: u64) -> Self; | ||
|
||
fn with_default_cycle_limit(self, cycle_limit: u64) -> Self; | ||
} | ||
|
||
impl BuildableProver for LocalProverBuilder { | ||
fn build_prover(self) -> Box<dyn Prover> { | ||
Box::new(self.build()) | ||
} | ||
|
||
fn with_default_timeout(self, timeout: u64) -> Self { | ||
self.with_timeout(timeout) | ||
} | ||
|
||
fn with_default_cycle_limit(self, cycle_limit: u64) -> Self { | ||
self.with_cycle_limit(cycle_limit) | ||
} | ||
} | ||
|
||
#[cfg(feature = "network-v2")] | ||
impl BuildableProver for NetworkProverBuilder { | ||
fn build_prover(self) -> Box<dyn Prover> { | ||
Box::new(self.build()) | ||
} | ||
|
||
fn with_default_cycle_limit(self, cycle_limit: u64) -> Self { | ||
self.with_cycle_limit(cycle_limit) | ||
} | ||
|
||
fn with_default_timeout(self, timeout: u64) -> Self { | ||
self.with_timeout(timeout) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use crate::{ | ||
proof::SP1ProofWithPublicValues, | ||
prover::Prover, | ||
}; | ||
|
||
|
||
use anyhow::Result; | ||
use sp1_core_machine::io::SP1Stdin; | ||
use sp1_prover::SP1ProvingKey; | ||
use std::sync::Arc; | ||
use crate::Mode; | ||
use crate::ProofOpts; | ||
use std::future::{Future, IntoFuture}; | ||
use std::pin::Pin; | ||
|
||
pub struct DynProofRequest<'a> { | ||
prover: &'a dyn Prover, | ||
pk: &'a Arc<SP1ProvingKey>, | ||
stdin: SP1Stdin, | ||
opts: ProofOpts, | ||
} | ||
|
||
impl<'a> DynProofRequest<'a> { | ||
pub fn new( | ||
prover: &'a dyn Prover, | ||
pk: &'a Arc<SP1ProvingKey>, | ||
stdin: SP1Stdin, | ||
opts: ProofOpts, | ||
) -> Self { | ||
Self { prover, pk, stdin, opts } | ||
} | ||
|
||
pub fn core(mut self) -> Self { | ||
self.opts.mode = Mode::Core; | ||
self | ||
} | ||
|
||
pub fn compressed(mut self) -> Self { | ||
self.opts.mode = Mode::Compressed; | ||
self | ||
} | ||
|
||
pub fn plonk(mut self) -> Self { | ||
self.opts.mode = Mode::Plonk; | ||
self | ||
} | ||
|
||
pub fn groth16(mut self) -> Self { | ||
self.opts.mode = Mode::Groth16; | ||
self | ||
} | ||
|
||
pub fn timeout(mut self, timeout: u64) -> Self { | ||
self.opts.timeout = timeout; | ||
self | ||
} | ||
|
||
pub fn cycle_limit(mut self, cycle_limit: u64) -> Self { | ||
self.opts.cycle_limit = cycle_limit; | ||
self | ||
} | ||
|
||
#[cfg(feature = "blocking")] | ||
fn run(self) -> Result<SP1ProofWithPublicValues> { | ||
self.prover.prove_with_options_sync(&self.pk, self.stdin, self.opts) | ||
} | ||
} | ||
|
||
impl<'a> IntoFuture for DynProofRequest<'a> { | ||
type Output = Result<SP1ProofWithPublicValues>; | ||
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>; | ||
|
||
fn into_future(self) -> Self::IntoFuture { | ||
self.prover.prove_with_options(self.pk, self.stdin, self.opts) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.