github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/src/L1/L1CrossDomainMessenger.sol (about) 1 // SPDX-License-Identifier: MIT 2 pragma solidity 0.8.15; 3 4 import { Predeploys } from "src/libraries/Predeploys.sol"; 5 import { OptimismPortal } from "src/L1/OptimismPortal.sol"; 6 import { CrossDomainMessenger } from "src/universal/CrossDomainMessenger.sol"; 7 import { ISemver } from "src/universal/ISemver.sol"; 8 import { SuperchainConfig } from "src/L1/SuperchainConfig.sol"; 9 10 /// @custom:proxied 11 /// @title L1CrossDomainMessenger 12 /// @notice The L1CrossDomainMessenger is a message passing interface between L1 and L2 responsible 13 /// for sending and receiving data on the L1 side. Users are encouraged to use this 14 /// interface instead of interacting with lower-level contracts directly. 15 contract L1CrossDomainMessenger is CrossDomainMessenger, ISemver { 16 /// @notice Contract of the SuperchainConfig. 17 SuperchainConfig public superchainConfig; 18 19 /// @notice Contract of the OptimismPortal. 20 /// @custom:network-specific 21 OptimismPortal public portal; 22 23 /// @notice Semantic version. 24 /// @custom:semver 2.3.0 25 string public constant version = "2.3.0"; 26 27 /// @notice Constructs the L1CrossDomainMessenger contract. 28 constructor() CrossDomainMessenger() { 29 initialize({ _superchainConfig: SuperchainConfig(address(0)), _portal: OptimismPortal(payable(address(0))) }); 30 } 31 32 /// @notice Initializes the contract. 33 /// @param _superchainConfig Contract of the SuperchainConfig contract on this network. 34 /// @param _portal Contract of the OptimismPortal contract on this network. 35 function initialize(SuperchainConfig _superchainConfig, OptimismPortal _portal) public initializer { 36 superchainConfig = _superchainConfig; 37 portal = _portal; 38 __CrossDomainMessenger_init({ _otherMessenger: CrossDomainMessenger(Predeploys.L2_CROSS_DOMAIN_MESSENGER) }); 39 } 40 41 /// @notice Getter function for the OptimismPortal contract on this chain. 42 /// Public getter is legacy and will be removed in the future. Use `portal()` instead. 43 /// @return Contract of the OptimismPortal on this chain. 44 /// @custom:legacy 45 function PORTAL() external view returns (OptimismPortal) { 46 return portal; 47 } 48 49 /// @inheritdoc CrossDomainMessenger 50 function _sendMessage(address _to, uint64 _gasLimit, uint256 _value, bytes memory _data) internal override { 51 portal.depositTransaction{ value: _value }({ 52 _to: _to, 53 _value: _value, 54 _gasLimit: _gasLimit, 55 _isCreation: false, 56 _data: _data 57 }); 58 } 59 60 /// @inheritdoc CrossDomainMessenger 61 function _isOtherMessenger() internal view override returns (bool) { 62 return msg.sender == address(portal) && portal.l2Sender() == address(otherMessenger); 63 } 64 65 /// @inheritdoc CrossDomainMessenger 66 function _isUnsafeTarget(address _target) internal view override returns (bool) { 67 return _target == address(this) || _target == address(portal); 68 } 69 70 /// @inheritdoc CrossDomainMessenger 71 function paused() public view override returns (bool) { 72 return superchainConfig.paused(); 73 } 74 }