Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/update solidity utils lib #97

Merged
merged 19 commits into from
Feb 6, 2025
Merged
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ broadcast/
input.json
compressedArtifacts.zip
zkout/

flattened/
reports/
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ endef
define deploy_fn
$(foreach network,$(2),$(call deploy_single_fn,$(1),$(network),$(3)))
endef


# Utilities
download :; cast etherscan-source --chain ${chain} -d src/etherscan/${chain}_${address} ${address}
git-diff :
@mkdir -p diffs
@printf '%s\n' "$$(git diff --no-index --diff-algorithm=patience --ignore-space-at-eol ${before} ${after})" > diffs/${out}
Binary file added bun.lockb
Binary file not shown.
92 changes: 92 additions & 0 deletions diff.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@

import { getRPCUrl, ChainId } from "@bgd-labs/rpc-env";
import { execSync } from "child_process";
import { existsSync, readFileSync, writeFileSync } from "fs";
import { Client, createClient, getAddress, Hex, http } from "viem";
import { getStorageAt } from "viem/actions";
import {GovernanceV3Arbitrum, GovernanceV3Avalanche, GovernanceV3Base, GovernanceV3BNB, GovernanceV3Ethereum, GovernanceV3Gnosis, GovernanceV3Linea, GovernanceV3Metis, GovernanceV3Optimism, GovernanceV3Polygon, GovernanceV3Scroll, GovernanceV3ZkSync} from '@bgd-labs/aave-address-book'

const CHAIN_ID_API_KEY_MAP = {
[ChainId.mainnet]: process.env.ETHERSCAN_API_KEY_MAINNET,
[ChainId.sepolia]: process.env.ETHERSCAN_API_KEY_MAINNET,
[ChainId.polygon]: process.env.ETHERSCAN_API_KEY_POLYGON,
[ChainId.zkEVM]: process.env.ETHERSCAN_API_KEY_ZKEVM,
[ChainId.arbitrum]: process.env.ETHERSCAN_API_KEY_ARBITRUM,
[ChainId.optimism]: process.env.ETHERSCAN_API_KEY_OPTIMISM,
[ChainId.scroll]: process.env.ETHERSCAN_API_KEY_SCROLL,
[ChainId.scroll_sepolia]: process.env.ETHERSCAN_API_KEY_SCROLL,
[ChainId.bnb]: process.env.ETHERSCAN_API_KEY_BNB,
[ChainId.base]: process.env.ETHERSCAN_API_KEY_BASE,
[ChainId.base_sepolia]: process.env.ETHERSCAN_API_KEY_BASE,
[ChainId.zksync]: process.env.ETHERSCAN_API_KEY_ZK_SYNC,
[ChainId.gnosis]: process.env.ETHERSCAN_API_KEY_GNOSIS,
[ChainId.linea]: process.env.ETHERSCAN_API_KEY_LINEA,
};

const bytes32toAddress = (bytes32: Hex) => {
return getAddress(`0x${bytes32.slice(26)}`);
};

const getImplementationStorageSlot = async (client: Client, address: Hex) => {
return (await getStorageAt(client, {
address,
slot: "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc",
})) as Hex;
};

