Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions .github/workflows/core-contracts-storage-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,46 @@ jobs:
done
echo "matrix=$(cat contracts.txt | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT

- name: Check if contracts are new (no storage baseline)
id: check-new-contracts
working-directory: packages/contracts
run: |
if [ ! -f contracts.txt ] || [ -z "$(cat contracts.txt)" ]; then
echo "is_new_only=true" >> $GITHUB_OUTPUT
echo "new_contracts=[]" >> $GITHUB_OUTPUT
else
NEW_CONTRACTS="[]"
for CONTRACT in $(cat contracts.txt); do
# Extract contract name (second part after :)
CONTRACT_NAME=$(echo $CONTRACT | cut -d':' -f2 | xargs basename -a .sol)
# Check if storage baseline exists for this contract
BASELINE_FILE="storage-layouts/${CONTRACT_NAME}.json"
if [ -f "$BASELINE_FILE" ]; then
echo "$CONTRACT is not new, has baseline"
else
echo "$CONTRACT is NEW (no baseline), skipping storage check"
# Remove from contracts.txt (filter out)
grep -v "^$CONTRACT$" contracts.txt > contracts_filtered.txt || true
mv contracts_filtered.txt contracts.txt
Comment on lines +60 to +61

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use fixed-string filtering when removing matrix entries.

grep -v "^$CONTRACT$" treats $CONTRACT as regex. A path like src/dollar/core/Foo.sol:Foo contains regex-significant chars (e.g., .), so this can remove unintended lines and silently skip required checks.

Suggested patch
-                grep -v "^$CONTRACT$" contracts.txt > contracts_filtered.txt || true
+                grep -Fvx -- "$CONTRACT" contracts.txt > contracts_filtered.txt || true
                 mv contracts_filtered.txt contracts.txt

fi
done
if [ -z "$(cat contracts.txt)" ]; then
echo "is_new_only=true" >> $GITHUB_OUTPUT
echo "new_contracts=[]" >> $GITHUB_OUTPUT
else
echo "is_new_only=false" >> $GITHUB_OUTPUT
echo "matrix=$(cat contracts.txt | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
fi
fi

outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
matrix: ${{ steps.set-matrix.outputs.matrix || steps.check-new-contracts.outputs.matrix || '[]' }}
is_new_only: ${{ steps.check-new-contracts.outputs.is_new_only || 'false' }}

check_storage_layout:
needs: provide_contracts
runs-on: ubuntu-latest
if: ${{ needs.provide_contracts.outputs.matrix != '[]' && needs.provide_contracts.outputs.matrix != '' }}
if: ${{ needs.provide_contracts.outputs.matrix != '[]' && needs.provide_contracts.outputs.matrix != '' && needs.provide_contracts.outputs.is_new_only != 'true' }}

strategy:
matrix:
Expand Down
31 changes: 29 additions & 2 deletions .github/workflows/diamond-storage-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,40 @@ jobs:
done
echo "matrix=$(cat contracts.txt | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT

- name: Check if libraries are new (no storage baseline)
id: check-new-libraries
working-directory: packages/contracts
run: |
if [ ! -f contracts.txt ] || [ -z "$(cat contracts.txt)" ]; then
echo "is_new_only=true" >> $GITHUB_OUTPUT
else
for LIB in $(cat contracts.txt); do
LIB_NAME=$(echo $LIB | cut -d':' -f2 | xargs basename -a .sol)
BASELINE_FILE="storage-layouts/${LIB_NAME}.json"
if [ -f "$BASELINE_FILE" ]; then
echo "$LIB has baseline"
else
echo "$LIB is NEW (no baseline), skipping storage check"
grep -v "^$LIB$" contracts.txt > contracts_filtered.txt || true
mv contracts_filtered.txt contracts.txt
Comment on lines +59 to +60

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use fixed-string matching for library filtering as well.

Dynamic regex in grep -v "^$LIB$" can overmatch and drop non-target libraries from contracts.txt, which may skip checks that should run.

Suggested patch
-                grep -v "^$LIB$" contracts.txt > contracts_filtered.txt || true
+                grep -Fvx -- "$LIB" contracts.txt > contracts_filtered.txt || true
                 mv contracts_filtered.txt contracts.txt

fi
done
if [ -z "$(cat contracts.txt)" ]; then
echo "is_new_only=true" >> $GITHUB_OUTPUT
else
echo "is_new_only=false" >> $GITHUB_OUTPUT
echo "matrix=$(cat contracts.txt | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
fi
fi

outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
matrix: ${{ steps.set-matrix.outputs.matrix || steps.check-new-libraries.outputs.matrix || '[]' }}
is_new_only: ${{ steps.check-new-libraries.outputs.is_new_only || 'false' }}

check_storage_layout:
needs: provide_contracts
runs-on: ubuntu-latest
if: ${{ needs.provide_contracts.outputs.matrix != '[]' && needs.provide_contracts.outputs.matrix != '' }}
if: ${{ needs.provide_contracts.outputs.matrix != '[]' && needs.provide_contracts.outputs.matrix != '' && needs.provide_contracts.outputs.is_new_only != 'true' }}

strategy:
matrix:
Expand Down
Loading