Skip to content
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

feat!: napi-rs binding #149

Merged
merged 142 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
9182d12
chore: add node 22 support
wemeetagain Jun 4, 2024
a72a898
chore: release v0.2.11
wemeetagain Jun 4, 2024
56bc9f1
feat: explore napi-rs binding
wemeetagain Jun 13, 2024
2ece252
feat: use signature sets in verifyMultipleAggregateSignatures
wemeetagain Jun 13, 2024
f9f386c
chore: fix batchVerify benchmark
wemeetagain Jun 13, 2024
f22a7c0
feat: simplify signature set handling, async functions
wemeetagain Jun 13, 2024
a74c710
wip
wemeetagain Jun 14, 2024
596a302
err handling
ec2 Jun 14, 2024
68bea80
chore: more cleanup
wemeetagain Jun 14, 2024
2b61c67
chore: use threads in blst crate
wemeetagain Jun 14, 2024
d9338a8
chore: add multithread benchmarks
wemeetagain Jun 15, 2024
953cfe0
feat rough out sigVerify and perf test
matthewkeil Jun 16, 2024
f21ec91
chore: more cleanup
wemeetagain Jun 17, 2024
f2a0fbe
feat: add keyValidate
wemeetagain Jun 17, 2024
4e294e9
chore: refresh index.d.ts
wemeetagain Jun 17, 2024
573f500
feat: add eip 2333 fns
wemeetagain Jun 17, 2024
d66802c
feat: add aggregateSerialized fns
wemeetagain Jun 17, 2024
6e2b25a
feat: add validation to from_bytes
wemeetagain Jun 17, 2024
6c723ba
chore: refresh index.d.ts
wemeetagain Jun 17, 2024
62021c5
chore: more cleanup
wemeetagain Jun 17, 2024
5e56106
chore: fix blstOpts benchmark
wemeetagain Jun 17, 2024
bb8ac3a
chore: more cleanup
wemeetagain Jun 17, 2024
0fd3570
feat: add hex helpers
wemeetagain Jun 17, 2024
4913912
fix: validation in factories
wemeetagain Jun 17, 2024
8b37df3
fix: default to sig_infcheck if sig_validate
wemeetagain Jun 17, 2024
81080fa
chore: fmt
wemeetagain Jun 17, 2024
223384d
feat: stringify BLST_ERROR
matthewkeil Jun 17, 2024
db1441c
feat: async aggregate* fns
wemeetagain Jun 18, 2024
1df06d4
chore: remove stray comment
wemeetagain Jun 18, 2024
8870f3e
feat: switch blst to matthewkeil fork for multiply_by
matthewkeil Jun 19, 2024
e408fe9
chore: update blst
matthewkeil Jun 19, 2024
d8ada41
chore: add settings.json so rust displays correctly
matthewkeil Jun 19, 2024
a8700e5
feat: add aggregate_with_randomness
matthewkeil Jun 19, 2024
cae50fd
chore: update blst
matthewkeil Jun 21, 2024
208415c
refactor: change aggregate_with_randomness implementation
matthewkeil Jun 21, 2024
2fa18b1
chore: use MultiPoint ops to do aggregate_with_randomness
wemeetagain Jun 23, 2024
bede4f0
chore: bench aggregation vs aggregate_with_randomness
wemeetagain Jun 23, 2024
e6c0d60
chore: add test aggregateWithMsm fn
wemeetagain Jun 23, 2024
1e04885
chore: update blst
matthewkeil Jun 23, 2024
ae4db61
chore: use blst bindings
matthewkeil Jun 23, 2024
5773a57
feat: implement to/from affine
matthewkeil Jun 23, 2024
f002234
feat: add verify_multiple_aggregate_signatures_same_message
wemeetagain Jun 24, 2024
9ff0a1b
chore: cleanup
wemeetagain Jun 29, 2024
8f97b71
chore: sig to Uint8Array everywhere
wemeetagain Jun 29, 2024
ba0ec86
chore: update napi-rs deps
wemeetagain Jun 30, 2024
192de79
feat: add verify_multiple_signatures_same_message_with_retries
wemeetagain Jul 1, 2024
0e4dd8f
fix: fix struct definition
wemeetagain Jul 1, 2024
65d467d
feat: add verify_multiple_signatures_same_messages_with_retries
wemeetagain Jul 1, 2024
d2145c8
chore: change the shape of same message set
wemeetagain Jul 1, 2024
0657730
fix: stray ref
wemeetagain Jul 2, 2024
8057918
chore: tweak shape of same msg set
wemeetagain Jul 2, 2024
f6e3780
chore: add index.d.ts
wemeetagain Jul 2, 2024
036a4c9
chore: update same msg shape
wemeetagain Jul 2, 2024
b266ea3
chore: use Signature instead of Uint8Array
wemeetagain Jul 2, 2024
0beec38
chore: optimize aggregate fns
wemeetagain Jul 3, 2024
6f0ff04
chore: update submodule
matthewkeil Jul 3, 2024
301a304
Revert "chore: optimize aggregate fns"
wemeetagain Jul 3, 2024
582a439
chore: fmt
wemeetagain Jul 3, 2024
6faeec8
chore: move napi-rs bindings to root
wemeetagain Jul 3, 2024
43f0e41
chore: replace tests
wemeetagain Jul 4, 2024
c9f725a
chore: start package.json cleanup
wemeetagain Jul 4, 2024
3463ef2
chore: start fixing CI
wemeetagain Jul 4, 2024
d742cf5
chore: fix blst path
wemeetagain Jul 4, 2024
709ed38
chore: get spec tests passing
wemeetagain Jul 4, 2024
e699baa
chore: remove experimental fns
wemeetagain Jul 4, 2024
f10063a
chore: better error codes
wemeetagain Jul 4, 2024
05a4182
chore: cleanup
wemeetagain Jul 4, 2024
8547d5a
chore: rebuild bindings
wemeetagain Jul 4, 2024
e6bc2cf
chore: simplify spec tests
wemeetagain Jul 4, 2024
d42bdf7
chore: comments
wemeetagain Jul 4, 2024
34b75f6
chore: simplify
wemeetagain Jul 4, 2024
23a5f46
chore: start fixing tests
wemeetagain Jul 4, 2024
aeac41d
chore: more test updates
wemeetagain Jul 4, 2024
e94c726
chore: pass unit tests
wemeetagain Jul 4, 2024
fc811de
chore: fix lint
wemeetagain Jul 4, 2024
876fa3e
chore: fix perf test
wemeetagain Jul 4, 2024
5a46596
chore: fix up package.json and CI
wemeetagain Jul 4, 2024
b6c7181
chore: more CI work
wemeetagain Jul 4, 2024
1a5a1fe
chore: more ci
wemeetagain Jul 5, 2024
c513488
chore: more ci
wemeetagain Jul 5, 2024
adf4420
chore: add test console.log
wemeetagain Jul 5, 2024
59c61f8
chore: update test
wemeetagain Jul 5, 2024
9308878
chore: tweak test
wemeetagain Jul 5, 2024
2ebe609
Merge branch 'cayman/napi-rs' into m
wemeetagain Jul 5, 2024
f059d58
chore: remove unused files
wemeetagain Jul 5, 2024
80b65df
feat: add compress for to_bytes and to_hex
matthewkeil Jul 6, 2024
5e2e290
test: add back tests for compressed/uncompressed
matthewkeil Jul 6, 2024
2e41038
test: add bindings.test
matthewkeil Jul 6, 2024
c21a30c
test: add case for showing which aggregate index is invalid
matthewkeil Jul 6, 2024
8a58bc7
chore: wip spec tests
wemeetagain Jul 6, 2024
7f3e23d
Merge remote-tracking branch 'origin/cayman/napi-rs' into cayman/napi-rs
wemeetagain Jul 6, 2024
4c96f1d
feat: build to_vec and fix to_hex
matthewkeil Jul 6, 2024
9d996c7
chore: fix spec test functions
wemeetagain Jul 6, 2024
f2eb4bd
chore: fix spec tests
wemeetagain Jul 6, 2024
5d6acac
chore: fix some unit tests
wemeetagain Jul 6, 2024
659f047
chore: remove stray import
wemeetagain Jul 6, 2024
5ef0c9a
test: check aggregateWithRandomness
matthewkeil Jul 7, 2024
18aab68
test: add invalid test case to verifyMultipleAggregateSignatures.test
matthewkeil Jul 7, 2024
a74f894
test: fix fuzz tests to get working
matthewkeil Jul 8, 2024
1259012
test: fix perf tests
matthewkeil Jul 8, 2024
6bb9792
fix: remove Promise.all from runWorkRequest
matthewkeil Jul 8, 2024
d6a9ed7
chore: some cleanup
wemeetagain Jul 8, 2024
d7174dd
chore: add separate invalid hex error status
wemeetagain Jul 8, 2024
b4d9e34
chore: move fns
wemeetagain Jul 8, 2024
10f761e
chore: remove verify_multiple_signatures_same_message
wemeetagain Jul 8, 2024
44a14d6
chore: better hex error msgs
wemeetagain Jul 8, 2024
e0f3d06
fix: create_rand_slice
wemeetagain Jul 11, 2024
d5d16c7
fix: bindings test
wemeetagain Jul 11, 2024
8b853d1
chore: revert license change
wemeetagain Jul 17, 2024
7cbaa64
fix: add compress false in __fixtures__
matthewkeil Jul 17, 2024
e3398d5
Apply suggestions from code review
wemeetagain Jul 18, 2024
22d0180
chore: remove yarn files
wemeetagain Jul 18, 2024
1f2e538
chore: use napi8
wemeetagain Jul 18, 2024
1d9b36e
chore: update yarn lock
wemeetagain Jul 18, 2024
b850568
chore: remove unused scripts
wemeetagain Jul 18, 2024
e921b82
chore: remove todo
wemeetagain Jul 18, 2024
a1be5a8
chore: refactor blst_error_to_reason
wemeetagain Jul 18, 2024
d5b3442
chore: cleanup spec test compatibility layer
wemeetagain Jul 18, 2024
cfcabfc
chore: remove default
wemeetagain Jul 18, 2024
23031c4
chore: add check for unstaged changes
wemeetagain Jul 18, 2024
5a47cc4
chore: pin node 22.4
wemeetagain Jul 18, 2024
bd3c889
chore: tweak workflow
wemeetagain Jul 18, 2024
524c361
chore: use to_le_bytes
wemeetagain Jul 18, 2024
52191be
chore: remove aggregate_with_randomness_native
wemeetagain Jul 18, 2024
fef413b
chore: update release workflow
wemeetagain Jul 18, 2024
f2c1ccb
chore: tweak workflow job names
wemeetagain Jul 18, 2024
051bac9
fix: package.json engines node16+
matthewkeil Jul 19, 2024
8bb18aa
chore: remove root utils folder
matthewkeil Jul 19, 2024
53a858f
Merge branch 'cayman/napi-rs' of github.com:ChainSafe/blst-ts into ca…
matthewkeil Jul 19, 2024
3bb0210
chore: cleanup .eslintrc.js
matthewkeil Jul 19, 2024
4409af6
chore: touch up tsconfig.json
matthewkeil Jul 19, 2024
3e7c221
docs: update CONTRIBUTING.md
matthewkeil Jul 19, 2024
56280fa
Update README.md
wemeetagain Jul 19, 2024
33b4e38
Update src/lib.rs
wemeetagain Jul 19, 2024
31bb3da
chore: tweak aggregate_with
wemeetagain Jul 19, 2024
03acbf8
chore: use to_ne_bytes
wemeetagain Jul 19, 2024
8e3f9bb
Update src/lib.rs
wemeetagain Jul 22, 2024
6da455b
chore: tweak comment
wemeetagain Jul 22, 2024
b867afb
chore: remove multithreading tests
wemeetagain Jul 22, 2024
67971cf
chore: update index.d.ts
wemeetagain Jul 22, 2024
92d643b
chore: fix lint error
wemeetagain Jul 22, 2024
bba7a0a
chore: update comment
wemeetagain Jul 22, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-20.04, macos-12, macos-14, windows-latest]
node: [16, 17, 18, 20]
node: [16, 17, 18, 20, 22]
defaults:
run:
shell: bash
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [14, 16, 18, 20]
node: [14, 16, 18, 20, 22]
defaults:
run:
shell: bash
Expand Down
40 changes: 40 additions & 0 deletions benchmark/batchVerify.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import crypto from "crypto";
import * as bls from "../src/lib";
import * as next from "../next/index.js";
import {Csv} from "./utils/csv";
import {BenchmarkRunner} from "./utils/runner";

Expand Down Expand Up @@ -44,6 +45,45 @@ import {BenchmarkRunner} from "./utils/runner";
batch: batch / i,
ratio: batch / serie,
});

{
const serie = await runner.run({
id: `${i} - BLS verification - next`,
before: () => {
const msg = Buffer.alloc(32, i);
const sk = next.SecretKey.fromKeygen(crypto.randomBytes(32));
const pk = sk.toPublicKey();
const sig = sk.sign(msg);
return {msg, pk, sig};
},
run: ({msg, pk, sig}) => {
for (let j = 0; j < i; j++) {
next.verify(msg, pk, sig);
}
},
});

const batch = await runner.run({
id: `${i} - BLS verification batch - next`,
before: () => {
const msg = Buffer.alloc(32, i);
const sk = next.SecretKey.fromKeygen(crypto.randomBytes(32));
const pk = sk.toPublicKey();
const sig = sk.sign(msg);
return Array.from({length: i}, (_, i) => ({msg, pk, sig}));
},
run: (sets) => {
next.verifyMultipleAggregateSignatures(sets);
},
});

csv.addRow({
n: i,
serie: serie / i,
batch: batch / i,
ratio: batch / serie,
});
}
}

csv.logToConsole();
Expand Down
45 changes: 45 additions & 0 deletions benchmark/blstOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import crypto from "crypto";
import {blst, BLST_ERROR, P1_Affine, P2_Affine, Pairing} from "../src/bindings";
import {aggregateSignatures, fastAggregateVerify, PublicKey, SecretKey, Signature, verify} from "../src/lib";
import {BenchmarkRunner} from "./utils/runner";
import * as next from "../next/index.js";

