bitcoin/src/wallet
Ava Chow 4ff42762fd
Merge bitcoin/bitcoin#28336: rpc: parse legacy pubkeys consistently with specific error messages
98570fe29b test: add coverage for parsing cryptographically invalid pubkeys (Sebastian Falbesoner)
c740b154d1 rpc: use `HexToPubKey` helper for all legacy pubkey-parsing RPCs (Sebastian Falbesoner)
100e8a75bf rpc: check and throw specific pubkey parsing errors in `HexToPubKey` (Sebastian Falbesoner)

Pull request description:

  Parsing legacy public keys can fail for three reasons (in this order):
  - pubkey is not in hex
  - pubkey has an invalid length (not 33 or 65 bytes for compressed/uncompressed, respectively)
  - pubkey is crytographically invalid, i.e. is not on curve (`CPubKey.IsFullyValid()` check)

  Many RPCs currently perform these checks manually with different error messages, even though we already have a `HexToPubKey` helper. This PR puts all three checks in this helper (the length check was done on the call-sites before), adds specific error messages for each case, and consequently uses it for all RPCs that parse legacy pubkeys. This leads to deduplicated code and also to more consistent and detailed error messages for the user.

  Affected RPC calls are `createmultisig`, `addmultisigaddress`, `importpubkey`, `importmulti`, `fundrawtransaction`, `walletcreatefundedpsbt`, `send` and `sendall`.

  Note that the error code (-5 a.k.a. `RPC_INVALID_ADDRESS_OR_KEY`) doesn't change in any of the causes, so the changes are not breaking RPC API compatibility. Only the messages are more specific.

  The last commits adds test coverage for the cryptographically invalid (not-on-curve) pubkey case which wasn't exercised before.

ACKs for top commit:
  stratospher:
    tested ACK 98570fe.
  davidgumberg:
    ACK 98570fe29b
  Eunovo:
    Tested ACK 98570fe29b
  achow101:
    ACK 98570fe29b

Tree-SHA512: cfa474176e95b5b18f3a9da28fdd9e87195cd58994c1331198f2840925fff322fd323a6371feab74a1b32e4b9ea58a6dc732fa751b4cdd45402c1029af609ece
2024-05-08 17:52:58 -04:00
..
rpc Merge bitcoin/bitcoin#28336: rpc: parse legacy pubkeys consistently with specific error messages 2024-05-08 17:52:58 -04:00
test scripted-diff: Add IWYU pragma keep to bitcoin-config.h includes 2024-05-01 08:33:04 +02:00
bdb.cpp wallet: bdb batch 'ErasePrefix', do not create txn internally 2024-02-12 16:05:15 -03:00
bdb.h wallet: bdb: include bdb header from our implementation files only 2023-07-07 14:14:20 +00:00
coincontrol.cpp wallet: Explicitly preserve scriptSig and scriptWitness in CreateTransaction 2023-12-08 17:12:19 -05:00
coincontrol.h wallet: Explicitly preserve scriptSig and scriptWitness in CreateTransaction 2023-12-08 17:12:19 -05:00
coinselection.cpp opt: Skip over barren combinations of tiny UTXOs 2024-02-09 11:03:18 +01:00
coinselection.h coinselection: Track whether CG completed 2024-02-09 10:50:10 +01:00
context.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
context.h interfaces: Add schedulerMockForward method so mockscheduler RPC can work across processes 2023-10-20 10:30:16 -04:00
crypter.cpp refactor: Remove unused C-style casts 2023-07-24 15:32:00 +02:00
crypter.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
db.cpp refactor: Fix bugprone-string-constructor warning 2023-10-30 14:59:17 +01:00
db.h wallet: remove unused 'accept_no_keys' arg from decryption process 2024-02-03 12:56:43 -03:00
dump.cpp wallettool: Don't create CWallet when dumping DB 2023-12-19 16:54:06 -05:00
dump.h wallettool: Don't create CWallet when dumping DB 2023-12-19 16:54:06 -05:00
external_signer_scriptpubkeyman.cpp wallet: return and display signer error 2024-04-16 17:47:43 +02:00
external_signer_scriptpubkeyman.h wallet: return and display signer error 2024-04-16 17:47:43 +02:00
feebumper.cpp test: wallet, fix change position out of range error 2023-12-12 15:20:38 -03:00
feebumper.h rpc: bumpfee, improve doc for 'reduce_output' arg 2023-09-26 20:17:02 -03:00
fees.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
fees.h Add src/wallet/* code to wallet:: namespace 2022-01-06 22:14:16 -05:00
init.cpp scripted-diff: Add IWYU pragma keep to bitcoin-config.h includes 2024-05-01 08:33:04 +02:00
interfaces.cpp Merge bitcoin/bitcoin#24313: Improve display address handling for external signer 2024-04-23 17:20:54 -04:00
load.cpp interfaces: Add schedulerMockForward method so mockscheduler RPC can work across processes 2023-10-20 10:30:16 -04:00
load.h interfaces: Add schedulerMockForward method so mockscheduler RPC can work across processes 2023-10-20 10:30:16 -04:00
receive.cpp [clang-tidy] Enable the misc-no-recursion check 2024-04-07 14:04:45 +01:00
receive.h wallet: Add wallet/types.h for simple public enum and struct types 2023-04-11 15:52:25 -04:00
salvage.cpp tidy: modernize-use-emplace 2023-10-12 11:27:19 +02:00
salvage.h refactor: Move fs.* to util/fs.* 2023-03-23 12:55:18 +01:00
scriptpubkeyman.cpp [clang-tidy] Enable the misc-no-recursion check 2024-04-07 14:04:45 +01:00
scriptpubkeyman.h wallet: return and display signer error 2024-04-16 17:47:43 +02:00
spend.cpp refactor: Avoid copying util::Result values 2024-04-25 16:08:24 -04:00
spend.h refactor: pass CRecipient to FundTransaction 2024-01-19 15:04:56 +01:00
sqlite.cpp scripted-diff: Add IWYU pragma keep to bitcoin-config.h includes 2024-05-01 08:33:04 +02:00
sqlite.h sqlite: Ensure that only one SQLiteBatch is writing to db at a time 2024-02-06 12:24:36 -05:00
transaction.cpp scripted-diff: wallet: s/TxStateConflicted/TxStateBlockConflicted 2024-03-14 17:38:39 -04:00
transaction.h wallet: track mempool conflicts 2024-03-20 15:05:34 -04:00
types.h wallet: add AddressPurpose enum to replace string values 2023-04-11 15:52:25 -04:00
wallet.cpp scripted-diff: Add IWYU pragma keep to bitcoin-config.h includes 2024-05-01 08:33:04 +02:00
wallet.h wallet: return and display signer error 2024-04-16 17:47:43 +02:00
walletdb.cpp scripted-diff: Add IWYU pragma keep to bitcoin-config.h includes 2024-05-01 08:33:04 +02:00
walletdb.h wallet: db, introduce 'RunWithinTxn()' helper function 2024-02-12 16:05:14 -03:00
wallettool.cpp scripted-diff: Add IWYU pragma keep to bitcoin-config.h includes 2024-05-01 08:33:04 +02:00
wallettool.h Add src/wallet/* code to wallet:: namespace 2022-01-06 22:14:16 -05:00
walletutil.cpp wallet, descspkm: Refactor wallet descriptor generation to standalone func 2024-03-20 16:15:43 -04:00
walletutil.h wallet, descspkm: Refactor wallet descriptor generation to standalone func 2024-03-20 16:15:43 -04:00