Compare commits

...

36 Commits

Author SHA1 Message Date
fanquake
62c22dd679 Merge bitcoin/bitcoin#29794: [25.x] Finalize 25.2
e95c484f7d doc: Update release notes for 25.2 final (Ava Chow)
14b85b6276 doc: Update manpages for 25.2 final (Ava Chow)
1c13eae6e0 doc: Bump bips.md to 25.2 (Ava Chow)
03a568deb6 build: Bump to 25.2 final (Ava Chow)

Pull request description:

  Final changes for 25.2 release

ACKs for top commit:
  glozow:
    utACK e95c484f7d
  fanquake:
    ACK e95c484f7d

Tree-SHA512: 10a4d6d516e2bea9b4383eb174a6c7827be0359522d366746ead0a28f275e0cadf6e5e9a0e4cafe425438532a57ada0ecbfba300f02370eac411f101dd86dfe6
2024-04-03 10:30:24 +01:00
Ava Chow
e95c484f7d doc: Update release notes for 25.2 final 2024-04-02 18:31:03 -04:00
Ava Chow
14b85b6276 doc: Update manpages for 25.2 final 2024-04-02 18:30:12 -04:00
Ava Chow
1c13eae6e0 doc: Bump bips.md to 25.2 2024-04-02 18:25:08 -04:00
Ava Chow
03a568deb6 build: Bump to 25.2 final 2024-04-02 18:24:34 -04:00
fanquake
d5bad0d2d1 Merge bitcoin/bitcoin#29531: [25.x] backports
27cfda1bae doc: Update release notes for 25.2rc2 (Ava Chow)
daba5e2c5b doc: Update manpages for 25.2rc2 (Ava Chow)
8a0c980d6e build: Bump to 25.2rc2 (Ava Chow)
cf7d3a8cd0 p2p: Don't consider blocks mutated if they don't connect to known prev block (Greg Sanders)
3eaaafa225 [test] IsBlockMutated unit tests (dergoegge)
0667441a7b [validation] Cache merkle root and witness commitment checks (dergoegge)
de97ecf14f [test] Add regression test for #27608 (dergoegge)
8cc4b24c74 [net processing] Don't process mutated blocks (dergoegge)
098f07dc8d [validation] Merkle root malleation should be caught by IsBlockMutated (dergoegge)
8804c368f5 [validation] Introduce IsBlockMutated (dergoegge)
4f5baac6ca [validation] Isolate merkle root checks (dergoegge)
f93be0103f test: make sure keypool sizes do not change on `getrawchangeaddress`/`getnewaddress` failures (UdjinM6)
7c08ccf19b wallet: Avoid updating `ReserveDestination::nIndex` when `GetReservedDestination` fails (UdjinM6)

Pull request description:

  Backport:

  * #29510
  * #29412
  * #29524

ACKs for top commit:
  glozow:
    utACK 27cfda1bae

Tree-SHA512: 37feadd65d9ea55c0a92c9d2a6f74f87cafed3bc67f8deeaaafc5b7042f954e55ea34816612e1a49088f4f1906f104e00c7c3bec7affd1c1f48220b57a8769c5
2024-03-22 13:40:07 +00:00
Ava Chow
27cfda1bae doc: Update release notes for 25.2rc2 2024-03-21 13:43:34 -04:00
Ava Chow
daba5e2c5b doc: Update manpages for 25.2rc2 2024-03-08 12:22:30 -05:00
Ava Chow
8a0c980d6e build: Bump to 25.2rc2 2024-03-08 12:14:46 -05:00
Greg Sanders
cf7d3a8cd0 p2p: Don't consider blocks mutated if they don't connect to known prev block
Github-Pull: #29524
Rebased-From: a1fbde0ef7
2024-03-05 12:18:05 -05:00
dergoegge
3eaaafa225 [test] IsBlockMutated unit tests
Github-Pull: #29412
Rebased-From: d8087adc7e
2024-03-05 12:17:59 -05:00
dergoegge
0667441a7b [validation] Cache merkle root and witness commitment checks
Slight performance improvement by avoiding duplicate work.

Github-Pull: #29412
Rebased-From: 1ec6bbeb8d
2024-03-05 12:17:54 -05:00
dergoegge
de97ecf14f [test] Add regression test for #27608
Github-Pull: #29412
Rebased-From: 5bf4f5ba32
2024-03-05 12:17:49 -05:00
dergoegge
8cc4b24c74 [net processing] Don't process mutated blocks
We preemptively perform a block mutation check before further processing
a block message (similar to early sanity checks on other messsage
types). The main reasons for this change are as follows:

- `CBlock::GetHash()` is a foot-gun without a prior mutation check, as
  the hash returned only commits to the header but not to the actual
  transactions (`CBlock::vtx`) contained in the block.
