Skip to content

Commit

Permalink
Move ImportedMessageRoot event to ORMP contract #153 (#155)
Browse files Browse the repository at this point in the history
* fmt

* clean

* move

* fix test
  • Loading branch information
hujw77 authored Apr 10, 2024
1 parent f5dd0bb commit 54ed001
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
15 changes: 15 additions & 0 deletions src/ORMP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ contract ORMP is ReentrancyGuard, Channel {
event MessageAssigned(
bytes32 indexed msgHash, address indexed oracle, address indexed relayer, uint256 oracleFee, uint256 relayerFee
);
event HashImported(uint256 indexed srcChainId, address indexed oracle, bytes32 indexed lookupKey, bytes32 hash);

/// oracle => srcChainId => lookupKey => hash
mapping(address => mapping(uint256 => mapping(bytes32 => bytes32))) public hashLookup;

constructor(address dao) Channel(dao) {}

Expand Down Expand Up @@ -66,6 +70,17 @@ contract ORMP is ReentrancyGuard, Channel {
return msgHash;
}

/// @dev Import hash by any oracle address.
/// @notice Hash is an abstract of the proof system, it can be a block hash or a message root hash,
/// specifically provided by oracles.
/// @param srcChainId The source chain Id.
/// @param lookupKey The key for loop up hash.
/// @param hash_ The hash to import.
function importHash(uint256 srcChainId, bytes32 lookupKey, bytes32 hash_) external {
hashLookup[msg.sender][srcChainId][lookupKey] = hash_;
emit HashImported(srcChainId, msg.sender, lookupKey, hash_);
}

function _handleFee(
address ua,
address refund,
Expand Down
14 changes: 7 additions & 7 deletions src/eco/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
pragma solidity 0.8.17;

import "../Verifier.sol";
import "../interfaces/IORMP.sol";

contract Oracle is Verifier {
event SetFee(uint256 indexed chainId, uint256 fee);
event SetApproved(address operator, bool approve);
event Withdrawal(address indexed to, uint256 amt);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event ImportedMessageRoot(uint256 indexed chainId, uint256 indexed blockHeight, bytes32 messageRoot);

address public immutable PROTOCOL;

address public owner;
// chainId => price
mapping(uint256 => uint256) public feeOf;
// chainId => blockNumber => messageRoot
mapping(uint256 => mapping(uint256 => bytes32)) rootOf;
// operator => isApproved
mapping(address => bool) public approvedOf;

Expand All @@ -44,7 +44,8 @@ contract Oracle is Verifier {
_;
}

constructor(address dao) {
constructor(address dao, address ormp) {
PROTOCOL = ormp;
owner = dao;
}

Expand All @@ -60,8 +61,7 @@ contract Oracle is Verifier {
/// @param blockNumber The source chain block number.
/// @param messageRoot The source chain message root corresponding to the channel.
function importMessageRoot(uint256 chainId, uint256 blockNumber, bytes32 messageRoot) external onlyOwner {
rootOf[chainId][blockNumber] = messageRoot;
emit ImportedMessageRoot(chainId, blockNumber, messageRoot);
IORMP(PROTOCOL).importHash(chainId, bytes32(blockNumber), messageRoot);
}

function changeOwner(address newOwner) external onlyOwner {
Expand Down Expand Up @@ -97,6 +97,6 @@ contract Oracle is Verifier {
}

function merkleRoot(uint256 chainId, uint256 blockNumber) public view override returns (bytes32) {
return rootOf[chainId][blockNumber];
return IORMP(PROTOCOL).hashLookup(address(this), chainId, bytes32(blockNumber));
}
}
15 changes: 15 additions & 0 deletions src/interfaces/IORMP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,19 @@ interface IORMP {
/// @param msgHash Hash of the checked message.
/// @return Return the dispatched result of the checked message.
function dones(bytes32 msgHash) external view returns (bool);

/// @dev Import hash by any oracle address.
/// @notice Hash is an abstract of the proof system, it can be a block hash or a message root hash,
/// specifically provided by oracles.
/// @param srcChainId The source chain Id.
/// @param lookupKey The key for loop up hash.
/// @param hash_ The hash to import.
function importHash(uint256 srcChainId, bytes32 lookupKey, bytes32 hash_) external;

/// @dev Fetch hash.
/// @param oracle The oracle address.
/// @param srcChainId The source chain Id.
/// @param lookupKey The key for loop up hash.
/// @return Return the hash imported by the oracle.
function hashLookup(address oracle, uint256 srcChainId, bytes32 lookupKey) external view returns (bytes32);
}
2 changes: 1 addition & 1 deletion test/eco/Oracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ contract OracleTest is Test {
assertEq(r, bytes32(uint256(1)));
}

function merkleRoot(uint256, uint256) external pure returns (bytes32) {
function hashLookup(address, uint256, bytes32) external pure returns (bytes32) {
return bytes32(uint256(1));
}
}

0 comments on commit 54ed001

Please sign in to comment.