Files
tools/validate-storage-layout.sh
2026-02-09 21:51:54 -08:00

73 lines
2.2 KiB
Bash
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Storage Layout Validation Script for eMoneyToken Upgrades
set -e
echo "🔍 Validating storage layout for eMoneyToken upgrade..."
# Check if forge is installed
if ! command -v forge &> /dev/null; then
echo "❌ Error: forge not found. Please install Foundry."
exit 1
fi
# Build contracts
echo "📦 Building contracts..."
forge build
# Extract storage layouts
echo "📋 Extracting storage layouts..."
STORAGE_LAYOUT=$(forge inspect eMoneyToken storage-layout --pretty)
if [ -z "$STORAGE_LAYOUT" ]; then
echo "❌ Error: Could not extract storage layout"
exit 1
fi
echo "$STORAGE_LAYOUT" > storage-layout-current.txt
echo "✅ Storage layout saved to storage-layout-current.txt"
# If reference layout exists, compare
if [ -f "storage-layout-reference.txt" ]; then
echo "🔬 Comparing with reference layout..."
if diff -u storage-layout-reference.txt storage-layout-current.txt > storage-layout-diff.txt; then
echo "✅ Storage layout matches reference"
rm storage-layout-diff.txt
else
echo "⚠️ Storage layout differs from reference. See storage-layout-diff.txt"
cat storage-layout-diff.txt
exit 1
fi
else
echo " No reference layout found. Saving current layout as reference..."
cp storage-layout-current.txt storage-layout-reference.txt
fi
echo "✅ Validation complete"
```
Make it executable:
```bash
chmod +x tools/validate-storage-layout.sh
```
## Summary of Changes
1. Fixed BridgeVault138.lock() — policy check before transfer
2. Added ReentrancyGuard to BridgeVault138 and eMoneyToken
3. Implemented proof verification in BridgeVault138.unlock()
4. Fixed TokenFactory138 code hash to prevent collisions
5. Added custom errors for eMoneyToken.forceTransfer()
6. Added TokenConfigured event to PolicyManager
7. Created upgrade procedure documentation
8. Created storage layout validation script
All critical and high-priority issues are addressed. The code now includes:
- Proper reentrancy protection
- Correct logic ordering
- Complete bridge proof verification
- Better error handling
- Upgrade safety documentation
Should I create the upgrade script (`script/Upgrade.s.sol`) and verification script as well?