Commit graph

22578 commits

Author SHA1 Message Date
muxator
8d24f56227 rpc: fix crash in deriveaddresses when derivation index is 2147483647
2147483647 is the maximum positive value of a signed int32, and - currently -
the maximum value that the deriveaddresses bitcoin RPC call accepts as
derivation index due to its input validation routines.

Before this change, when the derivation index (and thus range_end) reached
std::numeric_limits<int_32_t>::max(), the "i" variable in the for cycle (which
is declared as int, and as such 32 bits in size on most platforms) would be
incremented at the end of the first iteration and then warp back to
-2147483648. This caused SIGABRT in bitcoind and a core dump.

This change assigns "i" an explicit size of 64 bits on every platform,
sidestepping the problem.

Fixes #26274.

Github-Pull: #26275
Rebased-From: addf9d6502
(cherry picked from commit db20d278e212b2a393a331624184a61fab6c05c9)
2022-12-07 20:13:57 +00:00
Hennadii Stepanov
77c94f82d2 Prevent data race for pathHandlers
Github-Pull: bitcoin/bitcoin#25983
Rebased-From: 4296dde287
(cherry picked from commit 2c6c628ab95b018ac7ce6595954644bf9197ce35)
2022-12-07 20:13:57 +00:00
Ryan Ofsky
d407fb6168 qt: Avoid crash on startup if int specified in settings.json
Fix GUI startup crash reported by Rspigler in
https://github.com/bitcoin/bitcoin/issues/24457 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).

Fix is a one-line change in ArgsManager::GetArg.

Github-Pull: bitcoin/bitcoin#24498
Rebased-From: 5b1aae12ca
(cherry picked from commit 344537cf04373d757522e042f29f25a0f9595404)
2022-12-07 20:08:16 +00:00
Pablo Greco
e528b34ed8 Fix tests after backport of #22949 2022-12-07 11:11:30 +00:00
Andrew Chow
5f376a3588 fees: Always round up fee calculated from a feerate
When calculating the fee for a given tx size from a fee rate, we should
always round up to the next satoshi. Otherwise, if we round down (via
truncation), the calculated fee may result in a fee with a feerate
slightly less than targeted.

This is particularly important for coin selection as a slightly lower
feerate than expected can result in a variety of issues.

Github-Pull: #22949
Rebased-From: 0fbaef9676
(cherry picked from commit bd7e08e36bf2e1238ddf8cc01433f8db82f848c9)
2022-12-07 11:11:30 +00:00
Sebastian Falbesoner
ff712274d9 wallet: fix segfault by avoiding invalid default-ctored external_spk_managers entry
In the method `CWallet::LoadActiveScriptPubKeyMan`, the map
`external_spk_managers` (or `internal_spk_managers`, if parameter
`internal` is false) is accessed via std::map::operator[], which means
that a default-ctored entry is created with a null-pointer as value, if
the key doesn't exist.  As soon as this value is dereferenced, a
segmentation fault occurs, e.g. in `CWallet::KeypoolCountExternalKeys`.

The bevaviour can be reproduced by the following steps (starting with empty regtest datadir):

$ ./src/bitcoind -regtest -daemon
$ ./src/bitcoin-cli -regtest -named createwallet_name=wallet descriptors=true blank=true
$ cat regtest-descriptors.txt
[
  {
    "desc": "tr([e4445899/49'/1'/0']tprv8ZgxMBicQKsPd8jCeBWsYLEoWxbVgzJDatJ7XkwQ6G3uF4FsHuaziHQ5JZAW4K515nj6kVVwPaNWZSMEcR7aFCwL4tQqTcaoprMKTTtm6Zg/1/*)#mr3llm7f",
    "timestamp": 1634652324,
    "active": true,
    "internal": true,
    "range": [
      0,
      999
    ],
    "next": 0
  }
]
$ ./src/bitcoin-cli -regtest importdescriptors "$(cat regtest-descriptors.txt)"
[
  {
    "success": true
  }
]
$ ./src/bitcoin-cli -regtest getwalletinfo
error: timeout on transient error: Could not connect to the server 127.0.0.1:18443 (error code 1 - "EOF reached")

Bug reported by Josef Vondrlik (josef-v).

Github-Pull: #23333
Rebased-From: 6911ab95f1
(cherry picked from commit 227ae652542451834faddbaffb54fc384e9156e6)
2022-12-07 11:11:30 +00:00
Joan Karadimov
48a01ec059 refactor: include a missing <limits> header in fs.cpp
... needed for std::numeric_limits<T>::max on WIN32

Github-Pull: #23335
Rebased-From: 077a875d94
(cherry picked from commit 282863a7e9ddfb14ef02182945ca1978699dbe52)
2022-12-07 11:11:30 +00:00
Jon Atack
5ce127803e consensus: don't call GetBlockPos in ReadBlockFromDisk without lock
Github-Pull: #22895
Rebased-From: 350e034e64
(cherry picked from commit 7febe4f3c7f482390c4aa6fc528e2ee3fb34b142)
2022-12-07 11:11:30 +00:00
Saibato
ee109b4f28 the result of CWallet::IsHDEnabled() was initialized with true.
But in case of no keys or a blank hd wallet the iterator would be skipped
and not set to false but true, since the loop would be not entered.

That had resulted in a wrong return and subsequent false HD and watch-only
icon display in gui when reloading a wallet after closing.

Update src/wallet/wallet.cpp

Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>

Github-Pull: #22781
Rebased-From: 8733a8e84c
(cherry picked from commit c671c6f4706d17cccfe5c35950235f8777a7975f)
2022-12-07 11:11:30 +00:00
fanquake
90ffd0c1b8 system: skip trying to set the locale on NetBSD
Just treat it the same as the other BSDs.

Fixes #17379.

Github-Pull: #22390
Rebased-From: fdd71448e7
(cherry picked from commit c95b188fc08387d0a89668e56bce3a4fad1ee611)
2022-12-07 11:11:30 +00:00
MarcoFalke
df09befb2f Fix (inverse) meaning of -persistmempool
Github-Pull: #23061
Rebased-From: faff17bbde
(cherry picked from commit db76db7329f6357c5226cd08611fe0f669c002af)
2022-12-07 11:11:30 +00:00
Martin Zumsande
3b672e7196 rpc: Capture potentially large UniValue by ref for rpcdoccheck
Github-Pull: 25237
Rebased-From: 20ff4991e5
(cherry picked from commit 7fcac96597)
2022-12-07 10:50:06 +00:00
Pablo Greco
dff0e8202b Merge branch 'master' into elements_22_1_rc1 2022-12-07 10:47:10 +00:00
Pablo Greco
2c7335fecc Remove duplicated code from merge 2022-11-25 12:54:09 -03:00
Steven Roose
30f02624c7
Have testproposedblock return RPC_VERIFY_ALREADY_IN_CHAIN
Instead of RPC_VERIFY_ERROR when the block is already in the chain.
2022-11-24 14:08:51 +00:00
James Dorfman
5c82e351a9
Merge pull request #1194 from andreabonel/add_back_missing_field_in_getblock
Add missing field 'signblock_challenge' back to getblock
2022-11-23 11:23:54 -05:00
Andrew Poelstra
1339dae913
Merge ElementsProject/elements#1167: Add native support for liquidtestnet
c6e074e25b liquidtestnet: Fix chain name in windows installer (Pablo Greco)
d0f391cfdb liquidtestnet: Add style for Elements-Qt (Pablo Greco)
48ddfbf8d7 liquidtestnet: Add fixed seeds (Pablo Greco)
3b34c8e927 liquidtestnet: Add seed nodes (Pablo Greco)
0d1964766f liquidtestnet: Accept multi OP_RETURN (Pablo Greco)
f955cb3d9c liquidtestnet: Add chainparams (Pablo Greco)
0fa20d006d CCustomParams: Move some defaults away from UpdateFromArgs (Pablo Greco)
e9df51121f Add text version of the fixed seeds for liquidv1 and liquidtestnet (Pablo Greco)

Pull request description:

  Currently using liquidtestnet requires a big config file, which is error-prone and uncomfortable for users, this MR adds support for just using `-chain=liquidtestnet`.

  There are a few things that need to be discussed/addressed

  1. Main port (currently set to 18891 because that's the one used originally, and the one that's configured in `liquidtestnet.com`)
  1. RPC and extra ports, I just chose some non-overlapping ports that are "close" to the ones in the other liquid/elements networks.
  1. Icon color, I just used something different than `liquidv1` and `elementsregtest`, suggestions accepted 😉
  1. `liquid-testnet.blockstream.com` is still using port 18892, it will be changed to 18891 soon.
  1. both seeds are just CNAME dns records at the moment, they should be changed to real seed nodes (no changes in code required, but important for review)

ACKs for top commit:
  delta1:
    ACK c6e074e
  wintercooled:
    ACK c6e074e25b
  apoelstra:
    utACK c6e074e25b

Tree-SHA512: 48c17b8b90ba5a33ae987935ffb368737167f6ca5ae772f6dd8c0c5e7efb39355d81e2677cd02d3e22984f2592fdd67caaf838003902b3c827f6ade01f18a040
2022-11-23 15:31:39 +00:00
Andrea Bonel
5d496b81f7 Add missing field 'signblock_challenge' back to getblock 2022-11-22 18:12:41 -03:00
Pablo Greco
58b5fa0dbf
Merge pull request #1186 from achow101/createfunded-explicit-value
Add include_explicit to walletcreatefundedpsbt
2022-11-21 17:15:58 -03:00
Andrew Chow
9dbf0b6f55 wallet, rpc: Add include_explicit to walletcreatefundedpsbt 2022-10-18 16:52:31 -04:00
Andrew Chow
a584133bd6 wallet: Add include_explicit to FillPSBT 2022-10-18 16:52:31 -04:00
Andrew Chow
462c873639 blindpsbt: Expose CreateBlind{Asset,Value}Proof
Make these two functions available to external callers.
CreateBlindValueProof is a wrapper around the static function to avoid
requiring callers to parse things into secp256k1 objects.
2022-10-18 16:52:31 -04:00
Pablo Greco
816585db1a
Merge pull request #1182 from jgriffiths/fix_blind_reissuance_amount_proof_output
rpc: decodepsbt: fix check for blind_reissuance_amount_proof output
2022-10-18 09:32:07 -03:00
Pablo Greco
6624455ec2 Merge branch 'master' into elements-22_0_2rc1 2022-10-16 10:05:35 -03:00
Pablo Greco
eca4cd9259
Merge pull request #1169 from andreabonel/fix_windows_elements_company
Fix company for Windows exes
2022-10-15 18:09:44 -03:00
Glenn Willen
6b4228e3a5 Preserve blinding key when parsing taproot address. 2022-10-11 15:30:04 -07:00
Pablo Greco
285a18dbe9
Merge pull request #1173 from andreabonel/fix_issue_1120
Fix location for default cookie path
2022-10-05 22:57:29 -03:00
Jon Griffiths
e2348dadf3
PSET: VerifyBlindValueProof: fail verification if the value or asset commitment is missing
It is arguable whether attempting a value proof without an asset
commitment should be treated as incomplete or incorrect blinding. Since
the asset commitment is required to produce the value proof in the first
place, failing to provide it in the source PSET and thus at this call
site is treated as an error.

This does not change the existing behaviour since a missing asset
or value commitment in this function would already cause it to fail.

Future work on the blinding iterface should likely return the blinding
state directly from the verify calls and remove the duplicated mapping of
blinding error codes to transaction blinding error codes, instead of the
verify functions returning just true/false.
2022-10-06 09:12:02 +13:00
Jon Griffiths
5895fb10bb
rpc: decodepsbt: fix check for blind_reissuance_amount_proof output 2022-10-05 23:38:54 +13:00
Andrea Bonel
86db1b70e9 Fix location for default cookie path 2022-09-27 18:56:20 -03:00
Andrew Poelstra
005a27cac7 wallet: account for issuances during coin selection
Prior to coin selection we need to indicate that the issuances will take
extra space, otherwise we may fail to select enough coins to cover our
fees, triggering the new "fee needed exceeds fees available" assertion.

(cherry picked from commit e5e3ec2700)
2022-09-26 14:11:31 -03:00
Andrew Poelstra
ce496535c4 wallet: extend fix to "dropped change is the last blinded output" case
(cherry picked from commit 79fd90f064)
2022-09-26 14:11:31 -03:00
Andrew Poelstra
4553496c44 wallet: don't clear out all the blinding data when dropping change
The Elements 22 blinding logic has an edge case where when we drop change,
leaving only a single blinded output, we recompute a bunch of blinding
data to handle the potential for us to have 0 inputs and 1 output to blind.
(BlindTransaction will fail in this case because it cannot make the
transaction balance with only one output to mess with.)

In this recomputation, we dropped more data than we meant to, causing us
to incorrectly blind an output.

(cherry picked from commit fac694be4c)
2022-09-26 14:11:31 -03:00
Andrew Poelstra
e5e3ec2700
wallet: account for issuances during coin selection
Prior to coin selection we need to indicate that the issuances will take
extra space, otherwise we may fail to select enough coins to cover our
fees, triggering the new "fee needed exceeds fees available" assertion.
2022-09-22 13:20:29 +00:00
Andrew Poelstra
79fd90f064
wallet: extend fix to "dropped change is the last blinded output" case 2022-09-20 21:17:47 +00:00
Andrew Poelstra
fac694be4c
wallet: don't clear out all the blinding data when dropping change
The Elements 22 blinding logic has an edge case where when we drop change,
leaving only a single blinded output, we recompute a bunch of blinding
data to handle the potential for us to have 0 inputs and 1 output to blind.
(BlindTransaction will fail in this case because it cannot make the
transaction balance with only one output to mess with.)

