Skip to content

Commit

Permalink
expose pub
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstam committed May 30, 2024
1 parent 874ac9c commit 194b365
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,32 @@ impl ProverClient {
pub fn verify_plonk(&self, proof: &SP1PlonkBn254Proof, vkey: &SP1VerifyingKey) -> Result<()> {
self.prover.verify_plonk(proof, vkey)
}

/// Simulates the execution of a program with the given input, and return the number of cycles.
///
/// ### Examples
/// ```no_run
/// use sp1_sdk::{ProverClient, SP1Stdin};
///
/// // Load the program.
/// let elf = include_bytes!("../../examples/fibonacci/program/elf/riscv32im-succinct-zkvm-elf");
///
/// // Initialize the prover client.
/// let client = ProverClient::new();
///
/// // Setup the program.
/// let (pk, vk) = client.setup(elf);
///
/// // Setup the inputs.
/// let mut stdin = SP1Stdin::new();
/// stdin.write(&10usize);
///
/// // Simulate the execution of the program.
/// let cycles = client.simulate(elf, &stdin).unwrap();
/// ```
pub fn simulate(&self, elf_bytes: &[u8], stdin: &SP1Stdin) -> Result<u64> {
self.prover.simulate(elf_bytes, stdin)
}
}

impl Default for ProverClient {
Expand Down Expand Up @@ -450,4 +476,16 @@ mod tests {
let proof = client.prove_plonk(&pk, stdin).unwrap();
client.verify_plonk(&proof, &vk).unwrap();
}

#[test]
fn test_simulate() {
utils::setup_logger();
let client = ProverClient::local();
let elf =
include_bytes!("../../examples/fibonacci/program/elf/riscv32im-succinct-zkvm-elf");
let (pk, vk) = client.setup(elf);

Check failure on line 486 in sdk/src/lib.rs

View workflow job for this annotation

GitHub Actions / Formatting & Clippy

unused variable: `pk`

Check failure on line 486 in sdk/src/lib.rs

View workflow job for this annotation

GitHub Actions / Formatting & Clippy

unused variable: `vk`

Check warning on line 486 in sdk/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ARM)

unused variable: `pk`

Check warning on line 486 in sdk/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ARM)

unused variable: `vk`

Check warning on line 486 in sdk/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ARM)

unused variable: `pk`

Check warning on line 486 in sdk/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ARM)

unused variable: `vk`

Check warning on line 486 in sdk/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (x86-64)

unused variable: `pk`

Check warning on line 486 in sdk/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (x86-64)

unused variable: `vk`

Check warning on line 486 in sdk/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (x86-64)

unused variable: `pk`

Check warning on line 486 in sdk/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (x86-64)

unused variable: `vk`
let mut stdin = SP1Stdin::new();
stdin.write(&10usize);
let cycles = client.simulate(elf, &stdin).unwrap();

Check failure on line 489 in sdk/src/lib.rs

View workflow job for this annotation

GitHub Actions / Formatting & Clippy

unused variable: `cycles`

Check warning on line 489 in sdk/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ARM)

unused variable: `cycles`

Check warning on line 489 in sdk/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ARM)

unused variable: `cycles`

Check warning on line 489 in sdk/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (x86-64)

unused variable: `cycles`

Check warning on line 489 in sdk/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (x86-64)

unused variable: `cycles`
}
}
2 changes: 1 addition & 1 deletion sdk/src/provers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub trait Prover: Send + Sync {
Ok(())
}

// Simulate the execution of a program with the given input, and return the number of cycles.
// Simulates the execution of a program with the given input, and return the number of cycles.
fn simulate(&self, elf_bytes: &[u8], stdin: &SP1Stdin) -> Result<u64> {
let program = Program::from(elf_bytes);
let mut runtime = Runtime::new(program, SP1CoreOpts::default());
Expand Down

0 comments on commit 194b365

Please sign in to comment.