forked from pooltogether/ERC5164
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EthereumToArbitrumExecutor.sol
90 lines (72 loc) · 2.86 KB
/
EthereumToArbitrumExecutor.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.16;
import { AddressAliasHelper } from "@arbitrum/nitro-contracts/src/libraries/AddressAliasHelper.sol";
import "../interfaces/IMessageExecutor.sol";
import "../libraries/MessageLib.sol";
/**
* @title MessageExecutorArbitrum contract
* @notice The MessageExecutorArbitrum contract executes messages from the Ethereum chain.
* These messages are sent by the `MessageDispatcherArbitrum` contract which lives on the Ethereum chain.
*/
contract MessageExecutorArbitrum is IMessageExecutor {
/* ============ Variables ============ */
/// @notice Address of the dispatcher contract on the Ethereum chain.
IMessageDispatcher public dispatcher;
/**
* @notice ID uniquely identifying the messages that were executed.
* messageId => boolean
* @dev Ensure that messages cannot be replayed once they have been executed.
*/
mapping(bytes32 => bool) public executed;
/* ============ External Functions ============ */
/// @inheritdoc IMessageExecutor
function executeMessage(
address _to,
bytes calldata _data,
bytes32 _messageId,
uint256 _fromChainId,
address _from
) external {
IMessageDispatcher _dispatcher = dispatcher;
_isAuthorized(_dispatcher);
bool _executedMessageId = executed[_messageId];
executed[_messageId] = true;
MessageLib.executeMessage(_to, _data, _messageId, _fromChainId, _from, _executedMessageId);
emit MessageIdExecuted(_fromChainId, _messageId);
}
/// @inheritdoc IMessageExecutor
function executeMessageBatch(
MessageLib.Message[] calldata _messages,
bytes32 _messageId,
uint256 _fromChainId,
address _from
) external {
IMessageDispatcher _dispatcher = dispatcher;
_isAuthorized(_dispatcher);
bool _executedMessageId = executed[_messageId];
executed[_messageId] = true;
MessageLib.executeMessageBatch(_messages, _messageId, _fromChainId, _from, _executedMessageId);
emit MessageIdExecuted(_fromChainId, _messageId);
}
/**
* @notice Set dispatcher contract address.
* @dev Will revert if it has already been set.
* @param _dispatcher Address of the dispatcher contract on the Ethereum chain
*/
function setDispatcher(IMessageDispatcher _dispatcher) external {
require(address(dispatcher) == address(0), "Executor/dispatcher-already-set");
dispatcher = _dispatcher;
}
/* ============ Internal Functions ============ */
/**
* @notice Check that the message came from the `dispatcher` on the Ethereum chain.
* @dev We check that the sender is the L1 contract's L2 alias.
* @param _dispatcher Address of the dispatcher on the Ethereum chain
*/
function _isAuthorized(IMessageDispatcher _dispatcher) internal view {
require(
msg.sender == AddressAliasHelper.applyL1ToL2Alias(address(_dispatcher)),
"Executor/sender-unauthorized"
);
}
}