-
Notifications
You must be signed in to change notification settings - Fork 6
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
Showing
6 changed files
with
151 additions
and
5 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
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,63 @@ | ||
use std::time::Duration; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use rand::Rng; | ||
use rust_kzg_bn254::{blob::Blob, kzg::Kzg}; | ||
|
||
fn bench_kzg_proof(c: &mut Criterion) { | ||
let mut rng = rand::thread_rng(); | ||
let mut kzg = Kzg::setup( | ||
"src/test-files/mainnet-data/g1.131072.point", | ||
"", | ||
"src/test-files/mainnet-data/g2.point.powerOf2", | ||
268435456, | ||
131072 | ||
).unwrap(); | ||
|
||
c.bench_function("bench_kzg_proof_10000", |b| { | ||
let random_blob: Vec<u8> = (0..10000).map(|_| rng.gen_range(32..=126) as u8).collect(); | ||
let input = Blob::from_bytes_and_pad(&random_blob); | ||
let input_poly = input.to_polynomial().unwrap(); | ||
kzg.data_setup_custom(1, input.len().try_into().unwrap()).unwrap(); | ||
let index = rand::thread_rng().gen_range(0..input_poly.get_length_of_padded_blob_as_fr_vector()); | ||
b.iter(|| { | ||
kzg.compute_kzg_proof_with_roots_of_unity(&input_poly, index.try_into().unwrap()).unwrap() | ||
}); | ||
}); | ||
|
||
c.bench_function("bench_kzg_proof_30000", |b| { | ||
let random_blob: Vec<u8> = (0..30000).map(|_| rng.gen_range(32..=126) as u8).collect(); | ||
let input = Blob::from_bytes_and_pad(&random_blob); | ||
let input_poly = input.to_polynomial().unwrap(); | ||
kzg.data_setup_custom(1, input.len().try_into().unwrap()).unwrap(); | ||
let index = rand::thread_rng().gen_range(0..input_poly.get_length_of_padded_blob_as_fr_vector()); | ||
b.iter(|| { | ||
kzg.compute_kzg_proof_with_roots_of_unity(&input_poly, index.try_into().unwrap()).unwrap() | ||
}); | ||
}); | ||
|
||
c.bench_function("bench_kzg_proof_50000", |b| { | ||
let random_blob: Vec<u8> = (0..50000).map(|_| rng.gen_range(32..=126) as u8).collect(); | ||
let input = Blob::from_bytes_and_pad(&random_blob); | ||
let input_poly = input.to_polynomial().unwrap(); | ||
kzg.data_setup_custom(1, input.len().try_into().unwrap()).unwrap(); | ||
let index = rand::thread_rng().gen_range(0..input_poly.get_length_of_padded_blob_as_fr_vector()); | ||
b.iter(|| { | ||
kzg.compute_kzg_proof_with_roots_of_unity(&input_poly, index.try_into().unwrap()).unwrap() | ||
}); | ||
}); | ||
} | ||
|
||
fn criterion_config() -> Criterion { | ||
Criterion::default() | ||
.warm_up_time(Duration::from_secs(5)) // Warm-up time | ||
.measurement_time(Duration::from_secs(10)) // Measurement time | ||
.sample_size(10) // Number of samples to take | ||
} | ||
|
||
|
||
criterion_group!( | ||
name = benches; | ||
config = criterion_config(); | ||
targets = bench_kzg_proof | ||
); | ||
criterion_main!(benches); |
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,75 @@ | ||
use std::time::Duration; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use rand::Rng; | ||
use rust_kzg_bn254::{blob::Blob, kzg::Kzg}; | ||
|
||
fn bench_kzg_verify(c: &mut Criterion) { | ||
let mut rng = rand::thread_rng(); | ||
let mut kzg = Kzg::setup( | ||
"src/test-files/mainnet-data/g1.131072.point", | ||
"", | ||
"src/test-files/mainnet-data/g2.point.powerOf2", | ||
268435456, | ||
131072 | ||
).unwrap(); | ||
|
||
c.bench_function("bench_kzg_verify_10000", |b| { | ||
let random_blob: Vec<u8> = (0..10000).map(|_| rng.gen_range(32..=126) as u8).collect(); | ||
let input = Blob::from_bytes_and_pad(&random_blob); | ||
let input_poly = input.to_polynomial().unwrap(); | ||
kzg.data_setup_custom(1, input.len().try_into().unwrap()).unwrap(); | ||
let index = rand::thread_rng().gen_range(0..input_poly.get_length_of_padded_blob_as_fr_vector()); | ||
let commitment = kzg.commit(&input_poly.clone()).unwrap(); | ||
let proof = kzg.compute_kzg_proof_with_roots_of_unity(&input_poly, index.try_into().unwrap()).unwrap(); | ||
let value_fr = input_poly.get_at_index(index).unwrap(); | ||
let z_fr = kzg.get_nth_root_of_unity(index).unwrap(); | ||
b.iter(|| { | ||
kzg.verify_kzg_proof(commitment, proof, value_fr.clone(), z_fr.clone()) | ||
}); | ||
}); | ||
|
||
c.bench_function("bench_kzg_verify_30000", |b| { | ||
let random_blob: Vec<u8> = (0..30000).map(|_| rng.gen_range(32..=126) as u8).collect(); | ||
let input = Blob::from_bytes_and_pad(&random_blob); | ||
let input_poly = input.to_polynomial().unwrap(); | ||
kzg.data_setup_custom(1, input.len().try_into().unwrap()).unwrap(); | ||
let index = rand::thread_rng().gen_range(0..input_poly.get_length_of_padded_blob_as_fr_vector()); | ||
let commitment = kzg.commit(&input_poly.clone()).unwrap(); | ||
let proof = kzg.compute_kzg_proof_with_roots_of_unity(&input_poly, index.try_into().unwrap()).unwrap(); | ||
let value_fr = input_poly.get_at_index(index).unwrap(); | ||
let z_fr = kzg.get_nth_root_of_unity(index).unwrap(); | ||
b.iter(|| { | ||
kzg.verify_kzg_proof(commitment, proof, value_fr.clone(), z_fr.clone()) | ||
}); | ||
}); | ||
|
||
c.bench_function("bench_kzg_verify_50000", |b| { | ||
let random_blob: Vec<u8> = (0..50000).map(|_| rng.gen_range(32..=126) as u8).collect(); | ||
let input = Blob::from_bytes_and_pad(&random_blob); | ||
let input_poly = input.to_polynomial().unwrap(); | ||
kzg.data_setup_custom(1, input.len().try_into().unwrap()).unwrap(); | ||
let index = rand::thread_rng().gen_range(0..input_poly.get_length_of_padded_blob_as_fr_vector()); | ||
let commitment = kzg.commit(&input_poly.clone()).unwrap(); | ||
let proof = kzg.compute_kzg_proof_with_roots_of_unity(&input_poly, index.try_into().unwrap()).unwrap(); | ||
let value_fr = input_poly.get_at_index(index).unwrap(); | ||
let z_fr = kzg.get_nth_root_of_unity(index).unwrap(); | ||
b.iter(|| { | ||
kzg.verify_kzg_proof(commitment, proof, value_fr.clone(), z_fr.clone()) | ||
}); | ||
}); | ||
} | ||
|
||
fn criterion_config() -> Criterion { | ||
Criterion::default() | ||
.warm_up_time(Duration::from_secs(5)) // Warm-up time | ||
.measurement_time(Duration::from_secs(10)) // Measurement time | ||
.sample_size(10) // Number of samples to take | ||
} | ||
|
||
|
||
criterion_group!( | ||
name = benches; | ||
config = criterion_config(); | ||
targets = bench_kzg_verify | ||
); | ||
criterion_main!(benches); |