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.
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 onforge 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.