Merge pull request #62 from paulmillr/patch-3

Benchmarks: update noble to use decompressed points.
This commit is contained in:
Cayman 2020-12-07 15:03:27 -07:00 committed by GitHub
commit 65cb5f2f35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 22 deletions

View File

@ -7,17 +7,17 @@ import {aggCount, runsNoble} from "./params";
(async function () { (async function () {
// verify // 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`, id: `noble verify`,
prepareTest: async () => { prepareTest: async () => {
const priv = generateRandomSecretKey(); const priv = generateRandomSecretKey();
const msg = randomMessage(); const msg = randomMessage();
const sig = await noble.sign(msg, priv); const pk = noble.PointG1.fromPrivateKey(priv);
const pk = noble.getPublicKey(priv); const sig = noble.PointG2.fromSignature(await noble.sign(msg, priv));
return { return {
input: {pk, msg, sig}, input: {pk, msg: await noble.PointG2.hashToCurve(msg), sig},
resultCheck: (valid: boolean) => valid === true, resultCheck: (valid: boolean) => valid === true,
}; };
}, },
@ -29,7 +29,7 @@ import {aggCount, runsNoble} from "./params";
// Fast aggregate // 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})`, id: `noble verifyAggregate (${aggCount})`,
prepareTest: async () => { prepareTest: async () => {
@ -37,46 +37,46 @@ import {aggCount, runsNoble} from "./params";
const dataArr = await Promise.all( const dataArr = await Promise.all(
range(aggCount).map(async () => { range(aggCount).map(async () => {
const sk = generateRandomSecretKey(); const sk = generateRandomSecretKey();
const pk = noble.getPublicKey(sk); const pk = noble.PointG1.fromPrivateKey(sk);
const sig = await noble.sign(msg, sk); const sig = noble.PointG2.fromSignature(await noble.sign(msg, sk));
return {pk, sig}; return {pk, sig};
}) })
); );
const pks = dataArr.map((data) => data.pk); 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 any as noble.PointG2;
return { return {
input: {pks, msg, sig}, input: {pks, msg: await noble.PointG2.hashToCurve(msg), sig},
resultCheck: (valid: boolean) => valid === true, resultCheck: (valid: boolean) => valid === true,
}; };
}, },
testRunner: async ({pks, msg, sig}) => { 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); return await noble.verify(sig, msg, pk);
}, },
runs: runsNoble, runs: runsNoble,
}); });
// Verify multiple // // 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})`, id: `noble verifyMultiple (${aggCount})`,
prepareTest: async () => { prepareTest: async () => {
const dataArr = await Promise.all( const dataArr = await Promise.all(
range(aggCount).map(async () => { range(aggCount).map(async () => {
const sk = generateRandomSecretKey(); const sk = generateRandomSecretKey();
const pk = noble.getPublicKey(sk); const pk = noble.PointG1.fromPrivateKey(sk);
const msg = randomMessage(); const msg = randomMessage();
const sig = await noble.sign(msg, sk); const sig = noble.PointG2.fromSignature(await noble.sign(msg, sk));
return {pk, msg, sig}; return {pk, msg: await noble.PointG2.hashToCurve(msg), sig};
}) })
); );
const pks = dataArr.map((data) => data.pk); const pks = dataArr.map((data) => data.pk);
const msgs = dataArr.map((data) => data.msg); 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 { return {
input: {pks, msgs, sig}, input: {pks, msgs, sig},
@ -91,12 +91,12 @@ import {aggCount, runsNoble} from "./params";
// Aggregate pubkeys // Aggregate pubkeys
await runBenchmark<Uint8Array[], void>({ await runBenchmark<noble.PointG1[], void>({
id: `noble aggregate pubkeys (${aggCount})`, id: `noble aggregate pubkeys (${aggCount})`,
prepareTest: () => { prepareTest: () => {
return { return {
input: range(aggCount).map(() => noble.getPublicKey(generateRandomSecretKey())), input: range(aggCount).map(() => noble.PointG1.fromPrivateKey(generateRandomSecretKey())),
}; };
}, },
testRunner: async (pks) => { testRunner: async (pks) => {
@ -105,15 +105,28 @@ import {aggCount, runsNoble} from "./params";
runs: runsNoble, runs: runsNoble,
}); });
// Sign await runBenchmark<noble.PointG2[], void>({
id: `noble aggregate signatures (${aggCount})`,
await runBenchmark<{sk: Uint8Array; msg: Uint8Array}, void>({ 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`, id: `noble sign`,
prepareTest: async () => ({ prepareTest: async () => ({
input: { input: {
sk: generateRandomSecretKey(), sk: generateRandomSecretKey(),
msg: randomMessage(), msg: await noble.PointG2.hashToCurve(randomMessage()),
}, },
}), }),
testRunner: async ({sk, msg}) => { testRunner: async ({sk, msg}) => {

View File

@ -8,6 +8,6 @@
"benchmark:all": "ts-node index && ts-node noble" "benchmark:all": "ts-node index && ts-node noble"
}, },
"dependencies": { "dependencies": {
"noble-bls12-381": "^0.6.1" "noble-bls12-381": "^0.7.2"
} }
} }