|
1 |
| -// use bellman_circuits::benches::benchmark_circuit; // Assuming this is the path to the bench_proof function |
2 | 1 | use bellman_circuits::circuits::exponentiate;
|
3 | 2 | use clap::{Parser};
|
4 | 3 | use rust_utils::{
|
5 |
| - get_memory, |
6 | 4 | read_file_contents,
|
7 |
| - save_results, |
8 | 5 | };
|
9 |
| -use bellman_utils::measure_size_in_bytes; |
10 |
| -use bellman::groth16; |
| 6 | +use bellman_utils::{BinaryArgs, f_setup, f_verify, f_prove}; |
11 | 7 | use bellman::gadgets::multipack;
|
12 |
| -use bls12_381::{Bls12, Scalar}; |
13 |
| -use rand::rngs::OsRng; |
| 8 | +use bls12_381::Scalar; |
14 | 9 | use ff::PrimeField;
|
15 | 10 |
|
16 |
| -#[derive(Parser, Debug)] |
17 |
| -#[clap( |
18 |
| - name = "MemoryBenchExponentiate", |
19 |
| - about = "MemoryBenchExponentiate CLI is a CLI Application to Benchmark memory consumption of Exponentiate", |
20 |
| - version = "0.0.1" |
21 |
| -)] |
22 |
| - |
23 |
| -struct Args { |
24 |
| - #[arg(short, long)] |
25 |
| - input: String, |
26 |
| - |
27 |
| - #[arg(short, long)] |
28 |
| - output: String, |
29 |
| -} |
30 |
| - |
31 | 11 | fn main() {
|
32 | 12 | // Parse command line arguments
|
33 |
| - let args = Args::parse(); |
| 13 | + let args = BinaryArgs::parse(); |
34 | 14 |
|
35 | 15 | // Read and parse input from the specified JSON file
|
36 | 16 | let input_str = read_file_contents(args.input);
|
37 | 17 |
|
38 |
| - // Get data from config |
39 |
| - let (x_64, e, y_64) = exponentiate::get_exponentiate_data(input_str); |
40 |
| - |
41 |
| - // Create Scalar from some values |
42 |
| - let x = Scalar::from(x_64); |
43 |
| - let y = Scalar::from(y_64); |
44 |
| - |
45 |
| - // Public inputs are x and y |
46 |
| - let x_bits = multipack::bytes_to_bits_le(&x.to_repr().as_ref()); |
47 |
| - let y_bits = multipack::bytes_to_bits_le(&y.to_repr().as_ref()); |
48 |
| - let inputs = [multipack::compute_multipacking(&x_bits), multipack::compute_multipacking(&y_bits)].concat(); |
49 |
| - |
50 |
| - |
51 |
| - // Define the circuit |
52 |
| - let circuit = exponentiate::ExponentiationCircuit { |
53 |
| - x: Some(x), |
54 |
| - e: e, |
55 |
| - y: Some(y), |
56 |
| - }; |
57 |
| - |
58 |
| - // Get the initial memory usage |
59 |
| - let initial_rss = get_memory(); |
60 |
| - |
61 |
| - // Generate Parameters |
62 |
| - let params = groth16::generate_random_parameters::<Bls12, _, _>(circuit.clone(), &mut OsRng).unwrap(); |
63 |
| - |
64 |
| - // Prepare the verification key |
65 |
| - let pvk = groth16::prepare_verifying_key(¶ms.vk); |
66 |
| - |
67 |
| - // Get the memory usage after setup |
68 |
| - let setup_rss = get_memory(); |
69 |
| - |
70 |
| - // Create a Groth16 proof with our parameters |
71 |
| - let proof = groth16::create_random_proof(circuit, ¶ms, &mut OsRng).unwrap(); |
72 |
| - |
73 |
| - // Get the memory usage after proof generation |
74 |
| - let proof_rss = get_memory(); |
75 |
| - |
76 |
| - // Verify the proof |
77 |
| - let _ = groth16::verify_proof(&pvk, &proof, &inputs); |
78 |
| - |
79 |
| - // Get the memory usage after proof verification |
80 |
| - let verify_rss = get_memory(); |
| 18 | + // Get data from config |
| 19 | + let (x_64, e, y_64) = exponentiate::get_exponentiate_data(input_str); |
| 20 | + |
| 21 | + // Create Scalar from some values |
| 22 | + let x = Scalar::from(x_64); |
| 23 | + let y = Scalar::from(y_64); |
| 24 | + |
| 25 | + if args.phase == "setup" { |
| 26 | + let circuit = exponentiate::ExponentiationCircuit { |
| 27 | + x: Some(x), |
| 28 | + e: e, |
| 29 | + y: Some(y), |
| 30 | + }; |
| 31 | + let params_file = args.params.expect("Missing params argument"); |
| 32 | + f_setup(circuit, params_file); |
| 33 | + } else if args.phase == "prove" { |
| 34 | + let circuit = exponentiate::ExponentiationCircuit { |
| 35 | + x: Some(x), |
| 36 | + e: e, |
| 37 | + y: Some(y), |
| 38 | + }; |
| 39 | + let params_file = args.params.expect("Missing params argument"); |
| 40 | + let proof_file = args.proof.expect("Missing proof argument"); |
| 41 | + f_prove(circuit, params_file, proof_file); |
| 42 | + } else if args.phase == "verify" { |
| 43 | + // Public inputs are x and y |
| 44 | + let x_bits = multipack::bytes_to_bits_le(&x.to_repr().as_ref()); |
| 45 | + let y_bits = multipack::bytes_to_bits_le(&y.to_repr().as_ref()); |
| 46 | + let inputs: Vec<Scalar> = [multipack::compute_multipacking(&x_bits), multipack::compute_multipacking(&y_bits)].concat(); |
| 47 | + let params_file = args.params.expect("Missing params argument"); |
| 48 | + let proof_file = args.proof.expect("Missing proof argument"); |
| 49 | + f_verify(params_file, proof_file, inputs) |
| 50 | + } else { |
| 51 | + panic!("Invalid phase (should be setup, prove, or verify)"); |
| 52 | + } |
81 | 53 |
|
82 |
| - // Measure the proof size |
83 |
| - let proof_size = measure_size_in_bytes(&proof); |
84 | 54 |
|
85 |
| - // Save the results |
86 |
| - save_results(initial_rss, setup_rss, proof_rss, verify_rss, proof_size, args.output); |
87 | 55 | }
|
0 commit comments