From 194b3653df87ba4097344931d881263e9441f53d Mon Sep 17 00:00:00 2001 From: mattstam Date: Thu, 30 May 2024 10:42:14 -0700 Subject: [PATCH] expose pub --- sdk/src/lib.rs | 38 ++++++++++++++++++++++++++++++++++++++ sdk/src/provers/mod.rs | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 38ae6183c..1a27f9081 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -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 { + self.prover.simulate(elf_bytes, stdin) + } } impl Default for ProverClient { @@ -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); + let mut stdin = SP1Stdin::new(); + stdin.write(&10usize); + let cycles = client.simulate(elf, &stdin).unwrap(); + } } diff --git a/sdk/src/provers/mod.rs b/sdk/src/provers/mod.rs index 79132b4bf..be0ce859a 100644 --- a/sdk/src/provers/mod.rs +++ b/sdk/src/provers/mod.rs @@ -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 { let program = Program::from(elf_bytes); let mut runtime = Runtime::new(program, SP1CoreOpts::default());