psbt: analyzepsbt reports an error when outputs exceed inputs #36569

pull Ravan002 wants to merge 1 commits into bitcoin:master from Ravan002:analyzepsbt-outputs-exceed-inputs changing 2 files +13 −0
  1. Ravan002 commented at 8:03 PM on October 18, 2026: none

    AnalyzePSBT computes fee = in_amt - out_amt once every input amount is known and returns it as is. A PSBT whose outputs are worth more than its inputs therefore gets a negative fee and a next role of updater, even though no wallet can ever sign it into a valid transaction. The function already returns PSBT is not valid. ... for bad input values, unspendable outputs and an out-of-range output total.

    An output total above the input total is reported the same way:

    before: {"fee": -1.00000000, "next": "updater", ...}
    after:  {"next": "creator", "error": "PSBT is not valid. Output amount larger than input amount"}
    

    The functional test builds a PSBT that spends a 1 BTC output into a 2 BTC output and checks the error and the creator role. Without the change the assertion on next fails. rpc_psbt.py, wallet_send.py, wallet_multisig_descriptor_psbt.py, rpc_openrpc.py and the psbt unit tests pass.

  2. psbt: analyzepsbt reports an error when outputs exceed inputs
    When every input amount is known, AnalyzePSBT computed fee as
    in_amt - out_amt and returned it even if it was negative, together with
    a negative fee rate and a next role of updater or signer. Treat a PSBT
    that pays out more than it spends as invalid, like the other amount
    checks in the same function.
    8262933013
  3. fanquake added the label PSBT on Oct 19, 2026
  4. DrahtBot commented at 7:16 AM on October 19, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK Yudis-bit, Husteem

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

  5. Yudis-bit commented at 10:44 AM on October 19, 2026: none

    Tested ACK 8262933013 on Windows. Would it be worth also adding a unit test in psbt_tests?

  6. Husteem commented at 9:28 AM on October 20, 2026: none

    tACK 8262933

    Verified the bug on master (where an overspending PSBT returned a negative fee, empty error, and signer role). rpc_psbt.py passes on this branch.

    The guard in AnalyzePSBT is a good fix. Also agree with @Yudis-bit - adding a companion unit test in psbt_tests.cpp would be worthwhile for regression coverage here.

  7. winterrdog commented at 9:37 AM on October 20, 2026: contributor

    @Husteem @Yudis-bit

    Sorry for bikeshedding. I am trying to understand what the motive for a unit test is here.. What special thing would the unit test assert that the current functional test does not 🤔 ?

  8. Husteem commented at 1:09 PM on October 20, 2026: none

    Hi @winterrdog. It's totally fine to enquire!

    While I'd say it's a nit, obviously, the thought was mainly direct coverage on the C++ struct (has_sane_fee = false and fee staying unset) without spinning up a test node.

    That said, since rpc_psbt.py already asserts both error and next == 'creator' across the RPC boundary, you're pretty right that it covers the regression well enough.


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: 2026-10-28 15:51 UTC

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