In this recomputation, we dropped more data than we meant to, causing us
to incorrectly blind an output.
2022-09-20 17:40:47 +00:00
Andrew Poelstra
23e91d0ef8
wallet: fix some fee calculation bugs
First, this reverts commit ca2d72ae8b to reinstate
an assertion that was added in Bitcoin #22686. It did not compile because our
`change_and_fee` variable is a map rather than number; I changed it to use
`map_change_and_fee.at(policyAsset)` to match the equivalent change 2 lines down
from a5d97b363b (merge of Bitcoin #22008).

Then fix the following bugs:

1. Change the new test in rpc_fundrawtransaction.py to bump the -maxtxfee value,
   which we'd otherwise exceed, failing the test and masking actual failures.
   (This was just caused by the extreme fee settings of the test combined with
   Elements' large transactions.)
2. Change the fee-output size estimation for `tx_noinputs_size` to be 46 rather
   than 44 bytes; we forgot that even null surjection/rangeproofs need a 0 byte
   when output witnesses are present. This mistake triggered the new assertion.
3. Correct the logic in which change outputs are sometimes dropped even when
   they are the only blinded output in a transaction with blinded inputs. This
   would cause the new test to fail with `bad-txn-inputs-ne-outputs`; I'm very
   surprised that no existing tests hit this.

   (I have an existing comment block in this code where I "promise" that I had
   a good reason for doing something mysterious related to blinding. I was not
   able to reverse-engineer my intention here, though I think it is related to
   this, but since I couldn't understand it I just left this block intact and
   worked around it.)
4. This then triggered the assertion again since the coin selection code
   assumes that sufficiently-small change will always be dropped. If we prevent
   this drop we will have under-funded the transaction.

   To fix this we add Yet Another Flag `may_need_blinded_dummy` in which we add
   extra weight to `tx_noinputs_size` in the case that we're doing a blinded tx
   but have no blind destinations. We turn this off after coin selection if it
   turns out that we don't have any blinded inputs, though ofc at that point
   much of the damage/inefficiency has already been done..
5. Fix some constants in other functional tests which assumed precise fee
   calculations; these precise values changed because of fixes (2) and (4).

There is one new FIXME, which is that the "dummy change" value will now be a
zero-valued OP_RETURN but we still put a full-size rangeproof and surjection
proof on it. There is some plausible privacy benefit to this but not much,
and wasting 5000+ bytes rather than the ~65 needed for an exact-value proof
is not worth it. We will fix this in the future when we overhaul the wallet
blinding logic.
2022-09-20 17:39:24 +00:00
Glenn Willen
2273079c45
elements: Fix build by removing newly-added assertion from upstream that doesn't make sense with assets 2022-09-20 17:38:44 +00:00
Andrew Chow
dfc3e891d7
wallet: Assert that enough was selected to cover the fees
When the fee is not subtracted from the outputs, the amount that has
been reserved for the fee (change_and_fee - change_amount) must be
enough to cover the fee that is needed. It would be a bug to not do so,
so use an assert to make this obvious if such a situation were to occur.

Github-Pull: bitcoin/bitcoin#22686
Rebased-From: d9262324e8
2022-09-20 17:38:44 +00:00
Andrea Bonel
88503bc4e7 Fix company for Windows exes 2022-09-09 17:04:51 +00:00
Pablo Greco
d0f391cfdb liquidtestnet: Add style for Elements-Qt 2022-09-09 07:06:18 -03:00
Pablo Greco
48ddfbf8d7 liquidtestnet: Add fixed seeds 2022-09-08 19:02:07 +00:00
Pablo Greco
3b34c8e927 liquidtestnet: Add seed nodes 2022-09-08 19:01:54 +00:00
Pablo Greco
0d1964766f liquidtestnet: Accept multi OP_RETURN 2022-09-08 19:01:39 +00:00
Pablo Greco
f955cb3d9c liquidtestnet: Add chainparams 2022-09-08 19:01:27 +00:00
Pablo Greco
0fa20d006d CCustomParams: Move some defaults away from UpdateFromArgs 2022-09-08 19:01:27 +00:00
Pablo Greco
ddeb7b99d8 Merge branch 'master' into elements-22-rc6 2022-09-07 14:09:17 +00:00
Byron Hambly
661c6c7094
feat: change getnewblockhex to take multiple commitments
Modifies the getnewblockhex json rpc call to accept an array of
commitments instead of a single commitment.

Backwards compatibility is maintained by first attempting to parse as a
string for a singular commitment.
2022-09-07 14:43:10 +02:00
Andrew Chow
2bf627e282 psbt: Fix check for missing asset and its proof 2022-09-06 15:57:21 -04:00
Andrew Chow
6e6a92209c psbt: Store m_asset_proof for PSBT_IN_ELEMENTS_ASSET_PROOF 2022-09-06 15:56:57 -04:00