- We have observed attacks that abused mutated blocks in the past, which
  could have been prevented by simply not processing mutated blocks
  (e.g. https://github.com/bitcoin/bitcoin/pull/27608).

Github-Pull: #29412
Rebased-From: 49257c0304
2024-03-05 12:17:45 -05:00
dergoegge
098f07dc8d [validation] Merkle root malleation should be caught by IsBlockMutated
Github-Pull: #29412
Rebased-From: 2d8495e080
2024-03-05 12:17:40 -05:00
dergoegge
8804c368f5 [validation] Introduce IsBlockMutated
Github-Pull: #29412
Rebased-From: 66abce1d98
2024-03-05 12:17:35 -05:00
dergoegge
4f5baac6ca [validation] Isolate merkle root checks
Github-Pull: #29412
Rebased-From: 95bddb930a
2024-03-05 12:17:28 -05:00
UdjinM6
f93be0103f test: make sure keypool sizes do not change on getrawchangeaddress/getnewaddress failures
Github-Pull: bitcoin/bitcoin#29510
Rebased-From: e073f1dfda
2024-03-01 17:12:36 -05:00
UdjinM6
7c08ccf19b wallet: Avoid updating ReserveDestination::nIndex when GetReservedDestination fails
Github-Pull: bitcoin/bitcoin#29510
Rebased-From: 367bb7a80c
2024-03-01 17:12:25 -05:00
fanquake
1ce5accc32 Merge bitcoin/bitcoin#29464: [25.2] Final backports and changes for 25.2rc1
9f13dc1ed3 doc: Update release notes for 25.2rc1 (Ava Chow)
a27662b16a doc: update manpages for 25.2rc1 (Ava Chow)
65c6171784 build: Bump to 25.2rc1 (Ava Chow)
cf0f43ee42 wallet: Fix use-after-free in WalletBatch::EraseRecords (MarcoFalke)
6acfc4324c Use only Span{} constructor for byte-like types where possible (MarcoFalke)
b40d10787b util: Allow std::byte and char Span serialization (MarcoFalke)

Pull request description:

  Backport:

  * #29176
  * #27927

  #29176 does not cleanly backport, and it also requires 27927 to work. Both are still fairly simple backports.

  Also does the rest of the version bump tasks for 25.2rc1.

ACKs for top commit:
  fanquake:
    ACK 9f13dc1ed3

Tree-SHA512: 9d9dbf415f8559410eba9a431b61a8fc94216898d2d1fd8398e1f7a22a04790faade810e65324c7a797456b33396c3a58f991e81319aaaa63d3ab441e5e20dbc
2024-02-26 11:54:29 +00:00
Ava Chow
9f13dc1ed3 doc: Update release notes for 25.2rc1 2024-02-21 18:52:41 -05:00
Ava Chow
a27662b16a doc: update manpages for 25.2rc1 2024-02-21 18:48:50 -05:00
Ava Chow
65c6171784 build: Bump to 25.2rc1 2024-02-21 18:39:11 -05:00
MarcoFalke
cf0f43ee42 wallet: Fix use-after-free in WalletBatch::EraseRecords
Github-Pull: bitcoin/bitcoin#29176
Rebased-From: faebf1df2a
2024-02-21 18:34:20 -05:00
MarcoFalke
6acfc4324c Use only Span{} constructor for byte-like types where possible
This removes bloat that is not needed.

Github-Pull: bitcoin/bitcoin#27927
Rebased-From: fa38d86235
2024-02-21 18:34:05 -05:00
MarcoFalke
b40d10787b util: Allow std::byte and char Span serialization
Github-Pull: bitcoin/bitcoin#27927
Rebased-From: fa257bc831
2024-02-21 18:33:43 -05:00
fanquake
8087626cbd Merge bitcoin/bitcoin#28768: [25.x] Backports
53bbda5114 doc: update release notes for 25.x (fanquake)
31e1e035be test: add regression test for the getrawtransaction segfault (Martin Zumsande)
041228d293 rpc: fix getrawtransaction segfault (Martin Zumsande)
b86285df1f gui: fix crash on selecting "Mask values" in transaction view (Sebastian Falbesoner)
c21024fd86 doc: add historical release notes for 25.1 (fanquake)

Pull request description:

  Collecting backports for the 25.x branch. Currently:
  * https://github.com/bitcoin-core/gui/pull/774
  * https://github.com/bitcoin/bitcoin/pull/29003

ACKs for top commit:
  stickies-v:
    ACK 53bbda5114

Tree-SHA512: 9b1ba17cce9de70d20329372ba71225dd930718a1f7db84a7be764dcfbba01c5e466255e7b95433ab6d7559ee8aaa04cc99ee5d1512d91fcc0a8015f1aa4150a
2024-01-16 11:23:36 +00:00
fanquake
53bbda5114 doc: update release notes for 25.x 2024-01-16 09:28:18 +00:00
Martin Zumsande
31e1e035be test: add regression test for the getrawtransaction segfault
This fails on master without the previous commit.

Github-Pull: #29003
Rebased-From: 9075a44646
2024-01-15 15:23:49 +00:00
Martin Zumsande
041228d293 rpc: fix getrawtransaction segfault
The crash would happen when querying a mempool transaction with verbosity=2, while pruning.

Github-Pull: #29003
Rebased-From: 494a926d05
2024-01-15 15:23:49 +00:00
Sebastian Falbesoner
b86285df1f gui: fix crash on selecting "Mask values" in transaction view
This commits fixes a crash bug that can be caused with the following steps:
- change to the "Transactions" view
- right-click on an arbitrary transaction -> "Show transaction details"
- close the transaction detail window again
- select "Settings" -> "Mask values"

The problem is that the list of opened dialogs, tracked in the member
variable `m_opened_dialogs`, is only ever appended with newly opened
transaction detail dialog pointers, but never removed. This leads to
dangling pointers in the list, and if the "Mask values" menu item is
selected, a crash is caused in the course of trying to close the opened
transaction detail dialogs (see `closeOpenedDialogs()` method). Fix this
by removing the pointer from the list if the corresponding widget is
destroyed.

Github-Pull: https://github.com/bitcoin-core/gui/pull/774
Rebased-From: e26e665f9f
2023-12-11 15:51:59 +00:00
fanquake
c21024fd86 doc: add historical release notes for 25.1 2023-12-11 15:51:59 +00:00
fanquake
7da4ae1f78 Merge bitcoin/bitcoin#28655: [25.1] Final Changes
a13670090d doc: update release notes for 25.1 (fanquake)
e8d5c35e80 doc: update manual pages for 25.1 (fanquake)
9e00b73ee7 build: bump version to 25.1 final (fanquake)

Pull request description:

  Final changes for `v25.1`.
  PR for bitcoincore.org is here: https://github.com/bitcoin-core/bitcoincore.org/pull/991.
  No additional changes have been backported since rc1 (tagged 14 days ago),
  and no bugs or issues have been reported (test bins have been available for 9 days).

ACKs for top commit:
  hebasto:
    ACK a13670090d.
  TheCharlatan:
    lgtm ACK a13670090d

Tree-SHA512: 037f937dd4d2a9de15ff15a80f35b6047b61ffc3d9a33e7d4a4fcbce6302569bbc516c6da5849211b34ebbe914c4edcdd182e2d1d43897d0dcd32834ce6f2574
2023-10-16 16:44:20 +01:00
fanquake
a13670090d doc: update release notes for 25.1 2023-10-16 11:35:40 +02:00
fanquake
e8d5c35e80 doc: update manual pages for 25.1 2023-10-16 11:34:25 +02:00
fanquake
9e00b73ee7 build: bump version to 25.1 final 2023-10-16 11:30:08 +02:00
31 changed files with 661 additions and 151 deletions

View File

@@ -1,8 +1,8 @@
AC_PREREQ([2.69])
define(_CLIENT_VERSION_MAJOR, 25)
define(_CLIENT_VERSION_MINOR, 1)
define(_CLIENT_VERSION_MINOR, 2)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_RC, 1)
define(_CLIENT_VERSION_RC, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2023)
define(_COPYRIGHT_HOLDERS,[The %s developers])

View File

