Skip to content

Commit 0bb938d

Browse files
mjlescanodbeal-eth
andauthored
Contract storage layout verification improvements (#2129)
* divide generate and verify tasks * fix state var validation, using only required files * fix tests * add flattening of nested structs * add storage parser by batches * refactor structs flattening * fix build * remove contract to address rendering * add dependency imports * fix contracts references * use solidity-parser * migrate previous validations * add dependencies parsing * add standalone storage validations * update dump * add contract for address replacement * add import directives with correct aliases * revert synthetix storage dump * fix imports duplication * add new dump format * update tests * refactor dump to json * add enum compatibility * fix array values on dump * add storage slot sizes * add storage slot sizes * remove storage size * update yarn.lock * fix struct size * refactor tasks * add layout print * Add simple validations * add storage mutation validations * add variable modifications checks * add verification errors * fix CI * update and execute verification script * fix dependencies lint errors * fix lint errors * remove empty dumps * fix yarn.lock * fix yarn dedupe * add comments * add comments * fix storage dump diff check * build is working much better still some issues tho * successful build * fix * fix subtask spec * fix yarn lock * fix * fixem * try storage dump ci work * move hre back * fix check test * update commands * build everything, not just ts * more fixes * fix local quirk * fix * ignore whitespace * add check compile step * prettier got in the way * fix more * add copy storage job to ensure its in sync before commit * small fix to the copy storage pre commit hook * use git merge base --------- Co-authored-by: Daniel Beal <[email protected]> Co-authored-by: dbeal <[email protected]>
1 parent 6a93c07 commit 0bb938d

File tree

101 files changed

+11720
-6267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+11720
-6267
lines changed

.circleci/config.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ jobs:
346346
# if there are no tests, terminate execution after this step
347347
if [ -s "/tmp/tests.txt" ]; then
348348
echo cat "/tmp/tests.txt"
349-
cat "/tmp/tests.txt"
349+
cat "/tmp/tests.txt"
350350
else
351-
echo "SKIP: No tests found"
351+
echo "SKIP: No tests found"
352352
circleci-agent step halt
353353
fi
354354
@@ -428,8 +428,12 @@ jobs:
428428
- install-foundry
429429
- yarn-install
430430
- run: yarn build:ts
431-
- run: yarn storage:verify
431+
- run: yarn storage:dump
432432
- run: yarn check:storage
433+
# pull the storage dumps from main so that we can compare against them
434+
- run: for f in $(find . -name 'storage.dump.json'); do git checkout $(git merge-base HEAD FETCH_HEAD) -- $f || true; done
435+
# todo: next step may be removable/optimizable, but it only takes like 20 seconds
436+
- run: yarn storage:verify
433437

434438
lint:
435439
docker:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ typechain-types
1818
lerna-debug.log
1919
docs/
2020
junit
21+
storage.new.dump.json
2122

2223
# Yarn v3
2324
.pnp.*

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ lerna.json
2727
**/tests/.latest.json
2828
**/lib
2929
**/out
30+
storage.dump.json
31+
storage.new.dump.json
3032

3133
utils/docgen/deployments/
3234
utils/docgen/abis/

.solhintignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
\*.dump.sol
2+
\*.dump.json
23
artifacts/
34
node_modules/
45
**/contracts/generated
@@ -17,8 +18,6 @@ utils/core-modules/contracts/modules/UpgradeModule.sol
1718
utils/core-contracts/contracts/ownership/Ownable.sol
1819
utils/core-contracts/contracts/ownership/OwnableStorage.sol
1920

20-
storage.dump.sol
21-
2221
# Immutable InitialProxy
2322
markets/legacy-market/contracts/InitialModuleBundle.sol
2423
markets/perps-market/contracts/modules/CoreModule.sol
Binary file not shown.
Binary file not shown.

auxiliary/ArbitrumGasPriceOracle/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
"scripts": {
99
"clean": "hardhat clean",
1010
"build": "yarn build:contracts",
11-
"storage:verify": "hardhat compile --force && hardhat storage:verify",
12-
"build:contracts": "hardhat compile --force && CANNON_REGISTRY_PRIORITY=local hardhat cannon:build",
1311
"build-testable": "CANNON_REGISTRY_PRIORITY=local hardhat cannon:build cannonfile.test.toml",
14-
"check:storage": "git diff --exit-code storage.dump.sol",
12+
"build:contracts": "hardhat compile --force && yarn storage:dump && CANNON_REGISTRY_PRIORITY=local hardhat cannon:build",
13+
"storage:dump": "hardhat storage:dump --output storage.new.dump.json",
14+
"check:storage": "diff -uw storage.dump.json storage.new.dump.json",
15+
"storage:verify": " hardhat storage:verify",
1516
"test": "CANNON_REGISTRY_PRIORITY=local hardhat test",
1617
"coverage": "hardhat coverage --network hardhat",
1718
"compile-contracts": "hardhat compile",
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"contracts/ArbGasPriceOracle.sol:ArbGasPriceOracle": {
3+
"name": "ArbGasPriceOracle",
4+
"kind": "contract",
5+
"structs": {
6+
"RuntimeParams": [
7+
{
8+
"type": "uint256",
9+
"name": "l1SettleGasUnits",
10+
"size": 32,
11+
"slot": "0",
12+
"offset": 0
13+
},
14+
{
15+
"type": "uint256",
16+
"name": "l2SettleGasUnits",
17+
"size": 32,
18+
"slot": "1",
19+
"offset": 0
20+
},
21+
{
22+
"type": "uint256",
23+
"name": "l1FlagGasUnits",
24+
"size": 32,
25+
"slot": "2",
26+
"offset": 0
27+
},
28+
{
29+
"type": "uint256",
30+
"name": "l2FlagGasUnits",
31+
"size": 32,
32+
"slot": "3",
33+
"offset": 0
34+
},
35+
{
36+
"type": "uint256",
37+
"name": "l1LiquidateGasUnits",
38+
"size": 32,
39+
"slot": "4",
40+
"offset": 0
41+
},
42+
{
43+
"type": "uint256",
44+
"name": "l2LiquidateGasUnits",
45+
"size": 32,
46+
"slot": "5",
47+
"offset": 0
48+
},
49+
{
50+
"type": "uint256",
51+
"name": "numberOfUpdatedFeeds",
52+
"size": 32,
53+
"slot": "6",
54+
"offset": 0
55+
},
56+
{
57+
"type": "uint256",
58+
"name": "executionKind",
59+
"size": 32,
60+
"slot": "7",
61+
"offset": 0
62+
}
63+
]
64+
}
65+
}
66+
}

auxiliary/ArbitrumGasPriceOracle/storage.dump.sol

Lines changed: 0 additions & 126 deletions
This file was deleted.

auxiliary/BuybackSnx/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
"coverage": "hardhat coverage --network hardhat",
1111
"clean": "hardhat clean",
1212
"build": "yarn build:contracts",
13-
"storage:verify": "hardhat compile --force && hardhat storage:verify",
14-
"build:contracts": "hardhat compile --force && CANNON_REGISTRY_PRIORITY=local hardhat cannon:build",
13+
"build:contracts": "hardhat compile --force && yarn storage:dump && CANNON_REGISTRY_PRIORITY=local hardhat cannon:build",
14+
"storage:dump": "hardhat storage:dump --output storage.new.dump.json",
15+
"storage:verify": " hardhat storage:verify",
1516
"build-testable": "CANNON_REGISTRY_PRIORITY=local hardhat cannon:build cannonfile.test.toml",
16-
"check:storage": "git diff --exit-code storage.dump.sol",
17+
"check:storage": "diff -uw storage.dump.json storage.new.dump.json",
1718
"compile-contracts": "hardhat compile",
1819
"size-contracts": "hardhat compile && hardhat size-contracts",
1920
"publish-contracts": "cannon publish buyback-snx:$(node -p 'require(`./package.json`).version') --chain-id 13370 --quiet --tags $(node -p '/^\\d+\\.\\d+\\.\\d+$/.test(require(`./package.json`).version) ? `latest` : `dev`')",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

auxiliary/BuybackSnx/storage.dump.sol

Lines changed: 0 additions & 114 deletions
This file was deleted.

0 commit comments

Comments
 (0)