🔥
🛠️
Foundry Storage Upgrade Seatbelt
- Protect your Smart Contract Proxy from storage collisions upon upgrading, by running this action in a CI on each of your Pull Requests!
How it works
Everytime somebody opens a Pull Request, the action expects Foundry forge
to generate the storage layout of the Smart Contract you want to check, generating a storage layout to a temporary file (named storage_layout.json
by default).
Once generated, the action will fetch the comparative storage layout stored as an artifact from previous runs; parse & compare them, storing the results in the action's outputs as shell and as markdown.
Getting started
Automatically generate & compare to the previous storage layout on every PR
Add a workflow (.github/workflows/foundry-storage-check.yml
):
name: Check storage layout
on:
push:
branches:
- main
pull_request:
# Optionally configure to run only for changes in specific files. For example:
# paths:
# - src/**
# - test/**
# - foundry.toml
# - remappings.txt
# - .github/workflows/foundry-storage-check.yml
jobs:
check_storage_layout:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly
# Add any step generating a storage layout to a temporary file named storage_layout.json
# For example:
- name: Generate storage layout
run: forge inspect contracts/compound/Morpho.sol:Morpho storage-layout | tee storage_layout.json # <- this file name should be unique in your repository!
- name: Check storage layout
uses: Rubilmax/[email protected]
ℹ️ An error will appear at first run!
🔴 Error: No workflow run found with an artifact named "main.storage_layout.json"
As the action is expecting a comparative file stored on the base branch and cannot find it (because the action never ran on the target branch and thus has never uploaded any storage layout report)
Options
report
{string}
This should correspond to the path of a file where the output of forge's gas report has been logged. Only necessary when generating multiple gas reports on the same repository.
Defaults to: gasreport.ansi
base
{string}
The gas diff reference branch name, used to fetch the previous gas report to compare the freshly generated gas report to.
Defaults to: ${{ github.base_ref || github.ref_name }}
head
{string}
The gas diff target branch name, used to upload the freshly generated gas report.
Defaults to: ${{ github.head_ref || github.ref_name }}
token
{string}
The github token allowing the action to upload and download gas reports generated by foundry. You should not need to customize this, as the action already has access to the default Github Action token.
Defaults to: ${{ github.token }}
This repository is maintained independently from Foundry and may not work as expected with all versions of forge
.