Skip to content

Commit

Permalink
Revert unrelated changes
Browse files Browse the repository at this point in the history
  • Loading branch information
yorhodes committed Nov 8, 2023
1 parent bcc1e18 commit 1a5cab3
Show file tree
Hide file tree
Showing 24 changed files with 471 additions and 356 deletions.
28 changes: 23 additions & 5 deletions solidity/contracts/client/MailboxClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {Message} from "../libs/Message.sol";

// ============ External Imports ============
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

abstract contract MailboxClient is Ownable {
abstract contract MailboxClient is OwnableUpgradeable {
using Message for bytes;

IMailbox public immutable mailbox;
Expand Down Expand Up @@ -68,12 +68,30 @@ abstract contract MailboxClient is Ownable {
* @notice Sets the address of the application's custom interchain security module.
* @param _module The address of the interchain security module contract.
*/
function setInterchainSecurityModule(
address _module
) public onlyContractOrNull(_module) onlyOwner {
function setInterchainSecurityModule(address _module)
public
onlyContractOrNull(_module)
onlyOwner
{
interchainSecurityModule = IInterchainSecurityModule(_module);
}

// ======== Initializer =========
function _MailboxClient_initialize(
address _hook,
address _interchainSecurityModule,
address _owner
) internal onlyInitializing {
__Ownable_init();
setHook(_hook);
setInterchainSecurityModule(_interchainSecurityModule);
_transferOwnership(_owner);
}

function _isLatestDispatched(bytes32 id) internal view returns (bool) {
return mailbox.latestDispatchedId() == id;
}

function _metadata(
uint32 /*_destinationDomain*/
) internal view virtual returns (bytes memory) {
Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/hooks/MerkleTreeHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ contract MerkleTreeHook is AbstractPostDispatchHook, MailboxClient, Indexed {

// ensure messages which were not dispatched are not inserted into the tree
bytes32 id = message.id();
require(id == mailbox.latestDispatchedId(), "message not dispatching");
require(_isLatestDispatched(id), "message not dispatching");

uint32 index = count();
_tree.insert(id);
Expand Down
17 changes: 8 additions & 9 deletions solidity/contracts/hooks/libs/AbstractMessageIdAuthHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ abstract contract AbstractMessageIdAuthHook is
// ============ Internal functions ============

/// @inheritdoc AbstractPostDispatchHook
function _postDispatch(
bytes calldata metadata,
bytes calldata message
) internal override {
function _postDispatch(bytes calldata metadata, bytes calldata message)
internal
override
{
bytes32 id = message.id();
require(
id == mailbox.latestDispatchedId(),
_isLatestDispatched(id),
"AbstractMessageIdAuthHook: message not latest dispatched"
);
require(
Expand All @@ -90,8 +90,7 @@ abstract contract AbstractMessageIdAuthHook is
* @param metadata The metadata for the hook caller
* @param payload The payload for call to the ISM
*/
function _sendMessageId(
bytes calldata metadata,
bytes memory payload
) internal virtual;
function _sendMessageId(bytes calldata metadata, bytes memory payload)
internal
virtual;
}
49 changes: 33 additions & 16 deletions solidity/contracts/isms/routing/DomainRoutingIsm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ pragma solidity >=0.8.0;

// ============ External Imports ============
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";

// ============ Internal Imports ============
import {AbstractRoutingIsm} from "./AbstractRoutingIsm.sol";
Expand All @@ -17,7 +16,7 @@ import {EnumerableMapExtended} from "../../libs/EnumerableMapExtended.sol";
/**
* @title DomainRoutingIsm
*/
contract DomainRoutingIsm is AbstractRoutingIsm, Ownable, Initializable {
contract DomainRoutingIsm is AbstractRoutingIsm, OwnableUpgradeable {
using EnumerableMapExtended for EnumerableMapExtended.UintToBytes32Map;
using Message for bytes;
using TypeCasts for bytes32;
Expand All @@ -29,6 +28,15 @@ contract DomainRoutingIsm is AbstractRoutingIsm, Ownable, Initializable {
EnumerableMapExtended.UintToBytes32Map internal _modules;

// ============ External Functions ============

/**
* @param _owner The owner of the contract.
*/
function initialize(address _owner) public initializer {
__Ownable_init();
_transferOwnership(_owner);
}

/**
* @notice Sets the ISMs to be used for the specified origin domains
* @param _owner The owner of the contract.
Expand All @@ -40,6 +48,7 @@ contract DomainRoutingIsm is AbstractRoutingIsm, Ownable, Initializable {
uint32[] calldata _domains,
IInterchainSecurityModule[] calldata __modules
) public initializer {
__Ownable_init();
require(_domains.length == __modules.length, "length mismatch");
uint256 _length = _domains.length;
for (uint256 i = 0; i < _length; ++i) {
Expand All @@ -53,10 +62,10 @@ contract DomainRoutingIsm is AbstractRoutingIsm, Ownable, Initializable {
* @param _domain The origin domain
* @param _module The ISM to use to verify messages
*/
function set(
uint32 _domain,
IInterchainSecurityModule _module
) external onlyOwner {
function set(uint32 _domain, IInterchainSecurityModule _module)
external
onlyOwner
{
_set(_domain, address(_module));
}

Expand All @@ -72,9 +81,12 @@ contract DomainRoutingIsm is AbstractRoutingIsm, Ownable, Initializable {
return _modules.keys();
}

function module(
uint32 origin
) public view virtual returns (IInterchainSecurityModule) {
function module(uint32 origin)
public
view
virtual
returns (IInterchainSecurityModule)
{
(bool contained, bytes32 _module) = _modules.tryGet(origin);
require(contained, _originNotFoundError(origin));
return IInterchainSecurityModule(_module.bytes32ToAddress());
Expand All @@ -87,9 +99,12 @@ contract DomainRoutingIsm is AbstractRoutingIsm, Ownable, Initializable {
* @param _message Formatted Hyperlane message (see Message.sol).
* @return module The ISM to use to verify _message
*/
function route(
bytes calldata _message
) public view override returns (IInterchainSecurityModule) {
function route(bytes calldata _message)
public
view
override
returns (IInterchainSecurityModule)
{
return module(_message.origin());
}

Expand All @@ -103,9 +118,11 @@ contract DomainRoutingIsm is AbstractRoutingIsm, Ownable, Initializable {
require(_modules.remove(_domain), _originNotFoundError(_domain));
}

function _originNotFoundError(
uint32 _origin
) internal pure returns (string memory) {
function _originNotFoundError(uint32 _origin)
internal
pure
returns (string memory)
{
return string.concat("No ISM found for origin: ", _origin.toString());
}

Expand Down
54 changes: 30 additions & 24 deletions solidity/contracts/middleware/InterchainAccountRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Ini
* @title A contract that allows accounts on chain A to call contracts via a
* proxy contract on chain B.
*/
contract InterchainAccountRouter is Router, Initializable {
contract InterchainAccountRouter is Router {
// ============ Libraries ============

using TypeCasts for address;
Expand Down Expand Up @@ -76,9 +76,7 @@ contract InterchainAccountRouter is Router, Initializable {

// ============ Constructor ============

constructor(address _mailbox) Router(_mailbox) {
_disableInitializers();
}
constructor(address _mailbox) Router(_mailbox) {}

// ============ Initializers ============

Expand All @@ -93,10 +91,11 @@ contract InterchainAccountRouter is Router, Initializable {
address _interchainSecurityModule,
address _owner
) external initializer {
_transferOwnership(msg.sender);
setHook(_interchainGasPaymaster);
setInterchainSecurityModule(_interchainSecurityModule);
transferOwnership(_owner);
_MailboxClient_initialize(
_interchainGasPaymaster,
_interchainSecurityModule,
_owner
);

implementation = address(new OwnableMulticall(address(this)));
// cannot be stored immutably because it is dynamically sized
Expand Down Expand Up @@ -181,10 +180,10 @@ contract InterchainAccountRouter is Router, Initializable {
* @param _calls The sequence of calls to make
* @return The Hyperlane message ID
*/
function callRemote(
uint32 _destination,
CallLib.Call[] calldata _calls
) external returns (bytes32) {
function callRemote(uint32 _destination, CallLib.Call[] calldata _calls)
external
returns (bytes32)
{
bytes32 _router = routers(_destination);
bytes32 _ism = isms[_destination];
return callRemoteWithOverrides(_destination, _router, _ism, _calls);
Expand Down Expand Up @@ -252,10 +251,11 @@ contract InterchainAccountRouter is Router, Initializable {
* @param _owner The local owner of the interchain account
* @return The remote address of the interchain account
*/
function getRemoteInterchainAccount(
uint32 _destination,
address _owner
) external view returns (address) {
function getRemoteInterchainAccount(uint32 _destination, address _owner)
external
view
returns (address)
{
address _router = routers(_destination).bytes32ToAddress();
address _ism = isms[_destination].bytes32ToAddress();
return getRemoteInterchainAccount(_owner, _router, _ism);
Expand Down Expand Up @@ -410,7 +410,11 @@ contract InterchainAccountRouter is Router, Initializable {
/**
* @dev Required for use of Router, compiler will not include this function in the bytecode
*/
function _handle(uint32, bytes32, bytes calldata) internal pure override {
function _handle(
uint32,
bytes32,
bytes calldata
) internal pure override {
assert(false);
}

Expand All @@ -420,10 +424,10 @@ contract InterchainAccountRouter is Router, Initializable {
* @param _address The address of the remote InterchainAccountRouter
* @dev Sets the default ISM to the zero address
*/
function _enrollRemoteRouter(
uint32 _destination,
bytes32 _address
) internal override {
function _enrollRemoteRouter(uint32 _destination, bytes32 _address)
internal
override
{
_enrollRemoteRouterAndIsm(_destination, _address, bytes32(0));
}

Expand Down Expand Up @@ -500,9 +504,11 @@ contract InterchainAccountRouter is Router, Initializable {
* @param _salt The CREATE2 salt used for deploying the interchain account
* @return The address of the interchain account
*/
function _getLocalInterchainAccount(
bytes32 _salt
) private view returns (address payable) {
function _getLocalInterchainAccount(bytes32 _salt)
private
view
returns (address payable)
{
return payable(Create2.computeAddress(_salt, bytecodeHash));
}
}
15 changes: 7 additions & 8 deletions solidity/contracts/middleware/InterchainQueryRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Ini
* @title Interchain Query Router that performs remote view calls on other chains and returns the result.
* @dev Currently does not support Sovereign Consensus (user specified Interchain Security Modules).
*/
contract InterchainQueryRouter is Router, Initializable {
contract InterchainQueryRouter is Router {
using TypeCasts for address;
using TypeCasts for bytes32;
using InterchainQueryMessage for bytes;
Expand All @@ -40,9 +40,7 @@ contract InterchainQueryRouter is Router, Initializable {
*/
event QueryResolved(uint32 indexed destination, address indexed sender);

constructor(address _mailbox) Router(_mailbox) {
_disableInitializers();
}
constructor(address _mailbox) Router(_mailbox) {}

/**
* @notice Initializes the Router contract with Hyperlane core contracts and the address of the interchain security module.
Expand All @@ -55,10 +53,11 @@ contract InterchainQueryRouter is Router, Initializable {
address _interchainSecurityModule,
address _owner
) external initializer {
_transferOwnership(msg.sender);
setHook(_interchainGasPaymaster);
setInterchainSecurityModule(_interchainSecurityModule);
transferOwnership(_owner);
_MailboxClient_initialize(
_interchainGasPaymaster,
_interchainSecurityModule,
_owner
);
}

/**
Expand Down
Loading

0 comments on commit 1a5cab3

Please sign in to comment.