consensus/doc: explain unreachable `bad-txns-fee-outofrange` check
What changed, and why it matters
This commit only adds explanatory comments to a piece of Bitcoin Core's transaction-validation code. It does not change any behavior, fix a bug, or alter consensus rules. The comment documents why a particular error check is mathematically unreachable under the already-enforced preconditions, while leaving the check in place for safety.
No action required. This is a documentation-only change with no security or functional effect.
Security signals we found
No strong security signals were identified.
Evidence from the diff
In src/consensus/tx_verify.cpp, a five-line comment is inserted before the if (!MoneyRange(txfee_aux)) check that returns bad-txns-fee-outofrange. The comment proves that, because value_out is already MoneyRange, nValueIn is already MoneyRange, and nValueIn < value_out was handled earlier, the fee txfee_aux = nValueIn - value_out must already satisfy 0 <= txfee_aux <= MAX_MONEY. Therefore the MoneyRange(txfee_aux) check cannot fail. The executable code is unchanged.
Changed components
src/consensus/tx_verify.cppInspect captured patch +5 / −0
diff --git a/src/consensus/tx_verify.cpp b/src/consensus/tx_verify.cpp
index 00022a33..ec612a55 100644
--- a/src/consensus/tx_verify.cpp
+++ b/src/consensus/tx_verify.cpp
@@ -197,6 +197,11 @@ bool Consensus::CheckTxInputs(const CTransaction& tx, TxValidationState& state,
// Tally transaction fees
const CAmount txfee_aux = nValueIn - value_out;
if (!MoneyRange(txfee_aux)) {
+ // Unreachable, given the following preconditions:
+ // * `value_out` comes from `tx.GetValueOut()`, which throws unless `MoneyRange(value_out)` and asserts `MoneyRange(nValueOut)` on return.
+ // * `MoneyRange(nValueIn)` was enforced in the input loop.
+ // * `nValueIn < value_out` was handled above, so `nValueIn >= value_out` here (and `txfee_aux >= 0`).
+ // Therefore `0 <= txfee_aux = nValueIn - value_out <= nValueIn <= MAX_MONEY`.
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-fee-outofrange");
}
Why this scored 15/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.