-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose Pippenger multiplication for combining multiple sigs of same m…
…sg (#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
- Loading branch information
1 parent
50f0466
commit d5d595a
Showing
7 changed files
with
387 additions
and
60 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,101 @@ | ||
/** | ||
* Copyright (c) 2024 Status Research & Development GmbH | ||
* Licensed under either of | ||
* * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) | ||
* * MIT license ([LICENSE-MIT](LICENSE-MIT)) | ||
* at your option. | ||
* This file may not be copied, modified, or distributed except according to | ||
* those terms. | ||
*/ | ||
|
||
#ifndef BLST_NIM_H | ||
#define BLST_NIM_H | ||
|
||
// Nim does not support annotating pointer destinations with C `const`. | ||
// | ||
// This leads to errors on certain platforms and toolchains | ||
// when interacting with APIs involving nested pointers, e.g.: | ||
// expected 'const blst_p1_affine * const*' | ||
// but argument is of type 'blst_p1_affine **' | ||
// [-Wincompatible-pointer-types] | ||
// | ||
// To prevent these issues, offending function signatures are replaced | ||
// with ones that lack C `const` annotations. | ||
|
||
#define blst_p1s_to_affine blst_p1s_to_affine_replaced | ||
#define blst_p1s_add blst_p1s_add_replaced | ||
#define blst_p1s_mult_wbits_precompute blst_p1s_mult_wbits_precompute_replaced | ||
#define blst_p1s_mult_wbits blst_p1s_mult_wbits_replaced | ||
#define blst_p1s_mult_pippenger blst_p1s_mult_pippenger_replaced | ||
#define blst_p1s_tile_pippenger blst_p1s_tile_pippenger_replaced | ||
|
||
#define blst_p2s_to_affine blst_p2s_to_affine_replaced | ||
#define blst_p2s_add blst_p2s_add_replaced | ||
#define blst_p2s_mult_wbits_precompute blst_p2s_mult_wbits_precompute_replaced | ||
#define blst_p2s_mult_wbits blst_p2s_mult_wbits_replaced | ||
#define blst_p2s_mult_pippenger blst_p2s_mult_pippenger_replaced | ||
#define blst_p2s_tile_pippenger blst_p2s_tile_pippenger_replaced | ||
|
||
#define blst_miller_loop_n blst_miller_loop_n_replaced | ||
|
||
#include "../../vendor/blst/bindings/blst.h" | ||
|
||
#undef blst_p1s_to_affine | ||
#undef blst_p1s_add | ||
#undef blst_p1s_mult_wbits_precompute | ||
#undef blst_p1s_mult_wbits | ||
#undef blst_p1s_mult_pippenger | ||
#undef blst_p1s_tile_pippenger | ||
|
||
#undef blst_p2s_to_affine | ||
#undef blst_p2s_add | ||
#undef blst_p2s_mult_wbits_precompute | ||
#undef blst_p2s_mult_wbits | ||
#undef blst_p2s_mult_pippenger | ||
#undef blst_p2s_tile_pippenger | ||
|
||
#undef blst_miller_loop_n | ||
|
||
void blst_p1s_to_affine(blst_p1_affine dst[], blst_p1 *points[], | ||
size_t npoints); | ||
void blst_p1s_add(blst_p1 *ret, blst_p1_affine *points[], | ||
size_t npoints); | ||
void blst_p1s_mult_wbits_precompute(blst_p1_affine table[], size_t wbits, | ||
blst_p1_affine *points[], | ||
size_t npoints); | ||
void blst_p1s_mult_wbits(blst_p1 *ret, const blst_p1_affine table[], | ||
size_t wbits, size_t npoints, | ||
byte *scalars[], size_t nbits, | ||
limb_t *scratch); | ||
void blst_p1s_mult_pippenger(blst_p1 *ret, blst_p1_affine *points[], | ||
size_t npoints, byte *scalars[], | ||
size_t nbits, limb_t *scratch); | ||
void blst_p1s_tile_pippenger(blst_p1 *ret, blst_p1_affine *points[], | ||
size_t npoints, byte *scalars[], | ||
size_t nbits, limb_t *scratch, | ||
size_t bit0, size_t window); | ||
|
||
void blst_p2s_to_affine(blst_p2_affine dst[], blst_p2 *points[], | ||
size_t npoints); | ||
void blst_p2s_add(blst_p2 *ret, blst_p2_affine *points[], | ||
size_t npoints); | ||
void blst_p2s_mult_wbits_precompute(blst_p2_affine table[], size_t wbits, | ||
blst_p2_affine *points[], | ||
size_t npoints); | ||
void blst_p2s_mult_wbits(blst_p2 *ret, const blst_p2_affine table[], | ||
size_t wbits, size_t npoints, | ||
byte *scalars[], size_t nbits, | ||
limb_t *scratch); | ||
void blst_p2s_mult_pippenger(blst_p2 *ret, blst_p2_affine *points[], | ||
size_t npoints, byte *scalars[], | ||
size_t nbits, limb_t *scratch); | ||
void blst_p2s_tile_pippenger(blst_p2 *ret, blst_p2_affine *points[], | ||
size_t npoints, byte *scalars[], | ||
size_t nbits, limb_t *scratch, | ||
size_t bit0, size_t window); | ||
|
||
void blst_miller_loop_n(blst_fp12 *ret, blst_p2_affine *Qs[], | ||
blst_p1_affine *Ps[], | ||
size_t n); | ||
|
||
#endif |
Oops, something went wrong.