diff --git a/libbitcoinkernel-sys/bitcoin/.github/workflows/ci.yml b/libbitcoinkernel-sys/bitcoin/.github/workflows/ci.yml index 3801c187..3ffaafe3 100644 --- a/libbitcoinkernel-sys/bitcoin/.github/workflows/ci.yml +++ b/libbitcoinkernel-sys/bitcoin/.github/workflows/ci.yml @@ -468,7 +468,7 @@ jobs: file-env: './ci/test/00_setup_env_arm.sh' provider: 'gha' - - name: 'ASan + LSan + UBSan + integer, no depends, USDT' + - name: 'ASan + LSan + UBSan + integer' cirrus-runner: 'ghcr.io/cirruslabs/ubuntu-runner-amd64:24.04-md' # has to match container in ci/test/00_setup_env_native_asan.sh for tracing tools fallback-runner: 'ubuntu-24.04' timeout-minutes: 120 @@ -510,7 +510,7 @@ jobs: timeout-minutes: 240 file-env: './ci/test/00_setup_env_native_fuzz_with_valgrind.sh' - - name: 'previous releases, depends DEBUG' + - name: 'previous releases' cirrus-runner: 'ghcr.io/cirruslabs/ubuntu-runner-amd64:24.04-md' fallback-runner: 'ubuntu-24.04' timeout-minutes: 120 diff --git a/libbitcoinkernel-sys/bitcoin/CMakeLists.txt b/libbitcoinkernel-sys/bitcoin/CMakeLists.txt index 3749cf7c..2d21f6e1 100644 --- a/libbitcoinkernel-sys/bitcoin/CMakeLists.txt +++ b/libbitcoinkernel-sys/bitcoin/CMakeLists.txt @@ -463,6 +463,8 @@ else() try_append_cxx_flags("-Wself-assign" TARGET warn_interface SKIP_LINK) try_append_cxx_flags("-Wbidi-chars=any" TARGET warn_interface SKIP_LINK) try_append_cxx_flags("-Wundef" TARGET warn_interface SKIP_LINK) + try_append_cxx_flags("-Wleading-whitespace=spaces" TARGET warn_interface SKIP_LINK) + try_append_cxx_flags("-Wtrailing-whitespace=any" TARGET warn_interface SKIP_LINK) # Some compilers (gcc) ignore unknown -Wno-* options, but warn about all # unknown options if any other warning is produced. Test the -Wfoo case, and @@ -493,8 +495,8 @@ try_append_cxx_flags("-fmacro-prefix-map=A=B" TARGET core_interface SKIP_LINK IF_CHECK_PASSED "-fmacro-prefix-map=${PROJECT_SOURCE_DIR}/src=." ) -# Currently all versions of gcc are subject to a class of bugs, see the -# gccbug_90348 test case (only reproduces on GCC 11 and earlier) and +# GCC versions 13.2 (and earlier) are subject to a class of bugs, see +# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348 and the meta bug # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111843. To work around that, set # -fstack-reuse=none for all gcc builds. (Only gcc understands this flag). try_append_cxx_flags("-fstack-reuse=none" TARGET core_interface) diff --git a/libbitcoinkernel-sys/bitcoin/ci/lint/01_install.sh b/libbitcoinkernel-sys/bitcoin/ci/lint/01_install.sh index 0d8cca98..fc422675 100755 --- a/libbitcoinkernel-sys/bitcoin/ci/lint/01_install.sh +++ b/libbitcoinkernel-sys/bitcoin/ci/lint/01_install.sh @@ -18,7 +18,8 @@ ${CI_RETRY_EXE} apt-get update # - curl/xz-utils (to install shellcheck) # - git (used in many lint scripts) # - gpg (used by verify-commits) -${CI_RETRY_EXE} apt-get install -y cargo curl xz-utils git gpg +# - moreutils (used by scripted-diff) +${CI_RETRY_EXE} apt-get install -y cargo curl xz-utils git gpg moreutils PYTHON_PATH="/python_build" if [ ! -d "${PYTHON_PATH}/bin" ]; then diff --git a/libbitcoinkernel-sys/bitcoin/ci/test/00_setup_env_arm.sh b/libbitcoinkernel-sys/bitcoin/ci/test/00_setup_env_arm.sh index d5b2bb4b..12ec71b8 100755 --- a/libbitcoinkernel-sys/bitcoin/ci/test/00_setup_env_arm.sh +++ b/libbitcoinkernel-sys/bitcoin/ci/test/00_setup_env_arm.sh @@ -19,10 +19,7 @@ export GOAL="install" export CI_LIMIT_STACK_SIZE=1 # -Wno-psabi is to disable ABI warnings: "note: parameter passing for argument of type ... changed in GCC 7.1" # This could be removed once the ABI change warning does not show up by default -# -# -Wno-error=dangling-reference helps to work around a GCC 13.1 false-positive, -# fixed in later versions. export BITCOIN_CONFIG=" \ -DREDUCE_EXPORTS=ON \ - -DCMAKE_CXX_FLAGS='-Wno-psabi -Wno-error=dangling-reference -Wno-error=maybe-uninitialized' \ + -DCMAKE_CXX_FLAGS='-Wno-psabi -Wno-error=maybe-uninitialized' \ " diff --git a/libbitcoinkernel-sys/bitcoin/ci/test/00_setup_env_native_asan.sh b/libbitcoinkernel-sys/bitcoin/ci/test/00_setup_env_native_asan.sh index 229d4fff..0e732240 100755 --- a/libbitcoinkernel-sys/bitcoin/ci/test/00_setup_env_native_asan.sh +++ b/libbitcoinkernel-sys/bitcoin/ci/test/00_setup_env_native_asan.sh @@ -26,7 +26,7 @@ export NO_DEPENDS=1 export GOAL="install" export CI_LIMIT_STACK_SIZE=1 export BITCOIN_CONFIG="\ - -DWITH_USDT=ON -DWITH_ZMQ=ON -DBUILD_GUI=ON \ + --preset=dev-mode \ -DSANITIZERS=address,float-divide-by-zero,integer,undefined \ -DCMAKE_C_COMPILER=clang \ -DCMAKE_CXX_COMPILER=clang++ \ diff --git a/libbitcoinkernel-sys/bitcoin/ci/test/00_setup_env_native_previous_releases.sh b/libbitcoinkernel-sys/bitcoin/ci/test/00_setup_env_native_previous_releases.sh index d9f8d3bf..a44a51c3 100755 --- a/libbitcoinkernel-sys/bitcoin/ci/test/00_setup_env_native_previous_releases.sh +++ b/libbitcoinkernel-sys/bitcoin/ci/test/00_setup_env_native_previous_releases.sh @@ -8,15 +8,16 @@ export LC_ALL=C.UTF-8 export CONTAINER_NAME=ci_native_previous_releases export CI_IMAGE_NAME_TAG="mirror.gcr.io/ubuntu:22.04" -# Use minimum supported python3.10 and gcc-11, see doc/dependencies.md -export PACKAGES="gcc-11 g++-11 python3-zmq" -export DEP_OPTS="CC=gcc-11 CXX=g++-11" +# Use minimum supported python3.10 and gcc-12, see doc/dependencies.md +export PACKAGES="gcc-12 g++-12 python3-zmq" +export DEP_OPTS="CC=gcc-12 CXX=g++-12" export TEST_RUNNER_EXTRA="--previous-releases --coverage --extended --exclude feature_dbcrash" # Run extended tests so that coverage does not fail, but exclude the very slow dbcrash export GOAL="install" export CI_LIMIT_STACK_SIZE=1 export DOWNLOAD_PREVIOUS_RELEASES="true" export BITCOIN_CONFIG="\ - -DWITH_ZMQ=ON -DBUILD_GUI=ON -DREDUCE_EXPORTS=ON \ + --preset=dev-mode \ + -DREDUCE_EXPORTS=ON \ -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_C_FLAGS='-funsigned-char' \ -DCMAKE_C_FLAGS_DEBUG='-g2 -O2' \ diff --git a/libbitcoinkernel-sys/bitcoin/ci/test/00_setup_env_win64.sh b/libbitcoinkernel-sys/bitcoin/ci/test/00_setup_env_win64.sh index 06134457..110db1a8 100755 --- a/libbitcoinkernel-sys/bitcoin/ci/test/00_setup_env_win64.sh +++ b/libbitcoinkernel-sys/bitcoin/ci/test/00_setup_env_win64.sh @@ -13,8 +13,6 @@ export PACKAGES="g++-mingw-w64-x86-64-posix nsis" export RUN_UNIT_TESTS=false export RUN_FUNCTIONAL_TESTS=false export GOAL="deploy" -# -Wno-error=dangling-reference helps to work around a GCC 13.1 false-positive, -# fixed in later versions. export BITCOIN_CONFIG="-DREDUCE_EXPORTS=ON -DBUILD_GUI_TESTS=OFF -DBUILD_KERNEL_LIB=ON -DBUILD_KERNEL_TEST=ON \ - -DCMAKE_CXX_FLAGS='-Wno-error=dangling-reference -Wno-error=maybe-uninitialized' \ + -DCMAKE_CXX_FLAGS='-Wno-error=maybe-uninitialized' \ " diff --git a/libbitcoinkernel-sys/bitcoin/contrib/guix/libexec/build.sh b/libbitcoinkernel-sys/bitcoin/contrib/guix/libexec/build.sh index 16e12d56..09cc058e 100755 --- a/libbitcoinkernel-sys/bitcoin/contrib/guix/libexec/build.sh +++ b/libbitcoinkernel-sys/bitcoin/contrib/guix/libexec/build.sh @@ -225,10 +225,15 @@ esac # LDFLAGS case "$HOST" in - *linux*) HOST_LDFLAGS="-Wl,--as-needed -Wl,--dynamic-linker=$glibc_dynamic_linker -static-libstdc++ -Wl,-O2" ;; + *linux*) HOST_LDFLAGS="-Wl,--as-needed -Wl,--dynamic-linker=$glibc_dynamic_linker -Wl,-O2" ;; *mingw*) HOST_LDFLAGS="-Wl,--no-insert-timestamp" ;; esac +# EXE FLAGS +case "$HOST" in + *linux*) CMAKE_EXE_LINKER_FLAGS="-DCMAKE_EXE_LINKER_FLAGS=${HOST_LDFLAGS} -static-libstdc++ -static-libgcc" ;; +esac + mkdir -p "$DISTSRC" ( cd "$DISTSRC" @@ -243,7 +248,8 @@ mkdir -p "$DISTSRC" --toolchain "${BASEPREFIX}/${HOST}/toolchain.cmake" \ -DWITH_CCACHE=OFF \ -Werror=dev \ - ${CONFIGFLAGS} + ${CONFIGFLAGS} \ + "${CMAKE_EXE_LINKER_FLAGS}" # Build Bitcoin Core cmake --build build -j "$JOBS" ${V:+--verbose} diff --git a/libbitcoinkernel-sys/bitcoin/contrib/guix/manifest.scm b/libbitcoinkernel-sys/bitcoin/contrib/guix/manifest.scm index 3670fcec..011ba0de 100644 --- a/libbitcoinkernel-sys/bitcoin/contrib/guix/manifest.scm +++ b/libbitcoinkernel-sys/bitcoin/contrib/guix/manifest.scm @@ -99,10 +99,10 @@ chain for " target " development.")) (define* (make-bitcoin-cross-toolchain target #:key - (base-gcc-for-libc linux-base-gcc) + (base-gcc-for-libc (gcc-libgcc-patches linux-base-gcc)) (base-kernel-headers base-linux-kernel-headers) (base-libc glibc-2.31) - (base-gcc linux-base-gcc)) + (base-gcc (gcc-libgcc-patches linux-base-gcc))) "Convenience wrapper around MAKE-CROSS-TOOLCHAIN with default values desirable for building Bitcoin Core release binaries." (make-cross-toolchain target @@ -111,7 +111,7 @@ desirable for building Bitcoin Core release binaries." base-libc base-gcc)) -(define (gcc-mingw-patches gcc) +(define (gcc-libgcc-patches gcc) (package-with-extra-patches gcc (search-our-patches "gcc-remap-guix-store.patch"))) @@ -128,10 +128,10 @@ desirable for building Bitcoin Core release binaries." (let* ((xbinutils (binutils-mingw-patches (cross-binutils target))) (machine (substring target 0 (string-index target #\-))) (pthreads-xlibc (winpthreads-patches (make-mingw-w64 machine - #:xgcc (cross-gcc target #:xgcc (gcc-mingw-patches base-gcc)) + #:xgcc (cross-gcc target #:xgcc (gcc-libgcc-patches base-gcc)) #:with-winpthreads? #t))) (pthreads-xgcc (cross-gcc target - #:xgcc (gcc-mingw-patches mingw-w64-base-gcc) + #:xgcc (gcc-libgcc-patches mingw-w64-base-gcc) #:xbinutils xbinutils #:libc pthreads-xlibc))) ;; Define a meta-package that propagates the resulting XBINUTILS, XLIBC, and diff --git a/libbitcoinkernel-sys/bitcoin/contrib/guix/patches/gcc-remap-guix-store.patch b/libbitcoinkernel-sys/bitcoin/contrib/guix/patches/gcc-remap-guix-store.patch index a8b41d48..4144bcd8 100644 --- a/libbitcoinkernel-sys/bitcoin/contrib/guix/patches/gcc-remap-guix-store.patch +++ b/libbitcoinkernel-sys/bitcoin/contrib/guix/patches/gcc-remap-guix-store.patch @@ -1,4 +1,4 @@ -Without ffile-prefix-map, the debug symbols will contain paths for the +Without -ffile-prefix-map, the debug symbols will contain paths for the guix store which will include the hashes of each package. However, the hash for the same package will differ when on different architectures. In order to be reproducible regardless of the architecture used to build @@ -6,7 +6,7 @@ the package, map all guix store prefixes to something fixed, e.g. /usr. --- a/libgcc/Makefile.in +++ b/libgcc/Makefile.in -@@ -854,7 +854,7 @@ endif +@@ -857,7 +857,7 @@ endif # libgcc_eh.a, only LIB2ADDEH matters. If we do, only LIB2ADDEHSTATIC and # LIB2ADDEHSHARED matter. (Usually all three are identical.) @@ -15,6 +15,15 @@ the package, map all guix store prefixes to something fixed, e.g. /usr. ifeq ($(enable_shared),yes) +@@ -880,7 +880,7 @@ endif + # Build LIBUNWIND. Use -fno-exceptions so that the unwind library does + # not generate calls to __gcc_personality_v0. + +-c_flags := -fno-exceptions ++c_flags := -fno-exceptions $(shell find /gnu/store -maxdepth 1 -mindepth 1 -type d -exec echo -n " -ffile-prefix-map={}=/usr" \;) + + libunwind-objects += $(addsuffix $(objext),$(basename $(notdir $(LIBUNWIND)))) + -- 2.37.0 diff --git a/libbitcoinkernel-sys/bitcoin/contrib/guix/symbol-check.py b/libbitcoinkernel-sys/bitcoin/contrib/guix/symbol-check.py index 464b33cf..249c53a2 100755 --- a/libbitcoinkernel-sys/bitcoin/contrib/guix/symbol-check.py +++ b/libbitcoinkernel-sys/bitcoin/contrib/guix/symbol-check.py @@ -16,23 +16,18 @@ # Debian 11 (Bullseye) EOL: 2026. https://wiki.debian.org/LTS # -# - libgcc version 10.2.1 (https://packages.debian.org/bullseye/libgcc-s1) # - libc version 2.31 (https://packages.debian.org/source/bullseye/glibc) # # Ubuntu 20.04 (Focal) EOL: 2030. https://wiki.ubuntu.com/ReleaseTeam # -# - libgcc version 10.5.0 (https://packages.ubuntu.com/focal/libgcc1) # - libc version 2.31 (https://packages.ubuntu.com/focal/libc6) # # CentOS Stream 9 EOL: 2027. https://www.centos.org/cl-vs-cs/#end-of-life # -# - libgcc version 12.2.1 (https://mirror.stream.centos.org/9-stream/AppStream/x86_64/os/Packages/) # - libc version 2.34 (https://mirror.stream.centos.org/9-stream/AppStream/x86_64/os/Packages/) # -# See https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html for more info. MAX_VERSIONS = { -'GCC': (7,0,0), 'GLIBC': { lief.ELF.ARCH.X86_64: (2,31), lief.ELF.ARCH.ARM: (2,31), @@ -40,7 +35,6 @@ lief.ELF.ARCH.PPC64: (2,31), lief.ELF.ARCH.RISCV: (2,31), }, -'LIBATOMIC': (1,0), 'V': (0,5,0), # xkb (bitcoin-qt only) } @@ -93,11 +87,9 @@ # Allowed NEEDED libraries ELF_ALLOWED_LIBRARIES = { # bitcoind and bitcoin-qt -'libgcc_s.so.1', # GCC base support 'libc.so.6', # C library 'libpthread.so.0', # threading 'libm.so.6', # math library -'libatomic.so.1', 'ld-linux-x86-64.so.2', # 64-bit dynamic linker 'ld-linux.so.2', # 32-bit dynamic linker 'ld-linux-aarch64.so.1', # 64-bit ARM dynamic linker diff --git a/libbitcoinkernel-sys/bitcoin/depends/packages/qt.mk b/libbitcoinkernel-sys/bitcoin/depends/packages/qt.mk index 9ac4088e..ad958b7b 100644 --- a/libbitcoinkernel-sys/bitcoin/depends/packages/qt.mk +++ b/libbitcoinkernel-sys/bitcoin/depends/packages/qt.mk @@ -12,7 +12,6 @@ $(package)_freebsd_dependencies := $($(package)_linux_dependencies) $(package)_patches_path := $(qt_details_patches_path) $(package)_patches := dont_hardcode_pwd.patch $(package)_patches += qtbase-moc-ignore-gcc-macro.patch -$(package)_patches += qtbase_avoid_native_float16.patch $(package)_patches += qtbase_avoid_qmain.patch $(package)_patches += qtbase_platformsupport.patch $(package)_patches += qtbase_plugins_cocoa.patch @@ -257,7 +256,6 @@ endif define $(package)_preprocess_cmds patch -p1 -i $($(package)_patch_dir)/dont_hardcode_pwd.patch && \ patch -p1 -i $($(package)_patch_dir)/qtbase-moc-ignore-gcc-macro.patch && \ - patch -p1 -i $($(package)_patch_dir)/qtbase_avoid_native_float16.patch && \ patch -p1 -i $($(package)_patch_dir)/qtbase_avoid_qmain.patch && \ patch -p1 -i $($(package)_patch_dir)/qtbase_platformsupport.patch && \ patch -p1 -i $($(package)_patch_dir)/qtbase_plugins_cocoa.patch && \ diff --git a/libbitcoinkernel-sys/bitcoin/depends/patches/qt/qtbase_avoid_native_float16.patch b/libbitcoinkernel-sys/bitcoin/depends/patches/qt/qtbase_avoid_native_float16.patch deleted file mode 100644 index ec03d140..00000000 --- a/libbitcoinkernel-sys/bitcoin/depends/patches/qt/qtbase_avoid_native_float16.patch +++ /dev/null @@ -1,37 +0,0 @@ -Avoid using native float16 types in Qt's qfloat16 - -Using native float16 types may introduce compatibility issues -in release binaries for Linux platforms. - -See: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=e42d2d2a20f2bb59928bc895ec9f46503a1b5c73 - -This patch can be dropped once the minimum required libgcc version -is updated to 12.x or newer. - - ---- a/qtbase/src/corelib/global/qtypes.h -+++ b/qtbase/src/corelib/global/qtypes.h -@@ -258,23 +258,8 @@ using qsizetype = QIntegerForSizeof::Signed; - - // Define a native float16 type - namespace QtPrivate { --#if defined(__STDCPP_FLOAT16_T__) --# define QFLOAT16_IS_NATIVE 1 --using NativeFloat16Type = std::float16_t; --#elif defined(Q_CC_CLANG) && defined(__FLT16_MAX__) && 0 --// disabled due to https://github.com/llvm/llvm-project/issues/56963 --# define QFLOAT16_IS_NATIVE 1 --using NativeFloat16Type = decltype(__FLT16_MAX__); --#elif defined(Q_CC_GNU_ONLY) && defined(__FLT16_MAX__) && defined(__ARM_FP16_FORMAT_IEEE) --# define QFLOAT16_IS_NATIVE 1 --using NativeFloat16Type = __fp16; --#elif defined(Q_CC_GNU_ONLY) && defined(__FLT16_MAX__) && defined(__SSE2__) --# define QFLOAT16_IS_NATIVE 1 --using NativeFloat16Type = _Float16; --#else - # define QFLOAT16_IS_NATIVE 0 - using NativeFloat16Type = void; --#endif - } // QtPrivate - - #endif // __cplusplus diff --git a/libbitcoinkernel-sys/bitcoin/doc/build-unix.md b/libbitcoinkernel-sys/bitcoin/doc/build-unix.md index d9bbb350..e499aa9b 100644 --- a/libbitcoinkernel-sys/bitcoin/doc/build-unix.md +++ b/libbitcoinkernel-sys/bitcoin/doc/build-unix.md @@ -46,10 +46,14 @@ Finally, clang (often less resource hungry) can be used instead of gcc, which is #### Dependency Build Instructions -Build requirements: +Build requirements for the latest Debian "stable" release, or the latest Ubuntu LTS release: sudo apt-get install build-essential cmake pkgconf python3 +For Debian "oldstable", or earlier Ubuntu LTS releases, you may need to pick a +later compiler version, according to the [dependencies](/doc/dependencies.md) +documentation. + Now, you can either build from self-compiled [depends](#dependencies) or install the required dependencies: sudo apt-get install libevent-dev libboost-dev diff --git a/libbitcoinkernel-sys/bitcoin/doc/dependencies.md b/libbitcoinkernel-sys/bitcoin/doc/dependencies.md index 77391f74..3ff306f8 100644 --- a/libbitcoinkernel-sys/bitcoin/doc/dependencies.md +++ b/libbitcoinkernel-sys/bitcoin/doc/dependencies.md @@ -11,7 +11,7 @@ Bitcoin Core requires one of the following compilers. | Dependency | Minimum required | | --- | --- | | [Clang](https://clang.llvm.org) | [17.0](https://github.com/bitcoin/bitcoin/pull/33555) | -| [GCC](https://gcc.gnu.org) | [11.1](https://github.com/bitcoin/bitcoin/pull/29091) | +| [GCC](https://gcc.gnu.org) | [12.1](https://github.com/bitcoin/bitcoin/pull/33842) | ## Required diff --git a/libbitcoinkernel-sys/bitcoin/doc/i2p.md b/libbitcoinkernel-sys/bitcoin/doc/i2p.md index b769a74d..624b651f 100644 --- a/libbitcoinkernel-sys/bitcoin/doc/i2p.md +++ b/libbitcoinkernel-sys/bitcoin/doc/i2p.md @@ -166,3 +166,13 @@ In most cases, the default router settings should work fine. Please see the "General Guidance for Developers" section in https://geti2p.net/en/docs/api/samv3 if you are developing a downstream application that may be bundling I2P with Bitcoin. + +## Privacy recommendations + +- Operating a node that listens on multiple networks (e.g. IPv4 and I2P) can help + strengthen the Bitcoin network, as nodes in this configuration (i.e. bridge nodes) increase + the cost and complexity of launching eclipse and partition attacks. However, under certain + conditions, an adversary that can connect to your node on multiple networks may be + able to correlate those identities by observing shared runtime characteristics. It + is not recommended to expose your node over multiple networks if you require + unlinkability across those identities. diff --git a/libbitcoinkernel-sys/bitcoin/doc/release-notes-33842.md b/libbitcoinkernel-sys/bitcoin/doc/release-notes-33842.md new file mode 100644 index 00000000..ad15f50b --- /dev/null +++ b/libbitcoinkernel-sys/bitcoin/doc/release-notes-33842.md @@ -0,0 +1,4 @@ +Build System +------------ + +- The minimum supported GCC compiler version has been raised to 12.1 (#33842). diff --git a/libbitcoinkernel-sys/bitcoin/doc/tor.md b/libbitcoinkernel-sys/bitcoin/doc/tor.md index 839c02ee..e9db555f 100644 --- a/libbitcoinkernel-sys/bitcoin/doc/tor.md +++ b/libbitcoinkernel-sys/bitcoin/doc/tor.md @@ -238,3 +238,10 @@ for normal IPv4/IPv6 communication, use: Otherwise it is trivial to link them, which may reduce privacy. Onion services created automatically (as in section 2) always have only one port open. +- Operating a node that listens on multiple networks (e.g. IPv4 and Tor) can help + strengthen the Bitcoin network, as nodes in this configuration (i.e. bridge nodes) increase + the cost and complexity of launching eclipse and partition attacks. However, under certain + conditions, an adversary that can connect to your node on multiple networks may be + able to correlate those identities by observing shared runtime characteristics. It + is not recommended to expose your node over multiple networks if you require + unlinkability across those identities. diff --git a/libbitcoinkernel-sys/bitcoin/src/chain.cpp b/libbitcoinkernel-sys/bitcoin/src/chain.cpp index 3dd22634..94be7180 100644 --- a/libbitcoinkernel-sys/bitcoin/src/chain.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/chain.cpp @@ -6,12 +6,6 @@ #include #include #include -#include - -std::string CBlockFileInfo::ToString() const -{ - return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, FormatISO8601Date(nTimeFirst), FormatISO8601Date(nTimeLast)); -} std::string CBlockIndex::ToString() const { diff --git a/libbitcoinkernel-sys/bitcoin/src/chain.h b/libbitcoinkernel-sys/bitcoin/src/chain.h index 2c865265..64c86357 100644 --- a/libbitcoinkernel-sys/bitcoin/src/chain.h +++ b/libbitcoinkernel-sys/bitcoin/src/chain.h @@ -47,47 +47,6 @@ static constexpr int32_t SEQ_ID_INIT_FROM_DISK = 1; */ static constexpr int64_t MAX_BLOCK_TIME_GAP = 90 * 60; -class CBlockFileInfo -{ -public: - unsigned int nBlocks{}; //!< number of blocks stored in file - unsigned int nSize{}; //!< number of used bytes of block file - unsigned int nUndoSize{}; //!< number of used bytes in the undo file - unsigned int nHeightFirst{}; //!< lowest height of block in file - unsigned int nHeightLast{}; //!< highest height of block in file - uint64_t nTimeFirst{}; //!< earliest time of block in file - uint64_t nTimeLast{}; //!< latest time of block in file - - SERIALIZE_METHODS(CBlockFileInfo, obj) - { - READWRITE(VARINT(obj.nBlocks)); - READWRITE(VARINT(obj.nSize)); - READWRITE(VARINT(obj.nUndoSize)); - READWRITE(VARINT(obj.nHeightFirst)); - READWRITE(VARINT(obj.nHeightLast)); - READWRITE(VARINT(obj.nTimeFirst)); - READWRITE(VARINT(obj.nTimeLast)); - } - - CBlockFileInfo() = default; - - std::string ToString() const; - - /** update statistics (does not update nSize) */ - void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn) - { - if (nBlocks == 0 || nHeightFirst > nHeightIn) - nHeightFirst = nHeightIn; - if (nBlocks == 0 || nTimeFirst > nTimeIn) - nTimeFirst = nTimeIn; - nBlocks++; - if (nHeightIn > nHeightLast) - nHeightLast = nHeightIn; - if (nTimeIn > nTimeLast) - nTimeLast = nTimeIn; - } -}; - enum BlockStatus : uint32_t { //! Unused. BLOCK_VALID_UNKNOWN = 0, diff --git a/libbitcoinkernel-sys/bitcoin/src/coins.cpp b/libbitcoinkernel-sys/bitcoin/src/coins.cpp index 090d36dd..554a3ebe 100644 --- a/libbitcoinkernel-sys/bitcoin/src/coins.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/coins.cpp @@ -349,8 +349,8 @@ void CCoinsViewCache::SanityCheck() const assert(recomputed_usage == cachedCoinsUsage); } -static const size_t MIN_TRANSACTION_OUTPUT_WEIGHT = WITNESS_SCALE_FACTOR * ::GetSerializeSize(CTxOut()); -static const size_t MAX_OUTPUTS_PER_BLOCK = MAX_BLOCK_WEIGHT / MIN_TRANSACTION_OUTPUT_WEIGHT; +static const uint64_t MIN_TRANSACTION_OUTPUT_WEIGHT{WITNESS_SCALE_FACTOR * ::GetSerializeSize(CTxOut())}; +static const uint64_t MAX_OUTPUTS_PER_BLOCK{MAX_BLOCK_WEIGHT / MIN_TRANSACTION_OUTPUT_WEIGHT}; const Coin& AccessByTxid(const CCoinsViewCache& view, const Txid& txid) { diff --git a/libbitcoinkernel-sys/bitcoin/src/crypto/sha256_sse4.cpp b/libbitcoinkernel-sys/bitcoin/src/crypto/sha256_sse4.cpp index 3de30f74..2d37d124 100644 --- a/libbitcoinkernel-sys/bitcoin/src/crypto/sha256_sse4.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/crypto/sha256_sse4.cpp @@ -969,27 +969,27 @@ void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks) /* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; Copyright (c) 2012, Intel Corporation -; -; All rights reserved. -; +; Copyright (c) 2012, Intel Corporation +; +; All rights reserved. +; ; Redistribution and use in source and binary forms, with or without ; modification, are permitted provided that the following conditions are -; met: -; +; met: +; ; * Redistributions of source code must retain the above copyright -; notice, this list of conditions and the following disclaimer. -; +; notice, this list of conditions and the following disclaimer. +; ; * Redistributions in binary form must reproduce the above copyright ; notice, this list of conditions and the following disclaimer in the ; documentation and/or other materials provided with the -; distribution. -; +; distribution. +; ; * Neither the name of the Intel Corporation nor the names of its ; contributors may be used to endorse or promote products derived from -; this software without specific prior written permission. -; -; +; this software without specific prior written permission. +; +; ; THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY ; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -1020,15 +1020,15 @@ void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks) ; This code schedules 1 blocks at a time, with 4 lanes per block ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -%define MOVDQ movdqu ;; assume buffers not aligned +%define MOVDQ movdqu ;; assume buffers not aligned ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Define Macros ; addm [mem], reg ; Add reg to mem using reg-mem add and store %macro addm 2 - add %2, %1 - mov %1, %2 + add %2, %1 + mov %1, %2 %endm ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -1054,31 +1054,31 @@ void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks) %define XTMP4 xmm8 %define XFER xmm9 -%define SHUF_00BA xmm10 ; shuffle xBxA -> 00BA -%define SHUF_DC00 xmm11 ; shuffle xDxC -> DC00 -%define BYTE_FLIP_MASK xmm12 - +%define SHUF_00BA xmm10 ; shuffle xBxA -> 00BA +%define SHUF_DC00 xmm11 ; shuffle xDxC -> DC00 +%define BYTE_FLIP_MASK xmm12 + %ifdef LINUX -%define NUM_BLKS rdx ; 3rd arg -%define CTX rsi ; 2nd arg -%define INP rdi ; 1st arg - -%define SRND rdi ; clobbers INP -%define c ecx -%define d r8d -%define e edx +%define NUM_BLKS rdx ; 3rd arg +%define CTX rsi ; 2nd arg +%define INP rdi ; 1st arg + +%define SRND rdi ; clobbers INP +%define c ecx +%define d r8d +%define e edx %else -%define NUM_BLKS r8 ; 3rd arg -%define CTX rdx ; 2nd arg -%define INP rcx ; 1st arg - -%define SRND rcx ; clobbers INP -%define c edi -%define d esi -%define e r8d - +%define NUM_BLKS r8 ; 3rd arg +%define CTX rdx ; 2nd arg +%define INP rcx ; 1st arg + +%define SRND rcx ; clobbers INP +%define c edi +%define d esi +%define e r8d + %endif -%define TBL rbp +%define TBL rbp %define a eax %define b ebx @@ -1092,22 +1092,22 @@ void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks) -_INP_END_SIZE equ 8 -_INP_SIZE equ 8 -_XFER_SIZE equ 8 +_INP_END_SIZE equ 8 +_INP_SIZE equ 8 +_XFER_SIZE equ 8 %ifdef LINUX -_XMM_SAVE_SIZE equ 0 +_XMM_SAVE_SIZE equ 0 %else -_XMM_SAVE_SIZE equ 7*16 +_XMM_SAVE_SIZE equ 7*16 %endif ; STACK_SIZE plus pushes must be an odd multiple of 8 -_ALIGN_SIZE equ 8 +_ALIGN_SIZE equ 8 -_INP_END equ 0 -_INP equ _INP_END + _INP_END_SIZE -_XFER equ _INP + _INP_SIZE -_XMM_SAVE equ _XFER + _XFER_SIZE + _ALIGN_SIZE -STACK_SIZE equ _XMM_SAVE + _XMM_SAVE_SIZE +_INP_END equ 0 +_INP equ _INP_END + _INP_END_SIZE +_XFER equ _INP + _INP_SIZE +_XMM_SAVE equ _XFER + _XFER_SIZE + _ALIGN_SIZE +STACK_SIZE equ _XMM_SAVE + _XMM_SAVE_SIZE ; rotate_Xs ; Rotate values of symbols X0...X3 @@ -1134,168 +1134,168 @@ STACK_SIZE equ _XMM_SAVE + _XMM_SAVE_SIZE %endm %macro FOUR_ROUNDS_AND_SCHED 0 - ;; compute s0 four at a time and s1 two at a time - ;; compute W[-16] + W[-7] 4 at a time - movdqa XTMP0, X3 - mov y0, e ; y0 = e - ror y0, (25-11) ; y0 = e >> (25-11) - mov y1, a ; y1 = a - palignr XTMP0, X2, 4 ; XTMP0 = W[-7] - ror y1, (22-13) ; y1 = a >> (22-13) - xor y0, e ; y0 = e ^ (e >> (25-11)) - mov y2, f ; y2 = f - ror y0, (11-6) ; y0 = (e >> (11-6)) ^ (e >> (25-6)) - movdqa XTMP1, X1 - xor y1, a ; y1 = a ^ (a >> (22-13) - xor y2, g ; y2 = f^g - paddd XTMP0, X0 ; XTMP0 = W[-7] + W[-16] - xor y0, e ; y0 = e ^ (e >> (11-6)) ^ (e >> (25-6)) - and y2, e ; y2 = (f^g)&e - ror y1, (13-2) ; y1 = (a >> (13-2)) ^ (a >> (22-2)) - ;; compute s0 - palignr XTMP1, X0, 4 ; XTMP1 = W[-15] - xor y1, a ; y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) - ror y0, 6 ; y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) - xor y2, g ; y2 = CH = ((f^g)&e)^g - movdqa XTMP2, XTMP1 ; XTMP2 = W[-15] - ror y1, 2 ; y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) - add y2, y0 ; y2 = S1 + CH - add y2, [rsp + _XFER + 0*4] ; y2 = k + w + S1 + CH - movdqa XTMP3, XTMP1 ; XTMP3 = W[-15] - mov y0, a ; y0 = a - add h, y2 ; h = h + S1 + CH + k + w - mov y2, a ; y2 = a - pslld XTMP1, (32-7) - or y0, c ; y0 = a|c - add d, h ; d = d + h + S1 + CH + k + w - and y2, c ; y2 = a&c - psrld XTMP2, 7 - and y0, b ; y0 = (a|c)&b - add h, y1 ; h = h + S1 + CH + k + w + S0 - por XTMP1, XTMP2 ; XTMP1 = W[-15] ror 7 - or y0, y2 ; y0 = MAJ = (a|c)&b)|(a&c) - add h, y0 ; h = h + S1 + CH + k + w + S0 + MAJ + ;; compute s0 four at a time and s1 two at a time + ;; compute W[-16] + W[-7] 4 at a time + movdqa XTMP0, X3 + mov y0, e ; y0 = e + ror y0, (25-11) ; y0 = e >> (25-11) + mov y1, a ; y1 = a + palignr XTMP0, X2, 4 ; XTMP0 = W[-7] + ror y1, (22-13) ; y1 = a >> (22-13) + xor y0, e ; y0 = e ^ (e >> (25-11)) + mov y2, f ; y2 = f + ror y0, (11-6) ; y0 = (e >> (11-6)) ^ (e >> (25-6)) + movdqa XTMP1, X1 + xor y1, a ; y1 = a ^ (a >> (22-13) + xor y2, g ; y2 = f^g + paddd XTMP0, X0 ; XTMP0 = W[-7] + W[-16] + xor y0, e ; y0 = e ^ (e >> (11-6)) ^ (e >> (25-6)) + and y2, e ; y2 = (f^g)&e + ror y1, (13-2) ; y1 = (a >> (13-2)) ^ (a >> (22-2)) + ;; compute s0 + palignr XTMP1, X0, 4 ; XTMP1 = W[-15] + xor y1, a ; y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) + ror y0, 6 ; y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) + xor y2, g ; y2 = CH = ((f^g)&e)^g + movdqa XTMP2, XTMP1 ; XTMP2 = W[-15] + ror y1, 2 ; y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) + add y2, y0 ; y2 = S1 + CH + add y2, [rsp + _XFER + 0*4] ; y2 = k + w + S1 + CH + movdqa XTMP3, XTMP1 ; XTMP3 = W[-15] + mov y0, a ; y0 = a + add h, y2 ; h = h + S1 + CH + k + w + mov y2, a ; y2 = a + pslld XTMP1, (32-7) + or y0, c ; y0 = a|c + add d, h ; d = d + h + S1 + CH + k + w + and y2, c ; y2 = a&c + psrld XTMP2, 7 + and y0, b ; y0 = (a|c)&b + add h, y1 ; h = h + S1 + CH + k + w + S0 + por XTMP1, XTMP2 ; XTMP1 = W[-15] ror 7 + or y0, y2 ; y0 = MAJ = (a|c)&b)|(a&c) + add h, y0 ; h = h + S1 + CH + k + w + S0 + MAJ ROTATE_ARGS - movdqa XTMP2, XTMP3 ; XTMP2 = W[-15] - mov y0, e ; y0 = e - mov y1, a ; y1 = a - movdqa XTMP4, XTMP3 ; XTMP4 = W[-15] - ror y0, (25-11) ; y0 = e >> (25-11) - xor y0, e ; y0 = e ^ (e >> (25-11)) - mov y2, f ; y2 = f - ror y1, (22-13) ; y1 = a >> (22-13) - pslld XTMP3, (32-18) - xor y1, a ; y1 = a ^ (a >> (22-13) - ror y0, (11-6) ; y0 = (e >> (11-6)) ^ (e >> (25-6)) - xor y2, g ; y2 = f^g - psrld XTMP2, 18 - ror y1, (13-2) ; y1 = (a >> (13-2)) ^ (a >> (22-2)) - xor y0, e ; y0 = e ^ (e >> (11-6)) ^ (e >> (25-6)) - and y2, e ; y2 = (f^g)&e - ror y0, 6 ; y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) - pxor XTMP1, XTMP3 - xor y1, a ; y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) - xor y2, g ; y2 = CH = ((f^g)&e)^g - psrld XTMP4, 3 ; XTMP4 = W[-15] >> 3 - add y2, y0 ; y2 = S1 + CH - add y2, [rsp + _XFER + 1*4] ; y2 = k + w + S1 + CH - ror y1, 2 ; y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) - pxor XTMP1, XTMP2 ; XTMP1 = W[-15] ror 7 ^ W[-15] ror 18 - mov y0, a ; y0 = a - add h, y2 ; h = h + S1 + CH + k + w - mov y2, a ; y2 = a - pxor XTMP1, XTMP4 ; XTMP1 = s0 - or y0, c ; y0 = a|c - add d, h ; d = d + h + S1 + CH + k + w - and y2, c ; y2 = a&c - ;; compute low s1 - pshufd XTMP2, X3, 11111010b ; XTMP2 = W[-2] {BBAA} - and y0, b ; y0 = (a|c)&b - add h, y1 ; h = h + S1 + CH + k + w + S0 - paddd XTMP0, XTMP1 ; XTMP0 = W[-16] + W[-7] + s0 - or y0, y2 ; y0 = MAJ = (a|c)&b)|(a&c) - add h, y0 ; h = h + S1 + CH + k + w + S0 + MAJ + movdqa XTMP2, XTMP3 ; XTMP2 = W[-15] + mov y0, e ; y0 = e + mov y1, a ; y1 = a + movdqa XTMP4, XTMP3 ; XTMP4 = W[-15] + ror y0, (25-11) ; y0 = e >> (25-11) + xor y0, e ; y0 = e ^ (e >> (25-11)) + mov y2, f ; y2 = f + ror y1, (22-13) ; y1 = a >> (22-13) + pslld XTMP3, (32-18) + xor y1, a ; y1 = a ^ (a >> (22-13) + ror y0, (11-6) ; y0 = (e >> (11-6)) ^ (e >> (25-6)) + xor y2, g ; y2 = f^g + psrld XTMP2, 18 + ror y1, (13-2) ; y1 = (a >> (13-2)) ^ (a >> (22-2)) + xor y0, e ; y0 = e ^ (e >> (11-6)) ^ (e >> (25-6)) + and y2, e ; y2 = (f^g)&e + ror y0, 6 ; y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) + pxor XTMP1, XTMP3 + xor y1, a ; y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) + xor y2, g ; y2 = CH = ((f^g)&e)^g + psrld XTMP4, 3 ; XTMP4 = W[-15] >> 3 + add y2, y0 ; y2 = S1 + CH + add y2, [rsp + _XFER + 1*4] ; y2 = k + w + S1 + CH + ror y1, 2 ; y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) + pxor XTMP1, XTMP2 ; XTMP1 = W[-15] ror 7 ^ W[-15] ror 18 + mov y0, a ; y0 = a + add h, y2 ; h = h + S1 + CH + k + w + mov y2, a ; y2 = a + pxor XTMP1, XTMP4 ; XTMP1 = s0 + or y0, c ; y0 = a|c + add d, h ; d = d + h + S1 + CH + k + w + and y2, c ; y2 = a&c + ;; compute low s1 + pshufd XTMP2, X3, 11111010b ; XTMP2 = W[-2] {BBAA} + and y0, b ; y0 = (a|c)&b + add h, y1 ; h = h + S1 + CH + k + w + S0 + paddd XTMP0, XTMP1 ; XTMP0 = W[-16] + W[-7] + s0 + or y0, y2 ; y0 = MAJ = (a|c)&b)|(a&c) + add h, y0 ; h = h + S1 + CH + k + w + S0 + MAJ ROTATE_ARGS - movdqa XTMP3, XTMP2 ; XTMP3 = W[-2] {BBAA} - mov y0, e ; y0 = e - mov y1, a ; y1 = a - ror y0, (25-11) ; y0 = e >> (25-11) - movdqa XTMP4, XTMP2 ; XTMP4 = W[-2] {BBAA} - xor y0, e ; y0 = e ^ (e >> (25-11)) - ror y1, (22-13) ; y1 = a >> (22-13) - mov y2, f ; y2 = f - xor y1, a ; y1 = a ^ (a >> (22-13) - ror y0, (11-6) ; y0 = (e >> (11-6)) ^ (e >> (25-6)) - psrlq XTMP2, 17 ; XTMP2 = W[-2] ror 17 {xBxA} - xor y2, g ; y2 = f^g - psrlq XTMP3, 19 ; XTMP3 = W[-2] ror 19 {xBxA} - xor y0, e ; y0 = e ^ (e >> (11-6)) ^ (e >> (25-6)) - and y2, e ; y2 = (f^g)&e - psrld XTMP4, 10 ; XTMP4 = W[-2] >> 10 {BBAA} - ror y1, (13-2) ; y1 = (a >> (13-2)) ^ (a >> (22-2)) - xor y1, a ; y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) - xor y2, g ; y2 = CH = ((f^g)&e)^g - ror y0, 6 ; y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) - pxor XTMP2, XTMP3 - add y2, y0 ; y2 = S1 + CH - ror y1, 2 ; y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) - add y2, [rsp + _XFER + 2*4] ; y2 = k + w + S1 + CH - pxor XTMP4, XTMP2 ; XTMP4 = s1 {xBxA} - mov y0, a ; y0 = a - add h, y2 ; h = h + S1 + CH + k + w - mov y2, a ; y2 = a - pshufb XTMP4, SHUF_00BA ; XTMP4 = s1 {00BA} - or y0, c ; y0 = a|c - add d, h ; d = d + h + S1 + CH + k + w - and y2, c ; y2 = a&c - paddd XTMP0, XTMP4 ; XTMP0 = {..., ..., W[1], W[0]} - and y0, b ; y0 = (a|c)&b - add h, y1 ; h = h + S1 + CH + k + w + S0 - ;; compute high s1 - pshufd XTMP2, XTMP0, 01010000b ; XTMP2 = W[-2] {DDCC} - or y0, y2 ; y0 = MAJ = (a|c)&b)|(a&c) - add h, y0 ; h = h + S1 + CH + k + w + S0 + MAJ + movdqa XTMP3, XTMP2 ; XTMP3 = W[-2] {BBAA} + mov y0, e ; y0 = e + mov y1, a ; y1 = a + ror y0, (25-11) ; y0 = e >> (25-11) + movdqa XTMP4, XTMP2 ; XTMP4 = W[-2] {BBAA} + xor y0, e ; y0 = e ^ (e >> (25-11)) + ror y1, (22-13) ; y1 = a >> (22-13) + mov y2, f ; y2 = f + xor y1, a ; y1 = a ^ (a >> (22-13) + ror y0, (11-6) ; y0 = (e >> (11-6)) ^ (e >> (25-6)) + psrlq XTMP2, 17 ; XTMP2 = W[-2] ror 17 {xBxA} + xor y2, g ; y2 = f^g + psrlq XTMP3, 19 ; XTMP3 = W[-2] ror 19 {xBxA} + xor y0, e ; y0 = e ^ (e >> (11-6)) ^ (e >> (25-6)) + and y2, e ; y2 = (f^g)&e + psrld XTMP4, 10 ; XTMP4 = W[-2] >> 10 {BBAA} + ror y1, (13-2) ; y1 = (a >> (13-2)) ^ (a >> (22-2)) + xor y1, a ; y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) + xor y2, g ; y2 = CH = ((f^g)&e)^g + ror y0, 6 ; y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) + pxor XTMP2, XTMP3 + add y2, y0 ; y2 = S1 + CH + ror y1, 2 ; y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) + add y2, [rsp + _XFER + 2*4] ; y2 = k + w + S1 + CH + pxor XTMP4, XTMP2 ; XTMP4 = s1 {xBxA} + mov y0, a ; y0 = a + add h, y2 ; h = h + S1 + CH + k + w + mov y2, a ; y2 = a + pshufb XTMP4, SHUF_00BA ; XTMP4 = s1 {00BA} + or y0, c ; y0 = a|c + add d, h ; d = d + h + S1 + CH + k + w + and y2, c ; y2 = a&c + paddd XTMP0, XTMP4 ; XTMP0 = {..., ..., W[1], W[0]} + and y0, b ; y0 = (a|c)&b + add h, y1 ; h = h + S1 + CH + k + w + S0 + ;; compute high s1 + pshufd XTMP2, XTMP0, 01010000b ; XTMP2 = W[-2] {DDCC} + or y0, y2 ; y0 = MAJ = (a|c)&b)|(a&c) + add h, y0 ; h = h + S1 + CH + k + w + S0 + MAJ ROTATE_ARGS - movdqa XTMP3, XTMP2 ; XTMP3 = W[-2] {DDCC} - mov y0, e ; y0 = e - ror y0, (25-11) ; y0 = e >> (25-11) - mov y1, a ; y1 = a - movdqa X0, XTMP2 ; X0 = W[-2] {DDCC} - ror y1, (22-13) ; y1 = a >> (22-13) - xor y0, e ; y0 = e ^ (e >> (25-11)) - mov y2, f ; y2 = f - ror y0, (11-6) ; y0 = (e >> (11-6)) ^ (e >> (25-6)) - psrlq XTMP2, 17 ; XTMP2 = W[-2] ror 17 {xDxC} - xor y1, a ; y1 = a ^ (a >> (22-13) - xor y2, g ; y2 = f^g - psrlq XTMP3, 19 ; XTMP3 = W[-2] ror 19 {xDxC} - xor y0, e ; y0 = e ^ (e >> (11-6)) ^ (e >> (25-6)) - and y2, e ; y2 = (f^g)&e - ror y1, (13-2) ; y1 = (a >> (13-2)) ^ (a >> (22-2)) - psrld X0, 10 ; X0 = W[-2] >> 10 {DDCC} - xor y1, a ; y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) - ror y0, 6 ; y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) - xor y2, g ; y2 = CH = ((f^g)&e)^g - pxor XTMP2, XTMP3 - ror y1, 2 ; y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) - add y2, y0 ; y2 = S1 + CH - add y2, [rsp + _XFER + 3*4] ; y2 = k + w + S1 + CH - pxor X0, XTMP2 ; X0 = s1 {xDxC} - mov y0, a ; y0 = a - add h, y2 ; h = h + S1 + CH + k + w - mov y2, a ; y2 = a - pshufb X0, SHUF_DC00 ; X0 = s1 {DC00} - or y0, c ; y0 = a|c - add d, h ; d = d + h + S1 + CH + k + w - and y2, c ; y2 = a&c - paddd X0, XTMP0 ; X0 = {W[3], W[2], W[1], W[0]} - and y0, b ; y0 = (a|c)&b - add h, y1 ; h = h + S1 + CH + k + w + S0 - or y0, y2 ; y0 = MAJ = (a|c)&b)|(a&c) - add h, y0 ; h = h + S1 + CH + k + w + S0 + MAJ + movdqa XTMP3, XTMP2 ; XTMP3 = W[-2] {DDCC} + mov y0, e ; y0 = e + ror y0, (25-11) ; y0 = e >> (25-11) + mov y1, a ; y1 = a + movdqa X0, XTMP2 ; X0 = W[-2] {DDCC} + ror y1, (22-13) ; y1 = a >> (22-13) + xor y0, e ; y0 = e ^ (e >> (25-11)) + mov y2, f ; y2 = f + ror y0, (11-6) ; y0 = (e >> (11-6)) ^ (e >> (25-6)) + psrlq XTMP2, 17 ; XTMP2 = W[-2] ror 17 {xDxC} + xor y1, a ; y1 = a ^ (a >> (22-13) + xor y2, g ; y2 = f^g + psrlq XTMP3, 19 ; XTMP3 = W[-2] ror 19 {xDxC} + xor y0, e ; y0 = e ^ (e >> (11-6)) ^ (e >> (25-6)) + and y2, e ; y2 = (f^g)&e + ror y1, (13-2) ; y1 = (a >> (13-2)) ^ (a >> (22-2)) + psrld X0, 10 ; X0 = W[-2] >> 10 {DDCC} + xor y1, a ; y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) + ror y0, 6 ; y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) + xor y2, g ; y2 = CH = ((f^g)&e)^g + pxor XTMP2, XTMP3 + ror y1, 2 ; y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) + add y2, y0 ; y2 = S1 + CH + add y2, [rsp + _XFER + 3*4] ; y2 = k + w + S1 + CH + pxor X0, XTMP2 ; X0 = s1 {xDxC} + mov y0, a ; y0 = a + add h, y2 ; h = h + S1 + CH + k + w + mov y2, a ; y2 = a + pshufb X0, SHUF_DC00 ; X0 = s1 {DC00} + or y0, c ; y0 = a|c + add d, h ; d = d + h + S1 + CH + k + w + and y2, c ; y2 = a&c + paddd X0, XTMP0 ; X0 = {W[3], W[2], W[1], W[0]} + and y0, b ; y0 = (a|c)&b + add h, y1 ; h = h + S1 + CH + k + w + S0 + or y0, y2 ; y0 = MAJ = (a|c)&b)|(a&c) + add h, y0 ; h = h + S1 + CH + k + w + S0 + MAJ ROTATE_ARGS rotate_Xs @@ -1303,34 +1303,34 @@ rotate_Xs ;; input is [rsp + _XFER + %1 * 4] %macro DO_ROUND 1 - mov y0, e ; y0 = e - ror y0, (25-11) ; y0 = e >> (25-11) - mov y1, a ; y1 = a - xor y0, e ; y0 = e ^ (e >> (25-11)) - ror y1, (22-13) ; y1 = a >> (22-13) - mov y2, f ; y2 = f - xor y1, a ; y1 = a ^ (a >> (22-13) - ror y0, (11-6) ; y0 = (e >> (11-6)) ^ (e >> (25-6)) - xor y2, g ; y2 = f^g - xor y0, e ; y0 = e ^ (e >> (11-6)) ^ (e >> (25-6)) - ror y1, (13-2) ; y1 = (a >> (13-2)) ^ (a >> (22-2)) - and y2, e ; y2 = (f^g)&e - xor y1, a ; y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) - ror y0, 6 ; y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) - xor y2, g ; y2 = CH = ((f^g)&e)^g - add y2, y0 ; y2 = S1 + CH - ror y1, 2 ; y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) - add y2, [rsp + _XFER + %1 * 4] ; y2 = k + w + S1 + CH - mov y0, a ; y0 = a - add h, y2 ; h = h + S1 + CH + k + w - mov y2, a ; y2 = a - or y0, c ; y0 = a|c - add d, h ; d = d + h + S1 + CH + k + w - and y2, c ; y2 = a&c - and y0, b ; y0 = (a|c)&b - add h, y1 ; h = h + S1 + CH + k + w + S0 - or y0, y2 ; y0 = MAJ = (a|c)&b)|(a&c) - add h, y0 ; h = h + S1 + CH + k + w + S0 + MAJ + mov y0, e ; y0 = e + ror y0, (25-11) ; y0 = e >> (25-11) + mov y1, a ; y1 = a + xor y0, e ; y0 = e ^ (e >> (25-11)) + ror y1, (22-13) ; y1 = a >> (22-13) + mov y2, f ; y2 = f + xor y1, a ; y1 = a ^ (a >> (22-13) + ror y0, (11-6) ; y0 = (e >> (11-6)) ^ (e >> (25-6)) + xor y2, g ; y2 = f^g + xor y0, e ; y0 = e ^ (e >> (11-6)) ^ (e >> (25-6)) + ror y1, (13-2) ; y1 = (a >> (13-2)) ^ (a >> (22-2)) + and y2, e ; y2 = (f^g)&e + xor y1, a ; y1 = a ^ (a >> (13-2)) ^ (a >> (22-2)) + ror y0, 6 ; y0 = S1 = (e>>6) & (e>>11) ^ (e>>25) + xor y2, g ; y2 = CH = ((f^g)&e)^g + add y2, y0 ; y2 = S1 + CH + ror y1, 2 ; y1 = S0 = (a>>2) ^ (a>>13) ^ (a>>22) + add y2, [rsp + _XFER + %1 * 4] ; y2 = k + w + S1 + CH + mov y0, a ; y0 = a + add h, y2 ; h = h + S1 + CH + k + w + mov y2, a ; y2 = a + or y0, c ; y0 = a|c + add d, h ; d = d + h + S1 + CH + k + w + and y2, c ; y2 = a&c + and y0, b ; y0 = (a|c)&b + add h, y1 ; h = h + S1 + CH + k + w + S0 + or y0, y2 ; y0 = MAJ = (a|c)&b)|(a&c) + add h, y0 ; h = h + S1 + CH + k + w + S0 + MAJ ROTATE_ARGS %endm @@ -1344,166 +1344,166 @@ section .text global sha256_sse4 align 32 sha256_sse4: - push rbx + push rbx %ifndef LINUX - push rsi - push rdi + push rsi + push rdi %endif - push rbp - push r13 - push r14 - push r15 + push rbp + push r13 + push r14 + push r15 - sub rsp,STACK_SIZE + sub rsp,STACK_SIZE %ifndef LINUX - movdqa [rsp + _XMM_SAVE + 0*16],xmm6 - movdqa [rsp + _XMM_SAVE + 1*16],xmm7 - movdqa [rsp + _XMM_SAVE + 2*16],xmm8 - movdqa [rsp + _XMM_SAVE + 3*16],xmm9 - movdqa [rsp + _XMM_SAVE + 4*16],xmm10 - movdqa [rsp + _XMM_SAVE + 5*16],xmm11 - movdqa [rsp + _XMM_SAVE + 6*16],xmm12 + movdqa [rsp + _XMM_SAVE + 0*16],xmm6 + movdqa [rsp + _XMM_SAVE + 1*16],xmm7 + movdqa [rsp + _XMM_SAVE + 2*16],xmm8 + movdqa [rsp + _XMM_SAVE + 3*16],xmm9 + movdqa [rsp + _XMM_SAVE + 4*16],xmm10 + movdqa [rsp + _XMM_SAVE + 5*16],xmm11 + movdqa [rsp + _XMM_SAVE + 6*16],xmm12 %endif - shl NUM_BLKS, 6 ; convert to bytes - jz done_hash - add NUM_BLKS, INP ; pointer to end of data - mov [rsp + _INP_END], NUM_BLKS + shl NUM_BLKS, 6 ; convert to bytes + jz done_hash + add NUM_BLKS, INP ; pointer to end of data + mov [rsp + _INP_END], NUM_BLKS ;; load initial digest - mov a,[4*0 + CTX] - mov b,[4*1 + CTX] - mov c,[4*2 + CTX] - mov d,[4*3 + CTX] - mov e,[4*4 + CTX] - mov f,[4*5 + CTX] - mov g,[4*6 + CTX] - mov h,[4*7 + CTX] - - movdqa BYTE_FLIP_MASK, [PSHUFFLE_BYTE_FLIP_MASK wrt rip] - movdqa SHUF_00BA, [_SHUF_00BA wrt rip] - movdqa SHUF_DC00, [_SHUF_DC00 wrt rip] + mov a,[4*0 + CTX] + mov b,[4*1 + CTX] + mov c,[4*2 + CTX] + mov d,[4*3 + CTX] + mov e,[4*4 + CTX] + mov f,[4*5 + CTX] + mov g,[4*6 + CTX] + mov h,[4*7 + CTX] + + movdqa BYTE_FLIP_MASK, [PSHUFFLE_BYTE_FLIP_MASK wrt rip] + movdqa SHUF_00BA, [_SHUF_00BA wrt rip] + movdqa SHUF_DC00, [_SHUF_DC00 wrt rip] loop0: - lea TBL,[K256 wrt rip] + lea TBL,[K256 wrt rip] ;; byte swap first 16 dwords - COPY_XMM_AND_BSWAP X0, [INP + 0*16], BYTE_FLIP_MASK - COPY_XMM_AND_BSWAP X1, [INP + 1*16], BYTE_FLIP_MASK - COPY_XMM_AND_BSWAP X2, [INP + 2*16], BYTE_FLIP_MASK - COPY_XMM_AND_BSWAP X3, [INP + 3*16], BYTE_FLIP_MASK - - mov [rsp + _INP], INP + COPY_XMM_AND_BSWAP X0, [INP + 0*16], BYTE_FLIP_MASK + COPY_XMM_AND_BSWAP X1, [INP + 1*16], BYTE_FLIP_MASK + COPY_XMM_AND_BSWAP X2, [INP + 2*16], BYTE_FLIP_MASK + COPY_XMM_AND_BSWAP X3, [INP + 3*16], BYTE_FLIP_MASK + + mov [rsp + _INP], INP ;; schedule 48 input dwords, by doing 3 rounds of 16 each - mov SRND, 3 + mov SRND, 3 align 16 loop1: - movdqa XFER, [TBL + 0*16] - paddd XFER, X0 - movdqa [rsp + _XFER], XFER + movdqa XFER, [TBL + 0*16] + paddd XFER, X0 + movdqa [rsp + _XFER], XFER FOUR_ROUNDS_AND_SCHED - movdqa XFER, [TBL + 1*16] - paddd XFER, X0 - movdqa [rsp + _XFER], XFER + movdqa XFER, [TBL + 1*16] + paddd XFER, X0 + movdqa [rsp + _XFER], XFER FOUR_ROUNDS_AND_SCHED - movdqa XFER, [TBL + 2*16] - paddd XFER, X0 - movdqa [rsp + _XFER], XFER + movdqa XFER, [TBL + 2*16] + paddd XFER, X0 + movdqa [rsp + _XFER], XFER FOUR_ROUNDS_AND_SCHED - movdqa XFER, [TBL + 3*16] - paddd XFER, X0 - movdqa [rsp + _XFER], XFER - add TBL, 4*16 + movdqa XFER, [TBL + 3*16] + paddd XFER, X0 + movdqa [rsp + _XFER], XFER + add TBL, 4*16 FOUR_ROUNDS_AND_SCHED - sub SRND, 1 - jne loop1 + sub SRND, 1 + jne loop1 - mov SRND, 2 + mov SRND, 2 loop2: - paddd X0, [TBL + 0*16] - movdqa [rsp + _XFER], X0 - DO_ROUND 0 - DO_ROUND 1 - DO_ROUND 2 - DO_ROUND 3 - paddd X1, [TBL + 1*16] - movdqa [rsp + _XFER], X1 - add TBL, 2*16 - DO_ROUND 0 - DO_ROUND 1 - DO_ROUND 2 - DO_ROUND 3 - - movdqa X0, X2 - movdqa X1, X3 - - sub SRND, 1 - jne loop2 - - addm [4*0 + CTX],a - addm [4*1 + CTX],b - addm [4*2 + CTX],c - addm [4*3 + CTX],d - addm [4*4 + CTX],e - addm [4*5 + CTX],f - addm [4*6 + CTX],g - addm [4*7 + CTX],h - - mov INP, [rsp + _INP] - add INP, 64 - cmp INP, [rsp + _INP_END] - jne loop0 + paddd X0, [TBL + 0*16] + movdqa [rsp + _XFER], X0 + DO_ROUND 0 + DO_ROUND 1 + DO_ROUND 2 + DO_ROUND 3 + paddd X1, [TBL + 1*16] + movdqa [rsp + _XFER], X1 + add TBL, 2*16 + DO_ROUND 0 + DO_ROUND 1 + DO_ROUND 2 + DO_ROUND 3 + + movdqa X0, X2 + movdqa X1, X3 + + sub SRND, 1 + jne loop2 + + addm [4*0 + CTX],a + addm [4*1 + CTX],b + addm [4*2 + CTX],c + addm [4*3 + CTX],d + addm [4*4 + CTX],e + addm [4*5 + CTX],f + addm [4*6 + CTX],g + addm [4*7 + CTX],h + + mov INP, [rsp + _INP] + add INP, 64 + cmp INP, [rsp + _INP_END] + jne loop0 done_hash: %ifndef LINUX - movdqa xmm6,[rsp + _XMM_SAVE + 0*16] - movdqa xmm7,[rsp + _XMM_SAVE + 1*16] - movdqa xmm8,[rsp + _XMM_SAVE + 2*16] - movdqa xmm9,[rsp + _XMM_SAVE + 3*16] - movdqa xmm10,[rsp + _XMM_SAVE + 4*16] - movdqa xmm11,[rsp + _XMM_SAVE + 5*16] - movdqa xmm12,[rsp + _XMM_SAVE + 6*16] + movdqa xmm6,[rsp + _XMM_SAVE + 0*16] + movdqa xmm7,[rsp + _XMM_SAVE + 1*16] + movdqa xmm8,[rsp + _XMM_SAVE + 2*16] + movdqa xmm9,[rsp + _XMM_SAVE + 3*16] + movdqa xmm10,[rsp + _XMM_SAVE + 4*16] + movdqa xmm11,[rsp + _XMM_SAVE + 5*16] + movdqa xmm12,[rsp + _XMM_SAVE + 6*16] %endif - add rsp, STACK_SIZE + add rsp, STACK_SIZE - pop r15 - pop r14 - pop r13 - pop rbp + pop r15 + pop r14 + pop r13 + pop rbp %ifndef LINUX - pop rdi - pop rsi + pop rdi + pop rsi %endif - pop rbx + pop rbx + + ret - ret - section .data align 64 K256: - dd 0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5 - dd 0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5 - dd 0xd807aa98,0x12835b01,0x243185be,0x550c7dc3 - dd 0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174 - dd 0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc - dd 0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da - dd 0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7 - dd 0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967 - dd 0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13 - dd 0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85 - dd 0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3 - dd 0xd192e819,0xd6990624,0xf40e3585,0x106aa070 - dd 0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5 - dd 0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3 - dd 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208 - dd 0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2 + dd 0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5 + dd 0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5 + dd 0xd807aa98,0x12835b01,0x243185be,0x550c7dc3 + dd 0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174 + dd 0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc + dd 0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da + dd 0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7 + dd 0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967 + dd 0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13 + dd 0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85 + dd 0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3 + dd 0xd192e819,0xd6990624,0xf40e3585,0x106aa070 + dd 0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5 + dd 0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3 + dd 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208 + dd 0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2 PSHUFFLE_BYTE_FLIP_MASK: ddq 0x0c0d0e0f08090a0b0405060700010203 diff --git a/libbitcoinkernel-sys/bitcoin/src/flatfile.h b/libbitcoinkernel-sys/bitcoin/src/flatfile.h index 3edb0b85..3ec4eaf3 100644 --- a/libbitcoinkernel-sys/bitcoin/src/flatfile.h +++ b/libbitcoinkernel-sys/bitcoin/src/flatfile.h @@ -13,16 +13,16 @@ struct FlatFilePos { - int nFile{-1}; - unsigned int nPos{0}; + int32_t nFile{-1}; + uint32_t nPos{0}; SERIALIZE_METHODS(FlatFilePos, obj) { READWRITE(VARINT_MODE(obj.nFile, VarIntMode::NONNEGATIVE_SIGNED), VARINT(obj.nPos)); } FlatFilePos() = default; - FlatFilePos(int nFileIn, unsigned int nPosIn) : - nFile(nFileIn), - nPos(nPosIn) + FlatFilePos(int32_t nFileIn, uint32_t nPosIn) + : nFile{nFileIn}, + nPos{nPosIn} {} friend bool operator==(const FlatFilePos &a, const FlatFilePos &b) { diff --git a/libbitcoinkernel-sys/bitcoin/src/index/blockfilterindex.cpp b/libbitcoinkernel-sys/bitcoin/src/index/blockfilterindex.cpp index 032a0b60..4bf2f5e6 100644 --- a/libbitcoinkernel-sys/bitcoin/src/index/blockfilterindex.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/index/blockfilterindex.cpp @@ -222,9 +222,9 @@ size_t BlockFilterIndex::WriteFilterToDisk(FlatFilePos& pos, const BlockFilter& { assert(filter.GetFilterType() == GetFilterType()); - size_t data_size = + uint64_t data_size{ GetSerializeSize(filter.GetBlockHash()) + - GetSerializeSize(filter.GetEncodedFilter()); + GetSerializeSize(filter.GetEncodedFilter())}; // If writing the filter would overflow the file, flush and move to the next one. if (pos.nPos + data_size > MAX_FLTR_FILE_SIZE) { diff --git a/libbitcoinkernel-sys/bitcoin/src/index/disktxpos.h b/libbitcoinkernel-sys/bitcoin/src/index/disktxpos.h index a0363846..5e4352db 100644 --- a/libbitcoinkernel-sys/bitcoin/src/index/disktxpos.h +++ b/libbitcoinkernel-sys/bitcoin/src/index/disktxpos.h @@ -10,14 +10,14 @@ struct CDiskTxPos : public FlatFilePos { - unsigned int nTxOffset{0}; // after header + uint32_t nTxOffset{0}; // after header SERIALIZE_METHODS(CDiskTxPos, obj) { READWRITE(AsBase(obj), VARINT(obj.nTxOffset)); } - CDiskTxPos(const FlatFilePos &blockIn, unsigned int nTxOffsetIn) : FlatFilePos(blockIn.nFile, blockIn.nPos), nTxOffset(nTxOffsetIn) { + CDiskTxPos(const FlatFilePos& blockIn, uint32_t nTxOffsetIn) : FlatFilePos{blockIn.nFile, blockIn.nPos}, nTxOffset{nTxOffsetIn} { } CDiskTxPos() = default; diff --git a/libbitcoinkernel-sys/bitcoin/src/kernel/bitcoinkernel.cpp b/libbitcoinkernel-sys/bitcoin/src/kernel/bitcoinkernel.cpp index 240255bb..0b9ea513 100644 --- a/libbitcoinkernel-sys/bitcoin/src/kernel/bitcoinkernel.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/kernel/bitcoinkernel.cpp @@ -497,6 +497,9 @@ struct btck_Txid: Handle {}; btck_Transaction* btck_transaction_create(const void* raw_transaction, size_t raw_transaction_len) { + if (raw_transaction == nullptr && raw_transaction_len != 0) { + return nullptr; + } try { DataStream stream{std::span{reinterpret_cast(raw_transaction), raw_transaction_len}}; return btck_Transaction::create(std::make_shared(deserialize, TX_WITH_WITNESS, stream)); @@ -556,6 +559,9 @@ void btck_transaction_destroy(btck_Transaction* transaction) btck_ScriptPubkey* btck_script_pubkey_create(const void* script_pubkey, size_t script_pubkey_len) { + if (script_pubkey == nullptr && script_pubkey_len != 0) { + return nullptr; + } auto data = std::span{reinterpret_cast(script_pubkey), script_pubkey_len}; return btck_ScriptPubkey::create(data.begin(), data.end()); } @@ -1033,6 +1039,9 @@ int btck_chainstate_manager_import_blocks(btck_ChainstateManager* chainman, cons btck_Block* btck_block_create(const void* raw_block, size_t raw_block_length) { + if (raw_block == nullptr && raw_block_length != 0) { + return nullptr; + } auto block{std::make_shared()}; DataStream stream{std::span{reinterpret_cast(raw_block), raw_block_length}}; diff --git a/libbitcoinkernel-sys/bitcoin/src/kernel/bitcoinkernel.h b/libbitcoinkernel-sys/bitcoin/src/kernel/bitcoinkernel.h index 4c94b59f..93e160cd 100644 --- a/libbitcoinkernel-sys/bitcoin/src/kernel/bitcoinkernel.h +++ b/libbitcoinkernel-sys/bitcoin/src/kernel/bitcoinkernel.h @@ -469,12 +469,12 @@ typedef uint8_t btck_ChainType; /** * @brief Create a new transaction from the serialized data. * - * @param[in] raw_transaction Non-null. + * @param[in] raw_transaction Serialized transaction. * @param[in] raw_transaction_len Length of the serialized transaction. * @return The transaction, or null on error. */ BITCOINKERNEL_API btck_Transaction* BITCOINKERNEL_WARN_UNUSED_RESULT btck_transaction_create( - const void* raw_transaction, size_t raw_transaction_len) BITCOINKERNEL_ARG_NONNULL(1); + const void* raw_transaction, size_t raw_transaction_len); /** * @brief Copy a transaction. Transactions are reference counted, so this just @@ -567,12 +567,12 @@ BITCOINKERNEL_API void btck_transaction_destroy(btck_Transaction* transaction); /** * @brief Create a script pubkey from serialized data. - * @param[in] script_pubkey Non-null. + * @param[in] script_pubkey Serialized script pubkey. * @param[in] script_pubkey_len Length of the script pubkey data. * @return The script pubkey. */ BITCOINKERNEL_API btck_ScriptPubkey* BITCOINKERNEL_WARN_UNUSED_RESULT btck_script_pubkey_create( - const void* script_pubkey, size_t script_pubkey_len) BITCOINKERNEL_ARG_NONNULL(1); + const void* script_pubkey, size_t script_pubkey_len); /** * @brief Copy a script pubkey. @@ -1111,12 +1111,12 @@ BITCOINKERNEL_API btck_Block* BITCOINKERNEL_WARN_UNUSED_RESULT btck_block_read( /** * @brief Parse a serialized raw block into a new block object. * - * @param[in] raw_block Non-null, serialized block. + * @param[in] raw_block Serialized block. * @param[in] raw_block_len Length of the serialized block. * @return The allocated block, or null on error. */ BITCOINKERNEL_API btck_Block* BITCOINKERNEL_WARN_UNUSED_RESULT btck_block_create( - const void* raw_block, size_t raw_block_len) BITCOINKERNEL_ARG_NONNULL(1); + const void* raw_block, size_t raw_block_len); /** * @brief Copy a block. Blocks are reference counted, so this just increments diff --git a/libbitcoinkernel-sys/bitcoin/src/node/blockstorage.cpp b/libbitcoinkernel-sys/bitcoin/src/node/blockstorage.cpp index 00ba109b..a9b9b9a6 100644 --- a/libbitcoinkernel-sys/bitcoin/src/node/blockstorage.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/node/blockstorage.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -151,6 +152,11 @@ bool BlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, s return true; } + +std::string CBlockFileInfo::ToString() const +{ + return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, FormatISO8601Date(nTimeFirst), FormatISO8601Date(nTimeLast)); +} } // namespace kernel namespace node { diff --git a/libbitcoinkernel-sys/bitcoin/src/node/blockstorage.h b/libbitcoinkernel-sys/bitcoin/src/node/blockstorage.h index caf291e9..d5da95c7 100644 --- a/libbitcoinkernel-sys/bitcoin/src/node/blockstorage.h +++ b/libbitcoinkernel-sys/bitcoin/src/node/blockstorage.h @@ -47,6 +47,47 @@ class SignalInterrupt; } // namespace util namespace kernel { +class CBlockFileInfo +{ +public: + uint32_t nBlocks{}; //!< number of blocks stored in file + uint32_t nSize{}; //!< number of used bytes of block file + uint32_t nUndoSize{}; //!< number of used bytes in the undo file + uint32_t nHeightFirst{}; //!< lowest height of block in file + uint32_t nHeightLast{}; //!< highest height of block in file + uint64_t nTimeFirst{}; //!< earliest time of block in file + uint64_t nTimeLast{}; //!< latest time of block in file + + SERIALIZE_METHODS(CBlockFileInfo, obj) + { + READWRITE(VARINT(obj.nBlocks)); + READWRITE(VARINT(obj.nSize)); + READWRITE(VARINT(obj.nUndoSize)); + READWRITE(VARINT(obj.nHeightFirst)); + READWRITE(VARINT(obj.nHeightLast)); + READWRITE(VARINT(obj.nTimeFirst)); + READWRITE(VARINT(obj.nTimeLast)); + } + + CBlockFileInfo() = default; + + std::string ToString() const; + + /** update statistics (does not update nSize) */ + void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn) + { + if (nBlocks == 0 || nHeightFirst > nHeightIn) + nHeightFirst = nHeightIn; + if (nBlocks == 0 || nTimeFirst > nTimeIn) + nTimeFirst = nTimeIn; + nBlocks++; + if (nHeightIn > nHeightLast) + nHeightLast = nHeightIn; + if (nTimeIn > nTimeLast) + nTimeLast = nTimeIn; + } +}; + /** Access to the block database (blocks/index/) */ class BlockTreeDB : public CDBWrapper { @@ -65,6 +106,7 @@ class BlockTreeDB : public CDBWrapper } // namespace kernel namespace node { +using kernel::CBlockFileInfo; using kernel::BlockTreeDB; /** The pre-allocation chunk size for blk?????.dat files (since 0.8) */ diff --git a/libbitcoinkernel-sys/bitcoin/src/policy/policy.cpp b/libbitcoinkernel-sys/bitcoin/src/policy/policy.cpp index 3da6cb74..e749b14f 100644 --- a/libbitcoinkernel-sys/bitcoin/src/policy/policy.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/policy/policy.cpp @@ -42,7 +42,7 @@ CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFeeIn) if (txout.scriptPubKey.IsUnspendable()) return 0; - size_t nSize = GetSerializeSize(txout); + uint64_t nSize{GetSerializeSize(txout)}; int witnessversion = 0; std::vector witnessprogram; diff --git a/libbitcoinkernel-sys/bitcoin/src/qt/CMakeLists.txt b/libbitcoinkernel-sys/bitcoin/src/qt/CMakeLists.txt index c23a7ec6..58fa08b5 100644 --- a/libbitcoinkernel-sys/bitcoin/src/qt/CMakeLists.txt +++ b/libbitcoinkernel-sys/bitcoin/src/qt/CMakeLists.txt @@ -50,11 +50,19 @@ endfunction() set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC_MOC_OPTIONS "-p${CMAKE_CURRENT_SOURCE_DIR}") -set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOUIC_SEARCH_PATHS forms) +set(CMAKE_AUTORCC OFF) configure_file(bitcoin_locale.qrc bitcoin_locale.qrc USE_SOURCE_PERMISSIONS COPYONLY) +qt6_add_resources(BITCOIN_QRC bitcoin.qrc) +qt6_add_resources(BITCOIN_LOCALE_QRC ${CMAKE_CURRENT_BINARY_DIR}/bitcoin_locale.qrc) +# See: https://bugreports.qt.io/browse/QTBUG-141858. +get_target_property(warn_flags warn_interface INTERFACE_COMPILE_OPTIONS) +if("-Wtrailing-whitespace=any" IN_LIST warn_flags) + set_source_files_properties(${BITCOIN_QRC} ${BITCOIN_LOCALE_QRC} PROPERTIES COMPILE_OPTIONS -Wno-trailing-whitespace) +endif() +unset(warn_flags) # The bitcoinqt sources have to include headers in # order to parse them to collect translatable strings. @@ -119,8 +127,8 @@ add_library(bitcoinqt STATIC EXCLUDE_FROM_ALL utilitydialog.h $<$:winshutdownmonitor.cpp> $<$:winshutdownmonitor.h> - bitcoin.qrc - ${CMAKE_CURRENT_BINARY_DIR}/bitcoin_locale.qrc + ${BITCOIN_QRC} + ${BITCOIN_LOCALE_QRC} ) target_compile_definitions(bitcoinqt PUBLIC diff --git a/libbitcoinkernel-sys/bitcoin/src/rpc/blockchain.cpp b/libbitcoinkernel-sys/bitcoin/src/rpc/blockchain.cpp index 2ff5f529..4ef7bc96 100644 --- a/libbitcoinkernel-sys/bitcoin/src/rpc/blockchain.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/rpc/blockchain.cpp @@ -185,9 +185,9 @@ UniValue blockToJSON(BlockManager& blockman, const CBlock& block, const CBlockIn { UniValue result = blockheaderToJSON(tip, blockindex, pow_limit); - result.pushKV("strippedsize", (int)::GetSerializeSize(TX_NO_WITNESS(block))); - result.pushKV("size", (int)::GetSerializeSize(TX_WITH_WITNESS(block))); - result.pushKV("weight", (int)::GetBlockWeight(block)); + result.pushKV("strippedsize", ::GetSerializeSize(TX_NO_WITNESS(block))); + result.pushKV("size", ::GetSerializeSize(TX_WITH_WITNESS(block))); + result.pushKV("weight", ::GetBlockWeight(block)); UniValue txs(UniValue::VARR); txs.reserve(block.vtx.size()); @@ -2033,7 +2033,7 @@ static RPCHelpMan getblockstats() for (const CTxOut& out : tx->vout) { tx_total_out += out.nValue; - size_t out_size = GetSerializeSize(out) + PER_UTXO_OVERHEAD; + uint64_t out_size{GetSerializeSize(out) + PER_UTXO_OVERHEAD}; utxo_size_inc += out_size; // The Genesis block and the repeated BIP30 block coinbases don't change the UTXO @@ -2085,7 +2085,7 @@ static RPCHelpMan getblockstats() const CTxOut& prevoutput = coin.out; tx_total_in += prevoutput.nValue; - size_t prevout_size = GetSerializeSize(prevoutput) + PER_UTXO_OVERHEAD; + uint64_t prevout_size{GetSerializeSize(prevoutput) + PER_UTXO_OVERHEAD}; utxo_size_inc -= prevout_size; utxo_size_inc_actual -= prevout_size; } diff --git a/libbitcoinkernel-sys/bitcoin/src/serialize.h b/libbitcoinkernel-sys/bitcoin/src/serialize.h index e88a25fa..4da48a0b 100644 --- a/libbitcoinkernel-sys/bitcoin/src/serialize.h +++ b/libbitcoinkernel-sys/bitcoin/src/serialize.h @@ -1051,31 +1051,32 @@ struct ActionUnserialize { class SizeComputer { protected: - size_t nSize{0}; + uint64_t m_size{0}; public: SizeComputer() = default; void write(std::span src) { - this->nSize += src.size(); + m_size += src.size(); } - /** Pretend _nSize bytes are written, without specifying them. */ - void seek(size_t _nSize) + /** Pretend this many bytes are written, without specifying them. */ + void seek(uint64_t num) { - this->nSize += _nSize; + m_size += num; } - template + template SizeComputer& operator<<(const T& obj) { ::Serialize(*this, obj); - return (*this); + return *this; } - size_t size() const { - return nSize; + uint64_t size() const + { + return m_size; } }; @@ -1091,7 +1092,7 @@ inline void WriteCompactSize(SizeComputer &s, uint64_t nSize) } template -size_t GetSerializeSize(const T& t) +uint64_t GetSerializeSize(const T& t) { return (SizeComputer() << t).size(); } diff --git a/libbitcoinkernel-sys/bitcoin/src/test/CMakeLists.txt b/libbitcoinkernel-sys/bitcoin/src/test/CMakeLists.txt index a67cd241..9528004e 100644 --- a/libbitcoinkernel-sys/bitcoin/src/test/CMakeLists.txt +++ b/libbitcoinkernel-sys/bitcoin/src/test/CMakeLists.txt @@ -34,7 +34,6 @@ add_executable(test_bitcoin coinscachepair_tests.cpp coinstatsindex_tests.cpp common_url_tests.cpp - compilerbug_tests.cpp compress_tests.cpp crypto_tests.cpp cuckoocache_tests.cpp diff --git a/libbitcoinkernel-sys/bitcoin/src/test/arith_uint256_tests.cpp b/libbitcoinkernel-sys/bitcoin/src/test/arith_uint256_tests.cpp index 38ff46cc..b0d75cde 100644 --- a/libbitcoinkernel-sys/bitcoin/src/test/arith_uint256_tests.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/test/arith_uint256_tests.cpp @@ -368,7 +368,7 @@ static bool almostEqual(double d1, double d2) return fabs(d1-d2) <= 4*fabs(d1)*std::numeric_limits::epsilon(); } -BOOST_AUTO_TEST_CASE(methods) // GetHex operator= size() GetLow64 GetSerializeSize, Serialize, Unserialize +BOOST_AUTO_TEST_CASE(methods) { BOOST_CHECK(R1L.GetHex() == R1L.ToString()); BOOST_CHECK(R2L.GetHex() == R2L.ToString()); diff --git a/libbitcoinkernel-sys/bitcoin/src/test/blockmanager_tests.cpp b/libbitcoinkernel-sys/bitcoin/src/test/blockmanager_tests.cpp index f06665d3..a3504da6 100644 --- a/libbitcoinkernel-sys/bitcoin/src/test/blockmanager_tests.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/test/blockmanager_tests.cpp @@ -17,6 +17,7 @@ #include #include +using kernel::CBlockFileInfo; using node::STORAGE_HEADER_BYTES; using node::BlockManager; using node::KernelNotifications; @@ -60,16 +61,16 @@ BOOST_AUTO_TEST_CASE(blockmanager_find_block_pos) BOOST_FIXTURE_TEST_CASE(blockmanager_scan_unlink_already_pruned_files, TestChain100Setup) { // Cap last block file size, and mine new block in a new block file. - const auto& chainman = Assert(m_node.chainman); - auto& blockman = chainman->m_blockman; - const CBlockIndex* old_tip{WITH_LOCK(chainman->GetMutex(), return chainman->ActiveChain().Tip())}; - WITH_LOCK(chainman->GetMutex(), blockman.GetBlockFileInfo(old_tip->GetBlockPos().nFile)->nSize = MAX_BLOCKFILE_SIZE); + auto& chainman{*Assert(m_node.chainman)}; + auto& blockman{chainman.m_blockman}; + const CBlockIndex* old_tip{WITH_LOCK(chainman.GetMutex(), return chainman.ActiveChain().Tip())}; + WITH_LOCK(chainman.GetMutex(), blockman.GetBlockFileInfo(old_tip->GetBlockPos().nFile)->nSize = MAX_BLOCKFILE_SIZE); CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); // Prune the older block file, but don't unlink it int file_number; { - LOCK(chainman->GetMutex()); + LOCK(chainman.GetMutex()); file_number = old_tip->GetBlockPos().nFile; blockman.PruneOneBlockFile(file_number); } @@ -78,22 +79,22 @@ BOOST_FIXTURE_TEST_CASE(blockmanager_scan_unlink_already_pruned_files, TestChain // Check that the file is not unlinked after ScanAndUnlinkAlreadyPrunedFiles // if m_have_pruned is not yet set - WITH_LOCK(chainman->GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles()); + WITH_LOCK(chainman.GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles()); BOOST_CHECK(!blockman.OpenBlockFile(pos, true).IsNull()); // Check that the file is unlinked after ScanAndUnlinkAlreadyPrunedFiles // once m_have_pruned is set blockman.m_have_pruned = true; - WITH_LOCK(chainman->GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles()); + WITH_LOCK(chainman.GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles()); BOOST_CHECK(blockman.OpenBlockFile(pos, true).IsNull()); // Check that calling with already pruned files doesn't cause an error - WITH_LOCK(chainman->GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles()); + WITH_LOCK(chainman.GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles()); // Check that the new tip file has not been removed - const CBlockIndex* new_tip{WITH_LOCK(chainman->GetMutex(), return chainman->ActiveChain().Tip())}; + const CBlockIndex* new_tip{WITH_LOCK(chainman.GetMutex(), return chainman.ActiveChain().Tip())}; BOOST_CHECK_NE(old_tip, new_tip); - const int new_file_number{WITH_LOCK(chainman->GetMutex(), return new_tip->GetBlockPos().nFile)}; + const int new_file_number{WITH_LOCK(chainman.GetMutex(), return new_tip->GetBlockPos().nFile)}; const FlatFilePos new_pos(new_file_number, 0); BOOST_CHECK(!blockman.OpenBlockFile(new_pos, true).IsNull()); } diff --git a/libbitcoinkernel-sys/bitcoin/src/test/compilerbug_tests.cpp b/libbitcoinkernel-sys/bitcoin/src/test/compilerbug_tests.cpp deleted file mode 100644 index ef558c1e..00000000 --- a/libbitcoinkernel-sys/bitcoin/src/test/compilerbug_tests.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) 2019-2021 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include - -BOOST_AUTO_TEST_SUITE(compilerbug_tests) - -#if defined(__GNUC__) -// This block will also be built under clang, which is fine (as it supports noinline) -void __attribute__ ((noinline)) set_one(unsigned char* ptr) -{ - *ptr = 1; -} - -int __attribute__ ((noinline)) check_zero(unsigned char const* in, unsigned int len) -{ - for (unsigned int i = 0; i < len; ++i) { - if (in[i] != 0) return 0; - } - return 1; -} - -void set_one_on_stack() { - unsigned char buf[1]; - set_one(buf); -} - -BOOST_AUTO_TEST_CASE(gccbug_90348) { - // Test for GCC bug 90348. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348 - for (int i = 0; i <= 4; ++i) { - unsigned char in[4]; - for (int j = 0; j < i; ++j) { - in[j] = 0; - set_one_on_stack(); // Apparently modifies in[0] - } - BOOST_CHECK(check_zero(in, i)); - } -} -#endif - -BOOST_AUTO_TEST_SUITE_END() diff --git a/libbitcoinkernel-sys/bitcoin/src/test/flatfile_tests.cpp b/libbitcoinkernel-sys/bitcoin/src/test/flatfile_tests.cpp index d94cab64..5ef603ca 100644 --- a/libbitcoinkernel-sys/bitcoin/src/test/flatfile_tests.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/test/flatfile_tests.cpp @@ -39,8 +39,8 @@ BOOST_AUTO_TEST_CASE(flatfile_open) std::string line2("Digital signatures provide part of the solution, but the main benefits are " "lost if a trusted third party is still required to prevent double-spending."); - size_t pos1 = 0; - size_t pos2 = pos1 + GetSerializeSize(line1); + uint64_t pos1{0}; + uint64_t pos2{pos1 + GetSerializeSize(line1)}; // Write first line to file. { diff --git a/libbitcoinkernel-sys/bitcoin/src/test/fs_tests.cpp b/libbitcoinkernel-sys/bitcoin/src/test/fs_tests.cpp index 28fcf952..89188904 100644 --- a/libbitcoinkernel-sys/bitcoin/src/test/fs_tests.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/test/fs_tests.cpp @@ -139,28 +139,4 @@ BOOST_AUTO_TEST_CASE(rename) fs::remove(path2); } -#ifndef __MINGW64__ // no symlinks on mingw -BOOST_AUTO_TEST_CASE(create_directories) -{ - // Test fs::create_directories workaround. - const fs::path tmpfolder{m_args.GetDataDirBase()}; - - const fs::path dir{tmpfolder / "a"}; - fs::create_directory(dir); - BOOST_CHECK(fs::exists(dir)); - BOOST_CHECK(fs::is_directory(dir)); - BOOST_CHECK(!fs::create_directories(dir)); - - const fs::path symlink{tmpfolder / "b"}; - fs::create_directory_symlink(dir, symlink); - BOOST_CHECK(fs::exists(symlink)); - BOOST_CHECK(fs::is_symlink(symlink)); - BOOST_CHECK(fs::is_directory(symlink)); - BOOST_CHECK(!fs::create_directories(symlink)); - - fs::remove(symlink); - fs::remove(dir); -} -#endif // __MINGW64__ - BOOST_AUTO_TEST_SUITE_END() diff --git a/libbitcoinkernel-sys/bitcoin/src/test/fuzz/block_index.cpp b/libbitcoinkernel-sys/bitcoin/src/test/fuzz/block_index.cpp index 5bc6240c..8e7210e5 100644 --- a/libbitcoinkernel-sys/bitcoin/src/test/fuzz/block_index.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/test/fuzz/block_index.cpp @@ -12,6 +12,8 @@ #include #include +using kernel::CBlockFileInfo; + namespace { const BasicTestingSetup* g_setup; diff --git a/libbitcoinkernel-sys/bitcoin/src/test/fuzz/deserialize.cpp b/libbitcoinkernel-sys/bitcoin/src/test/fuzz/deserialize.cpp index 05ca62b6..97985ef0 100644 --- a/libbitcoinkernel-sys/bitcoin/src/test/fuzz/deserialize.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/test/fuzz/deserialize.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -34,6 +35,7 @@ #include #include +using kernel::CBlockFileInfo; using node::SnapshotMetadata; namespace { diff --git a/libbitcoinkernel-sys/bitcoin/src/test/fuzz/miniscript.cpp b/libbitcoinkernel-sys/bitcoin/src/test/fuzz/miniscript.cpp index aea31c6f..42195313 100644 --- a/libbitcoinkernel-sys/bitcoin/src/test/fuzz/miniscript.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/test/fuzz/miniscript.cpp @@ -1120,7 +1120,7 @@ void TestNode(const MsCtx script_ctx, const NodeRef& node, FuzzedDataProvider& p assert(mal_success); assert(stack_nonmal == stack_mal); // Compute witness size (excluding script push, control block, and witness count encoding). - const size_t wit_size = GetSerializeSize(stack_nonmal) - GetSizeOfCompactSize(stack_nonmal.size()); + const uint64_t wit_size{GetSerializeSize(stack_nonmal) - GetSizeOfCompactSize(stack_nonmal.size())}; assert(wit_size <= *node->GetWitnessSize()); // Test non-malleable satisfaction. diff --git a/libbitcoinkernel-sys/bitcoin/src/test/kernel/test_kernel.cpp b/libbitcoinkernel-sys/bitcoin/src/test/kernel/test_kernel.cpp index e1c9376d..75c9e466 100644 --- a/libbitcoinkernel-sys/bitcoin/src/test/kernel/test_kernel.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/test/kernel/test_kernel.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -395,6 +394,12 @@ BOOST_AUTO_TEST_CASE(btck_transaction_tests) auto tx2{Transaction{tx_data_2}}; CheckHandle(tx, tx2); + auto invalid_data = hex_string_to_byte_vec("012300"); + BOOST_CHECK_THROW(Transaction{invalid_data}, std::runtime_error); + auto empty_data = hex_string_to_byte_vec(""); + BOOST_CHECK_THROW(Transaction{empty_data}, std::runtime_error); + BOOST_CHECK_THROW(Transaction{std::span(static_cast(nullptr), 2)}, std::runtime_error); + BOOST_CHECK_EQUAL(tx.CountOutputs(), 2); BOOST_CHECK_EQUAL(tx.CountInputs(), 1); auto broken_tx_data{std::span{tx_data.begin(), tx_data.begin() + 10}}; @@ -469,6 +474,8 @@ BOOST_AUTO_TEST_CASE(btck_script_pubkey) ScriptPubkey script{script_data}; ScriptPubkey script2{script_data_2}; CheckHandle(script, script2); + + BOOST_CHECK_THROW(ScriptPubkey{std::span(static_cast(nullptr), 2)}, std::runtime_error); } BOOST_AUTO_TEST_CASE(btck_transaction_output) @@ -581,6 +588,11 @@ BOOST_AUTO_TEST_CASE(btck_block) CheckHandle(block, block_100); Block block_tx{hex_string_to_byte_vec(REGTEST_BLOCK_DATA[205])}; CheckRange(block_tx.Transactions(), block_tx.CountTransactions()); + auto invalid_data = hex_string_to_byte_vec("012300"); + BOOST_CHECK_THROW(Block{invalid_data}, std::runtime_error); + auto empty_data = hex_string_to_byte_vec(""); + BOOST_CHECK_THROW(Block{empty_data}, std::runtime_error); + BOOST_CHECK_THROW(Block{std::span(static_cast(nullptr), 2)}, std::runtime_error); } Context create_context(std::shared_ptr notifications, ChainType chain_type, std::shared_ptr validation_interface = nullptr) @@ -713,17 +725,6 @@ void chainman_mainnet_validation_test(TestDirectory& test_directory) auto context{create_context(notifications, ChainType::MAINNET, validation_interface)}; auto chainman{create_chainman(test_directory, false, false, false, false, context)}; - { - // Process an invalid block - auto raw_block = hex_string_to_byte_vec("012300"); - BOOST_CHECK_THROW(Block{raw_block}, std::runtime_error); - } - { - // Process an empty block - auto raw_block = hex_string_to_byte_vec(""); - BOOST_CHECK_THROW(Block{raw_block}, std::runtime_error); - } - // mainnet block 1 auto raw_block = hex_string_to_byte_vec("010000006fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000982051fd1e4ba744bbbe680e1fee14677ba1a3c3540bf7b1cdb606e857233e0e61bc6649ffff001d01e362990101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0104ffffffff0100f2052a0100000043410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac00000000"); Block block{raw_block}; diff --git a/libbitcoinkernel-sys/bitcoin/src/test/miner_tests.cpp b/libbitcoinkernel-sys/bitcoin/src/test/miner_tests.cpp index 94ade598..a3c576dd 100644 --- a/libbitcoinkernel-sys/bitcoin/src/test/miner_tests.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/test/miner_tests.cpp @@ -188,7 +188,7 @@ void MinerTestingSetup::TestPackageSelection(const CScript& scriptPubKey, const tx.vout[0].nValue = 5000000000LL - 1000 - 50000; // 0 fee Txid hashFreeTx = tx.GetHash(); AddToMempool(tx_mempool, entry.Fee(0).FromTx(tx)); - size_t freeTxSize = ::GetSerializeSize(TX_WITH_WITNESS(tx)); + uint64_t freeTxSize{::GetSerializeSize(TX_WITH_WITNESS(tx))}; // Calculate a fee on child transaction that will put the package just // below the block min tx fee (assuming 1 child tx of the same size). diff --git a/libbitcoinkernel-sys/bitcoin/src/test/miniscript_tests.cpp b/libbitcoinkernel-sys/bitcoin/src/test/miniscript_tests.cpp index 0a32727f..4d31968c 100644 --- a/libbitcoinkernel-sys/bitcoin/src/test/miniscript_tests.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/test/miniscript_tests.cpp @@ -372,7 +372,7 @@ void TestSatisfy(const KeyConverter& converter, const std::string& testcase, con CScriptWitness witness_nonmal; const bool nonmal_success = node->Satisfy(satisfier, witness_nonmal.stack, true) == miniscript::Availability::YES; // Compute witness size (excluding script push, control block, and witness count encoding). - const size_t wit_size = GetSerializeSize(witness_nonmal.stack) - GetSizeOfCompactSize(witness_nonmal.stack.size()); + const uint64_t wit_size{GetSerializeSize(witness_nonmal.stack) - GetSizeOfCompactSize(witness_nonmal.stack.size())}; SatisfactionToWitness(converter.MsContext(), witness_nonmal, script, builder); if (nonmal_success) { diff --git a/libbitcoinkernel-sys/bitcoin/src/test/net_tests.cpp b/libbitcoinkernel-sys/bitcoin/src/test/net_tests.cpp index 711b067a..a2ff9a10 100644 --- a/libbitcoinkernel-sys/bitcoin/src/test/net_tests.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/test/net_tests.cpp @@ -1301,7 +1301,7 @@ class V2TransportTester { // Construct contents consisting of 0x00 + 12-byte message type + payload. std::vector contents(1 + CMessageHeader::MESSAGE_TYPE_SIZE + payload.size()); - std::copy(mtype.begin(), mtype.end(), reinterpret_cast(contents.data() + 1)); + std::copy(mtype.begin(), mtype.end(), contents.begin() + 1); std::copy(payload.begin(), payload.end(), contents.begin() + 1 + CMessageHeader::MESSAGE_TYPE_SIZE); // Send a packet with that as contents. SendPacket(contents); diff --git a/libbitcoinkernel-sys/bitcoin/src/univalue/include/univalue_escapes.h b/libbitcoinkernel-sys/bitcoin/src/univalue/include/univalue_escapes.h index c486aeeb..7f4d89b0 100644 --- a/libbitcoinkernel-sys/bitcoin/src/univalue/include/univalue_escapes.h +++ b/libbitcoinkernel-sys/bitcoin/src/univalue/include/univalue_escapes.h @@ -6,261 +6,261 @@ #ifndef BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_ESCAPES_H #define BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_ESCAPES_H static const char *escapes[256] = { - "\\u0000", - "\\u0001", - "\\u0002", - "\\u0003", - "\\u0004", - "\\u0005", - "\\u0006", - "\\u0007", - "\\b", - "\\t", - "\\n", - "\\u000b", - "\\f", - "\\r", - "\\u000e", - "\\u000f", - "\\u0010", - "\\u0011", - "\\u0012", - "\\u0013", - "\\u0014", - "\\u0015", - "\\u0016", - "\\u0017", - "\\u0018", - "\\u0019", - "\\u001a", - "\\u001b", - "\\u001c", - "\\u001d", - "\\u001e", - "\\u001f", - nullptr, - nullptr, - "\\\"", - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - "\\\\", - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - "\\u007f", - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, + "\\u0000", + "\\u0001", + "\\u0002", + "\\u0003", + "\\u0004", + "\\u0005", + "\\u0006", + "\\u0007", + "\\b", + "\\t", + "\\n", + "\\u000b", + "\\f", + "\\r", + "\\u000e", + "\\u000f", + "\\u0010", + "\\u0011", + "\\u0012", + "\\u0013", + "\\u0014", + "\\u0015", + "\\u0016", + "\\u0017", + "\\u0018", + "\\u0019", + "\\u001a", + "\\u001b", + "\\u001c", + "\\u001d", + "\\u001e", + "\\u001f", + nullptr, + nullptr, + "\\\"", + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + "\\\\", + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + "\\u007f", + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, }; #endif // BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_ESCAPES_H diff --git a/libbitcoinkernel-sys/bitcoin/src/util/fs.h b/libbitcoinkernel-sys/bitcoin/src/util/fs.h index 8b5c0460..147904d0 100644 --- a/libbitcoinkernel-sys/bitcoin/src/util/fs.h +++ b/libbitcoinkernel-sys/bitcoin/src/util/fs.h @@ -185,29 +185,6 @@ static inline path PathFromString(const std::string& string) return std::filesystem::path(string); #endif } - -/** - * Create directory (and if necessary its parents), unless the leaf directory - * already exists or is a symlink to an existing directory. - * This is a temporary workaround for an issue in libstdc++ that has been fixed - * upstream [PR101510]. - * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101510 - */ -static inline bool create_directories(const std::filesystem::path& p) -{ - if (std::filesystem::is_symlink(p) && std::filesystem::is_directory(p)) { - return false; - } - return std::filesystem::create_directories(p); -} - -/** - * This variant is not used. Delete it to prevent it from accidentally working - * around the workaround. If it is needed, add a workaround in the same pattern - * as above. - */ -bool create_directories(const std::filesystem::path& p, std::error_code& ec) = delete; - } // namespace fs /** Bridge operations to C stdio */ diff --git a/libbitcoinkernel-sys/bitcoin/src/util/subprocess.h b/libbitcoinkernel-sys/bitcoin/src/util/subprocess.h index 9abca911..e90c1652 100644 --- a/libbitcoinkernel-sys/bitcoin/src/util/subprocess.h +++ b/libbitcoinkernel-sys/bitcoin/src/util/subprocess.h @@ -1146,7 +1146,7 @@ inline void Popen::execute_process() noexcept(false) NULL, // process security attributes NULL, // primary thread security attributes TRUE, // handles are inherited - creation_flags, // creation flags + creation_flags, // creation flags NULL, // use parent's environment NULL, // use parent's current directory &siStartInfo, // STARTUPINFOW pointer diff --git a/libbitcoinkernel-sys/bitcoin/src/wallet/spend.cpp b/libbitcoinkernel-sys/bitcoin/src/wallet/spend.cpp index 146fb49e..bd7bb01f 100644 --- a/libbitcoinkernel-sys/bitcoin/src/wallet/spend.cpp +++ b/libbitcoinkernel-sys/bitcoin/src/wallet/spend.cpp @@ -1034,7 +1034,7 @@ void DiscourageFeeSniping(CMutableTransaction& tx, FastRandomContext& rng_fast, } } -size_t GetSerializeSizeForRecipient(const CRecipient& recipient) +uint64_t GetSerializeSizeForRecipient(const CRecipient& recipient) { return ::GetSerializeSize(CTxOut(recipient.nAmount, GetScriptForDestination(recipient.dest))); }