Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .benchrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ node-option:

# benchmark opts
threshold: 3
maxMs: 60_000
maxMs: 180_000
minRuns: 10
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ pub fn verify_multiple_aggregate_signatures(
&sigs,
sigs_groupcheck.unwrap_or(false),
&rands,
64,
128,
) == BLST_ERROR::BLST_SUCCESS
}

Expand Down Expand Up @@ -552,8 +552,8 @@ fn rand_non_zero(rng: &mut ThreadRng) -> u64 {

/// copied from lighthouse:
/// https://github.com/sigp/lighthouse/blob/9e12c21f268c80a3f002ae0ca27477f9f512eb6f/crypto/bls/src/impls/blst.rs#L52
fn create_scalar(i: u64) -> blst_scalar {
let vals = [i, 0, 0, 0];
fn create_scalar(i1: u64, i2: u64) -> blst_scalar {
let vals = [i1, i2, 0, 0];
let mut scalar = std::mem::MaybeUninit::<blst_scalar>::uninit();
unsafe {
blst_scalar_from_uint64(scalar.as_mut_ptr(), vals.as_ptr());
Expand All @@ -565,14 +565,14 @@ fn create_scalar(i: u64) -> blst_scalar {
fn create_rand_scalars(len: usize) -> Vec<blst_scalar> {
let mut rng = rand::thread_rng();
(0..len)
.map(|_| create_scalar(rand_non_zero(&mut rng)))
.map(|_| create_scalar(rand_non_zero(&mut rng), rand_non_zero(&mut rng)))
.collect()
}

/// Creates a vector of random bytes, length len * 8
fn create_rand_slice(len: usize) -> Vec<u8> {
let mut rng = rand::thread_rng();
(0..len)
(0..(2 * len))
.map(|_| rand_non_zero(&mut rng).to_ne_bytes())
.flatten()
.collect()
Expand All @@ -584,8 +584,8 @@ fn aggregate_with(
sigs: &[min_pk::Signature],
scalars: &[u8],
) -> (min_pk::PublicKey, min_pk::Signature) {
let pk = pks.mult(scalars, 64).to_public_key();
let sig = sigs.mult(scalars, 64).to_signature();
let pk = pks.mult(scalars, 128).to_public_key();
let sig = sigs.mult(scalars, 128).to_signature();

(pk, sig)
}
46 changes: 29 additions & 17 deletions test/perf/functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("functions", () => {
}
});
describe("aggregateWithRandomness", () => {
for (const count of [1, 16, 128, 256, 512, 1024]) {
for (const count of [1, 8, 64, 512, 2048, 16_000]) {
itBench({
id: `aggregateWithRandomness - ${count} sets`,
before: () => {
Expand Down Expand Up @@ -75,40 +75,52 @@ describe("functions", () => {
}
});
describe("verifyMultipleAggregateSignatures", () => {
for (const count of [1, 8, 32, 128, 256]) {
for (const count of [1, 8, 64, 512, 2048, 16_000]) {
itBench({
id: `verifyMultipleAggregateSignatures - ${count} sets`,
beforeEach: () => arrayOfIndexes(0, count - 1).map((i) => getTestSet(i)),
beforeEach: () =>
arrayOfIndexes(0, count - 1).map((i) => {
const set = getTestSet(i);
return {
msg: set.msg,
pk: set.pk,
sig: set.sig.toBytes(),
};
}),
fn: (sets) => {
blst.verifyMultipleAggregateSignatures(sets);
blst.verifyMultipleAggregateSignatures(
sets.map((set) => {
const sig = blst.Signature.fromBytes(set.sig);
sig.sigValidate();
return {
msg: set.msg,
pk: set.pk,
sig,
};
})
);
},
});
}
});
describe("verifyMultipleAggregateSignatures same message", () => {
for (const count of [1, 8, 32, 128, 256]) {
for (const count of [1, 8, 64, 512, 2048, 16_000]) {
itBench({
id: `Same message - ${count} sets`,
beforeEach: () =>
arrayOfIndexes(0, count - 1)
.map((i) => getTestSetSameMessage(i))
.map((set) => {
return {
message: set.msg,
secretKey: set.sk,
publicKey: set.pk,
signature: set.sig.toBytes(),
msg: set.msg,
sk: set.sk,
pk: set.pk,
sig: set.sig.toBytes(),
};
}),
fn: (sets) => {
const aggregatedPubkey = blst.aggregatePublicKeys(sets.map((set) => set.publicKey));
const aggregatedSignature = blst.aggregateSignatures(
sets.map((set) => {
const sig = blst.Signature.fromBytes(set.signature, true, true);
return sig;
})
);
const isValid = blst.verify(sets[0].message, aggregatedPubkey, aggregatedSignature);
const {pk, sig} = blst.aggregateWithRandomness(sets);
const isValid = blst.verify(sets[0].msg, pk, sig);
if (!isValid) throw Error("Invalid");
},
});
Expand Down