Skip to content

Commit

Permalink
make perf crate work
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstam committed Dec 12, 2024
1 parent 6f90556 commit 13dc1d5
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 31 deletions.
2 changes: 1 addition & 1 deletion crates/cli/src/commands/vkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl VkeyCmd {
file.read_to_end(&mut elf)?;

// Get the verification key
let prover = ProverClient::new();
let prover = ProverClient::builder().local().build();
let pk = rt.block_on(prover.setup(Arc::from(&elf[..])));

// Print the verification key hash
Expand Down
2 changes: 1 addition & 1 deletion crates/perf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ categories = { workspace = true }
[dependencies]
sp1-prover = { workspace = true }
sp1-core-executor = { workspace = true, features = ["programs"] }
sp1-sdk = { workspace = true }
sp1-sdk = { workspace = true, features = ["blocking"] }
p3-baby-bear = { workspace = true }
sp1-stark = { workspace = true }
sp1-cuda = { workspace = true }
Expand Down
16 changes: 8 additions & 8 deletions crates/perf/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{
env,
sync::Arc,
time::{Duration, Instant},
};

Expand Down Expand Up @@ -179,30 +180,29 @@ fn main() {
let private_key = env::var("SP1_PRIVATE_KEY")
.expect("SP1_PRIVATE_KEY must be set for remote proving");
let rpc_url = env::var("PROVER_NETWORK_RPC").ok();
let skip_simulation =
env::var("SKIP_SIMULATION").map(|val| val == "true").unwrap_or_default();

let mut prover_builder = ProverClient::builder().network();

if let Some(rpc_url) = rpc_url {
prover_builder = prover_builder.rpc_url(rpc_url);
}

if skip_simulation {
prover_builder = prover_builder.skip_simulation();
}
let pk = Arc::new(pk);
let vk = Arc::new(vk);

let prover = prover_builder.private_key(private_key).build();
let (_, _) = time_operation(|| prover.execute(&elf, stdin.clone()));
let (_, _) = time_operation(|| prover.execute(Arc::from(&elf[..]), stdin.clone()));

let (proof, _) =
time_operation(|| prover.prove(&pk, stdin.clone()).groth16().run().unwrap());
let proof = Arc::new(proof);

let (_, _) = time_operation(|| prover.verify(&proof, &vk));
let (_, _) = time_operation(|| prover.verify(proof, vk.clone()));

let (proof, _) = time_operation(|| prover.prove(&pk, stdin).plonk().run().unwrap());
let proof = Arc::new(proof);

let (_, _) = time_operation(|| prover.verify(&proof, &vk));
let (_, _) = time_operation(|| prover.verify(proof, vk));
}
ProverMode::Mock => unreachable!(),
};
Expand Down
1 change: 1 addition & 0 deletions crates/sdk/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct ProverClient {
inner: Box<dyn Prover>,
}

#[allow(clippy::new_without_default)]
impl ProverClient {
pub fn builder() -> ProverClientBuilder<None> {
ProverClientBuilder::new()
Expand Down
13 changes: 4 additions & 9 deletions crates/sdk/src/client/request.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
use crate::{
proof::SP1ProofWithPublicValues,
prover::Prover,
};

use crate::{proof::SP1ProofWithPublicValues, prover::Prover};

use crate::Mode;
use crate::ProofOpts;
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;
use std::sync::Arc;

pub struct DynProofRequest<'a> {
prover: &'a dyn Prover,
Expand Down Expand Up @@ -74,4 +70,3 @@ impl<'a> IntoFuture for DynProofRequest<'a> {
self.prover.prove_with_options(self.pk, self.stdin, self.opts)
}
}

4 changes: 2 additions & 2 deletions crates/sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ pub use crate::network_v2::NetworkProver;

#[cfg(feature = "network-v2")]
#[path = "network-v2/mod.rs"]
pub mod network_v2;/// The default timeout seconds for a proof request to be generated (4 hours).
pub mod network_v2;
/// 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 struct ProofOpts {
pub mode: Mode,
pub timeout: u64,
Expand Down
1 change: 0 additions & 1 deletion crates/sdk/src/local/mock.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![allow(unused_variables)]


// /// An implementation of [crate::ProverClient] that can generate mock proofs.
// pub struct MockProver {
// pub(crate) prover: SP1Prover,
Expand Down
2 changes: 1 addition & 1 deletion crates/sdk/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use sp1_core_machine::io::SP1Stdin;
use sp1_primitives::io::SP1PublicValues;
use sp1_prover::{SP1ProvingKey, SP1VerifyingKey};

use crate::{ProofOpts, proof::SP1ProofWithPublicValues, SP1VerificationError};
use crate::{proof::SP1ProofWithPublicValues, ProofOpts, SP1VerificationError};

#[async_trait]
pub trait Prover: Sync {
Expand Down
10 changes: 2 additions & 8 deletions examples/fibonacci/script/bin/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,9 @@ async fn main() {
let private_key = std::env::var("SP1_PRIVATE_KEY").unwrap();


// let client = ProverClient::builder().local().build();

// Or use old env var behavior

let client = ProverClient::builder()
.from_env();

// let client = ProverClient::new();

// Generate the proof, using the specified network configuration.
let client = ProverClient::builder()
.network()
Expand All @@ -50,10 +44,10 @@ async fn main() {
let proof_result = client
.prove(&pk, stdin)
.compressed()
.timeout(10000)
.timeout(10)
.cycle_limit(20_000)
.await;


// Example of handling potential errors.
let mut proof = match proof_result {
Ok(proof) => proof,
Expand Down

0 comments on commit 13dc1d5

Please sign in to comment.