bls benchmarks
This commit is contained in:
parent
0e856d82b5
commit
75b9a3bedf
|
@ -30,7 +30,8 @@
|
||||||
"test:unit": "nyc --cache-dir .nyc_output/.cache -r lcov -e .ts mocha -r ./.babel-register 'test/unit/**/*.test.ts' && nyc report",
|
"test:unit": "nyc --cache-dir .nyc_output/.cache -r lcov -e .ts mocha -r ./.babel-register 'test/unit/**/*.test.ts' && nyc report",
|
||||||
"test:spec": "mocha -r ./.babel-register 'test/spec/**/*.test.ts'",
|
"test:spec": "mocha -r ./.babel-register 'test/spec/**/*.test.ts'",
|
||||||
"test": "yarn test:unit && yarn test:spec",
|
"test": "yarn test:unit && yarn test:spec",
|
||||||
"coverage": "codecov -F bls"
|
"coverage": "codecov -F bls",
|
||||||
|
"benchmark": "node -r ./.babel-register test/benchmarks"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@chainsafe/eth2.0-types": "^0.1.0",
|
"@chainsafe/eth2.0-types": "^0.1.0",
|
||||||
|
@ -49,11 +50,12 @@
|
||||||
"@babel/preset-typescript": "^7.3.3",
|
"@babel/preset-typescript": "^7.3.3",
|
||||||
"@babel/register": "^7.0.0",
|
"@babel/register": "^7.0.0",
|
||||||
"@babel/runtime": "^7.4.4",
|
"@babel/runtime": "^7.4.4",
|
||||||
|
"@chainsafe/benchmark-utils": "^0.1.0",
|
||||||
"@chainsafe/eth2.0-spec-test-util": "^0.2.3",
|
"@chainsafe/eth2.0-spec-test-util": "^0.2.3",
|
||||||
"@types/assert": "^1.4.2",
|
"@types/assert": "^1.4.2",
|
||||||
"@types/chai": "^4.1.7",
|
"@types/chai": "^4.1.7",
|
||||||
"@types/mocha": "^5.2.5",
|
"@types/mocha": "^5.2.5",
|
||||||
"@types/node": "^10.12.17",
|
"@types/node": "^12.7.2",
|
||||||
"@typescript-eslint/eslint-plugin": "^1.3.0",
|
"@typescript-eslint/eslint-plugin": "^1.3.0",
|
||||||
"@typescript-eslint/parser": "^1.3.0",
|
"@typescript-eslint/parser": "^1.3.0",
|
||||||
"babel-plugin-rewire-exports": "^1.1.0",
|
"babel-plugin-rewire-exports": "^1.1.0",
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
// Import benchmarks
|
||||||
|
import * as suites from "./suites";
|
||||||
|
import {createReportDir, runSuite} from "@chainsafe/benchmark-utils";
|
||||||
|
// Create file
|
||||||
|
const directory: string = createReportDir();
|
||||||
|
|
||||||
|
|
||||||
|
// Run benchmarks
|
||||||
|
Object.values(suites).forEach((suite) => {
|
||||||
|
runSuite(suite(directory));
|
||||||
|
});
|
|
@ -0,0 +1,5 @@
|
||||||
|
export {verifyInValidSignatureBenchmark} from './verifyInValidSignature';
|
||||||
|
export {verifyValidSignatureBenchmark} from './verifyValidSignature';
|
||||||
|
export {verifyValidAggregatedSignature} from './verifyValidAggregatedSignature';
|
||||||
|
export {verifyInvalidAggregatedSignature} from './verifyInvalidAggregatedSignature';
|
||||||
|
export {aggregateSignaturesBenchmark} from './signatureAggregation';
|
|
@ -0,0 +1,39 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires */
|
||||||
|
|
||||||
|
import {BenchSuite} from "@chainsafe/benchmark-utils";
|
||||||
|
import {aggregateSignatures} from "../../../src";
|
||||||
|
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||||
|
declare namespace global {
|
||||||
|
export let signatures: Buffer[];
|
||||||
|
export let aggregateSignatures: Function;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
global.require = require;
|
||||||
|
|
||||||
|
global.aggregateSignatures = aggregateSignatures;
|
||||||
|
|
||||||
|
export function aggregateSignaturesBenchmark(dir: string): BenchSuite {
|
||||||
|
|
||||||
|
// Set the function test
|
||||||
|
const FUNCTION_NAME = "verifyValidSignature"; // PLEASE FILL THIS OUT
|
||||||
|
|
||||||
|
const aggregateSignatures = function (): void {
|
||||||
|
global.aggregateSignatures(global.signatures);
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
testFunctions: [aggregateSignatures],
|
||||||
|
setup: function() {
|
||||||
|
global.signatures = [];
|
||||||
|
const {Keypair} = require("../../../src");
|
||||||
|
const {sha256} = require('js-sha256');
|
||||||
|
const keypair = Keypair.generate();
|
||||||
|
const message = Buffer.from(sha256.arrayBuffer(Math.random().toString(36)));
|
||||||
|
global.signatures.push(keypair.privateKey.signMessage(Buffer.from(message), Buffer.alloc(8)).toBytesCompressed());
|
||||||
|
},
|
||||||
|
file: dir + FUNCTION_NAME + ".txt"
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
import {BenchSuite} from "@chainsafe/benchmark-utils";
|
||||||
|
import {verify} from "../../../src";
|
||||||
|
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||||
|
declare namespace global {
|
||||||
|
export let domain: Buffer;
|
||||||
|
export let message: Buffer;
|
||||||
|
export let signature: Buffer;
|
||||||
|
export let publicKey: Buffer;
|
||||||
|
export let verify: Function;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
global.require = require;
|
||||||
|
|
||||||
|
global.domain = Buffer.alloc(8);
|
||||||
|
global.verify = verify;
|
||||||
|
|
||||||
|
export function verifyInValidSignatureBenchmark(dir: string): BenchSuite {
|
||||||
|
|
||||||
|
// Set the function test
|
||||||
|
const FUNCTION_NAME = "verifyInValidSignature"; // PLEASE FILL THIS OUT
|
||||||
|
|
||||||
|
const verifyInValidSignature = function (): void {
|
||||||
|
global.verify(global.publicKey, global.message, global.signature, global.domain);
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
testFunctions: [verifyInValidSignature],
|
||||||
|
setup: function() {
|
||||||
|
const {Keypair} = require("../../../src");
|
||||||
|
const {sha256} = require('js-sha256');
|
||||||
|
const keypair = Keypair.generate();
|
||||||
|
const keypair2 = Keypair.generate();
|
||||||
|
global.publicKey = keypair2.publicKey.toBytesCompressed();
|
||||||
|
global.message = Buffer.from(sha256.arrayBuffer(Math.random().toString(36)));
|
||||||
|
global.signature = keypair.privateKey.signMessage(Buffer.from(global.message), global.domain).toBytesCompressed();
|
||||||
|
},
|
||||||
|
file: dir + FUNCTION_NAME + ".txt"
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
import {BenchSuite} from "@chainsafe/benchmark-utils";
|
||||||
|
import {aggregateSignatures, verifyMultiple} from "../../../src";
|
||||||
|
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||||
|
declare namespace global {
|
||||||
|
export let domain: Buffer;
|
||||||
|
export let messages: Buffer[];
|
||||||
|
export let signature: Buffer;
|
||||||
|
export let publicKeys: Buffer[];
|
||||||
|
export let verify: Function;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
global.require = require;
|
||||||
|
|
||||||
|
global.domain = Buffer.alloc(8);
|
||||||
|
global.verify = verifyMultiple;
|
||||||
|
|
||||||
|
export function verifyInvalidAggregatedSignature(dir: string): BenchSuite {
|
||||||
|
|
||||||
|
// Set the function test
|
||||||
|
const FUNCTION_NAME = "verifyInvalidAggregatedSignature"; // PLEASE FILL THIS OUT
|
||||||
|
|
||||||
|
const verifyInvalidAggregatedSignature = function (): void {
|
||||||
|
global.verify(global.publicKeys, global.messages, global.signature, global.domain);
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
testFunctions: [verifyInvalidAggregatedSignature],
|
||||||
|
setup: function() {
|
||||||
|
const {Keypair, aggregateSignatures} = require("../../../src");
|
||||||
|
const {sha256} = require('js-sha256');
|
||||||
|
const signatures = [];
|
||||||
|
global.publicKeys = [];
|
||||||
|
const message = Buffer.from(sha256.arrayBuffer(Math.random().toString(36)));
|
||||||
|
const message2 = Buffer.from(sha256.arrayBuffer(Math.random().toString(36)));
|
||||||
|
for(let i = 0; i < 128; i++) {
|
||||||
|
const keypair = Keypair.generate();
|
||||||
|
global.publicKeys.push(keypair.publicKey.toBytesCompressed());
|
||||||
|
signatures.push(keypair.privateKey.signMessage(Buffer.from(message), global.domain).toBytesCompressed());
|
||||||
|
}
|
||||||
|
global.messages = global.publicKeys.map(() => message2);
|
||||||
|
global.signature = aggregateSignatures(signatures);
|
||||||
|
},
|
||||||
|
file: dir + FUNCTION_NAME + ".txt"
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
import {BenchSuite} from "@chainsafe/benchmark-utils";
|
||||||
|
import {aggregateSignatures, verifyMultiple} from "../../../src";
|
||||||
|
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||||
|
declare namespace global {
|
||||||
|
export let domain: Buffer;
|
||||||
|
export let messages: Buffer[];
|
||||||
|
export let signature: Buffer;
|
||||||
|
export let publicKeys: Buffer[];
|
||||||
|
export let verify: Function;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
global.require = require;
|
||||||
|
|
||||||
|
global.domain = Buffer.alloc(8);
|
||||||
|
global.verify = verifyMultiple;
|
||||||
|
|
||||||
|
export function verifyValidAggregatedSignature(dir: string): BenchSuite {
|
||||||
|
|
||||||
|
// Set the function test
|
||||||
|
const FUNCTION_NAME = "verifyValidAggregatedSignature"; // PLEASE FILL THIS OUT
|
||||||
|
|
||||||
|
const verifyValidAggregatedSignature = function (): void {
|
||||||
|
global.verify(global.publicKeys, global.messages, global.signature, global.domain);
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
testFunctions: [verifyValidAggregatedSignature],
|
||||||
|
setup: function() {
|
||||||
|
const {Keypair, aggregateSignatures} = require("../../../src");
|
||||||
|
const {sha256} = require('js-sha256');
|
||||||
|
const signatures = [];
|
||||||
|
global.publicKeys = [];
|
||||||
|
const message = Buffer.from(sha256.arrayBuffer(Math.random().toString(36)));
|
||||||
|
for(let i = 0; i < 128; i++) {
|
||||||
|
const keypair = Keypair.generate();
|
||||||
|
global.publicKeys.push(keypair.publicKey.toBytesCompressed());
|
||||||
|
signatures.push(keypair.privateKey.signMessage(Buffer.from(message), global.domain).toBytesCompressed());
|
||||||
|
}
|
||||||
|
global.messages = global.publicKeys.map(() => message);
|
||||||
|
global.signature = aggregateSignatures(signatures);
|
||||||
|
global.publicKeys.map(() => message);
|
||||||
|
},
|
||||||
|
file: dir + FUNCTION_NAME + ".txt"
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires */
|
||||||
|
|
||||||
|
import {BenchSuite} from "@chainsafe/benchmark-utils";
|
||||||
|
import {verify} from "../../../src";
|
||||||
|
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||||
|
declare namespace global {
|
||||||
|
export let domain: Buffer;
|
||||||
|
export let message: Buffer;
|
||||||
|
export let signature: Buffer;
|
||||||
|
export let publicKey: Buffer;
|
||||||
|
export let verify: Function;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
global.require = require;
|
||||||
|
|
||||||
|
global.domain = Buffer.alloc(8);
|
||||||
|
global.verify = verify;
|
||||||
|
|
||||||
|
export function verifyValidSignatureBenchmark(dir: string): BenchSuite {
|
||||||
|
|
||||||
|
// Set the function test
|
||||||
|
const FUNCTION_NAME = "verifyValidSignature"; // PLEASE FILL THIS OUT
|
||||||
|
|
||||||
|
const verifyValidSignature = function (): void {
|
||||||
|
global.verify(global.publicKey, global.message, global.signature, global.domain);
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
testFunctions: [verifyValidSignature],
|
||||||
|
setup: function() {
|
||||||
|
const {Keypair} = require("../../../src");
|
||||||
|
const {sha256} = require('js-sha256');
|
||||||
|
const keypair = Keypair.generate();
|
||||||
|
global.publicKey = keypair.publicKey.toBytesCompressed();
|
||||||
|
global.message = Buffer.from(sha256.arrayBuffer(Math.random().toString(36)));
|
||||||
|
global.signature = keypair.privateKey.signMessage(Buffer.from(global.message), global.domain).toBytesCompressed();
|
||||||
|
},
|
||||||
|
file: dir + FUNCTION_NAME + ".txt"
|
||||||
|
};
|
||||||
|
}
|
Reference in New Issue