contracts/storage-snapshots/README.md
This directory contains storage layout snapshots for upgradeable contracts. These snapshots are used to detect unintended storage layout changes that could corrupt state during proxy upgrades.
When you intentionally modify the storage layout of a contract (e.g., adding new state variables), you must update the snapshot:
cd contracts
forge inspect DataHavenServiceManager storage --json > storage-snapshots/DataHavenServiceManager.storage.json
__GAP - This preserves upgrade safety| Contract | Gap Size | Gap Slot |
|---|---|---|
| DataHavenServiceManager | 46 | 105 |
# Check storage layout (CI script)
./scripts/check-storage-layout.sh
# Negative check (proves detector fails on broken layout)
./scripts/check-storage-layout-negative.sh
# Run upgrade simulation tests
forge test --match-contract StorageLayoutTest -vvv
# View human-readable layout
forge inspect DataHavenServiceManager storage --pretty
The snapshot comparison normalizes both files to avoid false positives:
astId: Changes with each compiler runcontract: Contains full file path.types section: Contains unstable AST IDs that cause false diffstype (e.g., t_contract(IGatewayV2)12345)This approach detects:
If you add struct-typed storage variables in the future, be aware that internal struct field changes may not be detected by the snapshot diff. This is because:
.types section (which contains struct field definitions) is dropped to avoid unstable AST IDsHowever, this does not break upgrades in the traditional sense. Struct field reordering or type changes within a struct would cause data misinterpretation (reading field A as field B), but the slot-level layout remains stable.
Mitigation: If adding struct storage, ensure the upgrade simulation tests (StorageLayoutTest) explicitly verify struct field values survive upgrades.
Current status: DataHavenServiceManager has no struct-typed storage variables, so this limitation does not apply.