Skip to content

Commit c28e1b5

Browse files
committed
Merge branch 'dev' of github.com:succinctlabs/sp1 into dev
2 parents 2a51f3d + fb566da commit c28e1b5

File tree

3 files changed

+89
-15
lines changed

3 files changed

+89
-15
lines changed

crates/build/src/lib.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub use build::{execute_build_program, generate_elf_paths};
88
pub use command::TOOLCHAIN_NAME;
99

1010
use clap::{Parser, ValueEnum};
11-
use sp1_prover::{components::CpuProverComponents, HashableKey, SP1Prover};
11+
use sp1_prover::{components::CpuProverComponents, HashableKey, SP1Prover, SP1VerifyingKey};
1212

1313
const DEFAULT_DOCKER_TAG: &str = concat!("v", env!("CARGO_PKG_VERSION"));
1414
const BUILD_TARGET: &str = "riscv32im-succinct-zkvm-elf";
@@ -156,7 +156,7 @@ pub fn build_program_with_args(path: &str, args: BuildArgs) {
156156
///
157157
/// Note: If used in a script `build.rs`, this function should be called *after* [`build_program`]
158158
/// to returns the vkey corresponding to the latest program version which has just been compiled.
159-
pub fn vkey(path: &str, target_name: &str) -> String {
159+
pub fn verifying_key(path: &str, target_name: &str) -> SP1VerifyingKey {
160160
let program_dir = std::path::Path::new(path);
161161
let metadata_file = program_dir.join("Cargo.toml");
162162
let mut metadata_cmd = cargo_metadata::MetadataCommand::new();
@@ -171,6 +171,20 @@ pub fn vkey(path: &str, target_name: &str) -> String {
171171

172172
file.read_to_end(&mut elf).unwrap();
173173
let (_, _, _, vk) = prover.setup(&elf);
174+
vk
175+
}
176+
177+
/// Returns the verification key hash for the provided program.
178+
///
179+
/// # Arguments
180+
///
181+
/// * `path` - A string slice that holds the path to the program directory.
182+
/// * `target_name` - A string slice that holds the binary target.
183+
///
184+
/// Note: If used in a script `build.rs`, this function should be called *after* [`build_program`]
185+
/// to returns the vkey corresponding to the latest program version which has just been compiled.
186+
pub fn vkey(path: &str, target_name: &str) -> String {
187+
let vk = verifying_key(path, target_name);
174188
vk.bytes32()
175189
}
176190

crates/sdk/src/network/prove.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::time::Duration;
77
use alloy_primitives::{Address, B256};
88
use anyhow::Result;
99
use sp1_core_machine::io::SP1Stdin;
10-
use sp1_prover::SP1ProvingKey;
10+
use sp1_prover::SP1VerifyingKey;
1111

1212
use crate::{
1313
utils::{block_on, sp1_dump},
@@ -25,7 +25,8 @@ use std::{
2525
pub struct NetworkProveBuilder<'a> {
2626
pub(crate) prover: &'a NetworkProver,
2727
pub(crate) mode: SP1ProofMode,
28-
pub(crate) pk: &'a SP1ProvingKey,
28+
pub(crate) vk: &'a SP1VerifyingKey,
29+
pub(crate) elf: &'a [u8],
2930
pub(crate) stdin: SP1Stdin,
3031
pub(crate) timeout: Option<Duration>,
3132
pub(crate) strategy: FulfillmentStrategy,
@@ -590,7 +591,8 @@ impl NetworkProveBuilder<'_> {
590591
pub async fn request_async(self) -> Result<B256> {
591592
self.prover
592593
.request_proof_impl(
593-
self.pk,
594+
self.vk,
595+
self.elf,
594596
&self.stdin,
595597
self.mode,
596598
self.strategy,
@@ -659,11 +661,12 @@ impl NetworkProveBuilder<'_> {
659661
self.skip_simulation = matches!(val.to_lowercase().as_str(), "true" | "1");
660662
}
661663

662-
sp1_dump(&self.pk.elf, &self.stdin);
664+
sp1_dump(self.elf, &self.stdin);
663665

664666
self.prover
665667
.prove_impl(
666-
self.pk,
668+
self.vk,
669+
self.elf,
667670
&self.stdin,
668671
self.mode,
669672
self.strategy,

crates/sdk/src/network/prover.rs

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,60 @@ impl NetworkProver {
167167
NetworkProveBuilder {
168168
prover: self,
169169
mode: SP1ProofMode::Core,
170-
pk,
170+
vk: &pk.vk,
171+
elf: &pk.elf,
172+
stdin: stdin.clone(),
173+
timeout: None,
174+
strategy: self.default_fulfillment_strategy(),
175+
skip_simulation: false,
176+
cycle_limit: None,
177+
gas_limit: None,
178+
tee_2fa: false,
179+
min_auction_period: 1,
180+
whitelist: None,
181+
auctioneer: None,
182+
executor: None,
183+
verifier: None,
184+
treasury: None,
185+
max_price_per_pgu: None,
186+
auction_timeout: None,
187+
}
188+
}
189+
190+
/// A request to generate a proof for a given verifying key, ELF and input.
191+
///
192+
/// This allow to send proof requests to the network without having to run
193+
/// `setup()`. You just need the verifying key that is cheap to
194+
/// deserialize.
195+
///
196+
/// # Details
197+
/// * `vk`: The verifying key to use for the proof.
198+
/// * `elf`: The ELF to use for the proof.
199+
/// * `stdin`: The input to use for the proof.
200+
///
201+
/// # Example
202+
/// ```rust,no_run
203+
/// use sp1_sdk::{Prover, ProverClient, SP1Stdin};
204+
///
205+
/// let elf = &[1, 2, 3];
206+
/// let vk_bytes = &[4, 5, 6];
207+
/// let stdin = SP1Stdin::new();
208+
///
209+
/// let client = ProverClient::builder().network().build();
210+
/// let vk = bincode::deserialize(vk_bytes).unwrap();
211+
/// let proof = client.prove_from_vk(&vk, elf, &stdin).run();
212+
/// ```
213+
pub fn prove_from_vk<'a>(
214+
&'a self,
215+
vk: &'a SP1VerifyingKey,
216+
elf: &'a [u8],
217+
stdin: &'a SP1Stdin,
218+
) -> NetworkProveBuilder<'a> {
219+
NetworkProveBuilder {
220+
prover: self,
221+
mode: SP1ProofMode::Core,
222+
vk,
223+
elf,
171224
stdin: stdin.clone(),
172225
timeout: None,
173226
strategy: self.default_fulfillment_strategy(),
@@ -555,7 +608,8 @@ impl NetworkProver {
555608
#[allow(clippy::too_many_arguments)]
556609
pub(crate) async fn request_proof_impl(
557610
&self,
558-
pk: &SP1ProvingKey,
611+
vk: &SP1VerifyingKey,
612+
elf: &[u8],
559613
stdin: &SP1Stdin,
560614
mode: SP1ProofMode,
561615
strategy: FulfillmentStrategy,
@@ -571,9 +625,9 @@ impl NetworkProver {
571625
treasury: Option<Address>,
572626
max_price_per_pgu: Option<u64>,
573627
) -> Result<B256> {
574-
let vk_hash = self.register_program(&pk.vk, &pk.elf).await?;
628+
let vk_hash = self.register_program(vk, elf).await?;
575629
let (cycle_limit, gas_limit, public_values_hash) =
576-
self.get_execution_limits(cycle_limit, gas_limit, &pk.elf, stdin, skip_simulation)?;
630+
self.get_execution_limits(cycle_limit, gas_limit, elf, stdin, skip_simulation)?;
577631
let (auctioneer, executor, verifier, treasury, max_price_per_pgu, base_fee, domain) = self
578632
.get_auction_request_params(
579633
mode,
@@ -610,7 +664,8 @@ impl NetworkProver {
610664
#[allow(clippy::too_many_arguments)]
611665
pub(crate) async fn prove_impl(
612666
&self,
613-
pk: &SP1ProvingKey,
667+
vk: &SP1VerifyingKey,
668+
elf: &[u8],
614669
stdin: &SP1Stdin,
615670
mode: SP1ProofMode,
616671
strategy: FulfillmentStrategy,
@@ -636,7 +691,8 @@ impl NetworkProver {
636691
loop {
637692
let request_id = self
638693
.request_proof_impl(
639-
pk,
694+
vk,
695+
elf,
640696
stdin,
641697
mode,
642698
strategy,
@@ -660,7 +716,7 @@ impl NetworkProver {
660716
let request = super::tee::api::TEERequest::new(
661717
&self.client.signer,
662718
*request_id,
663-
pk.elf.clone(),
719+
elf.to_vec(),
664720
stdin.clone(),
665721
cycle_limit.unwrap_or_else(|| {
666722
super::utils::get_default_cycle_limit_for_mode(self.network_mode)
@@ -899,7 +955,8 @@ impl Prover<CpuProverComponents> for NetworkProver {
899955
mode: SP1ProofMode,
900956
) -> Result<SP1ProofWithPublicValues> {
901957
block_on(self.prove_impl(
902-
pk,
958+
&pk.vk,
959+
&pk.elf,
903960
stdin,
904961
mode,
905962
self.default_fulfillment_strategy(),

0 commit comments

Comments
 (0)