consensus/doc: explain `GetValueOut()` precondition
What changed, and why it matters
This commit only adds a code comment explaining why a particular function call is safe. It does not change any program logic, fix a bug, or alter validation behavior. There is no security issue here.
No action required. This is a documentation-only change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds an inline comment in src/consensus/tx_verify.cpp documenting that Consensus::CheckTxInputs’s call to tx.GetValueOut() is guaranteed not to throw because output-range checks are performed earlier in both mempool acceptance (via MemPoolAccept::PreChecks -> CheckTransaction) and block connection (via Chainstate::ConnectBlock -> CheckBlock -> CheckTransaction). The executable code is unchanged.
Changed components
src/consensus/tx_verify.cppInspect captured patch +4 / −0
diff --git a/src/consensus/tx_verify.cpp b/src/consensus/tx_verify.cpp
index ec612a55..4efed70f 100644
--- a/src/consensus/tx_verify.cpp
+++ b/src/consensus/tx_verify.cpp
@@ -188,6 +188,10 @@ bool Consensus::CheckTxInputs(const CTransaction& tx, TxValidationState& state,
}
}
+ // `tx.GetValueOut()` won't throw in validation paths because output-range checks run first
+ // (`bad-txns-vout-negative`, `bad-txns-vout-toolarge`, `bad-txns-txouttotal-toolarge`):
+ // * `MemPoolAccept::PreChecks`: `CheckTransaction()` is called before this method;
+ // * `Chainstate::ConnectBlock`: `CheckTransaction()` is called via `CheckBlock()` before this method.
const CAmount value_out = tx.GetValueOut();
if (nValueIn < value_out) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-in-belowout",
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.