Skip to content

Commit 59405c4

Browse files
eth/gasestimator: check ErrGasLimitTooHigh conditions (#32348)
This PR makes 2 changes to how [EIP-7825](#31824) behaves. When `eth_estimateGas` or `eth_createAccessList` is called without any gas limit in the payload, geth will choose the block's gas limit or the `RPCGasCap`, which can be larger than the `maxTxGas`. When this happens for `estimateGas`, the gas estimation just errors out and ends, when it should continue doing binary search to find the lowest possible gas limit. This PR will: - Add a check to see if `hi` is larger than `maxTxGas` and cap it to `maxTxGas` if it's larger. And add a special case handling for gas estimation execute when it errs with `ErrGasLimitTooHigh` --------- Co-authored-by: Gary Rong <[email protected]>
1 parent e9dca3b commit 59405c4

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

eth/gasestimator/gasestimator.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ func Estimate(ctx context.Context, call *core.Message, opts *Options, gasCap uin
6262
if call.GasLimit >= params.TxGas {
6363
hi = call.GasLimit
6464
}
65+
66+
// Cap the maximum gas allowance according to EIP-7825 if the estimation targets Osaka
67+
if hi > params.MaxTxGas {
68+
blockNumber, blockTime := opts.Header.Number, opts.Header.Time
69+
if opts.BlockOverrides != nil {
70+
if opts.BlockOverrides.Number != nil {
71+
blockNumber = opts.BlockOverrides.Number.ToInt()
72+
}
73+
if opts.BlockOverrides.Time != nil {
74+
blockTime = uint64(*opts.BlockOverrides.Time)
75+
}
76+
}
77+
if opts.Config.IsOsaka(blockNumber, blockTime) {
78+
hi = params.MaxTxGas
79+
}
80+
}
81+
6582
// Normalize the max fee per gas the call is willing to spend.
6683
var feeCap *big.Int
6784
if call.GasFeeCap != nil {
@@ -209,6 +226,9 @@ func execute(ctx context.Context, call *core.Message, opts *Options, gasLimit ui
209226
if errors.Is(err, core.ErrIntrinsicGas) {
210227
return true, nil, nil // Special case, raise gas limit
211228
}
229+
if errors.Is(err, core.ErrGasLimitTooHigh) {
230+
return true, nil, nil // Special case, lower gas limit
231+
}
212232
return true, nil, err // Bail out
213233
}
214234
return result.Failed(), result, nil

internal/ethapi/override/override_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ import (
3131

3232
type precompileContract struct{}
3333

34+
func (p *precompileContract) Name() string {
35+
panic("implement me")
36+
}
37+
3438
func (p *precompileContract) RequiredGas(input []byte) uint64 { return 0 }
3539

3640
func (p *precompileContract) Run(input []byte) ([]byte, error) { return nil, nil }

0 commit comments

Comments
 (0)