0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-06 14:19:59 -05:00
bitcoin-core/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
bdb.h
coincontrol.cpp
coincontrol.h
coinselection.cpp
coinselection.h
context.cpp
context.h
crypter.cpp
crypter.h
db.cpp
db.h
dump.cpp
dump.h
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
feebumper.h
fees.cpp
fees.h
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
load.h
receive.cpp [clang-tidy] Enable the misc-no-recursion check 2024-04-07 14:04:45 +01:00
receive.h
salvage.cpp
salvage.h
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
sqlite.cpp scripted-diff: Add IWYU pragma keep to bitcoin-config.h includes 2024-05-01 08:33:04 +02:00
sqlite.h
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.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
wallettool.cpp scripted-diff: Add IWYU pragma keep to bitcoin-config.h includes 2024-05-01 08:33:04 +02:00
wallettool.h
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