Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,10 @@ AC_CHECK_LIB([gmp], [__gmpz_init],GMP_LIBS=-lgmp, AC_MSG_ERROR(libgmp missing))
CPPFLAGS="$TEMP_CPPFLAGS"
LDFLAGS="$TEMP_LDFLAGS"

dnl blst (BLS12-381 backend of src/dashbls), provided by depends or the system
AC_CHECK_HEADER([blst.h],, AC_MSG_ERROR([blst headers missing]))
AC_CHECK_LIB([blst], [blst_p1_compress], [BLST_LIBS=-lblst], AC_MSG_ERROR([libblst missing]))

AM_CONDITIONAL([ENABLE_ZMQ], [test "$use_zmq" = "yes"])

dnl libmultiprocess library check
Expand Down Expand Up @@ -2041,6 +2045,7 @@ AC_SUBST(BACKTRACE_FLAGS)
AC_SUBST(BACKTRACE_LDFLAGS)
AC_SUBST(BACKTRACE_LIBS)
AC_SUBST(GMP_LIBS)
AC_SUBST(BLST_LIBS)
AC_SUBST(NATPMP_CPPFLAGS)
AC_SUBST(NATPMP_LIBS)
AC_SUBST(DSYMUTIL_FLAT)
Expand Down Expand Up @@ -2081,7 +2086,7 @@ fi
dnl The ECDH module is required by the wallet's Platform key provider
dnl (DashPay contact request encryption, wallet/platformkeys.cpp).
ac_configure_args="${ac_configure_args} --disable-shared --with-pic --enable-benchmark=no --enable-module-recovery --enable-module-ecdh --disable-openssl-tests"
AC_CONFIG_SUBDIRS([src/dashbls src/secp256k1])
AC_CONFIG_SUBDIRS([src/secp256k1])

AC_OUTPUT

Expand Down
2 changes: 1 addition & 1 deletion contrib/guix/libexec/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ mkdir -p "$DISTSRC"
${HOST_CXXFLAGS:+CXXFLAGS="${HOST_CXXFLAGS}"} \
${HOST_LDFLAGS:+LDFLAGS="${HOST_LDFLAGS}"}

sed -i.old 's/-lstdc++ //g' {./,src/dashbls/,src/secp256k1/}{config.status,libtool}
sed -i.old 's/-lstdc++ //g' {./,src/secp256k1/}{config.status,libtool}


# Build Dash Core
Expand Down
24 changes: 24 additions & 0 deletions depends/packages/blst.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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

# 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)_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
2 changes: 1 addition & 1 deletion depends/packages/packages.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
packages:=gmp backtrace
packages:=gmp backtrace blst

boost_packages = boost

