The home for Hyperlane core contracts, sdk packages, and other infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hyperlane-monorepo/solidity/contracts/hooks/MerkleTreeHook.sol

55 lines
1.6 KiB

// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import {MerkleLib, TREE_DEPTH} from "../libs/Merkle.sol";
import {Message} from "../libs/Message.sol";
import {MailboxClient} from "../client/MailboxClient.sol";
import {Indexed} from "../Indexed.sol";
import {IPostDispatchHook} from "../interfaces/hooks/IPostDispatchHook.sol";
contract MerkleTreeHook is IPostDispatchHook, MailboxClient, Indexed {
using Message for bytes;
using MerkleLib for MerkleLib.Tree;
// An incremental merkle tree used to store outbound message IDs.
MerkleLib.Tree internal _tree;
constructor(address _mailbox) MailboxClient(_mailbox) {}
function count() public view returns (uint32) {
return uint32(_tree.count);
}
function root() public view returns (bytes32) {
return _tree.root();
}
function branch() public view returns (bytes32[TREE_DEPTH] memory) {
return _tree.branch;
}
function tree() public view returns (MerkleLib.Tree memory) {
return _tree;
}
function latestCheckpoint() external view returns (bytes32, uint32) {
return (root(), count() - 1);
}
function postDispatch(
bytes calldata, /*metadata*/
bytes calldata message
) external payable override {
bytes32 id = message.id();
require(isLatestDispatched(id), "message not dispatching");
_tree.insert(id);
}
function quoteDispatch(
bytes calldata, /*metadata*/
bytes calldata /*message*/
) external pure override returns (uint256) {
return 0;
}
}