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
Describe the feature
Summary
npx hardhat test solidity --snapshot-checkcan't validate a.gas-snapshotproduced byforge snapshot, even though the gas values are identical, it fails withHHE803: 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 tothrow … INVALID_SNAPSHOT_FORMAT.Motivation
Projects migrating Foundry → Hardhat may already commit a
.gas-snapshot; today they must regenerate it under Hardhat before--snapshot-checkworks, 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.Search terms
gas snapshots, snapshot, --snapshot-check