Expand Down
1 change: 1 addition & 0 deletions doc/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ You can find installation instructions in the `build-*.md` file for your platfor
| --- | --- | --- | --- | --- |
| [Boost](../depends/packages/boost.mk) | [link](https://www.boost.org/users/download/) | 1.81.0 | [1.73.0](https://github.com/bitcoin/bitcoin/pull/29066) | No |
| [libevent](../depends/packages/libevent.mk) | [link](https://github.com/libevent/libevent/releases) | [2.1.12-stable](https://github.com/bitcoin/bitcoin/pull/21991) | [2.1.8](https://github.com/bitcoin/bitcoin/pull/24681) | No |
| [blst](../depends/packages/blst.mk) | [link](https://github.com/supranational/blst/releases) | 0.3.17 | | No |
| glibc | [link](https://www.gnu.org/software/libc/) | N/A | [2.31](https://github.com/bitcoin/bitcoin/pull/29987) | Yes |
| Linux Kernel | [link](https://www.kernel.org/) | N/A | [3.17.0](https://github.com/bitcoin/bitcoin/pull/27699) | Yes |

Expand Down
13 changes: 5 additions & 8 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ endif # ENABLE_CRASH_HOOKS
endif # ENABLE_STACKTRACES

BITCOIN_INCLUDES=-I$(builddir) -I$(srcdir)/$(MINISKETCH_INCLUDE_DIR_INT) -I$(srcdir)/secp256k1/include -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT) $(LEVELDB_CPPFLAGS)
BITCOIN_INCLUDES+=-isystem$(srcdir)/dashbls/include -isystem$(srcdir)/dashbls/depends/relic/include -isystem$(srcdir)/dashbls/depends/minialloc/include
BITCOIN_INCLUDES+=$(DASHBLS_CPPFLAGS)
BITCOIN_INCLUDES+=-isystem$(srcdir)/immer

LIBBITCOIN_NODE=libbitcoin_node.a
Expand All @@ -56,7 +56,6 @@ LIBBITCOIN_CLI=libbitcoin_cli.a
LIBBITCOIN_UTIL=libbitcoin_util.a
LIBBITCOIN_CRYPTO_BASE=crypto/libbitcoin_crypto_base.la
LIBBITCOINQT=qt/libbitcoinqt.a
LIBDASHBLS=dashbls/libdashbls.la
LIBSECP256K1=secp256k1/libsecp256k1.la

if ENABLE_ZMQ
Expand Down Expand Up @@ -110,9 +109,6 @@ LIBBITCOIN_CRYPTO += $(LIBBITCOIN_CRYPTO_ARM_SHANI)
endif
noinst_LTLIBRARIES += $(LIBBITCOIN_CRYPTO)

$(LIBDASHBLS):
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D)

$(LIBSECP256K1): $(wildcard secp256k1/src/*.h) $(wildcard secp256k1/src/*.c) $(wildcard secp256k1/include/*)
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F)

Expand Down Expand Up @@ -1224,7 +1220,7 @@ lib_LTLIBRARIES += $(LIBBITCOINKERNEL)

libdashkernel_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS) $(PTHREAD_FLAGS)
libdashkernel_la_LIBADD = $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) $(LIBSECP256K1) $(LIBDASHBLS) $(GMP_LIBS)
libdashkernel_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL -isystem$(srcdir)/dashbls/include -isystem$(srcdir)/dashbls/depends/relic/include -isystem$(srcdir)/dashbls/depends/minialloc/include -isystem$(srcdir)/immer $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS) -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT)
libdashkernel_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL $(DASHBLS_CPPFLAGS) -isystem$(srcdir)/immer $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS) -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT)

# libdashkernel requires default symbol visibility, explicitly specify that
# here so that things still work even when user configures with
Expand Down Expand Up @@ -1410,7 +1406,7 @@ libdashconsensus_la_SOURCES = support/cleanse.cpp $(crypto_libbitcoin_crypto_bas
libdashconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS)
libdashconsensus_la_LIBADD = $(LIBDASHBLS) $(LIBSECP256K1) $(GMP_LIBS)
libdashconsensus_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL -DDISABLE_OPTIMIZED_SHA256
libdashconsensus_la_CPPFLAGS += -isystem$(srcdir)/dashbls/include -isystem$(srcdir)/dashbls/depends/relic/include -isystem$(srcdir)/dashbls/depends/minialloc/include
libdashconsensus_la_CPPFLAGS += $(DASHBLS_CPPFLAGS)
libdashconsensus_la_CPPFLAGS += -isystem$(srcdir)/immer
libdashconsensus_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)

Expand Down Expand Up @@ -1443,6 +1439,7 @@ CLEANFILES += util/*.gcda util/*.gcno
CLEANFILES += wallet/*.gcda wallet/*.gcno
CLEANFILES += wallet/test/*.gcda wallet/test/*.gcno
CLEANFILES += zmq/*.gcda zmq/*.gcno
CLEANFILES += dashbls/src/*.gcda dashbls/src/*.gcno dashbls/depends/mimalloc/src/*.gcda dashbls/depends/mimalloc/src/*.gcno
CLEANFILES += obj/build.h

IMMER_DIST = immer/immer
Expand All @@ -1462,7 +1459,6 @@ $(top_srcdir)/$(subdir)/config/bitcoin-config.h.in: $(am__configure_deps)


clean-local:
-$(MAKE) -C dashbls clean
-$(MAKE) -C secp256k1 clean
-rm -f leveldb/*/*.gcda leveldb/*/*.gcno leveldb/helpers/memenv/*.gcda leveldb/helpers/memenv/*.gcno
-rm -f config.h
Expand Down Expand Up @@ -1539,6 +1535,7 @@ include Makefile.minisketch.include

include Makefile.crc32c.include
include Makefile.leveldb.include
include Makefile.dashbls.include

include Makefile.test_util.include
include Makefile.test_fuzz.include
Expand Down
111 changes: 111 additions & 0 deletions src/Makefile.dashbls.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# 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
LIBMIMALLOC_INT = dashbls/libmimalloc-secure.la

noinst_LTLIBRARIES += $(LIBDASHBLS_INT)
noinst_LTLIBRARIES += $(LIBMIMALLOC_INT)

# 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

# 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 =
DASHBLS_CPPFLAGS_INT += -isystem$(srcdir)/dashbls/include/dashbls
DASHBLS_CPPFLAGS_INT += -isystem$(srcdir)/dashbls/depends/mimalloc/include
DASHBLS_CPPFLAGS_INT += -DBLSALLOC_MIMALLOC=1

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

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
2 changes: 1 addition & 1 deletion src/bls/bls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ static void create_secure_allocator()

// static variable in function scope ensures it's initialized when first accessed
// and destroyed before LockedPoolManager
static mt_pooled_secure_allocator<uint8_t> a(sizeof(bn_t) + sizeof(size_t));
static mt_pooled_secure_allocator<uint8_t> a(sizeof(blst_p2) + sizeof(size_t));
secure_allocator_instance = &a;
}

Expand Down
18 changes: 11 additions & 7 deletions src/bls/bls.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@
#include <uint256.h>
#include <util/strencodings.h>

// bls-dash uses relic, which may define DEBUG and ERROR, which leads to many warnings in some build setups
#undef ERROR
#undef DEBUG
#include <dashbls/bls.hpp>
#include <dashbls/privatekey.hpp>
#include <dashbls/elements.hpp>
#include <dashbls/schemes.hpp>
#include <dashbls/threshold.hpp>
#undef DOUBLE
#undef SEED

#include <array>
#include <atomic>
#include <mutex>
#include <ranges>
#include <type_traits>

namespace bls {
extern std::atomic<bool> bls_legacy_scheme;
Expand Down Expand Up @@ -127,15 +123,23 @@ class CBLSWrapper
if (!fValid) {
return std::vector<uint8_t>(SerSize, 0);
}
return impl.Serialize(specificLegacyScheme);
if constexpr (std::is_same_v<ImplType, bls::PrivateKey>) {
return impl.Serialize();
} else {
return impl.Serialize(specificLegacyScheme);
}
}

std::array<uint8_t, SerSize> ToBytes(const bool specificLegacyScheme) const
{
if (!fValid) {
return std::array<uint8_t, SerSize>{};
}
return impl.SerializeToArray(specificLegacyScheme);
if constexpr (std::is_same_v<ImplType, bls::PrivateKey>) {
return impl.SerializeToArray();
} else {
return impl.SerializeToArray(specificLegacyScheme);
}
}

const uint256& GetHash() const
Expand Down
4 changes: 0 additions & 4 deletions src/dashbls/.flake8

This file was deleted.

Loading
Loading