Skip to content

Commit

Permalink
add dummy contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
zkbenny committed Feb 3, 2024
1 parent 2bc7526 commit ff78e5b
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 32 deletions.
31 changes: 31 additions & 0 deletions contracts/dev-contracts/DummyArbitrator.sol
Original file line number Diff line number Diff line change
@@ -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);
}
}
47 changes: 47 additions & 0 deletions contracts/dev-contracts/DummyZkLink.sol
Original file line number Diff line number Diff line change
@@ -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);
}
}
16 changes: 14 additions & 2 deletions script/deploy_arbitrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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];
Expand All @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions script/deploy_eth_gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 7 additions & 7 deletions script/deploy_l1_gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 7 additions & 7 deletions script/deploy_l2_gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
30 changes: 21 additions & 9 deletions script/deploy_zklink.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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];
Expand All @@ -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);
Expand Down

0 comments on commit ff78e5b

Please sign in to comment.