-
Notifications
You must be signed in to change notification settings - Fork 1
/
L2CrossDomainMessenger.sol
58 lines (50 loc) · 2.61 KB
/
L2CrossDomainMessenger.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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import { AddressAliasHelper } from "src/vendor/AddressAliasHelper.sol";
import { Predeploys } from "src/libraries/Predeploys.sol";
import { CrossDomainMessenger } from "src/universal/CrossDomainMessenger.sol";
import { ISemver } from "src/universal/ISemver.sol";
import { L2ToL1MessagePasser } from "src/L2/L2ToL1MessagePasser.sol";
import { Constants } from "src/libraries/Constants.sol";
import { L1Block } from "src/L2/L1Block.sol";
import { Predeploys } from "src/libraries/Predeploys.sol";
/// @custom:proxied
/// @custom:predeploy 0x4200000000000000000000000000000000000007
/// @title L2CrossDomainMessenger
/// @notice The L2CrossDomainMessenger is a high-level interface for message passing between L1 and
/// L2 on the L2 side. Users are generally encouraged to use this contract instead of lower
/// level message passing contracts.
contract L2CrossDomainMessenger is CrossDomainMessenger, ISemver {
/// @custom:semver 2.1.0
string public constant version = "2.1.0";
/// @notice Constructs the L2CrossDomainMessenger contract.
constructor() CrossDomainMessenger() {
initialize({ _l1CrossDomainMessenger: CrossDomainMessenger(address(0)) });
}
/// @notice Initializer.
/// @param _l1CrossDomainMessenger L1CrossDomainMessenger contract on the other network.
function initialize(CrossDomainMessenger _l1CrossDomainMessenger) public initializer {
__CrossDomainMessenger_init({ _otherMessenger: _l1CrossDomainMessenger });
}
/// @notice Getter for the remote messenger.
/// Public getter is legacy and will be removed in the future. Use `otherMessenger()` instead.
/// @return L1CrossDomainMessenger contract.
/// @custom:legacy
function l1CrossDomainMessenger() public view returns (CrossDomainMessenger) {
return otherMessenger;
}
/// @inheritdoc CrossDomainMessenger
function _sendMessage(address _to, uint64 _gasLimit, uint256 _value, bytes memory _data) internal override {
L2ToL1MessagePasser(payable(Predeploys.L2_TO_L1_MESSAGE_PASSER)).initiateWithdrawal{ value: _value }(
_to, _gasLimit, _data
);
}
/// @inheritdoc CrossDomainMessenger
function _isOtherMessenger() internal view override returns (bool) {
return AddressAliasHelper.undoL1ToL2Alias(msg.sender) == address(otherMessenger);
}
/// @inheritdoc CrossDomainMessenger
function _isUnsafeTarget(address _target) internal view override returns (bool) {
return _target == address(this) || _target == address(Predeploys.L2_TO_L1_MESSAGE_PASSER);
}
}