Skip to content

Optionally read Forge's .gas-snapshot format in --snapshot-check #8357

Description

@anaPerezGhiglia

Describe the feature

Summary

npx hardhat test solidity --snapshot-check can't validate a .gas-snapshot produced by forge snapshot, even though the gas values are identical, it fails with HHE803: Invalid format in snapshot file. Optionally reading Forge's format would smooth Foundry → Hardhat migrations.

Background

Hardhat reads/writes its whole-suite snapshot at the hardcoded path <root>/.gas-snapshot — the same filename Forge uses — but the parser hard-requires a # separator where Forge writes ::

The separator is the only structural difference; the (gas: N) / (runs:, μ:, ~:) details are byte-identical, and the gas values are computed identically. So a Forge-format line falls through to throw … INVALID_SNAPSHOT_FORMAT.

Motivation

Projects migrating Foundry → Hardhat may already commit a .gas-snapshot; today they must regenerate it under Hardhat before --snapshot-check works, with no signal that the gas numbers actually agree. (It would also let repos keep both toolchains share a baseline, though that's a secondary consideration.)

Proposed enhancement

Accept both separators on the read path — relax the parse regexes to allow either : or #. Hardhat keeps writing its own # format. No new config.

Note: accepting : at read time should cover most basic projects, but may not be sufficient on its own for full parity. The two tools seem to differ in how they name entries when the same ContractName appears in multiple files — Hardhat appears to use a fully-qualified name in that case, while Forge files use the bare contract name. Flagging for awareness.

Search terms

gas snapshots, snapshot, --snapshot-check

Metadata

Metadata

Assignees

Labels

No labels
No labels

Fields

No fields configured for Feature.

Projects

Status
Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions