Skip to content

Gas cost discrepancies when testing calls through a proxy #2503

Closed
@elenadimitrova

Description

@elenadimitrova

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (33dbaa5 2022-07-23T00:04:10.615195Z)

What command(s) is the bug in?

forge test --gas-report

Operating System

macOS (Apple Silicon)

Describe the bug

When comparing the gas cost test results between hardhat-gas-reporter and foundry they significantly differ for the following sample test cases:
a) ContractA.mint() calling external contract ContractB.mint() where ContractB is the implementation of a Minimal Proxy

foundry reports 68,530 gas
hardhat reports 105,796 gas

b) ContractB.mint() getting called on top of an implementation Proxy (where ContractB is the implementation set on Proxy)

foundry reports 68,992 gas
hardhat reports 93,040 gas

I would normally expect test case a) to be more expensive than test case b) as it is doing a cross contract call (even if in test case B the proxy does an extra read from storage to get implementation address).

Additionally (as this maybe related symptom), when measuring gas costs for calls routed through a proxy referencing an implementation contract, there are two sets of gas costs foundry reports, one for the Proxy itself and another for the implementation contract as seen in screenshot below

Screenshot 2022-07-27 at 20 47 32

However when a different proxy is used that does no local storage reads (e.g. a minimal proxy or the same as above but with immutable implementation instantiated in the proxy constructor) the Proxy gas cost table is no longer displayed and only implementation costs show.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Blocked

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions