-
Notifications
You must be signed in to change notification settings - Fork 6
/
ExecutorAware.sol
84 lines (70 loc) · 2.59 KB
/
ExecutorAware.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
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.16;
/**
* @title ExecutorAware abstract contract
* @notice The ExecutorAware contract allows contracts on a receiving chain to execute messages from an origin chain.
* These messages are sent by the `MessageDispatcher` contract which live on the origin chain.
* The `MessageExecutor` contract on the receiving chain executes these messages
* and then forward them to an ExecutorAware contract on the receiving chain.
* @dev This contract implements EIP-2771 (https://eips.ethereum.org/EIPS/eip-2771)
* to ensure that messages are sent by a trusted `MessageExecutor` contract.
*/
abstract contract ExecutorAware {
/* ============ Variables ============ */
/// @notice Address of the trusted executor contract.
address public immutable trustedExecutor;
/* ============ Constructor ============ */
/**
* @notice ExecutorAware constructor.
* @param _executor Address of the `MessageExecutor` contract
*/
constructor(address _executor) {
require(_executor != address(0), "executor-not-zero-address");
trustedExecutor = _executor;
}
/* ============ External Functions ============ */
/**
* @notice Check which executor this contract trust.
* @param _executor Address to check
*/
function isTrustedExecutor(address _executor) public view returns (bool) {
return _executor == trustedExecutor;
}
/* ============ Internal Functions ============ */
/**
* @notice Retrieve messageId from message data.
* @return _msgDataMessageId ID uniquely identifying the message that was executed
*/
function _messageId() internal pure returns (bytes32 _msgDataMessageId) {
_msgDataMessageId;
if (msg.data.length >= 84) {
assembly {
_msgDataMessageId := calldataload(sub(calldatasize(), 84))
}
}
}
/**
* @notice Retrieve fromChainId from message data.
* @return _msgDataFromChainId ID of the chain that dispatched the messages
*/
function _fromChainId() internal pure returns (uint256 _msgDataFromChainId) {
_msgDataFromChainId;
if (msg.data.length >= 52) {
assembly {
_msgDataFromChainId := calldataload(sub(calldatasize(), 52))
}
}
}
/**
* @notice Retrieve signer address from message data.
* @return _signer Address of the signer
*/
function _msgSender() internal view returns (address payable _signer) {
_signer = payable(msg.sender);
if (msg.data.length >= 20 && isTrustedExecutor(_signer)) {
assembly {
_signer := shr(96, calldataload(sub(calldatasize(), 20)))
}
}
}
}