mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-08 22:28:12 -05:00
tests/bench: delete bench_zk, add zk_arith (uses criterion crate)
This commit is contained in:
71
bench/zk_arith.rs
Normal file
71
bench/zk_arith.rs
Normal file
@@ -0,0 +1,71 @@
|
||||
/* This file is part of DarkFi (https://dark.fi)
|
||||
*
|
||||
* Copyright (C) 2020-2024 Dyne.org foundation
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
||||
use halo2_proofs::{circuit::Value, pasta::Fp};
|
||||
use rand::rngs::OsRng;
|
||||
|
||||
use darkfi::{
|
||||
zk::{
|
||||
proof::{ProvingKey, VerifyingKey},
|
||||
vm::ZkCircuit,
|
||||
vm_heap::{empty_witnesses, Witness},
|
||||
Proof,
|
||||
},
|
||||
zkas::ZkBinary,
|
||||
};
|
||||
|
||||
fn zk_arith_bench(c: &mut Criterion) {
|
||||
let bincode = include_bytes!("../proof/arithmetic.zk.bin");
|
||||
let zkbin = ZkBinary::decode(bincode).unwrap();
|
||||
|
||||
let a = Fp::from(4);
|
||||
let b = Fp::from(110);
|
||||
|
||||
let prover_witnesses = vec![Witness::Base(Value::known(a)), Witness::Base(Value::known(b))];
|
||||
let public_inputs = vec![a + b, a * b, a - b];
|
||||
|
||||
let circuit = ZkCircuit::new(prover_witnesses.clone(), &zkbin);
|
||||
|
||||
let mut prove_group = c.benchmark_group("prove");
|
||||
for k in 11..20 {
|
||||
let proving_key = ProvingKey::build(k, &circuit.clone());
|
||||
prove_group.bench_with_input(BenchmarkId::from_parameter(k), &k, |b, &_k| {
|
||||
b.iter(|| Proof::create(&proving_key, &[circuit.clone()], &public_inputs, &mut OsRng))
|
||||
});
|
||||
}
|
||||
prove_group.finish();
|
||||
|
||||
let mut verif_group = c.benchmark_group("verify");
|
||||
for k in 11..20 {
|
||||
let proving_key = ProvingKey::build(k, &circuit.clone());
|
||||
let proof =
|
||||
Proof::create(&proving_key, &[circuit.clone()], &public_inputs, &mut OsRng).unwrap();
|
||||
let verifier_witnesses = empty_witnesses(&zkbin).unwrap();
|
||||
let circuit = ZkCircuit::new(verifier_witnesses, &zkbin);
|
||||
let verifying_key = VerifyingKey::build(k, &circuit);
|
||||
|
||||
verif_group.bench_with_input(BenchmarkId::from_parameter(k), &k, |b, &_k| {
|
||||
b.iter(|| proof.verify(&verifying_key, &public_inputs))
|
||||
});
|
||||
}
|
||||
verif_group.finish();
|
||||
}
|
||||
|
||||
criterion_group!(benches, zk_arith_bench);
|
||||
criterion_main!(benches);
|
||||
Reference in New Issue
Block a user