Skip to content

Commit

Permalink
oracle reset message index to block number
Browse files Browse the repository at this point in the history
  • Loading branch information
hujw77 committed Feb 4, 2024
1 parent 4d74cd1 commit 9055978
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/Verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ abstract contract Verifier is IVerifier {
/// @param messageIndex Leaf index of the message hash in incremental merkle tree.
/// @param messageProof Merkle proof of the message hash.
struct Proof {
uint256 blockNumber;
uint256 messageIndex;
bytes32[32] messageProof;
}

/// @inheritdoc IVerifier
function merkleRoot(uint256 chainId, uint256 messageIndex) public view virtual returns (bytes32);
function merkleRoot(uint256 chainId, uint256 blockNumber) public view virtual returns (bytes32);

/// @inheritdoc IVerifier
function verifyMessageProof(uint256 fromChainId, bytes32 msgHash, bytes calldata proof)
Expand All @@ -42,7 +43,7 @@ abstract contract Verifier is IVerifier {
Proof memory p = abi.decode(proof, (Proof));

// fetch message root in block number from chain
bytes32 imtRootOracle = merkleRoot(fromChainId, p.messageIndex);
bytes32 imtRootOracle = merkleRoot(fromChainId, p.blockNumber);
// calculate the expected root based on the proof
bytes32 imtRootProof = IncrementalMerkleTree.branchRoot(msgHash, p.messageProof, p.messageIndex);

Expand Down
16 changes: 8 additions & 8 deletions src/eco/ORMPOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ contract ORMPOracle is Verifier {
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 messageIndex, bytes32 messageRoot);
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 => messageIndex => messageRoot
// chainId => blockNumber => messageRoot
mapping(uint256 => mapping(uint256 => bytes32)) rootOf;
// operator => isApproved
mapping(address => bool) public approvedOf;
Expand All @@ -57,11 +57,11 @@ contract ORMPOracle is Verifier {
/// @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 blockNumber The source chain message accepted block number.
/// @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);
function importMessageRoot(uint256 chainId, uint256 blockNumber, bytes32 messageRoot) external onlyOwner {
rootOf[chainId][blockNumber] = messageRoot;
emit ImportedMessageRoot(chainId, blockNumber, messageRoot);
}

function changeOwner(address newOwner) external onlyOwner {
Expand Down Expand Up @@ -101,7 +101,7 @@ contract ORMPOracle is Verifier {
emit Assigned(msgHash, msg.value);
}

function merkleRoot(uint256 chainId, uint256 messageIndex) public view override returns (bytes32) {
return rootOf[chainId][messageIndex];
function merkleRoot(uint256 chainId, uint256 blockNumber) public view override returns (bytes32) {
return rootOf[chainId][blockNumber];
}
}
4 changes: 2 additions & 2 deletions src/interfaces/IVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ pragma solidity 0.8.17;
interface IVerifier {
/// @notice Fetch message root oracle.
/// @param chainId The destination chain id.
/// @param messageIndex Leaf index of the message hash in incremental merkle tree.
/// @param blockNumber The block number where the message root is located.
/// @return Message root in destination chain.
function merkleRoot(uint256 chainId, uint256 messageIndex) external view returns (bytes32);
function merkleRoot(uint256 chainId, uint256 blockNumber) external view returns (bytes32);

/// @notice Verify message proof
/// @dev Message proof provided by relayer. Oracle should provide message root of
Expand Down

0 comments on commit 9055978

Please sign in to comment.