From 1ba12479786cdfa2e52972cc0ca7f318f50ac5f8 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Thu, 3 Dec 2020 20:01:14 +0400 Subject: [PATCH 1/7] Benchmarks: update noble to use decompressed points. Much faster now --- benchmark/noble.ts | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/benchmark/noble.ts b/benchmark/noble.ts index 3d70d10..eb223d0 100644 --- a/benchmark/noble.ts +++ b/benchmark/noble.ts @@ -13,11 +13,11 @@ import {aggCount, runsNoble} from "./params"; prepareTest: async () => { const priv = generateRandomSecretKey(); const msg = randomMessage(); - const sig = await noble.sign(msg, priv); - const pk = noble.getPublicKey(priv); + const pk = noble.PointG1.fromPrivateKey(priv); + const sig = noble.PointG2.fromSignature(await noble.sign(msg, priv)); return { - input: {pk, msg, sig}, + input: {pk, msg: await noble.PointG2.hashToCurve(msg), sig}, resultCheck: (valid: boolean) => valid === true, }; }, @@ -37,14 +37,14 @@ import {aggCount, runsNoble} from "./params"; const dataArr = await Promise.all( range(aggCount).map(async () => { const sk = generateRandomSecretKey(); - const pk = noble.getPublicKey(sk); - const sig = await noble.sign(msg, sk); + const pk = noble.PointG1.fromPrivateKey(sk); + const sig = noble.PointG2.fromSignature(await noble.sign(msg, sk)); return {pk, sig}; }) ); const pks = dataArr.map((data) => data.pk); - const sig = noble.aggregateSignatures(dataArr.map((data) => data.sig)); + const sig = noble.aggregateSignatures(dataArr.map((data) => data.sig)) as unknown as noble.PointG2[]; return { input: {pks, msg, sig}, @@ -58,7 +58,7 @@ import {aggCount, runsNoble} from "./params"; runs: runsNoble, }); - // Verify multiple + // // Verify multiple await runBenchmark<{pks: Uint8Array[]; msgs: Uint8Array[]; sig: Uint8Array}, boolean>({ id: `noble verifyMultiple (${aggCount})`, @@ -67,10 +67,10 @@ import {aggCount, runsNoble} from "./params"; const dataArr = await Promise.all( range(aggCount).map(async () => { const sk = generateRandomSecretKey(); - const pk = noble.getPublicKey(sk); + const pk = noble.PointG1.fromPrivateKey(sk); const msg = randomMessage(); - const sig = await noble.sign(msg, sk); - return {pk, msg, sig}; + const sig = noble.PointG2.fromSignature(await noble.sign(msg, sk)); + return {pk, msg: await noble.PointG2.hashToCurve(msg), sig}; }) ); @@ -96,7 +96,21 @@ import {aggCount, runsNoble} from "./params"; prepareTest: () => { return { - input: range(aggCount).map(() => noble.getPublicKey(generateRandomSecretKey())), + input: range(aggCount).map(() => noble.PointG1.fromPrivateKey(generateRandomSecretKey())), + }; + }, + testRunner: async (pks) => { + noble.aggregatePublicKeys(pks); + }, + runs: runsNoble, + }); + + await runBenchmark({ + id: `noble aggregate sigs (${aggCount})`, + + prepareTest: async () => { + return { + input: await Promise.all(range(aggCount).map(() => noble.PointG2.hashToCurve(generateRandomSecretKey()))), }; }, testRunner: async (pks) => { From fcdb61b19385f3cd869571e3aaf329e609954ec0 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Thu, 3 Dec 2020 20:17:28 +0400 Subject: [PATCH 2/7] Fix aggregate sigs. --- benchmark/noble.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmark/noble.ts b/benchmark/noble.ts index eb223d0..e67a162 100644 --- a/benchmark/noble.ts +++ b/benchmark/noble.ts @@ -113,8 +113,8 @@ import {aggCount, runsNoble} from "./params"; input: await Promise.all(range(aggCount).map(() => noble.PointG2.hashToCurve(generateRandomSecretKey()))), }; }, - testRunner: async (pks) => { - noble.aggregatePublicKeys(pks); + testRunner: async (sigs) => { + noble.aggregateSignatures(sigs); }, runs: runsNoble, }); From 78c289cb21d7cdca5e095149b8b7b1eb728936dd Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Thu, 3 Dec 2020 20:18:13 +0400 Subject: [PATCH 3/7] Update noble. --- benchmark/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/package.json b/benchmark/package.json index 4b404a9..0ffe6e3 100644 --- a/benchmark/package.json +++ b/benchmark/package.json @@ -8,6 +8,6 @@ "benchmark:all": "ts-node index && ts-node noble" }, "dependencies": { - "noble-bls12-381": "^0.6.1" + "noble-bls12-381": "^0.7.1" } } From e995e07fbb6957aa8de14f15e52f1cc930862770 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Thu, 3 Dec 2020 20:22:28 +0400 Subject: [PATCH 4/7] Fix conflicts --- benchmark/noble.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/benchmark/noble.ts b/benchmark/noble.ts index e67a162..3ae821a 100644 --- a/benchmark/noble.ts +++ b/benchmark/noble.ts @@ -118,4 +118,19 @@ import {aggCount, runsNoble} from "./params"; }, runs: runsNoble, }); + + await runBenchmark<{sk: Uint8Array; msg: Uint8Array}, void>({ + id: `noble sign`, + + prepareTest: async () => ({ + input: { + sk: generateRandomSecretKey(), + msg: randomMessage(), + }, + }), + testRunner: async ({sk, msg}) => { + await noble.sign(msg, sk); + }, + runs: runsNoble, + }); })(); From 86c956e12a3026a1226f1fbcedd234ea8be60a0f Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Thu, 3 Dec 2020 23:37:42 +0400 Subject: [PATCH 5/7] Quick fix for types --- benchmark/runner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/runner.ts b/benchmark/runner.ts index 90bdaeb..bb9ca67 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: T) => PromiseOptional; + testRunner: (input: any) => PromiseOptional; runs?: number; id: string; }): Promise { From 94d8fce8157440569327c1d1d5db144753a9a1cc Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Fri, 4 Dec 2020 18:54:47 +0000 Subject: [PATCH 6/7] 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 { From a303f771203ce904d70b1b4ff804c06007d07c35 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Sat, 5 Dec 2020 11:13:40 +0400 Subject: [PATCH 7/7] Update package.json --- benchmark/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/package.json b/benchmark/package.json index 0ffe6e3..20e1c85 100644 --- a/benchmark/package.json +++ b/benchmark/package.json @@ -8,6 +8,6 @@ "benchmark:all": "ts-node index && ts-node noble" }, "dependencies": { - "noble-bls12-381": "^0.7.1" + "noble-bls12-381": "^0.7.2" } }