Commit graph

25133 commits

Author SHA1 Message Date
Hennadii Stepanov
cc323e0d95 wallet: Postpone NotifyWalletLoaded() for encrypted wallets
Too early NotifyWalletLoaded() call in CWallet::Create() results the
notification goes before DescriptorScriptPubKeyMans were created and
added to an encrypted wallet.

Co-authored-by: Andrew Chow <achow101-github@achow101.com>

Github-Pull: bitcoin/bitcoin#24711
Rebased-From: 0c12f0116c
2025-03-10 15:36:55 +00:00
Hennadii Stepanov
92a518c4f3 wallet, refactor: Add wallet::NotifyWalletLoaded() function
This change is a prerequisite for the following bugfix.

Github-Pull: bitcoin/bitcoin#24711
Rebased-From: aeee419c6a
2025-03-10 15:36:42 +00:00
Hennadii Stepanov
17562c0a58 util: Add inotify_rm_watch to syscall sandbox (AllowFileSystem)
Github-Pull: bitcoin#24690
Rebased-From: f05a4cd
2025-03-10 15:35:55 +00:00
fanquake
ba78a0a8cb util: add linkat to syscall sandbox (AllowFileSystem)
Github-Pull: bitcoin#24659
Rebased-From: 9809db3
2025-03-10 15:15:25 +00:00
Vasil Dimov
ff3e02f606 options: flip listenonion to false if not listening
If the user has unchecked "Allow incoming connections" in
`Settings->Options...->Network` then `fListen=false` is saved in
`~/.config/Bitcoin/Bitcoin-Qt.conf`. This flips `-listen` to `false`
during startup, but leaves `-listenonion` to `true`.

This flipping of `-listen` is done in `OptionsModel::Init()` after
`InitParameterInteraction()` has been executed which would have flipped
`-listenonion`, should it have seen `-listen` being `false`
(this is a difference between `bitcoind` and `bitcoin-qt`).

Fixes: https://github.com/bitcoin-core/gui/issues/567

Github-Pull: bitcoin-core/gui#568
Rebased-From: 7f90dc26c8
2025-03-10 15:14:53 +00:00
Thomas Trevethan
218360bb71 fix prefix 2025-03-10 14:39:32 +00:00
MarcoFalke
e8941f064a rpc: Exclude descriptor when address is excluded
Github-Pull: bitcoin#24636
Rebased-From: faf37c2
2025-03-10 13:35:38 +00:00
Jon Atack
ccb3a3e636 Clarify in -maxtimeadjustment that only outbound peers influence time data
Github-Pull: bitcoin#24609
Rebased-From: 1bba72d
2025-03-10 13:33:32 +00:00
Jon Atack
608381c1e8 rpc: rename getdeploymentinfo status-next to status_next
Github-Pull: bitcoin#24528
Rebased-From: 5d7c69b
2025-03-10 11:51:55 +00:00
Martin Zumsande
b670213579 test: set segwit height back to 0 on regtest
This was changed in #22818 from 0 to 1. Since it changes
BLOCK_OPT_WIT of the genesis block, older versions of bitcoin
core would not read regtest directories created with newer versions
without a reindex.

Github-Pull: bitcoin#24527
Rebased-From: 5ce3057
2025-03-10 11:51:38 +00:00
Ryan Ofsky
7e7dbadf44 test: Add tests for GetArg methods / settings.json type coercion
Just add tests. No changes to application behavior. Tests will be
updated in the next commit changing & improving current behavior.

Include a Qt test for GUI startup crash reported by Rspigler in
https://github.com/bitcoin/bitcoin/issues/24457 caused by GetArg
behavior that happens if settings.json contains an integer value for any
of the configuration options which GUI settings can currently clash with
(-dbcache, -par, -spendzeroconfchange, -signer, -upnp, -natpmp, -listen,
-server, -proxy, -proxy, -onion, -onion, -lang, and -prune).

