Skip to content

Commit 5352f64

Browse files
committed
Replace EnvProver with NetworkProver
Plus: set skip_simulation(true) to save ~1minute of proving time.
1 parent 5babc79 commit 5352f64

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

src/cli/mod.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ use crate::{
1616
utils,
1717
utils::{BoxedSP1Prover, Shared},
1818
};
19-
use bitcoin::{address::NetworkUnchecked, Address};
19+
use bitcoin::{Address, address::NetworkUnchecked};
2020
use charms_app_runner::AppRunner;
2121
use clap::{Args, CommandFactory, Parser, Subcommand};
22-
use clap_complete::{generate, Shell};
22+
use clap_complete::{Shell, generate};
2323
#[cfg(not(feature = "prover"))]
2424
use reqwest::Client;
2525
use serde::Serialize;
26-
use sp1_sdk::{install::try_install_circuit_artifacts, CpuProver, ProverClient};
26+
use sp1_sdk::{CpuProver, NetworkProver, ProverClient, install::try_install_circuit_artifacts};
2727
use std::{io, net::IpAddr, path::PathBuf, str::FromStr, sync::Arc};
2828
use utils::AsyncShared;
2929

@@ -414,14 +414,14 @@ fn spell_sp1_client(app_sp1_client: &Arc<Shared<BoxedSP1Prover>>) -> Arc<Shared<
414414
let name = std::env::var("SPELL_SP1_PROVER").unwrap_or_default();
415415
match name.as_str() {
416416
"app" => app_sp1_client.clone(),
417-
"env" | "" => Arc::new(Shared::new(sp1_env_client)),
418-
_ => unreachable!("Only 'app' or 'env' are supported as SPELL_SP1_PROVER values"),
417+
"network" => Arc::new(Shared::new(sp1_network_client)),
418+
_ => unreachable!("Only 'app' or 'network' are supported as SPELL_SP1_PROVER values"),
419419
}
420420
}
421421

422422
#[tracing::instrument(level = "info")]
423423
#[cfg(feature = "prover")]
424-
fn charms_sp1_cuda_client() -> utils::sp1::CudaProver {
424+
fn charms_sp1_cuda_prover() -> utils::sp1::CudaProver {
425425
utils::sp1::CudaProver::new(
426426
sp1_prover::SP1Prover::new(),
427427
SP1CudaProver::new(gpu_service_url()).unwrap(),
@@ -434,13 +434,18 @@ fn gpu_service_url() -> String {
434434
}
435435

436436
#[tracing::instrument(level = "info")]
437-
pub fn sp1_cpu_client() -> CpuProver {
437+
pub fn sp1_cpu_prover() -> CpuProver {
438438
ProverClient::builder().cpu().build()
439439
}
440440

441-
#[tracing::instrument(level = "debug")]
442-
fn sp1_env_client() -> BoxedSP1Prover {
443-
sp1_named_env_client("env")
441+
#[tracing::instrument(level = "info")]
442+
pub fn sp1_network_prover() -> NetworkProver {
443+
ProverClient::builder().network().build()
444+
}
445+
446+
#[tracing::instrument(level = "info")]
447+
pub fn sp1_network_client() -> BoxedSP1Prover {
448+
sp1_named_env_client("network")
444449
}
445450

446451
#[tracing::instrument(level = "debug")]
@@ -452,9 +457,10 @@ fn sp1_named_env_client(name: &str) -> BoxedSP1Prover {
452457
};
453458
match name {
454459
#[cfg(feature = "prover")]
455-
"cuda" => Box::new(charms_sp1_cuda_client()),
456-
"cpu" => Box::new(sp1_cpu_client()),
457-
_ => Box::new(ProverClient::from_env()),
460+
"cuda" => Box::new(charms_sp1_cuda_prover()),
461+
"cpu" => Box::new(sp1_cpu_prover()),
462+
"network" => Box::new(sp1_network_prover()),
463+
_ => unimplemented!("only 'cuda', 'cpu' and 'network' are supported as prover values"),
458464
}
459465
}
460466

src/utils/prover.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use sp1_core_machine::io::SP1Stdin;
2-
use sp1_prover::{components::CpuProverComponents, SP1ProvingKey, SP1VerifyingKey};
3-
use sp1_sdk::{CpuProver, EnvProver, Prover, SP1ProofMode, SP1ProofWithPublicValues};
2+
use sp1_prover::{SP1ProvingKey, SP1VerifyingKey, components::CpuProverComponents};
3+
use sp1_sdk::{
4+
CpuProver, NetworkProver, Prover, SP1ProofMode, SP1ProofWithPublicValues,
5+
network::FulfillmentStrategy,
6+
};
47

58
pub trait CharmsSP1Prover: Send + Sync {
69
fn setup(&self, elf: &[u8]) -> (SP1ProvingKey, SP1VerifyingKey);
@@ -29,7 +32,7 @@ impl CharmsSP1Prover for CpuProver {
2932
}
3033
}
3134

32-
impl CharmsSP1Prover for EnvProver {
35+
impl CharmsSP1Prover for NetworkProver {
3336
fn setup(&self, elf: &[u8]) -> (SP1ProvingKey, SP1VerifyingKey) {
3437
let (pk, _, _, vk) = <Self as Prover<CpuProverComponents>>::inner(self).setup(elf);
3538
(pk, vk)
@@ -41,7 +44,13 @@ impl CharmsSP1Prover for EnvProver {
4144
stdin: &SP1Stdin,
4245
kind: SP1ProofMode,
4346
) -> anyhow::Result<(SP1ProofWithPublicValues, u64)> {
44-
let proof = self.prove(pk, stdin).mode(kind).run()?;
47+
let proof = self
48+
.prove(pk, stdin)
49+
.mode(kind)
50+
.cycle_limit(32000000)
51+
.skip_simulation(true)
52+
.strategy(FulfillmentStrategy::Hosted)
53+
.run()?;
4554
Ok((proof, 0))
4655
}
4756
}

0 commit comments

Comments
 (0)