Repository navigation
Reject psbts whose outputs exceed their inputs - #1041
Conversation
cb6b252 to
d063daa
Compare
d063daa to
3952d1d
Compare
|
ACK and reviewed 3952d1d |
PROWLERx15
left a comment
There was a problem hiding this comment.
tACK ad09655a
Tested this locally on the emulator and verified that it behaves as expected.
In addition to the default scenario provided via negative-fee scenario on testqrs.com, I also tested the PR across different wallet script types. To do this, I used Keith's btc-datagen repository to generate malformed PSBTs locally with some code changes.
I constructed the test transactions using random outputs, tested them, and confirmed that the psbt parser correctly intercepted the malformed transaction for the following wallet types:
| Wallet Type | Input | Output | Fees |
|---|---|---|---|
| P2WPKH (Single-Sig Native Segwit) | 300,000 sats | 2,727,106 sats | -2,427,106 sats |
| P2TR (Single-Sig Taproot) | 300,000 sats | 2,463,137 sats | -2,163,137 sats |
| P2WSH (2-of-3 Multisig Native Segwit) | 300,000 sats | 393,246 sats | -93,246 sats |
|
re-ACK 9124a29 |
embit computes the fee as inputs minus outputs and never looks at the sign of the result, so a psbt that spends more than it funds parses cleanly and reaches the review flow quoting a negative fee. Raise PSBTNegativeFeeError as soon as the fee is known and route it to its own warning. Malformed rather than hostile: no honest coordinator builds one and the network would refuse to relay it, so it gets a plain warning, not the attack framing. A zero fee is still accepted.
The error's docstring argued about a lying coordinator's motives and why the error exists for the user. Like the other PSBTVerificationError subclasses, it now just states the problem and that it is not treated as an attack. The one part of the reasoning that matters, that both totals are the coordinator's own claims, moves to the check that raises it.
_verify_input_amounts() now checks every input's amount before the outputs are parsed, so the input total is no longer just the coordinator's claim.
9124a29 to
9994a04
Compare
|
re-ACK 9994a04 |
|
Regarding proposed embit pr152 I have tested seedsigner as of Nov 1 (last merge pr1047), using pr152 atop embit 0.8.2, instead of embit 0.8.0. All tests for this pr at testqrs dot com still behave exactly as expected. |
Description
Problem or Issue being addressed
PSBTParser.fee_amountis embit'spsbt.fee(), which is just inputs minus outputsNothing looks at the sign of that result. A psbt whose outputs spend more than its inputs bring in therefore parses cleanly and walks into the review flow quoting a negative fee on the overview and math screens.
No honest coordinator builds such a transaction and the network would refuse to relay it, so the exposure is misleading arithmetic on screen rather than funds at risk. It still belongs behind a purposeful refusal rather than a nonsensical fee display.
Found by @knorrium in #1032 (comment)
Solution
PSBTNegativeFeeError, aPSBTVerificationErrorsubclass raised at the end of_parse_outputsas soon as the fee is known. Framed as a malformed transaction rather than an attack.PSBTNegativeFeeView, aWarningScreentitled "Transaction Problem" that discards the psbt to the main menu, routed fromPSBTOverviewViewalongside the otherPSBTVerificationErrorsubclasses.Screenshots
This pull request is categorized as a:
Checklist
I ran
pytestlocallyI included screenshots of any new or modified screens
I added or updated tests
I tested this PR hands-on on the following platform(s):
Tested with the negative-fee scenario on testqrs.com, added in kdmukAI-bot/btc-datagen#1.
I have reviewed these notes: