Skip to content

Conversation

@random-zebra
Copy link

This adds support, helpers/wrappers, and first benchmark tests for the Chia-Network BLS library (forked at https://github.com/PIVX-Project/bls-signatures).

Current benchmarks measured here:

#Benchmark,                count,min(ns),max(ns),average(ns),min_cycles,max_cycles,average_cycles
BLSDKG_BQV_p_10,           2816,353109,372122,360647,918101,967534,937699
BLSDKG_BQV_p_100,          56,18020215,23336174,18941736,46853334,60675202,49249355
BLSDKG_BQV_p_400,          4,273863550,280607089,277235319,712057419,729590941,720824180
BLSDKG_BQV_s_10,           1792,552062,818822,563527,1435388,2128977,1465197
BLSDKG_BQV_s_100,          20,50876386,52260564,51565050,132280890,135879812,134071428
BLSDKG_BQV_s_400,          2,841535540,841535540,841535540,2188029701,2188029701,2188029701
BLSDKG_VCS_a_10,           52,19126782,22153527,20579889,49730482,57600151,53508613
BLSDKG_VCS_a_100,          2,740001826,740001826,740001826,1924037680,1924037680,1924037680
BLSDKG_VCS_a_400,          2,6578287562,6578287562,6578287562,17103840249,17103840249,17103840249
BLSDKG_VCS_p_10,           160,5504112,7943794,6422171,14310932,20654234,16697932
BLSDKG_VCS_p_100,          4,404123640,416599229,410361434,1050739542,1083176687,1066958114
BLSDKG_VCS_p_400,          2,6458895418,6458895418,6458895418,16793415540,16793415540,16793415540
BLSDKG_VCS_pa_10,          104,9324382,10495940,9939787,24244000,27289904,25843897
BLSDKG_VCS_pa_100,         6,177723661,232347723,208653253,462089456,604114221,542507747
BLSDKG_VCS_pa_400,         2,1711054633,1711054633,1711054633,4448818080,4448818080,4448818080
BLSDKG_VCS_s_10,           60,17392167,19417721,17683328,45220421,50486871,45977438
BLSDKG_VCS_s_100,          2,1619269765,1619269765,1619269765,4210173355,4210173355,4210173355
BLSDKG_VCS_s_400,          2,25627885873,25627885873,25627885873,66633644685,66633644685,66633644685
BLSPubKeyAggregate_Normal, 163840,6352,6750,6507,16518,17552,16920
BLSSecKeyAggregate_Normal, 589824,1748,2400,1857,4547,6242,4830
BLSSign_Normal,            448,2342227,2471536,2394191,6089894,6426102,6225004
BLSVerify_Batched,         352,2447098,7455880,2963072,6362567,19385628,7704120
BLSVerify_BatchedParallel, 1408,646911,961480,783204,1681999,2499891,2036367
BLSVerify_LAB1000,         2,2316651736,2316651736,2316651736,6023397761,6023397761,6023397761
BLSVerify_LAB10000,        2,23157736538,23157736538,23157736538,60211148104,60211148104,60211148104
BLSVerify_LAB1000PV,       4,250084835,256612570,253348702,650231758,667204148,658717953
BLSVerify_LAB1000,         2,4912472578,4912472578,4912472578,12772647962,12772647962,12772647962
BLSVerify_LBSA1000,        2,2370638156,2370638156,2370638156,6163765047,6163765047,6163765047
BLSVerify_LBSA10000,       2,23495406477,23495406477,23495406477,61089106448,61089106448,61089106448
BLSVerify_Normal,          208,4808194,5017221,4938452,12501487,13044999,12840198

Note: In WIP as it needs support for non-deterministic builds (only working with depends atm).

random-zebra and others added 13 commits June 2, 2021 15:43
The old solution relied on thread-local-storage and was thus not
compatible to libc6 2.11 (which is the minimum supported version we
use).

Also, the old solution turned out to be erroneous. It would have crashed
or memory leaked when ownership of CBLSPrivateKey would be handled over
to another thread.
Uses the same trick as LockedPoolManager::Instance()
In some cases it takes too much time to perform full deserialization of
BLS signatures in the message handler thread. Better to just read the
buffer and do the actual deserialization when the signature is needed
for the first time (which is can be in another thread).
>>> extracted from dash@864856688dd9b1488daa6fe500edc37dd5a0a571

- Generalize CBLSLazyWrapper so that it can be used for signatures,
  pubkeys, and secret keys
- Implement == and != operators for CBLSLazyWrapper
- Implement cached hash for CBLSLazyWrapper
- undefine ERROR and DOUBLE
- check size in SetBuf and GetBuf
- check hex format of input string in SetHexStr
- remove size from InternalSetBuf/InternalGetBuf
>>> backports dash PR 3867

* bls: Add CBLSImplicit, a wrapper around uint256
  This makes `CBLSImplicit` compatible (related to methods called by
  CBLSWrapper) with the other classes from the bls-signatures library.

* bls: Use CBLSImplicit instead of uint256 as base type of CBLSId

* bls: Use FromBytes directly instead of indirectly through
  InternalSetBuf

* bls: Use Serialize directly instead of indirectly through
  InternalGetBuf

* bls: Drop all occurrences of InternalSetBuf and InternalGetBuf

* bls: Use `CBLSIdImplicit` instead of `uint256` in some more places
xdustinface and others added 10 commits June 2, 2021 17:38
>>> extracted from dash@982623860554ad1b558380f1ceffc154baf68a77
>>> from dash@6afa245307be43d300620a90aa118935f9439c5f
       + dash@d6a61e21cb6f5138fffd56151eab5ce4ac41b3b2
>>> backports dash PR 4013

* bls: Only update cached hash in CBLSWrapper when it's really needed

* bls: Reset cached hash in CBLSLazyWrapper instead of re-assigning
  uint256() to it

* bench: Update expected numbers in bls benchmarks

* bls: Drop UpdateHash methods
  Make sure the hash is updated via GetHash() only.
>>>backports dash@304678881a2303cdad408ab66361ffe9f7194255
           + dash@e22956f5e4e2dd42c6deda6d20897b6cd0851006
           + dash@6a73d532b592b4ab165022fe2e3a9f72ede23bc6
           + dash@02a850246e77092b057fc4c2444330b14d788d69
in order to use the current v1.0.0 release of the bls-signatures forked
from dash
>>> backports dash@637c34aa427cd41533d815a60650367f27c7eabd
@random-zebra
Copy link
Author

Pushed several updates/backports, and integrated library version v1.0.0.
New benchmarks:

#Benchmark,                count,min(ns),max(ns),average(ns),min_cycles,max_cycles,average_cycles
BLSDKG_BQV_p_10,           6656,158986,166183,162003,413372,432084,421217
BLSDKG_BQV_p_100,          112,8980109,9900697,9543218,23348778,25742264,24812815
BLSDKG_BQV_p_400,          10,123141748,128194789,125304114,320174279,333312274,325796537
BLSDKG_BQV_s_10,           6656,158486,169923,159595,412073,441808,414954
BLSDKG_BQV_s_100,          64,15756324,18341653,15915978,40967171,47689037,41382281
BLSDKG_BQV_s_4400,         4,277369887,289381071,283375479,721174619,752404256,736789437
BLSDKG_VCS_a_10,           32,28638066,36295336,32771970,74460305,94369573,85208651
BLSDKG_VCS_a_100,          2,800273879,800273879,800273879,2080749176,2080749176,2080749176
BLSDKG_VCS_a_400,          2,7078814566,7078814566,7078814566,18405246844,18405246844,18405246844
BLSDKG_VCS_p_10,           104,9132932,12915978,10363613,23746047,33582324,26945882
BLSDKG_VCS_p_100,          2,531127889,531127889,531127889,1380957388,1380957388,1380957388
BLSDKG_VCS_p_400,          2,8051185562,8051185562,8051185562,20933456959,20933456959,20933456959
BLSDKG_VCS_pa_10,          72,13723979,16134596,15075694,35683062,41950706,39197513
BLSDKG_VCS_pa_100,         4,269089875,284926926,277008400,699646168,740823405,720234787
BLSDKG_VCS_pa_400,         2,1819057048,1819057048,1819057048,4729633130,4729633130,4729633130
BLSDKG_VCS_s_10,           36,28434979,32486278,29048970,73932261,84465720,75528669
BLSDKG_VCS_s_100,          2,1962838791,1962838791,1962838791,5103472167,5103472167,5103472167
BLSDKG_VCS_s_400,          2,30568662153,30568662153,30568662153,79479943670,79479943670,79479943670
BLSPubKeyAggregate_Normal, 458752,2209,2473,2277,5745,6431,5921
BLSSecKeyAggregate_Normal, 458752,2229,2677,2314,5797,6961,6016
BLSSign_Normal,            240,3975191,8185054,4173389,10335686,21281595,10851006
BLSVerify_Batched,         208,4193797,11452455,5363656,10904068,29776923,13945756
BLSVerify_BatchedParallel, 768,1169866,1495796,1309412,3041708,3889138,3404533
BLSVerify_LAB1000,         2,4045689570,4045689570,4045689570,10518981155,10518981155,10518981155
BLSVerify_LAB10000,        2,40631723517,40631723517,40631723517,105644372674,105644372674,105644372674
BLSVerify_LAB1000PV,       4,409967073,411692429,410829751,1065933470,1070419492,1068176481
BLSVerify_LB1000,          2,6878854794,6878854794,6878854794,17885342767,17885342767,17885342767
BLSVerify_LBSA1000,        2,4128365562,4128365562,4128365562,10733942723,10733942723,10733942723
BLSVerify_LBSA10000,       2,40439437027,40439437027,40439437027,105144419946,105144419946,105144419946
BLSVerify_Normal,          144,6790571,7236512,6946850,17655807,18815253,18062134

@random-zebra
Copy link
Author

Closing this one, as with PIVX-Project/bls-signatures#1 we will be able to include the library as subtree, and build with autotools (so no need to include it as depends package). Wrappers and tests will be added once the new build system is complete.

random-zebra added a commit that referenced this pull request Jul 28, 2021
5b289eb CI: Lint chiabls subtree (Fuzzbawls)
c775ab3 Lint: exclude chiabls subtree from whitespace linting (Fuzzbawls)
e5d5ef7 CMake: integrate chiabls subtree CMake targets (Fuzzbawls)
50318c6 Build: build chiabls library from git subtree (Fuzzbawls)
4a71f9a Squashed 'src/chiabls/' content from commit 676ea45e80 (Fuzzbawls)

Pull request description:

  This introduces a new upcoming library dependency as a git subtree with support for native autotools (and CMake) builds.

  #2405 had also introduced this library dependency, but only as part of the `depends` system, which introduced numerous issues, not least of which was essentially breaking any non-depends based builds. After some discussion, it was decided that the git subtree approach (as used with `leveldb`, `crc32`, `univalue`, and `secp256k1`) would be more ideal as it would allow for both depends and non-depends based builds.

  Achieving this requires us to maintain our own fork of https://github.com/Chia-Network/bls-signatures (ours is at https://github.com/PIVX-Project/bls-signatures) with a native autotools based build system added to it (PIVX-Project/bls-signatures#1) that has been integrated into PIVX Core here.

  Note: This PR simply introduces the new library and connects it to our autotools and CMake build systems, but does not introduce new code that actually _uses_ the new library.

  Also Note: This effectively bumps our minimum required version of CMake (for CMake builds only) to `3.14`.

ACKs for top commit:
  random-zebra:
    utACK 5b289eb and merging...

Tree-SHA512: 9a36015395f310031a59a4b0c2159704753db627802b73b26ccb0fa3b85a9f33403c53ff424aadf56da81de546bfcf8e150fb3eac99fa232c29fd98a828aedb9
random-zebra added a commit that referenced this pull request Sep 17, 2021
… and unit tests

0d126ee [QA] Test encryption/decryption of sk shares in dkg unit test (random-zebra)
db69885 [QA] Refactor bls_ies_tests using CBLSIESEncryptedObject (random-zebra)
0453474 Test: Add bls ies basic encryption and decryption test coverage. (furszy)
aa51751 [Refactoring] Replace std::random_shuffle with Shuffle (random-zebra)
9f4ac39 [QA] Add unit test for DKG using wrapper/worker (random-zebra)
0253ea7 [QA] Add test for BLS sign/verify message and sethexstr (random-zebra)
c4c6efe [Refactor] Initialize BLS allocator in BasicTestingSetup (random-zebra)
104c4b0 Bail out early from secure deallocation (Alexander Block)
f5c0870 Add ECDSA benchmarks (Alexander Block)
5b16d89 [BUG] Initialize Random for bench tests (random-zebra)
1c3f2cb [Trivial] Remove unused variables in bls bench test (random-zebra)
9502597 Add BLS and DKG benchmarks (Alexander Block)
7bb9f02 [Trivial] bls_worker: Fix members initialization order in Aggregators (random-zebra)
225c8a8 Add highly parallelized worker/helper for BLS/DKG calculations (Alexander Block)
df56dea Add simple helpers/wrappers for BLS+AES based integrated encryption schemes (IES) (Alexander Block)
6f1d0e2 Implement wrappers around Chia BLS libs (random-zebra)
a0b04c1 Add pooled_secure_allocator and mt_pooled_secure_allocator (Alexander Block)
dbb0305 [Trivial] Rename BCLog::BENCH/RAND to BCLog::BENCHMARK/RANDOM (random-zebra)
d9ffaa6 Add helper to rename all threads of a ctpl::thread_pool (Alexander Block)
9f9a3d7 Add ctpl header only library (random-zebra)

Pull request description:

  Based on top of:
  - [x] #2419

  This reworks #2405, adapting the commits to the new build system (which includes the library already at `v1.0.1`, as git subtree).

ACKs for top commit:
  furszy:
    one step closer, ACK 0d126ee
  Fuzzbawls:
    ACK 0d126ee

Tree-SHA512: 9a07bf32790326444c7e035bd9b24351715d3906fb6e2b9e51b46950ed1aa82cf2cb72fba1b13611d771c339936433ff4c5a914e1ca2bb03965b83c371c8817f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants