Skip to content

Commit d55cd8a

Browse files
committed
Update gas estimation logic to account for the max gas limit introduced by EIP-7825
1 parent 234d623 commit d55cd8a

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

services/requester/requester.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,36 @@ func (e *EVM) EstimateGas(
345345
passingGasLimit = uint64(*txArgs.Gas)
346346
}
347347

348+
// Cap the maximum gas allowance according to EIP-7825 if the estimation targets Osaka
349+
if passingGasLimit > gethParams.MaxTxGas {
350+
latestBlockHeight, err := e.blocks.LatestEVMHeight()
351+
if err != nil {
352+
return 0, err
353+
}
354+
latestBlock, err := e.blocks.GetByHeight(latestBlockHeight)
355+
if err != nil {
356+
return 0, err
357+
}
358+
blockNumber, blockTime := new(big.Int).SetUint64(latestBlock.Height), latestBlock.Timestamp
359+
emulatorConfig := emulator.NewConfig(
360+
emulator.WithChainID(e.config.EVMNetworkID),
361+
emulator.WithBlockNumber(blockNumber),
362+
emulator.WithBlockTime(blockTime),
363+
)
364+
365+
if blockOverrides != nil {
366+
if blockOverrides.Number != nil {
367+
blockNumber = blockOverrides.Number.ToInt()
368+
}
369+
if blockOverrides.Time != nil {
370+
blockTime = uint64(*blockOverrides.Time)
371+
}
372+
}
373+
if emulatorConfig.ChainConfig.IsOsaka(blockNumber, blockTime) {
374+
passingGasLimit = gethParams.MaxTxGas
375+
}
376+
}
377+
348378
// We first execute the transaction at the highest allowable gas limit,
349379
// since if this fails we can return the error immediately.
350380
result, err := dryRun(passingGasLimit)

tests/web3js/estimate_gas_overrides_test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,23 @@ it('should apply block overrides on eth_estimateGas', async () => {
101101
assert.equal(response.status, 200)
102102
assert.isDefined(response.body)
103103
assert.equal(web3.utils.hexToNumber(response.body.result), 273693n)
104+
105+
// test that gas estimation still allows gas limits above the configured
106+
// EIP-7825 value
107+
txArgs = {
108+
from: conf.eoa.address,
109+
to: contractAddress,
110+
gas: '0x10F4240', // this is equal to 17,777,216, which is greater than 16,777,216
111+
gasPrice: web3.utils.toHex(conf.minGasPrice),
112+
value: '0x0',
113+
data: testFuncSelector,
114+
}
115+
116+
response = await helpers.callRPCMethod(
117+
'eth_estimateGas',
118+
[txArgs, 'latest', null, null]
119+
)
120+
assert.equal(response.status, 200)
121+
assert.isDefined(response.body)
122+
assert.equal(web3.utils.hexToNumber(response.body.result), 21473n)
104123
})

0 commit comments

Comments
 (0)