RPC: Internal bug in walletprocesspsbt when non_witness_utxo is not provided and a witness signature is invalid #30077

issue spacebear21 openend this issue on May 10, 2024
  1. spacebear21 commented at 3:15 am on May 10, 2024: none

    Is there an existing issue for this?

    • I have searched the existing issues

    Current behaviour

    Calling walletprocesspsbt on a signed PSBT that only includes a witness_utxo (no non_witness_utxo) with an invalid signature produces an internal bug (CHECK_NONFATAL):

    0❯ bitcoin-cli walletprocesspsbt "cHNidP8BAJoCAAAAAq3g8bgaDs84DkYQ6urdGcuevx4mTtc5ImnEuw/RKiZ2AAAAAAD9////O+qpBnMQ44R69kLMIMPrviyL4ml4zSC1iA8Ec7ux/8YBAAAAAP3///8ClnsOAAAAAAAWABQ1vvbTc5DqIMQ7qVHMKjCDEWY5m+DhDQAAAAAAFgAUWIMWf8n1WEfQh3v8yh+J7jCs/a577QIAAAEBH9C6DQAAAAAAFgAUsPZp8CKeWQmHjCFZ2elo6XlxIAEAAQEflqMOAAAAAAAWABRNIMqZK+4V6Fbf76G+CxrSoMafyQEIawJHMEQCIG7dSys9CpWsVOhrVH4aPc4s2hWr0gkYAwOZDWMczlweAiAj7av+wVmv37x4BNEWygqRxeP/GUblTMYzFePeJa5x0QEhA4Uz0JSTf/5CkbMHXfV7C5q8HjcjKGH6frUU57sDbHYDAAAA"
    1error code: -1
    2error message:
    3Internal bug detected: FinalizeAndExtractPSBT(psbtx, mtx)
    4wallet/rpc/spend.cpp:1618 (operator())
    5Bitcoin Core v27.99.0-24572cf76816
    6Please report this issue here: https://github.com/bitcoin/bitcoin/issues
    

    Expected behaviour

    This scenario should be handled gracefully either with an explanatory error message or by ignoring those bad signatures (the latter happens when non_witness_utxo is provided). There are many reasons why a previously added signature could be invalid, e.g. if new inputs were added, outputs modified, etc.

    A concrete example is a Payjoin transaction, where the receiver contributes inputs of their own after the sender has signed an initial PSBT. That’s the scenario I was testing when I stumbled onto this (see discussion here).

    Steps to reproduce

    I produced a minimal repro by modifying the rpc_psbt.py functional test: https://github.com/grizznaut/bitcoin/commit/0ddee75a59d33ceed11f5f8a5e59bbc46054676b). After signing the initial PSBT, it substitutes the output address and attempts to call walletprocesspsbt again, but fails:

     02024-05-10T02:42:01.177000Z TestFramework (ERROR): JSONRPC error
     1Traceback (most recent call last):
     2  File "/Users/jaad/bin/bitcoin/test/functional/test_framework/test_framework.py", line 132, in main
     3    self.run_test()
     4  File "/Users/jaad/bin/bitcoin/test/functional/rpc_psbt.py", line 601, in run_test                                                                                                                                                               self.test_utxo_conversion()                                                                                                                                                                                                                 File "/Users/jaad/bin/bitcoin/test/functional/rpc_psbt.py", line 118, in test_utxo_conversion
     5    signed_psbt = offline_node.walletprocesspsbt(signed_psbt_new.to_base64())
     6                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     7  File "/Users/jaad/bin/bitcoin/test/functional/test_framework/coverage.py", line 50, in __call__
     8    return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
     9                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                     File "/Users/jaad/bin/bitcoin/test/functional/test_framework/authproxy.py", line 129, in __call__                                                                                                                                               raise JSONRPCException(response['error'], status)
    10test_framework.authproxy.JSONRPCException: Internal bug detected: FinalizeAndExtractPSBT(psbtx, mtx)
    11wallet/rpc/spend.cpp:1618 (operator())
    

    Relevant log output

    No response

    How did you obtain Bitcoin Core

    Compiled from source

    What version of Bitcoin Core are you using?

    master@98dd4e7

    Operating system and version

    MacOS Ventura 13.6

    Machine specifications

    No response

  2. willcl-ark added the label Wallet on May 15, 2024
  3. maflcko added the label Bug on May 28, 2024
  4. maflcko added the label RPC/REST/ZMQ on May 28, 2024
  5. maflcko added this to the milestone 28.0 on May 28, 2024
  6. willcl-ark referenced this in commit 8ec3bb3add on Jun 28, 2024
  7. willcl-ark referenced this in commit 26cadb8c0e on Jul 1, 2024
  8. willcl-ark referenced this in commit 7101965765 on Jul 1, 2024
  9. willcl-ark referenced this in commit 39cea21ec5 on Jul 2, 2024
  10. achow101 closed this on Jul 16, 2024


spacebear21

Labels
Bug Wallet RPC/REST/ZMQ

Milestone
28.0


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-09-28 22:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me