Merge bitcoin/bitcoin#36931: test: cover negative output after positive in CheckTransaction
What changed, and why it matters
This commit only adds a new test case to Bitcoin Core's test data. It does not change any production code. The test verifies that a transaction containing a positive output followed by a negative output is correctly rejected as invalid. The accompanying pull request discussion explains this test 'kills' a hypothetical code mutation that could, if it actually existed in the software, lead to an inflation bug. But the mutation is not present in the code being committed; the commit merely improves test coverage.
No action required. This is a test-only addition that improves coverage. Reviewers may consider whether the new test vector is also exercised by the unit tests that consume tx_invalid.json.
Security signals we found
Adds regression test for negative transaction output following a positive output
PR description references a hypothetical mutation that could lead to an inflation bug if present in consensus code
No change to src/consensus/tx_check.cpp or any production code path
Evidence from the diff
The diff adds one test vector to src/test/data/tx_invalid.json. The vector is a serialized transaction with two outputs: the first has nValue=1 (positive), the second has nValue=-1 (0xffffffffffffffff, interpreted as negative in signed int64). It is tagged ‘BADTX’, meaning CheckTransaction must reject it. The PR description references a mutation-testing result showing that if CheckTransaction accumulated nValueOut before checking negativity (instead of checking each output individually), a negative output after a positive one could bypass the per-output negative check and only be caught later by MoneyRange or GetValueOut. This commit ensures that scenario is covered by the existing test suite, but it does not alter consensus code.
Changed components
src/test/data/tx_invalid.jsonCheckTransaction test coverageInspect captured patch +4 / −0
### src/test/data/tx_invalid.json
@@ -39,6 +39,10 @@
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "HASH160 0x14 0xae609aca8061d77c5e111f6bb62501a6bbe2bfdb EQUAL"]],
"01000000010001000000000000000000000000000000000000000000000000000000000000000000006d4830450220063222cbb128731fc09de0d7323746539166544d6c1df84d867ccea84bcc8903022100bf568e8552844de664cd41648a031554327aa8844af34b4f27397c65b92c04de0123210243ec37dee0e2e053a9c976f43147e79bc7d9dc606ea51010af1ac80db6b069e1acffffffff01ffffffffffffffff015100000000", "BADTX"],
+["Negative output after positive output"],
+[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "HASH160 0x14 0xae609aca8061d77c5e111f6bb62501a6bbe2bfdb EQUAL"]],
+"01000000010001000000000000000000000000000000000000000000000000000000000000000000006d4830450220063222cbb128731fc09de0d7323746539166544d6c1df84d867ccea84bcc8903022100bf568e8552844de664cd41648a031554327aa8844af34b4f27397c65b92c04de0123210243ec37dee0e2e053a9c976f43147e79bc7d9dc606ea51010af1ac80db6b069e1acffffffff0201000000000000000151ffffffffffffffff015100000000", "BADTX"],
+
["MAX_MONEY + 1 output"],
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "HASH160 0x14 0x32afac281462b822adbec5094b8d4d337dd5bd6a EQUAL"]],
"01000000010001000000000000000000000000000000000000000000000000000000000000000000006e493046022100e1eadba00d9296c743cb6ecc703fd9ddc9b3cd12906176a226ae4c18d6b00796022100a71aef7d2874deff681ba6080f1b278bac7bb99c61b08a85f4311970ffe7f63f012321030c0588dc44d92bdcbf8e72093466766fdc265ead8db64517b0c542275b70fffbacffffffff010140075af0750700015100000000", "BADTX"],Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.