Skip to content

Commit 9fef23d

Browse files
fix: storage layout compatibility (#7078)
Co-authored-by: Cursor Agent <[email protected]>
1 parent b634235 commit 9fef23d

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

.github/workflows/storage-analysis.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ name: Check Storage Layout Changes
22

33
on:
44
pull_request:
5-
branches: [main]
5+
branches:
6+
- '*'
67
paths:
78
- 'solidity/**'
89
workflow_dispatch:
@@ -53,13 +54,30 @@ jobs:
5354
env:
5455
BASE_REF: ${{ github.event.inputs.base || github.event.pull_request.base.sha }}
5556
run: |
57+
# Fetch the base reference
5658
git fetch origin $BASE_REF
57-
git checkout $BASE_REF -- solidity/contracts
59+
# Check if BASE_REF is a commit SHA (40 hex characters) or a branch name
60+
if [[ "$BASE_REF" =~ ^[0-9a-f]{40}$ ]]; then
61+
# For commit SHAs, checkout directly without origin/ prefix
62+
git checkout $BASE_REF -- solidity/contracts
63+
else
64+
# For branch names, use origin/ prefix
65+
git checkout origin/$BASE_REF -- solidity/contracts
66+
fi
5867
5968
# Run the command on the target branch
6069
- name: Run command on target branch
6170
run: yarn workspace @hyperlane-xyz/core storage base-storage
6271

6372
# Compare outputs
64-
- name: Compare outputs
65-
run: diff --unified solidity/base-storage solidity/HEAD-storage
73+
- name: Compare outputs (fail on removals only)
74+
run: |
75+
DIFF_OUTPUT=$(diff --unified solidity/base-storage solidity/HEAD-storage || true)
76+
echo "$DIFF_OUTPUT"
77+
# Fail only if there are removal lines in diff hunks (lines starting with '-' but not '---')
78+
if echo "$DIFF_OUTPUT" | grep -E '^-([^-])' >/dev/null; then
79+
echo "Detected storage removals in diff. Failing job."
80+
exit 1
81+
else
82+
echo "No storage removals detected."
83+
fi

solidity/storage.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,22 @@ do
1515
continue
1616
fi
1717

18-
contract=$(basename "$file" .sol)
19-
echo "Generating storage layout of $contract"
20-
forge inspect "$contract" storage > "$OUTPUT_PATH/$contract.md"
18+
# Skip files that don't end in .sol
19+
if [[ ! "$file" =~ \.sol$ ]]; then
20+
continue
21+
fi
22+
23+
# Extract all contract names from the file
24+
contracts=$(grep -o '^contract [A-Za-z0-9_][A-Za-z0-9_]*' "$file" | sed 's/^contract //')
25+
26+
if [ -z "$contracts" ]; then
27+
continue
28+
fi
29+
30+
# Process each contract found in the file
31+
for contract in $contracts; do
32+
echo "Generating storage layout of $contract"
33+
echo "slot offset label" > "$OUTPUT_PATH/$contract-layout.tsv"
34+
forge inspect "$contract" storage --json | jq -r '.storage .[] | "\(.slot)\t\(.offset)\t\(.label)"' >> "$OUTPUT_PATH/$contract-layout.tsv"
35+
done
2136
done

0 commit comments

Comments
 (0)