-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #531 from input-output-hk/batch_verify
Batch verify of StmAggregateSignatures
- Loading branch information
Showing
9 changed files
with
570 additions
and
115 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,17 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## 0.2.1 (04-01-2022) | ||
### Added | ||
- Batch verification for `StmAggrSig`. | ||
|
||
## 0.2.0 (16-12-2022) | ||
### Changed | ||
- Addapted the `Signature` struct, so that it does not contain the verification key and | ||
the stake, as these values are not required. | ||
|
||
## 0.1.0 (05-12-2022) | ||
Initial release. |
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,93 @@ | ||
use blake2::{digest::consts::U64, Blake2b, Digest}; | ||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; | ||
use mithril_stm::multi_sig::{Signature, SigningKey, VerificationKey}; | ||
use rand_chacha::ChaCha20Rng; | ||
use rand_core::{RngCore, SeedableRng}; | ||
|
||
fn batch_benches(c: &mut Criterion, array_batches: &[usize], nr_sigs: usize) { | ||
let mut group = c.benchmark_group("MultiSig".to_string()); | ||
let mut rng = ChaCha20Rng::from_seed([0u8; 32]); | ||
let mut batch_msgs = Vec::new(); | ||
let mut batch_vk = Vec::new(); | ||
let mut batch_sig = Vec::new(); | ||
|
||
for &nr_batches in array_batches { | ||
let batch_string = format!("Batch size: {}", nr_batches); | ||
|
||
for _ in 0..nr_batches { | ||
let mut msg = [0u8; 32]; | ||
rng.fill_bytes(&mut msg); | ||
let mut mvks = Vec::new(); | ||
let mut sigs = Vec::new(); | ||
for _ in 0..nr_sigs { | ||
let sk = SigningKey::gen(&mut rng); | ||
let vk = VerificationKey::from(&sk); | ||
let sig = sk.sign(&msg); | ||
sigs.push(sig); | ||
mvks.push(vk); | ||
} | ||
let (agg_vk, agg_sig) = Signature::aggregate(&mvks, &sigs).unwrap(); | ||
batch_msgs.push(msg.to_vec()); | ||
batch_vk.push(agg_vk); | ||
batch_sig.push(agg_sig); | ||
} | ||
|
||
group.bench_function(BenchmarkId::new("Batch Verification", batch_string), |b| { | ||
b.iter(|| { | ||
Signature::batch_verify_aggregates(&batch_msgs, &batch_vk, &batch_sig).is_ok() | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
fn aggregate_and_verify(c: &mut Criterion, nr_sigs: usize) { | ||
let mut group = c.benchmark_group("BLS".to_string()); | ||
let mut rng = ChaCha20Rng::from_seed([0u8; 32]); | ||
|
||
let mut msg = [0u8; 32]; | ||
rng.fill_bytes(&mut msg); | ||
let mut mvks = Vec::new(); | ||
let mut sigs = Vec::new(); | ||
for _ in 0..nr_sigs { | ||
let sk = SigningKey::gen(&mut rng); | ||
let vk = VerificationKey::from(&sk); | ||
let sig = sk.sign(&msg); | ||
sigs.push(sig); | ||
mvks.push(vk); | ||
} | ||
|
||
group.bench_function(BenchmarkId::new("Individual verif", nr_sigs), |b| { | ||
b.iter(|| { | ||
for (vk, sig) in mvks.iter().zip(sigs.iter()) { | ||
assert!(sig.verify(&msg, vk).is_ok()); | ||
} | ||
}) | ||
}); | ||
|
||
group.bench_function(BenchmarkId::new("Batch Verification", nr_sigs), |b| { | ||
b.iter(|| { | ||
for sig in sigs.iter() { | ||
let mut hasher = Blake2b::<U64>::new(); | ||
hasher.update(sig.to_bytes()); | ||
hasher.finalize(); | ||
} | ||
let (agg_vk, agg_sig) = Signature::aggregate(&mvks, &sigs).unwrap(); | ||
assert!(agg_sig.verify(&msg, &agg_vk).is_ok()) | ||
}) | ||
}); | ||
} | ||
|
||
fn batch_multi_sig_benches(c: &mut Criterion) { | ||
batch_benches(c, &[1, 10, 20, 50, 100], 300); | ||
} | ||
fn batch_bls_benches(c: &mut Criterion) { | ||
aggregate_and_verify(c, 856); | ||
} | ||
|
||
criterion_group!(name = benches; | ||
config = Criterion::default().nresamples(1000); | ||
targets = | ||
batch_multi_sig_benches, | ||
batch_bls_benches | ||
); | ||
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
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
Oops, something went wrong.