Merge bitcoin/bitcoin#36686: test: cover cumulative input value range in CheckTxInput tests.
What changed, and why it matters
This commit only adds new test cases to Bitcoin Core's test suite. It does not change any production consensus, validation, or networking code. The tests verify that an existing check in the transaction validation logic correctly rejects transactions with out-of-range input values, including cases with multiple inputs. There is no security vulnerability being fixed here—only test coverage is being improved.
No security action required. This is a routine test-coverage improvement. Reviewers may verify the new test cases correctly exercise the intended consensus paths.
Security signals we found
No production code changes
Test-only commit
Adds regression tests for existing consensus input-value range check
No vulnerability patch present
Evidence from the diff
The change modifies src/test/transaction_tests.cpp to extend the checktxinputs_invalid_transactions_test helper to accept multiple input values and adds test cases covering: (1) a single input exceeding MAX_MONEY, (2) multiple valid inputs whose cumulative sum exceeds MAX_MONEY, and (3) a negative input value. The production code in src/consensus/tx_verify.cpp is unchanged. The PR description references a mutation-testing ‘mutant’ that would survive without these tests, but the actual consensus logic remains the safe disjunctive check: if (!MoneyRange(coin.out.nValue) || !MoneyRange(nValueIn)).
Changed components
src/test/transaction_tests.cppInspect captured patch +24 / −9
### src/test/transaction_tests.cpp
@@ -39,6 +39,7 @@
#include <functional>
#include <map>
#include <string>
+#include <vector>
#include <boost/test/unit_test.hpp>
@@ -1143,14 +1144,16 @@ BOOST_AUTO_TEST_CASE(getlegacysigopcount_inaccurate_test)
BOOST_AUTO_TEST_CASE(checktxinputs_invalid_transactions_test)
{
- auto check_invalid{[](CAmount input_value, CAmount output_value, bool coinbase, int spend_height, TxValidationResult expected_result, std::string_view expected_reason) {
+ auto check_invalid{[](const std::vector<CAmount>& input_values, CAmount output_value, bool coinbase, int spend_height, TxValidationResult expected_result, std::string_view expected_reason) {
CCoinsViewCache inputs{&CoinsViewEmpty::Get()};
-
- const COutPoint prevout{Txid::FromUint256(uint256::ONE), 0};
- inputs.AddCoin(prevout, Coin{{input_value, CScript() << OP_TRUE}, /*nHeightIn=*/1, coinbase}, /*possible_overwrite=*/false);
-
CMutableTransaction mtx;
- mtx.vin.emplace_back(prevout);
+ const auto txid{Txid::FromUint256(uint256::ONE)};
+ uint32_t output_index{0};
+ for (const CAmount input_value : input_values) {
+ const COutPoint prevout{txid, output_index++};
+ inputs.AddCoin(prevout, Coin{{input_value, CScript() << OP_TRUE}, /*nHeightIn=*/1, coinbase}, /*possible_overwrite=*/false);
+ mtx.vin.emplace_back(prevout);
+ }
mtx.vout.emplace_back(output_value, CScript() << OP_TRUE);
TxValidationState state;
@@ -1161,19 +1164,31 @@ BOOST_AUTO_TEST_CASE(checktxinputs_invalid_transactions_test)
BOOST_CHECK_EQUAL(state.GetRejectReason(), expected_reason);
}};
- check_invalid(/*input_value=*/MAX_MONEY + 1,
+ check_invalid(/*input_values=*/{MAX_MONEY + 1},
/*output_value=*/0,
/*coinbase=*/false,
/*spend_height=*/2,
TxValidationResult::TX_CONSENSUS, /*expected_reason=*/"bad-txns-inputvalues-outofrange");
- check_invalid(/*input_value=*/1 * COIN,
+ check_invalid(/*input_values=*/{MAX_MONEY, 1},
+ /*output_value=*/1,
+ /*coinbase=*/false,
+ /*spend_height=*/2,
+ TxValidationResult::TX_CONSENSUS, /*expected_reason=*/"bad-txns-inputvalues-outofrange");
+
+ check_invalid(/*input_values=*/{2 * COIN, -1 * COIN},
+ /*output_value=*/1,
+ /*coinbase=*/false,
+ /*spend_height=*/2,
+ TxValidationResult::TX_CONSENSUS, /*expected_reason=*/"bad-txns-inputvalues-outofrange");
+
+ check_invalid(/*input_values=*/{1 * COIN},
/*output_value=*/2 * COIN,
/*coinbase=*/false,
/*spend_height=*/2,
TxValidationResult::TX_CONSENSUS, /*expected_reason=*/"bad-txns-in-belowout");
- check_invalid(/*input_value=*/1 * COIN,
+ check_invalid(/*input_values=*/{1 * COIN},
/*output_value=*/0,
/*coinbase=*/true,
/*spend_height=*/COINBASE_MATURITY,Why this scored 14/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.