Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
aa6617b
add blst
spiral-ladder Sep 30, 2025
b898003
fix bindings
spiral-ladder Sep 30, 2025
44a2415
feat: move blst tests
spiral-ladder Sep 30, 2025
159a5e7
clean up blst dep
spiral-ladder Sep 30, 2025
4e2fb84
rm blst/.benchrc.yaml
spiral-ladder Sep 30, 2025
03096d3
remove redundant code
spiral-ladder Sep 30, 2025
71b55a9
remove misisng file from export
spiral-ladder Sep 30, 2025
39bbcb5
centralize blst exports at src/blst.ts
spiral-ladder Sep 30, 2025
21b021c
update build.zig.zon
spiral-ladder Sep 30, 2025
5cbeb80
remove seemingly redundant commented out code
spiral-ladder Sep 30, 2025
6141690
remove commented out code in aggregatedWithRandomness.test.ts
spiral-ladder Sep 30, 2025
229168b
remove afterAll closeBinding in tests
spiral-ladder Sep 30, 2025
4762165
use toEqual for deep equals
spiral-ladder Sep 30, 2025
000b4d3
remove benchmark TODO in verifyMultipleAggregateSignatures
spiral-ladder Sep 30, 2025
f3c671a
remove more comments
spiral-ladder Sep 30, 2025
b26d201
update blst
spiral-ladder Sep 30, 2025
8b1e5f8
chore: move blst dependency in alpha order
wemeetagain Oct 16, 2025
9b53bb7
chore: simplify hex utils
wemeetagain Oct 16, 2025
7926626
chore: small import cleanup
wemeetagain Oct 16, 2025
361b6a2
feat: add some blst benchmarks
wemeetagain Oct 16, 2025
69bfae9
use new aggregateverify (#21)
spiral-ladder Oct 31, 2025
d85fc71
fix blst
spiral-ladder Oct 17, 2025
b62e36c
regen bindings
spiral-ladder Oct 31, 2025
81f6198
fix bun-ffi-z dep
spiral-ladder Oct 31, 2025
6e849dc
update blst
spiral-ladder Oct 31, 2025
1a1a0d6
blst(bun): init memory pool before tests
spiral-ladder Oct 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
249 changes: 249 additions & 0 deletions bench/blst.bench.ts
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({
Copy link
Member

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

Copy link
Contributor Author

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

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);
},
});


});

6 changes: 6 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const dep_blst = b.dependency("blst", .{
.optimize = optimize,
.target = target,
});

const dep_hashtree = b.dependency("hashtree", .{
.optimize = optimize,
.target = target,
Expand Down Expand Up @@ -77,5 +82,6 @@ pub fn build(b: *std.Build) void {
module_lodestar_z_bun.addImport("leveldb", dep_leveldb.module("leveldb"));
module_lodestar_z_bun.addImport("snappy", dep_snappy.module("snappy"));
module_lodestar_z_bun.addImport("state_transition", dep_state_transition.module("state_transition"));
module_lodestar_z_bun.addImport("blst", dep_blst.module("blst"));
module_lodestar_z_bun.addImport("ssz:persistent_merkle_tree", dep_ssz.module("persistent_merkle_tree"));
}
4 changes: 4 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
.fingerprint = 0xed854bdae2354180,
.minimum_zig_version = "0.14.1",
.dependencies = .{
.blst = .{
.url = "git+https://github.com/Chainsafe/blst-z#c92cf2fa111d4355f10a7f7c47d0a6efa258c006",
.hash = "blst_z-0.0.0-td3FNPboAAC58NCM4qPLn64RVh8hxIjD-0iVg-3J2y3L",
},
.hashtree = .{
.url = "git+https://github.com/chainsafe/hashtree-z#43a58b0fd4813515cda3d0ffc622125243a01c54",
.hash = "hashtree-0.1.0-sBOovrYSAAArAQVa-a6BhOPWPTrgKrJtufxWjQYMNNAN",
Expand Down
16 changes: 16 additions & 0 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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=="],

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
"exports": "./src/index.ts",
"scripts": {
"bench:files": "bun node_modules/.bin/benchmark",
"bench": "bun run bench:files bench/bytes.bench.ts",
"bench": "bun run bench:files",
"check": "tsc --noEmit",
"generate": "bun node_modules/.bin/bun-ffi-z generate-binding"
},
"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",
Expand Down
Loading