Skip to content

refactor: bls: fold the BLS library into src/bls on top of blst - #7680

Draft
knst wants to merge 7 commits into
dashpay:developfrom
knst:refactor-dissolve-bls-signatures
Draft

knst wants to merge 7 commits into
dashpay:developfrom
knst:refactor-dissolve-bls-signatures

Conversation

@knst

@knst knst commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

Issue being fixed or feature implemented

The library bls-signatures originally is forked from Chia's library that is built on the top of relic.
Though, at some moment they are migrated to blst library instead relic and afterward migrated to rust's bindings without extra layer of abstraction.

Their repo is archieved now:

This repository was archived by the owner on Jul 3, 2025. It is now read-only.

This library and language bindings are no longer maintained. The Chia blockchain uses the implementation from https://github.com/Chia-Network/chia_rs

Python projects should use chia_rs as a drop-in replacement for blspy C/C++ projects are recommended to use blst https://github.com/supranational/blst

As far as Dash Core is migrated to blst library as well, [see https://github.com//pull/7678], we no need this level of abstraction for GMP + relic files and could call blst's API directly.

What was done?

CBLSSecretKey, CBLSPublicKey, CBLSSignature and CBLSId now sit directly on blst's C API instead of on the vendored dashbls C++ library, which is removed. The public interface of bls/bls.h is unchanged; what changes underneath:

  • CBLSWrapper delegates the codec to four static hooks of the derived class (DecodeImpl, EncodeImpl, IsIdentity, EqualImpl). Public keys and signatures hold a blst_p1 / blst_p2, ids a uint256, secret keys a CBLSSecretScalar: a blst_scalar in secure memory, allocated lazily.
  • bls/bls_legacy.{h,cpp} carry the pre-v19 scheme: the point codec with the relic quirks that are visible through re-serialization of on-chain data, and the Fouque-Tibouchi hash-to-G2.
  • Verification keeps the relic semantics (a pairing with the point at infinity contributes the identity; the basic scheme additionally requires subgroup elements and distinct messages), secure aggregation keeps its coefficient derivation, and threshold shares and recovery keep their polynomial arithmetic, without the intermediate element copies, scheme dispatch and re-decoding of the library.

How Has This Been Tested?

The 1500 reference vectors recorded from the previous implementation are reproduced unchanged. mimalloc moves to src/mimalloc and is built by src/Makefile.mimalloc.include; blst is linked from depends. Aggregation benchmarks roughly halve, aggregated block verification is ~15% faster, everything else is unchanged.

Extra benefits are from the same optimization as dashpay/bls-signatures#110 [that PR is closed as DNM as it is impossible to provide safety guarantee for public key that pass as an argument to library]

Breaking Changes

  • removed bls-signatures library completely. Should not affect any external usages.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

blst (https://github.com/supranational/blst) is the BLS12-381 backend of
the upcoming src/dashbls update. The package runs blst's own build.sh and
installs libblst.a plus bindings/blst.h and blst_aux.h into the depends
prefix. __BLST_PORTABLE__ selects runtime CPU dispatch so the build does
not depend on the builder's CPU flags.
src/dashbls is no longer a configure sub-project. Its library, the
vendored mimalloc secure allocator and its Catch2 test binary are built by
the new src/Makefile.dashbls.include as libtool convenience libraries, the
same way crc32c and leveldb are, and dashbls/runtest (including the relic
reference vectors) is part of `make check`. The BLS12-381 backend blst is
detected by configure and linked from depends (or the system).

The library's PrivateKey::Serialize no longer takes a scheme flag, so
CBLSWrapper dispatches on the implementation type; the secure allocator
pool is sized for the largest blst object; the relic macro workarounds in
bls/bls.h are gone.
GMP was only needed by relic, the previous backend of src/dashbls.
Remove the depends package and its patch, the configure checks and the
GMP_LIBS link entries, and the build documentation that told users to
install it.
Everything that only served the standalone library build or the relic
backend goes: the relic tree, the CMake and autotools files, the
Go/Rust/JS/Python bindings and their helper scripts, the relic
differential fuzzer and the library benchmark. What stays is what Dash
Core builds and tests: the library sources and headers, the Catch2 test
with its relic reference vectors (plus the generator that produced them),
mimalloc, LICENSE, NOTICE and README.

NOTICE now lists blst instead of relic, GMP and pybind11, and
contrib/debian/copyright gains entries for dashbls and mimalloc.
A deterministic generator exercises the public API of bls/bls.h (both
schemes, explicit flags and the global bls::bls_legacy_scheme switch):
codec round trips including malformed input, signing and verification,
insecure and secure aggregation, threshold shares and recovery,
Diffie-Hellman, stream serialization with the malleability protocol,
the version and lazy wrappers, IES and the batch verifier. Its 1500
results are recorded in test/data/bls_reference_vectors.json and pin
the observable behaviour of the wrapper layer, so the implementation
underneath can change without changing consensus-visible results.

Set BLS_REFERENCE_VECTORS_DUMP to regenerate the file after an
intentional behaviour change.
CBLSSecretKey, CBLSPublicKey, CBLSSignature and CBLSId now sit directly
on blst's C API instead of on the vendored dashbls C++ library, which is
removed. The public interface of bls/bls.h is unchanged; what changes
underneath:

- CBLSWrapper delegates the codec to four static hooks of the derived
  class (DecodeImpl, EncodeImpl, IsIdentity, EqualImpl). Public keys and
  signatures hold a blst_p1 / blst_p2, ids a uint256, secret keys a
  CBLSSecretScalar: a blst_scalar in secure memory, allocated lazily.
- bls/bls_legacy.{h,cpp} carry the pre-v19 scheme: the point codec with
  the relic quirks that are visible through re-serialization of on-chain
  data, and the Fouque-Tibouchi hash-to-G2.
- Verification keeps the relic semantics (a pairing with the point at
  infinity contributes the identity; the basic scheme additionally
  requires subgroup elements and distinct messages), secure aggregation
  keeps its coefficient derivation, and threshold shares and recovery
  keep their polynomial arithmetic, without the intermediate element
  copies, scheme dispatch and re-decoding of the library.
- Secret memory: mimalloc in secure mode by default (and always in the
  consensus and kernel libraries), the locked pool once BLSInit() has
  run; the backend is latched at the first allocation so no block is
  ever released through the wrong allocator.

The 1500 reference vectors recorded from the previous implementation
are reproduced unchanged. mimalloc moves to src/mimalloc and is built by
src/Makefile.mimalloc.include; blst is linked from depends. Aggregation
benchmarks roughly halve, aggregated block verification is ~15% faster,
everything else is unchanged.
@thepastaclaw

Copy link
Copy Markdown
Collaborator

🕓 Review not started yet because this PR is a draft.

  • Request normal review — click when the PR is ready for review.
  • Request priority review — click to move this review to the front of the queue.

Commit d7af61c. Normal review starts when eligible; priority review starts as soon as a slot is available.

@github-actions

Copy link
Copy Markdown

This pull request has conflicts, please rebase.

PastaPastaPasta added a commit that referenced this pull request Nov 10, 2026
e6d4d7e build: compile dashbls with Dash's autotools, blst from depends (Konstantin Akimov)
b2efb31 Squashed 'src/dashbls/' changes from dbd61e6a4e..77c8da5a53 (Konstantin Akimov)
01f7215 depends: update 'src/dashbls' to dashpay/bls-signatures@77c8da5 (Konstantin Akimov)
ef50cc5 depends: add blst 0.3.17 (Konstantin Akimov)

Pull request description:

  ## Issue being fixed or feature implemented
  Blst library has much better performance compare to relic for bls signatures.

  See dashpay/bls-signatures#132 for details.

  | Benchmark | relic | v0.3.17 | Speedup |
  |---|---:|---:|---:|
  | Signing | 0.4738 ms | 0.2427 ms | 1.95x |
  | Verification | 1.526 ms | 0.6607 ms | 2.31x |
  | Batch verification preparation | 0.5659 ms | 0.2819 ms | 2.01x |
  | Public key validation | 0.124 ms | 0.0341 ms | 3.64x |
  | Signature validation | 0.1398 ms | 0.0487 ms | 2.87x |
  | Aggregation | 1.4 µs | 1.0 µs | 1.40x |
  | Batch verification | 0.663 ms | 0.2417 ms | 2.74x |
  | Serialize PrivateKey | 11.4 ns | 9.9 ns | 1.15x |
  | Serialize G1Element | 108.2 ns | 47.6 ns | 2.27x |
  | Serialize G2Element | 156.0 ns | 92.7 ns | 1.68x |
  | SerializeToArray PrivateKey | 7.6 ns | 5.7 ns | 1.33x |
  | SerializeToArray G1Element | 105.0 ns | 43.6 ns | 2.41x |
  | SerializeToArray G2Element | 147.2 ns | 86.0 ns | 1.71x |

  ## What was done?
  Migrated dash core repo to use blst library [over chia's framework v2]. Changes kept minimal as possible while everything still works.

  Beyond blst's migration one more PR is relevant with bls-signatures's version bump: dashpay/bls-signatures#123
  Behaviour change: legacy verification (LegacySchemeMPL::Verify/AggregateVerify/VerifySecure) now rejects public keys and signatures that are not on the curve or not in the prime-order subgroup, following dashpay/bls-signatures#123. Identity points were already rejected by CBLSWrapper::SetBytes, so only non-subgroup points are newly rejected; honest signers cannot produce them, and mainnet replay with this branch rejects nothing.

  There's futher PRs that do:
   - drop gmp dependency see #7679
   - drop relic relevant files, various binding [js, go, python, etc] which are not required for Dash Core. it's preliminary step to clean up all unused files and it is NOT included in this PR due to huge diff [-250k lines] which will make this PR unresponsible on github + more difficult to review for people and for agents, see #7679 for details
   - final phase: get rid of chia's layer and call blst's methods directly from CBLSSecretKey, CBLSPublicKey, CBLSSignature and CBLSId. Accordingly benchmark it gives extra 15% of performance for aggregate's functionality and simplify implementation significantly.  See #7680 for mockup / proof-of-concept.

  ## How Has This Been Tested?

  Dash Core chains are re-synced from genesis successfully with `-reindex -assumevalid=0` and ``-reindex -assumevalid=0 -testnet`

  Performance impact is measured by block-reconsider ~5000blocks measured performance impact for blocks validation:

  | Step | develop | PR | Speedup |
  |---|---:|---:|---:|
  | Sanity checks | 0.19s | 0.20s | 0.95x |
  | Fork checks | 0.04s | 0.05s | 0.80x |
  | GetTxPayload | 1.10s | 0.38s | 2.89x |
  | Loop | 1.94s | 1.15s | 1.69x |
  | CheckCreditPoolDiffForBlock | 0.06s | 0.03s | 2.00x |
  | m_qblockman.ProcessBlock | 14.09s | 6.76s | 2.08x |
  | m_dmnman.ProcessBlock | 2.75s | 3.10s | 0.89x |
  | CalcCbTxMerkleRootMNList | 0.16s | 0.18s | 0.89x |
  | GetQcHashes | 3.76s | 2.51s | 1.50x |
  | Loop (quorums) | 0.04s | 0.04s | 1.00x |
  | ComputeMerkleRoot | 0.04s | 0.04s | 1.00x |
  | CalcCbTxMerkleRootQuorums | 3.85s | 2.60s | 1.48x |
  | CheckCbTxBestChainlock | 10.36s | 4.36s | 2.38x |
  | m_mnhfman->ProcessBlock | 0.09s | 0.13s | 0.69x |
  | ProcessSpecialTxsInBlock | 34.47s | 18.78s | 1.84x |
  | Connect 1 transactions | 35.27s | 19.62s | 1.80x |
  | Verify 0 txins | 37.90s | 21.03s | 1.80x |
  | IS filter | 0.00s | 0.27s | slower |
  | GetBlockSubsidy | 0.00s | 0.00s | – |
  | IsBlockValueValid | 0.00s | 0.00s | – |
  | IsBlockPayeeValid | 0.04s | 0.04s | 1.00x |
  | Dash specific | 0.05s | 0.31s | 0.16x |
  | Write undo data | 0.00s | 0.00s | – |
  | Index writing | 0.00s | 0.00s | – |
  | **Connect total** | **38.39s** | **21.85s** | **1.76x** |
  | Flush | 0.31s | 0.34s | 0.91x |
  | Writing chainstate | 0.01s | 0.02s | 0.50x |
  | Connect postprocess | 0.78s | 0.88s | 0.89x |
  | **Connect block** | **39.88s** | **23.52s** | **1.70x** |

  Beside pure faster block validation time, it's expected lower CPU usage for nodes and especially masternodes; it's expected faster performance for instant-send locks, higher throughput for instant-send locks, faster forming of chainlocks.

  There's extra validity tests that had been done inside bls-signatures and enabled as regression tests of Dash Core.

  ## Breaking Changes
  `blst 0.3.17` is a new dependency for Dash Core, no other changes in behaviour beside performance is expected.

  Please note that build process for bls-signatures is updated. It's no more has own 'config.status' and other autoconf's files, but directly integrated to dash core's build.

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [x] I have commented my code, particularly in hard-to-understand areas
  - [x] I have added or updated relevant unit/integration/functional/e2e tests
  - [x] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

Top commit has no ACKs.

Tree-SHA512: 511e5635ad68f9bd6ea63a925a58a0b6136658d08ca54a23009779e9dae619678e01f867752195a7725ea11da9e60ec6d0f84dd0b98d78b43ce1097beb302f97
PastaPastaPasta added a commit that referenced this pull request Nov 15, 2026
…cleanup unused files from the repo

688b47a build: restore the dashbls runbench binary (Konstantin Akimov)
824b74f ci: drop libgmp-dev from the slim CI image (Konstantin Akimov)
869b9ce doc: list dashbls and mimalloc in the debian copyright file (Konstantin Akimov)
5243be3 build: compile the dashbls sources added by the subtree update (Konstantin Akimov)
48a2d9e dashbls: remove bindings and standalone build files (Konstantin Akimov)
af92b59 Squashed 'src/dashbls/' changes from 77c8da5a53..85f016781b (Konstantin Akimov)

Pull request description:

  ## Issue being fixed or feature implemented

  Since #7678 Dash Core builds `src/dashbls` with its own autotools files on top of blst. The subtree still carried relic and everything that serves only the standalone bls-signatures build: CMake files, the Go/Rust/JS/Python bindings, their CI workflows and helper scripts.

  This is a prerequisite for #7680 - inline calls of blst directory to dash bls primitives: CBLSPrivateKyee, CBLSPublicKey, CBLSSignature, etc.

  ## What was done?

  - Updated the `src/dashbls` subtree to dashpay/bls-signatures@85f016781b. Upstream removed the unused relic tree there and moved definitions from headers into `hdkeys.cpp`, `hkdf.cpp`, `secure.cpp` and `util.cpp`.
  - Added the new source files to `src/Makefile.dashbls.include`, and built upstream's `test/test_secure.cpp` into `dashbls/runtest`.
  - Removed the bindings and the standalone build files from `src/dashbls`. What stays is what Dash Core builds and tests: the library sources and headers, the Catch2 tests with the reference vectors and their generator, mimalloc, `LICENSE`, `NOTICE` and `README.md`.
  - `src/dashbls/NOTICE` and `README.md` no longer describe the removed code.
  - Listed dashbls and mimalloc in `contrib/debian/copyright`.
  - Dropped `libgmp-dev` from the slim CI image; GMP was only needed by relic.

  No changes to Dash Core's own sources.

  ## How Has This Been Tested?

  CI.

  ## Breaking Changes

  None.

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [x] I have added or updated relevant unit/integration/functional/e2e tests
  - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

Top commit has no ACKs.

Tree-SHA512: 0e69156f99b0a0d04bd2bbacd1e6219f3a5e4aa06b02423ab917623c21ff60c90750c34f40282b53355c46d3339d3286dcd701813af5ffcd0d31930b10312ce5
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.

2 participants