github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/src/L2/CrossDomainOwnable2.sol (about)

     1  // SPDX-License-Identifier: MIT
     2  pragma solidity ^0.8.0;
     3  
     4  import { Predeploys } from "src/libraries/Predeploys.sol";
     5  import { L2CrossDomainMessenger } from "src/L2/L2CrossDomainMessenger.sol";
     6  import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
     7  
     8  /// @title CrossDomainOwnable2
     9  /// @notice This contract extends the OpenZeppelin `Ownable` contract for L2 contracts to be owned
    10  ///         by contracts on L1. Note that this contract is meant to be used with systems that use
    11  ///         the CrossDomainMessenger system. It will not work if the OptimismPortal is used
    12  ///         directly.
    13  abstract contract CrossDomainOwnable2 is Ownable {
    14      /// @notice Overrides the implementation of the `onlyOwner` modifier to check that the unaliased
    15      ///         `xDomainMessageSender` is the owner of the contract. This value is set to the caller
    16      ///         of the L1CrossDomainMessenger.
    17      function _checkOwner() internal view override {
    18          L2CrossDomainMessenger messenger = L2CrossDomainMessenger(Predeploys.L2_CROSS_DOMAIN_MESSENGER);
    19  
    20          require(msg.sender == address(messenger), "CrossDomainOwnable2: caller is not the messenger");
    21  
    22          require(owner() == messenger.xDomainMessageSender(), "CrossDomainOwnable2: caller is not the owner");
    23      }
    24  }