Skip to content

Commit

Permalink
stuff compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstam committed Dec 11, 2024
1 parent 1dbb0d4 commit 360ffc0
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 10 deletions.
40 changes: 40 additions & 0 deletions crates/sdk/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
use crate::{
local::{LocalProver, LocalProverBuilder},
network::{NetworkProver, NetworkProverBuilder},
opts::ProofOpts,
proof::SP1ProofWithPublicValues,
prover::Prover,
};
use anyhow::Result;
use sp1_core_executor::ExecutionReport;
use sp1_core_machine::io::SP1Stdin;
use sp1_prover::{SP1ProvingKey, SP1VerifyingKey};
use std::env;

pub struct None;
Expand All @@ -24,6 +30,40 @@ impl ProverClient {
pub fn new() -> Self {
Self::builder().from_env()
}

pub async fn setup(&self, elf: &[u8]) -> (SP1ProvingKey, SP1VerifyingKey) {
self.inner.setup(elf).await
}

pub async fn execute(&self, elf: &[u8], stdin: SP1Stdin) -> Result<ExecutionReport> {
self.inner.execute(elf, stdin).await
}

pub async fn prove(
&self,
pk: &SP1ProvingKey,
stdin: &SP1Stdin,
) -> Result<SP1ProofWithPublicValues> {
let opts = ProofOpts::default();
self.inner.prove_with_options(pk, stdin, &opts).await
}

pub async fn prove_with_options(
&self,
pk: &SP1ProvingKey,
stdin: &SP1Stdin,
opts: &ProofOpts,
) -> Result<SP1ProofWithPublicValues> {
self.inner.prove_with_options(pk, stdin, opts).await
}

pub async fn verify(
&self,
proof: &SP1ProofWithPublicValues,
vk: &SP1VerifyingKey,
) -> Result<(), crate::provers::SP1VerificationError> {
self.inner.verify(proof, vk).await
}
}

impl ProverClientBuilder<None> {
Expand Down
7 changes: 7 additions & 0 deletions crates/sdk/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ pub struct ProofOpts {
pub timeout: u64,
pub cycle_limit: u64,
}

impl Default for ProofOpts {
fn default() -> Self {
// TODO better defaults
Self { mode: Mode::default(), timeout: 10000, cycle_limit: 100000000 }
}
}
7 changes: 7 additions & 0 deletions examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/fibonacci/script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ sp1-sdk = { workspace = true, features = ["network-v2"] }
hex = "0.4.3"
tokio = { version = "1.0", features = ["full", "macros"] }
futures = "0.3"
dotenv = "0.15"

[build-dependencies]
sp1-build = { workspace = true }
Expand Down
26 changes: 16 additions & 10 deletions examples/fibonacci/script/bin/network.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use sp1_sdk::network_v2::{Error, FulfillmentStrategy};
use sp1_sdk::{include_elf, utils, client::ProverClient, proof::SP1ProofWithPublicValues, SP1Stdin};
use std::time::Duration;
use dotenv::dotenv;

/// The ELF we want to execute inside the zkVM.
const ELF: &[u8] = include_elf!("fibonacci-program");
Expand All @@ -18,23 +19,28 @@ async fn main() {
let mut stdin = SP1Stdin::new();
stdin.write(&n);

dotenv().ok();

let rpc_url = std::env::var("PROVER_NETWORK_RPC").unwrap();
let private_key = std::env::var("SP1_PRIVATE_KEY").unwrap();

// Generate the proof, using the specified network configuration.
let client = ProverClient::builder()
.network()
.with_rpc_url("https://...".to_string())
.with_private_key("0x...".to_string())
.with_rpc_url(rpc_url)
.with_private_key(private_key)
.build();

// Generate the proving key and verifying key for the given program.
let (pk, vk) = client.setup(ELF).await.unwrap();
let (pk, vk) = client.setup(ELF).await;

// Generate the proof.
let proof_result = client
.prove(&pk, stdin)
.timeout(300)
.cycle_limit(1_000_000)
.skip_simulation(true)
.strategy(FulfillmentStrategy::Hosted)
.prove(&pk, &stdin)
// .timeout(300)
// .cycle_limit(1_000_000)
// .skip_simulation(true)
// .strategy(FulfillmentStrategy::Hosted)
.await;

// Example of handling potential errors.
Expand Down Expand Up @@ -81,15 +87,15 @@ async fn main() {
println!("b: {}", b);

// Verify proof and public values
client.verify(&proof, &vk).expect("verification failed");
// client.verify(&proof, &vk).expect("verification failed");

// Test a round trip of proof serialization and deserialization.
proof.save("proof-with-pis.bin").expect("saving proof failed");
let deserialized_proof =
SP1ProofWithPublicValues::load("proof-with-pis.bin").expect("loading proof failed");

// Verify the deserialized proof.
client.verify(&deserialized_proof, &vk).expect("verification failed");
// client.verify(&deserialized_proof, &vk).expect("verification failed");

println!("successfully generated and verified proof for the program!")
}

0 comments on commit 360ffc0

Please sign in to comment.