mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-13 12:33:42 +02:00
Fix HasValidFee potential overflow
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.
This commit is contained in:
parent
0551932844
commit
11d6f808e0
2 changed files with 7 additions and 1 deletions
|
|
@ -33,9 +33,12 @@ bool HasValidFee(const CTransaction& tx) {
|
|||
if (fee == 0 || !MoneyRange(fee))
|
||||
return false;
|
||||
totalFee[tx.vout[i].nAsset.GetAsset()] += fee;
|
||||
if (!MoneyRange(totalFee)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return MoneyRange(totalFee);
|
||||
return true;
|
||||
}
|
||||
|
||||
CAmountMap GetFeeMap(const CTransaction& tx) {
|
||||
|
|
|
|||
|
|
@ -306,6 +306,9 @@ bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoins
|
|||
return state.DoS(100, false, REJECT_INVALID, "bad-txns-in-ne-out", false, "value in != value out");
|
||||
}
|
||||
fee_map += GetFeeMap(tx);
|
||||
if (!MoneyRange(fee_map)) {
|
||||
return state.DoS(100, false, REJECT_INVALID, "bad-block-total-fee-outofrange");
|
||||
}
|
||||
} else {
|
||||
const CAmount value_out = tx.GetValueOutMap()[CAsset()];
|
||||
if (nValueIn < value_out) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue