mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-02-15 03:05:48 +00:00
Test deserialization of proofs in MiMC test example.
This commit is contained in:
parent
5f8747a0f4
commit
f5370057bd
@ -28,6 +28,7 @@ use bellman::{
|
|||||||
|
|
||||||
// We're going to use the Groth16 proving system.
|
// We're going to use the Groth16 proving system.
|
||||||
use bellman::groth16::{
|
use bellman::groth16::{
|
||||||
|
Proof,
|
||||||
generate_random_parameters,
|
generate_random_parameters,
|
||||||
prepare_verifying_key,
|
prepare_verifying_key,
|
||||||
create_random_proof,
|
create_random_proof,
|
||||||
@ -165,7 +166,8 @@ impl<'a, E: Engine> Circuit<E> for MiMCDemo<'a, E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
#[test]
|
||||||
|
fn test_mimc() {
|
||||||
// This may not be cryptographically safe, use
|
// This may not be cryptographically safe, use
|
||||||
// `OsRng` (for example) in production software.
|
// `OsRng` (for example) in production software.
|
||||||
let rng = &mut thread_rng();
|
let rng = &mut thread_rng();
|
||||||
@ -196,14 +198,20 @@ fn main() {
|
|||||||
let mut total_proving = Duration::new(0, 0);
|
let mut total_proving = Duration::new(0, 0);
|
||||||
let mut total_verifying = Duration::new(0, 0);
|
let mut total_verifying = Duration::new(0, 0);
|
||||||
|
|
||||||
|
// Just a place to put the proof data, so we can
|
||||||
|
// benchmark deserialization.
|
||||||
|
let mut proof_vec = vec![];
|
||||||
|
|
||||||
for _ in 0..SAMPLES {
|
for _ in 0..SAMPLES {
|
||||||
// Generate a random preimage and compute the image
|
// Generate a random preimage and compute the image
|
||||||
let xl = rng.gen();
|
let xl = rng.gen();
|
||||||
let xr = rng.gen();
|
let xr = rng.gen();
|
||||||
let image = mimc::<Bls12>(xl, xr, &constants);
|
let image = mimc::<Bls12>(xl, xr, &constants);
|
||||||
|
|
||||||
|
proof_vec.truncate(0);
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let proof = {
|
{
|
||||||
// Create an instance of our circuit (with the
|
// Create an instance of our circuit (with the
|
||||||
// witness)
|
// witness)
|
||||||
let c = MiMCDemo {
|
let c = MiMCDemo {
|
||||||
@ -213,11 +221,15 @@ fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Create a groth16 proof with our parameters.
|
// Create a groth16 proof with our parameters.
|
||||||
create_random_proof(c, ¶ms, rng).unwrap()
|
let proof = create_random_proof(c, ¶ms, rng).unwrap();
|
||||||
};
|
|
||||||
|
proof.write(&mut proof_vec).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
total_proving += start.elapsed();
|
total_proving += start.elapsed();
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
|
let proof = Proof::read(&proof_vec[..]).unwrap();
|
||||||
// Check the proof
|
// Check the proof
|
||||||
assert!(verify_proof(
|
assert!(verify_proof(
|
||||||
&pvk,
|
&pvk,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user