async function snapshotCCC({ CHAIN_ID, CROSS_CHAIN_CONTROLLER }, isEmergencyMode = false) {
const client = createClient({ transport: http(getRPCUrl(CHAIN_ID)) });
const impl = bytes32toAddress(
await getImplementationStorageSlot(client, CROSS_CHAIN_CONTROLLER),
);

const destination = `flattened/${CHAIN_ID}/${impl}.sol`;
if (!existsSync(destination)) {
const sourceCommand = `cast etherscan-source --flatten --chain ${CHAIN_ID} -d ${destination} ${impl} --etherscan-api-key ${CHAIN_ID_API_KEY_MAP[CHAIN_ID]}`;
execSync(sourceCommand);
}
// const codeDiff = `make git-diff before=${destination} after=flattened/CrossChainController${isEmergencyMode ? 'WithEmergencyMode' : ''}.sol out=${CHAIN_ID}.patch`;
// execSync(codeDiff);

const command = `mkdir -p reports/${CHAIN_ID} && forge inspect --json ${destination}:CrossChainController${isEmergencyMode ? 'WithEmergencyMode' : ''} storage > reports/${CHAIN_ID}/${isEmergencyMode ? 'emergency_storage' : 'storage'}_${CROSS_CHAIN_CONTROLLER}.json`;
execSync(command);

execSync(
`npx @bgd-labs/aave-cli diff-storage reports/${CHAIN_ID}/${isEmergencyMode ? 'emergency_storage' : 'storage'}_${CROSS_CHAIN_CONTROLLER}.json reports/${isEmergencyMode ? 'emergency_storage_new' : 'storage_new'}.json -o diffs/storage/${CHAIN_ID}.md`,
)
}

async function diffReference() {
execSync(
`forge flatten src/contracts/CrossChainController.sol -o flattened/CrossChainController.sol && forge fmt flattened/CrossChainController.sol`,
);
execSync(
`forge inspect --json flattened/CrossChainController.sol:CrossChainController storage > reports/storage_new.json`,
);
}

async function diffReferenceEmergencyMode() {
execSync(
`forge flatten src/contracts/CrossChainControllerWithEmergencyMode.sol -o flattened/CrossChainControllerWithEmergencyMode.sol && forge fmt flattened/CrossChainControllerWithEmergencyMode.sol`,
);
execSync(
`forge inspect --json flattened/CrossChainControllerWithEmergencyMode.sol:CrossChainControllerWithEmergencyMode storage > reports/emergency_storage_new.json`,
);
}

