2024-07-23 12:43:54 +00:00
|
|
|
use blst::min_sig::SecretKey;
|
|
|
|
use divan::counter::BytesCount;
|
|
|
|
use divan::Bencher;
|
|
|
|
use kzgrs_backend::common::blob::DaBlob;
|
|
|
|
use kzgrs_backend::encoder::{DaEncoder, DaEncoderParams};
|
2024-10-08 16:39:38 +00:00
|
|
|
use kzgrs_backend::global::GLOBAL_PARAMETERS;
|
2024-07-23 12:43:54 +00:00
|
|
|
use kzgrs_backend::verifier::DaVerifier;
|
2024-08-02 17:01:18 +00:00
|
|
|
use nomos_core::da::DaEncoder as _;
|
2024-07-23 12:43:54 +00:00
|
|
|
use rand::{thread_rng, RngCore};
|
|
|
|
use std::hint::black_box;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
divan::main()
|
|
|
|
}
|
|
|
|
|
|
|
|
const MB: usize = 1024;
|
|
|
|
|
|
|
|
pub fn rand_data(elements_count: usize) -> Vec<u8> {
|
|
|
|
let mut buff = vec![0; elements_count * DaEncoderParams::MAX_BLS12_381_ENCODING_CHUNK_SIZE];
|
|
|
|
rand::thread_rng().fill_bytes(&mut buff);
|
|
|
|
buff
|
|
|
|
}
|
|
|
|
#[divan::bench(consts = [32, 64, 128, 256, 512, 1024], args = [128, 256, 512, 1024, 2048, 4096], sample_count = 1, sample_size = 30)]
|
|
|
|
fn verify<const SIZE: usize>(bencher: Bencher, column_size: usize) {
|
|
|
|
bencher
|
|
|
|
.with_inputs(|| {
|
2024-10-08 16:39:38 +00:00
|
|
|
let params = DaEncoderParams::new(column_size, true, GLOBAL_PARAMETERS.clone());
|
2024-07-23 12:43:54 +00:00
|
|
|
|
|
|
|
let encoder = DaEncoder::new(params);
|
|
|
|
let data = rand_data(SIZE * MB / DaEncoderParams::MAX_BLS12_381_ENCODING_CHUNK_SIZE);
|
|
|
|
let encoded_data = encoder.encode(&data).unwrap();
|
|
|
|
let mut buff = [0u8; 32];
|
|
|
|
let mut rng = thread_rng();
|
|
|
|
rng.fill_bytes(&mut buff);
|
|
|
|
let sk = SecretKey::key_gen(&buff, &[]).unwrap();
|
2024-10-08 16:39:38 +00:00
|
|
|
let verifier = DaVerifier::new(
|
|
|
|
sk.clone(),
|
|
|
|
(0..column_size as u32).collect(),
|
|
|
|
GLOBAL_PARAMETERS.clone(),
|
|
|
|
);
|
2024-07-23 12:43:54 +00:00
|
|
|
let da_blob = DaBlob {
|
|
|
|
column: encoded_data.extended_data.columns().next().unwrap(),
|
2024-09-17 09:32:11 +00:00
|
|
|
column_idx: 0,
|
2024-07-23 12:43:54 +00:00
|
|
|
column_commitment: encoded_data
|
|
|
|
.column_commitments
|
|
|
|
.iter()
|
|
|
|
.next()
|
|
|
|
.copied()
|
|
|
|
.unwrap(),
|
|
|
|
aggregated_column_commitment: encoded_data.aggregated_column_commitment.clone(),
|
|
|
|
aggregated_column_proof: encoded_data
|
|
|
|
.aggregated_column_proofs
|
|
|
|
.iter()
|
|
|
|
.next()
|
|
|
|
.copied()
|
|
|
|
.unwrap(),
|
|
|
|
rows_commitments: encoded_data.row_commitments.clone(),
|
|
|
|
rows_proofs: encoded_data
|
|
|
|
.rows_proofs
|
|
|
|
.iter()
|
|
|
|
.map(|row| row.iter().next().copied().unwrap())
|
|
|
|
.collect(),
|
|
|
|
};
|
|
|
|
(verifier, da_blob)
|
|
|
|
})
|
|
|
|
.input_counter(|_| BytesCount::new(SIZE))
|
2024-09-17 09:32:11 +00:00
|
|
|
.bench_refs(|(verifier, blob)| black_box(verifier.verify(blob, column_size)));
|
2024-07-23 12:43:54 +00:00
|
|
|
}
|