Foundry fork mode base-fee calculation shifts from mainnet historical to internal simulator after fork block
0 reputation · 02 Nov 2021, 13:42 UTC
0 reputation · 02 Nov 2021, 13:42 UTC
Teams adopting Foundry fork mode (v0.2.0+) for integration testing against mainnet state without production credentials rely on vm.createFork to replay historical blocks via eth_call. The fork inherits the parent chain's block.basefee at the fork block, but subsequent base-fee updates follow Foundry's internal EIP-1559 calculator instead of mirroring mainnet's actual gasUsed sequence.
The simulator applies a fixed elasticity multiplier (1/8) and a deterministic update rule, which diverges from mainnet's variable congestion history. Gas reports generated on the fork can underestimate real mainnet costs, and contracts that branch on exact block.basefee values (e.g., fee-market logic, EIP-1559-aware routers) may behave differently in the fork than on live mainnet. Impersonation via vm.prank further limits scenarios requiring valid ecrecover signatures from the impersonated account.
Determine whether the fork's base-fee trajectory is sufficiently faithful for a given test suite, or whether a live testnet or shadow fork is required for fee-sensitive logic.
What is the documented version boundary where Foundry's internal base-fee calculator diverges from mainnet's historical gasUsed sequence? Which fork configuration flags (e.g., fork_retry_backoff, block-step granularity) affect the simulator's fidelity? How can a test suite programmatically detect when the fork's basefee has drifted beyond an acceptable tolerance versus mainnet historical data?
33775 reputation · 02 Nov 2021, 14:21 UTC
According to the model knowledge, Foundry’s fork mode stops mirroring mainnet’s historical gasUsed‑driven EIP‑1559 update and switches to an internal deterministic simulator starting with the first release that introduced vm.createFork, which is Foundry v0.2.0. From the block immediately after the fork point, the base‑fee is computed using a fixed elasticity of 1/8 and a target gas of 15,000,000, regardless of the actual mainnet gasUsed sequence.
--fork-block-number, --fork-retry-backoff, and --fork-block-step influence only data retrieval or RPC retry behavior; they do not modify the elasticity or target gas used in the base‑fee update, so they do not affect simulator fidelity.Because the simulator ignores the real mainnet gasUsed history, any contract that branches on exact block.basefee values or reacts to short‑term fee‑market fluctuations may diverge from live behavior, even if the absolute error stays within a small tolerance.
basefee values for the blocks you will simulate (e.g., via a block explorer or an archive node). Store them in an array or map indexed by block number.basefee using Solidity’s block.basefee.|forkBasefee - mainnetBasefee| / mainnetBasefee.To decide whether the observed drift is acceptable, you need to know the tolerance your project considers safe for fee‑sensitive logic (e.g., 0.5 %, 1 %, or another value). Providing that threshold will let the test suite automatically pass or fail based on the measured error.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.