(async function main() {
diffReference();
diffReferenceEmergencyMode();
await snapshotCCC(GovernanceV3Ethereum);
await snapshotCCC(GovernanceV3ZkSync);
await snapshotCCC(GovernanceV3Polygon, true);
await snapshotCCC(GovernanceV3Avalanche, true);
await snapshotCCC(GovernanceV3Arbitrum);
await snapshotCCC(GovernanceV3Optimism);
await snapshotCCC(GovernanceV3Base);
await snapshotCCC(GovernanceV3Gnosis, true);
await snapshotCCC(GovernanceV3Metis);
await snapshotCCC(GovernanceV3BNB, true);
await snapshotCCC(GovernanceV3Scroll);
await snapshotCCC(GovernanceV3Linea);
})();
21 changes: 21 additions & 0 deletions diffs/storage/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
```diff
| Label | Offset | Slot | Type | Bytes |
|--------------------------|--------|------|--------------------------------------------------------------------------|-------||
| _owner | 0 | 0 | address | 20 |
| _guardian | 0 | 1 | address | 20 |
| _currentEnvelopeNonce | 0 | 2 | uint256 | 32 |
| _currentTransactionNonce | 0 | 3 | uint256 | 32 |
| _approvedSenders | 0 | 4 | mapping(address => bool) | 32 |
| _registeredEnvelopes | 0 | 5 | mapping(bytes32 => bool) | 32 |
| _forwardedTransactions | 0 | 6 | mapping(bytes32 => bool) | 32 |
| _bridgeAdaptersByChain | 0 | 7 | mapping(uint256 => struct ICrossChainForwarder.ChainIdBridgeConfig[]) | 32 |
| _optimalBandwidthByChain | 0 | 8 | mapping(uint256 => uint256) | 32 |
| __FORWARDER_GAP | 0 | 9 | uint256[49] | 1568 |
| _configurationsByChain | 0 | 58 | mapping(uint256 => struct ICrossChainReceiver.ReceiverConfigurationFull) | 32 |
| _transactionsState | 0 | 59 | mapping(bytes32 => struct ICrossChainReceiver.TransactionState) | 32 |
| _envelopesState | 0 | 60 | mapping(bytes32 => enum ICrossChainReceiver.EnvelopeState) | 32 |
| _supportedChains | 0 | 61 | struct EnumerableSet.UintSet | 64 |
| __RECEIVER_GAP | 0 | 63 | uint256[50] | 1600 |
| _initialized | 0 | 113 | uint8 | 1 |
| _initializing | 1 | 113 | bool | 1 |
```
21 changes: 21 additions & 0 deletions diffs/storage/10.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
```diff
| Label | Offset | Slot | Type | Bytes |
|--------------------------|--------|------|--------------------------------------------------------------------------|-------||
| _owner | 0 | 0 | address | 20 |
| _guardian | 0 | 1 | address | 20 |
| _currentEnvelopeNonce | 0 | 2 | uint256 | 32 |
| _currentTransactionNonce | 0 | 3 | uint256 | 32 |
| _approvedSenders | 0 | 4 | mapping(address => bool) | 32 |
| _registeredEnvelopes | 0 | 5 | mapping(bytes32 => bool) | 32 |
| _forwardedTransactions | 0 | 6 | mapping(bytes32 => bool) | 32 |
| _bridgeAdaptersByChain | 0 | 7 | mapping(uint256 => struct ICrossChainForwarder.ChainIdBridgeConfig[]) | 32 |
| _optimalBandwidthByChain | 0 | 8 | mapping(uint256 => uint256) | 32 |
| __FORWARDER_GAP | 0 | 9 | uint256[49] | 1568 |
| _configurationsByChain | 0 | 58 | mapping(uint256 => struct ICrossChainReceiver.ReceiverConfigurationFull) | 32 |
| _transactionsState | 0 | 59 | mapping(bytes32 => struct ICrossChainReceiver.TransactionState) | 32 |
| _envelopesState | 0 | 60 | mapping(bytes32 => enum ICrossChainReceiver.EnvelopeState) | 32 |
| _supportedChains | 0 | 61 | struct EnumerableSet.UintSet | 64 |
| __RECEIVER_GAP | 0 | 63 | uint256[50] | 1600 |
| _initialized | 0 | 113 | uint8 | 1 |
| _initializing | 1 | 113 | bool | 1 |
```
23 changes: 23 additions & 0 deletions diffs/storage/100.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
```diff
| Label | Offset | Slot | Type | Bytes |
|---------------------------|--------|------|--------------------------------------------------------------------------|-------||
| _owner | 0 | 0 | address | 20 |
| _guardian | 0 | 1 | address | 20 |
| _currentEnvelopeNonce | 0 | 2 | uint256 | 32 |
| _currentTransactionNonce | 0 | 3 | uint256 | 32 |
| _approvedSenders | 0 | 4 | mapping(address => bool) | 32 |
| _registeredEnvelopes | 0 | 5 | mapping(bytes32 => bool) | 32 |
| _forwardedTransactions | 0 | 6 | mapping(bytes32 => bool) | 32 |
| _bridgeAdaptersByChain | 0 | 7 | mapping(uint256 => struct ICrossChainForwarder.ChainIdBridgeConfig[]) | 32 |
| _optimalBandwidthByChain | 0 | 8 | mapping(uint256 => uint256) | 32 |
| __FORWARDER_GAP | 0 | 9 | uint256[49] | 1568 |
| _configurationsByChain | 0 | 58 | mapping(uint256 => struct ICrossChainReceiver.ReceiverConfigurationFull) | 32 |
| _transactionsState | 0 | 59 | mapping(bytes32 => struct ICrossChainReceiver.TransactionState) | 32 |
| _envelopesState | 0 | 60 | mapping(bytes32 => enum ICrossChainReceiver.EnvelopeState) | 32 |
| _supportedChains | 0 | 61 | struct EnumerableSet.UintSet | 64 |
| __RECEIVER_GAP | 0 | 63 | uint256[50] | 1600 |
| _initialized | 0 | 113 | uint8 | 1 |
| _initializing | 1 | 113 | bool | 1 |
| _chainlinkEmergencyOracle | 2 | 113 | address | 20 |
| _emergencyCount | 0 | 114 | uint256 | 32 |
```
21 changes: 21 additions & 0 deletions diffs/storage/1088.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
```diff
| Label | Offset | Slot | Type | Bytes |
|--------------------------|--------|------|--------------------------------------------------------------------------|-------||
| _owner | 0 | 0 | address | 20 |
| _guardian | 0 | 1 | address | 20 |
| _currentEnvelopeNonce | 0 | 2 | uint256 | 32 |
| _currentTransactionNonce | 0 | 3 | uint256 | 32 |
| _approvedSenders | 0 | 4 | mapping(address => bool) | 32 |
| _registeredEnvelopes | 0 | 5 | mapping(bytes32 => bool) | 32 |
| _forwardedTransactions | 0 | 6 | mapping(bytes32 => bool) | 32 |
| _bridgeAdaptersByChain | 0 | 7 | mapping(uint256 => struct ICrossChainForwarder.ChainIdBridgeConfig[]) | 32 |
| _optimalBandwidthByChain | 0 | 8 | mapping(uint256 => uint256) | 32 |
| __FORWARDER_GAP | 0 | 9 | uint256[49] | 1568 |
| _configurationsByChain | 0 | 58 | mapping(uint256 => struct ICrossChainReceiver.ReceiverConfigurationFull) | 32 |
| _transactionsState | 0 | 59 | mapping(bytes32 => struct ICrossChainReceiver.TransactionState) | 32 |
| _envelopesState | 0 | 60 | mapping(bytes32 => enum ICrossChainReceiver.EnvelopeState) | 32 |
| _supportedChains | 0 | 61 | struct EnumerableSet.UintSet | 64 |
| __RECEIVER_GAP | 0 | 63 | uint256[50] | 1600 |
| _initialized | 0 | 113 | uint8 | 1 |
| _initializing | 1 | 113 | bool | 1 |
```
23 changes: 23 additions & 0 deletions diffs/storage/137.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
```diff
| Label | Offset | Slot | Type | Bytes |
|---------------------------|--------|------|--------------------------------------------------------------------------|-------||
| _owner | 0 | 0 | address | 20 |
| _guardian | 0 | 1 | address | 20 |
| _currentEnvelopeNonce | 0 | 2 | uint256 | 32 |
| _currentTransactionNonce | 0 | 3 | uint256 | 32 |
| _approvedSenders | 0 | 4 | mapping(address => bool) | 32 |
| _registeredEnvelopes | 0 | 5 | mapping(bytes32 => bool) | 32 |
| _forwardedTransactions | 0 | 6 | mapping(bytes32 => bool) | 32 |
| _bridgeAdaptersByChain | 0 | 7 | mapping(uint256 => struct ICrossChainForwarder.ChainIdBridgeConfig[]) | 32 |
| _optimalBandwidthByChain | 0 | 8 | mapping(uint256 => uint256) | 32 |
| __FORWARDER_GAP | 0 | 9 | uint256[49] | 1568 |
| _configurationsByChain | 0 | 58 | mapping(uint256 => struct ICrossChainReceiver.ReceiverConfigurationFull) | 32 |
| _transactionsState | 0 | 59 | mapping(bytes32 => struct ICrossChainReceiver.TransactionState) | 32 |
| _envelopesState | 0 | 60 | mapping(bytes32 => enum ICrossChainReceiver.EnvelopeState) | 32 |
| _supportedChains | 0 | 61 | struct EnumerableSet.UintSet | 64 |
| __RECEIVER_GAP | 0 | 63 | uint256[50] | 1600 |
| _initialized | 0 | 113 | uint8 | 1 |
| _initializing | 1 | 113 | bool | 1 |
| _chainlinkEmergencyOracle | 2 | 113 | address | 20 |
| _emergencyCount | 0 | 114 | uint256 | 32 |
```
Loading
Loading