Skip to content

Commit 18fadba

Browse files
committed
Merge #863: Fix HasValidFee potential overflow
98e42a0 Fix HasValidFee potential overflow (Steven Roose) Pull request description: Dmitry pointed out this potential overflow. They can't really happen because of the `CheckTransaction` check on explicit amounts that happens earlier in the verification chain. But it's a good idea to add the check here as well so that a potential relaxing of other rules cannot accidentally introduce an overflow risk. Tree-SHA512: 0c6abb7719d4cf84596da5cb31e700bee53d26d6ffc6da0ba8f1300b3357ca3d29fb46e2754d182e64cb5794fd58fa1efed5ebf9c1bd58d08e2fb7841725ca66
2 parents a19c972 + 98e42a0 commit 18fadba

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/confidential_validation.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ bool HasValidFee(const CTransaction& tx) {
3333
if (fee == 0 || !MoneyRange(fee))
3434
return false;
3535
totalFee[tx.vout[i].nAsset.GetAsset()] += fee;
36+
if (!MoneyRange(totalFee)) {
37+
return false;
38+
}
3639
}
3740
}
38-
return MoneyRange(totalFee);
41+
return true;
3942
}
4043

4144
CAmountMap GetFeeMap(const CTransaction& tx) {

src/consensus/tx_verify.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoins
306306
return state.DoS(100, false, REJECT_INVALID, "bad-txns-in-ne-out", false, "value in != value out");
307307
}
308308
fee_map += GetFeeMap(tx);
309+
if (!MoneyRange(fee_map)) {
310+
return state.DoS(100, false, REJECT_INVALID, "bad-block-total-fee-outofrange");
311+
}
309312
} else {
310313
const CAmount value_out = tx.GetValueOutMap()[CAsset()];
311314
if (nValueIn < value_out) {

0 commit comments

Comments
 (0)