Skip to content

Commit 36b5d38

Browse files
committed
add aggregateVerify bench
1 parent f4e7aa9 commit 36b5d38

1 file changed

Lines changed: 46 additions & 6 deletions

File tree

bindings/perf/blst.test.ts

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import crypto from "node:crypto";
2-
import { bench, describe } from "@chainsafe/benchmark";
2+
import {bench, describe} from "@chainsafe/benchmark";
33
import {
44
SecretKey as SecretKeyTS,
55
type Signature as SignatureTS,
6+
aggregateSignatures as aggregateSignaturesTS,
7+
aggregateVerify as aggregateVerifyTS,
68
verifyMultipleAggregateSignatures as verifyTS,
79
} from "@chainsafe/blst";
810
import {
911
SecretKey as SecretKeyZig,
1012
type Signature as SignatureZig,
13+
aggregateSignatures as aggregateSignaturesZig,
14+
aggregateVerify as aggregateVerifyZig,
1115
verifyMultipleAggregateSignatures as verifyZig,
1216
} from "../src/blst.js";
1317

1418
interface SignatureSetZig {
1519
msg: Uint8Array;
16-
pk: InstanceType<typeof SecretKeyZig> extends { toPublicKey(): infer P } ? P : never;
20+
pk: InstanceType<typeof SecretKeyZig> extends {toPublicKey(): infer P} ? P : never;
1721
sig: InstanceType<typeof SignatureZig>;
1822
}
1923

@@ -24,25 +28,61 @@ interface SignatureSetTS {
2428
}
2529

2630
function generateZigSets(count: number): SignatureSetZig[] {
27-
return Array.from({ length: count }, () => {
31+
return Array.from({length: count}, () => {
2832
const msg = crypto.randomBytes(32);
2933
const sk = SecretKeyZig.fromKeygen(crypto.randomBytes(32));
3034
const pk = sk.toPublicKey();
3135
const sig = sk.sign(msg);
32-
return { msg, pk, sig };
36+
return {msg, pk, sig};
3337
});
3438
}
3539

3640
function generateTSSets(count: number): SignatureSetTS[] {
37-
return Array.from({ length: count }, () => {
41+
return Array.from({length: count}, () => {
3842
const msg = crypto.randomBytes(32);
3943
const sk = SecretKeyTS.fromKeygen(crypto.randomBytes(32));
4044
const pk = sk.toPublicKey();
4145
const sig = sk.sign(msg);
42-
return { msg, pk, sig };
46+
return {msg, pk, sig};
4347
});
4448
}
4549

50+
describe("aggregateVerify", () => {
51+
for (const count of [3, 8, 32, 64, 128]) {
52+
bench({
53+
beforeEach: () => {
54+
const sets = generateZigSets(count);
55+
return {
56+
messages: sets.map((s) => s.msg),
57+
publicKeys: sets.map((s) => s.pk),
58+
signature: aggregateSignaturesZig(sets.map((s) => s.sig)),
59+
};
60+
},
61+
fn: ({messages, publicKeys, signature}) => {
62+
const isValid = aggregateVerifyZig(messages, publicKeys, signature);
63+
if (!isValid) throw Error("Invalid");
64+
},
65+
id: `aggregateVerify lodestar-z ${count} sets`,
66+
});
67+
68+
bench({
69+
beforeEach: () => {
70+
const sets = generateTSSets(count);
71+
return {
72+
messages: sets.map((s) => s.msg),
73+
publicKeys: sets.map((s) => s.pk),
74+
signature: aggregateSignaturesTS(sets.map((s) => s.sig)),
75+
};
76+
},
77+
fn: ({messages, publicKeys, signature}) => {
78+
const isValid = aggregateVerifyTS(messages, publicKeys, signature);
79+
if (!isValid) throw Error("Invalid");
80+
},
81+
id: `aggregateVerify @chainsafe/blst ${count} sets`,
82+
});
83+
}
84+
});
85+
4686
describe("verifyMultipleAggregateSignatures", () => {
4787
for (const count of [3, 8, 32, 64, 128]) {
4888
bench({

0 commit comments

Comments
 (0)