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

     1  // SPDX-License-Identifier: MIT
     2  pragma solidity 0.8.15;
     3  
     4  import { L1Block } from "src/L2/L1Block.sol";
     5  import { Predeploys } from "src/libraries/Predeploys.sol";
     6  import { ISemver } from "src/universal/ISemver.sol";
     7  
     8  /// @custom:legacy
     9  /// @custom:proxied
    10  /// @custom:predeploy 0x4200000000000000000000000000000000000013
    11  /// @title L1BlockNumber
    12  /// @notice L1BlockNumber is a legacy contract that fills the roll of the OVM_L1BlockNumber contract
    13  ///        in the old version of the Optimism system. Only necessary for backwards compatibility.
    14  ///        If you want to access the L1 block number going forward, you should use the L1Block
    15  ///        contract instead.
    16  contract L1BlockNumber is ISemver {
    17      /// @notice Semantic version.
    18      /// @custom:semver 1.1.0
    19      string public constant version = "1.1.0";
    20  
    21      /// @notice Returns the L1 block number.
    22      receive() external payable {
    23          uint256 l1BlockNumber = getL1BlockNumber();
    24          assembly {
    25              mstore(0, l1BlockNumber)
    26              return(0, 32)
    27          }
    28      }
    29  
    30      /// @notice Returns the L1 block number.
    31      fallback() external payable {
    32          uint256 l1BlockNumber = getL1BlockNumber();
    33          assembly {
    34              mstore(0, l1BlockNumber)
    35              return(0, 32)
    36          }
    37      }
    38  
    39      /// @notice Retrieves the latest L1 block number.
    40      /// @return Latest L1 block number.
    41      function getL1BlockNumber() public view returns (uint256) {
    42          return L1Block(Predeploys.L1_BLOCK_ATTRIBUTES).number();
    43      }
    44  }