const dst = "BLS_SIG_BLS12381G2-SHA256-SSWU-RO_POP_";
const hashOrEncode = true;
Expand Down Expand Up @@ -279,6 +280,50 @@ const msg = Buffer.from("Mr F was here");
});
}

await runner.run({
matthewkeil marked this conversation as resolved.
Show resolved Hide resolved
id: "BLS signature - next",
before: () => {},
beforeEach: () => next.SecretKey.fromKeygen(crypto.randomBytes(32)),
run: (sk) => {
sk.sign(msg);
},
});

await runner.run<{pk: next.PublicKey; sig: next.Signature}>({
id: "BLS verification - next",
before: () => {
const sk = next.SecretKey.fromKeygen(crypto.randomBytes(32));
const pk = sk.toPublicKey();
const sig = sk.sign(msg);
return {pk, sig};
},
run: ({pk, sig}) => {
next.verify(msg, pk, sig);
},
});

for (const n of [32, 128]) {
await runner.run<{pks: next.PublicKey[]; sig: next.Signature}>({
id: `BLS agg verif of 1 msg by ${n} pubkeys - next`,
before: () => {
const pks: next.PublicKey[] = [];
const sigs: next.Signature[] = [];

for (let i = 0; i < n; i++) {
const sk = next.SecretKey.fromKeygen(Buffer.alloc(32, i));
pks.push(sk.toPublicKey());
sigs.push(sk.sign(msg));
}

const sig = next.aggregateSignatures(sigs);
return {pks, sig};
},
run: ({pks, sig}) => {
next.fastAggregateVerify(msg, pks, sig);
},
});
}

// BLS verif of 6 msgs by 6 pubkeys
// Serial batch verify 6 msgs by 6 pubkeys (with blinding)
// Parallel batch verify of 6 msgs by 6 pubkeys (with blinding)
Expand Down
29 changes: 29 additions & 0 deletions benchmark/multithread.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os from "os";
import * as bls from "../src/lib";
import * as next from "../next/index.js";
import {BlsMultiThreadNaive} from "../test/unit/multithread/naive";
import {warmUpWorkers, chunkify} from "../test/unit/multithread/naive/utils";
import {Csv} from "./utils/csv";
Expand All @@ -24,10 +25,13 @@ import {BenchmarkRunner} from "./utils/runner";

// Preparing test data
const sets: bls.SignatureSet[] = [];
const setsNext: next.SignatureSet[] = [];
for (let i = 0; i < sigCount; i++) {
const msg = Buffer.alloc(32, i);
const sk = bls.SecretKey.fromKeygen(Buffer.alloc(32, i));
sets.push({msg, pk: sk.toPublicKey(), sig: sk.sign(msg)});
const skNext = next.SecretKey.fromKeygen(Buffer.alloc(32, i));
setsNext.push({msg, pk: skNext.toPublicKey(), sig: skNext.sign(msg)});
}

// BLS batch verify
Expand All @@ -51,6 +55,14 @@ import {BenchmarkRunner} from "./utils/runner";
},
});

const serieNext = await runner.run({
id: `BLS batch verify ${sigCount} sigs - main thread - next`,
before: () => {},
run: () => {
next.verifyMultipleAggregateSignatures(setsNext);
},
});

for (let workers = 1; workers <= logicalCpuCount; workers++) {
const parallel = await runner.run({
id: `BLS batch verify ${sigCount} sigs - ${workers} worker_threads`,
Expand All @@ -68,6 +80,23 @@ import {BenchmarkRunner} from "./utils/runner";
parallel: parallel,
ratio: serie / parallel,
});

const parallelNext = await runner.run({
id: `BLS batch verify ${sigCount} sigs - ${workers} worker_threads - next`,
before: () => {},
run: async () => {
await Promise.all(
chunkify(setsNext, workers).map((setsWorker) => next.verifyMultipleAggregateSignaturesAsync(setsWorker))
);
},
});

csv.addRow({
workers,
serie: serieNext,
parallel: parallelNext,
ratio: serieNext / parallelNext,
});
}
csv.logToConsole();
}
Expand Down
2 changes: 2 additions & 0 deletions next/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]
Loading
Loading