primitives: test individual output value > MAX_MONEY
What changed, and why it matters
This commit only adds a new unit test. It does not change any production code. The test checks that the library rejects Bitcoin transactions containing an output worth more than the maximum allowed money (MAX_MONEY + 1 satoshi) when decoding transaction bytes. It is a defensive test borrowed from Bitcoin Core's test data, confirming an existing safety check works.
No action required. This is a test-only change. If reviewing the broader PR or branch, verify that the production decoder already enforces the MAX_MONEY limit and that this test passes.
Security signals we found
Adds a regression test for MAX_MONEY output validation
Uses a known Bitcoin Core invalid transaction test vector
No production code changes
Evidence from the diff
The diff adds a single test in primitives/src/transaction.rs named reject_output_value_greater_than_max_money. It uses a hex-encoded transaction from Bitcoin Core’s tx_invalid.json (the ‘MAX_MONEY + 1 output’ vector), feeds it through Transaction::decoder(), and asserts that decoding fails. No library logic is modified; the patch only increases test coverage for an already-implemented validation rule.
Changed components
primitives/src/transaction.rs testsInspect captured patch +14 / −0
diff --git a/primitives/src/transaction.rs b/primitives/src/transaction.rs
index dab0be30..6ca2c9f4 100644
--- a/primitives/src/transaction.rs
+++ b/primitives/src/transaction.rs
@@ -2548,4 +2548,18 @@ mod tests {
let total: u64 = tx.outputs.iter().map(|o| o.amount.to_sat()).sum();
assert_eq!(total, Amount::MAX_MONEY.to_sat());
}
+
+ #[test]
+ #[cfg(all(feature = "alloc", feature = "hex"))]
+ fn reject_output_value_greater_than_max_money() {
+ // Test vector taken from Bitcoin Core tx_invalid.json
+ // https://github.com/bitcoin/bitcoin/blob/master/src/test/data/tx_invalid.json#L44
+ // "MAX_MONEY + 1 output"
+ let tx_bytes = hex!("01000000010001000000000000000000000000000000000000000000000000000000000000000000006e493046022100e1eadba00d9296c743cb6ecc703fd9ddc9b3cd12906176a226ae4c18d6b00796022100a71aef7d2874deff681ba6080f1b278bac7bb99c61b08a85f4311970ffe7f63f012321030c0588dc44d92bdcbf8e72093466766fdc265ead8db64517b0c542275b70fffbacffffffff010140075af0750700015100000000");
+
+ let mut decoder = Transaction::decoder();
+ let mut slice = tx_bytes.as_slice();
+ let result = decoder.push_bytes(&mut slice);
+ assert!(result.is_err(), "output value > MAX_MONEY should be rejected during decoding");
+ }
}
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.