// Copyright (c) 2023 spawn-zk-snarks developers // // Licensed under the MIT License // use criterion::{black_box, criterion_group, criterion_main, Criterion}; use spawn_zk_snarks::Groth16Setup; use ark_bn254::Fr; use ark_ff::One; fn proof_generation_benchmark(c: &mut Criterion) { // Setup let num_constraints = 1000; let num_variables = 100; let setup = Groth16Setup::new(num_constraints, num_variables).unwrap(); // Test inputs let inputs = vec![Fr::one(); 10]; let witness = vec![Fr::one(); num_variables]; c.bench_function("proof generation", |b| { b.iter(|| { black_box(setup.prove(&inputs, &witness).unwrap()); }); }); } fn proof_verification_benchmark(c: &mut Criterion) { // Setup - Daha gerçekçi bir circuit oluşturalım let setup = Groth16Setup::new(10, 5).unwrap(); // Doğru boyutta inputs ve witness oluşturalım let inputs = vec![Fr::one(); 1]; // Bir tane public input let witness = vec![Fr::one(); 5]; // 5 tane witness // Önce bir proof oluşturalım let proof = setup.prove(&inputs, &witness).unwrap(); c.bench_function("proof verification", |b| { b.iter(|| { black_box(setup.verify(&proof, &inputs).unwrap()); }); }); } fn evm_conversion_benchmark(c: &mut Criterion) { // Setup let setup = Groth16Setup::new(10, 5).unwrap(); let inputs = vec![Fr::one(); 1]; let witness = vec![Fr::one(); 5]; let proof = setup.prove(&inputs, &witness).unwrap(); c.bench_function("evm conversion", |b| { b.iter(|| { black_box(Groth16Setup::proof_to_evm_format(&proof).unwrap()); }); }); } criterion_group!( benches, proof_generation_benchmark, proof_verification_benchmark, evm_conversion_benchmark ); criterion_main!(benches);