From 74b386b03500b9a593e6f3e95c2cda82f935640d Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Thu, 21 Aug 2025 09:39:18 +0200 Subject: [PATCH] core/types: adding overflow checks on SetFromBig Better check in case this is used as library. Not using MustFromBig as we don't have control over how this is being used. Signed-off-by: Csaba Kiraly --- core/types/transaction.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/core/types/transaction.go b/core/types/transaction.go index 9cb17773b1..be8e90364e 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -37,7 +37,7 @@ var ( ErrInvalidTxType = errors.New("transaction type not valid in this context") ErrTxTypeNotSupported = errors.New("transaction type not supported") ErrGasFeeCapTooLow = errors.New("fee cap less than base fee") - ErrGasFeeCapOverflow = errors.New("fee cap overflow, too large for uint256") + ErrUint256Overflow = errors.New("bigint overflow, too large for uint256") errShortTypedTx = errors.New("typed transaction too short") errInvalidYParity = errors.New("'yParity' field must be 0 or 1") errVYParityMismatch = errors.New("'v' and 'yParity' fields do not match") @@ -360,7 +360,9 @@ func (tx *Transaction) EffectiveGasTip(baseFee *big.Int) (*big.Int, error) { dst := new(uint256.Int) base := new(uint256.Int) if baseFee != nil { - base.SetFromBig(baseFee) + if base.SetFromBig(baseFee) { + return nil, ErrUint256Overflow + } } err := tx.calcEffectiveGasTip(dst, base) return dst.ToBig(), err @@ -370,13 +372,15 @@ func (tx *Transaction) EffectiveGasTip(baseFee *big.Int) (*big.Int, error) { // saves the result to dst. func (tx *Transaction) calcEffectiveGasTip(dst *uint256.Int, baseFee *uint256.Int) error { if baseFee == nil { - dst.SetFromBig(tx.inner.gasTipCap()) + if dst.SetFromBig(tx.inner.gasTipCap()) { + return ErrUint256Overflow + } return nil } var err error if dst.SetFromBig(tx.inner.gasFeeCap()) { - return ErrGasFeeCapOverflow + return ErrUint256Overflow } if dst.Cmp(baseFee) < 0 { err = ErrGasFeeCapTooLow @@ -384,7 +388,9 @@ func (tx *Transaction) calcEffectiveGasTip(dst *uint256.Int, baseFee *uint256.In dst.Sub(dst, baseFee) gasTipCap := new(uint256.Int) - gasTipCap.SetFromBig(tx.inner.gasTipCap()) + if gasTipCap.SetFromBig(tx.inner.gasTipCap()) { + return ErrUint256Overflow + } if gasTipCap.Cmp(dst) < 0 { dst.Set(gasTipCap) }