Skip to content

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

Open
@St0rmBr3w

Description

@St0rmBr3w

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions