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 () {
// 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 () => {
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,
};
},
@ -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 () => {
@ -37,46 +37,46 @@ 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 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,
});
// 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})`,
prepareTest: async () => {
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};
})
);
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,12 +91,12 @@ import {aggCount, runsNoble} from "./params";
// Aggregate pubkeys
await runBenchmark<Uint8Array[], void>({
await runBenchmark<noble.PointG1[], void>({
id: `noble aggregate pubkeys (${aggCount})`,
prepareTest: () => {
return {
input: range(aggCount).map(() => noble.getPublicKey(generateRandomSecretKey())),
input: range(aggCount).map(() => noble.PointG1.fromPrivateKey(generateRandomSecretKey())),
};
},
testRunner: async (pks) => {
@ -105,15 +105,28 @@ import {aggCount, runsNoble} from "./params";
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`,
prepareTest: async () => ({
input: {
sk: generateRandomSecretKey(),
msg: randomMessage(),
msg: await noble.PointG2.hashToCurve(randomMessage()),
},
}),
testRunner: async ({sk, msg}) => {

View File

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