From d68528cadb62141a423fc8bf66f65e4269ba5d90 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Wed, 10 Sep 2025 15:33:15 +0200 Subject: [PATCH] core/txpool: add sanity overflow check (#32544) Adds a sanity check in the transaction pool Co-authored-by @rjl493456442 --- core/txpool/legacypool/list.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/txpool/legacypool/list.go b/core/txpool/legacypool/list.go index 507c0b429a..0c9f13c62f 100644 --- a/core/txpool/legacypool/list.go +++ b/core/txpool/legacypool/list.go @@ -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)