diff --git a/crates/sdk/src/client.rs b/crates/sdk/src/client.rs index 8f4669708..d6439c1d0 100644 --- a/crates/sdk/src/client.rs +++ b/crates/sdk/src/client.rs @@ -7,8 +7,9 @@ use crate::{ prover::Prover, }; use anyhow::Result; -use sp1_core_executor::ExecutionReport; +use sp1_core_executor::{ExecutionError, ExecutionReport}; use sp1_core_machine::io::SP1Stdin; +use sp1_primitives::io::SP1PublicValues; use sp1_prover::{SP1ProvingKey, SP1VerifyingKey}; use std::env; @@ -39,15 +40,11 @@ impl ProverClient { .unwrap_or_else(|_| DEFAULT_PROVER_NETWORK_RPC.to_string()); let private_key = env::var("SP1_PRIVATE_KEY").unwrap_or_default(); - let network_prover = NetworkProver::builder() - .with_rpc_url(rpc_url) - .with_private_key(private_key) - .build(); - + let network_prover = NetworkProver::new(rpc_url, private_key); ProverClient { inner: Box::new(network_prover) } } _ => { - let local_prover = LocalProver::builder().build(); + let local_prover = LocalProver::new(); ProverClient { inner: Box::new(local_prover) } } } @@ -57,7 +54,11 @@ impl ProverClient { self.inner.setup(elf).await } - pub async fn execute(&self, elf: &[u8], stdin: SP1Stdin) -> Result { + pub async fn execute( + &self, + elf: &[u8], + stdin: &SP1Stdin, + ) -> Result<(SP1PublicValues, ExecutionReport), ExecutionError> { self.inner.execute(elf, stdin).await } diff --git a/crates/sdk/src/lib.rs b/crates/sdk/src/lib.rs index 7fdbb171e..685bfdd5b 100644 --- a/crates/sdk/src/lib.rs +++ b/crates/sdk/src/lib.rs @@ -31,7 +31,7 @@ pub mod utils { } #[cfg(any(feature = "network", feature = "network-v2"))] -use {std::future::Future, tokio::task::block_in_place}; +use std::future::Future; pub use sp1_build::include_elf; pub use sp1_core_executor::{ExecutionReport, HookEnv, SP1Context, SP1ContextBuilder}; @@ -50,8 +50,6 @@ pub use sp1_prover::{ pub fn block_on(fut: impl Future) -> T { // Handle case if we're already in an tokio runtime. - use std::future::Future; - use tokio::task::block_in_place; if let Ok(handle) = tokio::runtime::Handle::try_current() { block_in_place(|| handle.block_on(fut)) diff --git a/crates/sdk/src/local.rs b/crates/sdk/src/local.rs index cde5a5c08..b8419941e 100644 --- a/crates/sdk/src/local.rs +++ b/crates/sdk/src/local.rs @@ -3,20 +3,22 @@ use crate::opts::ProofOpts; use crate::proof::SP1ProofWithPublicValues; use crate::prover::Prover; use crate::provers::SP1VerificationError; -use crate::request::ProofRequest; +use crate::request::{ProofRequest, DEFAULT_TIMEOUT}; use crate::verify; use anyhow::Result; use async_trait::async_trait; -use sp1_core_executor::{ExecutionReport, SP1Context}; +use futures::executor; +use sp1_core_executor::{ExecutionError, ExecutionReport, SP1Context}; use sp1_core_machine::io::SP1Stdin; +use sp1_primitives::io::SP1PublicValues; use sp1_prover::components::DefaultProverComponents; use sp1_prover::{SP1Prover, SP1ProvingKey, SP1VerifyingKey, SP1_CIRCUIT_VERSION}; use std::future::{Future, IntoFuture}; use std::pin::Pin; pub struct LocalProver { - prover: SP1Prover, + pub prover: SP1Prover, } impl LocalProver { @@ -29,13 +31,11 @@ impl LocalProver { } } -pub struct LocalProverBuilder { - mode: Mode, -} +pub struct LocalProverBuilder {} impl LocalProverBuilder { pub fn new() -> Self { - Self { mode: Mode::default() } + Self {} } pub fn build(self) -> LocalProver { @@ -53,7 +53,7 @@ pub struct LocalProofRequest<'a> { impl<'a> LocalProofRequest<'a> { pub fn new(prover: &'a LocalProver, pk: &'a SP1ProvingKey, stdin: SP1Stdin) -> Self { - Self { prover, pk, stdin, timeout: 0, mode: Mode::default() } + Self { prover, pk, stdin, timeout: DEFAULT_TIMEOUT, mode: Mode::default() } } pub fn with_mode(mut self, mode: Mode) -> Self { @@ -83,9 +83,12 @@ impl Prover for LocalProver { self.prover.setup(elf) } - async fn execute(&self, elf: &[u8], stdin: SP1Stdin) -> Result { - let (_, report) = self.prover.execute(elf, &stdin, SP1Context::default())?; - Ok(report) + async fn execute( + &self, + elf: &[u8], + stdin: &SP1Stdin, + ) -> Result<(SP1PublicValues, ExecutionReport), ExecutionError> { + self.prover.execute(elf, stdin, SP1Context::default()) } async fn prove_with_options( @@ -106,7 +109,7 @@ impl Prover for LocalProver { opts: &ProofOpts, ) -> Result { let request = LocalProofRequest::new(self, pk, stdin.clone()).with_timeout(opts.timeout); - futures::executor::block_on(request.run()) + executor::block_on(request.run()) } async fn verify( @@ -136,6 +139,6 @@ impl<'a> IntoFuture for LocalProofRequest<'a> { #[cfg(feature = "blocking")] impl<'a> ProofRequest for LocalProofRequest<'a> { fn run(self) -> Result { - futures::executor::block_on(self.run()) + executor::block_on(self.run()) } } diff --git a/crates/sdk/src/network.rs b/crates/sdk/src/network.rs index dee4b940a..15aa3069e 100644 --- a/crates/sdk/src/network.rs +++ b/crates/sdk/src/network.rs @@ -1,8 +1,9 @@ use anyhow::Result; use async_trait::async_trait; use serde::de::DeserializeOwned; -use sp1_core_executor::{ExecutionReport, SP1Context}; +use sp1_core_executor::{ExecutionError, ExecutionReport, SP1Context}; use sp1_core_machine::io::SP1Stdin; +use sp1_primitives::io::SP1PublicValues; use sp1_prover::components::DefaultProverComponents; use sp1_prover::{SP1Prover, SP1ProvingKey, SP1VerifyingKey, SP1_CIRCUIT_VERSION}; use std::future::{Future, IntoFuture}; @@ -159,6 +160,7 @@ impl<'a> NetworkProofRequest<'a> { prover, pk, stdin, + // TODO fill in defaults version: SP1_CIRCUIT_VERSION.to_owned(), mode: Mode::default(), fulfillment_strategy: None, @@ -241,10 +243,12 @@ impl Prover for NetworkProver { async fn setup(&self, elf: &[u8]) -> (SP1ProvingKey, SP1VerifyingKey) { self.prover.setup(elf) } - - async fn execute(&self, elf: &[u8], stdin: SP1Stdin) -> Result { - let (_, report) = self.prover.execute(elf, &stdin, SP1Context::default())?; - Ok(report) + async fn execute( + &self, + elf: &[u8], + stdin: &SP1Stdin, + ) -> Result<(SP1PublicValues, ExecutionReport), ExecutionError> { + self.prover.execute(elf, stdin, SP1Context::default()) } async fn prove_with_options( diff --git a/crates/sdk/src/opts.rs b/crates/sdk/src/opts.rs index f9a32ff8b..e55bf8d3e 100644 --- a/crates/sdk/src/opts.rs +++ b/crates/sdk/src/opts.rs @@ -1,4 +1,7 @@ -use crate::mode::Mode; +use crate::{ + mode::Mode, + request::{DEFAULT_CYCLE_LIMIT, DEFAULT_TIMEOUT}, +}; pub struct ProofOpts { pub mode: Mode, @@ -8,7 +11,6 @@ pub struct ProofOpts { impl Default for ProofOpts { fn default() -> Self { - // TODO better defaults - Self { mode: Mode::default(), timeout: 10000, cycle_limit: 100000000 } + Self { mode: Mode::default(), timeout: DEFAULT_TIMEOUT, cycle_limit: DEFAULT_CYCLE_LIMIT } } } diff --git a/crates/sdk/src/prover.rs b/crates/sdk/src/prover.rs index 5554d422b..a7e3c54b6 100644 --- a/crates/sdk/src/prover.rs +++ b/crates/sdk/src/prover.rs @@ -1,7 +1,8 @@ use anyhow::Result; use async_trait::async_trait; -use sp1_core_executor::ExecutionReport; +use sp1_core_executor::{ExecutionError, ExecutionReport}; use sp1_core_machine::io::SP1Stdin; +use sp1_primitives::io::SP1PublicValues; use sp1_prover::{SP1ProvingKey, SP1VerifyingKey}; use crate::{opts::ProofOpts, proof::SP1ProofWithPublicValues, provers::SP1VerificationError}; @@ -10,7 +11,11 @@ use crate::{opts::ProofOpts, proof::SP1ProofWithPublicValues, provers::SP1Verifi pub trait Prover: Send + Sync { async fn setup(&self, elf: &[u8]) -> (SP1ProvingKey, SP1VerifyingKey); - async fn execute(&self, elf: &[u8], stdin: SP1Stdin) -> Result; + async fn execute( + &self, + elf: &[u8], + stdin: &SP1Stdin, + ) -> Result<(SP1PublicValues, ExecutionReport), ExecutionError>; async fn prove_with_options( &self, diff --git a/crates/sdk/src/request.rs b/crates/sdk/src/request.rs index 63e2709f4..54c49530d 100644 --- a/crates/sdk/src/request.rs +++ b/crates/sdk/src/request.rs @@ -8,6 +8,12 @@ use sp1_prover::SP1ProvingKey; use std::future::{Future, IntoFuture}; use std::pin::Pin; +/// The default timeout seconds for a proof request to be generated (4 hours). +pub const DEFAULT_TIMEOUT: u64 = 14400; + +/// The default cycle limit for a proof request. +pub const DEFAULT_CYCLE_LIMIT: u64 = 100_000_000; + pub trait ProofRequest { fn run( self, diff --git a/examples/fibonacci/script/bin/network.rs b/examples/fibonacci/script/bin/network.rs index 589715de4..6ccafe3ee 100644 --- a/examples/fibonacci/script/bin/network.rs +++ b/examples/fibonacci/script/bin/network.rs @@ -33,10 +33,10 @@ async fn main() { // Or use old env var behavior - let client = ProverClient::builder() - .from_env(); + // let client = ProverClient::builder() + // .from_env(); - // let client = ProverClient::new(); + let client = ProverClient::new(); // Generate the proving key and verifying key for the given program. let (pk, vk) = client.setup(ELF).await;