-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathmain.rs
More file actions
41 lines (32 loc) · 1.14 KB
/
main.rs
File metadata and controls
41 lines (32 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use sp1_sdk::{HashableKey, ProverClient, SP1Stdin};
/// The ELF (executable and linkable format) file for the Succinct RISC-V zkVM.
pub const FIBONACCI_ELF: &[u8] = include_bytes!("../../sp1_fibonacci.elf");
fn main() {
// Setup the logger.
sp1_sdk::utils::setup_logger();
// Setup the prover client.
let client = ProverClient::from_env();
// Setup the inputs.
let n = 500;
let mut stdin = SP1Stdin::new();
stdin.write(&n);
// Setup the program for proving.
let (pk, vk) = client.setup(FIBONACCI_ELF);
// // Generate the proof
let proof = client
.prove(&pk, &stdin)
.compressed()
.run()
.expect("failed to generate proof");
println!("Successfully generated proof!");
// Verify the proof.
client.verify(&proof, &vk).expect("failed to verify proof");
println!("Successfully verified proof!");
// Print ELF
println!("{}", hex::encode(vk.hash_bytes()));
proof
.save("../sp1_fibonacci.proof")
.expect("failed to save proof");
std::fs::write("../sp1_fibonacci.pub", proof.public_values)
.expect("failed to save public input");
}