mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-08 22:28:12 -05:00
bench: simplify and improve zk-from-json benchmark
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use rand::rngs::OsRng;
|
||||
use std::{fs::File, io::Read};
|
||||
|
||||
@@ -34,91 +34,91 @@ use darkfi::{
|
||||
fn zk_from_json(c: &mut Criterion) {
|
||||
#[rustfmt::skip]
|
||||
let tests = [
|
||||
(
|
||||
"Opcodes",
|
||||
"proof/opcodes.zk.bin",
|
||||
"proof/witness/opcodes.json"
|
||||
),
|
||||
(
|
||||
"Arithmetic",
|
||||
"proof/arithmetic.zk.bin",
|
||||
"proof/witness/arithmetic.json"
|
||||
),
|
||||
(
|
||||
"SMT",
|
||||
"proof/smt.zk.bin",
|
||||
"proof/witness/smt.json"
|
||||
),
|
||||
(
|
||||
"DAO::mint",
|
||||
"src/contract/dao/proof/mint.zk.bin",
|
||||
"src/contract/dao/proof/witness/mint.json"
|
||||
),
|
||||
//(
|
||||
// "Opcodes",
|
||||
// "proof/opcodes.zk.bin",
|
||||
// "proof/witness/opcodes.json"
|
||||
//),
|
||||
//(
|
||||
// "Arithmetic",
|
||||
// "proof/arithmetic.zk.bin",
|
||||
// "proof/witness/arithmetic.json"
|
||||
//),
|
||||
//(
|
||||
// "SMT",
|
||||
// "proof/smt.zk.bin",
|
||||
// "proof/witness/smt.json"
|
||||
//),
|
||||
//(
|
||||
// "DAO::mint",
|
||||
// "src/contract/dao/proof/mint.zk.bin",
|
||||
// "src/contract/dao/proof/witness/mint.json"
|
||||
//),
|
||||
(
|
||||
"DAO::propose-input",
|
||||
"src/contract/dao/proof/propose-input.zk.bin",
|
||||
"src/contract/dao/proof/witness/propose-input.json"
|
||||
),
|
||||
(
|
||||
"DAO::propose",
|
||||
"src/contract/dao/proof/propose-main.zk.bin",
|
||||
"src/contract/dao/proof/witness/propose-main.json"
|
||||
),
|
||||
//(
|
||||
// "DAO::propose",
|
||||
// "src/contract/dao/proof/propose-main.zk.bin",
|
||||
// "src/contract/dao/proof/witness/propose-main.json"
|
||||
//),
|
||||
(
|
||||
"DAO::vote-input",
|
||||
"src/contract/dao/proof/vote-input.zk.bin",
|
||||
"src/contract/dao/proof/witness/vote-input.json"
|
||||
),
|
||||
(
|
||||
"DAO::vote",
|
||||
"src/contract/dao/proof/vote-main.zk.bin",
|
||||
"src/contract/dao/proof/witness/vote-main.json"
|
||||
),
|
||||
(
|
||||
"DAO::exec",
|
||||
"src/contract/dao/proof/exec.zk.bin",
|
||||
"src/contract/dao/proof/witness/exec.json"
|
||||
),
|
||||
(
|
||||
"DAO::auth_xfer-coin",
|
||||
"src/contract/dao/proof/auth-money-transfer-enc-coin.zk.bin",
|
||||
"src/contract/dao/proof/witness/auth-money-transfer-enc-coin.json"
|
||||
),
|
||||
(
|
||||
"DAO::auth_xfer",
|
||||
"src/contract/dao/proof/auth-money-transfer.zk.bin",
|
||||
"src/contract/dao/proof/witness/auth-money-transfer.json"
|
||||
),
|
||||
(
|
||||
"Money::xfer-mint",
|
||||
"src/contract/money/proof/mint_v1.zk.bin",
|
||||
"src/contract/money/proof/witness/mint_v1.json"
|
||||
),
|
||||
(
|
||||
"Money::xfer-burn",
|
||||
"src/contract/money/proof/burn_v1.zk.bin",
|
||||
"src/contract/money/proof/witness/burn_v1.json"
|
||||
),
|
||||
(
|
||||
"Money::fee",
|
||||
"src/contract/money/proof/fee_v1.zk.bin",
|
||||
"src/contract/money/proof/witness/fee_v1.json"
|
||||
),
|
||||
(
|
||||
"Money::auth_token-mint",
|
||||
"src/contract/money/proof/auth_token_mint_v1.zk.bin",
|
||||
"src/contract/money/proof/witness/auth_token_mint_v1.json"
|
||||
),
|
||||
(
|
||||
"Money::token-mint",
|
||||
"src/contract/money/proof/token_mint_v1.zk.bin",
|
||||
"src/contract/money/proof/witness/token_mint_v1.json"
|
||||
),
|
||||
(
|
||||
"Money::token-freeze",
|
||||
"src/contract/money/proof/token_freeze_v1.zk.bin",
|
||||
"src/contract/money/proof/witness/token_freeze_v1.json"
|
||||
),
|
||||
//(
|
||||
// "DAO::vote",
|
||||
// "src/contract/dao/proof/vote-main.zk.bin",
|
||||
// "src/contract/dao/proof/witness/vote-main.json"
|
||||
//),
|
||||
//(
|
||||
// "DAO::exec",
|
||||
// "src/contract/dao/proof/exec.zk.bin",
|
||||
// "src/contract/dao/proof/witness/exec.json"
|
||||
//),
|
||||
//(
|
||||
// "DAO::auth_xfer-coin",
|
||||
// "src/contract/dao/proof/auth-money-transfer-enc-coin.zk.bin",
|
||||
// "src/contract/dao/proof/witness/auth-money-transfer-enc-coin.json"
|
||||
//),
|
||||
//(
|
||||
// "DAO::auth_xfer",
|
||||
// "src/contract/dao/proof/auth-money-transfer.zk.bin",
|
||||
// "src/contract/dao/proof/witness/auth-money-transfer.json"
|
||||
//),
|
||||
//(
|
||||
// "Money::xfer-mint",
|
||||
// "src/contract/money/proof/mint_v1.zk.bin",
|
||||
// "src/contract/money/proof/witness/mint_v1.json"
|
||||
//),
|
||||
//(
|
||||
// "Money::xfer-burn",
|
||||
// "src/contract/money/proof/burn_v1.zk.bin",
|
||||
// "src/contract/money/proof/witness/burn_v1.json"
|
||||
//),
|
||||
//(
|
||||
// "Money::fee",
|
||||
// "src/contract/money/proof/fee_v1.zk.bin",
|
||||
// "src/contract/money/proof/witness/fee_v1.json"
|
||||
//),
|
||||
//(
|
||||
// "Money::auth_token-mint",
|
||||
// "src/contract/money/proof/auth_token_mint_v1.zk.bin",
|
||||
// "src/contract/money/proof/witness/auth_token_mint_v1.json"
|
||||
//),
|
||||
//(
|
||||
// "Money::token-mint",
|
||||
// "src/contract/money/proof/token_mint_v1.zk.bin",
|
||||
// "src/contract/money/proof/witness/token_mint_v1.json"
|
||||
//),
|
||||
//(
|
||||
// "Money::token-freeze",
|
||||
// "src/contract/money/proof/token_freeze_v1.zk.bin",
|
||||
// "src/contract/money/proof/witness/token_freeze_v1.json"
|
||||
//),
|
||||
];
|
||||
|
||||
println!("Running ZK Json benchmarks");
|
||||
@@ -138,33 +138,20 @@ fn run_benchmark(c: &mut Criterion, name: &str, proof: &str, witness: &str) {
|
||||
let (prover_witnesses, public_inputs) = darkfi::zk::import_witness_json(witness);
|
||||
let circuit = ZkCircuit::new(prover_witnesses.clone(), &zkbin);
|
||||
|
||||
let mut prove_group = c.benchmark_group(format!("prove {}", name));
|
||||
prove_group.significance_level(0.01).sample_size(10);
|
||||
let proving_key = ProvingKey::build(zkbin.k, &circuit.clone());
|
||||
c.bench_function(&format!("prove {}", name), |b| {
|
||||
b.iter(|| Proof::create(&proving_key, &[circuit.clone()], &public_inputs, &mut OsRng))
|
||||
});
|
||||
|
||||
for k in zkbin.k..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 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(zkbin.k, &circuit);
|
||||
|
||||
let mut verif_group = c.benchmark_group(format!("verify {}", name));
|
||||
verif_group.significance_level(0.01).sample_size(10);
|
||||
|
||||
for k in zkbin.k..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();
|
||||
c.bench_function(&format!("verify {}", name), |b| {
|
||||
b.iter(|| proof.verify(&verifying_key, &public_inputs))
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(bench, zk_from_json);
|
||||
|
||||
Reference in New Issue
Block a user