Github-Pull: bitcoin/bitcoin#24498
Rebased-From: 84b0973e35
2025-03-10 11:49:53 +00:00
Russell O'Connor
3a80782963 Avoid double free in simplicity pointer when copying PrecomputedTransactionData
We cannot put a raw pointer into a class that has a default copy constructor.
2025-03-03 17:35:07 -05:00
Pablo Greco
59c30c0779 Blinding: update change_position after calling fillBlindDetails 2025-02-25 14:57:10 -08:00
Pablo Greco
4058bd114b Remove extra ; in confidential.h 2025-02-25 14:57:10 -08:00
Pablo Greco
b92a3ceda2 TSAN: Avoid unlocked access to pindexBestHeader 2025-02-23 14:34:19 -08:00
Pablo Greco
38065e1159 Fix warning about mixing enum and int 2025-02-23 14:34:19 -08:00
Pablo Greco
73c542ea58 Fix error reading cookie file on windows when path contains UTF-8 2025-02-23 14:34:19 -08:00
Pablo Greco
fe04483875 Avoid concatenating default path when mainchainrpccookiefile is an absolute path 2025-02-23 14:34:19 -08:00
Russell O'Connor
c211d1a4d9 Merge commit '37adf7d72d' into simplicity 2025-02-18 13:11:04 -05:00
Byron Hambly
12c586a3bf
Merge pull request #1417 from psgreco/master-fix-win64native
Fix Win64 native unit test
2025-02-18 16:05:44 +02:00
Byron Hambly
c9c21cf7df
Merge pull request #1416 from apoelstra/2025-02--psbt-fix
pset: fix NULL pointer dereference when deserializing malformed PSETs over RPC
2025-02-18 15:06:38 +02:00
Jon Atack
7f56623441 Put lock logging behind DEBUG_LOCKCONTENTION preprocessor directive 2025-02-15 00:22:57 -08:00
Andrew Poelstra
0bff9b06f7
psbt: guard against empty PSBT transaction
There is a crashing bug in psbt.h which works as follows. This occurs in
the psbt_deserialize_input fuzz test, which deserializes an input and
then tries to reserialize it. Here a PSET input may contain a mainchain
transaction, which is where our trouble is.

The process is as follows:

1. On line 901, we create a CTransactionRef, which is a newtype around
   std::shared_ptr<CTransaction> which defaults to being null.
2. On line 903 we then call `UnserializeFromVector` to populate this,
   where this is a helper function which attempts to read some number of
   objects from a byte vector, i.e. a length-prefixed blob.
3. HOWEVER, `UnserializeFromVector` when given an empty vector, decides
   that it has successfully deserialized zero elements, and returns.
4. Then, on line 904 we assign the CTransactionRef, which is a valid
   std::shared_ptr whose internal pointer is NULL, to `m_peg_in_tx`,
   which is a variant of monostate, Bitcoin::CTransactionRef, and
   CTransactionRef. Its variant changes from the default monostate
   to CTransactionRef.
5. Then, on line 419, we call `std::get_if<CTransactionRef>` on this
   object, which returns a std::optional<CTransactionRef>. Because
   `m_peg_in_tx` is in the `CTransactionRef` variant, this succeeds,
   returning a true std::optional containing a valid std::shared_ptr
   which contains a NULL pointer.
6. Then, on line 420, we call `if (peg_in_tx)`, which is true, because
   we have a true std::optional. We then dereference it on line 423,
   which is perfectly legal, to get our std::shared_ptr, and pass this
   shared pointer to SerializeToVector.
7. SerializeToVector passes through like 6 layers of serialize.h
   obfuscation and eventually dereferences the shared pointer, but
   because it's NULL, this is a NULL pointer dereference, and we get a
   crash.

There are two lessons here:

1. Don't use C++. As I say in acf709b3ab,
   where I introduced some of the offending code here (but only by
   replacing boost stuff with their STL equivalents; the bug existed
   before I did this), "what a trainwreck of a language".
2. Don't use `UnserializeFromVector` and expect it to throw if the data
   you're deserializing is malformed. If it's malformed in the sense of
   being empty, it will "succeed" and silently do nothing.

I glanced at every other instance of UnserializeFromVector to check what
will happen when it's passed an empty string. I believe there are no
other cases where it will fail to initialize a NULL pointer, so I
believe that this will not cause other crashes. But I also believe that
the behavior in this case is almost always wrong and that we parse
malformed PSETs in crazy and incorrect ways all over the place.

If anybody has a problem with this, I encourage you to go review the
Bitcoin PSBT2 PRs, which this stuff is based on, which have been
languishing in rebase hell for the better part of a decade. Don't blame
the author for not writing perfect code in a hostile language with no
support.

