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

     1  // SPDX-License-Identifier: MIT
     2  pragma solidity 0.8.15;
     3  
     4  import { ISemver } from "src/universal/ISemver.sol";
     5  
     6  /// @custom:proxied
     7  /// @custom:predeploy 0x4200000000000000000000000000000000000015
     8  /// @title L1Block
     9  /// @notice The L1Block predeploy gives users access to information about the last known L1 block.
    10  ///         Values within this contract are updated once per epoch (every L1 block) and can only be
    11  ///         set by the "depositor" account, a special system address. Depositor account transactions
    12  ///         are created by the protocol whenever we move to a new epoch.
    13  contract L1Block is ISemver {
    14      /// @notice Address of the special depositor account.
    15      address public constant DEPOSITOR_ACCOUNT = 0xDeaDDEaDDeAdDeAdDEAdDEaddeAddEAdDEAd0001;
    16  
    17      /// @notice The latest L1 block number known by the L2 system.
    18      uint64 public number;
    19  
    20      /// @notice The latest L1 timestamp known by the L2 system.
    21      uint64 public timestamp;
    22  
    23      /// @notice The latest L1 base fee.
    24      uint256 public basefee;
    25  
    26      /// @notice The latest L1 blockhash.
    27      bytes32 public hash;
    28  
    29      /// @notice The number of L2 blocks in the same epoch.
    30      uint64 public sequenceNumber;
    31  
    32      /// @notice The scalar value applied to the L1 blob base fee portion of the blob-capable L1 cost func.
    33      uint32 public blobBaseFeeScalar;
    34  
    35      /// @notice The scalar value applied to the L1 base fee portion of the blob-capable L1 cost func.
    36      uint32 public baseFeeScalar;
    37  
    38      /// @notice The versioned hash to authenticate the batcher by.
    39      bytes32 public batcherHash;
    40  
    41      /// @notice The overhead value applied to the L1 portion of the transaction fee.
    42      /// @custom:legacy
    43      uint256 public l1FeeOverhead;
    44  
    45      /// @notice The scalar value applied to the L1 portion of the transaction fee.
    46      /// @custom:legacy
    47      uint256 public l1FeeScalar;
    48  
    49      /// @notice The latest L1 blob base fee.
    50      uint256 public blobBaseFee;
    51  
    52      /// @custom:semver 1.2.0
    53      string public constant version = "1.2.0";
    54  
    55      /// @custom:legacy
    56      /// @notice Updates the L1 block values.
    57      /// @param _number         L1 blocknumber.
    58      /// @param _timestamp      L1 timestamp.
    59      /// @param _basefee        L1 basefee.
    60      /// @param _hash           L1 blockhash.
    61      /// @param _sequenceNumber Number of L2 blocks since epoch start.
    62      /// @param _batcherHash    Versioned hash to authenticate batcher by.
    63      /// @param _l1FeeOverhead  L1 fee overhead.
    64      /// @param _l1FeeScalar    L1 fee scalar.
    65      function setL1BlockValues(
    66          uint64 _number,
    67          uint64 _timestamp,
    68          uint256 _basefee,
    69          bytes32 _hash,
    70          uint64 _sequenceNumber,
    71          bytes32 _batcherHash,
    72          uint256 _l1FeeOverhead,
    73          uint256 _l1FeeScalar
    74      )
    75          external
    76      {
    77          require(msg.sender == DEPOSITOR_ACCOUNT, "L1Block: only the depositor account can set L1 block values");
    78  
    79          number = _number;
    80          timestamp = _timestamp;
    81          basefee = _basefee;
    82          hash = _hash;
    83          sequenceNumber = _sequenceNumber;
    84          batcherHash = _batcherHash;
    85          l1FeeOverhead = _l1FeeOverhead;
    86          l1FeeScalar = _l1FeeScalar;
    87      }
    88  
    89      /// @notice Updates the L1 block values for an Ecotone upgraded chain.
    90      /// Params are packed and passed in as raw msg.data instead of ABI to reduce calldata size.
    91      /// Params are expected to be in the following order:
    92      ///   1. _baseFeeScalar      L1 base fee scalar
    93      ///   2. _blobBaseFeeScalar  L1 blob base fee scalar
    94      ///   3. _sequenceNumber     Number of L2 blocks since epoch start.
    95      ///   4. _timestamp          L1 timestamp.
    96      ///   5. _number             L1 blocknumber.
    97      ///   6. _basefee            L1 base fee.
    98      ///   7. _blobBaseFee        L1 blob base fee.
    99      ///   8. _hash               L1 blockhash.
   100      ///   9. _batcherHash        Versioned hash to authenticate batcher by.
   101      function setL1BlockValuesEcotone() external {
   102          assembly {
   103              // Revert if the caller is not the depositor account.
   104              if xor(caller(), DEPOSITOR_ACCOUNT) {
   105                  mstore(0x00, 0x3cc50b45) // 0x3cc50b45 is the 4-byte selector of "NotDepositor()"
   106                  revert(0x1C, 0x04) // returns the stored 4-byte selector from above
   107              }
   108              let data := calldataload(4)
   109              // sequencenum (uint64), blobBaseFeeScalar (uint32), baseFeeScalar (uint32)
   110              sstore(sequenceNumber.slot, shr(128, calldataload(4)))
   111              // number (uint64) and timestamp (uint64)
   112              sstore(number.slot, shr(128, calldataload(20)))
   113              sstore(basefee.slot, calldataload(36)) // uint256
   114              sstore(blobBaseFee.slot, calldataload(68)) // uint256
   115              sstore(hash.slot, calldataload(100)) // bytes32
   116              sstore(batcherHash.slot, calldataload(132)) // bytes32
   117          }
   118      }
   119  }