@@ -1,4 +1,4 @@
BIPs that are implemented by Bitcoin Core (up-to-date up to **v25.0**):
BIPs that are implemented by Bitcoin Core (up-to-date up to **v25.2**):
* [`BIP 9`](https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki): The changes allowing multiple soft-forks to be deployed in parallel have been implemented since **v0.12.1** ([PR #7575](https://github.com/bitcoin/bitcoin/pull/7575))
* [`BIP 11`](https://github.com/bitcoin/bips/blob/master/bip-0011.mediawiki): Multisig outputs are standard since **v0.6.0** ([PR #669](https://github.com/bitcoin/bitcoin/pull/669)).

View File

@@ -1,7 +1,7 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH BITCOIN-CLI "1" "October 2023" "bitcoin-cli v25.1.0rc1" "User Commands"
.TH BITCOIN-CLI "1" "April 2024" "bitcoin-cli v25.2.0" "User Commands"
.SH NAME
bitcoin-cli \- manual page for bitcoin-cli v25.1.0rc1
bitcoin-cli \- manual page for bitcoin-cli v25.2.0
.SH SYNOPSIS
.B bitcoin-cli
[\fI\,options\/\fR] \fI\,<command> \/\fR[\fI\,params\/\fR] \fI\,Send command to Bitcoin Core\/\fR
@@ -15,7 +15,7 @@ bitcoin-cli \- manual page for bitcoin-cli v25.1.0rc1
.B bitcoin-cli
[\fI\,options\/\fR] \fI\,help <command> Get help for a command\/\fR
.SH DESCRIPTION
Bitcoin Core RPC client version v25.1.0rc1
Bitcoin Core RPC client version v25.2.0
.SH OPTIONS
.HP
\-?

View File

@@ -1,12 +1,12 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH BITCOIN-QT "1" "October 2023" "bitcoin-qt v25.1.0rc1" "User Commands"
.TH BITCOIN-QT "1" "April 2024" "bitcoin-qt v25.2.0" "User Commands"
.SH NAME
bitcoin-qt \- manual page for bitcoin-qt v25.1.0rc1
bitcoin-qt \- manual page for bitcoin-qt v25.2.0
.SH SYNOPSIS
.B bitcoin-qt
[\fI\,command-line options\/\fR]
.SH DESCRIPTION
Bitcoin Core version v25.1.0rc1
Bitcoin Core version v25.2.0
.SH OPTIONS
.HP
\-?
@@ -116,7 +116,7 @@ Do not keep transactions in the mempool longer than <n> hours (default:
.HP
\fB\-par=\fR<n>
.IP
Set the number of script verification threads (\fB\-10\fR to 15, 0 = auto, <0 =
Set the number of script verification threads (\fB\-64\fR to 15, 0 = auto, <0 =
leave that many cores free, default: 0)
.HP
\fB\-persistmempool\fR

View File

@@ -1,7 +1,7 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH BITCOIN-TX "1" "October 2023" "bitcoin-tx v25.1.0rc1" "User Commands"
.TH BITCOIN-TX "1" "April 2024" "bitcoin-tx v25.2.0" "User Commands"
.SH NAME
bitcoin-tx \- manual page for bitcoin-tx v25.1.0rc1
bitcoin-tx \- manual page for bitcoin-tx v25.2.0
.SH SYNOPSIS
.B bitcoin-tx
[\fI\,options\/\fR] \fI\,<hex-tx> \/\fR[\fI\,commands\/\fR] \fI\,Update hex-encoded bitcoin transaction\/\fR
@@ -9,7 +9,7 @@ bitcoin-tx \- manual page for bitcoin-tx v25.1.0rc1
.B bitcoin-tx
[\fI\,options\/\fR] \fI\,-create \/\fR[\fI\,commands\/\fR] \fI\,Create hex-encoded bitcoin transaction\/\fR
.SH DESCRIPTION
Bitcoin Core bitcoin\-tx utility version v25.1.0rc1
Bitcoin Core bitcoin\-tx utility version v25.2.0
.SH OPTIONS
.HP
\-?

View File

@@ -1,12 +1,12 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH BITCOIN-UTIL "1" "October 2023" "bitcoin-util v25.1.0rc1" "User Commands"
.TH BITCOIN-UTIL "1" "April 2024" "bitcoin-util v25.2.0" "User Commands"
.SH NAME
bitcoin-util \- manual page for bitcoin-util v25.1.0rc1
bitcoin-util \- manual page for bitcoin-util v25.2.0
.SH SYNOPSIS
.B bitcoin-util
[\fI\,options\/\fR] [\fI\,commands\/\fR] \fI\,Do stuff\/\fR
.SH DESCRIPTION
Bitcoin Core bitcoin\-util utility version v25.1.0rc1
Bitcoin Core bitcoin\-util utility version v25.2.0
.SH OPTIONS
.HP
\-?

View File

@@ -1,9 +1,9 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH BITCOIN-WALLET "1" "October 2023" "bitcoin-wallet v25.1.0rc1" "User Commands"
.TH BITCOIN-WALLET "1" "April 2024" "bitcoin-wallet v25.2.0" "User Commands"
.SH NAME
bitcoin-wallet \- manual page for bitcoin-wallet v25.1.0rc1
bitcoin-wallet \- manual page for bitcoin-wallet v25.2.0
.SH DESCRIPTION
Bitcoin Core bitcoin\-wallet version v25.1.0rc1
Bitcoin Core bitcoin\-wallet version v25.2.0
.PP
bitcoin\-wallet is an offline tool for creating and interacting with Bitcoin Core wallet files.
By default bitcoin\-wallet will act on wallets in the default mainnet wallet directory in the datadir.

View File

@@ -1,12 +1,12 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH BITCOIND "1" "October 2023" "bitcoind v25.1.0rc1" "User Commands"
.TH BITCOIND "1" "April 2024" "bitcoind v25.2.0" "User Commands"
.SH NAME
bitcoind \- manual page for bitcoind v25.1.0rc1
bitcoind \- manual page for bitcoind v25.2.0
.SH SYNOPSIS
.B bitcoind
[\fI\,options\/\fR] \fI\,Start Bitcoin Core\/\fR
.SH DESCRIPTION
Bitcoin Core version v25.1.0rc1
Bitcoin Core version v25.2.0
.SH OPTIONS
.HP
\-?
@@ -116,7 +116,7 @@ Do not keep transactions in the mempool longer than <n> hours (default:
.HP
\fB\-par=\fR<n>
.IP
Set the number of script verification threads (\fB\-10\fR to 15, 0 = auto, <0 =
Set the number of script verification threads (\fB\-64\fR to 15, 0 = auto, <0 =
leave that many cores free, default: 0)
.HP
\fB\-persistmempool\fR

View File

@@ -1,11 +1,11 @@
25.1rc1 Release Notes
25.2 Release Notes
==================
Bitcoin Core version 25.1rc1 is now available from:
Bitcoin Core version 25.2 is now available from:
<https://bitcoincore.org/bin/bitcoin-core-25.1/test.rc1>
<https://bitcoincore.org/bin/bitcoin-core-25.2>
This release includes new features, various bug fixes and performance
This release includes various bug fixes and performance
improvements, as well as updated translations.
Please report bugs using the issue tracker at GitHub:
@@ -40,69 +40,35 @@ unsupported systems.
Notable changes
===============
### P2P
### Gui
- #27626 Parallel compact block downloads, take 3
- #27743 p2p: Unconditionally return when compact block status == READ_STATUS_FAILED
### Fees
- #27622 Fee estimation: avoid serving stale fee estimate
- gui#774 Fix crash on selecting "Mask values" in transaction view
### RPC
- #27727 rpc: Fix invalid bech32 address handling
### Rest
- #27853 rest: fix crash error when calling /deploymentinfo
- #28551 http: bugfix: allow server shutdown in case of remote client disconnection
- #29003 rpc: fix getrawtransaction segfault
### Wallet
- #28038 wallet: address book migration bug fixes
- #28067 descriptors: do not return top-level only funcs as sub descriptors
- #28125 wallet: bugfix, disallow migration of invalid scripts
- #28542 wallet: Check for uninitialized last processed and conflicting heights in MarkConflicted
- #29176 wallet: Fix use-after-free in WalletBatch::EraseRecords
- #29510 wallet: `getrawchangeaddress` and `getnewaddress` failures should not affect keypools for descriptor wallets
### Build
### P2P and network changes
- #27724 build: disable boost multi index safe mode in debug mode
- #28097 depends: xcb-proto 1.15.2
- #28543 build, macos: Fix qt package build with new Xcode 15 linker
- #28571 depends: fix unusable memory_resource in macos qt build
### Gui
- gui#751 macOS, do not process actions during shutdown
### Miscellaneous
- #28452 Do not use std::vector = {} to release memory
### CI
- #27777 ci: Prune dangling images on RESTART_CI_DOCKER_BEFORE_RUN
- #27834 ci: Nuke Android APK task, Use credits for tsan
- #27844 ci: Use podman stop over podman kill
- #27886 ci: Switch to amd64 container in "ARM" task
- #29412 p2p: Don't process mutated blocks
- #29524 p2p: Don't consider blocks mutated if they don't connect to known prev block
Credits
=======
Thanks to everyone who directly contributed to this release:
- Abubakar Sadiq Ismail
- Andrew Chow
- Bruno Garcia
- Gregory Sanders
- Hennadii Stepanov
- MacroFake
- Matias Furszyfer
- Michael Ford
- Pieter Wuille
- stickies-v
- Will Clark
- Martin Zumsande
- Sebastian Falbesoner
- MarcoFalke
- UdjinM6
- dergoegge
- Greg Sanders
As well as to everyone that helped with translations on
[Transifex](https://www.transifex.com/bitcoin/bitcoin/).

View File

@@ -0,0 +1,108 @@
25.1 Release Notes
==================
Bitcoin Core version 25.1 is now available from:
<https://bitcoincore.org/bin/bitcoin-core-25.1/>
This release includes various bug fixes and performance
improvements, as well as updated translations.
Please report bugs using the issue tracker at GitHub:
<https://github.com/bitcoin/bitcoin/issues>
To receive security and update notifications, please subscribe to:
<https://bitcoincore.org/en/list/announcements/join/>
How to Upgrade
==============
If you are running an older version, shut it down. Wait until it has completely
shut down (which might take a few minutes in some cases), then run the
installer (on Windows) or just copy over `/Applications/Bitcoin-Qt` (on macOS)
or `bitcoind`/`bitcoin-qt` (on Linux).
Upgrading directly from a version of Bitcoin Core that has reached its EOL is
possible, but it might take some time if the data directory needs to be migrated. Old
wallet versions of Bitcoin Core are generally supported.
Compatibility
==============
Bitcoin Core is supported and extensively tested on operating systems
using the Linux kernel, macOS 10.15+, and Windows 7 and newer. Bitcoin
Core should also work on most other Unix-like systems but is not as
frequently tested on them. It is not recommended to use Bitcoin Core on
unsupported systems.
Notable changes
===============
### P2P
- #27626 Parallel compact block downloads, take 3
- #27743 p2p: Unconditionally return when compact block status == READ_STATUS_FAILED
### Fees
- #27622 Fee estimation: avoid serving stale fee estimate
### RPC
- #27727 rpc: Fix invalid bech32 address handling
### Rest
- #27853 rest: fix crash error when calling /deploymentinfo
- #28551 http: bugfix: allow server shutdown in case of remote client disconnection
### Wallet
- #28038 wallet: address book migration bug fixes
- #28067 descriptors: do not return top-level only funcs as sub descriptors
- #28125 wallet: bugfix, disallow migration of invalid scripts
- #28542 wallet: Check for uninitialized last processed and conflicting heights in MarkConflicted
### Build
- #27724 build: disable boost multi index safe mode in debug mode
- #28097 depends: xcb-proto 1.15.2
- #28543 build, macos: Fix qt package build with new Xcode 15 linker
- #28571 depends: fix unusable memory_resource in macos qt build
### Gui
- gui#751 macOS, do not process actions during shutdown
### Miscellaneous
- #28452 Do not use std::vector = {} to release memory
### CI
- #27777 ci: Prune dangling images on RESTART_CI_DOCKER_BEFORE_RUN
- #27834 ci: Nuke Android APK task, Use credits for tsan
- #27844 ci: Use podman stop over podman kill
- #27886 ci: Switch to amd64 container in "ARM" task
Credits
=======
Thanks to everyone who directly contributed to this release:
- Abubakar Sadiq Ismail
- Andrew Chow
- Bruno Garcia
- Gregory Sanders
- Hennadii Stepanov
- MacroFake
- Matias Furszyfer
- Michael Ford
- Pieter Wuille
- stickies-v
- Will Clark
As well as to everyone that helped with translations on
[Transifex](https://www.transifex.com/bitcoin/bitcoin/).

View File

@@ -33,7 +33,7 @@ static void LoadExternalBlockFile(benchmark::Bench& bench)
ss << static_cast<uint32_t>(benchmark::data::block413567.size());
// We can't use the streaming serialization (ss << benchmark::data::block413567)
// because that first writes a compact size.
ss.write(MakeByteSpan(benchmark::data::block413567));
ss << Span{benchmark::data::block413567};
// Create the test file.
{

View File

@@ -2939,13 +2939,13 @@ void CaptureMessageToFile(const CAddress& addr,
AutoFile f{fsbridge::fopen(path, "ab")};
ser_writedata64(f, now.count());
f.write(MakeByteSpan(msg_type));
f << Span{msg_type};
for (auto i = msg_type.length(); i < CMessageHeader::COMMAND_SIZE; ++i) {
f << uint8_t{'\0'};
}
uint32_t size = data.size();
ser_writedata32(f, size);
f.write(AsBytes(data));
f << data;
}
std::function<void(const CAddress& addr,

View File

@@ -4629,6 +4629,17 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
LogPrint(BCLog::NET, "received block %s peer=%d\n", pblock->GetHash().ToString(), pfrom.GetId());
const CBlockIndex* prev_block{WITH_LOCK(m_chainman.GetMutex(), return m_chainman.m_blockman.LookupBlockIndex(pblock->hashPrevBlock))};
// Check for possible mutation if it connects to something we know so we can check for DEPLOYMENT_SEGWIT being active
if (prev_block && IsBlockMutated(/*block=*/*pblock,
/*check_witness_root=*/DeploymentActiveAfter(prev_block, m_chainman, Consensus::DEPLOYMENT_SEGWIT))) {
LogPrint(BCLog::NET, "Received mutated block from peer=%d\n", peer->m_id);
Misbehaving(*peer, 100, "mutated block");
WITH_LOCK(cs_main, RemoveBlockRequest(pblock->GetHash(), peer->m_id));
return;
}
bool forceProcessing = false;
const uint256 hash(pblock->GetHash());
bool min_pow_checked = false;
@@ -4644,7 +4655,6 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
mapBlockSource.emplace(hash, std::make_pair(pfrom.GetId(), true));
// Check work on this block against our anti-dos thresholds.
const CBlockIndex* prev_block = m_chainman.m_blockman.LookupBlockIndex(pblock->hashPrevBlock);
if (prev_block && prev_block->nChainWork + CalculateHeadersWork({pblock->GetBlockHeader()}) >= GetAntiDoSWorkThreshold()) {
min_pow_checked = true;
}

View File

@@ -71,8 +71,10 @@ public:
// network and disk
std::vector<CTransactionRef> vtx;
// memory only
mutable bool fChecked;
// Memory-only flags for caching expensive checks
mutable bool fChecked; // CheckBlock()
mutable bool m_checked_witness_commitment{false}; // CheckWitnessCommitment()
mutable bool m_checked_merkle_root{false}; // CheckMerkleRoot()
CBlock()
{
@@ -96,6 +98,8 @@ public:
CBlockHeader::SetNull();
vtx.clear();
fChecked = false;
m_checked_witness_commitment = false;
m_checked_merkle_root = false;
}
CBlockHeader GetBlockHeader() const

View File

@@ -142,14 +142,14 @@ public:
{
unsigned int len = size();
::WriteCompactSize(s, len);
s.write(AsBytes(Span{vch, len}));
s << Span{vch, len};
}
template <typename Stream>
void Unserialize(Stream& s)
{
const unsigned int len(::ReadCompactSize(s));
if (len <= SIZE) {
s.read(AsWritableBytes(Span{vch, len}));
s >> Span{vch, len};
if (len != size()) {
Invalidate();
}

View File

@@ -532,6 +532,9 @@ void TransactionView::showDetails()
TransactionDescDialog *dlg = new TransactionDescDialog(selection.at(0));
dlg->setAttribute(Qt::WA_DeleteOnClose);
m_opened_dialogs.append(dlg);
connect(dlg, &QObject::destroyed, [this, dlg] {
m_opened_dialogs.removeOne(dlg);
});
dlg->show();
}
}

View File

@@ -310,7 +310,7 @@ static RPCHelpMan getrawtransaction()
LOCK(cs_main);
blockindex = chainman.m_blockman.LookupBlockIndex(hash_block);
}
if (verbosity == 1) {
if (verbosity == 1 || !blockindex) {
TxToJSON(*tx, hash_block, result, chainman.ActiveChainstate());
return result;
}
@@ -319,8 +319,7 @@ static RPCHelpMan getrawtransaction()
CBlock block;
const bool is_block_pruned{WITH_LOCK(cs_main, return chainman.m_blockman.IsBlockPruned(blockindex))};
if (tx->IsCoinBase() ||
!blockindex || is_block_pruned ||
if (tx->IsCoinBase() || is_block_pruned ||
!(UndoReadFromDisk(blockUndo, blockindex) && ReadBlockFromDisk(block, blockindex, Params().GetConsensus()))) {
TxToJSON(*tx, hash_block, result, chainman.ActiveChainstate());
return result;

View File

@@ -188,6 +188,7 @@ template<typename X> const X& ReadWriteAsHelper(const X& x) { return x; }
} \
FORMATTER_METHODS(cls, obj)
// clang-format off
#ifndef CHAR_EQUALS_INT8
template <typename Stream> void Serialize(Stream&, char) = delete; // char serialization forbidden. Use uint8_t or int8_t
#endif
@@ -201,8 +202,7 @@ template<typename Stream> inline void Serialize(Stream& s, int64_t a ) { ser_wri
template<typename Stream> inline void Serialize(Stream& s, uint64_t a) { ser_writedata64(s, a); }
template<typename Stream, int N> inline void Serialize(Stream& s, const char (&a)[N]) { s.write(MakeByteSpan(a)); }
template<typename Stream, int N> inline void Serialize(Stream& s, const unsigned char (&a)[N]) { s.write(MakeByteSpan(a)); }
template<typename Stream> inline void Serialize(Stream& s, const Span<const unsigned char>& span) { s.write(AsBytes(span)); }
template<typename Stream> inline void Serialize(Stream& s, const Span<unsigned char>& span) { s.write(AsBytes(span)); }
template <typename Stream, typename B> void Serialize(Stream& s, Span<B> span) { (void)/* force byte-type */UCharCast(span.data()); s.write(AsBytes(span)); }
#ifndef CHAR_EQUALS_INT8
template <typename Stream> void Unserialize(Stream&, char) = delete; // char serialization forbidden. Use uint8_t or int8_t
@@ -217,10 +217,11 @@ template<typename Stream> inline void Unserialize(Stream& s, int64_t& a ) { a =
template<typename Stream> inline void Unserialize(Stream& s, uint64_t& a) { a = ser_readdata64(s); }
template<typename Stream, int N> inline void Unserialize(Stream& s, char (&a)[N]) { s.read(MakeWritableByteSpan(a)); }
template<typename Stream, int N> inline void Unserialize(Stream& s, unsigned char (&a)[N]) { s.read(MakeWritableByteSpan(a)); }
template<typename Stream> inline void Unserialize(Stream& s, Span<unsigned char>& span) { s.read(AsWritableBytes(span)); }
template <typename Stream, typename B> void Unserialize(Stream& s, Span<B> span) { (void)/* force byte-type */UCharCast(span.data()); s.read(AsWritableBytes(span)); }
template <typename Stream> inline void Serialize(Stream& s, bool a) { uint8_t f = a; ser_writedata8(s, f); }
template <typename Stream> inline void Unserialize(Stream& s, bool& a) { uint8_t f = ser_readdata8(s); a = f; }
// clang-format on
/**

View File

@@ -76,7 +76,7 @@ FUZZ_TARGET_INIT(p2p_transport_serialization, initialize_p2p_transport_serializa
assert(msg.m_time == m_time);
std::vector<unsigned char> header;
auto msg2 = CNetMsgMaker{msg.m_recv.GetVersion()}.Make(msg.m_type, MakeUCharSpan(msg.m_recv));
auto msg2 = CNetMsgMaker{msg.m_recv.GetVersion()}.Make(msg.m_type, Span{msg.m_recv});
serializer.prepareForTransport(msg2, header);
}
}

View File

@@ -186,32 +186,32 @@ BOOST_AUTO_TEST_CASE(noncanonical)
std::vector<char>::size_type n;
// zero encoded with three bytes:
ss.write(MakeByteSpan("\xfd\x00\x00").first(3));
ss << Span{"\xfd\x00\x00"}.first(3);
BOOST_CHECK_EXCEPTION(ReadCompactSize(ss), std::ios_base::failure, isCanonicalException);
// 0xfc encoded with three bytes:
ss.write(MakeByteSpan("\xfd\xfc\x00").first(3));
ss << Span{"\xfd\xfc\x00"}.first(3);
BOOST_CHECK_EXCEPTION(ReadCompactSize(ss), std::ios_base::failure, isCanonicalException);
// 0xfd encoded with three bytes is OK:
ss.write(MakeByteSpan("\xfd\xfd\x00").first(3));
ss << Span{"\xfd\xfd\x00"}.first(3);
n = ReadCompactSize(ss);
BOOST_CHECK(n == 0xfd);
// zero encoded with five bytes:
ss.write(MakeByteSpan("\xfe\x00\x00\x00\x00").first(5));
ss << Span{"\xfe\x00\x00\x00\x00"}.first(5);
BOOST_CHECK_EXCEPTION(ReadCompactSize(ss), std::ios_base::failure, isCanonicalException);
// 0xffff encoded with five bytes:
ss.write(MakeByteSpan("\xfe\xff\xff\x00\x00").first(5));
ss << Span{"\xfe\xff\xff\x00\x00"}.first(5);
BOOST_CHECK_EXCEPTION(ReadCompactSize(ss), std::ios_base::failure, isCanonicalException);
// zero encoded with nine bytes:
ss.write(MakeByteSpan("\xff\x00\x00\x00\x00\x00\x00\x00\x00").first(9));
ss << Span{"\xff\x00\x00\x00\x00\x00\x00\x00\x00"}.first(9);
BOOST_CHECK_EXCEPTION(ReadCompactSize(ss), std::ios_base::failure, isCanonicalException);
// 0x01ffffff encoded with nine bytes:
ss.write(MakeByteSpan("\xff\xff\xff\xff\x01\x00\x00\x00\x00").first(9));
ss << Span{"\xff\xff\xff\xff\x01\x00\x00\x00\x00"}.first(9);
BOOST_CHECK_EXCEPTION(ReadCompactSize(ss), std::ios_base::failure, isCanonicalException);
}
@@ -241,6 +241,15 @@ BOOST_AUTO_TEST_CASE(class_methods)
ss2 << intval << boolval << stringval << charstrval << txval;
ss2 >> methodtest3;
BOOST_CHECK(methodtest3 == methodtest4);
{
DataStream ds;
const std::string in{"ab"};
ds << Span{in};
std::array<std::byte, 2> out;
ds >> Span{out};
BOOST_CHECK_EQUAL(out.at(0), std::byte{'a'});
BOOST_CHECK_EQUAL(out.at(1), std::byte{'b'});
}
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -4,11 +4,16 @@
#include <chainparams.h>
#include <consensus/amount.h>
#include <consensus/merkle.h>
#include <core_io.h>
#include <hash.h>
#include <net.h>
#include <signet.h>
#include <uint256.h>
#include <validation.h>
#include <string>
#include <test/util/setup_common.h>
#include <boost/test/unit_test.hpp>
@@ -144,4 +149,215 @@ BOOST_AUTO_TEST_CASE(test_assumeutxo)
BOOST_CHECK_EQUAL(out210.nChainTx, 200U);
}
BOOST_AUTO_TEST_CASE(block_malleation)
{
// Test utilities that calls `IsBlockMutated` and then clears the validity
// cache flags on `CBlock`.
auto is_mutated = [](CBlock& block, bool check_witness_root) {
bool mutated{IsBlockMutated(block, check_witness_root)};
block.fChecked = false;
block.m_checked_witness_commitment = false;
block.m_checked_merkle_root = false;
return mutated;
};
auto is_not_mutated = [&is_mutated](CBlock& block, bool check_witness_root) {
return !is_mutated(block, check_witness_root);
};
// Test utilities to create coinbase transactions and insert witness
// commitments.
//
// Note: this will not include the witness stack by default to avoid
// triggering the "no witnesses allowed for blocks that don't commit to
// witnesses" rule when testing other malleation vectors.
auto create_coinbase_tx = [](bool include_witness = false) {
CMutableTransaction coinbase;
coinbase.vin.resize(1);
if (include_witness) {
coinbase.vin[0].scriptWitness.stack.resize(1);
coinbase.vin[0].scriptWitness.stack[0] = std::vector<unsigned char>(32, 0x00);
}
coinbase.vout.resize(1);
coinbase.vout[0].scriptPubKey.resize(MINIMUM_WITNESS_COMMITMENT);
coinbase.vout[0].scriptPubKey[0] = OP_RETURN;
coinbase.vout[0].scriptPubKey[1] = 0x24;
coinbase.vout[0].scriptPubKey[2] = 0xaa;
coinbase.vout[0].scriptPubKey[3] = 0x21;
coinbase.vout[0].scriptPubKey[4] = 0xa9;
coinbase.vout[0].scriptPubKey[5] = 0xed;
auto tx = MakeTransactionRef(coinbase);
assert(tx->IsCoinBase());
return tx;
};
auto insert_witness_commitment = [](CBlock& block, uint256 commitment) {
assert(!block.vtx.empty() && block.vtx[0]->IsCoinBase() && !block.vtx[0]->vout.empty());
CMutableTransaction mtx{*block.vtx[0]};
CHash256().Write(commitment).Write(std::vector<unsigned char>(32, 0x00)).Finalize(commitment);
memcpy(&mtx.vout[0].scriptPubKey[6], commitment.begin(), 32);
block.vtx[0] = MakeTransactionRef(mtx);
};
{
CBlock block;
// Empty block is expected to have merkle root of 0x0.
BOOST_CHECK(block.vtx.empty());
block.hashMerkleRoot = uint256{1};
BOOST_CHECK(is_mutated(block, /*check_witness_root=*/false));
block.hashMerkleRoot = uint256{};
BOOST_CHECK(is_not_mutated(block, /*check_witness_root=*/false));
// Block with a single coinbase tx is mutated if the merkle root is not
// equal to the coinbase tx's hash.
block.vtx.push_back(create_coinbase_tx());
BOOST_CHECK(block.vtx[0]->GetHash() != block.hashMerkleRoot);
BOOST_CHECK(is_mutated(block, /*check_witness_root=*/false));
block.hashMerkleRoot = block.vtx[0]->GetHash();
BOOST_CHECK(is_not_mutated(block, /*check_witness_root=*/false));
// Block with two transactions is mutated if the merkle root does not
// match the double sha256 of the concatenation of the two transaction
// hashes.
block.vtx.push_back(MakeTransactionRef(CMutableTransaction{}));
BOOST_CHECK(is_mutated(block, /*check_witness_root=*/false));
HashWriter hasher;
hasher.write(Span(reinterpret_cast<const std::byte*>(block.vtx[0]->GetHash().data()), 32));
hasher.write(Span(reinterpret_cast<const std::byte*>(block.vtx[1]->GetHash().data()), 32));
block.hashMerkleRoot = hasher.GetHash();
BOOST_CHECK(is_not_mutated(block, /*check_witness_root=*/false));
// Block with two transactions is mutated if any node is duplicate.
{
block.vtx[1] = block.vtx[0];
BOOST_CHECK(is_mutated(block, /*check_witness_root=*/false));
HashWriter hasher;
hasher.write(Span(reinterpret_cast<const std::byte*>(block.vtx[0]->GetHash().data()), 32));
hasher.write(Span(reinterpret_cast<const std::byte*>(block.vtx[1]->GetHash().data()), 32));
block.hashMerkleRoot = hasher.GetHash();
BOOST_CHECK(is_mutated(block, /*check_witness_root=*/false));
}
// Blocks with 64-byte coinbase transactions are not considered mutated
block.vtx.clear();
{
CMutableTransaction mtx;
mtx.vin.resize(1);
mtx.vout.resize(1);
mtx.vout[0].scriptPubKey.resize(4);
block.vtx.push_back(MakeTransactionRef(mtx));
block.hashMerkleRoot = block.vtx.back()->GetHash();
assert(block.vtx.back()->IsCoinBase());
assert(GetSerializeSize(block.vtx.back(), PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) == 64);
}
BOOST_CHECK(is_not_mutated(block, /*check_witness_root=*/false));
}
{
// Test merkle root malleation
// Pseudo code to mine transactions tx{1,2,3}:
//
// ```
// loop {
// tx1 = random_tx()
// tx2 = random_tx()
// tx3 = deserialize_tx(txid(tx1) || txid(tx2));
// if serialized_size_without_witness(tx3) == 64 {
// print(hex(tx3))
// break
// }
// }
// ```
//
// The `random_tx` function used to mine the txs below simply created
// empty transactions with a random version field.
CMutableTransaction tx1;
BOOST_CHECK(DecodeHexTx(tx1, "ff204bd0000000000000", /*try_no_witness=*/true, /*try_witness=*/false));
CMutableTransaction tx2;
BOOST_CHECK(DecodeHexTx(tx2, "8ae53c92000000000000", /*try_no_witness=*/true, /*try_witness=*/false));
CMutableTransaction tx3;
BOOST_CHECK(DecodeHexTx(tx3, "cdaf22d00002c6a7f848f8ae4d30054e61dcf3303d6fe01d282163341f06feecc10032b3160fcab87bdfe3ecfb769206ef2d991b92f8a268e423a6ef4d485f06", /*try_no_witness=*/true, /*try_witness=*/false));
{
// Verify that double_sha256(txid1||txid2) == txid3
HashWriter hasher;
hasher.write(Span(reinterpret_cast<const std::byte*>(tx1.GetHash().data()), 32));
hasher.write(Span(reinterpret_cast<const std::byte*>(tx2.GetHash().data()), 32));
assert(hasher.GetHash() == tx3.GetHash());
// Verify that tx3 is 64 bytes in size (without witness).
assert(GetSerializeSize(tx3, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) == 64);
}
CBlock block;
block.vtx.push_back(MakeTransactionRef(tx1));
block.vtx.push_back(MakeTransactionRef(tx2));
uint256 merkle_root = block.hashMerkleRoot = BlockMerkleRoot(block);
BOOST_CHECK(is_not_mutated(block, /*check_witness_root=*/false));
// Mutate the block by replacing the two transactions with one 64-byte
// transaction that serializes into the concatenation of the txids of
// the transactions in the unmutated block.
block.vtx.clear();
block.vtx.push_back(MakeTransactionRef(tx3));
BOOST_CHECK(!block.vtx.back()->IsCoinBase());
BOOST_CHECK(BlockMerkleRoot(block) == merkle_root);
BOOST_CHECK(is_mutated(block, /*check_witness_root=*/false));
}
{
CBlock block;
block.vtx.push_back(create_coinbase_tx(/*include_witness=*/true));
{
CMutableTransaction mtx;
mtx.vin.resize(1);
mtx.vin[0].scriptWitness.stack.resize(1);
mtx.vin[0].scriptWitness.stack[0] = {0};
block.vtx.push_back(MakeTransactionRef(mtx));
}
block.hashMerkleRoot = BlockMerkleRoot(block);
// Block with witnesses is considered mutated if the witness commitment
// is not validated.
BOOST_CHECK(is_mutated(block, /*check_witness_root=*/false));
// Block with invalid witness commitment is considered mutated.
BOOST_CHECK(is_mutated(block, /*check_witness_root=*/true));
// Block with valid commitment is not mutated
{
auto commitment{BlockWitnessMerkleRoot(block)};
insert_witness_commitment(block, commitment);
block.hashMerkleRoot = BlockMerkleRoot(block);
}
BOOST_CHECK(is_not_mutated(block, /*check_witness_root=*/true));
// Malleating witnesses should be caught by `IsBlockMutated`.
{
CMutableTransaction mtx{*block.vtx[1]};
assert(!mtx.vin[0].scriptWitness.stack[0].empty());
++mtx.vin[0].scriptWitness.stack[0][0];
block.vtx[1] = MakeTransactionRef(mtx);
}
// Without also updating the witness commitment, the merkle root should
// not change when changing one of the witnesses.
BOOST_CHECK(block.hashMerkleRoot == BlockMerkleRoot(block));
BOOST_CHECK(is_mutated(block, /*check_witness_root=*/true));
{
auto commitment{BlockWitnessMerkleRoot(block)};
insert_witness_commitment(block, commitment);
block.hashMerkleRoot = BlockMerkleRoot(block);
}
BOOST_CHECK(is_not_mutated(block, /*check_witness_root=*/true));
// Test malleating the coinbase witness reserved value
{
CMutableTransaction mtx{*block.vtx[0]};
mtx.vin[0].scriptWitness.stack.resize(0);
block.vtx[0] = MakeTransactionRef(mtx);
block.hashMerkleRoot = BlockMerkleRoot(block);
}
BOOST_CHECK(is_mutated(block, /*check_witness_root=*/true));
}
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -77,7 +77,7 @@ public:
template<typename Stream>
void Serialize(Stream& s) const
{
s.write(MakeByteSpan(m_data));
s << Span(m_data);
}
template<typename Stream>

View File

@@ -3486,6 +3486,60 @@ static bool CheckBlockHeader(const CBlockHeader& block, BlockValidationState& st
return true;
}
static bool CheckMerkleRoot(const CBlock& block, BlockValidationState& state)
{
if (block.m_checked_merkle_root) return true;
bool mutated;
uint256 hashMerkleRoot2 = BlockMerkleRoot(block, &mutated);
if (block.hashMerkleRoot != hashMerkleRoot2)
return state.Invalid(BlockValidationResult::BLOCK_MUTATED, "bad-txnmrklroot", "hashMerkleRoot mismatch");
// Check for merkle tree malleability (CVE-2012-2459): repeating sequences
// of transactions in a block without affecting the merkle root of a block,
// while still invalidating it.
if (mutated)
return state.Invalid(BlockValidationResult::BLOCK_MUTATED, "bad-txns-duplicate", "duplicate transaction");
block.m_checked_merkle_root = true;
return true;
}
static bool CheckWitnessMalleation(const CBlock& block, bool expect_witness_commitment, BlockValidationState& state)
{
if (expect_witness_commitment) {
if (block.m_checked_witness_commitment) return true;
int commitpos = GetWitnessCommitmentIndex(block);
if (commitpos != NO_WITNESS_COMMITMENT) {
bool malleated = false;
uint256 hashWitness = BlockWitnessMerkleRoot(block, &malleated);
// The malleation check is ignored; as the transaction tree itself
// already does not permit it, it is impossible to trigger in the
// witness tree.
if (block.vtx[0]->vin[0].scriptWitness.stack.size() != 1 || block.vtx[0]->vin[0].scriptWitness.stack[0].size() != 32) {
return state.Invalid(BlockValidationResult::BLOCK_MUTATED, "bad-witness-nonce-size", strprintf("%s : invalid witness reserved value size", __func__));
}
CHash256().Write(hashWitness).Write(block.vtx[0]->vin[0].scriptWitness.stack[0]).Finalize(hashWitness);
if (memcmp(hashWitness.begin(), &block.vtx[0]->vout[commitpos].scriptPubKey[6], 32)) {
return state.Invalid(BlockValidationResult::BLOCK_MUTATED, "bad-witness-merkle-match", strprintf("%s : witness merkle commitment mismatch", __func__));
}
block.m_checked_witness_commitment = true;
return true;
}
}
// No witness data is allowed in blocks that don't commit to witness data, as this would otherwise leave room for spam
for (const auto& tx : block.vtx) {
if (tx->HasWitness()) {
return state.Invalid(BlockValidationResult::BLOCK_MUTATED, "unexpected-witness", strprintf("%s : unexpected witness data found", __func__));
}
}
return true;
}
bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW, bool fCheckMerkleRoot)
{
// These are checks that are independent of context.
@@ -3504,17 +3558,8 @@ bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensu
}
// Check the merkle root.
if (fCheckMerkleRoot) {
bool mutated;
uint256 hashMerkleRoot2 = BlockMerkleRoot(block, &mutated);
if (block.hashMerkleRoot != hashMerkleRoot2)
return state.Invalid(BlockValidationResult::BLOCK_MUTATED, "bad-txnmrklroot", "hashMerkleRoot mismatch");
// Check for merkle tree malleability (CVE-2012-2459): repeating sequences
// of transactions in a block without affecting the merkle root of a block,
// while still invalidating it.
if (mutated)
return state.Invalid(BlockValidationResult::BLOCK_MUTATED, "bad-txns-duplicate", "duplicate transaction");
if (fCheckMerkleRoot && !CheckMerkleRoot(block, state)) {
return false;
}
// All potential-corruption validation must be done before we do any
@@ -3605,6 +3650,37 @@ bool HasValidProofOfWork(const std::vector<CBlockHeader>& headers, const Consens
[&](const auto& header) { return CheckProofOfWork(header.GetHash(), header.nBits, consensusParams);});
}
bool IsBlockMutated(const CBlock& block, bool check_witness_root)
{
BlockValidationState state;
if (!CheckMerkleRoot(block, state)) {
LogPrint(BCLog::VALIDATION, "Block mutated: %s\n", state.ToString());
return true;
}
if (block.vtx.empty() || !block.vtx[0]->IsCoinBase()) {
// Consider the block mutated if any transaction is 64 bytes in size (see 3.1
// in "Weaknesses in Bitcoins Merkle Root Construction":
// https://lists.linuxfoundation.org/pipermail/bitcoin-dev/attachments/20190225/a27d8837/attachment-0001.pdf).
//
// Note: This is not a consensus change as this only applies to blocks that
// don't have a coinbase transaction and would therefore already be invalid.
return std::any_of(block.vtx.begin(), block.vtx.end(),
[](auto& tx) { return ::GetSerializeSize(tx, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) == 64; });
} else {
// Theoretically it is still possible for a block with a 64 byte
// coinbase transaction to be mutated but we neglect that possibility
// here as it requires at least 224 bits of work.
}
if (!CheckWitnessMalleation(block, check_witness_root, state)) {
LogPrint(BCLog::VALIDATION, "Block mutated: %s\n", state.ToString());
return true;
}
return false;
}
arith_uint256 CalculateHeadersWork(const std::vector<CBlockHeader>& headers)
{
arith_uint256 total_work{0};
@@ -3713,33 +3789,8 @@ static bool ContextualCheckBlock(const CBlock& block, BlockValidationState& stat
// * There must be at least one output whose scriptPubKey is a single 36-byte push, the first 4 bytes of which are
// {0xaa, 0x21, 0xa9, 0xed}, and the following 32 bytes are SHA256^2(witness root, witness reserved value). In case there are
// multiple, the last one is used.
bool fHaveWitness = false;
if (DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_SEGWIT)) {
int commitpos = GetWitnessCommitmentIndex(block);
if (commitpos != NO_WITNESS_COMMITMENT) {
bool malleated = false;
uint256 hashWitness = BlockWitnessMerkleRoot(block, &malleated);
// The malleation check is ignored; as the transaction tree itself
// already does not permit it, it is impossible to trigger in the
// witness tree.
if (block.vtx[0]->vin[0].scriptWitness.stack.size() != 1 || block.vtx[0]->vin[0].scriptWitness.stack[0].size() != 32) {
return state.Invalid(BlockValidationResult::BLOCK_MUTATED, "bad-witness-nonce-size", strprintf("%s : invalid witness reserved value size", __func__));
}
CHash256().Write(hashWitness).Write(block.vtx[0]->vin[0].scriptWitness.stack[0]).Finalize(hashWitness);
if (memcmp(hashWitness.begin(), &block.vtx[0]->vout[commitpos].scriptPubKey[6], 32)) {
return state.Invalid(BlockValidationResult::BLOCK_MUTATED, "bad-witness-merkle-match", strprintf("%s : witness merkle commitment mismatch", __func__));
}
fHaveWitness = true;
}
}
// No witness data is allowed in blocks that don't commit to witness data, as this would otherwise leave room for spam
if (!fHaveWitness) {
for (const auto& tx : block.vtx) {
if (tx->HasWitness()) {
return state.Invalid(BlockValidationResult::BLOCK_MUTATED, "unexpected-witness", strprintf("%s : unexpected witness data found", __func__));
}
}
if (!CheckWitnessMalleation(block, DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_SEGWIT), state)) {
return false;
}
// After the coinbase witness reserved value and commitment are verified,

View File

@@ -352,6 +352,9 @@ bool TestBlockValidity(BlockValidationState& state,
/** Check with the proof of work on each blockheader matches the value in nBits */
bool HasValidProofOfWork(const std::vector<CBlockHeader>& headers, const Consensus::Params& consensusParams);
/** Check if a block has been mutated (with respect to its merkle root and witness commitments). */
bool IsBlockMutated(const CBlock& block, bool check_witness_root);
/** Return the sum of the work on a given set of headers */
arith_uint256 CalculateHeadersWork(const std::vector<CBlockHeader>& headers);

View File

@@ -57,12 +57,12 @@ bool DumpWallet(const ArgsManager& args, CWallet& wallet, bilingual_str& error)
// Write out a magic string with version
std::string line = strprintf("%s,%u\n", DUMP_MAGIC, DUMP_VERSION);
dump_file.write(line.data(), line.size());
hasher.write(MakeByteSpan(line));
hasher << Span{line};
// Write out the file format
line = strprintf("%s,%s\n", "format", db.Format());
dump_file.write(line.data(), line.size());
hasher.write(MakeByteSpan(line));
hasher << Span{line};
if (ret) {
@@ -83,7 +83,7 @@ bool DumpWallet(const ArgsManager& args, CWallet& wallet, bilingual_str& error)
std::string value_str = HexStr(ss_value);
line = strprintf("%s,%s\n", key_str, value_str);
dump_file.write(line.data(), line.size());
hasher.write(MakeByteSpan(line));
hasher << Span{line};
}
}
@@ -160,7 +160,7 @@ bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs::
return false;
}
std::string magic_hasher_line = strprintf("%s,%s\n", magic_key, version_value);
hasher.write(MakeByteSpan(magic_hasher_line));
hasher << Span{magic_hasher_line};
// Get the stored file format
std::string format_key;
@@ -191,7 +191,7 @@ bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs::
warnings.push_back(strprintf(_("Warning: Dumpfile wallet format \"%s\" does not match command line specified format \"%s\"."), format_value, file_format));
}
std::string format_hasher_line = strprintf("%s,%s\n", format_key, format_value);
hasher.write(MakeByteSpan(format_hasher_line));
hasher << Span{format_hasher_line};
DatabaseOptions options;
DatabaseStatus status;
@@ -236,7 +236,7 @@ bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs::
}
std::string line = strprintf("%s,%s\n", key, value);
hasher.write(MakeByteSpan(line));
hasher << Span{line};
if (key.empty() || value.empty()) {
continue;

View File

@@ -2596,8 +2596,10 @@ util::Result<CTxDestination> ReserveDestination::GetReservedDestination(bool int
if (nIndex == -1) {
CKeyPool keypool;
auto op_address = m_spk_man->GetReservedDestination(type, internal, nIndex, keypool);
int64_t index;
auto op_address = m_spk_man->GetReservedDestination(type, internal, index, keypool);
if (!op_address) return op_address;
nIndex = index;
address = *op_address;
fInternal = keypool.fInternal;
}
@@ -3863,9 +3865,7 @@ bool CWallet::MigrateToSQLite(bilingual_str& error)
bool began = batch->TxnBegin();
assert(began); // This is a critical error, the new db could not be written to. The original db exists as a backup, but we should not continue execution.
for (const auto& [key, value] : records) {
DataStream ss_key{key};
DataStream ss_value{value};
if (!batch->Write(ss_key, ss_value)) {
if (!batch->Write(Span{key}, Span{value})) {
batch->TxnAbort();
m_database->Close();
fs::remove(m_database->Filename());

View File

@@ -1132,13 +1132,13 @@ bool WalletBatch::EraseRecords(const std::unordered_set<std::string>& types)
}
// Make a copy of key to avoid data being deleted by the following read of the type
Span<const unsigned char> key_data = MakeUCharSpan(key);
const SerializeData key_data{key.begin(), key.end()};
std::string type;
key >> type;
if (types.count(type) > 0) {
m_batch->Erase(key_data);
m_batch->Erase(Span{key_data});
}
}
return true;

View File

@@ -0,0 +1,116 @@
#!/usr/bin/env python3
# Copyright (c) The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""
Test that an attacker can't degrade compact block relay by sending unsolicited
mutated blocks to clear in-flight blocktxn requests from other honest peers.
"""
from test_framework.p2p import P2PInterface
from test_framework.messages import (
BlockTransactions,
msg_cmpctblock,
msg_block,
msg_blocktxn,
HeaderAndShortIDs,
)
from test_framework.test_framework import BitcoinTestFramework
from test_framework.blocktools import (
COINBASE_MATURITY,
create_block,
add_witness_commitment,
NORMAL_GBT_REQUEST_PARAMS,
)
from test_framework.util import assert_equal
from test_framework.wallet import MiniWallet
import copy
class MutatedBlocksTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 1
self.extra_args = [
[
"-testactivationheight=segwit@1", # causes unconnected headers/blocks to not have segwit considered deployed
],
]
def run_test(self):
self.wallet = MiniWallet(self.nodes[0])
self.generate(self.wallet, COINBASE_MATURITY)
honest_relayer = self.nodes[0].add_outbound_p2p_connection(P2PInterface(), p2p_idx=0, connection_type="outbound-full-relay")
attacker = self.nodes[0].add_p2p_connection(P2PInterface())
# Create new block with two transactions (coinbase + 1 self-transfer).
# The self-transfer transaction is needed to trigger a compact block
# `getblocktxn` roundtrip.
tx = self.wallet.create_self_transfer()["tx"]
block = create_block(tmpl=self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS), txlist=[tx])
add_witness_commitment(block)
block.solve()
# Create mutated version of the block by changing the transaction
# version on the self-transfer.
mutated_block = copy.deepcopy(block)
mutated_block.vtx[1].nVersion = 4
# Announce the new block via a compact block through the honest relayer
cmpctblock = HeaderAndShortIDs()
cmpctblock.initialize_from_block(block, use_witness=True)
honest_relayer.send_message(msg_cmpctblock(cmpctblock.to_p2p()))
# Wait for a `getblocktxn` that attempts to fetch the self-transfer
def self_transfer_requested():
if not honest_relayer.last_message.get('getblocktxn'):
return False
get_block_txn = honest_relayer.last_message['getblocktxn']
return get_block_txn.block_txn_request.blockhash == block.sha256 and \
get_block_txn.block_txn_request.indexes == [1]
honest_relayer.wait_until(self_transfer_requested, timeout=5)
# Block at height 101 should be the only one in flight from peer 0
peer_info_prior_to_attack = self.nodes[0].getpeerinfo()
assert_equal(peer_info_prior_to_attack[0]['id'], 0)
assert_equal([101], peer_info_prior_to_attack[0]["inflight"])
# Attempt to clear the honest relayer's download request by sending the
# mutated block (as the attacker).
with self.nodes[0].assert_debug_log(expected_msgs=["Block mutated: bad-txnmrklroot, hashMerkleRoot mismatch"]):
attacker.send_message(msg_block(mutated_block))
# Attacker should get disconnected for sending a mutated block
attacker.wait_for_disconnect(timeout=5)
# Block at height 101 should *still* be the only block in-flight from
# peer 0
peer_info_after_attack = self.nodes[0].getpeerinfo()
assert_equal(peer_info_after_attack[0]['id'], 0)
assert_equal([101], peer_info_after_attack[0]["inflight"])
# The honest relayer should be able to complete relaying the block by
# sending the blocktxn that was requested.
block_txn = msg_blocktxn()
block_txn.block_transactions = BlockTransactions(blockhash=block.sha256, transactions=[tx])
honest_relayer.send_and_ping(block_txn)
assert_equal(self.nodes[0].getbestblockhash(), block.hash)
# Check that unexpected-witness mutation check doesn't trigger on a header that doesn't connect to anything
assert_equal(len(self.nodes[0].getpeerinfo()), 1)
attacker = self.nodes[0].add_p2p_connection(P2PInterface())
block_missing_prev = copy.deepcopy(block)
block_missing_prev.hashPrevBlock = 123
block_missing_prev.solve()
# Attacker gets a DoS score of 10, not immediately disconnected, so we do it 10 times to get to 100
for _ in range(10):
assert_equal(len(self.nodes[0].getpeerinfo()), 2)
with self.nodes[0].assert_debug_log(expected_msgs=["AcceptBlock FAILED (prev-blk-not-found)"]):
attacker.send_message(msg_block(block_missing_prev))
attacker.wait_for_disconnect(timeout=5)
if __name__ == '__main__':
MutatedBlocksTest().main()

View File

@@ -32,6 +32,7 @@ from test_framework.script import (
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
assert_greater_than,
assert_raises_rpc_error,
)
from test_framework.wallet import (
@@ -70,7 +71,7 @@ class RawTransactionsTest(BitcoinTestFramework):
self.extra_args = [
["-txindex"],
["-txindex"],
[],
["-fastprune", "-prune=1"],
]
# whitelist all peers to speed up tx relay / mempool sync
for args in self.extra_args:
@@ -85,7 +86,6 @@ class RawTransactionsTest(BitcoinTestFramework):
self.wallet = MiniWallet(self.nodes[0])
self.getrawtransaction_tests()
self.getrawtransaction_verbosity_tests()
self.createrawtransaction_tests()
self.sendrawtransaction_tests()
self.sendrawtransaction_testmempoolaccept_tests()
@@ -94,6 +94,8 @@ class RawTransactionsTest(BitcoinTestFramework):
if self.is_specified_wallet_compiled() and not self.options.descriptors:
self.import_deterministic_coinbase_privkeys()
self.raw_multisig_transaction_legacy_tests()
self.getrawtransaction_verbosity_tests()
def getrawtransaction_tests(self):
tx = self.wallet.send_self_transfer(from_node=self.nodes[0])
@@ -243,6 +245,13 @@ class RawTransactionsTest(BitcoinTestFramework):
coin_base = self.nodes[1].getblock(block1)['tx'][0]
gottx = self.nodes[1].getrawtransaction(txid=coin_base, verbosity=2, blockhash=block1)
assert 'fee' not in gottx
# check that verbosity 2 for a mempool tx will fallback to verbosity 1
# Do this with a pruned chain, as a regression test for https://github.com/bitcoin/bitcoin/pull/29003
self.generate(self.nodes[2], 400)
assert_greater_than(self.nodes[2].pruneblockchain(250), 0)
mempool_tx = self.wallet.send_self_transfer(from_node=self.nodes[2])['txid']
gottx = self.nodes[2].getrawtransaction(txid=mempool_tx, verbosity=2)
assert 'fee' not in gottx
def createrawtransaction_tests(self):
self.log.info("Test createrawtransaction")

View File

@@ -275,6 +275,7 @@ BASE_SCRIPTS = [
'wallet_crosschain.py',
'mining_basic.py',
'feature_signet.py',
'p2p_mutated_blocks.py',
'wallet_implicitsegwit.py --legacy-wallet',
'rpc_named_arguments.py',
'feature_startupnotify.py',

View File

@@ -103,11 +103,18 @@ class KeyPoolTest(BitcoinTestFramework):
nodes[0].getrawchangeaddress()
nodes[0].getrawchangeaddress()
nodes[0].getrawchangeaddress()
addr = set()
# remember keypool sizes
wi = nodes[0].getwalletinfo()
kp_size_before = [wi['keypoolsize_hd_internal'], wi['keypoolsize']]
# the next one should fail
assert_raises_rpc_error(-12, "Keypool ran out", nodes[0].getrawchangeaddress)
# check that keypool sizes did not change
wi = nodes[0].getwalletinfo()
kp_size_after = [wi['keypoolsize_hd_internal'], wi['keypoolsize']]
assert_equal(kp_size_before, kp_size_after)
# drain the external keys
addr = set()
addr.add(nodes[0].getnewaddress(address_type="bech32"))
addr.add(nodes[0].getnewaddress(address_type="bech32"))
addr.add(nodes[0].getnewaddress(address_type="bech32"))
@@ -115,8 +122,15 @@ class KeyPoolTest(BitcoinTestFramework):
addr.add(nodes[0].getnewaddress(address_type="bech32"))
addr.add(nodes[0].getnewaddress(address_type="bech32"))
assert len(addr) == 6
# remember keypool sizes
wi = nodes[0].getwalletinfo()
kp_size_before = [wi['keypoolsize_hd_internal'], wi['keypoolsize']]
# the next one should fail
assert_raises_rpc_error(-12, "Error: Keypool ran out, please call keypoolrefill first", nodes[0].getnewaddress)
# check that keypool sizes did not change
wi = nodes[0].getwalletinfo()
kp_size_after = [wi['keypoolsize_hd_internal'], wi['keypoolsize']]
assert_equal(kp_size_before, kp_size_after)
# refill keypool with three new addresses
nodes[0].walletpassphrase('test', 1)