After this PR I ran the fuzzer for 16 hours on a 192-thread machine (so
3072 CPU-hours) and didn't see any more crashes.
2025-02-14 18:08:45 +00:00
Andrew Poelstra
f7826f9199
psbt: avoid assigning non-boolean values to bool (ubsan)
ubsan doesn't like assigning arbitrary uint8_t values to bool. It's easy
to avoid doing, so do it. (We do this specifically in PSET since that's
Elements-specific code, but the same issue is present in Bitcoin in the
Unserialize impl for bool in serialize.h. Upstream this is only used in
the wallet database, where it may be that non 0/1 values are impossible
(absent a corrupt wallet).
2025-02-14 18:07:48 +00:00
Andrew Poelstra
a2d24eff9e
fuzz: remove dead code from simplicity_tx.cpp 2025-02-13 23:09:51 +00:00
Andrew Poelstra
69c241592f
fuzz: update simplicity_tx target to hit simplicity CMR error 2025-02-13 23:08:57 +00:00
Russell O'Connor
b475a32abd Merge commit '9fc3797c7e' into simplicity 2025-02-12 14:05:32 -05:00
Andrew Poelstra
3fe5d12c57
fuzz: simplicity: use zero CMR for invalid programs
When we have an invalid program, use a zero CMR and create a valid
control block/taptweak. Otherwise we fail to hit the Simplicity logic at
all with bad programs.

#
# You are committing on CAMUS
#

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch 2024-12--simple-fuzz
# Changes to be committed:
#	modified:   src/test/fuzz/simplicity_tx.cpp
#
# Untracked files:
#	reduced-corpus/
#	run-fuzz-merge-dir-CPzq/
#	run-fuzz-merge-dir-sscf/
#
2025-02-11 16:12:29 +00:00
Andrew Poelstra
eea423e3d6
fuzz: add second simplicity fuzz test
The first fuzztest takes a Simplicity program and a transaction and
directly calls the Simplicity interpreter with some context cobbled
together from the transaction. It also tries messing with the budget
and computes AMRs to check that the AMR-check works, even though on
the blockchain AMRs are never used.

It also attempts mangling programs to directly fuzz the parser, type
inference and CMR checking.

THIS test, on the other hand, takes a transaction, looks for Simplicity
programs (or witnesses which look like Simplicity programs), computes
their CMRs to produce a correct corresponding scriptPubKey, creates
scriptchecks, and executes them. This should do an end-to-end coverage
of the whole Simplicity consensus logic, including all the new branches
in interpreter.cpp.

To produce seeds for this, I have a a local fuzz target which uses
rust-simplicity and rust-elements to produce programs, deep Taproot trees,
and transactions. I run this to get high coverage, then dump the
resulting complete transactions to disk, where they can be used as
seeds for this test.
2025-02-11 16:12:29 +00:00
Andrew Poelstra
a87e4cf70b
simplicity: rewrite fuzz target
This fuzz target takes its seeds in a simple and well-defined format: a
four-byte LE budget, then a transaction, Simplicity program and witness,
each prefixed by a four-byte LE length. The fuzz target extracts any
additional randomness it needs from the txid of the first input of the
transaction, since this data is not interpreted in any other way we
therefore won't confuse the fuzzer.

The reason for this design, rather than a more typical "just query the
fuzzer when you need stuff", is to make it possible to fairly easily
generate test vectors from sources other than this fuzz test. (For
example, I have an alternate target which uses Rust code to generate
well-formed Simplicity programs, which quickly gets high coverage at the
expense of being an unmaintainable mess.)

This commit includes a .c file with a small function to comute the AMR
of a program. This is needed to pass a correct AMR to the Simplicity
interpreter, to exercise all the AMR-checking paths. In practice this is
not really necessary; Elements passes NULL to disable these AMR checks.
2025-02-11 16:12:28 +00:00
Byron Hambly
52642b1afd
simplicity: add fuzz target 2025-02-11 16:12:28 +00:00
Byron Hambly
d020546243
Merge pull request #1401 from apoelstra/2025-02--fuzz-fixes-2
more fuzzer fixes (continuation of #1399)
2025-02-11 17:58:42 +02:00
Pablo Greco
b703da1148 Fix build with gcc-15 2025-02-11 06:14:51 -08:00
fanquake
8251fc8162 23.x Add missing includes to fix gcc-13 compile error
Additional include fixes are required to make the 23.x branch compile
using GCC 13.

(cherry picked from commit af86266165)
2025-02-11 06:14:51 -08:00
MarcoFalke
f64aa1e6c6 Add missing includes to fix gcc-13 compile error
(cherry picked from commit fadeb6b103)
2025-02-11 06:14:51 -08:00
Hennadii Stepanov
f8b1bb7070 build: Fix Boost.Process test for Boost 1.78
(cherry picked from commit 532c64a726)
2025-02-11 06:14:51 -08:00
MarcoFalke
56eec70de4
Fix signed integer overflow in prioritisetransaction RPC
Cherry-pick of fa52cf8e11
https://github.com/bitcoin/bitcoin/pull/23418 (2/2)
2025-02-11 13:47:57 +00:00
MarcoFalke
6043ab449e
refactor: Replace feeDelta by m_modified_fee
* feeDelta tracked the delta (to be applied on top of the actual fee)
* m_modified_fee tracks the actual fee with the delta included
* Instead of passing in the new total delta to the Updater, pass in by
  how much the total delta should be modified.

This is needed for the next commit, but makes sense on its own because
the same is done by UpdateDescendantState and UpdateAncestorState.

Cherry-pick of fa52cf8e11
https://github.com/bitcoin/bitcoin/pull/23418 (1/2)
2025-02-11 13:47:56 +00:00
Byron Hambly
99c2ee7f9a
Merge pull request #1399 from apoelstra/2025-02--fuzz-fixes
various bugfixes for new fuzz test vectors
2025-02-11 09:49:42 +02:00
Byron Hambly
22089ac8f6
Merge pull request #1372 from delta1/issues-1371
decodepsbt: add asset/assetcommitment to input.witness_utxo
2025-02-11 08:47:17 +02:00
Andrew Poelstra
363c5101c2
fuzz: change int to unsigned in witness_program
Avoids a signed/unsigned integer conversion.
2025-02-11 04:04:25 +00:00
MarcoFalke
371718bc99
Use CAmount for fee delta and modified fee
Cherry-pick of fa84a49526
https://github.com/bitcoin/bitcoin/pull/24625 (2/2)
2025-02-11 02:58:42 +00:00
MarcoFalke
3e46754507
Replace struct update_fee_delta with lambda
Cherry-pick of https://github.com/bitcoin/bitcoin/pull/24625 (1/2)
2025-02-11 02:58:42 +00:00
Andrew Poelstra
bd4ae1bcc4
rpc: fix crash in getcompactsketch
This originates in 8723debb3d which has no
PR associated with it. We've really gotta stop putting thousands of
unreviewed commits into this project and rebasing the history away..
2025-02-11 02:58:41 +00:00
Andrew Poelstra
f5ed4e4520
chain: make some integer conversions explicit
We have an unsigned constant which we're bit-inverting, or'ing into a
signed constant, then assigning back to the signed constant. We should
make it explicit wth is going on here.
2025-02-11 02:53:49 +00:00
Andrew Poelstra
86d740b5eb
fuzz: fix crash on null pointer in witness_program target 2025-02-11 02:53:44 +00:00
Cory Fields
cad37df99f upnp: add compatibility for miniupnpc 2.2.8
See: c0a50ce33e

The return value of 2 now indicates:
"A valid connected IGD has been found but its IP address is reserved (non routable)"

We continue to ignore any return value other than 1.

(cherry picked from commit 8acdf66540)
2025-02-07 13:25:48 -08:00
Andrew Poelstra
ff6482fc29
fuzz: add SelectParams to rbf.cpp
We cannot fuzz RBF (or do anything mempool-related, really) without
chainparams. This has been true since 2019 at least. I suspect this fuzz
test has never really been run.
2025-02-06 21:31:47 +00:00
Andrew Poelstra
a3b7e71a3d
transaction: refuse to deserialize TxOuts with null values
In Bitcoin Core the notion of a "null" amount (and therefore a "null"
txout) is one which cannot be serialized or deserialized. In Core this
is implemented using a value of -1.

In Elements we use the CT notion of "nullness" which is that the flag on
the confidential value is 0. See d53479c9ff
which implemented this. This is reasonable, but because we don't have
checks on deserialization, we can deserialize objects that cannot be
reserialized.

In particular, in coins.h, we deserialize a coin by deserializing its
txout. When reserializing we assert that !out.IsNull(). This assertion
is hit by the `coins_deserialize` fuzztest.

There are a few potential fixes here:

* Remove the assertion from coins.h, which is there to catch logic bugs
  in Core, on the assumption that if they have no bugs then we don't
  either. This seems like a bad idea.
* Change "nullness" for amounts to be an encoding of -1, like in Core.
  This seems dangerous because we call `GetAmount` all over the place,
  and if this could return the -1 amount, this will likely blow
  something up. Probably this is safe for the same reason it is in Core
  -- that is, we never create null txouts except as sentinel values. But
  do you wanna bet that this is true now? That it'll always be true?
* Same as above, but assert that the amount is not null. This is safer
  than just blindly hoping that no overflows will occur but still not
  obviously safe.
* Refuse to deserialize null CT objects. This is impossible because we
  use null nonce values in txouts.
* Refuse to deserialize null CT values. Similarly, this is impossible
  because we use null values in null asset issuances, which are legal.
* Refused to deserialize CTxOuts with null values or assets.

We are going with the latter solution, because it is narrowly scoped,
does not increase the "crash surface" (we throw an exception, and we
already throw exceptions for other kinds of invalid serializations),
and is very unlikely to cause bugs (null values are invalid on the
network anyway; this is the first check in VerifyAmounts) (so are null
assets for that matter, which we maybe also should refuse to
deserialize).
2025-02-06 21:31:47 +00:00
Russell O'Connor
31d94775b3 Update to latest Simplicity
The main difference is that there is now explicit simplicity deallocation functions to go with the allocation functions in the API.
There are some minor changes to error message text.
The deserialization code is now automatically generated.
The are some other minor internal changes.
2025-02-04 12:14:25 -05:00