2020-12-04 21:05:48 +00:00
|
|
|
import {runForAllImplementations} from "../test/switch";
|
|
|
|
import {range, randomMessage} from "../test/util";
|
|
|
|
|
|
|
|
(async function () {
|
|
|
|
console.log("verifyMultipleSignatures savings");
|
|
|
|
console.log(["Impl", "# sigs", "ratio multi/single"].join("\t"));
|
|
|
|
|
|
|
|
await runForAllImplementations(async (bls, implementation) => {
|
|
|
|
for (const aggCount of [2, 5, 10, 20, 50, 100]) {
|
|
|
|
const dataArr = range(aggCount).map(() => {
|
|
|
|
const sk = bls.SecretKey.fromKeygen();
|
|
|
|
const pk = sk.toPublicKey();
|
|
|
|
const msg = randomMessage();
|
|
|
|
const sig = sk.sign(msg);
|
2021-04-05 16:03:49 +00:00
|
|
|
return {publicKey: pk, message: msg, signature: sig};
|
2020-12-04 21:05:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const startMulti = process.hrtime.bigint();
|
2021-04-04 23:44:55 +00:00
|
|
|
bls.Signature.verifyMultipleSignatures(dataArr);
|
2020-12-04 21:05:48 +00:00
|
|
|
const endMulti = process.hrtime.bigint();
|
|
|
|
const diffMulti = endMulti - startMulti;
|
|
|
|
|
|
|
|
const startSingle = process.hrtime.bigint();
|
2021-04-05 16:03:49 +00:00
|
|
|
for (const {publicKey, message, signature} of dataArr) {
|
|
|
|
signature.verify(publicKey, message);
|
2020-12-04 21:05:48 +00:00
|
|
|
}
|
|
|
|
const endSingle = process.hrtime.bigint();
|
|
|
|
const diffSingle = endSingle - startSingle;
|
|
|
|
|
|
|
|
const ratio = Number(diffMulti) / Number(diffSingle);
|
|
|
|
console.log([implementation, aggCount, ratio.toPrecision(2)].join("\t"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})();
|