Skip to content

Add a --tolerance flag to Solidity test gas snapshots #8382

Description

@schaable

Hardhat's Solidity test gas snapshots (hardhat test --snapshot / --snapshot-check) currently use exact comparisons. Any gas change, even +1, fails the check and requires re-running --snapshot.

Foundry offers a --tolerance <PERCENT> option on forge snapshot --check. It allows each test's gas usage to drift by up to the specified percentage without failing the check (the snapshot isn't updated automatically and the diff is ignored). The option applies to both standard and fuzz tests and was introduced as a DX improvement: small gas changes are common, and overly strict checks often result in snapshot updates being accepted without much review foundry-rs/foundry#3102.

Hardhat already runs fuzz tests with a fixed default seed, so gas usage is deterministic across runs. This isn't about reducing fuzz-related noise, but about avoiding churn from small intentional or cumulative gas changes. The downside is that a tolerance threshold can allow gas regressions to accumulate unnoticed against an outdated baseline.

The goal of this issue is to gauge interest. If you'd find a tolerance option useful for gas snapshots, please upvote the issue and, if possible, share your use case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions