Commit Graph

24 Commits

Author SHA1 Message Date
Etan Kissling d5d595a59c
Expose Pippenger multiplication for combining multiple sigs of same msg (#178)
* Expose Pippenger multiplication for combining multiple sigs of same msg

In many use cases, there are multiple signatures of the same message,
e.g., Ethereum attestations often share the signed `AttestationData`.

For that situation, `blst` started exposing Pippenger multiplication
to accelerate this use case. Multiscalar multiplication is much faster
than individual scalar multiplication of each signature / pubkey.

Further optimizations may be achieved with parallel tiling, see the Rust
binding code in the `npoints >= 32` situation:

- https://github.com/supranational/blst/blob/v0.3.13/bindings/rust/src/pippenger.rs

Likewise, multiple pubkeys / signatures may be loaded simultaneously
using the new `blst` APIs.

We don't do either of these additional optimizations as our architecture
does not readily support them. Pippenger multiplication alone already
offers a significant speedup until prioritizing further optimizations.

```
------------------------------------------------------------------------------------------------------------------------------------
BLS verif of 6 msgs by 6 pubkeys                                                117.232 ops/s      8530098 ns/op     20471994 cycles
BLS verif of 6 sigs of same msg by 6 pubkeys (with blinding)                    553.186 ops/s      1807711 ns/op      4338371 cycles
BLS verif of 6 sigs of same msg by 6 pubkeys                                    724.279 ops/s      1380683 ns/op      3313617 cycles
------------------------------------------------------------------------------------------------------------------------------------
BLS verif of 60 msgs by 60 pubkeys                                               11.131 ops/s     89839743 ns/op    215615251 cycles
BLS verif of 60 sigs of same msg by 60 pubkeys (with blinding)                  238.059 ops/s      4200634 ns/op     10081380 cycles
BLS verif of 60 sigs of same msg by 60 pubkeys                                  680.634 ops/s      1469219 ns/op      3526031 cycles
------------------------------------------------------------------------------------------------------------------------------------
BLS verif of 180 msgs by 180 pubkeys                                              3.887 ops/s    257298895 ns/op    617517127 cycles
BLS verif of 180 sigs of same msg by 180 pubkeys (with blinding)                166.340 ops/s      6011785 ns/op     14428186 cycles
BLS verif of 180 sigs of same msg by 180 pubkeys                                536.938 ops/s      1862413 ns/op      4469689 cycles
------------------------------------------------------------------------------------------------------------------------------------
```

* Suppress `const` warning for Windows build

* Different approach for dealing with [-Wincompatible-pointer-types]

* Extend documentation
2024-08-12 02:19:19 +00:00
Eugene Kabanov f29698d2e9
Fix GCC-14 [-Wincompatible-pointer-types] issue (one more version). (#173)
* One more way of fix.

* POC blst sha256 issue

---------

Co-authored-by: jangko <jangko128@gmail.com>
2024-06-06 22:00:59 +00:00
Etan Kissling d091a579a2
remove MIRACL Core backend (#170)
EIP-4844 requires BLST via `nim-kzg4844`; MIRACL Core is not supported.
Furthermore, BLST now has fallback for generic CPU architectures.
Therefore, remove support for the MIRACL Core backend.
2024-02-22 15:54:55 +01:00
Etan Kissling 1002533ad2
rename `milagro` references -> `miracl` in documentation (#168)
Followup from #66 where we switched from Milagro to MIRACL Core.
The internal documentation was not fully updated for Miracl. Doing now.
2024-02-17 19:04:28 +01:00
Etan Kissling eb5007a908
rename `milagro.nim` -> `miracl.nim` (#166)
Followup from #66 where we switched from Milagro to MIRACL Core.
The main module was not yet renamed. Doing now. Should not break
clients as the module is not usually directly imported.
2024-02-17 11:43:08 +00:00
Jacek Sieka b97eeb2055
add sig aggregation bench 2023-08-06 09:27:17 +02:00
Jacek Sieka 5937eb9a56
avoid blocking batchVerifyParallel (#154)
* avoid blocking batchVerifyParallel

The current version of `batchVerifyParallel` calls `syncAll` which syncs
on all executing tasks.

This PR changes this to syncing a Flowvar instead thus allowing
`batchVerifyParallel` to be called as a task itself.

Requires https://github.com/status-im/nim-taskpools/pull/33

* autoselect too

---------

Co-authored-by: zah <zahary@gmail.com>
2023-07-26 01:21:21 +03:00
Jacek Sieka a47e2aa931
normalise nimble, fix stylecheck (#147)
* normalise nimble, fix stylecheck
* cancel redundant PR jobs
* bump checkout
2022-11-23 13:21:12 +01:00
Zahary Karadjov 1d42842007
Routines for working with threshold signatures
Other changes:

Cosmetic fixes bringing the project closer to the
Status style guide.
2022-05-09 15:38:12 +03:00
Jacek Sieka a29e467cd4
enable `styleCheck:usages` (#136)
* enable `styleCheck:usages`

* oops
2022-04-07 10:12:00 +02:00
Mamy Ratsimbazafy 35add386bf
Remove old hashToG2 and unsed impl #78 (#131) 2022-01-02 13:26:11 +01:00
Ștefan Talpalaru 02d4848d84
BLST: allow disabling SSSE3 support (#128)
Also fix some CI benchmarks and no longer pass "-fno-tree-vectorize" to
the C compiler.
2021-12-11 19:19:30 +01:00
Mamy Ratsimbazafy 5be0f19795
add deserialization benchmarks (#126) 2021-11-23 11:54:12 +01:00
Mamy Ratsimbazafy c3f325b8e5
Use taskpools (#116)
* Use taskpools instead of OpenMP

* actually parallelize the partial pairings

* update benches

* Actually make processing parallel

* Import taskpools only with --threads:on

* renaming

* Fix thread partitioning: split on numBatches and not numThreads

* missed input len in chunking

* slight optim to reduce number of tasks created

* Add test for batch signature forgery

* update nimble requirements

* Fix benchmark

* don't test multithreading on Windows 32-bit: no SynchronizationBarrier in MinGW

* add comment about elliptic affine coordinates negation [skip CI]
2021-07-10 08:25:12 +02:00
Ștefan Talpalaru 7275c56de0
fix ASM for 32-bit Linux (#110)
* fix ASM for 32-bit Linux

* fix mingw links
2021-06-03 02:19:56 +02:00
Mamy Ratsimbazafy be2be6711d
More bench: sha256(32 bytes) and longer pairing bench (#108) 2021-03-08 11:19:24 +01:00
Mamy Ratsimbazafy f7d0341f80
Batched API update (#103)
* Parallel API update

* Update blscurve/bls_batch_verifier.nim

Co-authored-by: Jacek Sieka <jacek@status.im>

Co-authored-by: Jacek Sieka <jacek@status.im>
2020-12-17 07:20:34 +01:00
Mamy Ratsimbazafy 09b4b07731
Parallel and Serial batch verification (#101)
* initial multithreaded BLS batch verification support

* Add benchmarks, fix misuse of omp_get_num_threads, init, ptr

* Change parallel algo: fix tests, better scalability, parallelism cutoff

* remove leftover debugging attachGC

* No need to tune, the bench was doing only one iter

* Rebase indentation bug

* Fix stacktraces in threaded calls

* Fix Nim stacktraces crashing OpenMP

* Properly use the thread separation tag at context init

* Workaround linker static inline vec_zero visibility

* Address review comments:
- specialize to 32 bytes digest like SHA256
- init of BatchBLSVerifier
- mention that `incl` might not return true if we do subgroup checks there in the future instead of at deserialization
- also done in previous PR, mention that if openarray[PublicKeys].len == 0 it is a spec violation

* use openmp in nimble test for benchmark

* Update blscurve/blst/blst_min_pubkey_sig_core.nim

Co-authored-by: Jacek Sieka <jacek@status.im>

* Address review comments

* update tests as well

Co-authored-by: Jacek Sieka <jacek@status.im>
2020-12-16 11:32:42 +01:00
Mamy Ratsimbazafy c925b0c13c
Benchmarks rework (#97)
* revive Miracl primitives benchmark

* Revive BLST benchmarks

* Bench hash-to-curve

* Add benchmark of BLS sign, verify and fastAggregateVerify

* Bench all + add benchmarks to CI

* don't bench on 32-bit, inline ASM issue with low-level calls (but high level calls are fine)

* Actually it's the SHA256 tests on 32-bit that causes ASM issue due to inlined headers

* don't bench at all on 32-bit for now

* fix: don't test SH1256 on PowerPC
2020-12-05 14:20:18 +01:00
Mamy Ratsimbazafy 2bd18f4493
Update BLST (#86)
* Update BLST

* Remove aliasing workaround (to be confirmed in NBC CI)

* Use the new SHA256 portable instead of Milagro fallback for non SSE3 CPU (ref da9ae49dab)

* Expose SHA256 from BLST

* add SHA256 to test

* On Azure MacOS it seems like the compiler aliases array[32, byte] at init :?

* reactivate commented out generators
2020-09-17 16:39:35 +02:00
Mamy Ratsimbazafy cfeb6ec4fd
Miracl core (#66)
* Switch to miracl core.

* Handle SQRT / isSquare changes

* Fix sqrt for serialization

* Removed AMCL

Co-authored-by: cheatfate <eugene.kabanov@status.im>
2020-07-22 10:00:21 +02:00
Mamy Ratsimbazafy 9efb20df12
Benchmarks (#46)
* initial benchmark of scalar multiplication

* Warning in 32-bit mode + Add elliptic curve addition

* Hash to curve bench

* put benches behind when isMainModule

* Add pairing bench (2 impl) and bench_all

* mention that cycles measurements are approximate

* Fallback without cycle count for ARM (and MIPS, Sparc, ...)

* Add a nimble task
2020-04-08 20:58:26 +02:00
Mamy Ratsimbazafy 13a89c9d73 Merge repo blscurve (#18)
Repo surgery to preserve nim-milagro-crypto history
2019-02-05 19:07:19 +01:00
mratsim 539c7bf6b3 Add a benchmark template 2018-10-27 14:01:15 +02:00