foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.34k stars 1.77k forks source link

bug(`anvil`): `eth_estimateGas` `max_fee_per_gas` overrides the `block.basefee` when simulating a transaction #8516

Closed jakim929 closed 4 months ago

jakim929 commented 4 months ago

Component

Anvil

Have you ensured that all of these are up to date?

What version of Foundry are you on?

forge 0.2.0 (e903484 2024-07-19T00:18:41.070490000Z)

What command(s) is the bug in?

anvil

Operating System

macOS (Apple Silicon)

Describe the bug

Opened an issue since I'm not sure if this is intended behavior.

when calling eth_estimateGas, the max_fee_per_gas parameter included in the tx ends up overwriting the block.basefee. Is there a reason for this? This makes it harder to estimate gas for contracts that rely on the value of block.basefee (although I see it's not a common issue).

the FeeDetails is created based on the transaction params, then https://github.com/foundry-rs/foundry/blob/5af9d16ecb620192d4fe5ae61d33e429b7f5aff3/crates/anvil/src/eth/api.rs#L2344-L2350

used in this line to override the block's basefee. https://github.com/foundry-rs/foundry/blob/5af9d16ecb620192d4fe5ae61d33e429b7f5aff3/crates/anvil/src/eth/backend/mem/mod.rs#L1155-L1157

Given the spec here, I would expect that all that eth_estimateGas does is set the block gas limit if unspecified, not change anything about the block otherwise. Curious if this is intended behavior? Thanks in advance!

mattsse commented 4 months ago

I believe we can remove this

jakim929 commented 4 months ago

thanks for the quick response! opened a PR here https://github.com/foundry-rs/foundry/pull/8517