Skip to content

Commit

Permalink
Merge pull request #44 from bgd-labs/feat/zksync
Browse files Browse the repository at this point in the history
feat: Add zkSync adapter
  • Loading branch information
sendra authored Jul 26, 2024
2 parents db38e62 + 2eed733 commit 5a9a33a
Show file tree
Hide file tree
Showing 68 changed files with 856 additions and 721 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ broadcast/

input.json
compressedArtifacts.zip
zkout/
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
branch = release-v4.9
[submodule "lib/aave-helpers"]
path = lib/aave-helpers
url = https://github.com/bgd-labs/aave-helpers
[submodule "lib/solidity-utils"]
path = lib/solidity-utils
url = https://github.com/bgd-labs/solidity-utils
14 changes: 14 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ remappings = [
'hyperlane-monorepo/=lib/hyperlane-monorepo/solidity/contracts/',
'@openzeppelin/=lib/openzeppelin-contracts/'
]
evm_version = 'shanghai'

fs_permissions = [{ access = "read-write", path = "./"}]

solc = "0.8.19"

[profile.default.zksync]
fallback_oz = true
mode = "3"
zksolc="1.4.1"

[rpc_endpoints]
ethereum="${RPC_MAINNET}"
ethereum-testnet="${RPC_ETHEREUM_SEPOLIA}"
Expand Down Expand Up @@ -41,6 +47,8 @@ scroll="${RPC_SCROLL}"
scroll-testnet="${RPC_SCROLL_TESTNET}"
celo="${RPC_CELO}"
celo-testnet="${RPC_CELO_ALFAJORES}"
zksync="${RPC_ZK_SYNC}"
zksync-testnet="${RPC_ZK_SYNC_TESTNET}"

