foundry
foundry copied to clipboard
Overestimated gas prices for cheap chains
Component
Forge
Describe the bug
Mentioned in https://github.com/foundry-rs/foundry/issues/6503#issuecomment-1837648597 and https://github.com/foundry-rs/foundry/issues/4903#issuecomment-1620446076.
Currently, due to ethers internals being oriented on Mainnet, gas prices for scripts are often over-estimated to be around 3 gwei when the actually needed gas price might be less than 1 gwei.
It can be reproduced by dry-running any script on any L2 via forge script <SCRIPT_CONTRACT> --rpc-url <RPC_OF_L2>
For Arbitrum the output will include
Estimated gas price: 3.2 gwei
And the estimation of required funds for execution will be calculated considering gas price being 3.2 as well, which is much higher than is actually needed and can result in script failing due to sender not having enough funds.
This is reproducible on Optimism, Base, Arbitrum and any other cheap chain I believe. Currently common workaround is to add --legacy
flag to the command which helps avoiding priority fee calculation.
I am not sure what's the best way to fix this as it is possible that we might break some scenarios as for some L2s this overestimation helped avoiding situations when script sender does not have enough funds to cover additional L2 fees. For example, the actuall gas price on Base is around 0.000000315
, but usually most of tx cost is coming from L1 fees which are not included in the estimation currently