From 94d8fce8157440569327c1d1d5db144753a9a1cc Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Fri, 4 Dec 2020 18:54:47 +0000 Subject: [PATCH] Fix noble --- benchmark/noble.ts | 35 +++++++++++++++++++++++++---------- benchmark/runner.ts | 2 +- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/benchmark/noble.ts b/benchmark/noble.ts index b33ff22..f7912e2 100644 --- a/benchmark/noble.ts +++ b/benchmark/noble.ts @@ -7,7 +7,7 @@ import {aggCount, runsNoble} from "./params"; (async function () { // verify - await runBenchmark<{pk: Uint8Array; msg: Uint8Array; sig: Uint8Array}, boolean>({ + await runBenchmark<{pk: noble.PointG1; msg: noble.PointG2; sig: noble.PointG2}, boolean>({ id: `noble verify`, prepareTest: async () => { @@ -29,7 +29,7 @@ import {aggCount, runsNoble} from "./params"; // Fast aggregate - await runBenchmark<{pks: Uint8Array[]; msg: Uint8Array; sig: Uint8Array}, boolean>({ + await runBenchmark<{pks: noble.PointG1[]; msg: noble.PointG2; sig: noble.PointG2}, boolean>({ id: `noble verifyAggregate (${aggCount})`, prepareTest: async () => { @@ -44,15 +44,15 @@ import {aggCount, runsNoble} from "./params"; ); const pks = dataArr.map((data) => data.pk); - const sig = noble.aggregateSignatures(dataArr.map((data) => data.sig)) as unknown as noble.PointG2[]; + const sig = noble.aggregateSignatures(dataArr.map((data) => data.sig)) as any as noble.PointG2; return { - input: {pks, msg, sig}, + input: {pks, msg: await noble.PointG2.hashToCurve(msg), sig}, resultCheck: (valid: boolean) => valid === true, }; }, testRunner: async ({pks, msg, sig}) => { - const pk = noble.aggregatePublicKeys(pks); + const pk = noble.aggregatePublicKeys(pks) as any as noble.PointG1; return await noble.verify(sig, msg, pk); }, runs: runsNoble, @@ -60,7 +60,7 @@ import {aggCount, runsNoble} from "./params"; // // Verify multiple - await runBenchmark<{pks: Uint8Array[]; msgs: Uint8Array[]; sig: Uint8Array}, boolean>({ + await runBenchmark<{pks: noble.PointG1[]; msgs: noble.PointG2[]; sig: noble.PointG2}, boolean>({ id: `noble verifyMultiple (${aggCount})`, prepareTest: async () => { @@ -76,7 +76,7 @@ import {aggCount, runsNoble} from "./params"; const pks = dataArr.map((data) => data.pk); const msgs = dataArr.map((data) => data.msg); - const sig = noble.aggregateSignatures(dataArr.map((data) => data.sig)); + const sig = noble.aggregateSignatures(dataArr.map((data) => data.sig)) as any as noble.PointG2; return { input: {pks, msgs, sig}, @@ -91,7 +91,7 @@ import {aggCount, runsNoble} from "./params"; // Aggregate pubkeys - await runBenchmark({ + await runBenchmark({ id: `noble aggregate pubkeys (${aggCount})`, prepareTest: () => { @@ -105,13 +105,28 @@ import {aggCount, runsNoble} from "./params"; runs: runsNoble, }); - await runBenchmark<{sk: Uint8Array; msg: Uint8Array}, void>({ + await runBenchmark({ + id: `noble aggregate signatures (${aggCount})`, + + prepareTest: async () => { + const hashes = range(aggCount).map(() => generateRandomSecretKey()).map(noble.PointG2.hashToCurve); + return { + input: await Promise.all(hashes), + }; + }, + testRunner: async (sigs) => { + noble.aggregateSignatures(sigs); + }, + runs: runsNoble, + }); + + await runBenchmark<{sk: Uint8Array; msg: noble.PointG2}, void>({ id: `noble sign`, prepareTest: async () => ({ input: { sk: generateRandomSecretKey(), - msg: randomMessage(), + msg: await noble.PointG2.hashToCurve(randomMessage()), }, }), testRunner: async ({sk, msg}) => { diff --git a/benchmark/runner.ts b/benchmark/runner.ts index bb9ca67..90bdaeb 100644 --- a/benchmark/runner.ts +++ b/benchmark/runner.ts @@ -7,7 +7,7 @@ export async function runBenchmark({ id, }: { prepareTest: (i: number) => PromiseOptional<{input: T; resultCheck?: (result: R) => boolean}>; - testRunner: (input: any) => PromiseOptional; + testRunner: (input: T) => PromiseOptional; runs?: number; id: string; }): Promise {