Repository navigation
feat: use blst library instead relic #7678
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
base: develop
Are you sure you want to change the base?
Changes from all commits
2df8145
0970a68
b2efb31
abc789d
1d8b87d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,9 @@ LIBCXX_FLAGS="-nostdinc++ -nostdlib++ -isystem ${LIBCXX_DIR}include/c++/v1 -L${L | |
| export MSAN_AND_LIBCXX_FLAGS="${MSAN_FLAGS} ${LIBCXX_FLAGS}" | ||
|
|
||
| # BDB generates false-positives and will be removed in future | ||
| export DEP_OPTS="DEBUG=1 NO_BDB=1 NO_QT=1 NO_UPNP=1 NO_NATPMP=1 CC=clang-19 CXX=clang++-19 CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}'" | ||
| # __BLST_NO_ASM__ makes blst use its C implementation instead of hand-written | ||
| # assembly, which MSan cannot see through. | ||
| export DEP_OPTS="DEBUG=1 NO_BDB=1 NO_QT=1 NO_UPNP=1 NO_NATPMP=1 CC=clang-19 CXX=clang++-19 CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' CPPFLAGS='-D__BLST_NO_ASM__'" | ||
| export GOAL="install" | ||
| # CC/CXX/CFLAGS/CXXFLAGS are repeated here rather than left to depends' | ||
| # config.site. Upstream dropped them in bitcoin#29800 because its | ||
|
|
@@ -26,12 +28,12 @@ export GOAL="install" | |
| # target whose compiler differs from the system default, so nothing else in | ||
| # Dash's CI exercises that hand-off. | ||
| # _FORTIFY_SOURCE is not compatible with MSAN. | ||
| # --with-asm=no and --with-backend=easy keep secp256k1 and relic off | ||
| # hand-written assembly, which MSan cannot see through. | ||
| # --with-asm=no keeps secp256k1 off hand-written assembly, which MSan cannot | ||
| # see through. | ||
| # --disable-mimalloc selects the plain malloc secure allocator; mimalloc seeds | ||
| # itself with a raw getrandom syscall before main(), which MSan cannot track. | ||
| export BITCOIN_CONFIG="--with-sanitizers=memory --with-gui=no --without-bdb --with-sqlite \ | ||
| --with-asm=no --with-backend=easy --disable-mimalloc \ | ||
| --with-asm=no --disable-mimalloc \ | ||
| CC=clang-19 CXX=clang++-19 CFLAGS='${MSAN_FLAGS}' CXXFLAGS='${MSAN_AND_LIBCXX_FLAGS}' \ | ||
| CPPFLAGS='-U_FORTIFY_SOURCE'" | ||
|
Comment on lines
+31
to
38
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🟡 Suggestion: Restore MSan coverage of BLS arithmetic Removing the old backend restriction leaves the replacement BLS arithmetic using hand-written assembly in this job. depends/packages/blst.mk defines BLST_PORTABLE, but blst 0.3.17's build.sh still compiles assembly.S on x86_64, and that file selects assembly implementations under BLST_PORTABLE; the flag enables CPU portability, not sanitizer instrumentation. This is separate from mimalloc's startup problem: after allocator initialization is fixed, the BLS arithmetic boundary remains uninstrumented and can hide uninitialized reads or produce false positives on assembly-written outputs. Establish a supported MSan-compatible blst build configuration. Do not blindly add BLST_NO_ASM: assembly.S's x86_64 branch is not disabled by that macro alone. source:
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed at the dependency layer: depends/patches/blst/no_asm_limbs.patch makes an explicit BLST_NO_ASM skip the x86_64/aarch64 64-bit-limb branch in vect.h, so it falls through to blst's existing 32-bit C configuration, the one build.sh already uses on targets without assembly. Builds that don't define the macro are unchanged.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved (re-reviewed at |
||
| export USE_MEMORY_SANITIZER="true" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package=blst | ||
| $(package)_version=0.3.17 | ||
| $(package)_download_path=https://github.com/supranational/blst/archive/refs/tags | ||
| $(package)_download_file=v$($(package)_version).tar.gz | ||
| $(package)_file_name=$(package)-$($(package)_version).tar.gz | ||
| $(package)_sha256_hash=c3fef37b566b67419703b2bbb648e15176276af9a880c22aa8f5f2e8cecc2e4d | ||
| $(package)_patches=no_asm_limbs.patch | ||
|
|
||
| # build.sh takes CC/AR/RANLIB/CFLAGS from the environment. __BLST_PORTABLE__ | ||
| # selects runtime CPU dispatch instead of letting build.sh probe the builder's | ||
| # /proc/cpuinfo for ADX, which keeps the build reproducible; build.sh itself | ||
| # adds -D__BLST_NO_ASM__ on hosts other than x86_64/aarch64. | ||
| define $(package)_set_vars | ||
| $(package)_build_env=CC="$($(package)_cc)" AR="$($(package)_ar)" RANLIB="$($(package)_ranlib)" CFLAGS="$($(package)_cflags) $($(package)_cppflags) -fno-builtin -fPIC -D__BLST_PORTABLE__" | ||
| endef | ||
|
|
||
| define $(package)_preprocess_cmds | ||
| patch -p1 < $($(package)_patch_dir)/no_asm_limbs.patch | ||
| endef | ||
|
|
||
| define $(package)_build_cmds | ||
| ./build.sh | ||
| endef | ||
|
|
||
| define $(package)_stage_cmds | ||
| mkdir -p $($(package)_staging_prefix_dir)/include $($(package)_staging_prefix_dir)/lib && \ | ||
| install -m 644 bindings/blst.h bindings/blst_aux.h $($(package)_staging_prefix_dir)/include && \ | ||
| install -m 644 libblst.a $($(package)_staging_prefix_dir)/lib | ||
| endef |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| packages:=gmp backtrace | ||
| packages:=gmp backtrace blst | ||
|
|
||
| boost_packages = boost | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- a/src/vect.h | ||
| +++ b/src/vect.h | ||
| @@ -10,3 +10,3 @@ | ||
|
|
||
| -#if defined(__x86_64__) || defined(__aarch64__) | ||
| +#if (defined(__x86_64__) || defined(__aarch64__)) && !defined(__BLST_NO_ASM__) | ||
| /* These are available even in ILP32 flavours, but even then they are |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| # Copyright (c) 2026 The Dash Core developers | ||
| # Distributed under the MIT software license, see the accompanying | ||
| # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
|
||
| LIBDASHBLS_INT = dashbls/libdashbls.la | ||
|
|
||
| noinst_LTLIBRARIES += $(LIBDASHBLS_INT) | ||
| if USE_MIMALLOC | ||
| LIBMIMALLOC_INT = dashbls/libmimalloc-secure.la | ||
| noinst_LTLIBRARIES += $(LIBMIMALLOC_INT) | ||
| endif | ||
|
|
||
| # What consumers link, dependents first: dashbls -> mimalloc -> blst (from depends) | ||
| LIBDASHBLS = $(LIBDASHBLS_INT) $(LIBMIMALLOC_INT) $(BLST_LIBS) | ||
|
|
||
| # Flags for consumers of the library | ||
| DASHBLS_CPPFLAGS = -isystem$(srcdir)/dashbls/include $(BLST_CPPFLAGS) | ||
|
|
||
| # Flags used only when building the library itself. Its headers are treated | ||
| # as system headers, as they are for consumers, so that Dash's warning set | ||
| # (-Werror in CI) does not apply to the vendored code. | ||
| DASHBLS_CPPFLAGS_INT = $(BLST_CPPFLAGS) | ||
| DASHBLS_CPPFLAGS_INT += -isystem$(srcdir)/dashbls/include/dashbls | ||
| DASHBLS_CPPFLAGS_INT += -isystem$(srcdir)/dashbls/depends/mimalloc/include | ||
| if USE_MIMALLOC | ||
| DASHBLS_CPPFLAGS_INT += -DBLSALLOC_MIMALLOC=1 | ||
| endif | ||
|
|
||
| MIMALLOC_CPPFLAGS_INT = | ||
| MIMALLOC_CPPFLAGS_INT += -I$(srcdir)/dashbls/depends/mimalloc/include | ||
| MIMALLOC_CPPFLAGS_INT += -I$(srcdir)/dashbls/depends/mimalloc/src | ||
| MIMALLOC_CPPFLAGS_INT += -DMI_SECURE=4 | ||
| MIMALLOC_CPPFLAGS_INT += -DNDEBUG | ||
|
Comment on lines
+22
to
+33
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🔴 Blocking: Preserve an MSan-compatible allocator configuration The integrated build always defines BLSALLOC_MIMALLOC and links mimalloc, while the MSan configuration removes --disable-mimalloc. On Linux, mimalloc's constructor invokes _mi_auto_process_init(), which initializes the main heap's random context using a stack key filled by syscall(SYS_getrandom, ...). That write has no MSan unpoisoning boundary before random.c consumes the key. This is the same startup failure explicitly documented by the base's c4cecb6 allocator configuration, and the relevant mimalloc path remains present. It executes before Core can install its secure allocator callbacks, so those callbacks do not solve it. Retain allocator selection for MSan or repair the randomness instrumentation boundary rather than unconditionally restoring the previously excluded startup path. source:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved (re-reviewed at |
||
|
|
||
| DASHBLS_H = \ | ||
| dashbls/include/dashbls/bls.hpp \ | ||
| dashbls/include/dashbls/chaincode.hpp \ | ||
| dashbls/include/dashbls/elements.hpp \ | ||
| dashbls/include/dashbls/extendedprivatekey.hpp \ | ||
| dashbls/include/dashbls/extendedpublickey.hpp \ | ||
| dashbls/include/dashbls/hdkeys.hpp \ | ||
| dashbls/include/dashbls/hkdf.hpp \ | ||
| dashbls/include/dashbls/legacy.hpp \ | ||
| dashbls/include/dashbls/privatekey.hpp \ | ||
| dashbls/include/dashbls/schemes.hpp \ | ||
| dashbls/include/dashbls/test-utils.hpp \ | ||
| dashbls/include/dashbls/threshold.hpp \ | ||
| dashbls/include/dashbls/util.hpp | ||
|
|
||
| dashbls_libdashbls_la_SOURCES = \ | ||
| $(DASHBLS_H) \ | ||
| dashbls/src/bls.cpp \ | ||
| dashbls/src/chaincode.cpp \ | ||
| dashbls/src/elements.cpp \ | ||
| dashbls/src/extendedprivatekey.cpp \ | ||
| dashbls/src/extendedpublickey.cpp \ | ||
| dashbls/src/legacy.cpp \ | ||
| dashbls/src/privatekey.cpp \ | ||
| dashbls/src/schemes.cpp \ | ||
| dashbls/src/threshold.cpp | ||
|
|
||
| dashbls_libdashbls_la_CPPFLAGS = $(AM_CPPFLAGS) $(DASHBLS_CPPFLAGS_INT) | ||
|
|
||
| # Specify -static in both CXXFLAGS and LDFLAGS so libtool will only build a | ||
| # static version of this library (same as crc32c and leveldb). | ||
| dashbls_libdashbls_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -static | ||
| dashbls_libdashbls_la_LDFLAGS = $(AM_LDFLAGS) -static | ||
|
|
||
| MIMALLOC_H = \ | ||
| dashbls/depends/mimalloc/include/mimalloc-new-delete.h \ | ||
| dashbls/depends/mimalloc/include/mimalloc-override.h \ | ||
| dashbls/depends/mimalloc/include/mimalloc-stats.h \ | ||
| dashbls/depends/mimalloc/include/mimalloc.h \ | ||
| dashbls/depends/mimalloc/src/bitmap.h | ||
|
|
||
| dashbls_libmimalloc_secure_la_SOURCES = \ | ||
| $(MIMALLOC_H) \ | ||
| dashbls/depends/mimalloc/src/alloc-aligned.c \ | ||
| dashbls/depends/mimalloc/src/alloc-posix.c \ | ||
| dashbls/depends/mimalloc/src/alloc.c \ | ||
| dashbls/depends/mimalloc/src/arena-meta.c \ | ||
| dashbls/depends/mimalloc/src/arena.c \ | ||
| dashbls/depends/mimalloc/src/bitmap.c \ | ||
| dashbls/depends/mimalloc/src/heap.c \ | ||
| dashbls/depends/mimalloc/src/init.c \ | ||
| dashbls/depends/mimalloc/src/libc.c \ | ||
| dashbls/depends/mimalloc/src/options.c \ | ||
| dashbls/depends/mimalloc/src/os.c \ | ||
| dashbls/depends/mimalloc/src/page-map.c \ | ||
| dashbls/depends/mimalloc/src/page.c \ | ||
| dashbls/depends/mimalloc/src/random.c \ | ||
| dashbls/depends/mimalloc/src/stats.c \ | ||
| dashbls/depends/mimalloc/src/prim/prim.c | ||
|
|
||
| dashbls_libmimalloc_secure_la_CPPFLAGS = $(AM_CPPFLAGS) $(MIMALLOC_CPPFLAGS_INT) | ||
| dashbls_libmimalloc_secure_la_CFLAGS = $(AM_CFLAGS) $(PIE_FLAGS) -static | ||
| dashbls_libmimalloc_secure_la_LDFLAGS = $(AM_LDFLAGS) -static | ||
|
|
||
| if ENABLE_TESTS | ||
| if !ENABLE_FUZZ | ||
| DASHBLS_RUNTEST = dashbls/runtest | ||
| TESTS += $(DASHBLS_RUNTEST) | ||
| check_PROGRAMS += $(DASHBLS_RUNTEST) | ||
|
|
||
| dashbls_runtest_SOURCES = \ | ||
| dashbls/src/test.cpp \ | ||
| dashbls/src/test-vectors.hpp \ | ||
| dashbls/depends/catch2/include/catch2/catch.hpp | ||
| dashbls_runtest_CPPFLAGS = $(AM_CPPFLAGS) $(DASHBLS_CPPFLAGS_INT) -isystem$(srcdir)/dashbls/depends/catch2/include | ||
| dashbls_runtest_CPPFLAGS += -DDASHBLS_REFERENCE_VECTORS=\"$(abs_srcdir)/dashbls/test-vectors/reference.txt\" | ||
| dashbls_runtest_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) | ||
| dashbls_runtest_LDADD = $(LIBDASHBLS) | ||
| dashbls_runtest_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS) -static | ||
| endif | ||
| endif | ||
Uh oh!
There was an error while loading. Please reload this page.