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

4 5
import { Semver } from "../universal/Semver.sol";

6
/**
7 8 9 10 11 12 13 14 15
 * @custom:legacy
 * @custom:proxied
 * @custom:predeployed 0x4200000000000000000000000000000000000002
 * @title DeployerWhitelist
 * @notice DeployerWhitelist is a legacy contract that was originally used to act as a whitelist of
 *         addresses allowed to the Optimism network. The DeployerWhitelist has since been
 *         disabled, but the code is kept in state for the sake of full backwards compatibility.
 *         As of the Bedrock upgrade, the DeployerWhitelist is completely unused by the Optimism
 *         system and could, in theory, be removed entirely.
16
 */
17
contract DeployerWhitelist is Semver {
18 19 20 21 22 23 24 25 26 27 28
    /**
     * @notice Address of the owner of this contract. Note that when this address is set to
     *         address(0), the whitelist is disabled.
     */
    address public owner;

    /**
     * @notice Mapping of deployer addresses to boolean whitelist status.
     */
    mapping(address => bool) public whitelist;

29 30 31 32 33 34
    /**
     * @notice Emitted when the owner of this contract changes.
     *
     * @param oldOwner Address of the previous owner.
     * @param newOwner Address of the new owner.
     */
35
    event OwnerChanged(address oldOwner, address newOwner);
36 37 38 39 40 41 42

    /**
     * @notice Emitted when the whitelist status of a deployer changes.
     *
     * @param deployer    Address of the deployer.
     * @param whitelisted Boolean indicating whether the deployer is whitelisted.
     */
43 44
    event WhitelistStatusChanged(address deployer, bool whitelisted);

45 46 47 48 49 50
    /**
     * @notice Emitted when the whitelist is disabled.
     *
     * @param oldOwner Address of the final owner of the whitelist.
     */
    event WhitelistDisabled(address oldOwner);
51 52

    /**
53
     * @notice Blocks functions to anyone except the contract owner.
54 55
     */
    modifier onlyOwner() {
56 57 58 59
        require(
            msg.sender == owner,
            "DeployerWhitelist: function can only be called by the owner of this contract"
        );
60 61 62
        _;
    }

63 64 65 66 67
    /**
     * @custom:semver 0.0.1
     */
    constructor() Semver(0, 0, 1) {}

68
    /**
69 70 71
     * @notice Adds or removes an address from the deployment whitelist.
     *
     * @param _deployer      Address to update permissions for.
72 73 74 75 76 77 78 79
     * @param _isWhitelisted Whether or not the address is whitelisted.
     */
    function setWhitelistedDeployer(address _deployer, bool _isWhitelisted) external onlyOwner {
        whitelist[_deployer] = _isWhitelisted;
        emit WhitelistStatusChanged(_deployer, _isWhitelisted);
    }

    /**
80 81
     * @notice Updates the owner of this contract.
     *
82 83
     * @param _owner Address of the new owner.
     */
84
    function setOwner(address _owner) external onlyOwner {
85 86 87 88 89
        // Prevent users from setting the whitelist owner to address(0) except via
        // enableArbitraryContractDeployment. If you want to burn the whitelist owner, send it to
        // any other address that doesn't have a corresponding knowable private key.
        require(
            _owner != address(0),
90
            "DeployerWhitelist: can only be disabled via enableArbitraryContractDeployment"
91 92 93 94 95 96 97
        );

        emit OwnerChanged(owner, _owner);
        owner = _owner;
    }

    /**
98
     * @notice Permanently enables arbitrary contract deployment and deletes the owner.
99 100 101 102 103 104 105
     */
    function enableArbitraryContractDeployment() external onlyOwner {
        emit WhitelistDisabled(owner);
        owner = address(0);
    }

    /**
106 107
     * @notice Checks whether an address is allowed to deploy contracts.
     *
108
     * @param _deployer Address to check.
109 110
     *
     * @return Whether or not the address can deploy contracts.
111 112 113 114 115
     */
    function isDeployerAllowed(address _deployer) external view returns (bool) {
        return (owner == address(0) || whitelist[_deployer]);
    }
}