-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add blst bindings #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
spiral-ladder
wants to merge
26
commits into
main
Choose a base branch
from
bing/blst-bun
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,584
−1
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
aa6617b
add blst
spiral-ladder b898003
fix bindings
spiral-ladder 44a2415
feat: move blst tests
spiral-ladder 159a5e7
clean up blst dep
spiral-ladder 4e2fb84
rm blst/.benchrc.yaml
spiral-ladder 03096d3
remove redundant code
spiral-ladder 71b55a9
remove misisng file from export
spiral-ladder 39bbcb5
centralize blst exports at src/blst.ts
spiral-ladder 21b021c
update build.zig.zon
spiral-ladder 5cbeb80
remove seemingly redundant commented out code
spiral-ladder 6141690
remove commented out code in aggregatedWithRandomness.test.ts
spiral-ladder 229168b
remove afterAll closeBinding in tests
spiral-ladder 4762165
use toEqual for deep equals
spiral-ladder 000b4d3
remove benchmark TODO in verifyMultipleAggregateSignatures
spiral-ladder f3c671a
remove more comments
spiral-ladder b26d201
update blst
spiral-ladder 8b1e5f8
chore: move blst dependency in alpha order
wemeetagain 9b53bb7
chore: simplify hex utils
wemeetagain 7926626
chore: small import cleanup
wemeetagain 361b6a2
feat: add some blst benchmarks
wemeetagain 69bfae9
use new aggregateverify (#21)
spiral-ladder d85fc71
fix blst
spiral-ladder b62e36c
regen bindings
spiral-ladder 81f6198
fix bun-ffi-z dep
spiral-ladder 6e849dc
update blst
spiral-ladder 1a1a0d6
blst(bun): init memory pool before tests
spiral-ladder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,249 @@ | ||
| import { describe, bench } from "@chainsafe/benchmark"; | ||
|
|
||
| import * as blst from "../src/blst.ts"; | ||
| import * as other from "@chainsafe/blst"; | ||
|
|
||
| describe("blst", () => { | ||
| const ikm = new Uint8Array(32); | ||
| // bench("blst - keygen", () => { | ||
| // blst.SecretKey.fromKeygen(ikm); | ||
| // }); | ||
| // bench("other - keygen", () => { | ||
| // other.SecretKey.fromKeygen(ikm); | ||
| // }); | ||
| // | ||
| // bench({ | ||
| // id: "blst - sign", | ||
| // beforeEach: () => { | ||
| // const sk = blst.SecretKey.fromKeygen(ikm); | ||
| // return { sk, msg: new Uint8Array(32) }; | ||
| // }, | ||
| // fn: ({ sk, msg }) => { | ||
| // sk.sign(msg); | ||
| // }, | ||
| // }); | ||
| // bench({ | ||
| // id: "other - sign", | ||
| // beforeEach: () => { | ||
| // const sk = other.SecretKey.fromKeygen(ikm); | ||
| // return { sk, msg: new Uint8Array(32) }; | ||
| // }, | ||
| // fn: ({ sk, msg }) => { | ||
| // sk.sign(msg); | ||
| // }, | ||
| // }); | ||
| // | ||
| // bench({ | ||
| // id: "blst - verify", | ||
| // beforeEach: () => { | ||
| // const sk = blst.SecretKey.fromKeygen(ikm); | ||
| // const pk = sk.toPublicKey(); | ||
| // const msg = new Uint8Array(32); | ||
| // const sig = sk.sign(msg); | ||
| // return { pk, msg, sig }; | ||
| // }, | ||
| // fn: ({ pk, msg, sig }) => { | ||
| // sig.verify(msg, pk, true, true); | ||
| // }, | ||
| // }); | ||
| // bench({ | ||
| // id: "other - verify", | ||
| // beforeEach: () => { | ||
| // const sk = other.SecretKey.fromKeygen(ikm); | ||
| // const pk = sk.toPublicKey(); | ||
| // const msg = new Uint8Array(32); | ||
| // const sig = sk.sign(msg); | ||
| // return { pk, msg, sig }; | ||
| // }, | ||
| // fn: ({ pk, msg, sig }) => { | ||
| // other.verify(msg, pk, sig, true, true); | ||
| // }, | ||
| // }); | ||
|
|
||
| bench({ | ||
| id: "blst - aggregateVerify 1", | ||
| beforeEach: () => { | ||
| const sks = []; | ||
| const pks = []; | ||
| const sigs = []; | ||
| const msgs = []; | ||
| for (let i = 0; i < 1; i++) { | ||
| const sk = blst.SecretKey.fromKeygen(ikm); | ||
| sks.push(sk); | ||
| pks.push(sk.toPublicKey()); | ||
| const msg = new Uint8Array(32); | ||
| msgs.push(msg); | ||
| sigs.push(sk.sign(msg)); | ||
| } | ||
| const aggSig = blst.aggregateSignatures(sigs, true); | ||
| blst.init(); | ||
| return { pks, msgs, aggSig }; | ||
| }, | ||
| fn: ({ pks, msgs, aggSig }) => { | ||
| aggSig.aggregateVerify(msgs, pks, true, true); | ||
| }, | ||
| }); | ||
| bench({ | ||
| id: "other - aggregateVerify 1", | ||
| beforeEach: () => { | ||
| const sks = []; | ||
| const pks = []; | ||
| const sigs = []; | ||
| const msgs = []; | ||
| for (let i = 0; i < 1; i++) { | ||
| const sk = other.SecretKey.fromKeygen(ikm); | ||
| sks.push(sk); | ||
| pks.push(sk.toPublicKey()); | ||
| const msg = new Uint8Array(32); | ||
| msgs.push(msg); | ||
| sigs.push(sk.sign(msg)); | ||
| } | ||
| const aggSig = other.aggregateSignatures(sigs, true); | ||
| return { pks, msgs, aggSig }; | ||
| }, | ||
| fn: ({ pks, msgs, aggSig }) => { | ||
| other.aggregateVerify(msgs, pks, aggSig, true, true); | ||
| }, | ||
| }); | ||
|
|
||
| bench({ | ||
| id: "blst - aggregateVerify 16", | ||
| beforeEach: () => { | ||
| const sks = []; | ||
| const pks = []; | ||
| const sigs = []; | ||
| const msgs = []; | ||
| for (let i = 0; i < 16; i++) { | ||
| const sk = blst.SecretKey.fromKeygen(ikm); | ||
| sks.push(sk); | ||
| pks.push(sk.toPublicKey()); | ||
| const msg = new Uint8Array(32); | ||
| msgs.push(msg); | ||
| sigs.push(sk.sign(msg)); | ||
| } | ||
| const aggSig = blst.aggregateSignatures(sigs, true); | ||
| blst.init(); | ||
| return { pks, msgs, aggSig }; | ||
| }, | ||
| fn: ({ pks, msgs, aggSig }) => { | ||
| aggSig.aggregateVerify(msgs, pks, true, true); | ||
| }, | ||
| }); | ||
| bench({ | ||
| id: "other - aggregateVerify 16", | ||
| beforeEach: () => { | ||
| const sks = []; | ||
| const pks = []; | ||
| const sigs = []; | ||
| const msgs = []; | ||
| for (let i = 0; i < 16; i++) { | ||
| const sk = other.SecretKey.fromKeygen(ikm); | ||
| sks.push(sk); | ||
| pks.push(sk.toPublicKey()); | ||
| const msg = new Uint8Array(32); | ||
| msgs.push(msg); | ||
| sigs.push(sk.sign(msg)); | ||
| } | ||
| const aggSig = other.aggregateSignatures(sigs, true); | ||
| return { pks, msgs, aggSig }; | ||
| }, | ||
| fn: ({ pks, msgs, aggSig }) => { | ||
| other.aggregateVerify(msgs, pks, aggSig, true, true); | ||
| }, | ||
| }); | ||
|
|
||
| bench({ | ||
| id: "blst - aggregateVerify 32", | ||
| beforeEach: () => { | ||
| const sks = []; | ||
| const pks = []; | ||
| const sigs = []; | ||
| const msgs = []; | ||
| for (let i = 0; i < 32; i++) { | ||
| const sk = blst.SecretKey.fromKeygen(ikm); | ||
| sks.push(sk); | ||
| pks.push(sk.toPublicKey()); | ||
| const msg = new Uint8Array(32); | ||
| msgs.push(msg); | ||
| sigs.push(sk.sign(msg)); | ||
| } | ||
| const aggSig = blst.aggregateSignatures(sigs, true); | ||
| blst.init(); | ||
| return { pks, msgs, aggSig }; | ||
| }, | ||
| fn: ({ pks, msgs, aggSig }) => { | ||
| aggSig.aggregateVerify(msgs, pks, true, true); | ||
| }, | ||
| }); | ||
| bench({ | ||
| id: "other - aggregateVerify 32", | ||
| beforeEach: () => { | ||
| const sks = []; | ||
| const pks = []; | ||
| const sigs = []; | ||
| const msgs = []; | ||
| for (let i = 0; i < 32; i++) { | ||
| const sk = other.SecretKey.fromKeygen(ikm); | ||
| sks.push(sk); | ||
| pks.push(sk.toPublicKey()); | ||
| const msg = new Uint8Array(32); | ||
| msgs.push(msg); | ||
| sigs.push(sk.sign(msg)); | ||
| } | ||
| const aggSig = other.aggregateSignatures(sigs, true); | ||
| return { pks, msgs, aggSig }; | ||
| }, | ||
| fn: ({ pks, msgs, aggSig }) => { | ||
| other.aggregateVerify(msgs, pks, aggSig, true, true); | ||
| }, | ||
| }); | ||
|
|
||
| bench({ | ||
| id: "blst - aggregateVerify 128", | ||
| beforeEach: () => { | ||
| const sks = []; | ||
| const pks = []; | ||
| const sigs = []; | ||
| const msgs = []; | ||
| for (let i = 0; i < 128; i++) { | ||
| const sk = blst.SecretKey.fromKeygen(ikm); | ||
| sks.push(sk); | ||
| pks.push(sk.toPublicKey()); | ||
| const msg = new Uint8Array(32); | ||
| msgs.push(msg); | ||
| sigs.push(sk.sign(msg)); | ||
| } | ||
| const aggSig = blst.aggregateSignatures(sigs, true); | ||
| blst.init(); | ||
| return { pks, msgs, aggSig }; | ||
| }, | ||
| fn: ({ pks, msgs, aggSig }) => { | ||
| aggSig.aggregateVerify(msgs, pks, true, true); | ||
| }, | ||
| }); | ||
| bench({ | ||
| id: "other - aggregateVerify 128", | ||
| beforeEach: () => { | ||
| const sks = []; | ||
| const pks = []; | ||
| const sigs = []; | ||
| const msgs = []; | ||
| for (let i = 0; i < 128; i++) { | ||
| const sk = other.SecretKey.fromKeygen(ikm); | ||
| sks.push(sk); | ||
| pks.push(sk.toPublicKey()); | ||
| const msg = new Uint8Array(32); | ||
| msgs.push(msg); | ||
| sigs.push(sk.sign(msg)); | ||
| } | ||
| const aggSig = other.aggregateSignatures(sigs, true); | ||
| return { pks, msgs, aggSig }; | ||
| }, | ||
| fn: ({ pks, msgs, aggSig }) => { | ||
| other.aggregateVerify(msgs, pks, aggSig, true, true); | ||
| }, | ||
| }); | ||
|
|
||
|
|
||
| }); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| "devDependencies": { | ||
| "@chainsafe/as-sha256": "^1.2.0", | ||
| "@chainsafe/benchmark": "^2.0.1", | ||
| "@chainsafe/blst": "^2.2.0", | ||
| "@chainsafe/hashtree": "^1.0.2", | ||
| "@types/bun": "latest", | ||
| "@types/snappyjs": "^0.7.1", | ||
|
|
@@ -68,6 +69,21 @@ | |
| "@chainsafe/benchmark": ["@chainsafe/[email protected]", "", { "dependencies": { "@actions/cache": "^4.0.0", "@actions/github": "^6.0.0", "@vitest/runner": "^2.1.8", "ajv": "^8.17.1", "aws-sdk": "^2.932.0", "cli-table3": "^0.6.5", "csv-parse": "^5.6.0", "csv-stringify": "^6.5.2", "debug": "^4.4.0", "glob": "^10.4.5", "log-symbols": "^7.0.0", "yaml": "^2.7.0", "yargs": "^17.7.2" }, "bin": { "benchmark": "bin/index.js" } }, "sha512-Noecu9z6kjXWdKl9ZL/PckJxfi+Ax4/8/i4F862jo3FZcViK8LWR5Byc8pKeNC5vcDMSP73/ME3vgUovYGqwUw=="], | ||
|
|
||
| "@chainsafe/bun-ffi-z": ["@chainsafe/[email protected]", "", { "peerDependencies": { "typescript": "^5" }, "bin": { "bun-ffi-z": "src/cli.ts" } }, "sha512-nmiRudOInH2JQk32FEyOq/VeBftKuHxP44TYd345xCdZKv2j4ajecM6IZ9SzTQTNozFqt7gCsnWINJXYikfRzw=="], | ||
| "@chainsafe/blst": ["@chainsafe/[email protected]", "", { "optionalDependencies": { "@chainsafe/blst-darwin-arm64": "2.2.0", "@chainsafe/blst-darwin-x64": "2.2.0", "@chainsafe/blst-linux-arm64-gnu": "2.2.0", "@chainsafe/blst-linux-arm64-musl": "2.2.0", "@chainsafe/blst-linux-x64-gnu": "2.2.0", "@chainsafe/blst-linux-x64-musl": "2.2.0", "@chainsafe/blst-win32-x64-msvc": "2.2.0" } }, "sha512-VBaQoNE2a9d9+skAjQKv3Suk0yGKqp3mZM0YWYJNPj/Ae/f6lAyeVSgKqo2LrsNQBzD/LqrJLKUY8rJT3vDKLA=="], | ||
|
|
||
| "@chainsafe/blst-darwin-arm64": ["@chainsafe/[email protected]", "", { "os": "darwin", "cpu": "arm64" }, "sha512-BOOy2KHbV028cioPWaAMqHdLRKd6/3XyEmUEcQC2E/SpyYLdNcaKiBUYIU4pT9CrWBbJJxX68UI+3vZVg0M8/w=="], | ||
|
|
||
| "@chainsafe/blst-darwin-x64": ["@chainsafe/[email protected]", "", { "os": "darwin", "cpu": "x64" }, "sha512-jG64cwIdPT7u/haRrW26tWCpfMfHBQCfGY169mFQifCwO4VEwvaiVBPOh5olFis6LjpcmD+O0jpM8GqrnsmUHQ=="], | ||
|
|
||
| "@chainsafe/blst-linux-arm64-gnu": ["@chainsafe/[email protected]", "", { "os": "linux", "cpu": "arm64" }, "sha512-L8xV2uuLn8we76vdzfryS9ePdheuZrmY6yArGUFaF1Uzcwml6V1/VvyPl9/uooo/YfVRIrvF/D+lQfI2GFAnhw=="], | ||
|
|
||
| "@chainsafe/blst-linux-arm64-musl": ["@chainsafe/[email protected]", "", { "os": "linux", "cpu": "arm64" }, "sha512-0Vn0luxLYVgC3lvWT1MapFHSAoz99PldqjhilXTGv0AcAk/X5LXPH2RC9Dp2KJGqthyUkpbk1j47jUBfBI+BIg=="], | ||
|
|
||
| "@chainsafe/blst-linux-x64-gnu": ["@chainsafe/[email protected]", "", { "os": "linux", "cpu": "x64" }, "sha512-gEY/z2SDBA7kXtFEI9VNhWTJAIjx16jdeAyCaS2k4ACGurWZaWk+Ee4KniTsr4WieSqeuNTUr7Pdja0Sr4EKNQ=="], | ||
|
|
||
| "@chainsafe/blst-linux-x64-musl": ["@chainsafe/[email protected]", "", { "os": "linux", "cpu": "x64" }, "sha512-58GKtiUmtVSuerRzPEcMNQZpICPboBKFnL7+1Wo+PSuajkvbae7tEFrFTtWeMoKIPgOEsPMnk96LF+0yNgavUg=="], | ||
|
|
||
| "@chainsafe/blst-win32-x64-msvc": ["@chainsafe/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-UFrZshl4dfX5Uh2zeKXAZtrkQ+otczHMON2tsrapQNICWmfHZrzE6pKuBL+9QeGAbgflwpbz7+D5nQRDpiuHxQ=="], | ||
|
|
||
| "@chainsafe/hashtree": ["@chainsafe/[email protected]", "", { "optionalDependencies": { "@chainsafe/hashtree-darwin-arm64": "1.0.2", "@chainsafe/hashtree-linux-arm64-gnu": "1.0.2", "@chainsafe/hashtree-linux-arm64-musl": "1.0.2", "@chainsafe/hashtree-linux-x64-gnu": "1.0.2", "@chainsafe/hashtree-linux-x64-musl": "1.0.2", "@chainsafe/hashtree-win32-x64-msvc": "1.0.2" } }, "sha512-OaWjsZ6S/GaT2RvaqdpsF5Mux8qQOE2KbitX2yHmQJZNUZkdh7C3N4PA5LsvewqX+z8Nkv8mr1uSe0LSrHGiQw=="], | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this code be deduped a bit?
even just a for loop with the various number of signatures/messages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure, this was supposed to be temporary so I quickly did this. The version before was pretty concise, I'll switch to that