[etherscan]
ethereum={key="${ETHERSCAN_API_KEY_MAINNET}", chain=1 }
Expand Down Expand Up @@ -69,5 +77,11 @@ scroll={key="${ETHERSCAN_API_KEY_SCROLL}", chain=534352, utl='https://api.scroll
scroll-testnet={key="${ETHERSCAN_API_KEY_SCROLL}", chain=534351, url='https://api-sepolia.scrollscan.com/api/'}
celo={key="${ETHERSCAN_API_KEY_CELO}", chain=42220, utl='https://api.celoscan.io/api'}
celo-testnet={key="${ETHERSCAN_API_KEY_CELO}", chain=44787, url='https://api-alfajores.celoscan.io/api'}
zksync={key="${ETHERSCAN_API_KEY_ZK_SYNC}", chain=324}
zksync-testnet={key="${ETHERSCAN_API_KEY_ZK_SYNC}", chain=300, url='https://api-sepolia-era.zksync.network/api'}

# See more config options https://github.com/gakonst/foundry/tree/master/config
[fuzz]
no_zksync_reserved_addresses = true
[invariant]
no_zksync_reserved_addresses = true
1 change: 0 additions & 1 deletion lib/aave-helpers
Submodule aave-helpers deleted from 2e1710
1 change: 1 addition & 0 deletions lib/solidity-utils
Submodule solidity-utils added at 9e1215
9 changes: 2 additions & 7 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
solidity-utils/=lib/aave-helpers/lib/solidity-utils/src/
ds-test/=lib/aave-helpers/lib/forge-std/lib/ds-test/src/
forge-std/=lib/aave-helpers/lib/forge-std/src/
fx-portal/=lib/fx-portal/contracts/
nitro-contracts/=lib/nitro-contracts/src/
solidity-utils/=lib/solidity-utils/src/
forge-std/=lib/solidity-utils/lib/forge-std/src/
openzeppelin-contracts/=lib/openzeppelin-contracts/
aave-helpers/=lib/aave-helpers/src/
aave-address-book/=lib/aave-helpers/lib/aave-address-book/src/
5 changes: 2 additions & 3 deletions scripts/Adapters/BaseAdapterScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ abstract contract BaseAdapterScript is BaseScript {
return false;
}

function _computeAdapterAddress(address currentNetworkCCC) internal view returns (address) {
function _computeAdapterAddress(address currentNetworkCCC) internal returns (address) {
bytes memory adapterCode = _getAdapterByteCode(currentNetworkCCC);
bytes32 salt = keccak256(abi.encode(SALT()));

return Create2Utils.computeCreate2Address(salt, adapterCode);
return _computeByteCodeAddress(adapterCode, SALT());
}

function _getAdapterByteCode(address currentNetworkCCC) internal view returns (bytes memory) {
Expand Down
84 changes: 84 additions & 0 deletions scripts/Adapters/DeployZkSyncAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import './BaseAdapterScript.sol';
import {ZkSyncAdapter} from '../../src/contracts/adapters/zkSync/ZkSyncAdapter.sol';
import {ZkSyncAdapterTestnet} from '../contract_extensions/ZkSyncAdapterTestnet.sol';

library ZkSyncAdapterDeploymentHelper {
struct ZkSyncAdapterArgs {
BaseAdapterArgs baseArgs;
address bridgeHub;
address refundAddress;
}

function getAdapterCode(
ZkSyncAdapterArgs memory zkSyncArgs
) internal pure returns (bytes memory) {
bytes memory creationCode = zkSyncArgs.baseArgs.isTestnet
? type(ZkSyncAdapterTestnet).creationCode
: type(ZkSyncAdapter).creationCode;

return
abi.encodePacked(
creationCode,
abi.encode(
zkSyncArgs.baseArgs.crossChainController,
zkSyncArgs.bridgeHub,
zkSyncArgs.refundAddress,
zkSyncArgs.baseArgs.providerGasLimit,
zkSyncArgs.baseArgs.trustedRemotes
)
);
}
}

abstract contract BaseZkSyncAdapter is BaseAdapterScript {
function BRIDGE_HUB() internal view virtual returns (address);

function REFUND_ADDRESS() internal view virtual returns (address) {
return address(0);
}

function _getAdapterByteCode(
BaseAdapterArgs memory baseArgs
) internal view override returns (bytes memory) {
require(BRIDGE_HUB() != address(0), 'Invalid BRIDGE_HUB');

return
ZkSyncAdapterDeploymentHelper.getAdapterCode(
ZkSyncAdapterDeploymentHelper.ZkSyncAdapterArgs({
baseArgs: baseArgs,
bridgeHub: BRIDGE_HUB(),
refundAddress: REFUND_ADDRESS()
})
);
}

function _deployWithoutCreate2(BaseAdapterArgs memory baseArgs) internal returns (address) {
require(BRIDGE_HUB() != address(0), 'Invalid BRIDGE_HUB');
if (isTestnet()) {
return
address(
new ZkSyncAdapterTestnet(
baseArgs.crossChainController,
BRIDGE_HUB(),
REFUND_ADDRESS(),
baseArgs.providerGasLimit,
baseArgs.trustedRemotes
)
);
} else {
return
address(
new ZkSyncAdapter(
baseArgs.crossChainController,
BRIDGE_HUB(),
REFUND_ADDRESS(),
baseArgs.providerGasLimit,
baseArgs.trustedRemotes
)
);
}
}
}
16 changes: 11 additions & 5 deletions scripts/BaseScript.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {ChainIds, TestNetChainIds} from 'aave-helpers/ChainIds.sol';
import {Create2Utils} from 'aave-helpers/ScriptUtils.sol';
import {ChainIds, TestNetChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';

abstract contract BaseScript {
function TRANSACTION_NETWORK() internal view virtual returns (uint256);

// Should only implement as:
// return Create2Utils.create2Deploy(keccak256(abi.encode(salt)), byteCode);
function _deployByteCode(
bytes memory byteCode,
string memory salt
) internal virtual returns (address) {
return Create2Utils.create2Deploy(keccak256(abi.encode(salt)), byteCode);
}
) internal virtual returns (address);

// Should only implement as:
// return Create2Utils.computeCreate2Address(salt, adapterCode);
function _computeByteCodeAddress(
bytes memory byteCode,
string memory salt
) internal virtual returns (address);
}
8 changes: 8 additions & 0 deletions scripts/CCC/DeployCrossChainController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ abstract contract BaseCCCDeploy is BaseScript {

return _deployByteCode(cccCode, SALT());
}

function _deployWithoutCreate2() internal returns (address) {
if (CL_EMERGENCY_ORACLE() == address(0)) {
return address(new CrossChainController());
} else {
return address(new CrossChainControllerWithEmergencyMode(CL_EMERGENCY_ORACLE()));
}
}
}
2 changes: 1 addition & 1 deletion scripts/contract_extensions/ArbitrumAdapter.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.8;

import {TestNetChainIds} from 'aave-helpers/ChainIds.sol';
import {TestNetChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
import {IArbAdapter, ArbAdapter} from '../../src/contracts/adapters/arbitrum/ArbAdapter.sol';

/**
Expand Down
2 changes: 1 addition & 1 deletion scripts/contract_extensions/CBAdapter.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.8;

import {TestNetChainIds} from 'aave-helpers/ChainIds.sol';
import {TestNetChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
import {CBaseAdapter, IOpAdapter} from '../../src/contracts/adapters/cBase/CBaseAdapter.sol';

/**
Expand Down
2 changes: 1 addition & 1 deletion scripts/contract_extensions/CCIPAdapter.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.8;

import {TestNetChainIds} from 'aave-helpers/ChainIds.sol';
import {TestNetChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
import {CCIPAdapter} from '../../src/contracts/adapters/ccip/CCIPAdapter.sol';
import {BaseAdapter, IBaseAdapter} from '../../src/contracts/adapters/BaseAdapter.sol';

Expand Down
2 changes: 1 addition & 1 deletion scripts/contract_extensions/GnosisChainAdapter.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.8;

import {TestNetChainIds} from 'aave-helpers/ChainIds.sol';
import {TestNetChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
import {GnosisChainAdapter} from '../../src/contracts/adapters/gnosisChain/GnosisChainAdapter.sol';
import {BaseAdapter, IBaseAdapter} from '../../src/contracts/adapters/BaseAdapter.sol';

Expand Down
4 changes: 2 additions & 2 deletions scripts/contract_extensions/LayerZeroAdapter.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.8;

import {SafeCast} from 'openzeppelin-contracts/contracts/utils/math/SafeCast.sol';
import {SafeCast} from 'solidity-utils/contracts/oz-common/SafeCast.sol';
import {BaseAdapter, IBaseAdapter} from '../../src/contracts/adapters/BaseAdapter.sol';
import {LayerZeroAdapter} from '../../src/contracts/adapters/layerZero/LayerZeroAdapter.sol';
import {ILayerZeroAdapter} from '../../src/contracts/adapters/layerZero/ILayerZeroAdapter.sol';
import {TestNetChainIds} from 'aave-helpers/ChainIds.sol';
import {TestNetChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
import {Errors} from '../../src/contracts/libs/Errors.sol';

/**
Expand Down
2 changes: 1 addition & 1 deletion scripts/contract_extensions/MetisAdapter.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.8;

import {TestNetChainIds} from 'aave-helpers/ChainIds.sol';
import {TestNetChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
import {IOpAdapter, MetisAdapter} from '../../src/contracts/adapters/metis/MetisAdapter.sol';

/**
Expand Down
2 changes: 1 addition & 1 deletion scripts/contract_extensions/OptimismAdapter.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.8;

import {TestNetChainIds} from 'aave-helpers/ChainIds.sol';
import {TestNetChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
import {IOpAdapter, OpAdapter} from '../../src/contracts/adapters/optimism/OpAdapter.sol';

/**
Expand Down
2 changes: 1 addition & 1 deletion scripts/contract_extensions/PolygonAdapterTestnets.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.8;

import {TestNetChainIds} from 'aave-helpers/ChainIds.sol';
import {TestNetChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
import {PolygonAdapterBase} from '../../src/contracts/adapters/polygon/PolygonAdapterBase.sol';
import {IPolygonAdapter} from '../../src/contracts/adapters/polygon/IPolygonAdapter.sol';

Expand Down
2 changes: 1 addition & 1 deletion scripts/contract_extensions/ScrollAdapter.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.8;

import {TestNetChainIds} from 'aave-helpers/ChainIds.sol';
import {TestNetChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
import {IOpAdapter, ScrollAdapter} from '../../src/contracts/adapters/scroll/ScrollAdapter.sol';

/**
Expand Down
2 changes: 1 addition & 1 deletion scripts/contract_extensions/WormholeAdapter.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.8;

import {TestNetChainIds} from 'aave-helpers/ChainIds.sol';
import {TestNetChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
import {WormholeAdapter} from '../../src/contracts/adapters/wormhole/WormholeAdapter.sol';
import {BaseAdapter, IBaseAdapter} from '../../src/contracts/adapters/BaseAdapter.sol';

Expand Down
25 changes: 25 additions & 0 deletions scripts/contract_extensions/ZkSyncAdapterTestnet.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.8;

import {TestNetChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
import {IZkSyncAdapter, ZkSyncAdapter} from '../../src/contracts/adapters/zkSync/ZkSyncAdapter.sol';

contract ZkSyncAdapterTestnet is ZkSyncAdapter {
constructor(
address crossChainController,
address mailBox,
address refundAddress,
uint256 providerGasLimit,
TrustedRemotesConfig[] memory trustedRemotes
) ZkSyncAdapter(crossChainController, mailBox, refundAddress, providerGasLimit, trustedRemotes) {}

/// @inheritdoc IZkSyncAdapter
function isDestinationChainIdSupported(uint256 chainId) public pure override returns (bool) {
return chainId == TestNetChainIds.ZK_SYNC_SEPOLIA;
}

/// @inheritdoc IZkSyncAdapter
function getOriginChainId() public pure override returns (uint256) {
return TestNetChainIds.ETHEREUM_SEPOLIA;
}
}
2 changes: 1 addition & 1 deletion scripts/examples/Payload_SolveEmergencyPrePopulated.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.0;

import 'forge-std/Script.sol';
import {ChainIds} from 'aave-helpers/ChainIds.sol';
import {ChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
import {ICrossChainReceiver} from '../../src/contracts/interfaces/ICrossChainReceiver.sol';
import {ICrossChainForwarder} from '../../src/contracts/interfaces/ICrossChainForwarder.sol';
import {ICrossChainControllerWithEmergencyMode} from '../../src/contracts/interfaces/ICrossChainControllerWithEmergencyMode.sol';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
"optimistic_hashing": true,
"optimistic_loop": true,
"packages": [
"solidity-utils/=lib/aave-helpers/lib/solidity-utils/src",
"forge-std/=lib/aave-helpers/lib/forge-std/src",
"solidity-utils/=lib/solidity-utils/src",
"forge-std/=lib/solidity-utils/lib/forge-std/src",
"openzeppelin-contracts/=lib/openzeppelin-contracts",
"aave-helpers/=lib/aave-helpers/src",
"aave-address-book/=lib/aave-helpers/lib/aave-address-book/src",
],
"process": "emv",
"prover_args": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
],
"link": [],
"packages": [
"solidity-utils/=lib/aave-helpers/lib/solidity-utils/src",
"forge-std/=lib/aave-helpers/lib/forge-std/src",
"solidity-utils/=lib/solidity-utils/src",
"forge-std/=lib/solidity-utils/lib/forge-std/src",
"openzeppelin-contracts/=lib/openzeppelin-contracts",
"aave-helpers/=lib/aave-helpers/src",
"aave-address-book/=lib/aave-helpers/lib/aave-address-book/src",
],
"verify": "CrossChainForwarderHarnessED:security/certora/specs/CrossChainForwarder-encode-decode-correct.spec",
"solc": "solc8.19",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
],
"link": [],
"packages": [
"solidity-utils/=lib/aave-helpers/lib/solidity-utils/src",
"forge-std/=lib/aave-helpers/lib/forge-std/src",
"solidity-utils/=lib/solidity-utils/src",
"forge-std/=lib/solidity-utils/lib/forge-std/src",
"openzeppelin-contracts/=lib/openzeppelin-contracts",
"aave-helpers/=lib/aave-helpers/src",
"aave-address-book/=lib/aave-helpers/lib/aave-address-book/src",
],
"verify": "CrossChainForwarderHarness:security/certora/specs/CrossChainForwarder-envelopRetry.spec",
"solc": "solc8.19",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
],
"link": [],
"packages": [
"solidity-utils/=lib/aave-helpers/lib/solidity-utils/src",
"forge-std/=lib/aave-helpers/lib/forge-std/src",
"solidity-utils/=lib/solidity-utils/src",
"forge-std/=lib/solidity-utils/lib/forge-std/src",
"openzeppelin-contracts/=lib/openzeppelin-contracts",
"aave-helpers/=lib/aave-helpers/src",
"aave-address-book/=lib/aave-helpers/lib/aave-address-book/src",
],
"verify": "CrossChainForwarderHarness:security/certora/specs/invariants.spec",
"solc": "solc8.19",
Expand Down
Loading

0 comments on commit 5a9a33a

Please sign in to comment.