Skip to content

Commit d68528c

Browse files
core/txpool: add sanity overflow check (#32544)
Adds a sanity check in the transaction pool Co-authored-by @rjl493456442
1 parent 586ac9b commit d68528c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

core/txpool/legacypool/list.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,22 @@ func (l *list) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Transa
323323
if tx.GasFeeCapIntCmp(thresholdFeeCap) < 0 || tx.GasTipCapIntCmp(thresholdTip) < 0 {
324324
return false, nil
325325
}
326-
// Old is being replaced, subtract old cost
327-
l.subTotalCost([]*types.Transaction{old})
328326
}
329327
// Add new tx cost to totalcost
330328
cost, overflow := uint256.FromBig(tx.Cost())
331329
if overflow {
332330
return false, nil
333331
}
334-
l.totalcost.Add(l.totalcost, cost)
332+
total, overflow := new(uint256.Int).AddOverflow(l.totalcost, cost)
333+
if overflow {
334+
return false, nil
335+
}
336+
l.totalcost = total
337+
338+
// Old is being replaced, subtract old cost
339+
if old != nil {
340+
l.subTotalCost([]*types.Transaction{old})
341+
}
335342

336343
// Otherwise overwrite the old transaction with the current one
337344
l.txs.Put(tx)

0 commit comments

Comments
 (0)