Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move ImportedMessageRoot event to ORMP contract #153 #155

Merged
merged 6 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
hujw77 marked this conversation as resolved.
Show resolved Hide resolved

/// 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));
}
}
Loading