diff --git a/consensus/misc/eip1559.go b/consensus/misc/eip1559.go index c20b627aa212..2ac839f7ec54 100644 --- a/consensus/misc/eip1559.go +++ b/consensus/misc/eip1559.go @@ -122,6 +122,11 @@ func calcBaseFeeFeynman(config *params.ChainConfig, parent *types.Header, overhe baseFee := new(big.Int).Set(baseFeeEIP1559) baseFee.Add(baseFee, overhead) + // Apply maximum base fee bound to the final result (including overhead) + if baseFee.Cmp(big.NewInt(MaximumL2BaseFee)) > 0 { + baseFee = big.NewInt(MaximumL2BaseFee) + } + return baseFee } @@ -159,9 +164,6 @@ func calcBaseFeeEIP1559(config *params.ChainConfig, parent *types.Header) *big.I return num.Add(parentBaseFeeEIP1559, common.Big1) } baseFee := num.Add(parentBaseFeeEIP1559, num) - if baseFee.Cmp(big.NewInt(MaximumL2BaseFee)) > 0 { - baseFee = big.NewInt(MaximumL2BaseFee) - } return baseFee } else { // Otherwise if the parent block used less gas than its target, the baseFee should decrease. @@ -179,10 +181,21 @@ func calcBaseFeeEIP1559(config *params.ChainConfig, parent *types.Header) *big.I } } -func extractBaseFeeEIP1559(config *params.ChainConfig, baseFee *big.Int) *big.Int { +func extractBaseFeeEIP1559(_ *params.ChainConfig, baseFee *big.Int) *big.Int { _, overhead := ReadL2BaseFeeCoefficients() + // In Feynman base fee calculation, we reuse the contract's baseFeeOverhead slot as the proving base fee. - return new(big.Int).Sub(baseFee, overhead) + result := new(big.Int).Sub(baseFee, overhead) + + // Add underflow protection: return max(0, baseFee - overhead) + // + // Potential underflow scenarios: + // - Contract overhead updates: when overhead is updated via contract, + // it might become larger than current base fee + if result.Sign() < 0 { + return big.NewInt(0) + } + return result } // MinBaseFee calculates the minimum L2 base fee based on the current coefficients. diff --git a/params/version.go b/params/version.go index 9df687409283..cafb96053c50 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 5 // Major version component of the current release VersionMinor = 8 // Minor version component of the current release - VersionPatch = 71 // Patch version component of the current release + VersionPatch = 72 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string )