Skip to content

Commit

Permalink
Merge pull request #49 from OffchainLabs/foundry-storage-check
Browse files Browse the repository at this point in the history
Foundry storage check
  • Loading branch information
gvladika authored Oct 27, 2023
2 parents 6f47c07 + c500417 commit 8aa70ea
Show file tree
Hide file tree
Showing 27 changed files with 133 additions and 163 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ jobs:
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Setup node/yarn
uses: actions/setup-node@v3
with:
Expand All @@ -85,7 +90,7 @@ jobs:
run: yarn

- name: Build
run: yarn build
run: forge build

- name: Test Storage Layouts
run: yarn run test:storage
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ forge-cache/

#Storage layout test files
test/storage/*-old.dot
test/storage/*-old

# local deployment files
network.json
6 changes: 3 additions & 3 deletions scripts/storage_layout_test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ output_dir="./test/storage"
for CONTRACTNAME in L1ERC20Gateway L1CustomGateway L1ReverseCustomGateway L1WethGateway L2ERC20Gateway L2CustomGateway L2ReverseCustomGateway L2WethGateway L1GatewayRouter L2GatewayRouter StandardArbERC20
do
echo "Checking storage change of $CONTRACTNAME"
[ -f "$output_dir/$CONTRACTNAME.dot" ] && mv "$output_dir/$CONTRACTNAME.dot" "$output_dir/$CONTRACTNAME-old.dot"
yarn sol2uml storage ./ -c "$CONTRACTNAME" -o "$output_dir/$CONTRACTNAME.dot" -f dot
diff "$output_dir/$CONTRACTNAME-old.dot" "$output_dir/$CONTRACTNAME.dot"
[ -f "$output_dir/$CONTRACTNAME" ] && mv "$output_dir/$CONTRACTNAME" "$output_dir/$CONTRACTNAME-old"
forge inspect "$CONTRACTNAME" --pretty storage > "$output_dir/$CONTRACTNAME"
diff "$output_dir/$CONTRACTNAME-old" "$output_dir/$CONTRACTNAME"
if [[ $? != "0" ]]
then
CHANGED=1
Expand Down
22 changes: 12 additions & 10 deletions test-foundry/L1ArbitrumExtendedGateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,18 @@ abstract contract L1ArbitrumExtendedGatewayTest is Test {
);
}

function test_supportsInterface(bytes4 iface) public {
bool expected = false;
if (
iface == type(IERC165).interfaceId ||
iface == IL1ArbitrumGateway.outboundTransferCustomRefund.selector
) {
expected = true;
}

assertEq(l1Gateway.supportsInterface(iface), expected, "Interface shouldn't be supported");
function test_supportsInterface() public {
bytes4 iface = type(IERC165).interfaceId;
assertEq(l1Gateway.supportsInterface(iface), true, "Interface should be supported");

iface = IL1ArbitrumGateway.outboundTransferCustomRefund.selector;
assertEq(l1Gateway.supportsInterface(iface), true, "Interface should be supported");

iface = bytes4(0);
assertEq(l1Gateway.supportsInterface(iface), false, "Interface shouldn't be supported");

iface = IL1ArbitrumGateway.inbox.selector;
assertEq(l1Gateway.supportsInterface(iface), false, "Interface shouldn't be supported");
}

function test_transferExitAndCall_EmptyData_NotRedirected(
Expand Down
20 changes: 11 additions & 9 deletions test-foundry/L1GatewayRouter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -664,16 +664,18 @@ contract L1GatewayRouterTest is GatewayRouterTest {
l1Router.setOwner(address(300));
}

function test_supportsInterface(bytes4 iface) public {
bool expected = false;
if (
iface == type(IERC165).interfaceId ||
iface == L1GatewayRouter.outboundTransferCustomRefund.selector
) {
expected = true;
}
function test_supportsInterface() public {
bytes4 iface = type(IERC165).interfaceId;
assertEq(l1Router.supportsInterface(iface), true, "Interface should be supported");

iface = L1GatewayRouter.outboundTransferCustomRefund.selector;
assertEq(l1Router.supportsInterface(iface), true, "Interface should be supported");

iface = bytes4(0);
assertEq(l1Router.supportsInterface(iface), false, "Interface shouldn't be supported");

assertEq(l1Router.supportsInterface(iface), expected, "Interface shouldn't be supported");
iface = L1GatewayRouter.setGateways.selector;
assertEq(l1Router.supportsInterface(iface), false, "Interface shouldn't be supported");
}

function test_outboundTransfer() public virtual {
Expand Down
10 changes: 10 additions & 0 deletions test/storage/L1CustomGateway
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
| Name | Type | Slot | Offset | Bytes | Contract |
|--------------------|---------------------------------------------------------------|------|--------|-------|----------------------------------------------------------------------------|
| counterpartGateway | address | 0 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1CustomGateway.sol:L1CustomGateway |
| router | address | 1 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1CustomGateway.sol:L1CustomGateway |
| inbox | address | 2 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1CustomGateway.sol:L1CustomGateway |
| redirectedExits | mapping(bytes32 => struct L1ArbitrumExtendedGateway.ExitData) | 3 | 0 | 32 | contracts/tokenbridge/ethereum/gateway/L1CustomGateway.sol:L1CustomGateway |
| l1ToL2Token | mapping(address => address) | 4 | 0 | 32 | contracts/tokenbridge/ethereum/gateway/L1CustomGateway.sol:L1CustomGateway |
| owner | address | 5 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1CustomGateway.sol:L1CustomGateway |
| whitelist | address | 6 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1CustomGateway.sol:L1CustomGateway |
| _status | uint256 | 7 | 0 | 32 | contracts/tokenbridge/ethereum/gateway/L1CustomGateway.sol:L1CustomGateway |
13 changes: 0 additions & 13 deletions test/storage/L1CustomGateway.dot

This file was deleted.

10 changes: 10 additions & 0 deletions test/storage/L1ERC20Gateway
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
| Name | Type | Slot | Offset | Bytes | Contract |
|----------------------|---------------------------------------------------------------|------|--------|-------|--------------------------------------------------------------------------|
| counterpartGateway | address | 0 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1ERC20Gateway.sol:L1ERC20Gateway |
| router | address | 1 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1ERC20Gateway.sol:L1ERC20Gateway |
| inbox | address | 2 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1ERC20Gateway.sol:L1ERC20Gateway |
| redirectedExits | mapping(bytes32 => struct L1ArbitrumExtendedGateway.ExitData) | 3 | 0 | 32 | contracts/tokenbridge/ethereum/gateway/L1ERC20Gateway.sol:L1ERC20Gateway |
| cloneableProxyHash | bytes32 | 4 | 0 | 32 | contracts/tokenbridge/ethereum/gateway/L1ERC20Gateway.sol:L1ERC20Gateway |
| l2BeaconProxyFactory | address | 5 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1ERC20Gateway.sol:L1ERC20Gateway |
| whitelist | address | 6 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1ERC20Gateway.sol:L1ERC20Gateway |
| _status | uint256 | 7 | 0 | 32 | contracts/tokenbridge/ethereum/gateway/L1ERC20Gateway.sol:L1ERC20Gateway |
13 changes: 0 additions & 13 deletions test/storage/L1ERC20Gateway.dot

This file was deleted.

9 changes: 9 additions & 0 deletions test/storage/L1GatewayRouter
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
| Name | Type | Slot | Offset | Bytes | Contract |
|--------------------|-----------------------------|------|--------|-------|----------------------------------------------------------------------------|
| whitelist | address | 0 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1GatewayRouter.sol:L1GatewayRouter |
| counterpartGateway | address | 1 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1GatewayRouter.sol:L1GatewayRouter |
| router | address | 2 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1GatewayRouter.sol:L1GatewayRouter |
| l1TokenToGateway | mapping(address => address) | 3 | 0 | 32 | contracts/tokenbridge/ethereum/gateway/L1GatewayRouter.sol:L1GatewayRouter |
| defaultGateway | address | 4 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1GatewayRouter.sol:L1GatewayRouter |
| owner | address | 5 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1GatewayRouter.sol:L1GatewayRouter |
| inbox | address | 6 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1GatewayRouter.sol:L1GatewayRouter |
10 changes: 0 additions & 10 deletions test/storage/L1GatewayRouter.dot

This file was deleted.

10 changes: 10 additions & 0 deletions test/storage/L1ReverseCustomGateway
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
| Name | Type | Slot | Offset | Bytes | Contract |
|--------------------|---------------------------------------------------------------|------|--------|-------|------------------------------------------------------------------------------------------|
| counterpartGateway | address | 0 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1ReverseCustomGateway.sol:L1ReverseCustomGateway |
| router | address | 1 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1ReverseCustomGateway.sol:L1ReverseCustomGateway |
| inbox | address | 2 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1ReverseCustomGateway.sol:L1ReverseCustomGateway |
| redirectedExits | mapping(bytes32 => struct L1ArbitrumExtendedGateway.ExitData) | 3 | 0 | 32 | contracts/tokenbridge/ethereum/gateway/L1ReverseCustomGateway.sol:L1ReverseCustomGateway |
| l1ToL2Token | mapping(address => address) | 4 | 0 | 32 | contracts/tokenbridge/ethereum/gateway/L1ReverseCustomGateway.sol:L1ReverseCustomGateway |
| owner | address | 5 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1ReverseCustomGateway.sol:L1ReverseCustomGateway |
| whitelist | address | 6 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1ReverseCustomGateway.sol:L1ReverseCustomGateway |
| _status | uint256 | 7 | 0 | 32 | contracts/tokenbridge/ethereum/gateway/L1ReverseCustomGateway.sol:L1ReverseCustomGateway |
13 changes: 0 additions & 13 deletions test/storage/L1ReverseCustomGateway.dot

This file was deleted.

8 changes: 8 additions & 0 deletions test/storage/L1WethGateway
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
| Name | Type | Slot | Offset | Bytes | Contract |
|--------------------|---------------------------------------------------------------|------|--------|-------|------------------------------------------------------------------------|
| counterpartGateway | address | 0 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1WethGateway.sol:L1WethGateway |
| router | address | 1 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1WethGateway.sol:L1WethGateway |
| inbox | address | 2 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1WethGateway.sol:L1WethGateway |
| redirectedExits | mapping(bytes32 => struct L1ArbitrumExtendedGateway.ExitData) | 3 | 0 | 32 | contracts/tokenbridge/ethereum/gateway/L1WethGateway.sol:L1WethGateway |
| l1Weth | address | 4 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1WethGateway.sol:L1WethGateway |
| l2Weth | address | 5 | 0 | 20 | contracts/tokenbridge/ethereum/gateway/L1WethGateway.sol:L1WethGateway |
13 changes: 0 additions & 13 deletions test/storage/L1WethGateway.dot

This file was deleted.

6 changes: 6 additions & 0 deletions test/storage/L2CustomGateway
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
| Name | Type | Slot | Offset | Bytes | Contract |
|--------------------|-----------------------------|------|--------|-------|----------------------------------------------------------------------------|
| counterpartGateway | address | 0 | 0 | 20 | contracts/tokenbridge/arbitrum/gateway/L2CustomGateway.sol:L2CustomGateway |
| router | address | 1 | 0 | 20 | contracts/tokenbridge/arbitrum/gateway/L2CustomGateway.sol:L2CustomGateway |
| exitNum | uint256 | 2 | 0 | 32 | contracts/tokenbridge/arbitrum/gateway/L2CustomGateway.sol:L2CustomGateway |
| l1ToL2Token | mapping(address => address) | 3 | 0 | 32 | contracts/tokenbridge/arbitrum/gateway/L2CustomGateway.sol:L2CustomGateway |
10 changes: 0 additions & 10 deletions test/storage/L2CustomGateway.dot

This file was deleted.

6 changes: 6 additions & 0 deletions test/storage/L2ERC20Gateway
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
| Name | Type | Slot | Offset | Bytes | Contract |
|--------------------|---------|------|--------|-------|--------------------------------------------------------------------------|
| counterpartGateway | address | 0 | 0 | 20 | contracts/tokenbridge/arbitrum/gateway/L2ERC20Gateway.sol:L2ERC20Gateway |
| router | address | 1 | 0 | 20 | contracts/tokenbridge/arbitrum/gateway/L2ERC20Gateway.sol:L2ERC20Gateway |
| exitNum | uint256 | 2 | 0 | 32 | contracts/tokenbridge/arbitrum/gateway/L2ERC20Gateway.sol:L2ERC20Gateway |
| beaconProxyFactory | address | 3 | 0 | 20 | contracts/tokenbridge/arbitrum/gateway/L2ERC20Gateway.sol:L2ERC20Gateway |
Loading

0 comments on commit 8aa70ea

Please sign in to comment.