From e0756f871cf2764b593825eee38e5bad18af61e8 Mon Sep 17 00:00:00 2001 From: echo Date: Fri, 2 Feb 2024 16:29:30 +0800 Subject: [PATCH] renaming and redeploy on testnet --- README.md | 2 +- bin/dao.sh | 4 ++-- bin/deploy.sh | 6 +++--- bin/fee.sh | 12 +++++------ bin/verify.sh | 8 ++++---- script/deploy/Deploy.s.sol | 22 ++++++++++----------- script/fee/Fee.s.sol | 2 +- script/input/c3.json | 6 +++--- script/output/11155111/ORMPOracle.v.json | 1 + script/output/11155111/deploy.a-latest.json | 2 +- script/output/421614/ORMPOracle.v.json | 1 + script/output/421614/deploy.a-latest.json | 2 +- script/output/43/deploy.a-latest.json | 2 +- script/output/44/ORMPOracle.v.json | 1 + script/output/44/deploy.a-latest.json | 2 +- src/eco/{OracleV2.sol => ORMPOracle.sol} | 7 ++++++- 16 files changed, 44 insertions(+), 36 deletions(-) create mode 100644 script/output/11155111/ORMPOracle.v.json create mode 100644 script/output/421614/ORMPOracle.v.json create mode 100644 script/output/44/ORMPOracle.v.json rename src/eco/{OracleV2.sol => ORMPOracle.sol} (89%) diff --git a/README.md b/README.md index c58de4b..7436104 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Oracle and Relayer based Message Protocol. |------------|--------------------------------------------| | ORMP | 0x00000000001523057a05d6293C1e5171eE33eE0A | | Oracle | 0x00000000046bc530804d66B6b64f7aF69B4E4E81 | -| OracleV2 | 0x0000000004A34ac73374b65a55C93CF9D4Bc3d17 | +| ORMPOracle | 0x000000000DA67291724858F7e759A43B2d23225e | | Relayer | 0x0000000000808fE9bDCc1d180EfbF5C53552a6b1 | | MsgDAO | 0x000000000879926D12aF396788C0785B7e581e53 | diff --git a/bin/dao.sh b/bin/dao.sh index 3535ae2..e8174dc 100755 --- a/bin/dao.sh +++ b/bin/dao.sh @@ -8,7 +8,7 @@ deployer=$(jq -r ".DEPLOYER" $c3) dao=$(jq -r ".MSGDAO" $c3) subapi_multisig=$(jq -r ".SUBAPIMULTISIG" $c3) ormp=$(jq -r ".ORMP_ADDR" $c3) -oracle=$(jq -r ".ORACLEV2_ADDR" $c3) +oracle=$(jq -r ".ORMPORACLE_ADDR" $c3) relayer=$(jq -r ".RELAYER_ADDR" $c3) set -x @@ -26,6 +26,6 @@ set -x # seth send -F $deployer $relayer "changeOwner(address)" $dao --chain ethereum seth send -F $deployer $oracle "changeOwner(address)" $subapi_multisig --chain pangolin -seth send -F $deployer $oracle "changeOwner(address)" $subapi_multisig --chain crab +# seth send -F $deployer $oracle "changeOwner(address)" $subapi_multisig --chain crab seth send -F $deployer $oracle "changeOwner(address)" $subapi_multisig --chain sepolia seth send -F $deployer $oracle "changeOwner(address)" $subapi_multisig --chain arbitrum-sepolia diff --git a/bin/deploy.sh b/bin/deploy.sh index efc5a9e..d05f706 100755 --- a/bin/deploy.sh +++ b/bin/deploy.sh @@ -7,6 +7,6 @@ set -eo pipefail # forge script script/deploy/Deploy.s.sol:Deploy --chain-id 42161 --broadcast --verify --slow --legacy forge script script/deploy/Deploy.s.sol:Deploy --chain-id 43 --broadcast --verify --skip-simulation --slow -# forge script script/deploy/Deploy.s.sol:Deploy --chain-id 44 --broadcast --verify --skip-simulation --slow -# forge script script/deploy/Deploy.s.sol:Deploy --chain-id 421614 --broadcast --verify --skip-simulation --slow -# forge script script/deploy/Deploy.s.sol:Deploy --chain-id 11155111 --broadcast --verify --skip-simulation --slow +forge script script/deploy/Deploy.s.sol:Deploy --chain-id 44 --broadcast --verify --skip-simulation --slow +forge script script/deploy/Deploy.s.sol:Deploy --chain-id 421614 --broadcast --verify --skip-simulation --slow +forge script script/deploy/Deploy.s.sol:Deploy --chain-id 11155111 --broadcast --verify --skip-simulation --slow diff --git a/bin/fee.sh b/bin/fee.sh index 02d12fa..c292d25 100755 --- a/bin/fee.sh +++ b/bin/fee.sh @@ -14,12 +14,12 @@ set -x # forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 11155111 --chain-id 44 --broadcast --slow # forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 421614 --chain-id 44 --broadcast --slow -# forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 421614 --chain-id 11155111 --broadcast --slow # forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 44 --chain-id 11155111 --broadcast --slow # forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 44 --chain-id 421614 --broadcast --skip-simulation --legacy --slow -# forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 11155111 --chain-id 421614 --broadcast --skip-simulation --legacy --slow -# forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 11155111 --chain-id 43 --broadcast -# forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 421614 --chain-id 43 --broadcast -# forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 43 --chain-id 11155111 --broadcast --slow -# forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 43 --chain-id 421614 --broadcast --skip-simulation --legacy --slow +forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 11155111 --chain-id 43 --broadcast +forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 421614 --chain-id 43 --broadcast +forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 43 --chain-id 11155111 --broadcast --slow +forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 421614 --chain-id 11155111 --broadcast --slow +forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 43 --chain-id 421614 --broadcast --skip-simulation --legacy --slow +forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 11155111 --chain-id 421614 --broadcast --skip-simulation --legacy --slow diff --git a/bin/verify.sh b/bin/verify.sh index 1b505af..0e59e60 100755 --- a/bin/verify.sh +++ b/bin/verify.sh @@ -6,7 +6,7 @@ c3=$PWD/script/input/c3.json deployer=$(jq -r ".DEPLOYER" $c3) ormp=$(jq -r ".ORMP_ADDR" $c3) -oracle=$(jq -r ".ORACLEV2_ADDR" $c3) +oracle=$(jq -r ".ORMPORACLE_ADDR" $c3) relayer=$(jq -r ".RELAYER_ADDR" $c3) verify() { @@ -31,9 +31,9 @@ verify() { # verify $oracle 46 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/OracleV2.sol:OracleV2 # verify $oracle 42161 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/OracleV2.sol:OracleV2 -verify $oracle 44 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/OracleV2.sol:OracleV2 -verify $oracle 421614 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/OracleV2.sol:OracleV2 -verify $oracle 11155111 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/OracleV2.sol:OracleV2 +verify $oracle 44 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/ORMPOracle.sol:ORMPOracle +verify $oracle 421614 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/ORMPOracle.sol:ORMPOracle +verify $oracle 11155111 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/ORMPOracle.sol:ORMPOracle # verify $ormp 42161 $(cast abi-encode "constructor(address)" $deployer) src/ORMP.sol:ORMP # verify $ormp 46 $(cast abi-encode "constructor(address)" $deployer) src/ORMP.sol:ORMP diff --git a/script/deploy/Deploy.s.sol b/script/deploy/Deploy.s.sol index 6eebf28..928d121 100644 --- a/script/deploy/Deploy.s.sol +++ b/script/deploy/Deploy.s.sol @@ -9,7 +9,7 @@ import {ScriptTools} from "create3-deploy/script/ScriptTools.sol"; import {ORMP} from "../../src/ORMP.sol"; import {Relayer} from "../../src/eco/Relayer.sol"; -import {OracleV2} from "../../src/eco/OracleV2.sol"; +import {ORMPOracle} from "../../src/eco/ORMPOracle.sol"; interface III { function PROTOCOL() external view returns (address); @@ -61,8 +61,8 @@ contract Deploy is Common { ORMP_ADDR = c3.readAddress(".ORMP_ADDR"); ORMP_SALT = c3.readBytes32(".ORMP_SALT"); - ORACLE_ADDR = c3.readAddress(".ORACLEV2_ADDR"); - ORACLE_SALT = c3.readBytes32(".ORACLEV2_SALT"); + ORACLE_ADDR = c3.readAddress(".ORMPORACLE_ADDR"); + ORACLE_SALT = c3.readBytes32(".ORMPORACLE_SALT"); RELAYER_ADDR = c3.readAddress(".RELAYER_ADDR"); RELAYER_SALT = c3.readBytes32(".RELAYER_SALT"); @@ -77,7 +77,7 @@ contract Deploy is Common { require(deployer == msg.sender, "!deployer"); // deployProtocol(); - // deployOralce(); + deployOralce(); // deployRelayer(); setConfig(); @@ -101,7 +101,7 @@ contract Deploy is Common { /// @notice Deploy the Oracle function deployOralce() public broadcast returns (address) { - bytes memory byteCode = type(OracleV2).creationCode; + bytes memory byteCode = type(ORMPOracle).creationCode; bytes memory initCode = bytes.concat(byteCode, abi.encode(deployer, ORMP_ADDR)); address oracle = _deploy3(ORACLE_SALT, initCode); require(oracle == ORACLE_ADDR, "!oracle"); @@ -127,13 +127,13 @@ contract Deploy is Common { /// @notice Set the protocol config function setConfig() public broadcast { - // ORMP(ORMP_ADDR).setDefaultConfig(ORACLE_ADDR, RELAYER_ADDR); - // (address o, address r) = ORMP(ORMP_ADDR).defaultUC(); - // require(o == ORACLE_ADDR, "!oracle"); - // require(r == RELAYER_ADDR, "!relayer"); + ORMP(ORMP_ADDR).setDefaultConfig(ORACLE_ADDR, RELAYER_ADDR); + (address o, address r) = ORMP(ORMP_ADDR).defaultUC(); + require(o == ORACLE_ADDR, "!oracle"); + require(r == RELAYER_ADDR, "!relayer"); - // III(ORACLE_ADDR).setApproved(oracleOperator, true); - // require(III(ORACLE_ADDR).isApproved(oracleOperator), "!o-operator"); + III(ORACLE_ADDR).setApproved(oracleOperator, true); + require(III(ORACLE_ADDR).isApproved(oracleOperator), "!o-operator"); // III(RELAYER_ADDR).setApproved(relayerOperator, true); // require(III(RELAYER_ADDR).isApproved(relayerOperator), "!r-operator"); diff --git a/script/fee/Fee.s.sol b/script/fee/Fee.s.sol index 1beabf3..2022068 100644 --- a/script/fee/Fee.s.sol +++ b/script/fee/Fee.s.sol @@ -43,7 +43,7 @@ contract Fee is Common { function run(uint256 chainId) public { require(dao == msg.sender, "!dao"); setOracleFee(chainId); - setRelayerFee(chainId); + // setRelayerFee(chainId); } function setOracleFee(uint256 chainId) public broadcast { diff --git a/script/input/c3.json b/script/input/c3.json index d3114d4..8967e4c 100644 --- a/script/input/c3.json +++ b/script/input/c3.json @@ -1,11 +1,11 @@ { "DEPLOYER": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec", "MSGDAO": "0x000000000879926D12aF396788C0785B7e581e53", - "SUBAPIMULTISIG": "0x0000000004127035e3559B9E3376e9DF07822B1E", + "SUBAPIMULTISIG": "0x000000000d60704384100A29efb6C9cf8cD72820", "ORMP_ADDR": "0x00000000001523057a05d6293C1e5171eE33eE0A", "ORMP_SALT": "0x4d629bbdb40d29206f12a51aa81faf14553b218f96845742a89e02e55ecfcef6", - "ORACLEV2_ADDR": "0x0000000004A34ac73374b65a55C93CF9D4Bc3d17", - "ORACLEV2_SALT": "0xdd9400fe0ca3f3183153937a7a1209e1b21fbf038eb74b835dd874301323965e", + "ORMPORACLE_ADDR": "0x000000000DA67291724858F7e759A43B2d23225e", + "ORMPORACLE_SALT": "0xb5616c300c82b5cd3f79afab022c8969a8bcdb7a02fa8c685437c22388e7ea29", "RELAYER_ADDR": "0x0000000000808fE9bDCc1d180EfbF5C53552a6b1", "RELAYER_SALT": "0x9d38bcb32422a45bc9c08605d4457bcd3dadddfee1573a352ace5f1defa45621" } diff --git a/script/output/11155111/ORMPOracle.v.json b/script/output/11155111/ORMPOracle.v.json new file mode 100644 index 0000000..63f586f --- /dev/null +++ b/script/output/11155111/ORMPOracle.v.json @@ -0,0 +1 @@ +{"language":"Solidity","sources":{"src/eco/ORMPOracle.sol":{"content":"// This file is part of Darwinia.\n// Copyright (C) 2018-2023 Darwinia Network\n// SPDX-License-Identifier: GPL-3.0\n//\n// Darwinia is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Darwinia is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Darwinia. If not, see .\n\npragma solidity 0.8.17;\n\nimport \"../Verifier.sol\";\n\ncontract ORMPOracle is Verifier {\n event Assigned(bytes32 indexed msgHash, uint256 fee);\n event SetFee(uint256 indexed chainId, uint256 fee);\n event SetApproved(address operator, bool approve);\n event Withdrawal(address indexed to, uint256 amt);\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n event ImportedMessageRoot(uint256 indexed chainId, uint256 indexed messageIndex, bytes32 messageRoot);\n\n address public immutable PROTOCOL;\n\n address public owner;\n // chainId => price\n mapping(uint256 => uint256) public feeOf;\n // chainId => messageIndex => messageRoot\n mapping(uint256 => mapping(uint256 => bytes32)) rootOf;\n // operator => isApproved\n mapping(address => bool) public approvedOf;\n\n modifier onlyOwner() {\n require(msg.sender == owner, \"!owner\");\n _;\n }\n\n modifier onlyApproved() {\n require(isApproved(msg.sender), \"!approve\");\n _;\n }\n\n constructor(address dao, address ormp) {\n PROTOCOL = ormp;\n owner = dao;\n }\n\n receive() external payable {}\n\n /// @dev Only could be called by owner.\n /// @notice Each channel has a corresponding oracle, and the message root should match with it.\n /// @param chainId The source chain id.\n /// @param messageIndex The source chain message index corresponds to the respective channel.\n /// @param messageRoot The source chain message root corresponding to the channel.\n function importMessageRoot(uint256 chainId, uint256 messageIndex, bytes32 messageRoot) external onlyOwner {\n rootOf[chainId][messageIndex] = messageRoot;\n emit ImportedMessageRoot(chainId, messageIndex, messageRoot);\n }\n\n function changeOwner(address newOwner) external onlyOwner {\n address oldOwner = owner;\n owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n\n function setApproved(address operator, bool approve) external onlyOwner {\n approvedOf[operator] = approve;\n emit SetApproved(operator, approve);\n }\n\n function isApproved(address operator) public view returns (bool) {\n return approvedOf[operator];\n }\n\n function withdraw(address to, uint256 amount) external onlyApproved {\n (bool success,) = to.call{value: amount}(\"\");\n require(success, \"!withdraw\");\n emit Withdrawal(to, amount);\n }\n\n function setFee(uint256 chainId, uint256 fee_) external onlyApproved {\n feeOf[chainId] = fee_;\n emit SetFee(chainId, fee_);\n }\n\n function fee(uint256 toChainId, address /*ua*/ ) public view returns (uint256) {\n uint256 f = feeOf[toChainId];\n require(f != 0, \"!fee\");\n return f;\n }\n\n function assign(bytes32 msgHash) external payable {\n require(msg.sender == PROTOCOL, \"!auth\");\n emit Assigned(msgHash, msg.value);\n }\n\n function merkleRoot(uint256 chainId, uint256 messageIndex) public view override returns (bytes32) {\n return rootOf[chainId][messageIndex];\n }\n}\n"},"src/Verifier.sol":{"content":"// This file is part of Darwinia.\n// Copyright (C) 2018-2023 Darwinia Network\n// SPDX-License-Identifier: GPL-3.0\n//\n// Darwinia is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Darwinia is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Darwinia. If not, see .\n\npragma solidity 0.8.17;\n\nimport \"./interfaces/IVerifier.sol\";\nimport \"./imt/IncrementalMerkleTree.sol\";\n\nabstract contract Verifier is IVerifier {\n /// @notice Message proof.\n /// @param messageIndex Leaf index of the message hash in incremental merkle tree.\n /// @param messageProof Merkle proof of the message hash.\n struct Proof {\n uint256 messageIndex;\n bytes32[32] messageProof;\n }\n\n /// @inheritdoc IVerifier\n function merkleRoot(uint256 chainId, uint256 messageIndex) public view virtual returns (bytes32);\n\n /// @inheritdoc IVerifier\n function verifyMessageProof(uint256 fromChainId, bytes32 msgHash, bytes calldata proof)\n external\n view\n returns (bool)\n {\n // decode proof\n Proof memory p = abi.decode(proof, (Proof));\n\n // fetch message root in block number from chain\n bytes32 imtRootOracle = merkleRoot(fromChainId, p.messageIndex);\n // calculate the expected root based on the proof\n bytes32 imtRootProof = IncrementalMerkleTree.branchRoot(msgHash, p.messageProof, p.messageIndex);\n\n // check oracle's merkle root equal relayer's merkle root\n return imtRootOracle == imtRootProof;\n }\n}\n"},"src/interfaces/IVerifier.sol":{"content":"// This file is part of Darwinia.\n// Copyright (C) 2018-2023 Darwinia Network\n// SPDX-License-Identifier: GPL-3.0\n//\n// Darwinia is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Darwinia is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Darwinia. If not, see .\n\npragma solidity 0.8.17;\n\ninterface IVerifier {\n /// @notice Fetch message root oracle.\n /// @param chainId The destination chain id.\n /// @param messageIndex Leaf index of the message hash in incremental merkle tree.\n /// @return Message root in destination chain.\n function merkleRoot(uint256 chainId, uint256 messageIndex) external view returns (bytes32);\n\n /// @notice Verify message proof\n /// @dev Message proof provided by relayer. Oracle should provide message root of\n /// source chain, and verify the merkle proof of the message hash.\n /// @param fromChainId Source chain id.\n /// @param msgHash Hash of the message.\n /// @param proof Merkle proof of the message\n /// @return Result of the message verify.\n function verifyMessageProof(uint256 fromChainId, bytes32 msgHash, bytes calldata proof)\n external\n view\n returns (bool);\n}\n"},"src/imt/IncrementalMerkleTree.sol":{"content":"// SPDX-License-Identifier: MIT OR Apache-2.0\npragma solidity 0.8.17;\n\n// Inspired: https://github.com/nomad-xyz/monorepo/blob/main/packages/contracts-core/contracts/libs/Merkle.sol\n\n/// @title IncrementalMerkleTree\n/// @author Illusory Systems Inc.\n/// @notice An incremental merkle tree modeled on the eth2 deposit contract.\nlibrary IncrementalMerkleTree {\n uint256 private constant TREE_DEPTH = 32;\n uint256 private constant MAX_LEAVES = 2 ** TREE_DEPTH - 1;\n\n /// @notice Struct representing incremental merkle tree. Contains current\n /// branch and the number of inserted leaves in the tree.\n struct Tree {\n bytes32[TREE_DEPTH] branch;\n uint256 count;\n }\n\n /// @notice Inserts `_node` into merkle tree\n /// @dev Reverts if tree is full\n /// @param _node Element to insert into tree\n function insert(Tree storage _tree, bytes32 _node) internal {\n require(_tree.count < MAX_LEAVES, \"merkle tree full\");\n\n _tree.count += 1;\n uint256 size = _tree.count;\n for (uint256 i = 0; i < TREE_DEPTH; i++) {\n if ((size & 1) == 1) {\n _tree.branch[i] = _node;\n return;\n }\n _node = keccak256(abi.encodePacked(_tree.branch[i], _node));\n size /= 2;\n }\n // As the loop should always end prematurely with the `return` statement,\n // this code should be unreachable. We assert `false` just to be safe.\n assert(false);\n }\n\n /// @notice Calculates and returns`_tree`'s current root given array of zero\n /// hashes\n /// @param _zeroes Array of zero hashes\n /// @return _current Calculated root of `_tree`\n function rootWithCtx(Tree storage _tree, bytes32[TREE_DEPTH] memory _zeroes)\n internal\n view\n returns (bytes32 _current)\n {\n uint256 _index = _tree.count;\n\n for (uint256 i = 0; i < TREE_DEPTH; i++) {\n uint256 _ithBit = (_index >> i) & 0x01;\n bytes32 _next = _tree.branch[i];\n if (_ithBit == 1) {\n _current = keccak256(abi.encodePacked(_next, _current));\n } else {\n _current = keccak256(abi.encodePacked(_current, _zeroes[i]));\n }\n }\n }\n\n /// @notice Calculates and returns`_tree`'s current root\n function root(Tree storage _tree) internal view returns (bytes32) {\n return rootWithCtx(_tree, zeroHashes());\n }\n\n /// @notice Returns array of TREE_DEPTH zero hashes\n /// @return _zeroes Array of TREE_DEPTH zero hashes\n function zeroHashes() internal pure returns (bytes32[TREE_DEPTH] memory _zeroes) {\n _zeroes[0] = Z_0;\n _zeroes[1] = Z_1;\n _zeroes[2] = Z_2;\n _zeroes[3] = Z_3;\n _zeroes[4] = Z_4;\n _zeroes[5] = Z_5;\n _zeroes[6] = Z_6;\n _zeroes[7] = Z_7;\n _zeroes[8] = Z_8;\n _zeroes[9] = Z_9;\n _zeroes[10] = Z_10;\n _zeroes[11] = Z_11;\n _zeroes[12] = Z_12;\n _zeroes[13] = Z_13;\n _zeroes[14] = Z_14;\n _zeroes[15] = Z_15;\n _zeroes[16] = Z_16;\n _zeroes[17] = Z_17;\n _zeroes[18] = Z_18;\n _zeroes[19] = Z_19;\n _zeroes[20] = Z_20;\n _zeroes[21] = Z_21;\n _zeroes[22] = Z_22;\n _zeroes[23] = Z_23;\n _zeroes[24] = Z_24;\n _zeroes[25] = Z_25;\n _zeroes[26] = Z_26;\n _zeroes[27] = Z_27;\n _zeroes[28] = Z_28;\n _zeroes[29] = Z_29;\n _zeroes[30] = Z_30;\n _zeroes[31] = Z_31;\n }\n\n /// @notice Calculates and returns the merkle root for the given leaf\n /// `_item`, a merkle branch, and the index of `_item` in the tree.\n /// @param _item Merkle leaf\n /// @param _branch Merkle proof\n /// @param _index Index of `_item` in tree\n /// @return _current Calculated merkle root\n function branchRoot(bytes32 _item, bytes32[TREE_DEPTH] memory _branch, uint256 _index)\n internal\n pure\n returns (bytes32 _current)\n {\n _current = _item;\n\n for (uint256 i = 0; i < TREE_DEPTH; i++) {\n uint256 _ithBit = (_index >> i) & 0x01;\n bytes32 _next = _branch[i];\n if (_ithBit == 1) {\n _current = keccak256(abi.encodePacked(_next, _current));\n } else {\n _current = keccak256(abi.encodePacked(_current, _next));\n }\n }\n }\n\n function prove(Tree storage _tree) internal view returns (bytes32[TREE_DEPTH] memory proof) {\n uint256 _index = _tree.count - 1;\n bytes32[TREE_DEPTH] memory left = _tree.branch;\n bytes32[TREE_DEPTH] memory right = zeroHashes();\n for (uint256 i = 0; i < TREE_DEPTH; i++) {\n uint256 _ith_bit = (_index >> i) & 0x01;\n if (_ith_bit == 1) {\n proof[i] = left[i];\n } else {\n proof[i] = right[i];\n }\n }\n }\n\n // keccak256 zero hashes\n bytes32 private constant Z_0 = hex\"0000000000000000000000000000000000000000000000000000000000000000\";\n bytes32 private constant Z_1 = hex\"ad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5\";\n bytes32 private constant Z_2 = hex\"b4c11951957c6f8f642c4af61cd6b24640fec6dc7fc607ee8206a99e92410d30\";\n bytes32 private constant Z_3 = hex\"21ddb9a356815c3fac1026b6dec5df3124afbadb485c9ba5a3e3398a04b7ba85\";\n bytes32 private constant Z_4 = hex\"e58769b32a1beaf1ea27375a44095a0d1fb664ce2dd358e7fcbfb78c26a19344\";\n bytes32 private constant Z_5 = hex\"0eb01ebfc9ed27500cd4dfc979272d1f0913cc9f66540d7e8005811109e1cf2d\";\n bytes32 private constant Z_6 = hex\"887c22bd8750d34016ac3c66b5ff102dacdd73f6b014e710b51e8022af9a1968\";\n bytes32 private constant Z_7 = hex\"ffd70157e48063fc33c97a050f7f640233bf646cc98d9524c6b92bcf3ab56f83\";\n bytes32 private constant Z_8 = hex\"9867cc5f7f196b93bae1e27e6320742445d290f2263827498b54fec539f756af\";\n bytes32 private constant Z_9 = hex\"cefad4e508c098b9a7e1d8feb19955fb02ba9675585078710969d3440f5054e0\";\n bytes32 private constant Z_10 = hex\"f9dc3e7fe016e050eff260334f18a5d4fe391d82092319f5964f2e2eb7c1c3a5\";\n bytes32 private constant Z_11 = hex\"f8b13a49e282f609c317a833fb8d976d11517c571d1221a265d25af778ecf892\";\n bytes32 private constant Z_12 = hex\"3490c6ceeb450aecdc82e28293031d10c7d73bf85e57bf041a97360aa2c5d99c\";\n bytes32 private constant Z_13 = hex\"c1df82d9c4b87413eae2ef048f94b4d3554cea73d92b0f7af96e0271c691e2bb\";\n bytes32 private constant Z_14 = hex\"5c67add7c6caf302256adedf7ab114da0acfe870d449a3a489f781d659e8becc\";\n bytes32 private constant Z_15 = hex\"da7bce9f4e8618b6bd2f4132ce798cdc7a60e7e1460a7299e3c6342a579626d2\";\n bytes32 private constant Z_16 = hex\"2733e50f526ec2fa19a22b31e8ed50f23cd1fdf94c9154ed3a7609a2f1ff981f\";\n bytes32 private constant Z_17 = hex\"e1d3b5c807b281e4683cc6d6315cf95b9ade8641defcb32372f1c126e398ef7a\";\n bytes32 private constant Z_18 = hex\"5a2dce0a8a7f68bb74560f8f71837c2c2ebbcbf7fffb42ae1896f13f7c7479a0\";\n bytes32 private constant Z_19 = hex\"b46a28b6f55540f89444f63de0378e3d121be09e06cc9ded1c20e65876d36aa0\";\n bytes32 private constant Z_20 = hex\"c65e9645644786b620e2dd2ad648ddfcbf4a7e5b1a3a4ecfe7f64667a3f0b7e2\";\n bytes32 private constant Z_21 = hex\"f4418588ed35a2458cffeb39b93d26f18d2ab13bdce6aee58e7b99359ec2dfd9\";\n bytes32 private constant Z_22 = hex\"5a9c16dc00d6ef18b7933a6f8dc65ccb55667138776f7dea101070dc8796e377\";\n bytes32 private constant Z_23 = hex\"4df84f40ae0c8229d0d6069e5c8f39a7c299677a09d367fc7b05e3bc380ee652\";\n bytes32 private constant Z_24 = hex\"cdc72595f74c7b1043d0e1ffbab734648c838dfb0527d971b602bc216c9619ef\";\n bytes32 private constant Z_25 = hex\"0abf5ac974a1ed57f4050aa510dd9c74f508277b39d7973bb2dfccc5eeb0618d\";\n bytes32 private constant Z_26 = hex\"b8cd74046ff337f0a7bf2c8e03e10f642c1886798d71806ab1e888d9e5ee87d0\";\n bytes32 private constant Z_27 = hex\"838c5655cb21c6cb83313b5a631175dff4963772cce9108188b34ac87c81c41e\";\n bytes32 private constant Z_28 = hex\"662ee4dd2dd7b2bc707961b1e646c4047669dcb6584f0d8d770daf5d7e7deb2e\";\n bytes32 private constant Z_29 = hex\"388ab20e2573d171a88108e79d820e98f26c0b84aa8b2f4aa4968dbb818ea322\";\n bytes32 private constant Z_30 = hex\"93237c50ba75ee485f4c22adf2f741400bdf8d6a9cc7df7ecae576221665d735\";\n bytes32 private constant Z_31 = hex\"8448818bb4ae4562849e949e17ac16e0be16688e156b5cf15e098c627c0056a9\";\n}\n"}},"settings":{"remappings":["forge-std/=lib/forge-std/src/","ds-test/=lib/forge-std/lib/ds-test/src/","create3-deploy/=lib/create3-deploy/"],"optimizer":{"enabled":true,"runs":999999},"metadata":{"useLiteralContent":false,"bytecodeHash":"ipfs"},"outputSelection":{"*":{"":["ast"],"*":["abi","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers","metadata","storageLayout","devdoc","userdoc"]}},"evmVersion":"london","libraries":{}}} diff --git a/script/output/11155111/deploy.a-latest.json b/script/output/11155111/deploy.a-latest.json index 7e30eed..44747a5 100644 --- a/script/output/11155111/deploy.a-latest.json +++ b/script/output/11155111/deploy.a-latest.json @@ -1,6 +1,6 @@ { "DAO": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec", - "ORACLE": "0x0000000004A34ac73374b65a55C93CF9D4Bc3d17", + "ORACLE": "0x000000000DA67291724858F7e759A43B2d23225e", "ORMP": "0x00000000001523057a05d6293C1e5171eE33eE0A", "RELAYER": "0x0000000000808fE9bDCc1d180EfbF5C53552a6b1" } \ No newline at end of file diff --git a/script/output/421614/ORMPOracle.v.json b/script/output/421614/ORMPOracle.v.json new file mode 100644 index 0000000..63f586f --- /dev/null +++ b/script/output/421614/ORMPOracle.v.json @@ -0,0 +1 @@ +{"language":"Solidity","sources":{"src/eco/ORMPOracle.sol":{"content":"// This file is part of Darwinia.\n// Copyright (C) 2018-2023 Darwinia Network\n// SPDX-License-Identifier: GPL-3.0\n//\n// Darwinia is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Darwinia is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Darwinia. If not, see .\n\npragma solidity 0.8.17;\n\nimport \"../Verifier.sol\";\n\ncontract ORMPOracle is Verifier {\n event Assigned(bytes32 indexed msgHash, uint256 fee);\n event SetFee(uint256 indexed chainId, uint256 fee);\n event SetApproved(address operator, bool approve);\n event Withdrawal(address indexed to, uint256 amt);\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n event ImportedMessageRoot(uint256 indexed chainId, uint256 indexed messageIndex, bytes32 messageRoot);\n\n address public immutable PROTOCOL;\n\n address public owner;\n // chainId => price\n mapping(uint256 => uint256) public feeOf;\n // chainId => messageIndex => messageRoot\n mapping(uint256 => mapping(uint256 => bytes32)) rootOf;\n // operator => isApproved\n mapping(address => bool) public approvedOf;\n\n modifier onlyOwner() {\n require(msg.sender == owner, \"!owner\");\n _;\n }\n\n modifier onlyApproved() {\n require(isApproved(msg.sender), \"!approve\");\n _;\n }\n\n constructor(address dao, address ormp) {\n PROTOCOL = ormp;\n owner = dao;\n }\n\n receive() external payable {}\n\n /// @dev Only could be called by owner.\n /// @notice Each channel has a corresponding oracle, and the message root should match with it.\n /// @param chainId The source chain id.\n /// @param messageIndex The source chain message index corresponds to the respective channel.\n /// @param messageRoot The source chain message root corresponding to the channel.\n function importMessageRoot(uint256 chainId, uint256 messageIndex, bytes32 messageRoot) external onlyOwner {\n rootOf[chainId][messageIndex] = messageRoot;\n emit ImportedMessageRoot(chainId, messageIndex, messageRoot);\n }\n\n function changeOwner(address newOwner) external onlyOwner {\n address oldOwner = owner;\n owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n\n function setApproved(address operator, bool approve) external onlyOwner {\n approvedOf[operator] = approve;\n emit SetApproved(operator, approve);\n }\n\n function isApproved(address operator) public view returns (bool) {\n return approvedOf[operator];\n }\n\n function withdraw(address to, uint256 amount) external onlyApproved {\n (bool success,) = to.call{value: amount}(\"\");\n require(success, \"!withdraw\");\n emit Withdrawal(to, amount);\n }\n\n function setFee(uint256 chainId, uint256 fee_) external onlyApproved {\n feeOf[chainId] = fee_;\n emit SetFee(chainId, fee_);\n }\n\n function fee(uint256 toChainId, address /*ua*/ ) public view returns (uint256) {\n uint256 f = feeOf[toChainId];\n require(f != 0, \"!fee\");\n return f;\n }\n\n function assign(bytes32 msgHash) external payable {\n require(msg.sender == PROTOCOL, \"!auth\");\n emit Assigned(msgHash, msg.value);\n }\n\n function merkleRoot(uint256 chainId, uint256 messageIndex) public view override returns (bytes32) {\n return rootOf[chainId][messageIndex];\n }\n}\n"},"src/Verifier.sol":{"content":"// This file is part of Darwinia.\n// Copyright (C) 2018-2023 Darwinia Network\n// SPDX-License-Identifier: GPL-3.0\n//\n// Darwinia is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Darwinia is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Darwinia. If not, see .\n\npragma solidity 0.8.17;\n\nimport \"./interfaces/IVerifier.sol\";\nimport \"./imt/IncrementalMerkleTree.sol\";\n\nabstract contract Verifier is IVerifier {\n /// @notice Message proof.\n /// @param messageIndex Leaf index of the message hash in incremental merkle tree.\n /// @param messageProof Merkle proof of the message hash.\n struct Proof {\n uint256 messageIndex;\n bytes32[32] messageProof;\n }\n\n /// @inheritdoc IVerifier\n function merkleRoot(uint256 chainId, uint256 messageIndex) public view virtual returns (bytes32);\n\n /// @inheritdoc IVerifier\n function verifyMessageProof(uint256 fromChainId, bytes32 msgHash, bytes calldata proof)\n external\n view\n returns (bool)\n {\n // decode proof\n Proof memory p = abi.decode(proof, (Proof));\n\n // fetch message root in block number from chain\n bytes32 imtRootOracle = merkleRoot(fromChainId, p.messageIndex);\n // calculate the expected root based on the proof\n bytes32 imtRootProof = IncrementalMerkleTree.branchRoot(msgHash, p.messageProof, p.messageIndex);\n\n // check oracle's merkle root equal relayer's merkle root\n return imtRootOracle == imtRootProof;\n }\n}\n"},"src/interfaces/IVerifier.sol":{"content":"// This file is part of Darwinia.\n// Copyright (C) 2018-2023 Darwinia Network\n// SPDX-License-Identifier: GPL-3.0\n//\n// Darwinia is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Darwinia is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Darwinia. If not, see .\n\npragma solidity 0.8.17;\n\ninterface IVerifier {\n /// @notice Fetch message root oracle.\n /// @param chainId The destination chain id.\n /// @param messageIndex Leaf index of the message hash in incremental merkle tree.\n /// @return Message root in destination chain.\n function merkleRoot(uint256 chainId, uint256 messageIndex) external view returns (bytes32);\n\n /// @notice Verify message proof\n /// @dev Message proof provided by relayer. Oracle should provide message root of\n /// source chain, and verify the merkle proof of the message hash.\n /// @param fromChainId Source chain id.\n /// @param msgHash Hash of the message.\n /// @param proof Merkle proof of the message\n /// @return Result of the message verify.\n function verifyMessageProof(uint256 fromChainId, bytes32 msgHash, bytes calldata proof)\n external\n view\n returns (bool);\n}\n"},"src/imt/IncrementalMerkleTree.sol":{"content":"// SPDX-License-Identifier: MIT OR Apache-2.0\npragma solidity 0.8.17;\n\n// Inspired: https://github.com/nomad-xyz/monorepo/blob/main/packages/contracts-core/contracts/libs/Merkle.sol\n\n/// @title IncrementalMerkleTree\n/// @author Illusory Systems Inc.\n/// @notice An incremental merkle tree modeled on the eth2 deposit contract.\nlibrary IncrementalMerkleTree {\n uint256 private constant TREE_DEPTH = 32;\n uint256 private constant MAX_LEAVES = 2 ** TREE_DEPTH - 1;\n\n /// @notice Struct representing incremental merkle tree. Contains current\n /// branch and the number of inserted leaves in the tree.\n struct Tree {\n bytes32[TREE_DEPTH] branch;\n uint256 count;\n }\n\n /// @notice Inserts `_node` into merkle tree\n /// @dev Reverts if tree is full\n /// @param _node Element to insert into tree\n function insert(Tree storage _tree, bytes32 _node) internal {\n require(_tree.count < MAX_LEAVES, \"merkle tree full\");\n\n _tree.count += 1;\n uint256 size = _tree.count;\n for (uint256 i = 0; i < TREE_DEPTH; i++) {\n if ((size & 1) == 1) {\n _tree.branch[i] = _node;\n return;\n }\n _node = keccak256(abi.encodePacked(_tree.branch[i], _node));\n size /= 2;\n }\n // As the loop should always end prematurely with the `return` statement,\n // this code should be unreachable. We assert `false` just to be safe.\n assert(false);\n }\n\n /// @notice Calculates and returns`_tree`'s current root given array of zero\n /// hashes\n /// @param _zeroes Array of zero hashes\n /// @return _current Calculated root of `_tree`\n function rootWithCtx(Tree storage _tree, bytes32[TREE_DEPTH] memory _zeroes)\n internal\n view\n returns (bytes32 _current)\n {\n uint256 _index = _tree.count;\n\n for (uint256 i = 0; i < TREE_DEPTH; i++) {\n uint256 _ithBit = (_index >> i) & 0x01;\n bytes32 _next = _tree.branch[i];\n if (_ithBit == 1) {\n _current = keccak256(abi.encodePacked(_next, _current));\n } else {\n _current = keccak256(abi.encodePacked(_current, _zeroes[i]));\n }\n }\n }\n\n /// @notice Calculates and returns`_tree`'s current root\n function root(Tree storage _tree) internal view returns (bytes32) {\n return rootWithCtx(_tree, zeroHashes());\n }\n\n /// @notice Returns array of TREE_DEPTH zero hashes\n /// @return _zeroes Array of TREE_DEPTH zero hashes\n function zeroHashes() internal pure returns (bytes32[TREE_DEPTH] memory _zeroes) {\n _zeroes[0] = Z_0;\n _zeroes[1] = Z_1;\n _zeroes[2] = Z_2;\n _zeroes[3] = Z_3;\n _zeroes[4] = Z_4;\n _zeroes[5] = Z_5;\n _zeroes[6] = Z_6;\n _zeroes[7] = Z_7;\n _zeroes[8] = Z_8;\n _zeroes[9] = Z_9;\n _zeroes[10] = Z_10;\n _zeroes[11] = Z_11;\n _zeroes[12] = Z_12;\n _zeroes[13] = Z_13;\n _zeroes[14] = Z_14;\n _zeroes[15] = Z_15;\n _zeroes[16] = Z_16;\n _zeroes[17] = Z_17;\n _zeroes[18] = Z_18;\n _zeroes[19] = Z_19;\n _zeroes[20] = Z_20;\n _zeroes[21] = Z_21;\n _zeroes[22] = Z_22;\n _zeroes[23] = Z_23;\n _zeroes[24] = Z_24;\n _zeroes[25] = Z_25;\n _zeroes[26] = Z_26;\n _zeroes[27] = Z_27;\n _zeroes[28] = Z_28;\n _zeroes[29] = Z_29;\n _zeroes[30] = Z_30;\n _zeroes[31] = Z_31;\n }\n\n /// @notice Calculates and returns the merkle root for the given leaf\n /// `_item`, a merkle branch, and the index of `_item` in the tree.\n /// @param _item Merkle leaf\n /// @param _branch Merkle proof\n /// @param _index Index of `_item` in tree\n /// @return _current Calculated merkle root\n function branchRoot(bytes32 _item, bytes32[TREE_DEPTH] memory _branch, uint256 _index)\n internal\n pure\n returns (bytes32 _current)\n {\n _current = _item;\n\n for (uint256 i = 0; i < TREE_DEPTH; i++) {\n uint256 _ithBit = (_index >> i) & 0x01;\n bytes32 _next = _branch[i];\n if (_ithBit == 1) {\n _current = keccak256(abi.encodePacked(_next, _current));\n } else {\n _current = keccak256(abi.encodePacked(_current, _next));\n }\n }\n }\n\n function prove(Tree storage _tree) internal view returns (bytes32[TREE_DEPTH] memory proof) {\n uint256 _index = _tree.count - 1;\n bytes32[TREE_DEPTH] memory left = _tree.branch;\n bytes32[TREE_DEPTH] memory right = zeroHashes();\n for (uint256 i = 0; i < TREE_DEPTH; i++) {\n uint256 _ith_bit = (_index >> i) & 0x01;\n if (_ith_bit == 1) {\n proof[i] = left[i];\n } else {\n proof[i] = right[i];\n }\n }\n }\n\n // keccak256 zero hashes\n bytes32 private constant Z_0 = hex\"0000000000000000000000000000000000000000000000000000000000000000\";\n bytes32 private constant Z_1 = hex\"ad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5\";\n bytes32 private constant Z_2 = hex\"b4c11951957c6f8f642c4af61cd6b24640fec6dc7fc607ee8206a99e92410d30\";\n bytes32 private constant Z_3 = hex\"21ddb9a356815c3fac1026b6dec5df3124afbadb485c9ba5a3e3398a04b7ba85\";\n bytes32 private constant Z_4 = hex\"e58769b32a1beaf1ea27375a44095a0d1fb664ce2dd358e7fcbfb78c26a19344\";\n bytes32 private constant Z_5 = hex\"0eb01ebfc9ed27500cd4dfc979272d1f0913cc9f66540d7e8005811109e1cf2d\";\n bytes32 private constant Z_6 = hex\"887c22bd8750d34016ac3c66b5ff102dacdd73f6b014e710b51e8022af9a1968\";\n bytes32 private constant Z_7 = hex\"ffd70157e48063fc33c97a050f7f640233bf646cc98d9524c6b92bcf3ab56f83\";\n bytes32 private constant Z_8 = hex\"9867cc5f7f196b93bae1e27e6320742445d290f2263827498b54fec539f756af\";\n bytes32 private constant Z_9 = hex\"cefad4e508c098b9a7e1d8feb19955fb02ba9675585078710969d3440f5054e0\";\n bytes32 private constant Z_10 = hex\"f9dc3e7fe016e050eff260334f18a5d4fe391d82092319f5964f2e2eb7c1c3a5\";\n bytes32 private constant Z_11 = hex\"f8b13a49e282f609c317a833fb8d976d11517c571d1221a265d25af778ecf892\";\n bytes32 private constant Z_12 = hex\"3490c6ceeb450aecdc82e28293031d10c7d73bf85e57bf041a97360aa2c5d99c\";\n bytes32 private constant Z_13 = hex\"c1df82d9c4b87413eae2ef048f94b4d3554cea73d92b0f7af96e0271c691e2bb\";\n bytes32 private constant Z_14 = hex\"5c67add7c6caf302256adedf7ab114da0acfe870d449a3a489f781d659e8becc\";\n bytes32 private constant Z_15 = hex\"da7bce9f4e8618b6bd2f4132ce798cdc7a60e7e1460a7299e3c6342a579626d2\";\n bytes32 private constant Z_16 = hex\"2733e50f526ec2fa19a22b31e8ed50f23cd1fdf94c9154ed3a7609a2f1ff981f\";\n bytes32 private constant Z_17 = hex\"e1d3b5c807b281e4683cc6d6315cf95b9ade8641defcb32372f1c126e398ef7a\";\n bytes32 private constant Z_18 = hex\"5a2dce0a8a7f68bb74560f8f71837c2c2ebbcbf7fffb42ae1896f13f7c7479a0\";\n bytes32 private constant Z_19 = hex\"b46a28b6f55540f89444f63de0378e3d121be09e06cc9ded1c20e65876d36aa0\";\n bytes32 private constant Z_20 = hex\"c65e9645644786b620e2dd2ad648ddfcbf4a7e5b1a3a4ecfe7f64667a3f0b7e2\";\n bytes32 private constant Z_21 = hex\"f4418588ed35a2458cffeb39b93d26f18d2ab13bdce6aee58e7b99359ec2dfd9\";\n bytes32 private constant Z_22 = hex\"5a9c16dc00d6ef18b7933a6f8dc65ccb55667138776f7dea101070dc8796e377\";\n bytes32 private constant Z_23 = hex\"4df84f40ae0c8229d0d6069e5c8f39a7c299677a09d367fc7b05e3bc380ee652\";\n bytes32 private constant Z_24 = hex\"cdc72595f74c7b1043d0e1ffbab734648c838dfb0527d971b602bc216c9619ef\";\n bytes32 private constant Z_25 = hex\"0abf5ac974a1ed57f4050aa510dd9c74f508277b39d7973bb2dfccc5eeb0618d\";\n bytes32 private constant Z_26 = hex\"b8cd74046ff337f0a7bf2c8e03e10f642c1886798d71806ab1e888d9e5ee87d0\";\n bytes32 private constant Z_27 = hex\"838c5655cb21c6cb83313b5a631175dff4963772cce9108188b34ac87c81c41e\";\n bytes32 private constant Z_28 = hex\"662ee4dd2dd7b2bc707961b1e646c4047669dcb6584f0d8d770daf5d7e7deb2e\";\n bytes32 private constant Z_29 = hex\"388ab20e2573d171a88108e79d820e98f26c0b84aa8b2f4aa4968dbb818ea322\";\n bytes32 private constant Z_30 = hex\"93237c50ba75ee485f4c22adf2f741400bdf8d6a9cc7df7ecae576221665d735\";\n bytes32 private constant Z_31 = hex\"8448818bb4ae4562849e949e17ac16e0be16688e156b5cf15e098c627c0056a9\";\n}\n"}},"settings":{"remappings":["forge-std/=lib/forge-std/src/","ds-test/=lib/forge-std/lib/ds-test/src/","create3-deploy/=lib/create3-deploy/"],"optimizer":{"enabled":true,"runs":999999},"metadata":{"useLiteralContent":false,"bytecodeHash":"ipfs"},"outputSelection":{"*":{"":["ast"],"*":["abi","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers","metadata","storageLayout","devdoc","userdoc"]}},"evmVersion":"london","libraries":{}}} diff --git a/script/output/421614/deploy.a-latest.json b/script/output/421614/deploy.a-latest.json index 7e30eed..44747a5 100644 --- a/script/output/421614/deploy.a-latest.json +++ b/script/output/421614/deploy.a-latest.json @@ -1,6 +1,6 @@ { "DAO": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec", - "ORACLE": "0x0000000004A34ac73374b65a55C93CF9D4Bc3d17", + "ORACLE": "0x000000000DA67291724858F7e759A43B2d23225e", "ORMP": "0x00000000001523057a05d6293C1e5171eE33eE0A", "RELAYER": "0x0000000000808fE9bDCc1d180EfbF5C53552a6b1" } \ No newline at end of file diff --git a/script/output/43/deploy.a-latest.json b/script/output/43/deploy.a-latest.json index 7e30eed..44747a5 100644 --- a/script/output/43/deploy.a-latest.json +++ b/script/output/43/deploy.a-latest.json @@ -1,6 +1,6 @@ { "DAO": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec", - "ORACLE": "0x0000000004A34ac73374b65a55C93CF9D4Bc3d17", + "ORACLE": "0x000000000DA67291724858F7e759A43B2d23225e", "ORMP": "0x00000000001523057a05d6293C1e5171eE33eE0A", "RELAYER": "0x0000000000808fE9bDCc1d180EfbF5C53552a6b1" } \ No newline at end of file diff --git a/script/output/44/ORMPOracle.v.json b/script/output/44/ORMPOracle.v.json new file mode 100644 index 0000000..ecc89e7 --- /dev/null +++ b/script/output/44/ORMPOracle.v.json @@ -0,0 +1 @@ +{"language": "Solidity", "sources": {"src/eco/ORMPOracle.sol": {"content": "// This file is part of Darwinia.\n// Copyright (C) 2018-2023 Darwinia Network\n// SPDX-License-Identifier: GPL-3.0\n//\n// Darwinia is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Darwinia is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Darwinia. If not, see .\n\npragma solidity 0.8.17;\n\nimport \"../Verifier.sol\";\n\ncontract ORMPOracle is Verifier {\n event Assigned(bytes32 indexed msgHash, uint256 fee);\n event SetFee(uint256 indexed chainId, uint256 fee);\n event SetApproved(address operator, bool approve);\n event Withdrawal(address indexed to, uint256 amt);\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n event ImportedMessageRoot(uint256 indexed chainId, uint256 indexed messageIndex, bytes32 messageRoot);\n\n address public immutable PROTOCOL;\n\n address public owner;\n // chainId => price\n mapping(uint256 => uint256) public feeOf;\n // chainId => messageIndex => messageRoot\n mapping(uint256 => mapping(uint256 => bytes32)) rootOf;\n // operator => isApproved\n mapping(address => bool) public approvedOf;\n\n modifier onlyOwner() {\n require(msg.sender == owner, \"!owner\");\n _;\n }\n\n modifier onlyApproved() {\n require(isApproved(msg.sender), \"!approve\");\n _;\n }\n\n constructor(address dao, address ormp) {\n PROTOCOL = ormp;\n owner = dao;\n }\n\n receive() external payable {}\n\n /// @dev Only could be called by owner.\n /// @notice Each channel has a corresponding oracle, and the message root should match with it.\n /// @param chainId The source chain id.\n /// @param messageIndex The source chain message index corresponds to the respective channel.\n /// @param messageRoot The source chain message root corresponding to the channel.\n function importMessageRoot(uint256 chainId, uint256 messageIndex, bytes32 messageRoot) external onlyOwner {\n rootOf[chainId][messageIndex] = messageRoot;\n emit ImportedMessageRoot(chainId, messageIndex, messageRoot);\n }\n\n function changeOwner(address newOwner) external onlyOwner {\n address oldOwner = owner;\n owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n\n function setApproved(address operator, bool approve) external onlyOwner {\n approvedOf[operator] = approve;\n emit SetApproved(operator, approve);\n }\n\n function isApproved(address operator) public view returns (bool) {\n return approvedOf[operator];\n }\n\n function withdraw(address to, uint256 amount) external onlyApproved {\n (bool success,) = to.call{value: amount}(\"\");\n require(success, \"!withdraw\");\n emit Withdrawal(to, amount);\n }\n\n function setFee(uint256 chainId, uint256 fee_) external onlyApproved {\n feeOf[chainId] = fee_;\n emit SetFee(chainId, fee_);\n }\n\n function fee(uint256 toChainId, address /*ua*/ ) public view returns (uint256) {\n uint256 f = feeOf[toChainId];\n require(f != 0, \"!fee\");\n return f;\n }\n\n function assign(bytes32 msgHash) external payable {\n require(msg.sender == PROTOCOL, \"!auth\");\n emit Assigned(msgHash, msg.value);\n }\n\n function merkleRoot(uint256 chainId, uint256 messageIndex) public view override returns (bytes32) {\n return rootOf[chainId][messageIndex];\n }\n}\n", "keccak256": "0x014d7b69eac7a1c1fb0b9789212cde2065a89dea0691607364568e39d25c22e4"}, "src/Verifier.sol": {"content": "// This file is part of Darwinia.\n// Copyright (C) 2018-2023 Darwinia Network\n// SPDX-License-Identifier: GPL-3.0\n//\n// Darwinia is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Darwinia is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Darwinia. If not, see .\n\npragma solidity 0.8.17;\n\nimport \"./interfaces/IVerifier.sol\";\nimport \"./imt/IncrementalMerkleTree.sol\";\n\nabstract contract Verifier is IVerifier {\n /// @notice Message proof.\n /// @param messageIndex Leaf index of the message hash in incremental merkle tree.\n /// @param messageProof Merkle proof of the message hash.\n struct Proof {\n uint256 messageIndex;\n bytes32[32] messageProof;\n }\n\n /// @inheritdoc IVerifier\n function merkleRoot(uint256 chainId, uint256 messageIndex) public view virtual returns (bytes32);\n\n /// @inheritdoc IVerifier\n function verifyMessageProof(uint256 fromChainId, bytes32 msgHash, bytes calldata proof)\n external\n view\n returns (bool)\n {\n // decode proof\n Proof memory p = abi.decode(proof, (Proof));\n\n // fetch message root in block number from chain\n bytes32 imtRootOracle = merkleRoot(fromChainId, p.messageIndex);\n // calculate the expected root based on the proof\n bytes32 imtRootProof = IncrementalMerkleTree.branchRoot(msgHash, p.messageProof, p.messageIndex);\n\n // check oracle's merkle root equal relayer's merkle root\n return imtRootOracle == imtRootProof;\n }\n}\n", "keccak256": "0x08f06c2b65b57e30c57fb088e1adf9236480a936414a16f3694feff19ca3e970"}, "src/interfaces/IVerifier.sol": {"content": "// This file is part of Darwinia.\n// Copyright (C) 2018-2023 Darwinia Network\n// SPDX-License-Identifier: GPL-3.0\n//\n// Darwinia is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Darwinia is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Darwinia. If not, see .\n\npragma solidity 0.8.17;\n\ninterface IVerifier {\n /// @notice Fetch message root oracle.\n /// @param chainId The destination chain id.\n /// @param messageIndex Leaf index of the message hash in incremental merkle tree.\n /// @return Message root in destination chain.\n function merkleRoot(uint256 chainId, uint256 messageIndex) external view returns (bytes32);\n\n /// @notice Verify message proof\n /// @dev Message proof provided by relayer. Oracle should provide message root of\n /// source chain, and verify the merkle proof of the message hash.\n /// @param fromChainId Source chain id.\n /// @param msgHash Hash of the message.\n /// @param proof Merkle proof of the message\n /// @return Result of the message verify.\n function verifyMessageProof(uint256 fromChainId, bytes32 msgHash, bytes calldata proof)\n external\n view\n returns (bool);\n}\n", "keccak256": "0x4b7161a706bb8aa2fad647c374317eeea786113e0cb63db04176eed693f43c43"}, "src/imt/IncrementalMerkleTree.sol": {"content": "// SPDX-License-Identifier: MIT OR Apache-2.0\npragma solidity 0.8.17;\n\n// Inspired: https://github.com/nomad-xyz/monorepo/blob/main/packages/contracts-core/contracts/libs/Merkle.sol\n\n/// @title IncrementalMerkleTree\n/// @author Illusory Systems Inc.\n/// @notice An incremental merkle tree modeled on the eth2 deposit contract.\nlibrary IncrementalMerkleTree {\n uint256 private constant TREE_DEPTH = 32;\n uint256 private constant MAX_LEAVES = 2 ** TREE_DEPTH - 1;\n\n /// @notice Struct representing incremental merkle tree. Contains current\n /// branch and the number of inserted leaves in the tree.\n struct Tree {\n bytes32[TREE_DEPTH] branch;\n uint256 count;\n }\n\n /// @notice Inserts `_node` into merkle tree\n /// @dev Reverts if tree is full\n /// @param _node Element to insert into tree\n function insert(Tree storage _tree, bytes32 _node) internal {\n require(_tree.count < MAX_LEAVES, \"merkle tree full\");\n\n _tree.count += 1;\n uint256 size = _tree.count;\n for (uint256 i = 0; i < TREE_DEPTH; i++) {\n if ((size & 1) == 1) {\n _tree.branch[i] = _node;\n return;\n }\n _node = keccak256(abi.encodePacked(_tree.branch[i], _node));\n size /= 2;\n }\n // As the loop should always end prematurely with the `return` statement,\n // this code should be unreachable. We assert `false` just to be safe.\n assert(false);\n }\n\n /// @notice Calculates and returns`_tree`'s current root given array of zero\n /// hashes\n /// @param _zeroes Array of zero hashes\n /// @return _current Calculated root of `_tree`\n function rootWithCtx(Tree storage _tree, bytes32[TREE_DEPTH] memory _zeroes)\n internal\n view\n returns (bytes32 _current)\n {\n uint256 _index = _tree.count;\n\n for (uint256 i = 0; i < TREE_DEPTH; i++) {\n uint256 _ithBit = (_index >> i) & 0x01;\n bytes32 _next = _tree.branch[i];\n if (_ithBit == 1) {\n _current = keccak256(abi.encodePacked(_next, _current));\n } else {\n _current = keccak256(abi.encodePacked(_current, _zeroes[i]));\n }\n }\n }\n\n /// @notice Calculates and returns`_tree`'s current root\n function root(Tree storage _tree) internal view returns (bytes32) {\n return rootWithCtx(_tree, zeroHashes());\n }\n\n /// @notice Returns array of TREE_DEPTH zero hashes\n /// @return _zeroes Array of TREE_DEPTH zero hashes\n function zeroHashes() internal pure returns (bytes32[TREE_DEPTH] memory _zeroes) {\n _zeroes[0] = Z_0;\n _zeroes[1] = Z_1;\n _zeroes[2] = Z_2;\n _zeroes[3] = Z_3;\n _zeroes[4] = Z_4;\n _zeroes[5] = Z_5;\n _zeroes[6] = Z_6;\n _zeroes[7] = Z_7;\n _zeroes[8] = Z_8;\n _zeroes[9] = Z_9;\n _zeroes[10] = Z_10;\n _zeroes[11] = Z_11;\n _zeroes[12] = Z_12;\n _zeroes[13] = Z_13;\n _zeroes[14] = Z_14;\n _zeroes[15] = Z_15;\n _zeroes[16] = Z_16;\n _zeroes[17] = Z_17;\n _zeroes[18] = Z_18;\n _zeroes[19] = Z_19;\n _zeroes[20] = Z_20;\n _zeroes[21] = Z_21;\n _zeroes[22] = Z_22;\n _zeroes[23] = Z_23;\n _zeroes[24] = Z_24;\n _zeroes[25] = Z_25;\n _zeroes[26] = Z_26;\n _zeroes[27] = Z_27;\n _zeroes[28] = Z_28;\n _zeroes[29] = Z_29;\n _zeroes[30] = Z_30;\n _zeroes[31] = Z_31;\n }\n\n /// @notice Calculates and returns the merkle root for the given leaf\n /// `_item`, a merkle branch, and the index of `_item` in the tree.\n /// @param _item Merkle leaf\n /// @param _branch Merkle proof\n /// @param _index Index of `_item` in tree\n /// @return _current Calculated merkle root\n function branchRoot(bytes32 _item, bytes32[TREE_DEPTH] memory _branch, uint256 _index)\n internal\n pure\n returns (bytes32 _current)\n {\n _current = _item;\n\n for (uint256 i = 0; i < TREE_DEPTH; i++) {\n uint256 _ithBit = (_index >> i) & 0x01;\n bytes32 _next = _branch[i];\n if (_ithBit == 1) {\n _current = keccak256(abi.encodePacked(_next, _current));\n } else {\n _current = keccak256(abi.encodePacked(_current, _next));\n }\n }\n }\n\n function prove(Tree storage _tree) internal view returns (bytes32[TREE_DEPTH] memory proof) {\n uint256 _index = _tree.count - 1;\n bytes32[TREE_DEPTH] memory left = _tree.branch;\n bytes32[TREE_DEPTH] memory right = zeroHashes();\n for (uint256 i = 0; i < TREE_DEPTH; i++) {\n uint256 _ith_bit = (_index >> i) & 0x01;\n if (_ith_bit == 1) {\n proof[i] = left[i];\n } else {\n proof[i] = right[i];\n }\n }\n }\n\n // keccak256 zero hashes\n bytes32 private constant Z_0 = hex\"0000000000000000000000000000000000000000000000000000000000000000\";\n bytes32 private constant Z_1 = hex\"ad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5\";\n bytes32 private constant Z_2 = hex\"b4c11951957c6f8f642c4af61cd6b24640fec6dc7fc607ee8206a99e92410d30\";\n bytes32 private constant Z_3 = hex\"21ddb9a356815c3fac1026b6dec5df3124afbadb485c9ba5a3e3398a04b7ba85\";\n bytes32 private constant Z_4 = hex\"e58769b32a1beaf1ea27375a44095a0d1fb664ce2dd358e7fcbfb78c26a19344\";\n bytes32 private constant Z_5 = hex\"0eb01ebfc9ed27500cd4dfc979272d1f0913cc9f66540d7e8005811109e1cf2d\";\n bytes32 private constant Z_6 = hex\"887c22bd8750d34016ac3c66b5ff102dacdd73f6b014e710b51e8022af9a1968\";\n bytes32 private constant Z_7 = hex\"ffd70157e48063fc33c97a050f7f640233bf646cc98d9524c6b92bcf3ab56f83\";\n bytes32 private constant Z_8 = hex\"9867cc5f7f196b93bae1e27e6320742445d290f2263827498b54fec539f756af\";\n bytes32 private constant Z_9 = hex\"cefad4e508c098b9a7e1d8feb19955fb02ba9675585078710969d3440f5054e0\";\n bytes32 private constant Z_10 = hex\"f9dc3e7fe016e050eff260334f18a5d4fe391d82092319f5964f2e2eb7c1c3a5\";\n bytes32 private constant Z_11 = hex\"f8b13a49e282f609c317a833fb8d976d11517c571d1221a265d25af778ecf892\";\n bytes32 private constant Z_12 = hex\"3490c6ceeb450aecdc82e28293031d10c7d73bf85e57bf041a97360aa2c5d99c\";\n bytes32 private constant Z_13 = hex\"c1df82d9c4b87413eae2ef048f94b4d3554cea73d92b0f7af96e0271c691e2bb\";\n bytes32 private constant Z_14 = hex\"5c67add7c6caf302256adedf7ab114da0acfe870d449a3a489f781d659e8becc\";\n bytes32 private constant Z_15 = hex\"da7bce9f4e8618b6bd2f4132ce798cdc7a60e7e1460a7299e3c6342a579626d2\";\n bytes32 private constant Z_16 = hex\"2733e50f526ec2fa19a22b31e8ed50f23cd1fdf94c9154ed3a7609a2f1ff981f\";\n bytes32 private constant Z_17 = hex\"e1d3b5c807b281e4683cc6d6315cf95b9ade8641defcb32372f1c126e398ef7a\";\n bytes32 private constant Z_18 = hex\"5a2dce0a8a7f68bb74560f8f71837c2c2ebbcbf7fffb42ae1896f13f7c7479a0\";\n bytes32 private constant Z_19 = hex\"b46a28b6f55540f89444f63de0378e3d121be09e06cc9ded1c20e65876d36aa0\";\n bytes32 private constant Z_20 = hex\"c65e9645644786b620e2dd2ad648ddfcbf4a7e5b1a3a4ecfe7f64667a3f0b7e2\";\n bytes32 private constant Z_21 = hex\"f4418588ed35a2458cffeb39b93d26f18d2ab13bdce6aee58e7b99359ec2dfd9\";\n bytes32 private constant Z_22 = hex\"5a9c16dc00d6ef18b7933a6f8dc65ccb55667138776f7dea101070dc8796e377\";\n bytes32 private constant Z_23 = hex\"4df84f40ae0c8229d0d6069e5c8f39a7c299677a09d367fc7b05e3bc380ee652\";\n bytes32 private constant Z_24 = hex\"cdc72595f74c7b1043d0e1ffbab734648c838dfb0527d971b602bc216c9619ef\";\n bytes32 private constant Z_25 = hex\"0abf5ac974a1ed57f4050aa510dd9c74f508277b39d7973bb2dfccc5eeb0618d\";\n bytes32 private constant Z_26 = hex\"b8cd74046ff337f0a7bf2c8e03e10f642c1886798d71806ab1e888d9e5ee87d0\";\n bytes32 private constant Z_27 = hex\"838c5655cb21c6cb83313b5a631175dff4963772cce9108188b34ac87c81c41e\";\n bytes32 private constant Z_28 = hex\"662ee4dd2dd7b2bc707961b1e646c4047669dcb6584f0d8d770daf5d7e7deb2e\";\n bytes32 private constant Z_29 = hex\"388ab20e2573d171a88108e79d820e98f26c0b84aa8b2f4aa4968dbb818ea322\";\n bytes32 private constant Z_30 = hex\"93237c50ba75ee485f4c22adf2f741400bdf8d6a9cc7df7ecae576221665d735\";\n bytes32 private constant Z_31 = hex\"8448818bb4ae4562849e949e17ac16e0be16688e156b5cf15e098c627c0056a9\";\n}\n", "keccak256": "0x535228355f8bd4339f42aa3dfe3cebcbdaad7a92704c4e3eeb0982dce8acf246"}}, "settings": {"remappings": ["forge-std/=lib/forge-std/src/", "ds-test/=lib/forge-std/lib/ds-test/src/", "create3-deploy/=lib/create3-deploy/"], "optimizer": {"enabled": true, "runs": 999999}, "metadata": {"useLiteralContent": false, "bytecodeHash": "ipfs"}, "outputSelection": {"*": {"": ["ast"], "*": ["abi", "evm.bytecode", "evm.deployedBytecode", "evm.methodIdentifiers", "metadata", "storageLayout", "devdoc", "userdoc"]}}, "evmVersion": "london", "libraries": {}, "compilationTarget": {"src/eco/ORMPOracle.sol": "ORMPOracle"}}} \ No newline at end of file diff --git a/script/output/44/deploy.a-latest.json b/script/output/44/deploy.a-latest.json index 7e30eed..44747a5 100644 --- a/script/output/44/deploy.a-latest.json +++ b/script/output/44/deploy.a-latest.json @@ -1,6 +1,6 @@ { "DAO": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec", - "ORACLE": "0x0000000004A34ac73374b65a55C93CF9D4Bc3d17", + "ORACLE": "0x000000000DA67291724858F7e759A43B2d23225e", "ORMP": "0x00000000001523057a05d6293C1e5171eE33eE0A", "RELAYER": "0x0000000000808fE9bDCc1d180EfbF5C53552a6b1" } \ No newline at end of file diff --git a/src/eco/OracleV2.sol b/src/eco/ORMPOracle.sol similarity index 89% rename from src/eco/OracleV2.sol rename to src/eco/ORMPOracle.sol index 476ccdb..e3c9e8c 100644 --- a/src/eco/OracleV2.sol +++ b/src/eco/ORMPOracle.sol @@ -19,7 +19,7 @@ pragma solidity 0.8.17; import "../Verifier.sol"; -contract OracleV2 is Verifier { +contract ORMPOracle is Verifier { event Assigned(bytes32 indexed msgHash, uint256 fee); event SetFee(uint256 indexed chainId, uint256 fee); event SetApproved(address operator, bool approve); @@ -54,6 +54,11 @@ contract OracleV2 is Verifier { receive() external payable {} + /// @dev Only could be called by owner. + /// @notice Each channel has a corresponding oracle, and the message root should match with it. + /// @param chainId The source chain id. + /// @param messageIndex The source chain message index corresponds to the respective channel. + /// @param messageRoot The source chain message root corresponding to the channel. function importMessageRoot(uint256 chainId, uint256 messageIndex, bytes32 messageRoot) external onlyOwner { rootOf[chainId][messageIndex] = messageRoot; emit ImportedMessageRoot(chainId, messageIndex, messageRoot);