diff --git a/src/ethereum-arbitrum/EthereumToArbitrumDispatcher.sol b/src/ethereum-arbitrum/EthereumToArbitrumDispatcher.sol index ad7662d..5e49769 100644 --- a/src/ethereum-arbitrum/EthereumToArbitrumDispatcher.sol +++ b/src/ethereum-arbitrum/EthereumToArbitrumDispatcher.sol @@ -178,7 +178,7 @@ contract MessageDispatcherArbitrum is IMessageDispatcherArbitrum { /** * @inheritdoc IMessageDispatcherArbitrum - * @dev `msg.sender` is passed as `_callValueRefundAddress` cause this address can cancel the retryable ticket. + * @dev `_refundAddress` is passed as `_callValueRefundAddress`, this address can cancel the retryable ticket. * @dev We store `_message` in memory to avoid a stack too deep error. */ function dispatchAndProcessMessage( @@ -189,16 +189,16 @@ contract MessageDispatcherArbitrum is IMessageDispatcherArbitrum { uint256 _gasLimit, uint256 _maxSubmissionCost, uint256 _gasPriceBid - ) external payable returns (uint256 ticketId) { + ) external payable returns (bytes32 messageId, uint256 ticketId) { address _executorAddress = address(executor); _checkProcessParams(_executorAddress, _refundAddress); _checkToChainId(_toChainId); - bytes32 _messageId = _computeMessageId(msg.sender, _to, _data); + messageId = _computeMessageId(msg.sender, _to, _data); bytes memory _message = MessageLib.encodeMessage( _to, _data, - _messageId, + messageId, block.chainid, msg.sender ); @@ -207,19 +207,19 @@ contract MessageDispatcherArbitrum is IMessageDispatcherArbitrum { _executorAddress, _maxSubmissionCost, _refundAddress, - msg.sender, + _refundAddress, _gasLimit, _gasPriceBid, _message ); - emit MessageDispatched(_messageId, msg.sender, _toChainId, _to, _data); - emit MessageProcessed(_messageId, msg.sender, ticketId); + emit MessageDispatched(messageId, msg.sender, _toChainId, _to, _data); + emit MessageProcessed(messageId, msg.sender, ticketId); } /** * @inheritdoc IMessageDispatcherArbitrum - * @dev `msg.sender` is passed as `_callValueRefundAddress` cause this address can cancel the retryable ticket. + * @dev `_refundAddress` is passed as `_callValueRefundAddress`, this address can cancel the retryable ticket. * @dev We store `_messageBatch` in memory to avoid a stack too deep error. */ function dispatchAndProcessMessageBatch( @@ -229,15 +229,15 @@ contract MessageDispatcherArbitrum is IMessageDispatcherArbitrum { uint256 _gasLimit, uint256 _maxSubmissionCost, uint256 _gasPriceBid - ) external payable returns (uint256 ticketId) { + ) external payable returns (bytes32 messageId, uint256 ticketId) { address _executorAddress = address(executor); _checkProcessParams(_executorAddress, _refundAddress); _checkToChainId(_toChainId); - bytes32 _messageId = _computeMessageBatchId(msg.sender, _messages); + messageId = _computeMessageBatchId(msg.sender, _messages); bytes memory _messageBatch = MessageLib.encodeMessageBatch( _messages, - _messageId, + messageId, block.chainid, msg.sender ); @@ -246,14 +246,14 @@ contract MessageDispatcherArbitrum is IMessageDispatcherArbitrum { _executorAddress, _maxSubmissionCost, _refundAddress, - msg.sender, + _refundAddress, _gasLimit, _gasPriceBid, _messageBatch ); - emit MessageBatchDispatched(_messageId, msg.sender, _toChainId, _messages); - emit MessageBatchProcessed(_messageId, msg.sender, ticketId); + emit MessageBatchDispatched(messageId, msg.sender, _toChainId, _messages); + emit MessageBatchProcessed(messageId, msg.sender, ticketId); } /** diff --git a/src/interfaces/extensions/IMessageDispatcherArbitrum.sol b/src/interfaces/extensions/IMessageDispatcherArbitrum.sol index ac77da4..13f944d 100644 --- a/src/interfaces/extensions/IMessageDispatcherArbitrum.sol +++ b/src/interfaces/extensions/IMessageDispatcherArbitrum.sol @@ -98,6 +98,7 @@ interface IMessageDispatcherArbitrum is IBatchMessageDispatcher { * @param gasLimit Maximum amount of gas required for the message to be executed * @param maxSubmissionCost Max gas deducted from user's L2 balance to cover base submission fee * @param gasPriceBid Gas price bid for L2 execution + * @return messageId ID uniquely identifying the message * @return ticketId ID of the retryable ticket that was created */ function dispatchAndProcessMessage( @@ -108,7 +109,7 @@ interface IMessageDispatcherArbitrum is IBatchMessageDispatcher { uint256 gasLimit, uint256 maxSubmissionCost, uint256 gasPriceBid - ) external payable returns (uint256 ticketId); + ) external payable returns (bytes32 messageId, uint256 ticketId); /** * @notice Dispatch and process a batch of messages in one transaction. @@ -120,6 +121,7 @@ interface IMessageDispatcherArbitrum is IBatchMessageDispatcher { * @param gasLimit Maximum amount of gas required for the message to be executed * @param maxSubmissionCost Max gas deducted from user's L2 balance to cover base submission fee * @param gasPriceBid Gas price bid for L2 execution + * @return messageId ID uniquely identifying the message * @return ticketId ID of the retryable ticket that was created */ function dispatchAndProcessMessageBatch( @@ -129,7 +131,7 @@ interface IMessageDispatcherArbitrum is IBatchMessageDispatcher { uint256 gasLimit, uint256 maxSubmissionCost, uint256 gasPriceBid - ) external payable returns (uint256 ticketId); + ) external payable returns (bytes32 messageId, uint256 ticketId); /** * @notice Get transaction hash for a single message. diff --git a/test/unit/ethereum-arbitrum/EthereumToArbitrumDispatcher.t.sol b/test/unit/ethereum-arbitrum/EthereumToArbitrumDispatcher.t.sol index 4b3ae8c..731575f 100644 --- a/test/unit/ethereum-arbitrum/EthereumToArbitrumDispatcher.t.sol +++ b/test/unit/ethereum-arbitrum/EthereumToArbitrumDispatcher.t.sol @@ -5,8 +5,12 @@ import { Test } from "forge-std/Test.sol"; import { IInbox } from "@arbitrum/nitro-contracts/src/bridge/IInbox.sol"; -import { MessageDispatcherArbitrum } from "../../../src/ethereum-arbitrum/EthereumToArbitrumDispatcher.sol"; -import { MessageExecutorArbitrum } from "../../../src/ethereum-arbitrum/EthereumToArbitrumExecutor.sol"; +import { + MessageDispatcherArbitrum +} from "../../../src/ethereum-arbitrum/EthereumToArbitrumDispatcher.sol"; +import { + MessageExecutorArbitrum +} from "../../../src/ethereum-arbitrum/EthereumToArbitrumExecutor.sol"; import { MessageLib } from "../../../src/libraries/MessageLib.sol"; import { Greeter } from "../../contracts/Greeter.sol"; @@ -249,7 +253,7 @@ contract MessageDispatcherArbitrumUnitTest is Test { vm.expectEmit(true, true, true, true, address(dispatcher)); emit MessageProcessed(_expectedMessageId, address(this), _randomNumber); - uint256 _ticketId = dispatcher.dispatchAndProcessMessage( + (bytes32 _messageId, uint256 _ticketId) = dispatcher.dispatchAndProcessMessage( toChainId, _message.to, _message.data, @@ -259,6 +263,7 @@ contract MessageDispatcherArbitrumUnitTest is Test { gasPriceBid ); + assertEq(_messageId, _expectedMessageId); assertEq(_ticketId, _randomNumber); } @@ -266,7 +271,6 @@ contract MessageDispatcherArbitrumUnitTest is Test { setExecutor(); bytes32 _expectedMessageId = MessageLib.computeMessageBatchId(nonce, address(this), messages); - uint256 _randomNumber = inbox.generateRandomNumber(); vm.expectEmit(true, true, true, true, address(dispatcher)); @@ -275,7 +279,7 @@ contract MessageDispatcherArbitrumUnitTest is Test { vm.expectEmit(true, true, true, true, address(dispatcher)); emit MessageBatchProcessed(_expectedMessageId, address(this), _randomNumber); - uint256 _ticketId = dispatcher.dispatchAndProcessMessageBatch( + (bytes32 _messageId, uint256 _ticketId) = dispatcher.dispatchAndProcessMessageBatch( toChainId, messages, msg.sender, @@ -284,6 +288,7 @@ contract MessageDispatcherArbitrumUnitTest is Test { gasPriceBid ); + assertEq(_messageId, _expectedMessageId); assertEq(_ticketId, _randomNumber); }