-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
cycle-tracking
example with multiple binaries (#1529)
- Loading branch information
1 parent
14567af
commit 8e82b81
Showing
10 changed files
with
72 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
use sp1_build::build_program; | ||
use sp1_build::{build_program_with_args, BuildArgs}; | ||
|
||
fn main() { | ||
build_program("../program") | ||
build_program_with_args("../program", BuildArgs { | ||
binary: "normal".to_string(), | ||
..Default::default() | ||
}); | ||
build_program_with_args("../program", BuildArgs { | ||
binary: "report".to_string(), | ||
..Default::default() | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,21 @@ | ||
use sp1_sdk::{utils, ProverClient, SP1ProofWithPublicValues, SP1Stdin}; | ||
use sp1_sdk::{utils, ProverClient, SP1Stdin}; | ||
|
||
/// The ELF we want to execute inside the zkVM. | ||
const ELF: &[u8] = include_bytes!("../../program/elf/riscv32im-succinct-zkvm-elf"); | ||
const REPORT_ELF: &[u8] = include_bytes!("../../program/elf/report"); | ||
const NORMAL_ELF: &[u8] = include_bytes!("../../program/elf/normal"); | ||
|
||
fn main() { | ||
// Setup a tracer for logging. | ||
utils::setup_logger(); | ||
|
||
// Create an input stream. | ||
let stdin = SP1Stdin::new(); | ||
|
||
// Generate the proof for the given program. | ||
// Execute the normal program. | ||
let client = ProverClient::new(); | ||
let (pk, vk) = client.setup(ELF); | ||
let proof = client.prove(&pk, stdin).run().expect("proving failed"); | ||
|
||
// Verify proof. | ||
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"); | ||
let (_, _) = client.execute(NORMAL_ELF, SP1Stdin::new()).run().expect("proving failed"); | ||
|
||
// Verify the deserialized proof. | ||
client | ||
.verify(&deserialized_proof, &vk) | ||
.expect("verification failed"); | ||
// Execute the report program. | ||
let (_, report) = client.execute(REPORT_ELF, SP1Stdin::new()).run().expect("proving failed"); | ||
|
||
println!("successfully generated and verified proof for the program!") | ||
// Get the "setup" cycle count from the report program. | ||
let setup_cycles = report.cycle_tracker.get("setup").unwrap(); | ||
println!("Using cycle-tracker-report saves the number of cycles to the cycle-tracker mapping in the report.\nHere's the number of cycles used by the setup: {}", setup_cycles); | ||
} |