-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverifier.rs
32 lines (26 loc) · 1.19 KB
/
verifier.rs
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
//! A program that takes a number `n` as input, and writes if `n` is prime as an output.
use sp1_sdk::{utils, ProverClient, SP1ProofWithPublicValues};
// Generated with `cargo prove build --docker --elf-name is-prime-write --output-directory elf`
// in the program directory
const ELF: &[u8] = include_bytes!("../../../program/elf/is-prime");
const FILENAME: &'static str = "42-is-prime.proof";
fn main() {
// Setup a tracer for logging.
utils::setup_logger();
// Generate the verifying key from the ELF
let client = ProverClient::new();
let (_, vk) = client.setup(ELF);
// Deserialize the proof
let mut deserialized_proof =
SP1ProofWithPublicValues::load(FILENAME).expect("loading proof failed");
eprintln!("{deserialized_proof:?}");
// Verify the deserialized proof.
client
.verify(&deserialized_proof, &vk)
.expect("verification failed");
// Now that it's accepted, read the primality boolean and the number from
// the proof's public values and display them.
let is_prime: bool = deserialized_proof.public_values.read();
let n: u64 = deserialized_proof.public_values.read();
println!("Verifier: Is {n} prime? {is_prime}");
}