core/txpool: add sanity overflow check (#32544)

Adds a sanity check in the transaction pool

Co-authored-by @rjl493456442
This commit is contained in:
Marius van der Wijden 2025-09-10 15:33:15 +02:00 committed by GitHub
parent 586ac9b334
commit d68528cadb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -323,15 +323,22 @@ func (l *list) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Transa
if tx.GasFeeCapIntCmp(thresholdFeeCap) < 0 || tx.GasTipCapIntCmp(thresholdTip) < 0 {
return false, nil
}
// Old is being replaced, subtract old cost
l.subTotalCost([]*types.Transaction{old})
}
// Add new tx cost to totalcost
cost, overflow := uint256.FromBig(tx.Cost())
if overflow {
return false, nil
}
l.totalcost.Add(l.totalcost, cost)
total, overflow := new(uint256.Int).AddOverflow(l.totalcost, cost)
if overflow {
return false, nil
}
l.totalcost = total
// Old is being replaced, subtract old cost
if old != nil {
l.subTotalCost([]*types.Transaction{old})
}
// Otherwise overwrite the old transaction with the current one
l.txs.Put(tx)