Skip to content

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

Open
Ravan002 wants to merge 1 commit into
bitcoin:masterfrom
Ravan002:analyzepsbt-outputs-exceed-inputs
Open

Ravan002 wants to merge 1 commit into
bitcoin:masterfrom
Ravan002:analyzepsbt-outputs-exceed-inputs

Conversation

@Ravan002

@Ravan002 Ravan002 commented Oct 18, 2026 •

Copy link
Copy Markdown

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.

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.
@fanquake fanquake added the PSBT label Oct 19, 2026
@DrahtBot

DrahtBot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

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

External sites

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 <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36990 (test: replace hard-coded RPC error codes by l0rinc)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@Yudis-bit

Copy link
Copy Markdown

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

@Husteem

Husteem commented Oct 20, 2026

Copy link
Copy Markdown

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.

@winterrdog

Copy link
Copy Markdown
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 🤔 ?

@Husteem

Husteem commented Oct 20, 2026

Copy link
Copy Markdown

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.

self.log.info("PSBT whose outputs exceed its inputs should have error message and Creator as next")
overspend_utxo = self.create_outpoints(self.nodes[0], outputs=[{self.nodes[0].getnewaddress(): 1}])[0]
self.generate(self.nodes[0], 1)
overspend = self.nodes[0].createpsbt([overspend_utxo], [{self.nodes[0].getnewaddress(): 2}], psbt_version=0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

psbt_version=0 doesn't seem required - v2 is the default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants