Skip to content

Commit

Permalink
fix(interfaces): add ISingleMessageExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
PierrickGT committed Nov 1, 2023
1 parent 0eac8e4 commit d744c25
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 36 deletions.
7 changes: 5 additions & 2 deletions src/ethereum-arbitrum/EthereumToArbitrumExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
pragma solidity ^0.8.16;

import { IMessageDispatcher } from "../interfaces/IMessageDispatcher.sol";
import { IBatchMessageExecutor, IMessageExecutor } from "../interfaces/extensions/IBatchMessageExecutor.sol";
import {
ISingleMessageExecutor,
IBatchMessageExecutor
} from "../interfaces/extensions/IBatchMessageExecutor.sol";
import { AddressAliasHelper } from "../libraries/AddressAliasHelper.sol";
import { MessageLib } from "../libraries/MessageLib.sol";

Expand All @@ -26,7 +29,7 @@ contract MessageExecutorArbitrum is IBatchMessageExecutor {

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

/// @inheritdoc IMessageExecutor
/// @inheritdoc ISingleMessageExecutor
function executeMessage(
address _to,
bytes calldata _data,
Expand Down
7 changes: 5 additions & 2 deletions src/ethereum-optimism/EthereumToOptimismExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ pragma solidity ^0.8.16;
import { ICrossDomainMessenger } from "../vendor/optimism/ICrossDomainMessenger.sol";

import { IMessageDispatcher } from "../interfaces/IMessageDispatcher.sol";
import { IBatchMessageExecutor, IMessageExecutor } from "../interfaces/extensions/IBatchMessageExecutor.sol";
import {
ISingleMessageExecutor,
IBatchMessageExecutor
} from "../interfaces/extensions/IBatchMessageExecutor.sol";
import { MessageLib } from "../libraries/MessageLib.sol";

/**
Expand Down Expand Up @@ -41,7 +44,7 @@ contract MessageExecutorOptimism is IBatchMessageExecutor {

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

/// @inheritdoc IMessageExecutor
/// @inheritdoc ISingleMessageExecutor
function executeMessage(
address _to,
bytes calldata _data,
Expand Down
23 changes: 2 additions & 21 deletions src/interfaces/IMessageExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pragma solidity ^0.8.16;

/**
* @title MessageExecutor interface
* @notice MessageExecutor interface of the ERC-5164 standard as defined in the EIP.
* @title ERC-5164: Cross-Chain Execution Standard
* @dev See https://eips.ethereum.org/EIPS/eip-5164
*/
interface IMessageExecutor {
/**
Expand All @@ -25,23 +25,4 @@ interface IMessageExecutor {
* @param messageId ID uniquely identifying the message that was executed
*/
event MessageIdExecuted(uint256 indexed fromChainId, bytes32 indexed messageId);

/**
* @notice Execute message from the origin chain.
* @dev Should authenticate that the call has been performed by the bridge transport layer.
* @dev Must revert if the message fails.
* @dev Must emit the `MessageIdExecuted` event once the message has been executed.
* @param to Address that will receive `data`
* @param data Data forwarded to address `to`
* @param messageId ID uniquely identifying the message
* @param fromChainId ID of the chain that dispatched the message
* @param from Address of the sender on the origin chain
*/
function executeMessage(
address to,
bytes calldata data,
bytes32 messageId,
uint256 fromChainId,
address from
) external;
}
7 changes: 3 additions & 4 deletions src/interfaces/extensions/IBatchMessageExecutor.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.16;

import { IMessageExecutor } from "../IMessageExecutor.sol";
import { IMessageExecutor, ISingleMessageExecutor } from "./ISingleMessageExecutor.sol";
import { MessageLib } from "../../libraries/MessageLib.sol";

/**
* @title BatchMessageExecutor interface
* @dev IMessageExecutor interface extended to support batch messaging.
* @notice BatchMessageExecutor interface of the ERC-5164 standard as defined in the EIP.
* @dev ISingleMessageExecutor interface extended to support batch messaging.
*/
interface IBatchMessageExecutor is IMessageExecutor {
interface IBatchMessageExecutor is ISingleMessageExecutor {
/**
* @notice Emitted if a call to a contract fails inside a batch of messages.
* @param messageId ID uniquely identifying the batch of messages
Expand Down
29 changes: 29 additions & 0 deletions src/interfaces/extensions/ISingleMessageExecutor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.16;

import { IMessageExecutor } from "../IMessageExecutor.sol";

/**
* @title SingleMessageExecutor interface
* @dev IMessageExecutor interface extended to execute a message.
*/
interface ISingleMessageExecutor is IMessageExecutor {
/**
* @notice Execute message from the origin chain.
* @dev Should authenticate that the call has been performed by the bridge transport layer.
* @dev Must revert if the message fails.
* @dev Must emit the `MessageIdExecuted` event once the message has been executed.
* @param to Address that will receive `data`
* @param data Data forwarded to address `to`
* @param messageId ID uniquely identifying the message
* @param fromChainId ID of the chain that dispatched the message
* @param from Address of the sender on the origin chain
*/
function executeMessage(
address to,
bytes calldata data,
bytes32 messageId,
uint256 fromChainId,
address from
) external;
}
11 changes: 9 additions & 2 deletions src/libraries/MessageLib.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.16;

import { IMessageExecutor, IBatchMessageExecutor } from "../interfaces/extensions/IBatchMessageExecutor.sol";
import {
IMessageExecutor,
ISingleMessageExecutor,
IBatchMessageExecutor
} from "../interfaces/extensions/IBatchMessageExecutor.sol";

/**
* @title MessageLib
Expand Down Expand Up @@ -70,7 +74,10 @@ library MessageLib {
address from
) internal pure returns (bytes memory) {
return
abi.encodeCall(IMessageExecutor.executeMessage, (to, data, messageId, fromChainId, from));
abi.encodeCall(
ISingleMessageExecutor.executeMessage,
(to, data, messageId, fromChainId, from)
);
}

/**
Expand Down
17 changes: 12 additions & 5 deletions test/fork/EthereumToOptimismFork.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ import { Test } from "forge-std/Test.sol";
import { ICrossDomainMessenger } from "../../src/vendor/optimism/ICrossDomainMessenger.sol";
import { AddressAliasHelper } from "../../src/libraries/AddressAliasHelper.sol";

import { IMessageExecutor, IBatchMessageExecutor } from "../../src/interfaces/extensions/IBatchMessageExecutor.sol";

import { MessageDispatcherOptimism } from "../../src/ethereum-optimism/EthereumToOptimismDispatcher.sol";
import { MessageExecutorOptimism } from "../../src/ethereum-optimism/EthereumToOptimismExecutor.sol";
import {
ISingleMessageExecutor,
IBatchMessageExecutor
} from "../../src/interfaces/extensions/IBatchMessageExecutor.sol";

import {
MessageDispatcherOptimism
} from "../../src/ethereum-optimism/EthereumToOptimismDispatcher.sol";
import {
MessageExecutorOptimism
} from "../../src/ethereum-optimism/EthereumToOptimismExecutor.sol";
import { MessageLib } from "../../src/libraries/MessageLib.sol";

import { Greeter } from "../contracts/Greeter.sol";
Expand Down Expand Up @@ -330,7 +337,7 @@ contract EthereumToOptimismForkTest is Test {
0,
defaultGasLimit,
abi.encodeCall(
IMessageExecutor.executeMessage,
ISingleMessageExecutor.executeMessage,
(_to, _data, _expectedMessageId, fromChainId, address(this))
)
);
Expand Down

0 comments on commit d744c25

Please sign in to comment.