L1BlockNumber.sol 1.47 KB
Newer Older
1
// SPDX-License-Identifier: MIT
2
pragma solidity 0.8.15;
3

4
import { L1Block } from "../L2/L1Block.sol";
5
import { Predeploys } from "../libraries/Predeploys.sol";
6
import { Semver } from "../universal/Semver.sol";
7

8 9 10 11 12 13 14 15
/// @custom:legacy
/// @custom:proxied
/// @custom:predeploy 0x4200000000000000000000000000000000000013
/// @title L1BlockNumber
/// @notice L1BlockNumber is a legacy contract that fills the roll of the OVM_L1BlockNumber contract
///        in the old version of the Optimism system. Only necessary for backwards compatibility.
///        If you want to access the L1 block number going forward, you should use the L1Block
///        contract instead.
16
contract L1BlockNumber is Semver {
17 18
    /// @custom:semver 1.0.1
    constructor() Semver(1, 0, 1) {}
19

20
    /// @notice Returns the L1 block number.
21 22 23 24 25 26 27 28
    receive() external payable {
        uint256 l1BlockNumber = getL1BlockNumber();
        assembly {
            mstore(0, l1BlockNumber)
            return(0, 32)
        }
    }

29
    /// @notice Returns the L1 block number.
30
    // solhint-disable-next-line no-complex-fallback
31 32 33 34 35 36 37 38
    fallback() external payable {
        uint256 l1BlockNumber = getL1BlockNumber();
        assembly {
            mstore(0, l1BlockNumber)
            return(0, 32)
        }
    }

39 40
    /// @notice Retrieves the latest L1 block number.
    /// @return Latest L1 block number.
41
    function getL1BlockNumber() public view returns (uint256) {
42
        return L1Block(Predeploys.L1_BLOCK_ATTRIBUTES).number();
43 44
    }
}