diff --git a/contracts/dev-contracts/DummyArbitrator.sol b/contracts/dev-contracts/DummyArbitrator.sol new file mode 100644 index 0000000..31d6619 --- /dev/null +++ b/contracts/dev-contracts/DummyArbitrator.sol @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 + +pragma solidity ^0.8.0; + +import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; +import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; +import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; +import {IArbitrator} from "../interfaces/IArbitrator.sol"; +import {IL1Gateway} from "../interfaces/IL1Gateway.sol"; + +contract DummyArbitrator is IArbitrator, OwnableUpgradeable, UUPSUpgradeable, ReentrancyGuardUpgradeable { + event ReceiveMessage(uint256 value, bytes callData); + + function initialize() external initializer { + __Ownable_init(); + __UUPSUpgradeable_init(); + __ReentrancyGuard_init(); + } + + function _authorizeUpgrade(address newImplementation) internal override onlyOwner {} + + function receiveMessage(uint256 _value, bytes memory _callData) external payable { + require(msg.value == _value, "Invalid msg value"); + emit ReceiveMessage(_value, _callData); + } + + function forwardMessage(IL1Gateway _gateway, uint256 _value, bytes memory _callData, bytes memory _adapterParams) external payable { + // Forward fee to send message + _gateway.sendMessage{value: msg.value + _value}(_value, _callData, _adapterParams); + } +} \ No newline at end of file diff --git a/contracts/dev-contracts/DummyZkLink.sol b/contracts/dev-contracts/DummyZkLink.sol new file mode 100644 index 0000000..c35dbf0 --- /dev/null +++ b/contracts/dev-contracts/DummyZkLink.sol @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 + +pragma solidity ^0.8.0; + +import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; +import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; +import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; +import {IL2Gateway} from "../interfaces/IL2Gateway.sol"; +import {IZkLink} from "../interfaces/IZkLink.sol"; + +contract DummyZkLink is IZkLink, OwnableUpgradeable, UUPSUpgradeable, ReentrancyGuardUpgradeable { + IL2Gateway public gateway; + + event ReceiveBatchRoot(uint256 batchNumber, bytes32 l2LogsRootHash); + event ReceiveL2TxHash(bytes32 l2TxHash, bytes32 primaryChainL2TxHash); + + modifier onlyGateway() { + require(msg.sender == address(gateway), "Not gateway"); + _; + } + + function initialize() external initializer { + __Ownable_init(); + __UUPSUpgradeable_init(); + __ReentrancyGuard_init(); + } + + function _authorizeUpgrade(address newImplementation) internal override onlyOwner {} + + function setGateway(IL2Gateway _gateway) external { + require(address(gateway) == address(0), "Duplicate init gateway"); + gateway = _gateway; + } + + function syncL2Requests(uint256 _newTotalSyncedPriorityTxs) external payable { + bytes memory callData = abi.encode(msg.value, _newTotalSyncedPriorityTxs); + gateway.sendMessage(msg.value, callData); + } + + function syncBatchRoot(uint256 _batchNumber, bytes32 _l2LogsRootHash) external onlyGateway { + emit ReceiveBatchRoot(_batchNumber, _l2LogsRootHash); + } + + function syncL2TxHash(bytes32 _l2TxHash, bytes32 _primaryChainL2TxHash) external onlyGateway { + emit ReceiveL2TxHash(_l2TxHash, _primaryChainL2TxHash); + } +} \ No newline at end of file diff --git a/script/deploy_arbitrator.js b/script/deploy_arbitrator.js index 1bd8bc1..8b64b23 100644 --- a/script/deploy_arbitrator.js +++ b/script/deploy_arbitrator.js @@ -3,14 +3,21 @@ const { getImplementationAddress } = require("@openzeppelin/upgrades-core"); const { verifyContractCode, createOrGetDeployLog, ChainContractDeployer, getDeployTx} = require("./utils"); const logName = require("./deploy_log_name"); +function getArbitratorContractName(dummy) { + return dummy ? "DummyArbitrator": "Arbitrator"; +} + task("deployArbitrator", "Deploy arbitrator") .addParam("force", "Fore redeploy all contracts", false, types.boolean, true) .addParam("skipVerify", "Skip verify", false, types.boolean, true) + .addParam("dummy", "Deploy dummy contract for test", false, types.boolean, true) .setAction(async (taskArgs, hardhat) => { let force = taskArgs.force; let skipVerify = taskArgs.skipVerify; + let dummy = taskArgs.dummy; console.log('force redeploy all contracts?', force); console.log('skip verify contracts?', skipVerify); + console.log('deploy dummy contracts?', dummy); const contractDeployer = new ChainContractDeployer(hardhat); await contractDeployer.init(); @@ -24,7 +31,8 @@ task("deployArbitrator", "Deploy arbitrator") let arbitratorAddr; if (!(logName.DEPLOY_LOG_ARBITRATOR in deployLog) || force) { console.log('deploy arbitrator...'); - const contract = await contractDeployer.deployProxy("Arbitrator"); + const contractName = getArbitratorContractName(dummy); + const contract = await contractDeployer.deployProxy(contractName); const transaction = await getDeployTx(contract); arbitratorAddr = await contract.getAddress(); deployLog[logName.DEPLOY_LOG_ARBITRATOR] = arbitratorAddr; @@ -67,9 +75,12 @@ task("deployArbitrator", "Deploy arbitrator") task("upgradeArbitrator","Upgrade arbitrator") .addParam("skipVerify", "Skip verify", false, types.boolean, true) + .addParam("dummy", "Deploy dummy contract for test", false, types.boolean, true) .setAction(async (taskArgs,hardhat)=>{ let skipVerify = taskArgs.skipVerify; + let dummy = taskArgs.dummy; console.log("skipVerify", skipVerify); + console.log('deploy dummy contracts?', dummy); const { deployLogPath, deployLog } = createOrGetDeployLog(logName.DEPLOY_ARBITRATOR_LOG_PREFIX); const contractAddr = deployLog[logName.DEPLOY_LOG_ARBITRATOR]; @@ -89,7 +100,8 @@ task("upgradeArbitrator","Upgrade arbitrator") await contractDeployer.init(); console.log("upgrade arbitrator..."); - const contract = await contractDeployer.upgradeProxy("Arbitrator", contractAddr); + const contractName = getArbitratorContractName(dummy); + const contract = await contractDeployer.upgradeProxy(contractName, contractAddr); const tx = await getDeployTx(contract); console.log('upgrade tx', tx.hash); const newContractTargetAddr = await getImplementationAddress(hardhat.ethers.provider, contractAddr); diff --git a/script/deploy_eth_gateway.js b/script/deploy_eth_gateway.js index d300b05..cebe806 100644 --- a/script/deploy_eth_gateway.js +++ b/script/deploy_eth_gateway.js @@ -63,19 +63,19 @@ task("deployETHGateway", "Deploy ETH Gateway") } console.log("eth gateway target", gatewayTargetAddr); - // verify proxy contract - if ((!(logName.DEPLOY_GATEWAY_VERIFIED in deployLog) || force) && !skipVerify) { - await verifyContractCode(hardhat, gatewayAddr, []); - deployLog[logName.DEPLOY_GATEWAY_VERIFIED] = true; - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - } - // verify target contract if ((!(logName.DEPLOY_GATEWAY_TARGET_VERIFIED in deployLog) || force) && !skipVerify) { await verifyContractCode(hardhat, gatewayTargetAddr, []); deployLog[logName.DEPLOY_GATEWAY_TARGET_VERIFIED] = true; fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); } + + // verify proxy contract + if ((!(logName.DEPLOY_GATEWAY_VERIFIED in deployLog) || force) && !skipVerify) { + await verifyContractCode(hardhat, gatewayAddr, []); + deployLog[logName.DEPLOY_GATEWAY_VERIFIED] = true; + fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + } }); task("upgradeETHGateway","Upgrade ETH gateway") diff --git a/script/deploy_l1_gateway.js b/script/deploy_l1_gateway.js index 59ceb9d..8de1668 100644 --- a/script/deploy_l1_gateway.js +++ b/script/deploy_l1_gateway.js @@ -74,19 +74,19 @@ task("deployL1Gateway", "Deploy L1 Gateway") } console.log("l1 gateway target", gatewayTargetAddr); - // verify proxy contract - if ((!(logName.DEPLOY_GATEWAY_VERIFIED in deployLog) || force) && !skipVerify) { - await verifyContractCode(hardhat, gatewayAddr, []); - deployLog[logName.DEPLOY_GATEWAY_VERIFIED] = true; - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - } - // verify target contract if ((!(logName.DEPLOY_GATEWAY_TARGET_VERIFIED in deployLog) || force) && !skipVerify) { await verifyContractCode(hardhat, gatewayTargetAddr, []); deployLog[logName.DEPLOY_GATEWAY_TARGET_VERIFIED] = true; fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); } + + // verify proxy contract + if ((!(logName.DEPLOY_GATEWAY_VERIFIED in deployLog) || force) && !skipVerify) { + await verifyContractCode(hardhat, gatewayAddr, []); + deployLog[logName.DEPLOY_GATEWAY_VERIFIED] = true; + fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + } }); task("upgradeL1Gateway","Upgrade l1 gateway") diff --git a/script/deploy_l2_gateway.js b/script/deploy_l2_gateway.js index d7e31ed..0794a47 100644 --- a/script/deploy_l2_gateway.js +++ b/script/deploy_l2_gateway.js @@ -71,19 +71,19 @@ task("deployL2Gateway", "Deploy L2 Gateway") } console.log("l2 gateway target", gatewayTargetAddr); - // verify proxy contract - if ((!(logName.DEPLOY_GATEWAY_VERIFIED in deployLog) || force) && !skipVerify) { - await verifyContractCode(hardhat, gatewayAddr, []); - deployLog[logName.DEPLOY_GATEWAY_VERIFIED] = true; - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - } - // verify target contract if ((!(logName.DEPLOY_GATEWAY_TARGET_VERIFIED in deployLog) || force) && !taskArgs.skipVerify) { await verifyContractCode(hardhat, gatewayTargetAddr, []); deployLog[logName.DEPLOY_GATEWAY_TARGET_VERIFIED] = true; fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); } + + // verify proxy contract + if ((!(logName.DEPLOY_GATEWAY_VERIFIED in deployLog) || force) && !skipVerify) { + await verifyContractCode(hardhat, gatewayAddr, []); + deployLog[logName.DEPLOY_GATEWAY_VERIFIED] = true; + fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + } }); task("upgradeL2Gateway","Upgrade L2 gateway") diff --git a/script/deploy_zklink.js b/script/deploy_zklink.js index bafffb2..3f3cb2e 100644 --- a/script/deploy_zklink.js +++ b/script/deploy_zklink.js @@ -3,14 +3,21 @@ const { getImplementationAddress } = require("@openzeppelin/upgrades-core"); const { verifyContractCode, createOrGetDeployLog, ChainContractDeployer, getDeployTx} = require("./utils"); const logName = require("./deploy_log_name"); +function getZkLinkContractName(dummy) { + return dummy ? "DummyZkLink": "ZkLink"; +} + task("deployZkLink", "Deploy zkLink") .addParam("force", "Fore redeploy all contracts", false, types.boolean, true) .addParam("skipVerify", "Skip verify", false, types.boolean, true) + .addParam("dummy", "Deploy dummy contract for test", false, types.boolean, true) .setAction(async (taskArgs, hardhat) => { let force = taskArgs.force; let skipVerify = taskArgs.skipVerify; + let dummy = taskArgs.dummy; console.log('force redeploy all contracts?', force); console.log('skip verify contracts?', skipVerify); + console.log('deploy dummy contracts?', dummy); const contractDeployer = new ChainContractDeployer(hardhat); await contractDeployer.init(); @@ -24,7 +31,8 @@ task("deployZkLink", "Deploy zkLink") let zkLinkAddr; if (!(logName.DEPLOY_LOG_ZKLINK_PROXY in deployLog) || force) { console.log('deploy zkLink...'); - const contract = await contractDeployer.deployProxy("ZkLink"); + const contractName = getZkLinkContractName(dummy); + const contract = await contractDeployer.deployProxy(contractName); const transaction = await getDeployTx(contract); zkLinkAddr = await contract.getAddress(); deployLog[logName.DEPLOY_LOG_ZKLINK_PROXY] = zkLinkAddr; @@ -50,26 +58,29 @@ task("deployZkLink", "Deploy zkLink") } console.log("zkLink target", zkLinkTargetAddr); - // verify proxy contract - if ((!(logName.DEPLOY_LOG_ZKLINK_PROXY_VERIFIED in deployLog) || force) && !skipVerify) { - await verifyContractCode(hardhat, zkLinkAddr, []); - deployLog[logName.DEPLOY_LOG_ZKLINK_PROXY_VERIFIED] = true; - fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); - } - // verify target contract if ((!(logName.DEPLOY_LOG_ZKLINK_TARGET_VERIFIED in deployLog) || force) && !skipVerify) { await verifyContractCode(hardhat, zkLinkTargetAddr, []); deployLog[logName.DEPLOY_LOG_ZKLINK_TARGET_VERIFIED] = true; fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); } + + // verify proxy contract + if ((!(logName.DEPLOY_LOG_ZKLINK_PROXY_VERIFIED in deployLog) || force) && !skipVerify) { + await verifyContractCode(hardhat, zkLinkAddr, []); + deployLog[logName.DEPLOY_LOG_ZKLINK_PROXY_VERIFIED] = true; + fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); + } }); task("upgradeZkLink","Upgrade zkLink") .addParam("skipVerify", "Skip verify", false, types.boolean, true) + .addParam("dummy", "Deploy dummy contract for test", false, types.boolean, true) .setAction(async (taskArgs,hardhat)=>{ let skipVerify = taskArgs.skipVerify; + let dummy = taskArgs.dummy; console.log("skipVerify", skipVerify); + console.log('deploy dummy contracts?', dummy); const { deployLogPath, deployLog } = createOrGetDeployLog(logName.DEPLOY_ZKLINK_LOG_PREFIX); const contractAddr = deployLog[logName.DEPLOY_LOG_ZKLINK_PROXY]; @@ -89,7 +100,8 @@ task("upgradeZkLink","Upgrade zkLink") await contractDeployer.init(); console.log("upgrade zkLink..."); - const contract = await contractDeployer.upgradeProxy("ZkLink", contractAddr); + const contractName = getZkLinkContractName(dummy); + const contract = await contractDeployer.upgradeProxy(contractName, contractAddr); const tx = await getDeployTx(contract); console.log('upgrade tx', tx.hash); const newContractTargetAddr = await getImplementationAddress(hardhat.ethers.provider, contractAddr);