foundry-rs / foundry-rs/foundry

feat(`cheatcodes`): adding an L1 data fee estimation method similar to `vm.lastCallGas`

Open
#9,514 2 comments 0 reactions 0 assignees View on GitHub
A-cheatcodes T-feature
Dominant language
Rust
Stars
10.6k
Forks
2.6k
Avg merge
18h 20m
Merged PRs (30d)
510

Description

### Component

Forge

### Describe the feature you would like

Currently, Foundry’s `vm.lastCallGas()` provides developers with the amount of gas used in the last call from the callee’s perspective.

This works well for L1 or pure L2 execution gas, but does not incorporate the L1 data fee that certain L2 environments impose when posting call data to their underlying L1 for data availability and finality.

As a result, when testing complex cross-chain calls, developers must manually compute or approximate the L1 data fee portion from external data sources or heuristics.

The problem is that in many L2 ecosystems (e.g., OP Stack rollups, Arbitrum Orbit chains, zkSync Elastic, Linea), a portion of the transaction’s total cost is determined by how much data must be posted back to L1. This L1 data fee isn’t reflected in the raw L2 execution gas usage that `vm.lastCallGas()` reports.

Ideally, it would be great to have a built-in Foundry feature that:

1. Identifies the chain model type (OP-like, Arbitrum-like, etc.) from the current fork configuration, or allows specifying it.
2. Retrieves relevant parameters (like L1 `gasPrice`, `gasPerL1Byte`, overhead constants, etc.) from known on-chain contracts or a standardized mapping.
3. Calculates the approximate L1 data fee based on the transaction’s input size and the chain’s known formula.

Having a standard cheatcode, say `vm.lastCallL1DataFee()` or an extended structure returned by `vm.lastCallGas()` that includes an L1 fee estimate, would simplify this process.

In essence, this feature would extend Foundry’s goal of providing realistic, in-depth EVM testing to also cover a crucial part of the L2 cost model: the L1 data fee.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.