Skip to content

Commit

Permalink
feat: clean up NetworkProver environment variables (#1790)
Browse files Browse the repository at this point in the history
  • Loading branch information
leruaa authored Nov 20, 2024
1 parent 5e35d9c commit b478609
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 101 deletions.
35 changes: 24 additions & 11 deletions crates/perf/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::time::{Duration, Instant};
use std::{
env,
time::{Duration, Instant},
};

use clap::{command, Parser, ValueEnum};
use clap::{command, Parser};
use sp1_cuda::SP1CudaProver;
use sp1_prover::components::DefaultProverComponents;
use sp1_prover::HashableKey;
use sp1_prover::{components::DefaultProverComponents, ProverMode};
use sp1_sdk::{self, ProverClient, SP1Context, SP1Prover, SP1Stdin};
use sp1_stark::SP1ProverOpts;
use test_artifacts::VERIFY_PROOF_ELF;
Expand Down Expand Up @@ -34,13 +37,6 @@ struct PerfResult {
pub verify_wrap_duration: Duration,
}

#[derive(Debug, Clone, ValueEnum, PartialEq, Eq)]
enum ProverMode {
Cpu,
Cuda,
Network,
}

pub fn time_operation<T, F: FnOnce() -> T>(operation: F) -> (T, std::time::Duration) {
let start = Instant::now();
let result = operation();
Expand Down Expand Up @@ -180,7 +176,23 @@ fn main() {
println!("{:?}", result);
}
ProverMode::Network => {
let prover = ProverClient::network();
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().mode(ProverMode::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 prover = prover_builder.private_key(private_key).build();
let (_, _) = time_operation(|| prover.execute(&elf, stdin.clone()));

let (proof, _) =
Expand All @@ -192,5 +204,6 @@ fn main() {

let (_, _) = time_operation(|| prover.verify(&proof, &vk));
}
ProverMode::Mock => unreachable!(),
};
}
11 changes: 11 additions & 0 deletions crates/prover/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{fs::File, path::Path};

use anyhow::Result;
use clap::ValueEnum;
use p3_baby_bear::BabyBear;
use p3_bn254_fr::Bn254Fr;
use p3_commit::{Pcs, TwoAdicMultiplicativeCoset};
Expand Down Expand Up @@ -183,6 +184,16 @@ impl SP1Bn254ProofData {
}
}

#[derive(Debug, Default, Clone, ValueEnum, PartialEq, Eq)]
pub enum ProverMode {
#[default]
Cpu,
Cuda,
Network,
#[value(skip)]
Mock,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProofSystem {
Plonk,
Expand Down
Loading

0 comments on commit b478609

Please sign in to comment.