@@ -122,6 +122,11 @@ func calcBaseFeeFeynman(config *params.ChainConfig, parent *types.Header, overhe
122
122
baseFee := new (big.Int ).Set (baseFeeEIP1559 )
123
123
baseFee .Add (baseFee , overhead )
124
124
125
+ // Apply maximum base fee bound to the final result (including overhead)
126
+ if baseFee .Cmp (big .NewInt (MaximumL2BaseFee )) > 0 {
127
+ baseFee = big .NewInt (MaximumL2BaseFee )
128
+ }
129
+
125
130
return baseFee
126
131
}
127
132
@@ -159,9 +164,6 @@ func calcBaseFeeEIP1559(config *params.ChainConfig, parent *types.Header) *big.I
159
164
return num .Add (parentBaseFeeEIP1559 , common .Big1 )
160
165
}
161
166
baseFee := num .Add (parentBaseFeeEIP1559 , num )
162
- if baseFee .Cmp (big .NewInt (MaximumL2BaseFee )) > 0 {
163
- baseFee = big .NewInt (MaximumL2BaseFee )
164
- }
165
167
return baseFee
166
168
} else {
167
169
// 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
179
181
}
180
182
}
181
183
182
- func extractBaseFeeEIP1559 (config * params.ChainConfig , baseFee * big.Int ) * big.Int {
184
+ func extractBaseFeeEIP1559 (_ * params.ChainConfig , baseFee * big.Int ) * big.Int {
183
185
_ , overhead := ReadL2BaseFeeCoefficients ()
186
+
184
187
// In Feynman base fee calculation, we reuse the contract's baseFeeOverhead slot as the proving base fee.
185
- return new (big.Int ).Sub (baseFee , overhead )
188
+ result := new (big.Int ).Sub (baseFee , overhead )
189
+
190
+ // Add underflow protection: return max(0, baseFee - overhead)
191
+ //
192
+ // Potential underflow scenarios:
193
+ // - Contract overhead updates: when overhead is updated via contract,
194
+ // it might become larger than current base fee
195
+ if result .Sign () < 0 {
196
+ return big .NewInt (0 )
197
+ }
198
+ return result
186
199
}
187
200
188
201
// MinBaseFee calculates the minimum L2 base fee based on the current coefficients.
0 commit comments