-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92ec298
commit 12508a9
Showing
9 changed files
with
167 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,3 +114,5 @@ gnark/template | |
.idea/ | ||
|
||
tags/ | ||
|
||
*.*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
params | ||
proof | ||
tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,55 @@ | ||
// use bellman_circuits::benches::benchmark_circuit; // Assuming this is the path to the bench_proof function | ||
use bellman_circuits::circuits::exponentiate; | ||
use clap::{Parser}; | ||
use rust_utils::{ | ||
get_memory, | ||
read_file_contents, | ||
save_results, | ||
}; | ||
use bellman_utils::measure_size_in_bytes; | ||
use bellman::groth16; | ||
use bellman_utils::{BinaryArgs, f_setup, f_verify, f_prove}; | ||
use bellman::gadgets::multipack; | ||
use bls12_381::{Bls12, Scalar}; | ||
use rand::rngs::OsRng; | ||
use bls12_381::Scalar; | ||
use ff::PrimeField; | ||
|
||
#[derive(Parser, Debug)] | ||
#[clap( | ||
name = "MemoryBenchExponentiate", | ||
about = "MemoryBenchExponentiate CLI is a CLI Application to Benchmark memory consumption of Exponentiate", | ||
version = "0.0.1" | ||
)] | ||
|
||
struct Args { | ||
#[arg(short, long)] | ||
input: String, | ||
|
||
#[arg(short, long)] | ||
output: String, | ||
} | ||
|
||
fn main() { | ||
// Parse command line arguments | ||
let args = Args::parse(); | ||
let args = BinaryArgs::parse(); | ||
|
||
// Read and parse input from the specified JSON file | ||
let input_str = read_file_contents(args.input); | ||
|
||
// Get data from config | ||
let (x_64, e, y_64) = exponentiate::get_exponentiate_data(input_str); | ||
|
||
// Create Scalar from some values | ||
let x = Scalar::from(x_64); | ||
let y = Scalar::from(y_64); | ||
|
||
// Public inputs are x and y | ||
let x_bits = multipack::bytes_to_bits_le(&x.to_repr().as_ref()); | ||
let y_bits = multipack::bytes_to_bits_le(&y.to_repr().as_ref()); | ||
let inputs = [multipack::compute_multipacking(&x_bits), multipack::compute_multipacking(&y_bits)].concat(); | ||
|
||
|
||
// Define the circuit | ||
let circuit = exponentiate::ExponentiationCircuit { | ||
x: Some(x), | ||
e: e, | ||
y: Some(y), | ||
}; | ||
|
||
// Get the initial memory usage | ||
let initial_rss = get_memory(); | ||
|
||
// Generate Parameters | ||
let params = groth16::generate_random_parameters::<Bls12, _, _>(circuit.clone(), &mut OsRng).unwrap(); | ||
|
||
// Prepare the verification key | ||
let pvk = groth16::prepare_verifying_key(¶ms.vk); | ||
|
||
// Get the memory usage after setup | ||
let setup_rss = get_memory(); | ||
|
||
// Create a Groth16 proof with our parameters | ||
let proof = groth16::create_random_proof(circuit, ¶ms, &mut OsRng).unwrap(); | ||
|
||
// Get the memory usage after proof generation | ||
let proof_rss = get_memory(); | ||
|
||
// Verify the proof | ||
let _ = groth16::verify_proof(&pvk, &proof, &inputs); | ||
|
||
// Get the memory usage after proof verification | ||
let verify_rss = get_memory(); | ||
// Get data from config | ||
let (x_64, e, y_64) = exponentiate::get_exponentiate_data(input_str); | ||
|
||
// Create Scalar from some values | ||
let x = Scalar::from(x_64); | ||
let y = Scalar::from(y_64); | ||
|
||
if args.phase == "setup" { | ||
let circuit = exponentiate::ExponentiationCircuit { | ||
x: Some(x), | ||
e: e, | ||
y: Some(y), | ||
}; | ||
let params_file = args.params.expect("Missing params argument"); | ||
f_setup(circuit, params_file); | ||
} else if args.phase == "prove" { | ||
let circuit = exponentiate::ExponentiationCircuit { | ||
x: Some(x), | ||
e: e, | ||
y: Some(y), | ||
}; | ||
let params_file = args.params.expect("Missing params argument"); | ||
let proof_file = args.proof.expect("Missing proof argument"); | ||
f_prove(circuit, params_file, proof_file); | ||
} else if args.phase == "verify" { | ||
// Public inputs are x and y | ||
let x_bits = multipack::bytes_to_bits_le(&x.to_repr().as_ref()); | ||
let y_bits = multipack::bytes_to_bits_le(&y.to_repr().as_ref()); | ||
let inputs: Vec<Scalar> = [multipack::compute_multipacking(&x_bits), multipack::compute_multipacking(&y_bits)].concat(); | ||
let params_file = args.params.expect("Missing params argument"); | ||
let proof_file = args.proof.expect("Missing proof argument"); | ||
f_verify(params_file, proof_file, inputs) | ||
} else { | ||
panic!("Invalid phase (should be setup, prove, or verify)"); | ||
} | ||
|
||
// Measure the proof size | ||
let proof_size = measure_size_in_bytes(&proof); | ||
|
||
// Save the results | ||
save_results(initial_rss, setup_rss, proof_rss, verify_rss, proof_size, args.output); | ||
} |
Oops, something went wrong.