diff --git a/.gitignore b/.gitignore index 211272a..7f9f0fb 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,9 @@ apidoc/ node_modules artifacts/ +hardhat.config.js +truffle-config.js +migrations/ +document/ +go_abi/ +cache/ diff --git a/contracts/core/assets/LPToken_template/LPToken.sol b/contracts/core/assets/LPToken_template/LPToken.sol new file mode 100644 index 0000000..944b36a --- /dev/null +++ b/contracts/core/assets/LPToken_template/LPToken.sol @@ -0,0 +1,13 @@ +pragma solidity ^0.5.0; + +import "./../../../libs/GSN/Context.sol"; +import "./../../../libs/token/ERC20/ERC20.sol"; +import "./../../../libs/token/ERC20/ERC20Detailed.sol"; + +contract LPToken is Context, ERC20, ERC20Detailed { + + constructor(string memory name, string memory symbol, uint8 decimal, address initReceiver, uint initAmount) + public ERC20Detailed(name, symbol, decimal) { + _mint(initReceiver, initAmount); + } +} \ No newline at end of file diff --git a/contracts/core/cross_chain_manager/interface/IEventWitness.sol b/contracts/core/cross_chain_manager/interface/IEventWitness.sol new file mode 100644 index 0000000..7051d1f --- /dev/null +++ b/contracts/core/cross_chain_manager/interface/IEventWitness.sol @@ -0,0 +1,6 @@ +pragma solidity ^0.5.0; + +interface IEventWitness { + event EventWitnessed(address indexed sender, bytes32 indexed hash); + function witness(bytes calldata evt) external ; +} \ No newline at end of file diff --git a/contracts/core/cross_chain_manager/logic/EthCrossChainManager.sol b/contracts/core/cross_chain_manager/logic/EthCrossChainManager.sol index 8880f6b..8f6165c 100644 --- a/contracts/core/cross_chain_manager/logic/EthCrossChainManager.sol +++ b/contracts/core/cross_chain_manager/logic/EthCrossChainManager.sol @@ -9,9 +9,11 @@ import "./../upgrade/UpgradableECCM.sol"; import "./../libs/EthCrossChainUtils.sol"; import "./../interface/IEthCrossChainManager.sol"; import "./../interface/IEthCrossChainData.sol"; +import "./../interface/IEventWitness.sol"; contract EthCrossChainManager is IEthCrossChainManager, UpgradableECCM { using SafeMath for uint256; + address constant EVENT_WITNESS = ; // add mainnet witness address here address public whiteLister; mapping(address => bool) public whiteListFromContract; mapping(address => mapping(bytes => bool)) public whiteListContractMethodMap; @@ -177,6 +179,10 @@ contract EthCrossChainManager is IEthCrossChainManager, UpgradableECCM { // Fire the cross chain event denoting there is a cross chain request from Ethereum network to other public chains through Poly chain network emit CrossChainEvent(tx.origin, paramTxHash, msg.sender, toChainId, toContract, rawParam); + + // call EventWitness for ont-evm + IEventWitness(EVENT_WITNESS).witness(rawParam); + return true; } /* @notice Verify Poly chain header and proof, execute the cross chain tx from Poly chain to Ethereum diff --git a/contracts/core/cross_chain_manager/logic/EthCrossChainManagerForTest.sol b/contracts/core/cross_chain_manager/logic/EthCrossChainManagerForTest.sol new file mode 100644 index 0000000..47891fe --- /dev/null +++ b/contracts/core/cross_chain_manager/logic/EthCrossChainManagerForTest.sol @@ -0,0 +1,213 @@ +pragma solidity ^0.5.16; + +import "./../../../libs/math/SafeMath.sol"; +import "./../../../libs/common/ZeroCopySource.sol"; +import "./../../../libs/common/ZeroCopySink.sol"; +import "./../../../libs/utils/Utils.sol"; +import "./../upgrade/UpgradableECCM.sol"; +import "./../libs/EthCrossChainUtils.sol"; +import "./../interface/IEthCrossChainManager.sol"; +import "./../interface/IEthCrossChainData.sol"; +import "./../interface/IEventWitness.sol"; +contract EthCrossChainManagerForTest is IEthCrossChainManager, UpgradableECCM { + using SafeMath for uint256; + + address constant EVENT_WITNESS = 0x2b1143484bf5097A29678FD9592f75FE4639CA08; + event InitGenesisBlockEvent(uint256 height, bytes rawHeader); + event ChangeBookKeeperEvent(uint256 height, bytes rawHeader); + event CrossChainEvent(address indexed sender, bytes txId, address proxyOrAssetContract, uint64 toChainId, bytes toContract, bytes rawdata); + event VerifyHeaderAndExecuteTxEvent(uint64 fromChainID, bytes toContract, bytes crossChainTxHash, bytes fromChainTxHash); + constructor( + address _eccd, + uint64 _chainId + ) UpgradableECCM(_eccd,_chainId) public {} + + /* @notice sync Poly chain genesis block header to smart contrat + * @dev this function can only be called once, nextbookkeeper of rawHeader can't be empty + * @param rawHeader Poly chain genesis block raw header or raw Header including switching consensus peers info + * @return true or false + */ + function initGenesisBlock(bytes memory rawHeader, bytes memory pubKeyList) whenNotPaused public returns(bool) { + // Load Ethereum cross chain data contract + IEthCrossChainData eccd = IEthCrossChainData(EthCrossChainDataAddress); + + // Make sure the contract has not been initialized before + require(eccd.getCurEpochConPubKeyBytes().length == 0, "EthCrossChainData contract has already been initialized!"); + + // Parse header and convit the public keys into nextBookKeeper and compare it with header.nextBookKeeper to verify the validity of signature + ECCUtils.Header memory header = ECCUtils.deserializeHeader(rawHeader); + (bytes20 nextBookKeeper, address[] memory keepers) = ECCUtils.verifyPubkey(pubKeyList); + require(header.nextBookkeeper == nextBookKeeper, "NextBookers illegal"); + + // Record current epoch start height and public keys (by storing them in address format) + require(eccd.putCurEpochStartHeight(header.height), "Save Poly chain current epoch start height to Data contract failed!"); + require(eccd.putCurEpochConPubKeyBytes(ECCUtils.serializeKeepers(keepers)), "Save Poly chain current epoch book keepers to Data contract failed!"); + + // Fire the event + emit InitGenesisBlockEvent(header.height, rawHeader); + return true; + } + + /* @notice change Poly chain consensus book keeper + * @param rawHeader Poly chain change book keeper block raw header + * @param pubKeyList Poly chain consensus nodes public key list + * @param sigList Poly chain consensus nodes signature list + * @return true or false + */ + function changeBookKeeper(bytes memory rawHeader, bytes memory pubKeyList, bytes memory sigList) whenNotPaused public returns(bool) { + // Load Ethereum cross chain data contract + ECCUtils.Header memory header = ECCUtils.deserializeHeader(rawHeader); + IEthCrossChainData eccd = IEthCrossChainData(EthCrossChainDataAddress); + + // Make sure rawHeader.height is higher than recorded current epoch start height + uint64 curEpochStartHeight = eccd.getCurEpochStartHeight(); + require(header.height > curEpochStartHeight, "The height of header is lower than current epoch start height!"); + + // Ensure the rawHeader is the key header including info of switching consensus peers by containing non-empty nextBookKeeper field + require(header.nextBookkeeper != bytes20(0), "The nextBookKeeper of header is empty"); + + // Verify signature of rawHeader comes from pubKeyList + address[] memory polyChainBKs = ECCUtils.deserializeKeepers(eccd.getCurEpochConPubKeyBytes()); + uint n = polyChainBKs.length; + require(ECCUtils.verifySig(rawHeader, sigList, polyChainBKs, n - (n - 1) / 3), "Verify signature failed!"); + + // Convert pubKeyList into ethereum address format and make sure the compound address from the converted ethereum addresses + // equals passed in header.nextBooker + (bytes20 nextBookKeeper, address[] memory keepers) = ECCUtils.verifyPubkey(pubKeyList); + require(header.nextBookkeeper == nextBookKeeper, "NextBookers illegal"); + + // update current epoch start height of Poly chain and current epoch consensus peers book keepers addresses + require(eccd.putCurEpochStartHeight(header.height), "Save MC LatestHeight to Data contract failed!"); + require(eccd.putCurEpochConPubKeyBytes(ECCUtils.serializeKeepers(keepers)), "Save Poly chain book keepers bytes to Data contract failed!"); + + // Fire the change book keeper event + emit ChangeBookKeeperEvent(header.height, rawHeader); + return true; + } + + + /* @notice ERC20 token cross chain to other blockchain. + * this function push tx event to blockchain + * @param toChainId Target chain id + * @param toContract Target smart contract address in target block chain + * @param txData Transaction data for target chain, include to_address, amount + * @return true or false + */ + function crossChain(uint64 toChainId, bytes calldata toContract, bytes calldata method, bytes calldata txData) whenNotPaused external returns (bool) { + + // Load Ethereum cross chain data contract + IEthCrossChainData eccd = IEthCrossChainData(EthCrossChainDataAddress); + + // To help differentiate two txs, the ethTxHashIndex is increasing automatically + uint256 txHashIndex = eccd.getEthTxHashIndex(); + + // Convert the uint256 into bytes + bytes memory paramTxHash = Utils.uint256ToBytes(txHashIndex); + + // Construct the makeTxParam, and put the hash info storage, to help provide proof of tx existence + bytes memory rawParam = abi.encodePacked(ZeroCopySink.WriteVarBytes(paramTxHash), + ZeroCopySink.WriteVarBytes(abi.encodePacked(sha256(abi.encodePacked(address(this), paramTxHash)))), + ZeroCopySink.WriteVarBytes(Utils.addressToBytes(msg.sender)), + ZeroCopySink.WriteUint64(toChainId), + ZeroCopySink.WriteVarBytes(toContract), + ZeroCopySink.WriteVarBytes(method), + ZeroCopySink.WriteVarBytes(txData) + ); + + // Must save it in the storage to be included in the proof to be verified. + require(eccd.putEthTxHash(keccak256(rawParam)), "Save ethTxHash by index to Data contract failed!"); + + // Fire the cross chain event denoting there is a cross chain request from Ethereum network to other public chains through Poly chain network + emit CrossChainEvent(tx.origin, paramTxHash, msg.sender, toChainId, toContract, rawParam); + + // call EventWitness for ont-evm + IEventWitness(EVENT_WITNESS).witness(rawParam); + + return true; + } + /* @notice Verify Poly chain header and proof, execute the cross chain tx from Poly chain to Ethereum + * @param proof Poly chain tx merkle proof + * @param rawHeader The header containing crossStateRoot to verify the above tx merkle proof + * @param headerProof The header merkle proof used to verify rawHeader + * @param curRawHeader Any header in current epoch consensus of Poly chain + * @param headerSig The coverted signature veriable for solidity derived from Poly chain consensus nodes' signature + * used to verify the validity of curRawHeader + * @return true or false + */ + function verifyHeaderAndExecuteTx(bytes memory proof, bytes memory rawHeader, bytes memory headerProof, bytes memory curRawHeader,bytes memory headerSig) whenNotPaused public returns (bool){ + ECCUtils.Header memory header = ECCUtils.deserializeHeader(rawHeader); + // Load ehereum cross chain data contract + IEthCrossChainData eccd = IEthCrossChainData(EthCrossChainDataAddress); + + // Get stored consensus public key bytes of current poly chain epoch and deserialize Poly chain consensus public key bytes to address[] + address[] memory polyChainBKs = ECCUtils.deserializeKeepers(eccd.getCurEpochConPubKeyBytes()); + + uint256 curEpochStartHeight = eccd.getCurEpochStartHeight(); + + uint n = polyChainBKs.length; + if (header.height >= curEpochStartHeight) { + // It's enough to verify rawHeader signature + require(ECCUtils.verifySig(rawHeader, headerSig, polyChainBKs, n - ( n - 1) / 3), "Verify poly chain header signature failed!"); + } else { + // We need to verify the signature of curHeader + require(ECCUtils.verifySig(curRawHeader, headerSig, polyChainBKs, n - ( n - 1) / 3), "Verify poly chain current epoch header signature failed!"); + + // Then use curHeader.StateRoot and headerProof to verify rawHeader.CrossStateRoot + ECCUtils.Header memory curHeader = ECCUtils.deserializeHeader(curRawHeader); + bytes memory proveValue = ECCUtils.merkleProve(headerProof, curHeader.blockRoot); + require(ECCUtils.getHeaderHash(rawHeader) == Utils.bytesToBytes32(proveValue), "verify header proof failed!"); + } + + // Through rawHeader.CrossStatesRoot, the toMerkleValue or cross chain msg can be verified and parsed from proof + bytes memory toMerkleValueBs = ECCUtils.merkleProve(proof, header.crossStatesRoot); + + // Parse the toMerkleValue struct and make sure the tx has not been processed, then mark this tx as processed + ECCUtils.ToMerkleValue memory toMerkleValue = ECCUtils.deserializeMerkleValue(toMerkleValueBs); + require(!eccd.checkIfFromChainTxExist(toMerkleValue.fromChainID, Utils.bytesToBytes32(toMerkleValue.txHash)), "the transaction has been executed!"); + require(eccd.markFromChainTxExist(toMerkleValue.fromChainID, Utils.bytesToBytes32(toMerkleValue.txHash)), "Save crosschain tx exist failed!"); + + // Ethereum ChainId is 2, we need to check the transaction is for Ethereum network + require(toMerkleValue.makeTxParam.toChainId == chainId, "This Tx is not aiming at this network!"); + + // Obtain the targeting contract, so that Ethereum cross chain manager contract can trigger the executation of cross chain tx on Ethereum side + address toContract = Utils.bytesToAddress(toMerkleValue.makeTxParam.toContract); + require(toContract != EthCrossChainDataAddress, "No eccd here!"); + + //TODO: check this part to make sure we commit the next line when doing local net UT test + require(_executeCrossChainTx(toContract, toMerkleValue.makeTxParam.method, toMerkleValue.makeTxParam.args, toMerkleValue.makeTxParam.fromContract, toMerkleValue.fromChainID), "Execute CrossChain Tx failed!"); + + // Fire the cross chain event denoting the executation of cross chain tx is successful, + // and this tx is coming from other public chains to current Ethereum network + emit VerifyHeaderAndExecuteTxEvent(toMerkleValue.fromChainID, toMerkleValue.makeTxParam.toContract, toMerkleValue.txHash, toMerkleValue.makeTxParam.txHash); + + return true; + } + + /* @notice Dynamically invoke the targeting contract, and trigger executation of cross chain tx on Ethereum side + * @param _toContract The targeting contract that will be invoked by the Ethereum Cross Chain Manager contract + * @param _method At which method will be invoked within the targeting contract + * @param _args The parameter that will be passed into the targeting contract + * @param _fromContractAddr From chain smart contract address + * @param _fromChainId Indicate from which chain current cross chain tx comes + * @return true or false + */ + function _executeCrossChainTx(address _toContract, bytes memory _method, bytes memory _args, bytes memory _fromContractAddr, uint64 _fromChainId) internal returns (bool){ + // // Ensure the targeting contract gonna be invoked is indeed a contract rather than a normal account address + // require(Utils.isContract(_toContract), "The passed in address is not a contract!"); + // bytes memory returnData; + // bool success; + + // // The returnData will be bytes32, the last byte must be 01; + // (success, returnData) = _toContract.call(abi.encodePacked(bytes4(keccak256(abi.encodePacked(_method, "(bytes,bytes,uint64)"))), abi.encode(_args, _fromContractAddr, _fromChainId))); + + // // Ensure the executation is successful + // require(success == true, "EthCrossChain call business contract failed"); + + // // Ensure the returned value is true + // require(returnData.length != 0, "No return value from business contract!"); + // (bool res,) = ZeroCopySource.NextBool(returnData, 31); + // require(res == true, "EthCrossChain call business contract return is not true"); + + return true; + } +} \ No newline at end of file diff --git a/contracts/core/cross_chain_manager/logic/EthCrossChainManagerNoWhiteList.sol b/contracts/core/cross_chain_manager/logic/EthCrossChainManagerNoWhiteList.sol index 7eab1d5..d7e7b55 100644 --- a/contracts/core/cross_chain_manager/logic/EthCrossChainManagerNoWhiteList.sol +++ b/contracts/core/cross_chain_manager/logic/EthCrossChainManagerNoWhiteList.sol @@ -8,9 +8,11 @@ import "./../upgrade/UpgradableECCM.sol"; import "./../libs/EthCrossChainUtils.sol"; import "./../interface/IEthCrossChainManager.sol"; import "./../interface/IEthCrossChainData.sol"; +import "./../interface/IEventWitness.sol"; contract EthCrossChainManagerNoWhiteList is IEthCrossChainManager, UpgradableECCM { using SafeMath for uint256; + address constant EVENT_WITNESS = 0xA8a1c2E2739725a14072B0bB1C6FAb0B36C15952; // testnet event InitGenesisBlockEvent(uint256 height, bytes rawHeader); event ChangeBookKeeperEvent(uint256 height, bytes rawHeader); event CrossChainEvent(address indexed sender, bytes txId, address proxyOrAssetContract, uint64 toChainId, bytes toContract, bytes rawdata); @@ -117,6 +119,10 @@ contract EthCrossChainManagerNoWhiteList is IEthCrossChainManager, UpgradableECC // Fire the cross chain event denoting there is a cross chain request from Ethereum network to other public chains through Poly chain network emit CrossChainEvent(tx.origin, paramTxHash, msg.sender, toChainId, toContract, rawParam); + + // call EventWitness for ont-evm + IEventWitness(EVENT_WITNESS).witness(rawParam); + return true; } /* @notice Verify Poly chain header and proof, execute the cross chain tx from Poly chain to Ethereum diff --git a/contracts/core/wrapper/PolyWrapper_v1 b/contracts/core/wrapper/PolyWrapper_v1 new file mode 100644 index 0000000..3dc0380 --- /dev/null +++ b/contracts/core/wrapper/PolyWrapper_v1 @@ -0,0 +1,100 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.5.0; + +import "../../libs/token/ERC20/SafeERC20.sol"; +import "../../libs/token/ERC20/IERC20.sol"; +import "../../libs/ownership/Ownable.sol"; +import "../../libs/utils/ReentrancyGuard.sol"; +import "../../libs/math/SafeMath.sol"; +import "../../libs/lifecycle/Pausable.sol"; + +import "./interfaces/ILockProxy.sol"; + +contract PolyWrapper is Ownable, Pausable, ReentrancyGuard { + using SafeMath for uint; + using SafeERC20 for IERC20; + + uint public chainId; + address public feeCollector; + + ILockProxy public lockProxy; + + constructor(address _owner, uint _chainId) public { + require(_chainId != 0, "!legal"); + transferOwnership(_owner); + chainId = _chainId; + } + + function setFeeCollector(address collector) external onlyOwner { + require(collector != address(0), "emtpy address"); + feeCollector = collector; + } + + + function setLockProxy(address _lockProxy) external onlyOwner { + require(_lockProxy != address(0)); + lockProxy = ILockProxy(_lockProxy); + require(lockProxy.managerProxyContract() != address(0), "not lockproxy"); + } + + function pause() external onlyOwner { + _pause(); + } + + function unpause() external onlyOwner { + _unpause(); + } + + + function extractFee(address token) external { + require(msg.sender == feeCollector, "!feeCollector"); + if (token == address(0)) { + msg.sender.transfer(address(this).balance); + } else { + IERC20(token).safeTransfer(feeCollector, IERC20(token).balanceOf(address(this))); + } + } + + function lock(address fromAsset, uint64 toChainId, bytes memory toAddress, uint amount, uint fee, uint id) public payable nonReentrant whenNotPaused { + + require(toChainId != chainId && toChainId != 0, "!toChainId"); + require(amount > fee, "amount less than fee"); + require(toAddress.length !=0, "empty toAddress"); + address addr; + assembly { addr := mload(add(toAddress,0x14)) } + require(addr != address(0),"zero toAddress"); + + _pull(fromAsset, amount); + + _push(fromAsset, toChainId, toAddress, amount.sub(fee)); + + emit PolyWrapperLock(fromAsset, msg.sender, toChainId, toAddress, amount.sub(fee), fee, id); + } + + function speedUp(address fromAsset, bytes memory txHash, uint fee) public payable nonReentrant whenNotPaused { + _pull(fromAsset, fee); + emit PolyWrapperSpeedUp(fromAsset, txHash, msg.sender, fee); + } + + function _pull(address fromAsset, uint amount) internal { + if (fromAsset == address(0)) { + require(msg.value == amount, "insufficient ether"); + } else { + IERC20(fromAsset).safeTransferFrom(msg.sender, address(this), amount); + } + } + + function _push(address fromAsset, uint64 toChainId, bytes memory toAddress, uint amount) internal { + if (fromAsset == address(0)) { + require(lockProxy.lock.value(amount)(fromAsset, toChainId, toAddress, amount), "lock ether fail"); + } else { + IERC20(fromAsset).safeApprove(address(lockProxy), 0); + IERC20(fromAsset).safeApprove(address(lockProxy), amount); + require(lockProxy.lock(fromAsset, toChainId, toAddress, amount), "lock erc20 fail"); + } + } + + event PolyWrapperLock(address indexed fromAsset, address indexed sender, uint64 toChainId, bytes toAddress, uint net, uint fee, uint id); + event PolyWrapperSpeedUp(address indexed fromAsset, bytes indexed txHash, address indexed sender, uint efee); + +} diff --git a/contracts/mocks/core/ECCUtilsMock.sol b/contracts/mocks/core/ECCUtilsMock.sol new file mode 100644 index 0000000..50f28ec --- /dev/null +++ b/contracts/mocks/core/ECCUtilsMock.sol @@ -0,0 +1,91 @@ +pragma solidity 0.5.17; + +import "../../core/cross_chain_manager/libs/EthCrossChainUtils.sol"; + +contract ECCUtilsMock { + + function merkleProve(bytes memory _auditPath, bytes32 _root) public pure returns (bytes memory) { + return ECCUtils.merkleProve(_auditPath, _root); + } + + function verifySig(bytes memory _rawHeader, bytes memory _sigList, address[] memory _keepers, uint _m) public pure returns (bool){ + return ECCUtils.verifySig(_rawHeader, _sigList, _keepers, _m); + } + + function deserializeMerkleValue(bytes memory _valueBs) public pure + returns ( + bytes memory polyTxHash, + uint64 fromChainID, + bytes memory txHash, + // bytes memory crossChainId, // STACK TO DEEP + bytes memory fromContract, + uint64 toChainId, + bytes memory toContract, + bytes memory method, + bytes memory args + ) { + uint256 off = 0; + + (polyTxHash, off) = ZeroCopySource.NextVarBytes(_valueBs, off); + + (fromChainID, off) = ZeroCopySource.NextUint64(_valueBs, off); + + (txHash, off) = ZeroCopySource.NextVarBytes(_valueBs, off); + + (, off) = ZeroCopySource.NextVarBytes(_valueBs, off); + + (fromContract, off) = ZeroCopySource.NextVarBytes(_valueBs, off); + + (toChainId, off) = ZeroCopySource.NextUint64(_valueBs, off); + + (toContract, off) = ZeroCopySource.NextVarBytes(_valueBs, off); + + (method, off) = ZeroCopySource.NextVarBytes(_valueBs, off); + + (args, off) = ZeroCopySource.NextVarBytes(_valueBs, off); + + } + + function deserializeHeader(bytes memory _headerBs) public pure + returns ( + uint32 version, + uint64 chainId, + bytes32 prevBlockHash, + bytes32 transactionsRoot, + bytes32 crossStatesRoot, + bytes32 blockRoot, + uint32 timestamp, + uint32 height, + uint64 consensusData, + bytes memory consensusPayload, + bytes20 nextBookkeeper + ) { + uint256 off = 0; + (version, off) = ZeroCopySource.NextUint32(_headerBs, off); + + (chainId, off) = ZeroCopySource.NextUint64(_headerBs, off); + + (prevBlockHash, off) = ZeroCopySource.NextHash(_headerBs, off); + + (transactionsRoot, off) = ZeroCopySource.NextHash(_headerBs, off); + + (crossStatesRoot, off) = ZeroCopySource.NextHash(_headerBs, off); + + (blockRoot, off) = ZeroCopySource.NextHash(_headerBs, off); + + (timestamp, off) = ZeroCopySource.NextUint32(_headerBs, off); + + (height, off) = ZeroCopySource.NextUint32(_headerBs, off); + + (consensusData, off) = ZeroCopySource.NextUint64(_headerBs, off); + + (consensusPayload, off) = ZeroCopySource.NextVarBytes(_headerBs, off); + + (nextBookkeeper, off) = ZeroCopySource.NextBytes20(_headerBs, off); + + } + + function getHeaderHash(bytes memory rawHeader) public pure returns (bytes32) { + return ECCUtils.getHeaderHash(rawHeader); + } +} \ No newline at end of file diff --git a/contracts/mocks/libs/common/ZeroCopySourceMock.sol b/contracts/mocks/libs/common/ZeroCopySourceMock.sol index b865bf6..4ebf1ea 100644 --- a/contracts/mocks/libs/common/ZeroCopySourceMock.sol +++ b/contracts/mocks/libs/common/ZeroCopySourceMock.sol @@ -4,7 +4,7 @@ import "../../../../contracts/libs/common/ZeroCopySource.sol"; contract ZeroCopySourceMock { uint N = 10; - function NextBool(bytes memory _b, uint256 _off) public returns (bool, uint256) { + function NextBool(bytes memory _b, uint256 _off) public view returns (bool, uint256) { bool res; uint256 offset = 0; for (uint i = 0; i <= N; i++) { @@ -13,31 +13,31 @@ contract ZeroCopySourceMock { return ZeroCopySource.NextBool(_b, _off); } - function NextByte(bytes memory _b, uint256 _off) public returns (byte, uint256) { + function NextByte(bytes memory _b, uint256 _off) public pure returns (byte, uint256) { return ZeroCopySource.NextByte(_b, _off); } - function NextUint8(bytes memory _b, uint256 _off) public returns (uint8, uint256) { + function NextUint8(bytes memory _b, uint256 _off) public pure returns (uint8, uint256) { return ZeroCopySource.NextUint8(_b, _off); } - function NextUint16(bytes memory _b, uint256 _off) public returns (uint16, uint256) { + function NextUint16(bytes memory _b, uint256 _off) public pure returns (uint16, uint256) { return ZeroCopySource.NextUint16(_b, _off); } - function NextUint32(bytes memory _b, uint256 _off) public returns (uint32, uint256) { + function NextUint32(bytes memory _b, uint256 _off) public pure returns (uint32, uint256) { return ZeroCopySource.NextUint32(_b, _off); } - function NextUint64(bytes memory _b, uint256 _off) public returns (uint64, uint256) { + function NextUint64(bytes memory _b, uint256 _off) public pure returns (uint64, uint256) { return ZeroCopySource.NextUint64(_b, _off); } - function NextVarBytes(bytes memory _b, uint256 _off) public returns (bytes memory, uint256) { + function NextVarBytes(bytes memory _b, uint256 _off) public pure returns (bytes memory, uint256) { return ZeroCopySource.NextVarBytes(_b, _off); } - function NextHash(bytes memory _b, uint256 _off) public returns (bytes32, uint256) { + function NextHash(bytes memory _b, uint256 _off) public pure returns (bytes32, uint256) { return ZeroCopySource.NextHash(_b, _off); } @@ -45,14 +45,14 @@ contract ZeroCopySourceMock { // return ZeroCopySource.NextAddress(_b, _off); // } - function NextBytes20(bytes memory _b, uint256 _off) public returns (bytes20, uint256) { + function NextBytes20(bytes memory _b, uint256 _off) public pure returns (bytes20, uint256) { return ZeroCopySource.NextBytes20(_b, _off); } - function NextUint255(bytes memory _b, uint256 _off) public returns (uint256, uint256) { + function NextUint255(bytes memory _b, uint256 _off) public pure returns (uint256, uint256) { return ZeroCopySource.NextUint255(_b, _off); } - function NextVarUint(bytes memory _b, uint256 _off) public returns (uint, uint256) { + function NextVarUint(bytes memory _b, uint256 _off) public pure returns (uint, uint256) { return ZeroCopySource.NextVarUint(_b, _off); } } diff --git a/hardhatTests/EthCrossChainMangerTest.js b/hardhatTests/EthCrossChainMangerTest.js new file mode 100644 index 0000000..24c3448 --- /dev/null +++ b/hardhatTests/EthCrossChainMangerTest.js @@ -0,0 +1,212 @@ +const hre = require("hardhat"); +const colors = require('colors'); +const { expect } = require("chai"); + +describe('EthCrossChain', function() { + let deployer; + let addr1; + let eccd; + let eccm; + let eccmp; + let eccm1; + + it("should do deployment", async function() { + [deployer, addr1] = await hre.ethers.getSigners(); + const EthCrossChainData = await hre.ethers.getContractFactory("EthCrossChainData"); + const EthCrossChainManager = await hre.ethers.getContractFactory("EthCrossChainManagerForTest"); + const EthCrossChainManagerProxy = await hre.ethers.getContractFactory("EthCrossChainManagerProxy"); + + eccd = await EthCrossChainData.deploy(); + await eccd.deployed(); + console.log("eccd deployed to ",eccd.address.green); + + eccm = await EthCrossChainManager.deploy(eccd.address, 2); + await eccm.deployed(); + console.log("eccm deployed to ",eccm.address.green); + + eccmp = await EthCrossChainManagerProxy.deploy(eccm.address); + await eccmp.deployed(); + console.log("eccmp deployed to ",eccmp.address.green); + + eccm1 = await EthCrossChainManager.deploy(eccd.address, 2); + await eccm1.deployed(); + console.log("eccm1 deployed to ",eccm1.address.green); + }); + + describe("transferOwnership", function() { + it('this.ECCD.transferOwnership(this.ECCM.address) correctly', async function () { + tx = await eccd.transferOwnership(eccm.address); + await tx.wait(); + expect(await eccd.owner()).to.equal(eccm.address) + }) + it('this.ECCM.transferOwnership(this.ECCMP.address) correctly', async function () { + tx = await eccm.transferOwnership(eccmp.address); + await tx.wait(); + expect(await eccm.owner()).to.equal(eccmp.address) + }) + it('this.ECCMP.getEthCrossChainManager() correctly', async function () { + expect(await eccmp.getEthCrossChainManager()).to.equal(eccm.address) + }) + }); + + describe('initGenesisBlock', function () { + + const genesisHeader = '0x000000009b9156170000000000000000000000000000000000000000000000000000000000000000000000006de0a8f7ee3fb67d8e04ac9547f3615e59adc6e0a2309c90080a272dc1fa1fd90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c8365b000000001dac2b7c00000000fd1a057b226c6561646572223a343239343936373239352c227672665f76616c7565223a22484a675171706769355248566745716354626e6443456c384d516837446172364e4e646f6f79553051666f67555634764d50675851524171384d6f38373853426a2b38577262676c2b36714d7258686b667a72375751343d222c227672665f70726f6f66223a22785864422b5451454c4c6a59734965305378596474572f442f39542f746e5854624e436667354e62364650596370382f55706a524c572f536a5558643552576b75646632646f4c5267727052474b76305566385a69413d3d222c226c6173745f636f6e6669675f626c6f636b5f6e756d223a343239343936373239352c226e65775f636861696e5f636f6e666967223a7b2276657273696f6e223a312c2276696577223a312c226e223a372c2263223a322c22626c6f636b5f6d73675f64656c6179223a31303030303030303030302c22686173685f6d73675f64656c6179223a31303030303030303030302c22706565725f68616e647368616b655f74696d656f7574223a31303030303030303030302c227065657273223a5b7b22696e646578223a312c226964223a2231323035303238313732393138353430623262353132656165313837326132613265336132386439383963363064393564616238383239616461376437646437303664363538227d2c7b22696e646578223a322c226964223a2231323035303338623861663632313065636664636263616232323535326566386438636634316336663836663963663961623533643836353734316366646238333366303662227d2c7b22696e646578223a332c226964223a2231323035303234383261636236353634623139623930363533663665396338303632393265386161383366373865376139333832613234613665666534316330633036663339227d2c7b22696e646578223a342c226964223a2231323035303236373939333061343261616633633639373938636138613366313265313334633031393430353831386437383364313137343865303339646538353135393838227d2c7b22696e646578223a352c226964223a2231323035303234363864643138393965643264316363326238323938383261313635613065636236613734356166306337326562323938326436366234333131623465663733227d2c7b22696e646578223a362c226964223a2231323035303265623162616162363032633538393932383235363163646161613761616262636464306363666362633365373937393361633234616366393037373866333561227d2c7b22696e646578223a372c226964223a2231323035303331653037373966356335636362323631323335326665346132303066393964336537373538653730626135336636303763353966663232613330663637386666227d5d2c22706f735f7461626c65223a5b362c342c332c352c362c312c322c352c342c372c342c322c332c332c372c362c352c342c362c352c312c342c332c312c322c352c322c322c362c312c342c352c342c372c322c332c342c312c352c372c342c312c322c322c352c362c342c342c322c372c332c362c362c352c312c372c332c312c362c312c332c332c322c342c342c312c352c362c352c312c322c362c372c352c362c332c342c372c372c332c322c372c312c352c362c352c322c332c362c322c362c312c372c372c372c312c372c342c332c332c332c322c312c372c355d2c226d61785f626c6f636b5f6368616e67655f76696577223a36303030307d7d9fe171f3fe643eb1c188400b828ba184816fc9ac0000' + const genesisPubKey = '0x1205041e0779f5c5ccb2612352fe4a200f99d3e7758e70ba53f607c59ff22a30f678ff757519efff911efc7ed326890a2752b9456cc0054f9b63215f1d616e574d6197120504468dd1899ed2d1cc2b829882a165a0ecb6a745af0c72eb2982d66b4311b4ef73cff28a6492b076445337d8037c6c7be4d3ec9c4dbe8d7dc65d458181de7b5250120504482acb6564b19b90653f6e9c806292e8aa83f78e7a9382a24a6efe41c0c06f39ef0a95ee60ad9213eb0be343b703dd32b12db32f098350cf3f4fc3bad6db23ce120504679930a42aaf3c69798ca8a3f12e134c019405818d783d11748e039de8515988754f348293c65055f0f1a9a5e895e4e7269739e243a661fff801941352c387121205048172918540b2b512eae1872a2a2e3a28d989c60d95dab8829ada7d7dd706d658df044eb93bbe698eff62156fc14d6d07b7aebfbc1a98ec4180b4346e67cc3fb01205048b8af6210ecfdcbcab22552ef8d8cf41c6f86f9cf9ab53d865741cfdb833f06b72fcc7e7d8b9e738b565edf42d8769fd161178432eadb2e446dd0a8785ba088f120504eb1baab602c5899282561cdaaa7aabbcdd0ccfcbc3e79793ac24acf90778f35a059fca7f73aeb60666178db8f704b58452b7a0b86219402c0770fcb52ac9828c' + const genesisHeaderWithWrongBookKeeper = "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c033644e70a2b4f8de4a15c4a0cd79315673b8346d033804807058f3ff4252900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c8365b000000001dac2b7c00000000fd1a057b226c6561646572223a343239343936373239352c227672665f76616c7565223a22484a675171706769355248566745716354626e6443456c384d516837446172364e4e646f6f79553051666f67555634764d50675851524171384d6f38373853426a2b38577262676c2b36714d7258686b667a72375751343d222c227672665f70726f6f66223a22785864422b5451454c4c6a59734965305378596474572f442f39542f746e5854624e436667354e62364650596370382f55706a524c572f536a5558643552576b75646632646f4c5267727052474b76305566385a69413d3d222c226c6173745f636f6e6669675f626c6f636b5f6e756d223a343239343936373239352c226e65775f636861696e5f636f6e666967223a7b2276657273696f6e223a312c2276696577223a312c226e223a372c2263223a322c22626c6f636b5f6d73675f64656c6179223a31303030303030303030302c22686173685f6d73675f64656c6179223a31303030303030303030302c22706565725f68616e647368616b655f74696d656f7574223a31303030303030303030302c227065657273223a5b7b22696e646578223a312c226964223a2231323035303364313031383338383037656334303739613436666539386436626439613036393061626362643863653136653066626334353230633763376566373838356462227d2c7b22696e646578223a322c226964223a2231323035303361366231623065316336393737663434663336323332613566336236316236613835396234636535313437633439616363666139613432663438336631323034227d2c7b22696e646578223a332c226964223a2231323035303266663764666337303562623561633638643265383932333063363632393939616562313832383431333165396663653934656639666166356239393137353364227d2c7b22696e646578223a342c226964223a2231323035303334343031376363636138323064393066306562623436316466343633333762303932336230616532626365353833636565316132363234633932303865323038227d2c7b22696e646578223a352c226964223a2231323035303331326631303233393531333134336330323938346263346561396438353438383366636466343937333264633732376466613734373438326663383037653634227d2c7b22696e646578223a362c226964223a2231323035303333336334343833376464623934616435666130656234363062306634393135346639303530333631396434643263386565303833333066623831353834316432227d2c7b22696e646578223a372c226964223a2231323035303363366536383165353135346566626136346337356230616131636135343438396261653736353330373764313664646439373236663336356265333036323264227d5d2c22706f735f7461626c65223a5b362c352c342c332c372c322c372c372c352c352c322c322c322c322c362c352c322c342c312c332c342c312c342c332c332c322c342c352c372c312c342c332c342c352c332c352c352c342c322c312c342c332c312c352c352c352c322c362c342c332c312c362c322c322c312c332c332c322c332c372c372c362c342c342c362c372c372c362c322c362c372c372c312c332c342c312c352c362c322c372c342c342c362c352c312c332c352c372c352c332c312c362c312c322c362c362c312c372c362c362c372c332c372c312c315d2c226d61785f626c6f636b5f6368616e67655f76696577223a31303030307d7da969bae1168780e35a40c4d1af2dede531fd6fb8"; + it('initGenesisBlock revert since wrong bookkeeper', async function () { + expect(await eccmp.paused()).to.equal(false); + await expect(eccm.initGenesisBlock(genesisHeaderWithWrongBookKeeper, genesisPubKey)).to.be.revertedWith("NextBookers illegal"); + }); + it('initGenesisBlock correctly', async function () { + expect(await eccmp.paused()).to.equal(false); + const expectedCurEpochStartHeight = 0; + + await expect(eccm.initGenesisBlock(genesisHeader, genesisPubKey)) + .to.emit(eccm, 'InitGenesisBlockEvent') + .withArgs(expectedCurEpochStartHeight, genesisHeader); + + // let storedCEPKB = await eccd.getCurEpochConPubKeyBytes(); + // console.log('stored Consensu Peers public key book keeper is: ', storedCEPKB); + expect(await eccd.getCurEpochStartHeight()).to.equal(expectedCurEpochStartHeight); + + }); + + it('InitGenesisBlock throws error on InitGenesisBlock twice', async function () { + await expect(eccm.initGenesisBlock(genesisHeaderWithWrongBookKeeper, genesisPubKey)) + .to.be.revertedWith("EthCrossChainData contract has already been initialized!"); + }); + + }); + + describe('verifyHeaderAndExecuteTx', function () { + const proofx = '0xd72000ca93f8738111a063d8ab7221f47c70a4cade0ca4a2829df494cd4b5e231bd60300000000000000204caa77a3d2ddfaa318c550f1f38dd09d610dcff827d1f2ccd4ddcafaa6c553cc081b0000000000000014b7041bc96b15da728fdfc1c47cbfc687b845adeb0200000000000000144ddcf539d13e92d4151b7f5e607d4a09f725c47d06756e6c6f636b4a14406d31a9291bdaed4f4bc31b97dc468f88256ded14344cfc3b8635f72f14200aaf2168d9f75df86fd353000000000000000000000000000000000000000000000000000000000000000177d99c0f0857535155071d49ded129993a5b98575761985e90e2d26c7a569a0d'; + const blockHeaderx1 = '0x000000009b91561700000000622b986e745766256e1b3bb6b478d3da265614dc3a481a1ece3c02a499cbec5c00000000000000000000000000000000000000000000000000000000000000008d8021b0dffcf4361f82ac31b6f990da35f304c1d11342b59b80bd836a8af94d9b970da4cb85cb93e406ce857353c33223b7558aad3f5c903bbd838fce0650314417185f9e43000082ad40a6f1e63ecffd0c017b226c6561646572223a322c227672665f76616c7565223a22424a4f784a3942326b4e446c48736a533359424150386b34414d4e446a716e7a4b32624c5839485576576272497a6d502f48425874783541654e626242436b48306c5734746f4a697455783947304d2b6d3350394677413d222c227672665f70726f6f66223a2258514a30514145775474586c5675594d68454f2f766e566f75776b394442416f4b686962506d3042706e6d3854436e7034334d73767455323868436f6c6c6c5075685573764b34647a7935416e34577730576d4639673d3d222c226c6173745f636f6e6669675f626c6f636b5f6e756d223a302c226e65775f636861696e5f636f6e666967223a6e756c6c7d0000000000000000000000000000000000000000' + const headerProofx = '0x' + const curRawHeader = '0x' + const signaturesx1 = '0x63fd63a8448a034a594c7e34034c0455628c3e879e6981e879b6f20ad1994f3e349d5021592a10908074d5ffc3d72384ee7dbfa7ad4b41388944c22dd3276bc701b046097a68620061598e5c59367f1faab18548ece6c8d6aca1572f95eee3915623eeba8a9c06a1886a16bd019f0d294fc1b204f273a32f4fcfcec994368827f00187206061136d01eb706c1950926d2986d20c3cc879977ccecbae6f8771dfc8873e9c269122575c7493a424f8cce1144e33115ed2402af40f141caf53fef4869500dc9caa49811f4d63c22752906cbfc03bf0bc646699cd82d143c349ab871bf6580102c40a38f4b9284865534dfb2059c100ae383e7f50c35f35eb7a768d4160890146487eb3f2ade194b48fb85df5c22e9a554d551375f23568e2f19f7d0b7021cf241b72890e4b12889480316e4a96404b36b9ef25d6337d947f8a9968577af554011c58c13bc05bff169897898d9c044e93006c8181e6231c1d7ab92b5bc45dd0242a65018cc843404e1e20f6748df88c48ba9a383a51c6493b0358153f0e2d78ca01' + const blockHeightx1 = 16734; + it('verifyHeaderAndExecuteTx correctly', async function () { + await expect(eccm.verifyHeaderAndExecuteTx(proofx, blockHeaderx1, headerProofx, curRawHeader, signaturesx1)) + .to.emit(eccm, 'VerifyHeaderAndExecuteTxEvent') + .withArgs(3, '0x4ddcf539d13e92d4151b7f5e607d4a09f725c47d', '0x00ca93f8738111a063d8ab7221f47c70a4cade0ca4a2829df494cd4b5e231bd6', '0x4caa77a3d2ddfaa318c550f1f38dd09d610dcff827d1f2ccd4ddcafaa6c553cc'); + }); + + it('verifyHeaderAndExecuteTx throws error on sync same block height header twice', async function () { + await expect(eccm.verifyHeaderAndExecuteTx(proofx, blockHeaderx1, headerProofx, curRawHeader, signaturesx1)) + .to.be.revertedWith("the transaction has been executed!"); + }); + }); + + describe('changeBookKeeper', function () { + const rawHeader = '0x000000009b91561700000000f48a4057bef268cc3fdb034e69dc2e942907e08ac4a420d1b196b8c28ebf5bf2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a8be0a1605a63a31704aec4eb4f1023f1ecc2934bd86f119ab77526f9477af9a57e1a5f508e0000410782720ab189fffd84057b226c6561646572223a332c227672665f76616c7565223a22424f4f336f58796b32524970655651593338547133714a423832737a4a68366e4f6f724a55702f4a4d582b474c707a347a497347394c4a6c34784a6f34657448674f56357169364d484b6674714f69724f755a495a69593d222c227672665f70726f6f66223a22635953525746506f69394748414247526255646836612b35506f4f317776354a557a53417457786845637071757430536a595873344c7453353574534a74334174493059616d4c67524a797a524f68564756626d34673d3d222c226c6173745f636f6e6669675f626c6f636b5f6e756d223a33363433322c226e65775f636861696e5f636f6e666967223a7b2276657273696f6e223a312c2276696577223a342c226e223a382c2263223a322c22626c6f636b5f6d73675f64656c6179223a31303030303030303030302c22686173685f6d73675f64656c6179223a31303030303030303030302c22706565725f68616e647368616b655f74696d656f7574223a31303030303030303030302c227065657273223a5b7b22696e646578223a312c226964223a2231323035303238313732393138353430623262353132656165313837326132613265336132386439383963363064393564616238383239616461376437646437303664363538227d2c7b22696e646578223a342c226964223a2231323035303236373939333061343261616633633639373938636138613366313265313334633031393430353831386437383364313137343865303339646538353135393838227d2c7b22696e646578223a332c226964223a2231323035303234383261636236353634623139623930363533663665396338303632393265386161383366373865376139333832613234613665666534316330633036663339227d2c7b22696e646578223a352c226964223a2231323035303234363864643138393965643264316363326238323938383261313635613065636236613734356166306337326562323938326436366234333131623465663733227d2c7b22696e646578223a382c226964223a2231323035303339333432313434356239343231626434636339306437626338386339333031353538303437613736623230633539653763353131656537643232393938326231227d2c7b22696e646578223a322c226964223a2231323035303338623861663632313065636664636263616232323535326566386438636634316336663836663963663961623533643836353734316366646238333366303662227d2c7b22696e646578223a372c226964223a2231323035303331653037373966356335636362323631323335326665346132303066393964336537373538653730626135336636303763353966663232613330663637386666227d2c7b22696e646578223a362c226964223a2231323035303265623162616162363032633538393932383235363163646161613761616262636464306363666362633365373937393361633234616366393037373866333561227d5d2c22706f735f7461626c65223a5b322c382c352c352c382c372c312c342c352c362c352c342c372c372c332c332c342c362c312c322c342c382c352c342c372c342c362c362c322c322c312c312c382c382c362c362c362c372c382c372c342c382c352c312c332c332c382c352c332c362c332c362c372c352c362c322c332c312c322c362c352c322c312c342c322c312c382c342c382c332c382c372c372c352c312c372c342c342c312c352c322c352c362c312c322c382c332c332c312c332c312c342c312c372c382c362c382c322c352c312c342c352c332c322c322c322c382c332c332c332c362c372c342c372c342c322c372c352c362c375d2c226d61785f626c6f636b5f6368616e67655f76696577223a36303030307d7df8fc7a1f6a856313c591a3a747f4eca7218a820b'; + const pubKeyList = '0x1205041e0779f5c5ccb2612352fe4a200f99d3e7758e70ba53f607c59ff22a30f678ff757519efff911efc7ed326890a2752b9456cc0054f9b63215f1d616e574d6197120504468dd1899ed2d1cc2b829882a165a0ecb6a745af0c72eb2982d66b4311b4ef73cff28a6492b076445337d8037c6c7be4d3ec9c4dbe8d7dc65d458181de7b5250120504482acb6564b19b90653f6e9c806292e8aa83f78e7a9382a24a6efe41c0c06f39ef0a95ee60ad9213eb0be343b703dd32b12db32f098350cf3f4fc3bad6db23ce120504679930a42aaf3c69798ca8a3f12e134c019405818d783d11748e039de8515988754f348293c65055f0f1a9a5e895e4e7269739e243a661fff801941352c387121205048172918540b2b512eae1872a2a2e3a28d989c60d95dab8829ada7d7dd706d658df044eb93bbe698eff62156fc14d6d07b7aebfbc1a98ec4180b4346e67cc3fb01205048b8af6210ecfdcbcab22552ef8d8cf41c6f86f9cf9ab53d865741cfdb833f06b72fcc7e7d8b9e738b565edf42d8769fd161178432eadb2e446dd0a8785ba088f12050493421445b9421bd4cc90d7bc88c9301558047a76b20c59e7c511ee7d229982b142bbf593006e8099ad4a2e3a2a9067ce46b7d54bab4b8996e7abc3fcd8bf0a5f120504eb1baab602c5899282561cdaaa7aabbcdd0ccfcbc3e79793ac24acf90778f35a059fca7f73aeb60666178db8f704b58452b7a0b86219402c0770fcb52ac9828c' + const sigList = '0x7d588d79ac9f0931c69150de6bfe5289f0147893781bffbcc32b5e07bd687d1048dda039ffc1e87de2e98610dc876e97411d604948473904b12b64bed8880bcc00ea8be33bb197c82690987e22e970221de11dfa019f470d784ef211edb6c9a3fd75bf74904adea08ed37a635c4dc58ccc21369afc1abcab4696a42be1097468a400289be668444122fd1d48c62781ded43e6fbda9bdd587dc7ee1bd326390d70e3f0e174fbd4854ed96c697dcee93feabbf7cdf290ebee93d4f5156d75d62b80ba301e79df9e679af49c403bbf05a24af2307adc96b641f4501fdb96e6704d27b2a87278e15bfee5909d4fa62dd45907cba23f833b3e96378d140d56722d1f59821e4006d8349493021e2cd6af96524357867b6be9d24ef33aaf66c430d5f91c33253304380ee17c6839fed964e7ba4910dd26533125b548cff6450140b10caec1b08fe01' + const rawHeaderHeight = 36432; + it('changeBookKeeper correctly', async function () { + await expect(eccm.changeBookKeeper(rawHeader, pubKeyList, sigList)) + .to.emit(eccm, 'ChangeBookKeeperEvent') + .withArgs(rawHeaderHeight, rawHeader); + }); + + it('changeBookKeeper throws error on sync same block height header twice', async function () { + await expect(eccm.changeBookKeeper(rawHeader, pubKeyList, sigList)) + .to.be.revertedWith("The height of header is lower than current epoch start height!"); + }); + }); + + describe('verifyHeaderAndExecuteTx', function () { + const proofx = '0xd020e91d858cba58b3dff91bf4b3adcacabf899e106ed6ad86a16a4a29e7817e307c080000000000000020b697330bd7a5850235f97d1bcd1c37739f4bc79a4f8e635dcb46ba45bc600ef4012f14f71b55ef55cedc91fd007f7a9ba386ec978f3aa80200000000000000144ddcf539d13e92d4151b7f5e607d4a09f725c47d06756e6c6f636b4a14000000000000000000000000000000000000000014344cfc3b8635f72f14200aaf2168d9f75df86fd36226100000000000000000000000000000000000000000000000000000000000'; + const blockHeaderx1 = '0x000000009b91561700000000285c4b50cb092422c306eee00b18730bd1e05f0c144bc04d0adf1f44e0aef6c70000000000000000000000000000000000000000000000000000000000000000829ba7727b3bb7d42eff74342bafb37362b4898169750e8b2b8af2267c863ebf6fb8849a086fbed1ccd873b63642cce60ac54875cc3c1f054c1866e0bca5136dc90a185f5e4100007de0abdc2a5b63d5fd0c017b226c6561646572223a312c227672665f76616c7565223a224249703243555764736c424c6b34754979584174417949682f74685a6b5072445539566279697358754c574d6e634a775a49515161434f4b74724474793437454d3541554e4a7542523133546b6857616e56422b4b7a493d222c227672665f70726f6f66223a224a3830534c2b6c62433537306f64426374486f477a45504631516d506f7a4f4332323132553563796b4949346a6b77374d2f74746f317537386e4634347256433443676d344f786f71667943656b3568487132576a413d3d222c226c6173745f636f6e6669675f626c6f636b5f6e756d223a302c226e65775f636861696e5f636f6e666967223a6e756c6c7d0000000000000000000000000000000000000000' + const headerProofx = '0x20c73c8b3c730086cfae83d735d2c405d6f5a00c3f1ff21ce91d223038d3c1ab4d000213149490394c2a8701af2dba1a303df05148a14092f6e59febca31eee4da660079807fe94ecb6f6d1b0b65be5f45159925a905bab8040af476c372ea0583dbba00b41a753c36f64bbe6d6fcd6c2ba40dc09c4c25b6b877bd363696fe1f62cbf6f700059195b0df4add4239eaef270bc187217dc872d11723d4fce02a3c2510461e5900f3c3d66c4611791ff1ebe8a2ef43f1cbf40876b637522c60a81f511445f8dc17011f86c65842afb760457d5ce8ad38821d2110331a7bbae87fe131a5e610f3a146004add0a7a5c74a56ce64a3555b4a73f367c414c80ecc15672dd86f7bff8bf65bc011daedaae87fc34d28ec3116dc04386c7c650f5db9e3a9a853c6e518821069bda001c6cf42ace3bf6b1a7e60ae29dc10aad67cdf672cdb083c601ee3996576cc2e401a1a8ab20062ebdcfa7a6e8f0c6c8b3de823920abd351eedc33d043de1c1449880171c734d6d77806f9475b69c8426bc5c09ce54c0b4ccb13df4315c62899e9926201f459d25426b21e5f2f6bdabf5e6a79f36002114b1ecc5cfa30a18cf3e4baf98d01ad42157822143a7be209b907901a31863d1b35ad9118c4c45d476e405872fb66017badaf21d00ca7e2a73c64dd7738ddcb6a881dcfb88ef0c171e33bfec529fe0a00e0a6008bab76556dbf47269adc41d6820c6a55982e9362257bfdf02a79ff5b8d01061cd147d032d11b1b7b6b5edc389f56d33f939e51be3c7949b357aac4e120df' + const curRawHeader = '0x000000009b91561700000000f2e3823838bcdfafe08c6e9ff2cd1f86ae65dfc1052d15c9441aa6c07097015f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000051d45928d93800ffebc80373df7dbe735a2e9c5998b883e69494921fedbbe858057f1a5f5a8e0000216854be71737efbfd10017b226c6561646572223a362c227672665f76616c7565223a224244592f6c4875783448587341376f394962357877634a4d39727466656a454c786d6637766a48583574507a64724d356a47304a305265756d4338632f6e64725131306b4751622f50537a3255667a6267723430666a413d222c227672665f70726f6f66223a2242437877375a6d49446243476a3839576e715744564f6b714f7239645574344f4f2f777176366d4c3165656377474d542b3078664476544642614f3951534451437879725551344c316835392b3130486671386176673d3d222c226c6173745f636f6e6669675f626c6f636b5f6e756d223a33363433322c226e65775f636861696e5f636f6e666967223a6e756c6c7d0000000000000000000000000000000000000000' + const signaturesx1 = '0x6d905d095fc1b47eb30b8f176c94b01b64502790f3c20db2a5b7e555791bdbf8458a24c73c8f690ad8481e3754c3297991f9f4148d03316e2e5a6c6af9e7bbc900a81911a6eb529979ee021124c242a828657865fc7a899ab55fb7d2a1623341a67ae83c90a40bec8bf54fa3c5caad445062568d3c4c4099e84ad6c774e70d7d7d000b5d0a2ebc3685a6deeb96cfabf71e4a9d05606a5918e4765be6cc4cad38c3954e248d97b2fa378b954f323335c93298913c61048cf0b396467df1c6b6bbba4d01cd68657ad3c6d5a979093ff1345eefb269e86498b519418fa0e5e756ce01a9b939d46b405d2a167883bda0a40023cce39659890c97a59e3f772b6fc3c2e03221004d425ad3bfef2de8b1d523cbfd754d4ea2c8e8fa5f6904b0389f4e5d62039083454e2a24da6e1c90334fd760eaa1921bdac10158758f682cb401e1df16ee0ec801b8e8eb23200a1571c6ad516528ce3f1280506eed9f1e380b9a5e770f1e89d8414182c7b83dc8f230d288c4745d0a8102cfc015d422af77d139bc606054363ecf0138fc63be97c354539b517bd8abd97d86fa3484894663aa7dcf578cfad7368df577206e28daf800cba179314f34f1a6dec569ff12e15c22b598028cce64bfa54601' + it('verifyHeaderAndExecuteTx correctly', async function () { + await expect(eccm.verifyHeaderAndExecuteTx(proofx, blockHeaderx1, headerProofx, curRawHeader, signaturesx1)) + .to.emit(eccm, 'VerifyHeaderAndExecuteTxEvent') + .withArgs(8, '0x4ddcf539d13e92d4151b7f5e607d4a09f725c47d', '0xe91d858cba58b3dff91bf4b3adcacabf899e106ed6ad86a16a4a29e7817e307c', '0xb697330bd7a5850235f97d1bcd1c37739f4bc79a4f8e635dcb46ba45bc600ef4'); + }); + + it('verifyHeaderAndExecuteTx throws error on sync same block height header twice', async function () { + await expect(eccm.verifyHeaderAndExecuteTx(proofx, blockHeaderx1, headerProofx, curRawHeader, signaturesx1)) + .to.be.revertedWith("the transaction has been executed!"); + }); + }); + + describe('Here, we demonstrate the steps to upgrade EthCrossChainManagerContract,', async function () { + it('first, owner of this.ECCMP invoke this.ECCMP.pauseEthCrossChainManager()', async function () { + tx = await eccmp.pauseEthCrossChainManager(); + await tx.wait(); + expect(await eccmp.paused()).to.equal(true); + expect(await eccm.paused()).to.equal(true); + expect(await eccd.paused()).to.equal(true); + }); + it('second, we deploy the new version of EthCrossChainManager contract which we have done in before with hash = this.ECCM1.address', async function () { + console.log('new version of EthCrossChainManager contract address we deployed previously: \n', eccm1.address); + }); + it('third, the deployer invoke this.ECCM1.transferOwnership(this.ECCMP.address)', async function () { + tx = await eccm1.transferOwnership(eccmp.address); + await tx.wait(); + expect(await eccm1.owner()).to.equal(eccmp.address) + }); + it('forth, the owner of this.ECCMP invoke this.ECCMP.upgradeEthCrossChainManager(this.ECCM1.address)', async function () { + expect(await eccmp.owner()).to.equal(deployer.address); + expect(await eccm.owner()).to.equal(eccmp.address); + expect(await eccd.owner()).to.equal(eccm.address); + tx = await eccmp.upgradeEthCrossChainManager(eccm1.address); + await tx.wait(); + expect(await eccd.owner()).to.equal(eccm1.address); + }); + it('fifth, the owner of this.ECCMP invoke this.ECCMP.unpauseEthCrossChainManager()', async function () { + tx = await eccmp.unpauseEthCrossChainManager(); + await tx.wait(); + expect(await eccmp.paused()).to.equal(false); + expect(await eccm1.paused()).to.equal(false); + expect(await eccd.paused()).to.equal(false); + expect(await eccmp.getEthCrossChainManager()).to.equal(eccm1.address) + }); + }); + + describe('Here, we try to use old method in the new EthCrossChainManager contract to process last epoch tx,', async function () { + const genesisHeader = '0x000000009b9156170000000000000000000000000000000000000000000000000000000000000000000000006de0a8f7ee3fb67d8e04ac9547f3615e59adc6e0a2309c90080a272dc1fa1fd90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c8365b000000001dac2b7c00000000fd1a057b226c6561646572223a343239343936373239352c227672665f76616c7565223a22484a675171706769355248566745716354626e6443456c384d516837446172364e4e646f6f79553051666f67555634764d50675851524171384d6f38373853426a2b38577262676c2b36714d7258686b667a72375751343d222c227672665f70726f6f66223a22785864422b5451454c4c6a59734965305378596474572f442f39542f746e5854624e436667354e62364650596370382f55706a524c572f536a5558643552576b75646632646f4c5267727052474b76305566385a69413d3d222c226c6173745f636f6e6669675f626c6f636b5f6e756d223a343239343936373239352c226e65775f636861696e5f636f6e666967223a7b2276657273696f6e223a312c2276696577223a312c226e223a372c2263223a322c22626c6f636b5f6d73675f64656c6179223a31303030303030303030302c22686173685f6d73675f64656c6179223a31303030303030303030302c22706565725f68616e647368616b655f74696d656f7574223a31303030303030303030302c227065657273223a5b7b22696e646578223a312c226964223a2231323035303238313732393138353430623262353132656165313837326132613265336132386439383963363064393564616238383239616461376437646437303664363538227d2c7b22696e646578223a322c226964223a2231323035303338623861663632313065636664636263616232323535326566386438636634316336663836663963663961623533643836353734316366646238333366303662227d2c7b22696e646578223a332c226964223a2231323035303234383261636236353634623139623930363533663665396338303632393265386161383366373865376139333832613234613665666534316330633036663339227d2c7b22696e646578223a342c226964223a2231323035303236373939333061343261616633633639373938636138613366313265313334633031393430353831386437383364313137343865303339646538353135393838227d2c7b22696e646578223a352c226964223a2231323035303234363864643138393965643264316363326238323938383261313635613065636236613734356166306337326562323938326436366234333131623465663733227d2c7b22696e646578223a362c226964223a2231323035303265623162616162363032633538393932383235363163646161613761616262636464306363666362633365373937393361633234616366393037373866333561227d2c7b22696e646578223a372c226964223a2231323035303331653037373966356335636362323631323335326665346132303066393964336537373538653730626135336636303763353966663232613330663637386666227d5d2c22706f735f7461626c65223a5b362c342c332c352c362c312c322c352c342c372c342c322c332c332c372c362c352c342c362c352c312c342c332c312c322c352c322c322c362c312c342c352c342c372c322c332c342c312c352c372c342c312c322c322c352c362c342c342c322c372c332c362c362c352c312c372c332c312c362c312c332c332c322c342c342c312c352c362c352c312c322c362c372c352c362c332c342c372c372c332c322c372c312c352c362c352c322c332c362c322c362c312c372c372c372c312c372c342c332c332c332c322c312c372c355d2c226d61785f626c6f636b5f6368616e67655f76696577223a36303030307d7d9fe171f3fe643eb1c188400b828ba184816fc9ac0000' + const genesisPubKey = '0x1205041e0779f5c5ccb2612352fe4a200f99d3e7758e70ba53f607c59ff22a30f678ff757519efff911efc7ed326890a2752b9456cc0054f9b63215f1d616e574d6197120504468dd1899ed2d1cc2b829882a165a0ecb6a745af0c72eb2982d66b4311b4ef73cff28a6492b076445337d8037c6c7be4d3ec9c4dbe8d7dc65d458181de7b5250120504482acb6564b19b90653f6e9c806292e8aa83f78e7a9382a24a6efe41c0c06f39ef0a95ee60ad9213eb0be343b703dd32b12db32f098350cf3f4fc3bad6db23ce120504679930a42aaf3c69798ca8a3f12e134c019405818d783d11748e039de8515988754f348293c65055f0f1a9a5e895e4e7269739e243a661fff801941352c387121205048172918540b2b512eae1872a2a2e3a28d989c60d95dab8829ada7d7dd706d658df044eb93bbe698eff62156fc14d6d07b7aebfbc1a98ec4180b4346e67cc3fb01205048b8af6210ecfdcbcab22552ef8d8cf41c6f86f9cf9ab53d865741cfdb833f06b72fcc7e7d8b9e738b565edf42d8769fd161178432eadb2e446dd0a8785ba088f120504eb1baab602c5899282561cdaaa7aabbcdd0ccfcbc3e79793ac24acf90778f35a059fca7f73aeb60666178db8f704b58452b7a0b86219402c0770fcb52ac9828c' + + it('InitGenesisBlock should revert', async function () { + await expect(eccm1.initGenesisBlock(genesisHeader, genesisPubKey)) + .to.be.revertedWith("EthCrossChainData contract has already been initialized!"); + }); + const proofy = '0xd0208a184af59286e0551fdfd485659957ace24bb7861777778886415ef1a0952c6908000000000000002015d2710ed6168a4042a9f3e12c3398e3e57fb47c95f5f7346480d0584f658c3c013014f71b55ef55cedc91fd007f7a9ba386ec978f3aa80200000000000000146aba9e15019537ac636932a4224ad99099116af006756e6c6f636b4a14000000000000000000000000000000000000000014344cfc3b8635f72f14200aaf2168d9f75df86fd323ee350000000000000000000000000000000000000000000000000000000000'; + const blockHeadery1 = '0x000000009b91561700000000c257d1ec56f09dda12a556f32a0d5518af470a5feecd35e984b18d347da47d480000000000000000000000000000000000000000000000000000000000000000a139bb8b9a0b35e76595c7a9c7ca01d9c93880298596c69c450cafe05aacceacc837b91e5d04ea6087fc337713c6ab67148e0d7c7c156fafaf3aea2ff43927a3f134195fe34f0000c6fec9145c223bc1fd0c017b226c6561646572223a312c227672665f76616c7565223a22424871556f7444456b56566e6b5070374542656f4b45384d514b4e4d72457a5a37316943687149494272554d3754765270532f634a4f2b393959725a7a3238494e424b6c44764e5969394945364f7079783850394942453d222c227672665f70726f6f66223a224c594931577864616236434b37414b2f757a655854716246576d6f5a4f756264776f7036656a374267796a4d4470732f64674f797961634e73464630536c627a756173546e416648656c68366b574d4b7561415464413d3d222c226c6173745f636f6e6669675f626c6f636b5f6e756d223a302c226e65775f636861696e5f636f6e666967223a6e756c6c7d0000000000000000000000000000000000000000' + const headerProofy = '0x20b869456987b33d8e8f132b9ed6a6527444064ffd1446a2b3e03759f00c55b55c019f9f5b35cb27c7c1c0edb10422cc60138c82b3a280349a198b9bc0488994d25501d56483ff3541ecdee8f2e035ad1bd6761c1563d10001e092d4969ceb80093ad900f0fdb68e60bc72aad2de1fde5c72cad8e13b817c4079306c7bafbbcccb6214b801b45e220b6c7fb4133efefbfe1060d10036af8fa0abd9042667b32e5d295f5275014e020ea299a2bc23809e0db9f184462389989005d204ec7645026081d1ee13f7007e0e81a6f88fa7a79a16f1bc0f1681e0e11a9246e4599b6a7345aa9af5f147a200d28d4b380fe35bb86f64f7d7caed40c1ceed959577f2ff114f995d1a171de07800d0f31c1cc0d1ab54b67d8d1f79b1f855092f2e599b9aba9825b2393c199b839c005406b1a3308d3e64b052c7feeba56da04d9c84bfaaaf73a00a24bfa4df70d1c2006798338128b154b681bd803cd240685b357bf6e7e34a7136c4a5435834bc21ce0023f43b40d8ac715c50578cbaef5841d1a69a6f3de4eabcb81cfc14e2a137809400bb91772ec2a977c9f90def0756ec66a660241aa69d304bb6216a9684a79628a901ad42157822143a7be209b907901a31863d1b35ad9118c4c45d476e405872fb66017badaf21d00ca7e2a73c64dd7738ddcb6a881dcfb88ef0c171e33bfec529fe0a00e0a6008bab76556dbf47269adc41d6820c6a55982e9362257bfdf02a79ff5b8d01fc4e7f387cafe5535ddc92aaa15feb7e13190f9f11e6ecc1eec194afb87507d1' + const curRawHeader = '0x000000009b91561700000000e37f8641960eb66c296d844f218a8ef3e9647f0045eb6bc74271a216b519185000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f29bae4752df05801218b94eb3294c78706aba82bb8b925ab533237b77f54945f7441e5f409c0000a13522121871fd50fd10017b226c6561646572223a362c227672665f76616c7565223a2242455555766655616b63466450376e36354362674166583134546732486232412f707434713547746f4a554b773877594743684233736a504e576e325a446e4949546d393062466c46436937586167464e59715671456f3d222c227672665f70726f6f66223a22626b593836525348357864536567425151586b6e576d665838582b374c516166334b416530465644655672684a4b2b744a617832693335633736794e4242797639616238734142525156306f454f42635837794839513d3d222c226c6173745f636f6e6669675f626c6f636b5f6e756d223a33363433322c226e65775f636861696e5f636f6e666967223a6e756c6c7d0000000000000000000000000000000000000000' + const signaturesy1 = '0x54bca9e64dd75bb07b0c4ae901b6322b19c9b23fa0a963c796f0684bf69911f66ed2e2b12cdb4bc4c275e670916478748e1b00c276975497baab64b09cbac33201708a22caf9049ee9f7cc19d2e0f2b166ac77f1db66c8472a0b299cde520887bc7b652990118e8cee6a39b2460f061807e9bbf986776d0123ef6b92ac53b097ea01ff956defca5f9b9841c431b1107b02ac19c5576ed3339de09952992290f0ae6e4d2e16f308ce73af45d0ba3fbffd3f868703bde4ff6393c46ba0d78070cce0a7013ca03404ebf6a08c8d3d7769bb7ccad1fdcfd4422906c8fc5464aa0c62975ee21d532c38a565da4dd100c68e18416646ec6d32497d6114fc08b98675bff8a76c013a1e4c7e36ab34ca5c64645493fd3a634874692c4a29cf0a72b764dbe8710f07616d810c16746c8aaa41bc9318e837a5545230edebce5b32bfb18d84bd8799a301f9b77a1ea5199ca55112e4d2c865ac530019f50a66daba9968880cca92187bd0775f7ac3230bdcce3a12d197f34c95251ca5ac1dd5fdb45e5f78288a00df283d01' + it('in new EthCrossChainManager contract, should verifyHeaderAndExecuteTx correctly', async function () { + await expect(eccm1.verifyHeaderAndExecuteTx(proofy, blockHeadery1, headerProofy, curRawHeader, signaturesy1)) + .to.emit(eccm1, 'VerifyHeaderAndExecuteTxEvent') + .withArgs(8, '0x6aba9e15019537ac636932a4224ad99099116af0', '0x8a184af59286e0551fdfd485659957ace24bb7861777778886415ef1a0952c69', '0x15d2710ed6168a4042a9f3e12c3398e3e57fb47c95f5f7346480d0584f658c3c'); + }); + it('in new EthCrossChainManager contract, verifyHeaderAndExecuteTx throws error on sync same block height header twice', async function () { + await expect(eccm1.verifyHeaderAndExecuteTx(proofy, blockHeadery1, headerProofy, curRawHeader, signaturesy1)) + .to.be.revertedWith("the transaction has been executed!"); + }); + }); + + describe('verifyHeaderAndExecuteTx for current epoch tx after upgrade contract', function () { + const proofz = '0xd7206de23520db9f6978f8d1b0ba7369edcbea4ea62396605363ea7cb721f31885930300000000000000204a96009aa5364a71f39f3a9984215da1dac4bf4fd5c459af542f028685d85031081e0400000000000014b7041bc96b15da728fdfc1c47cbfc687b845adeb0200000000000000146aba9e15019537ac636932a4224ad99099116af006756e6c6f636b4a14283d389667f28d5fc7e3049a2bd7a40a2ae08f1514344cfc3b8635f72f14200aaf2168d9f75df86fd30f0000000000000000000000000000000000000000000000000000000000000000b6baca2408e3d037f744210446279438b7d7cef89cc1ab738f18e0ff007c7fb80063f78a02a450496c46279b75a2943fe31b8d2b81b61b030ab33c6bc079e473f900a6998c80cfc576a19fbc313501003bfc0d014db3511ae7e6ee27f446fcaed9d600e20a98f755c55e7f0c29fae8cb81539a2158e1ba15a1e3523439f639eda613a7'; + const blockHeaderz1 = '0x000000009b91561700000000a38ff31f1a18ccd3f0da6293f2995d841fb54fffb6e5c5b2c4a90e0958e07f241fb0cc7b597ddb67f70b457e7ae8b827c692f594bfe130f5c3e3a04914a76127fc2e9b603bb187f6f0006312db8d248c1225c76a0672b9caee589408238e217ee3a10983975e8ddedd7336fc6c4fdee4972213d7d670f85bbd0898e6cf29260c25c01a5faa8f0000c9c576cb2c4a58c4fd10017b226c6561646572223a372c227672665f76616c7565223a224249766435556654576d6761335868594a54487a66425178503164767972316a6e41324f636d736b2b2f32706f4c6d6758445530316b4c61324d3553646366746c482f6657674652613431726c754f7879337462386c383d222c227672665f70726f6f66223a22366e63657331786952666c4757775841586642773348426e4263767477584977684a4669564b664335753030463844413233683858796248367856596f63334a76676955765a32465869572b3162774b554935656d513d3d222c226c6173745f636f6e6669675f626c6f636b5f6e756d223a33363433322c226e65775f636861696e5f636f6e666967223a6e756c6c7d0000000000000000000000000000000000000000' + const headerProofz = '0x' + const curRawHeader = '0x000000009b91561700000000a38ff31f1a18ccd3f0da6293f2995d841fb54fffb6e5c5b2c4a90e0958e07f241fb0cc7b597ddb67f70b457e7ae8b827c692f594bfe130f5c3e3a04914a76127fc2e9b603bb187f6f0006312db8d248c1225c76a0672b9caee589408238e217ee3a10983975e8ddedd7336fc6c4fdee4972213d7d670f85bbd0898e6cf29260c25c01a5faa8f0000c9c576cb2c4a58c4fd10017b226c6561646572223a372c227672665f76616c7565223a224249766435556654576d6761335868594a54487a66425178503164767972316a6e41324f636d736b2b2f32706f4c6d6758445530316b4c61324d3553646366746c482f6657674652613431726c754f7879337462386c383d222c227672665f70726f6f66223a22366e63657331786952666c4757775841586642773348426e4263767477584977684a4669564b664335753030463844413233683858796248367856596f63334a76676955765a32465869572b3162774b554935656d513d3d222c226c6173745f636f6e6669675f626c6f636b5f6e756d223a33363433322c226e65775f636861696e5f636f6e666967223a6e756c6c7d0000000000000000000000000000000000000000' + const signaturesz1 = '0x44defe311767bed6f2116dd15016ebc9441787d4cca2da0b514b8ab78dd6cdff0f07b03badc144e00db05459cecc9131c8841ef65f18b8c063b460265ef05e7d0090ccf8b906d4d5fc34e8f01691449d7c02a0763018e9ccf45817d1a880bccbe57739d9b34e52eec1cae8cfda4fee1d99fca578560b1d111c498e9e20f13c4d1a003a2413b4de268e1cb9d9dc61634ff7c8239935872ad891184bf361f30fe54bb04c2b8990ecc5f7feea4a2606619ff2db0d281caea64ca65d7d3b7f950cc6454a01ef1eed36f7e6cae364fc0cb996ba246988d631fdb2d9cb77d871f0a436ac4d9b337c84b7fb690c535d11a1dede8582a5441501483b8334ad529c02e63eb61c5900975991429c2b809ba8d914e985637bbfa65b4a8f626347d3f1b9f385e33e827f2b6e22f426c96d784d207041c62b77280a0d903f0153fd8bead3c8615680cad301c8b89c176a369f814078a39d8535f47758de53b504c1009682dd4118dfeae3f2074870d5d6bebd0b718a58773d4189d0e2463a1fc98efbaa992bf12dd240f9dc0115cbd70a63cf78faebc088da7ca43f07efed0800a20610b323a5772acb6c212d33799a2345b305baa2a3adb3ae65151f93be170677529fea4334a614d6b0ce5c00' + it('verifyHeaderAndExecuteTx correctly after upgrade contract', async function () { + await expect(eccm1.verifyHeaderAndExecuteTx(proofz, blockHeaderz1, headerProofz, curRawHeader, signaturesz1)) + .to.emit(eccm1, 'VerifyHeaderAndExecuteTxEvent') + .withArgs(3, '0x6aba9e15019537ac636932a4224ad99099116af0', '0x6de23520db9f6978f8d1b0ba7369edcbea4ea62396605363ea7cb721f3188593', '0x4a96009aa5364a71f39f3a9984215da1dac4bf4fd5c459af542f028685d85031'); + }); + + it('verifyHeaderAndExecuteTx throws error on sync same block height header twice after upgrade contract', async function () { + await expect(eccm1.verifyHeaderAndExecuteTx(proofz, blockHeaderz1, headerProofz, curRawHeader, signaturesz1)) + .to.be.revertedWith("the transaction has been executed!"); + }); + }); + +}); \ No newline at end of file diff --git a/scripts/deploy.js b/scripts/deploy.js new file mode 100644 index 0000000..debfe49 --- /dev/null +++ b/scripts/deploy.js @@ -0,0 +1,110 @@ +const { ethers } = require("hardhat"); +const hre = require("hardhat"); +const fs = require("fs"); +const Web3 = require("web3"); +const colors = require('colors'); +hre.web3 = new Web3(hre.network.provider); + +async function main() { + + [deployer] = await hre.ethers.getSigners(); + let polyId; + + // check if given networkId is registered + await getPolyChainId().then((_polyId) => { + polyId = _polyId; + console.log("\nDeploy EthCrossChainManager on chain with Poly_Chain_Id:".cyan, _polyId); + }).catch((error) => { + throw error; + });; + + console.log("Start , deployer:".cyan, deployer.address.blue); + + // deploy EthCrossChainData + console.log("\ndeploy EthCrossChainData ......".cyan); + const ECCD = await hre.ethers.getContractFactory("EthCrossChainData"); + const eccd = await ECCD.deploy(); + await eccd.deployed(); + console.log("EthCrossChainData deployed to:".green, eccd.address.blue); + + // deploy EthCrossChainManager + console.log("\ndeploy EthCrossChainManager ......".cyan); + const CCM = await hre.ethers.getContractFactory("EthCrossChainManager"); + const ccm = await CCM.deploy(eccd.address, polyId, [], []); + await ccm.deployed(); + console.log("EthCrossChainManager deployed to:".green, ccm.address.blue); + + // deploy EthCrossChainManagerProxy + console.log("\ndeploy EthCrossChainManagerProxy ......".cyan); + const CCMP = await hre.ethers.getContractFactory("EthCrossChainManagerProxy"); + const ccmp = await CCMP.deploy(ccm.address); + await ccmp.deployed(); + console.log("EthCrossChainManagerProxy deployed to:".green, ccmp.address.blue); + + // transfer ownership + console.log("\ntransfer eccd's ownership to ccm ......".cyan); + await eccd.transferOwnership(ccm.address); + console.log("ownership transferred".green); + + console.log("\ntransfer ccm's ownership to ccmp ......".cyan); + await ccm.transferOwnership(ccmp.address); + console.log("ownership transferred".green); + + console.log("\nDone.\n".magenta); + +} + +async function getPolyChainId() { + const chainId = await hre.web3.eth.getChainId(); + switch (chainId) { + + // mainnet + case 1: // eth-main + return 2; + case 56: // bsc-main + return 6; + case 128: // heco-main + return 7; + case 137: // polygon-main + return 17; + case 66: // ok-main + return 12; + case 1718: // plt-main + return 8; + case 42161: // arbitrum-main + return 19; + + // testnet + case 3: // eth-test + return 2; + case 97: // bsc-test + return 79; + case 256: // heco-test + return 7; + case 80001: // polygon-test + return 202; + case 65: // ok-test + return 200; + case 101: // plt-test + return 107; + case 421611: // arbitrum-test + return 205; + + // hardhat devnet + case 31337: + return 77777; + + // unknown chainid + default: + throw new Error("fail to get Poly_Chain_Id, unknown Network_Id: "+chainId); + } +} + +// We recommend this pattern to be able to use async/await everywhere +// and properly handle errors. +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); \ No newline at end of file diff --git a/scripts/deploy_testnet.js b/scripts/deploy_testnet.js new file mode 100644 index 0000000..83d76d0 --- /dev/null +++ b/scripts/deploy_testnet.js @@ -0,0 +1,119 @@ +const hre = require("hardhat"); +const fs = require("fs"); +const Web3 = require("web3"); +const colors = require('colors'); +const { deployContract } = require("ethereum-waffle"); +hre.web3 = new Web3(hre.network.provider); + +async function main() { + + [deployer] = await hre.ethers.getSigners(); + let polyId; + + // check if given networkId is registered + await getPolyChainId().then((_polyId) => { + polyId = _polyId; + console.log("\nDeploy EthCrossChainManager on chain with Poly_Chain_Id:".cyan, _polyId); + }).catch((error) => { + throw error; + });; + + console.log("Start , deployer:".cyan, deployer.address.blue); + + const ECCD = await hre.ethers.getContractFactory("EthCrossChainData"); + const CCM = await hre.ethers.getContractFactory("EthCrossChainManagerNoWhiteList"); + const CCMP = await hre.ethers.getContractFactory("EthCrossChainManagerProxy"); + const LockProxy = await hre.ethers.getContractFactory("LockProxy"); + const WrapperV2 = await hre.ethers.getContractFactory("PolyWrapper"); + + // deploy EthCrossChainData + console.log("\ndeploy EthCrossChainData ......".cyan); + const eccd = await ECCD.deploy(); + await eccd.deployed(); + console.log("EthCrossChainData deployed to:".green, eccd.address.blue); + + // deploy EthCrossChainManager + console.log("\ndeploy EthCrossChainManager ......".cyan); + const ccm = await CCM.deploy(eccd.address, polyId); + await ccm.deployed(); + console.log("EthCrossChainManager deployed to:".green, ccm.address.blue); + + // deploy EthCrossChainManagerProxy + console.log("\ndeploy EthCrossChainManagerProxy ......".cyan); + const ccmp = await CCMP.deploy(ccm.address); + await ccmp.deployed(); + console.log("EthCrossChainManagerProxy deployed to:".green, ccmp.address.blue); + + // transfer ownership + console.log("\ntransfer eccd's ownership to ccm ......".cyan); + tx = await eccd.transferOwnership(ccm.address); + await tx.wait(); + console.log("ownership transferred".green); + + console.log("\ntransfer ccm's ownership to ccmp ......".cyan); + tx = await ccm.transferOwnership(ccmp.address); + await tx.wait(); + console.log("ownership transferred".green); + + // deploy LockProxy + console.log("\ndeploy LockProxy ......".cyan); + const lockproxy = await LockProxy.deploy(); + await lockproxy.deployed(); + console.log("LockProxy deployed to:".green, lockproxy.address.blue); + + // setup LockProxy + console.log("\nsetup LockProxy ......".cyan); + tx = await lockproxy.setManagerProxy(ccmp.address); + await tx.wait(); + console.log("setManagerProxy Done".green); + + // deploy wrapper + console.log("\ndeploy PolyWrapperV2 ......".cyan); + const wrapper = await WrapperV2.deploy(deployer.address, polyId); + await wrapper.deployed(); + console.log("PolyWrapperV2 deployed to:".green, wrapper.address.blue); + + // setup wrapper + console.log("\nsetup WrapperV2 ......".cyan); + tx = await wrapper.setFeeCollector(deployer.address); + await tx.wait(); + console.log("setFeeCollector Done".green); + tx = await wrapper.setLockProxy(lockproxy.address); + await tx.wait(); + console.log("setLockProxy Done".green); + + + console.log("\nDone.\n".magenta); + +} + +async function getPolyChainId() { + const chainId = await hre.web3.eth.getChainId(); + switch (chainId) { + + // mainnet + + // testnet + case 5851: // ont_testnet + return 333; + case 12345: // ont-private + return 5555; + + // hardhat devnet + case 31337: + return 77777; + + // unknown chainid + default: + throw new Error("fail to get Poly_Chain_Id, unknown Network_Id: "+chainId); + } +} + +// We recommend this pattern to be able to use async/await everywhere +// and properly handle errors. +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); \ No newline at end of file diff --git a/scripts/getPolyId.js b/scripts/getPolyId.js new file mode 100644 index 0000000..0c78172 --- /dev/null +++ b/scripts/getPolyId.js @@ -0,0 +1,18 @@ +const hre = require("hardhat"); +const Web3 = require("web3"); +const fs = require("fs"); +hre.web3 = new Web3(hre.network.provider); +require("colors"); + +var configPath = './zionDevConfig.json' + +async function main() { + console.log(hre.config.networks[hre.network.name].polyId); +} + +main() + .then(() => process.exit(0)) + .catch((err) => { + console.error(err) + process.exit(1) + }); \ No newline at end of file diff --git a/scripts/resumeUpdate.js b/scripts/resumeUpdate.js new file mode 100644 index 0000000..8496ab0 --- /dev/null +++ b/scripts/resumeUpdate.js @@ -0,0 +1,399 @@ +const { ethers } = require("hardhat"); +const hre = require("hardhat"); +const fs = require("fs"); +const Web3 = require("web3"); +const colors = require('colors'); +const { expect } = require("chai"); +hre.web3 = new Web3(hre.network.provider); + +async function main() { + + [deployer] = await hre.ethers.getSigners(); + + let polyId; + let _eccd; + let _old_ccm; + let _ccmp; + let fromContractWhiteList; + let contractMethodWhiteList; + + // check polyId + await getPolyChainId().then((_polyId) => { + polyId = _polyId; + console.log("\nResume update EthCrossChainManager on chain with Poly_Chain_Id:".cyan, _polyId); + }).catch((error) => { + throw error; + });; + + try { + [_eccd, _old_ccm, _ccmp] = getDeployedContract(polyId); + } catch(error) { + throw error; + } + + try { + [fromContractWhiteList,contractMethodWhiteList] = getWhiteListInfo(polyId); + } catch(error) { + throw error; + } + + const ECCD = await hre.ethers.getContractFactory("EthCrossChainData"); + const CCM = await hre.ethers.getContractFactory("EthCrossChainManager"); + const CCMP = await hre.ethers.getContractFactory("EthCrossChainManagerProxy"); + + let eccd = ECCD.attach(_eccd); + let old_ccm = CCM.attach(_old_ccm); + let ccmp = CCMP.attach(_ccmp); + + // check if given contracts are valid + expect(await old_ccm.chainId()).to.equal(polyId); + expect(await eccd.owner()).to.equal(old_ccm.address); + expect(await old_ccm.owner()).to.equal(ccmp.address); + //expect(await ccmp.getEthCrossChainManager()).to.equal(old_ccm.address); + expect(await hre.web3.eth.getStorageAt(ccmp.address,1)).to.equal('0x000000000000000000000000'+old_ccm.address.slice(2).toLowerCase()); + expect(await old_ccm.EthCrossChainDataAddress()).to.equal(eccd.address); + + console.log("Start , deployer:".cyan, deployer.address.blue); + + // deploy EthCrossChainManager + console.log("\nLoad new EthCrossChainManager ......".cyan); + let ccm = CCM.attach('0x14413419452Aaf089762A0c5e95eD2A13bBC488C'); + expect(await ccm.owner()).to.equal(ccmp.address); + console.log("Use new EthCrossChainManager:".green, ccm.address.blue); + + // paused + console.log("\nCheck if paused and pause if not".cyan); + let paused_1 = await ccmp.paused(); + let paused_2 = await old_ccm.paused(); + if (!paused_1 && paused_2) { + tx = await ccmp.pause(); + await tx.wait(); + } else if (!paused_1 && !paused_2) { + tx = await ccmp.pauseEthCrossChainManager(); + await tx.wait(); + } else if (paused_1 && !paused_2) { + tx = await ccmp.unpause(); + await tx.wait(); + tx = await ccmp.pauseEthCrossChainManager(); + await tx.wait(); + } + expect(await ccmp.paused()).to.equal(true); + expect(await old_ccm.paused()).to.equal(true); + console.log("all paused".green); + + // update to new + console.log("\nUpdate to new ccm".cyan); + tx = await ccmp.upgradeEthCrossChainManager(ccm.address); + await tx.wait(); + expect(await eccd.owner()).to.equal(ccm.address); + expect(await ccm.owner()).to.equal(ccmp.address); + expect(await hre.web3.eth.getStorageAt(ccmp.address,1)).to.equal('0x000000000000000000000000'+ccm.address.slice(2).toLowerCase()); + expect(await ccm.EthCrossChainDataAddress()).to.equal(eccd.address); + console.log("updated".green); + + // unpaused + console.log("\nUnpaused all".cyan); + tx = await ccmp.unpauseEthCrossChainManager(); + await tx.wait(); + expect(await ccmp.paused()).to.equal(false); + expect(await ccm.paused()).to.equal(false); + console.log("unpaused".green); + + console.log("\nDone.\n".magenta); + +} + +function getDeployedContract(polyId) { + switch (polyId) { + case 2 : //eth + eccd = '0xcf2afe102057ba5c16f899271045a0a37fcb10f2'; + ccm = '0xe020877e67CfAAFFC33a6E7eB9e85741bbb3eA79'; + ccmp = '0x5a51e2ebf8d136926b9ca7b59b60464e7c44d2eb'; + return [eccd, ccm, ccmp]; + + case 6 : //bsc + eccd = '0x11e2A718d46EBe97645b87F2363AFE1BF28c2672'; + ccm = '0x00EeE7b864062c40F8096f948a2B0Db3c28aa6fE'; + ccmp = '0xABD7f7B89c5fD5D0AEf06165f8173b1b83d7D5c9'; + return [eccd, ccm, ccmp]; + + case 7 : //heco + eccd = '0x11e2A718d46EBe97645b87F2363AFE1BF28c2672'; + ccm = '0x59A2C3062D9F1097D5CD239FA1BAbE6cb64fB96C'; + ccmp = '0xABD7f7B89c5fD5D0AEf06165f8173b1b83d7D5c9'; + return [eccd, ccm, ccmp]; + + case 12 : //ok + eccd = '0xdb3A0149f3155cC1B6890FE382d309dB4b322630'; + ccm = '0x3758fD8D5c29AD2620De837Da7531Bb4d1f64EDc'; + ccmp = '0x4739fe955BE4704BcB7d6a699823F5B29217Baf6'; + return [eccd, ccm, ccmp]; + + case 17 : //polygon + eccd = '0x7ceA671DABFBa880aF6723bDdd6B9f4caA15C87B'; + ccm = '0x39Cd00c5d0fa3e880B86B6a76224a18128DE89E5'; + ccmp = '0x5366eA2B5B729FF3cEf404c2408C8c60cC061B71'; + return [eccd, ccm, ccmp]; + + case 19 : //arbitrum + eccd = '0x11e2A718d46EBe97645b87F2363AFE1BF28c2672'; + ccm = '0x7ceA671DABFBa880aF6723bDdd6B9f4caA15C87B'; + ccmp = '0xABD7f7B89c5fD5D0AEf06165f8173b1b83d7D5c9'; + return [eccd, ccm, ccmp]; + + default : + throw new Error("fail to get DeployedContract, unknown Network: "+polyId); + } +} + +function getWhiteListInfo(polyId) { + switch (polyId) { + case 2 : //eth + fromContractWhiteList = [ + '0x250e76987d838a75310c34bf422ea9f1AC4Cc906', + '0xaf83ce8d461e8834de03a3803c968615013c6b3d', + '0x2cdfc90250EF967036838DA601099656e74bCfc5', + '0x9a016ce184a22dbf6c17daa59eb7d3140dbd1c54' + ]; + contractMethodWhiteList = [ + '0x000000000000000000000000250e76987d838a75310c34bf422ea9f1ac4cc9060000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000002cdfc90250ef967036838da601099656e74bcfc50000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000009a016ce184a22dbf6c17daa59eb7d3140dbd1c5400000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000c616464457874656e73696f6e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f72656d6f7665457874656e73696f6e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d72656769737465724173736574000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000' + ]; + return [fromContractWhiteList,contractMethodWhiteList]; + + case 6 : //bsc + fromContractWhiteList = [ + '0x2f7ac9436ba4B548f9582af91CA1Ef02cd2F1f03', + '0x00b93851e3135663AAeC351555EddEE5B01325e6', + '0x2cdfc90250EF967036838DA601099656e74bCfc5', + '0xb5d4f343412dc8efb6ff599d790074d0f1e8d430', + '0x6B7C026621d53d092FB446C2162D1DFc048bC9D7', + '0xf14a7d43bedaC1C17Da9C22cf3D8c900AA8DEcA9', + '0x9800c0EB44cCb5423bb95205921fCb5FFa066a62', + '0xa61E289C29c47A2EEA7092355602De8A0dCB16e2', + '0x3803e2A56F657922b76211ab22eAFE6C0Aa4F95f', + '0x303E57962D735A8dfC7CA5d30676d48A63AF7338', + '0x5601D189D5751e4f9dde2E598999228B4a5DB9e2', + '0x58EEac66d46d90Cc1c563CABc2c77D610B91284c', + '0xd397a9F470212d419AcEC535783aeD8145E58853', + '0xaeD9013944dFD09a16e5c4115ce45c48520383CE', + '0xB8c221dc3EE9132015AE6816cEF428089498fB82', + '0x6cE07781968c5f4747AcDd46D0975A797a8B1143', + '0x54CF38E6B75859cD7958d3B7bc020a1b89482d7E', + '0xc7d0d0E5bcfe73799EEcc1aD7204e9c52ea014eC', + '0x19630C41EeD3d437348FF8A6ddcB9FAcF550AC41' + ]; + contractMethodWhiteList = [ + '0x0000000000000000000000002f7ac9436ba4b548f9582af91ca1ef02cd2f1f030000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000002cdfc90250ef967036838da601099656e74bcfc50000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x000000000000000000000000b5d4f343412dc8efb6ff599d790074d0f1e8d43000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000c616464457874656e73696f6e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f72656d6f7665457874656e73696f6e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d72656769737465724173736574000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000006b7c026621d53d092fb446c2162d1dfc048bc9d7000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000f14a7d43bedac1c17da9c22cf3d8c900aa8deca9000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000009800c0eb44ccb5423bb95205921fcb5ffa066a62000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000a61e289c29c47a2eea7092355602de8a0dcb16e2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000003803e2a56f657922b76211ab22eafe6c0aa4f95f000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000303e57962d735a8dfc7ca5d30676d48a63af7338000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000005601d189d5751e4f9dde2e598999228b4a5db9e2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000058eeac66d46d90cc1c563cabc2c77d610b91284c000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000d397a9f470212d419acec535783aed8145e58853000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000aed9013944dfd09a16e5c4115ce45c48520383ce000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000b8c221dc3ee9132015ae6816cef428089498fb82000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000006ce07781968c5f4747acdd46d0975a797a8b1143000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000054cf38e6b75859cd7958d3b7bc020a1b89482d7e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000c7d0d0e5bcfe73799eecc1ad7204e9c52ea014ec000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000019630c41eed3d437348ff8a6ddcb9facf550ac41000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000' + ]; + return [fromContractWhiteList,contractMethodWhiteList]; + + case 7 : // heco + fromContractWhiteList = [ + '0x020c15e7d08A8Ec7D35bCf3AC3CCbF0BBf2704e6', + '0xD98Ee7Ca1B33e60C75E3cd9493c566fc857592c8', + '0x2cdfc90250EF967036838DA601099656e74bCfc5', + '0xA38a2038136a57B6B1019a50A91Ab66738905a8A', + '0xfa8440025d7EE21925be5A4adfd4aC35A156e0ed', + '0x8b963E30f67C9a6C3F88306e799Fe2bBC3626f2E', + '0xdf42B52157c10aaD666886dB0AB8Bb99b6485ae6', + '0xAfFb645d73A784Ab53D074488349fF4dC22D3435', + '0x93D3B6713c08F50C576490c7C975E1D315927EF3', + '0x6F5E4F841DAbEac07A9270cdD26421aA869A59Bb', + '0x64840C731022E51b20Dc5aeA6180F1b2299b5De1', + '0x5C3CD4846d07548020eD9F40a08Fd66D16f71fE7', + '0xB6626Eb5BB5918D01593Ad8504E4513f4385b62b', + '0x5902BDbB4FDD0d44e2871577eaA46Fd0b3424B3e', + '0xb4F8FeBb7372F47bEa2B06B6F9D878093a3B014E', + '0x22A3f421115FbF2eda8AbCb56CE63219481C2A6C', + '0x37De929B55B811FEe16a9244a0De6aac008c3F3C', + '0xC5293535d05A98f73f5e2Af9A804363FA39BE5f3' + ]; + contractMethodWhiteList = [ + '0x000000000000000000000000020c15e7d08a8ec7d35bcf3ac3ccbf0bbf2704e60000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000002cdfc90250ef967036838da601099656e74bcfc50000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x000000000000000000000000a38a2038136a57b6b1019a50a91ab66738905a8a000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000fa8440025d7ee21925be5a4adfd4ac35a156e0ed000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000008b963e30f67c9a6c3f88306e799fe2bbc3626f2e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000df42b52157c10aad666886db0ab8bb99b6485ae6000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000affb645d73a784ab53d074488349ff4dc22d3435000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000093d3b6713c08f50c576490c7c975e1d315927ef3000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000006f5e4f841dabeac07a9270cdd26421aa869a59bb000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000064840c731022e51b20dc5aea6180f1b2299b5de1000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000005c3cd4846d07548020ed9f40a08fd66d16f71fe7000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000b6626eb5bb5918d01593ad8504e4513f4385b62b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000005902bdbb4fdd0d44e2871577eaa46fd0b3424b3e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000b4f8febb7372f47bea2b06b6f9d878093a3b014e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000022a3f421115fbf2eda8abcb56ce63219481c2a6c000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000037de929b55b811fee16a9244a0de6aac008c3f3c000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000c5293535d05a98f73f5e2af9a804363fa39be5f3000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000' + ]; + return [fromContractWhiteList,contractMethodWhiteList]; + + case 12 : // ok + fromContractWhiteList = [ + '0x9a3658864Aa2Ccc63FA61eAAD5e4f65fA490cA7D', + '0x6d981C8535af305915c7eC2FceFA126d6286c0F5', + '0xA7FeD91A00fE5847cc4970a1122fA5bCf2700291', + '0x8b0963Ac00776111160f9bAB0E1835719ce5ff6C', + '0x1ee6dCa80F09E7d387DbFA8EB2Dea08e83FaD182', + '0xBe7F5e9eC0b1911251D61Ac64860a315a5185A18', + '0xA08584E87703Da3E454133080362FfBE545dEf11', + '0xf2575b39ADF3fC2d9370862e17efDCC79D935c00', + '0xaca1227d3526D78a7Df361dF3495Aa2A64042808', + '0xdE8B716F43dcD94e4D4afE73D040825b2E990E6D', + '0x35b161F6F1Aa5787045505bd2E8307195485725D', + '0xf195EeC267130FFF260b107a26b94976f59e09e2', + '0x353881c2afda8D07Db6c01f59D91Bef75570d4D2', + '0xA86E17e1B40F251d50Ce64Da1f2F824Ff9520E44', + '0xE5bbC1FaF1dD83251B2949c08dE53Ba86BFf4Fb8', + '0x5CB3Ff30Ae417fddC9301b64C35A211f40f801C2' + ]; + contractMethodWhiteList = [ + '0x0000000000000000000000009a3658864aa2ccc63fa61eaad5e4f65fa490ca7d0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000006d981c8535af305915c7ec2fcefa126d6286c0f5000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000a7fed91a00fe5847cc4970a1122fa5bcf2700291000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000008b0963ac00776111160f9bab0e1835719ce5ff6c000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000001ee6dca80f09e7d387dbfa8eb2dea08e83fad182000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000be7f5e9ec0b1911251d61ac64860a315a5185a18000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000a08584e87703da3e454133080362ffbe545def11000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000f2575b39adf3fc2d9370862e17efdcc79d935c00000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000aca1227d3526d78a7df361df3495aa2a64042808000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000de8b716f43dcd94e4d4afe73d040825b2e990e6d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000035b161f6f1aa5787045505bd2e8307195485725d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000f195eec267130fff260b107a26b94976f59e09e2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000353881c2afda8d07db6c01f59d91bef75570d4d2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000a86e17e1b40f251d50ce64da1f2f824ff9520e44000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000e5bbc1faf1dd83251b2949c08de53ba86bff4fb8000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000005cb3ff30ae417fddc9301b64c35a211f40f801c2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000' + ]; + return [fromContractWhiteList,contractMethodWhiteList]; + + case 17 : // polygon + fromContractWhiteList = [ + '0x28ff66a1b95d7cacf8eded2e658f768f44841212', + '0xaC57280B3A657A2e8D1180493C519a476D208F61', + '0xf14a7d43bedaC1C17Da9C22cf3D8c900AA8DEcA9', + '0x9800c0EB44cCb5423bb95205921fCb5FFa066a62', + '0xa61E289C29c47A2EEA7092355602De8A0dCB16e2', + '0x3803e2A56F657922b76211ab22eAFE6C0Aa4F95f', + '0x303E57962D735A8dfC7CA5d30676d48A63AF7338', + '0x5601D189D5751e4f9dde2E598999228B4a5DB9e2', + '0xaca1227d3526D78a7Df361dF3495Aa2A64042808', + '0xdE8B716F43dcD94e4D4afE73D040825b2E990E6D', + '0x35b161F6F1Aa5787045505bd2E8307195485725D', + '0x2d7Fe908524180D17C058e6C5388738C1b30d198', + '0x487Fd5C13f5764b798D4AecaEA79B2e0DF5d3952', + '0x1B49485342C38C83f5376efF64800b52ee35787F', + '0x6e4475B49f5b2d0f06D6B7218C80C2A588252889', + '0x039DB2Fc6377b20A30ac9F05eb6477ce7461cB0b', + '0x32cAf282bdb48147C157285E0eb715fbFa07826a' + ]; + contractMethodWhiteList = [ + '0x00000000000000000000000028ff66a1b95d7cacf8eded2e658f768f448412120000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x000000000000000000000000f14a7d43bedac1c17da9c22cf3d8c900aa8deca9000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000009800c0eb44ccb5423bb95205921fcb5ffa066a62000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000a61e289c29c47a2eea7092355602de8a0dcb16e2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000003803e2a56f657922b76211ab22eafe6c0aa4f95f000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000303e57962d735a8dfc7ca5d30676d48a63af7338000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000005601d189d5751e4f9dde2e598999228b4a5db9e2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000aca1227d3526d78a7df361df3495aa2a64042808000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000de8b716f43dcd94e4d4afe73d040825b2e990e6d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000035b161f6f1aa5787045505bd2e8307195485725d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000002d7fe908524180d17c058e6c5388738c1b30d198000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000487fd5c13f5764b798d4aecaea79b2e0df5d3952000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000001b49485342c38c83f5376eff64800b52ee35787f000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000006e4475b49f5b2d0f06d6b7218c80c2a588252889000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000039db2fc6377b20a30ac9f05eb6477ce7461cb0b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000032caf282bdb48147c157285e0eb715fbfa07826a000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000' + ]; + return [fromContractWhiteList,contractMethodWhiteList]; + + case 19 : // arbitrum + fromContractWhiteList = [ + '0x2f7ac9436ba4B548f9582af91CA1Ef02cd2F1f03', + '0x7E418a9926c8D1cbd09CC93E8051cC3BbdfE3854' + ]; + contractMethodWhiteList = [ + '0x0000000000000000000000002f7ac9436ba4b548f9582af91ca1ef02cd2f1f030000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000' + ]; + return [fromContractWhiteList,contractMethodWhiteList]; + + default : + throw new Error("fail to get WhiteListInfo, unknown Network: "+polyId); + } +} + +async function getPolyChainId() { + const chainId = await hre.web3.eth.getChainId(); + switch (chainId) { + + // mainnet + case 1: // eth-main + return 2; + case 56: // bsc-main + return 6; + case 128: // heco-main + return 7; + case 137: // polygon-main + return 17; + case 66: // ok-main + return 12; + case 1718: // plt-main + return 8; + case 42161: // arbitrum-main + return 19; + + // testnet + case 3: // eth-test + return 2; + case 97: // bsc-test + return 79; + case 256: // heco-test + return 7; + case 80001: // polygon-test + return 202; + case 65: // ok-test + return 200; + case 101: // plt-test + return 107; + case 421611: // arbitrum-test + return 205; + + // hardhat devnet + case 31337: + return 77777; + + // unknown chainid + default: + throw new Error("fail to get Poly_Chain_Id, unknown Network_Id: "+chainId); + } +} + +// We recommend this pattern to be able to use async/await everywhere +// and properly handle errors. +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); + diff --git a/scripts/update.js b/scripts/update.js new file mode 100644 index 0000000..f211e1b --- /dev/null +++ b/scripts/update.js @@ -0,0 +1,406 @@ +const { ethers } = require("hardhat"); +const hre = require("hardhat"); +const fs = require("fs"); +const Web3 = require("web3"); +const colors = require('colors'); +const { expect } = require("chai"); +hre.web3 = new Web3(hre.network.provider); + +async function main() { + + [deployer] = await hre.ethers.getSigners(); + + let polyId; + let _eccd; + let _old_ccm; + let _ccmp; + let fromContractWhiteList; + let contractMethodWhiteList; + + // check polyId + await getPolyChainId().then((_polyId) => { + polyId = _polyId; + console.log("\nUpdate EthCrossChainManager on chain with Poly_Chain_Id:".cyan, _polyId); + }).catch((error) => { + throw error; + });; + + try { + [_eccd, _old_ccm, _ccmp] = getDeployedContract(polyId); + } catch(error) { + throw error; + } + + try { + [fromContractWhiteList,contractMethodWhiteList] = getWhiteListInfo(polyId); + } catch(error) { + throw error; + } + + const ECCD = await hre.ethers.getContractFactory("EthCrossChainData"); + const CCM = await hre.ethers.getContractFactory("EthCrossChainManager"); + const CCMP = await hre.ethers.getContractFactory("EthCrossChainManagerProxy"); + + let eccd = ECCD.attach(_eccd); + let old_ccm = CCM.attach(_old_ccm); + let ccmp = CCMP.attach(_ccmp); + + // check if given contracts are valid + expect(await old_ccm.chainId()).to.equal(polyId); + expect(await eccd.owner()).to.equal(old_ccm.address); + expect(await old_ccm.owner()).to.equal(ccmp.address); + //expect(await ccmp.getEthCrossChainManager()).to.equal(old_ccm.address); + expect(await hre.web3.eth.getStorageAt(ccmp.address,1)).to.equal('0x000000000000000000000000'+old_ccm.address.slice(2).toLowerCase()); + expect(await old_ccm.EthCrossChainDataAddress()).to.equal(eccd.address); + + console.log("Start , deployer:".cyan, deployer.address.blue); + + // deploy EthCrossChainManager + console.log("\ndeploy new EthCrossChainManager ......".cyan); + let ccm = await CCM.deploy(eccd.address, polyId, fromContractWhiteList, contractMethodWhiteList); + await ccm.deployed(); + console.log("New EthCrossChainManager deployed to:".green, ccm.address.blue); + + // transfer ownership + console.log("\ntransfer new ccm's ownership to ccmp ......".cyan); + tx = await ccm.transferOwnership(ccmp.address); + await tx.wait(); + expect(await ccm.owner()).to.equal(ccmp.address); + console.log("ownership transferred".green); + + // paused + console.log("\nCheck if paused and pause if not".cyan); + let paused_1 = await ccmp.paused(); + let paused_2 = await old_ccm.paused(); + if (!paused_1 && paused_2) { + tx = await ccmp.pause(); + await tx.wait(); + } else if (!paused_1 && !paused_2) { + tx = await ccmp.pauseEthCrossChainManager(); + await tx.wait(); + } else if (paused_1 && !paused_2) { + tx = await ccmp.unpause(); + await tx.wait(); + tx = await ccmp.pauseEthCrossChainManager(); + await tx.wait(); + } + expect(await ccmp.paused()).to.equal(true); + expect(await old_ccm.paused()).to.equal(true); + console.log("all paused".green); + + // update to new + console.log("\nUpdate to new ccm".cyan); + tx = await ccmp.upgradeEthCrossChainManager(ccm.address); + await tx.wait(); + expect(await eccd.owner()).to.equal(ccm.address); + expect(await ccm.owner()).to.equal(ccmp.address); + expect(await hre.web3.eth.getStorageAt(ccmp.address,1)).to.equal('0x000000000000000000000000'+ccm.address.slice(2).toLowerCase()); + expect(await ccm.EthCrossChainDataAddress()).to.equal(eccd.address); + console.log("updated".green); + + // unpaused + console.log("\nUnpaused all".cyan); + tx = await ccmp.unpauseEthCrossChainManager(); + await tx.wait(); + expect(await ccmp.paused()).to.equal(false); + expect(await ccm.paused()).to.equal(false); + console.log("unpaused".green); + + console.log("\nDone.\n".magenta); + +} + +function getDeployedContract(polyId) { + switch (polyId) { + case 2 : //eth + eccd = '0xcf2afe102057ba5c16f899271045a0a37fcb10f2'; + ccm = '0xe020877e67CfAAFFC33a6E7eB9e85741bbb3eA79'; + ccmp = '0x5a51e2ebf8d136926b9ca7b59b60464e7c44d2eb'; + return [eccd, ccm, ccmp]; + + case 6 : //bsc + eccd = '0x11e2A718d46EBe97645b87F2363AFE1BF28c2672'; + ccm = '0x00EeE7b864062c40F8096f948a2B0Db3c28aa6fE'; + ccmp = '0xABD7f7B89c5fD5D0AEf06165f8173b1b83d7D5c9'; + return [eccd, ccm, ccmp]; + + case 7 : //heco + eccd = '0x11e2A718d46EBe97645b87F2363AFE1BF28c2672'; + ccm = '0x59A2C3062D9F1097D5CD239FA1BAbE6cb64fB96C'; + ccmp = '0xABD7f7B89c5fD5D0AEf06165f8173b1b83d7D5c9'; + return [eccd, ccm, ccmp]; + + case 12 : //ok + eccd = '0xdb3A0149f3155cC1B6890FE382d309dB4b322630'; + ccm = '0x3758fD8D5c29AD2620De837Da7531Bb4d1f64EDc'; + ccmp = '0x4739fe955BE4704BcB7d6a699823F5B29217Baf6'; + return [eccd, ccm, ccmp]; + + case 17 : //polygon + eccd = '0x7cea671dabfba880af6723bddd6b9f4caa15c87b'; + ccm = '0x39Cd00c5d0fa3e880B86B6a76224a18128DE89E5'; + ccmp = '0x5366ea2b5b729ff3cef404c2408c8c60cc061b71'; + return [eccd, ccm, ccmp]; + + case 19 : //arbitrum + eccd = '0x11e2A718d46EBe97645b87F2363AFE1BF28c2672'; + ccm = '0x7ceA671DABFBa880aF6723bDdd6B9f4caA15C87B'; + ccmp = '0xABD7f7B89c5fD5D0AEf06165f8173b1b83d7D5c9'; + return [eccd, ccm, ccmp]; + + default : + throw new Error("fail to get DeployedContract, unknown Network: "+polyId); + } +} + +function getWhiteListInfo(polyId) { + switch (polyId) { + case 2 : //eth + fromContractWhiteList = [ + '0x250e76987d838a75310c34bf422ea9f1AC4Cc906', + '0xaf83ce8d461e8834de03a3803c968615013c6b3d', + '0x2cdfc90250EF967036838DA601099656e74bCfc5', + '0x9a016ce184a22dbf6c17daa59eb7d3140dbd1c54' + ]; + contractMethodWhiteList = [ + '0x000000000000000000000000250e76987d838a75310c34bf422ea9f1ac4cc9060000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000002cdfc90250ef967036838da601099656e74bcfc50000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000009a016ce184a22dbf6c17daa59eb7d3140dbd1c5400000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000c616464457874656e73696f6e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f72656d6f7665457874656e73696f6e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d72656769737465724173736574000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000' + ]; + return [fromContractWhiteList,contractMethodWhiteList]; + + case 6 : //bsc + fromContractWhiteList = [ + '0x2f7ac9436ba4B548f9582af91CA1Ef02cd2F1f03', + '0x00b93851e3135663AAeC351555EddEE5B01325e6', + '0x2cdfc90250EF967036838DA601099656e74bCfc5', + '0xb5d4f343412dc8efb6ff599d790074d0f1e8d430', + '0x6B7C026621d53d092FB446C2162D1DFc048bC9D7', + '0xf14a7d43bedaC1C17Da9C22cf3D8c900AA8DEcA9', + '0x9800c0EB44cCb5423bb95205921fCb5FFa066a62', + '0xa61E289C29c47A2EEA7092355602De8A0dCB16e2', + '0x3803e2A56F657922b76211ab22eAFE6C0Aa4F95f', + '0x303E57962D735A8dfC7CA5d30676d48A63AF7338', + '0x5601D189D5751e4f9dde2E598999228B4a5DB9e2', + '0x58EEac66d46d90Cc1c563CABc2c77D610B91284c', + '0xd397a9F470212d419AcEC535783aeD8145E58853', + '0xaeD9013944dFD09a16e5c4115ce45c48520383CE', + '0xB8c221dc3EE9132015AE6816cEF428089498fB82', + '0x6cE07781968c5f4747AcDd46D0975A797a8B1143', + '0x54CF38E6B75859cD7958d3B7bc020a1b89482d7E', + '0xc7d0d0E5bcfe73799EEcc1aD7204e9c52ea014eC', + '0x19630C41EeD3d437348FF8A6ddcB9FAcF550AC41' + ]; + contractMethodWhiteList = [ + '0x0000000000000000000000002f7ac9436ba4b548f9582af91ca1ef02cd2f1f030000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000002cdfc90250ef967036838da601099656e74bcfc50000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x000000000000000000000000b5d4f343412dc8efb6ff599d790074d0f1e8d43000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000c616464457874656e73696f6e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f72656d6f7665457874656e73696f6e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d72656769737465724173736574000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000006b7c026621d53d092fb446c2162d1dfc048bc9d7000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000f14a7d43bedac1c17da9c22cf3d8c900aa8deca9000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000009800c0eb44ccb5423bb95205921fcb5ffa066a62000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000a61e289c29c47a2eea7092355602de8a0dcb16e2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000003803e2a56f657922b76211ab22eafe6c0aa4f95f000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000303e57962d735a8dfc7ca5d30676d48a63af7338000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000005601d189d5751e4f9dde2e598999228b4a5db9e2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000058eeac66d46d90cc1c563cabc2c77d610b91284c000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000d397a9f470212d419acec535783aed8145e58853000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000aed9013944dfd09a16e5c4115ce45c48520383ce000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000b8c221dc3ee9132015ae6816cef428089498fb82000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000006ce07781968c5f4747acdd46d0975a797a8b1143000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000054cf38e6b75859cd7958d3b7bc020a1b89482d7e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000c7d0d0e5bcfe73799eecc1ad7204e9c52ea014ec000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000019630c41eed3d437348ff8a6ddcb9facf550ac41000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000' + ]; + return [fromContractWhiteList,contractMethodWhiteList]; + + case 7 : // heco + fromContractWhiteList = [ + '0x020c15e7d08A8Ec7D35bCf3AC3CCbF0BBf2704e6', + '0xD98Ee7Ca1B33e60C75E3cd9493c566fc857592c8', + '0x2cdfc90250EF967036838DA601099656e74bCfc5', + '0xA38a2038136a57B6B1019a50A91Ab66738905a8A', + '0xfa8440025d7EE21925be5A4adfd4aC35A156e0ed', + '0x8b963E30f67C9a6C3F88306e799Fe2bBC3626f2E', + '0xdf42B52157c10aaD666886dB0AB8Bb99b6485ae6', + '0xAfFb645d73A784Ab53D074488349fF4dC22D3435', + '0x93D3B6713c08F50C576490c7C975E1D315927EF3', + '0x6F5E4F841DAbEac07A9270cdD26421aA869A59Bb', + '0x64840C731022E51b20Dc5aeA6180F1b2299b5De1', + '0x5C3CD4846d07548020eD9F40a08Fd66D16f71fE7', + '0xB6626Eb5BB5918D01593Ad8504E4513f4385b62b', + '0x5902BDbB4FDD0d44e2871577eaA46Fd0b3424B3e', + '0xb4F8FeBb7372F47bEa2B06B6F9D878093a3B014E', + '0x22A3f421115FbF2eda8AbCb56CE63219481C2A6C', + '0x37De929B55B811FEe16a9244a0De6aac008c3F3C', + '0xC5293535d05A98f73f5e2Af9A804363FA39BE5f3' + ]; + contractMethodWhiteList = [ + '0x000000000000000000000000020c15e7d08a8ec7d35bcf3ac3ccbf0bbf2704e60000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000002cdfc90250ef967036838da601099656e74bcfc50000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x000000000000000000000000a38a2038136a57b6b1019a50a91ab66738905a8a000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000fa8440025d7ee21925be5a4adfd4ac35a156e0ed000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000008b963e30f67c9a6c3f88306e799fe2bbc3626f2e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000df42b52157c10aad666886db0ab8bb99b6485ae6000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000affb645d73a784ab53d074488349ff4dc22d3435000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000093d3b6713c08f50c576490c7c975e1d315927ef3000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000006f5e4f841dabeac07a9270cdd26421aa869a59bb000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000064840c731022e51b20dc5aea6180f1b2299b5de1000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000005c3cd4846d07548020ed9f40a08fd66d16f71fe7000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000b6626eb5bb5918d01593ad8504e4513f4385b62b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000005902bdbb4fdd0d44e2871577eaa46fd0b3424b3e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000b4f8febb7372f47bea2b06b6f9d878093a3b014e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000022a3f421115fbf2eda8abcb56ce63219481c2a6c000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000037de929b55b811fee16a9244a0de6aac008c3f3c000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000c5293535d05a98f73f5e2af9a804363fa39be5f3000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000' + ]; + return [fromContractWhiteList,contractMethodWhiteList]; + + case 12 : // ok + fromContractWhiteList = [ + '0x9a3658864Aa2Ccc63FA61eAAD5e4f65fA490cA7D', + '0x6d981C8535af305915c7eC2FceFA126d6286c0F5', + '0xA7FeD91A00fE5847cc4970a1122fA5bCf2700291', + '0x8b0963Ac00776111160f9bAB0E1835719ce5ff6C', + '0x1ee6dCa80F09E7d387DbFA8EB2Dea08e83FaD182', + '0xBe7F5e9eC0b1911251D61Ac64860a315a5185A18', + '0xA08584E87703Da3E454133080362FfBE545dEf11', + '0xf2575b39ADF3fC2d9370862e17efDCC79D935c00', + '0xaca1227d3526D78a7Df361dF3495Aa2A64042808', + '0xdE8B716F43dcD94e4D4afE73D040825b2E990E6D', + '0x35b161F6F1Aa5787045505bd2E8307195485725D', + '0xf195EeC267130FFF260b107a26b94976f59e09e2', + '0x353881c2afda8D07Db6c01f59D91Bef75570d4D2', + '0xA86E17e1B40F251d50Ce64Da1f2F824Ff9520E44', + '0xE5bbC1FaF1dD83251B2949c08dE53Ba86BFf4Fb8', + '0x5CB3Ff30Ae417fddC9301b64C35A211f40f801C2' + ]; + contractMethodWhiteList = [ + '0x0000000000000000000000009a3658864aa2ccc63fa61eaad5e4f65fa490ca7d0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000006d981c8535af305915c7ec2fcefa126d6286c0f5000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000a7fed91a00fe5847cc4970a1122fa5bcf2700291000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000008b0963ac00776111160f9bab0e1835719ce5ff6c000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000001ee6dca80f09e7d387dbfa8eb2dea08e83fad182000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000be7f5e9ec0b1911251d61ac64860a315a5185a18000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000a08584e87703da3e454133080362ffbe545def11000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000f2575b39adf3fc2d9370862e17efdcc79d935c00000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000aca1227d3526d78a7df361df3495aa2a64042808000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000de8b716f43dcd94e4d4afe73d040825b2e990e6d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000035b161f6f1aa5787045505bd2e8307195485725d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000f195eec267130fff260b107a26b94976f59e09e2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000353881c2afda8d07db6c01f59d91bef75570d4d2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000a86e17e1b40f251d50ce64da1f2f824ff9520e44000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000e5bbc1faf1dd83251b2949c08de53ba86bff4fb8000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000005cb3ff30ae417fddc9301b64c35a211f40f801c2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000' + ]; + return [fromContractWhiteList,contractMethodWhiteList]; + + case 17 : // polygon + fromContractWhiteList = [ + '0x28ff66a1b95d7cacf8eded2e658f768f44841212', + '0xaC57280B3A657A2e8D1180493C519a476D208F61', + '0xf14a7d43bedaC1C17Da9C22cf3D8c900AA8DEcA9', + '0x9800c0EB44cCb5423bb95205921fCb5FFa066a62', + '0xa61E289C29c47A2EEA7092355602De8A0dCB16e2', + '0x3803e2A56F657922b76211ab22eAFE6C0Aa4F95f', + '0x303E57962D735A8dfC7CA5d30676d48A63AF7338', + '0x5601D189D5751e4f9dde2E598999228B4a5DB9e2', + '0xaca1227d3526D78a7Df361dF3495Aa2A64042808', + '0xdE8B716F43dcD94e4D4afE73D040825b2E990E6D', + '0x35b161F6F1Aa5787045505bd2E8307195485725D', + '0x2d7Fe908524180D17C058e6C5388738C1b30d198', + '0x487Fd5C13f5764b798D4AecaEA79B2e0DF5d3952', + '0x1B49485342C38C83f5376efF64800b52ee35787F', + '0x6e4475B49f5b2d0f06D6B7218C80C2A588252889', + '0x039DB2Fc6377b20A30ac9F05eb6477ce7461cB0b', + '0x32cAf282bdb48147C157285E0eb715fbFa07826a' + ]; + contractMethodWhiteList = [ + '0x00000000000000000000000028ff66a1b95d7cacf8eded2e658f768f448412120000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x000000000000000000000000f14a7d43bedac1c17da9c22cf3d8c900aa8deca9000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000009800c0eb44ccb5423bb95205921fcb5ffa066a62000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000a61e289c29c47a2eea7092355602de8a0dcb16e2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000003803e2a56f657922b76211ab22eafe6c0aa4f95f000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000303e57962d735a8dfc7ca5d30676d48a63af7338000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000005601d189d5751e4f9dde2e598999228b4a5db9e2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000aca1227d3526d78a7df361df3495aa2a64042808000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000de8b716f43dcd94e4d4afe73d040825b2e990e6d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000035b161f6f1aa5787045505bd2e8307195485725d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000002d7fe908524180d17c058e6c5388738c1b30d198000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000487fd5c13f5764b798d4aecaea79b2e0df5d3952000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000001b49485342c38c83f5376eff64800b52ee35787f000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000006e4475b49f5b2d0f06d6b7218c80c2a588252889000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000039db2fc6377b20a30ac9f05eb6477ce7461cb0b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000032caf282bdb48147c157285e0eb715fbfa07826a000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000' + ]; + return [fromContractWhiteList,contractMethodWhiteList]; + + case 19 : // arbitrum + fromContractWhiteList = [ + '0x2f7ac9436ba4B548f9582af91CA1Ef02cd2F1f03', + '0x7E418a9926c8D1cbd09CC93E8051cC3BbdfE3854' + ]; + contractMethodWhiteList = [ + '0x0000000000000000000000002f7ac9436ba4b548f9582af91ca1ef02cd2f1f030000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000' + ]; + return [fromContractWhiteList,contractMethodWhiteList]; + + default : + throw new Error("fail to get WhiteListInfo, unknown Network: "+polyId); + } +} + +async function getPolyChainId() { + const chainId = await hre.web3.eth.getChainId(); + switch (chainId) { + + // mainnet + case 1: // eth-main + return 2; + case 56: // bsc-main + return 6; + case 128: // heco-main + return 7; + case 137: // polygon-main + return 17; + case 66: // ok-main + return 12; + case 1718: // plt-main + return 8; + case 42161: // arbitrum-main + return 19; + + // testnet + case 3: // eth-test + return 2; + case 97: // bsc-test + return 79; + case 256: // heco-test + return 7; + case 80001: // polygon-test + return 202; + case 65: // ok-test + return 200; + case 101: // plt-test + return 107; + case 421611: // arbitrum-test + return 205; + + // hardhat devnet + case 31337: + return 77777; + + // unknown chainid + default: + throw new Error("fail to get Poly_Chain_Id, unknown Network_Id: "+chainId); + } +} + +// We recommend this pattern to be able to use async/await everywhere +// and properly handle errors. +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); + diff --git a/scripts/update_testnet.js b/scripts/update_testnet.js new file mode 100644 index 0000000..bf33c39 --- /dev/null +++ b/scripts/update_testnet.js @@ -0,0 +1,368 @@ +const { ethers } = require("hardhat"); +const hre = require("hardhat"); +const fs = require("fs"); +const Web3 = require("web3"); +const colors = require('colors'); +const { expect } = require("chai"); +hre.web3 = new Web3(hre.network.provider); + +async function main() { + + [deployer] = await hre.ethers.getSigners(); + + let polyId; + let _eccd; + let _old_ccm; + let _ccmp; + + // check polyId + await getPolyChainId().then((_polyId) => { + polyId = _polyId; + console.log("\nUpdate EthCrossChainManager on chain with Poly_Chain_Id:".cyan, _polyId); + }).catch((error) => { + throw error; + });; + + try { + [_eccd, _old_ccm, _ccmp] = getDeployedContract(polyId); + } catch(error) { + throw error; + } + + const ECCD = await hre.ethers.getContractFactory("EthCrossChainData"); + const CCM = await hre.ethers.getContractFactory("EthCrossChainManagerNoWhiteList"); + const CCMP = await hre.ethers.getContractFactory("EthCrossChainManagerProxy"); + + let eccd = ECCD.attach(_eccd); + let old_ccm = CCM.attach(_old_ccm); + let ccmp = CCMP.attach(_ccmp); + + // check if given contracts are valid + expect(await old_ccm.chainId()).to.equal(polyId); + expect(await eccd.owner()).to.equal(old_ccm.address); + expect(await old_ccm.owner()).to.equal(ccmp.address); + //expect(await ccmp.getEthCrossChainManager()).to.equal(old_ccm.address); + expect(await hre.web3.eth.getStorageAt(ccmp.address,1)).to.equal('0x000000000000000000000000'+old_ccm.address.slice(2).toLowerCase()); + expect(await old_ccm.EthCrossChainDataAddress()).to.equal(eccd.address); + + console.log("Start , deployer:".cyan, deployer.address.blue); + + // deploy EthCrossChainManager + console.log("\ndeploy new EthCrossChainManager ......".cyan); + let ccm = await CCM.deploy(eccd.address, polyId); + await ccm.deployed(); + console.log("New EthCrossChainManager deployed to:".green, ccm.address.blue); + + // transfer ownership + console.log("\ntransfer new ccm's ownership to ccmp ......".cyan); + tx = await ccm.transferOwnership(ccmp.address); + await tx.wait(); + expect(await ccm.owner()).to.equal(ccmp.address); + console.log("ownership transferred".green); + + // paused + console.log("\nCheck if paused and pause if not".cyan); + let paused_1 = await ccmp.paused(); + let paused_2 = await old_ccm.paused(); + if (!paused_1 && paused_2) { + tx = await ccmp.pause(); + await tx.wait(); + } else if (!paused_1 && !paused_2) { + tx = await ccmp.pauseEthCrossChainManager(); + await tx.wait(); + } else if (paused_1 && !paused_2) { + tx = await ccmp.unpause(); + await tx.wait(); + tx = await ccmp.pauseEthCrossChainManager(); + await tx.wait(); + } + expect(await ccmp.paused()).to.equal(true); + expect(await old_ccm.paused()).to.equal(true); + console.log("all paused".green); + + // update to new + console.log("\nUpdate to new ccm".cyan); + tx = await ccmp.upgradeEthCrossChainManager(ccm.address); + await tx.wait(); + expect(await eccd.owner()).to.equal(ccm.address); + expect(await ccm.owner()).to.equal(ccmp.address); + expect(await hre.web3.eth.getStorageAt(ccmp.address,1)).to.equal('0x000000000000000000000000'+ccm.address.slice(2).toLowerCase()); + expect(await ccm.EthCrossChainDataAddress()).to.equal(eccd.address); + console.log("updated".green); + + // unpaused + console.log("\nUnpaused all".cyan); + tx = await ccmp.unpauseEthCrossChainManager(); + await tx.wait(); + expect(await ccmp.paused()).to.equal(false); + expect(await ccm.paused()).to.equal(false); + console.log("unpaused".green); + + console.log("\nDone.\n".magenta); + +} + +function getDeployedContract(polyId) { + switch (polyId) { + case 2 : // ropsten + eccd = '0xA38366d552672556CE82426Da5031E2Ae0598dcD'; + ccm = '0xeC923170324db31cd9cd43C87483D04a2C73F388'; + ccmp = '0xb600c8a2e8852832B75DB9Da1A3A1c173eAb28d8'; + return [eccd, ccm, ccmp]; + + default : + throw new Error("fail to get DeployedContract, unknown Network: "+polyId); + } +} + +function getWhiteListInfo(polyId) { + switch (polyId) { + case 2 : //eth + fromContractWhiteList = [ + '0x250e76987d838a75310c34bf422ea9f1AC4Cc906', + '0xaf83ce8d461e8834de03a3803c968615013c6b3d', + '0x2cdfc90250EF967036838DA601099656e74bCfc5', + '0x9a016ce184a22dbf6c17daa59eb7d3140dbd1c54' + ]; + contractMethodWhiteList = [ + '0x000000000000000000000000250e76987d838a75310c34bf422ea9f1ac4cc9060000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000002cdfc90250ef967036838da601099656e74bcfc50000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000009a016ce184a22dbf6c17daa59eb7d3140dbd1c5400000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000c616464457874656e73696f6e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f72656d6f7665457874656e73696f6e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d72656769737465724173736574000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000' + ]; + return [fromContractWhiteList,contractMethodWhiteList]; + + case 6 : //bsc + fromContractWhiteList = [ + '0x2f7ac9436ba4B548f9582af91CA1Ef02cd2F1f03', + '0x00b93851e3135663AAeC351555EddEE5B01325e6', + '0x2cdfc90250EF967036838DA601099656e74bCfc5', + '0xb5d4f343412dc8efb6ff599d790074d0f1e8d430', + '0x6B7C026621d53d092FB446C2162D1DFc048bC9D7', + '0xf14a7d43bedaC1C17Da9C22cf3D8c900AA8DEcA9', + '0x9800c0EB44cCb5423bb95205921fCb5FFa066a62', + '0xa61E289C29c47A2EEA7092355602De8A0dCB16e2', + '0x3803e2A56F657922b76211ab22eAFE6C0Aa4F95f', + '0x303E57962D735A8dfC7CA5d30676d48A63AF7338', + '0x5601D189D5751e4f9dde2E598999228B4a5DB9e2', + '0x58EEac66d46d90Cc1c563CABc2c77D610B91284c', + '0xd397a9F470212d419AcEC535783aeD8145E58853', + '0xaeD9013944dFD09a16e5c4115ce45c48520383CE', + '0xB8c221dc3EE9132015AE6816cEF428089498fB82', + '0x6cE07781968c5f4747AcDd46D0975A797a8B1143', + '0x54CF38E6B75859cD7958d3B7bc020a1b89482d7E', + '0xc7d0d0E5bcfe73799EEcc1aD7204e9c52ea014eC', + '0x19630C41EeD3d437348FF8A6ddcB9FAcF550AC41' + ]; + contractMethodWhiteList = [ + '0x0000000000000000000000002f7ac9436ba4b548f9582af91ca1ef02cd2f1f030000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000002cdfc90250ef967036838da601099656e74bcfc50000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x000000000000000000000000b5d4f343412dc8efb6ff599d790074d0f1e8d43000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000c616464457874656e73696f6e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f72656d6f7665457874656e73696f6e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d72656769737465724173736574000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000006b7c026621d53d092fb446c2162d1dfc048bc9d7000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000f14a7d43bedac1c17da9c22cf3d8c900aa8deca9000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000009800c0eb44ccb5423bb95205921fcb5ffa066a62000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000a61e289c29c47a2eea7092355602de8a0dcb16e2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000003803e2a56f657922b76211ab22eafe6c0aa4f95f000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000303e57962d735a8dfc7ca5d30676d48a63af7338000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000005601d189d5751e4f9dde2e598999228b4a5db9e2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000058eeac66d46d90cc1c563cabc2c77d610b91284c000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000d397a9f470212d419acec535783aed8145e58853000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000aed9013944dfd09a16e5c4115ce45c48520383ce000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000b8c221dc3ee9132015ae6816cef428089498fb82000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000006ce07781968c5f4747acdd46d0975a797a8b1143000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000054cf38e6b75859cd7958d3b7bc020a1b89482d7e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000c7d0d0e5bcfe73799eecc1ad7204e9c52ea014ec000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000019630c41eed3d437348ff8a6ddcb9facf550ac41000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000' + ]; + return [fromContractWhiteList,contractMethodWhiteList]; + + case 7 : // heco + fromContractWhiteList = [ + '0x020c15e7d08A8Ec7D35bCf3AC3CCbF0BBf2704e6', + '0xD98Ee7Ca1B33e60C75E3cd9493c566fc857592c8', + '0x2cdfc90250EF967036838DA601099656e74bCfc5', + '0xA38a2038136a57B6B1019a50A91Ab66738905a8A', + '0xfa8440025d7EE21925be5A4adfd4aC35A156e0ed', + '0x8b963E30f67C9a6C3F88306e799Fe2bBC3626f2E', + '0xdf42B52157c10aaD666886dB0AB8Bb99b6485ae6', + '0xAfFb645d73A784Ab53D074488349fF4dC22D3435', + '0x93D3B6713c08F50C576490c7C975E1D315927EF3', + '0x6F5E4F841DAbEac07A9270cdD26421aA869A59Bb', + '0x64840C731022E51b20Dc5aeA6180F1b2299b5De1', + '0x5C3CD4846d07548020eD9F40a08Fd66D16f71fE7', + '0xB6626Eb5BB5918D01593Ad8504E4513f4385b62b', + '0x5902BDbB4FDD0d44e2871577eaA46Fd0b3424B3e', + '0xb4F8FeBb7372F47bEa2B06B6F9D878093a3B014E', + '0x22A3f421115FbF2eda8AbCb56CE63219481C2A6C', + '0x37De929B55B811FEe16a9244a0De6aac008c3F3C', + '0xC5293535d05A98f73f5e2Af9A804363FA39BE5f3' + ]; + contractMethodWhiteList = [ + '0x000000000000000000000000020c15e7d08a8ec7d35bcf3ac3ccbf0bbf2704e60000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000002cdfc90250ef967036838da601099656e74bcfc50000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x000000000000000000000000a38a2038136a57b6b1019a50a91ab66738905a8a000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000fa8440025d7ee21925be5a4adfd4ac35a156e0ed000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000008b963e30f67c9a6c3f88306e799fe2bbc3626f2e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000df42b52157c10aad666886db0ab8bb99b6485ae6000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000affb645d73a784ab53d074488349ff4dc22d3435000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000093d3b6713c08f50c576490c7c975e1d315927ef3000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000006f5e4f841dabeac07a9270cdd26421aa869a59bb000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000064840c731022e51b20dc5aea6180f1b2299b5de1000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000005c3cd4846d07548020ed9f40a08fd66d16f71fe7000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000b6626eb5bb5918d01593ad8504e4513f4385b62b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000005902bdbb4fdd0d44e2871577eaa46fd0b3424b3e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000b4f8febb7372f47bea2b06b6f9d878093a3b014e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000022a3f421115fbf2eda8abcb56ce63219481c2a6c000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000037de929b55b811fee16a9244a0de6aac008c3f3c000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000c5293535d05a98f73f5e2af9a804363fa39be5f3000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000' + ]; + return [fromContractWhiteList,contractMethodWhiteList]; + + case 12 : // ok + fromContractWhiteList = [ + '0x9a3658864Aa2Ccc63FA61eAAD5e4f65fA490cA7D', + '0x6d981C8535af305915c7eC2FceFA126d6286c0F5', + '0xA7FeD91A00fE5847cc4970a1122fA5bCf2700291', + '0x8b0963Ac00776111160f9bAB0E1835719ce5ff6C', + '0x1ee6dCa80F09E7d387DbFA8EB2Dea08e83FaD182', + '0xBe7F5e9eC0b1911251D61Ac64860a315a5185A18', + '0xA08584E87703Da3E454133080362FfBE545dEf11', + '0xf2575b39ADF3fC2d9370862e17efDCC79D935c00', + '0xaca1227d3526D78a7Df361dF3495Aa2A64042808', + '0xdE8B716F43dcD94e4D4afE73D040825b2E990E6D', + '0x35b161F6F1Aa5787045505bd2E8307195485725D', + '0xf195EeC267130FFF260b107a26b94976f59e09e2', + '0x353881c2afda8D07Db6c01f59D91Bef75570d4D2', + '0xA86E17e1B40F251d50Ce64Da1f2F824Ff9520E44', + '0xE5bbC1FaF1dD83251B2949c08dE53Ba86BFf4Fb8', + '0x5CB3Ff30Ae417fddC9301b64C35A211f40f801C2' + ]; + contractMethodWhiteList = [ + '0x0000000000000000000000009a3658864aa2ccc63fa61eaad5e4f65fa490ca7d0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x0000000000000000000000006d981c8535af305915c7ec2fcefa126d6286c0f5000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000a7fed91a00fe5847cc4970a1122fa5bcf2700291000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000008b0963ac00776111160f9bab0e1835719ce5ff6c000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000001ee6dca80f09e7d387dbfa8eb2dea08e83fad182000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000be7f5e9ec0b1911251d61ac64860a315a5185a18000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000a08584e87703da3e454133080362ffbe545def11000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000f2575b39adf3fc2d9370862e17efdcc79d935c00000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000aca1227d3526d78a7df361df3495aa2a64042808000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000de8b716f43dcd94e4d4afe73d040825b2e990e6d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000035b161f6f1aa5787045505bd2e8307195485725d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000f195eec267130fff260b107a26b94976f59e09e2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000353881c2afda8d07db6c01f59d91bef75570d4d2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000a86e17e1b40f251d50ce64da1f2f824ff9520e44000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000e5bbc1faf1dd83251b2949c08de53ba86bff4fb8000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000005cb3ff30ae417fddc9301b64c35a211f40f801c2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000' + ]; + return [fromContractWhiteList,contractMethodWhiteList]; + + case 17 : // polygon + fromContractWhiteList = [ + '0x28ff66a1b95d7cacf8eded2e658f768f44841212', + '0xaC57280B3A657A2e8D1180493C519a476D208F61', + '0xf14a7d43bedaC1C17Da9C22cf3D8c900AA8DEcA9', + '0x9800c0EB44cCb5423bb95205921fCb5FFa066a62', + '0xa61E289C29c47A2EEA7092355602De8A0dCB16e2', + '0x3803e2A56F657922b76211ab22eAFE6C0Aa4F95f', + '0x303E57962D735A8dfC7CA5d30676d48A63AF7338', + '0x5601D189D5751e4f9dde2E598999228B4a5DB9e2', + '0xaca1227d3526D78a7Df361dF3495Aa2A64042808', + '0xdE8B716F43dcD94e4D4afE73D040825b2E990E6D', + '0x35b161F6F1Aa5787045505bd2E8307195485725D', + '0x2d7Fe908524180D17C058e6C5388738C1b30d198', + '0x487Fd5C13f5764b798D4AecaEA79B2e0DF5d3952', + '0x1B49485342C38C83f5376efF64800b52ee35787F', + '0x6e4475B49f5b2d0f06D6B7218C80C2A588252889', + '0x039DB2Fc6377b20A30ac9F05eb6477ce7461cB0b', + '0x32cAf282bdb48147C157285E0eb715fbFa07826a' + ]; + contractMethodWhiteList = [ + '0x00000000000000000000000028ff66a1b95d7cacf8eded2e658f768f448412120000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000', + '0x000000000000000000000000f14a7d43bedac1c17da9c22cf3d8c900aa8deca9000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000009800c0eb44ccb5423bb95205921fcb5ffa066a62000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000a61e289c29c47a2eea7092355602de8a0dcb16e2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000003803e2a56f657922b76211ab22eafe6c0aa4f95f000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000303e57962d735a8dfc7ca5d30676d48a63af7338000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000005601d189d5751e4f9dde2e598999228b4a5db9e2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000aca1227d3526d78a7df361df3495aa2a64042808000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000de8b716f43dcd94e4d4afe73d040825b2e990e6d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000035b161f6f1aa5787045505bd2e8307195485725d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000002d7fe908524180d17c058e6c5388738c1b30d198000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000487fd5c13f5764b798d4aecaea79b2e0df5d3952000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000001b49485342c38c83f5376eff64800b52ee35787f000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x0000000000000000000000006e4475b49f5b2d0f06d6b7218c80c2a588252889000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x000000000000000000000000039db2fc6377b20a30ac9f05eb6477ce7461cb0b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000', + '0x00000000000000000000000032caf282bdb48147c157285e0eb715fbfa07826a000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f6f6e43726f73735472616e736665720000000000000000000000000000000000' + ]; + return [fromContractWhiteList,contractMethodWhiteList]; + + case 19 : // arbitrum + fromContractWhiteList = [ + '0x2f7ac9436ba4B548f9582af91CA1Ef02cd2F1f03', + '0x7E418a9926c8D1cbd09CC93E8051cC3BbdfE3854' + ]; + contractMethodWhiteList = [ + '0x0000000000000000000000002f7ac9436ba4b548f9582af91ca1ef02cd2f1f030000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006756e6c6f636b0000000000000000000000000000000000000000000000000000' + ]; + return [fromContractWhiteList,contractMethodWhiteList]; + + default : + throw new Error("fail to get WhiteListInfo, unknown Network: "+polyId); + } +} + +async function getPolyChainId() { + const chainId = await hre.web3.eth.getChainId(); + switch (chainId) { + + // mainnet + case 1: // eth-main + return 2; + case 56: // bsc-main + return 6; + case 128: // heco-main + return 7; + case 137: // polygon-main + return 17; + case 66: // ok-main + return 12; + case 1718: // plt-main + return 8; + case 42161: // arbitrum-main + return 19; + + // testnet + case 3: // eth-test + return 2; + case 97: // bsc-test + return 79; + case 256: // heco-test + return 7; + case 80001: // polygon-test + return 202; + case 65: // ok-test + return 200; + case 101: // plt-test + return 107; + case 421611: // arbitrum-test + return 205; + + // hardhat devnet + case 31337: + return 77777; + + // unknown chainid + default: + throw new Error("fail to get Poly_Chain_Id, unknown Network_Id: "+chainId); + } +} + +// We recommend this pattern to be able to use async/await everywhere +// and properly handle errors. +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); + diff --git a/scripts/whiteListGen.js b/scripts/whiteListGen.js new file mode 100644 index 0000000..dc3d13e --- /dev/null +++ b/scripts/whiteListGen.js @@ -0,0 +1,322 @@ +const { ethers } = require("hardhat"); +const hre = require("hardhat"); +const fs = require("fs"); +const Web3 = require("web3"); +const colors = require('colors'); +hre.web3 = new Web3(hre.network.provider); + +async function main() { + await printWhiteListInfo("xdai-main"); + // await printWhiteListInfo("bsc-main"); + // await printWhiteListInfo("heco-main"); + // await printWhiteListInfo("ok-main"); + // await printWhiteListInfo("polygon-main"); + // await printWhiteListInfo("arbitrum-main"); +} + +async function printWhiteListInfo(networkName) { + + //let networkName = 'eth-main'; + + let fromContractWhiteList; + let contractMethodWhiteList; + + try { + [fromContractWhiteList,contractMethodWhiteList] = getWhiteListInfo(networkName); + } catch(error) { + throw error; + } + + const Encoder = await hre.ethers.getContractFactory("AbiEncoder"); + let encoder = await Encoder.deploy(); + for (let i=0;i process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); \ No newline at end of file diff --git a/test/EthCrossChainManagerTest.js b/test/EthCrossChainManagerTest.js index 16f9e33..f76c5af 100644 --- a/test/EthCrossChainManagerTest.js +++ b/test/EthCrossChainManagerTest.js @@ -1,19 +1,19 @@ const { expectRevert, expectEvent, constants, BN } = require('@openzeppelin/test-helpers'); const { expect } = require('chai'); -const EthCrossChainManager = artifacts.require('./../../contracts/core/.0/CrossChainManager/logic/EthCrossChainManager'); +const EthCrossChainManager = artifacts.require('./../../contracts/core/.0/CrossChainManager/logic/EthCrossChainManagerForTest'); const EthCrossChainData = artifacts.require('./../../contracts/core/.0/CrossChainManager/data/EthCrossChainData'); const EthCrossChainManagerProxy = artifacts.require('./../../contracts/core/.0/CrossChainManager/upgrade/EthCrossChainManagerProxy'); -const NewEthCrossChainManager = artifacts.require('./../../contracts/core/.0/CrossChainManager/logic/NewEthCrossChainManager'); +const NewEthCrossChainManager = artifacts.require('./../../contracts/core/.0/CrossChainManager/logic/EthCrossChainManagerForTest'); contract('EthCrossChain', (accounts) => { before(async function () { - this.ECCD = await EthCrossChainData.new({ from: accounts[0], value: web3.utils.toWei('0', 'ether'), gas: 10000000, gasPrice: 50 }); + this.ECCD = await EthCrossChainData.new({ from: accounts[0], value: web3.utils.toWei('0', 'ether'), gas: 8000000, gasPrice: 50 }); console.log("this.ECCD.address = ", this.ECCD.address); - this.ECCM = await EthCrossChainManager.new(this.ECCD.address, { from: accounts[0], value: web3.utils.toWei('0', 'ether'), gas: 200000000, gasPrice: 50 }); + this.ECCM = await EthCrossChainManager.new(this.ECCD.address,2, { from: accounts[0], value: web3.utils.toWei('0', 'ether'), gas: 8000000, gasPrice: 50 }); console.log("this.ECCM.address........... = ", this.ECCM.address); - this.ECCMP = await EthCrossChainManagerProxy.new(this.ECCM.address, { from: accounts[0], value: web3.utils.toWei('0', 'ether'), gas: 60000000, gasPrice: 50 }); + this.ECCMP = await EthCrossChainManagerProxy.new(this.ECCM.address, { from: accounts[0], value: web3.utils.toWei('0', 'ether'), gas: 8000000, gasPrice: 50 }); console.log("this.ECCMP.address........... = ", this.ECCMP.address); - this.ECCM1 = await NewEthCrossChainManager.new(this.ECCD.address, { from: accounts[0], value: web3.utils.toWei('0', 'ether'), gas: 200000000, gasPrice: 50 }); + this.ECCM1 = await NewEthCrossChainManager.new(this.ECCD.address,2, { from: accounts[0], value: web3.utils.toWei('0', 'ether'), gas: 8000000, gasPrice: 50 }); console.log("this.ECCM1.address........... = ", this.ECCM1.address); }); @@ -70,7 +70,7 @@ contract('EthCrossChain', (accounts) => { }); let storedCEPKB = await this.ECCD.getCurEpochConPubKeyBytes(); - console.log('stored Consensu Peers public key book keeper is: ', storedCEPKB); + // console.log('stored Consensu Peers public key book keeper is: ', storedCEPKB); let curEpochStartHeight = await this.ECCD.getCurEpochStartHeight(); expect(curEpochStartHeight).to.be.bignumber.equal(expectedCurEpochStartHeight); @@ -98,8 +98,8 @@ contract('EthCrossChain', (accounts) => { crossChainTxHash:'0x00ca93f8738111a063d8ab7221f47c70a4cade0ca4a2829df494cd4b5e231bd6', fromChainTxHash:'0x4caa77a3d2ddfaa318c550f1f38dd09d610dcff827d1f2ccd4ddcafaa6c553cc', }); - console.log("receipt is ", receipt); - console.log("verifyHeaderAndExecuteTx gas:", receipt.gasUsed); + // console.log("receipt is ", receipt); + // console.log("verifyHeaderAndExecuteTx gas:", receipt.gasUsed); }); @@ -119,8 +119,8 @@ contract('EthCrossChain', (accounts) => { height: rawHeaderHeight, rawHeader: rawHeader, }); - console.log("receipt is ", receipt); - console.log("changeBookKeeper gas:", receipt.gasUsed); + // console.log("receipt is ", receipt); + // console.log("changeBookKeeper gas:", receipt.gasUsed); }); it('changeBookKeeper throws error on sync same block height header twice', async function () { @@ -242,15 +242,6 @@ contract('EthCrossChain', (accounts) => { await expectRevert(this.ECCM1.verifyHeaderAndExecuteTx(proofy, blockHeadery1, headerProofy, curRawHeader, signaturesy1), "the transaction has been executed!"); }); }); - describe('Here, we try to use new method in the new EthCrossChainManager contract,', async function () { - const a = new web3.utils.BN('123456789'); - const b = new web3.utils.BN('987654321'); - const expectResult = a.add(b); - it('in new EthCrossChainManager contract, should addFunctionTest1 correctly', async function () { - const res = await this.ECCM1.addFunctionTest1.call(a, b); - assert.equal(expectResult.toNumber(), res.toNumber()); - }); - }); describe('verifyHeaderAndExecuteTx for current epoch tx after upgrade contract', function () { const proofz = '0xd7206de23520db9f6978f8d1b0ba7369edcbea4ea62396605363ea7cb721f31885930300000000000000204a96009aa5364a71f39f3a9984215da1dac4bf4fd5c459af542f028685d85031081e0400000000000014b7041bc96b15da728fdfc1c47cbfc687b845adeb0200000000000000146aba9e15019537ac636932a4224ad99099116af006756e6c6f636b4a14283d389667f28d5fc7e3049a2bd7a40a2ae08f1514344cfc3b8635f72f14200aaf2168d9f75df86fd30f0000000000000000000000000000000000000000000000000000000000000000b6baca2408e3d037f744210446279438b7d7cef89cc1ab738f18e0ff007c7fb80063f78a02a450496c46279b75a2943fe31b8d2b81b61b030ab33c6bc079e473f900a6998c80cfc576a19fbc313501003bfc0d014db3511ae7e6ee27f446fcaed9d600e20a98f755c55e7f0c29fae8cb81539a2158e1ba15a1e3523439f639eda613a7'; const blockHeaderz1 = '0x000000009b91561700000000a38ff31f1a18ccd3f0da6293f2995d841fb54fffb6e5c5b2c4a90e0958e07f241fb0cc7b597ddb67f70b457e7ae8b827c692f594bfe130f5c3e3a04914a76127fc2e9b603bb187f6f0006312db8d248c1225c76a0672b9caee589408238e217ee3a10983975e8ddedd7336fc6c4fdee4972213d7d670f85bbd0898e6cf29260c25c01a5faa8f0000c9c576cb2c4a58c4fd10017b226c6561646572223a372c227672665f76616c7565223a224249766435556654576d6761335868594a54487a66425178503164767972316a6e41324f636d736b2b2f32706f4c6d6758445530316b4c61324d3553646366746c482f6657674652613431726c754f7879337462386c383d222c227672665f70726f6f66223a22366e63657331786952666c4757775841586642773348426e4263767477584977684a4669564b664335753030463844413233683858796248367856596f63334a76676955765a32465869572b3162774b554935656d513d3d222c226c6173745f636f6e6669675f626c6f636b5f6e756d223a33363433322c226e65775f636861696e5f636f6e666967223a6e756c6c7d0000000000000000000000000000000000000000'