diff --git a/.changeset/three-timers-behave.md b/.changeset/three-timers-behave.md new file mode 100644 index 0000000000000..f1571ec5e3354 --- /dev/null +++ b/.changeset/three-timers-behave.md @@ -0,0 +1,5 @@ +--- +"@eth-optimism/contracts": patch +--- + +Port OVM_DeployerWhitelist to use optimistic-solc. diff --git a/packages/contracts/contracts/optimistic-ethereum/OVM/predeploys/OVM_DeployerWhitelist.sol b/packages/contracts/contracts/optimistic-ethereum/OVM/predeploys/OVM_DeployerWhitelist.sol index 8b5189cfdaf2d..69bc8eef43c7d 100644 --- a/packages/contracts/contracts/optimistic-ethereum/OVM/predeploys/OVM_DeployerWhitelist.sol +++ b/packages/contracts/contracts/optimistic-ethereum/OVM/predeploys/OVM_DeployerWhitelist.sol @@ -1,12 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity >0.5.0 <0.8.0; -/* Library Imports */ -import { Lib_Bytes32Utils } from "../../libraries/utils/Lib_Bytes32Utils.sol"; - /* Interface Imports */ import { iOVM_DeployerWhitelist } from "../../iOVM/predeploys/iOVM_DeployerWhitelist.sol"; -import { Lib_SafeExecutionManagerWrapper } from "../../libraries/wrappers/Lib_SafeExecutionManagerWrapper.sol"; /** * @title OVM_DeployerWhitelist @@ -15,7 +11,7 @@ import { Lib_SafeExecutionManagerWrapper } from "../../libraries/wrappers/Lib_Sa * which are allowed to deploy contracts on Layer2. The Execution Manager will only allow an * ovmCREATE or ovmCREATE2 operation to proceed if the deployer's address whitelisted. * - * Compiler used: solc + * Compiler used: optimistic-solc * Runtime target: OVM */ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist { @@ -23,10 +19,11 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist { /********************** * Contract Constants * **********************/ - - bytes32 internal constant KEY_INITIALIZED = 0x0000000000000000000000000000000000000000000000000000000000000010; - bytes32 internal constant KEY_OWNER = 0x0000000000000000000000000000000000000000000000000000000000000011; - bytes32 internal constant KEY_ALLOW_ARBITRARY_DEPLOYMENT = 0x0000000000000000000000000000000000000000000000000000000000000012; + + bool public initialized; + bool public allowArbitraryDeployment; + address override public owner; + mapping (address => bool) public whitelist; /********************** @@ -37,14 +34,8 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist { * Blocks functions to anyone except the contract owner. */ modifier onlyOwner() { - address owner = Lib_Bytes32Utils.toAddress( - Lib_SafeExecutionManagerWrapper.safeSLOAD( - KEY_OWNER - ) - ); - - Lib_SafeExecutionManagerWrapper.safeREQUIRE( - Lib_SafeExecutionManagerWrapper.safeCALLER() == owner, + require( + msg.sender == owner, "Function can only be called by the owner of this contract." ); _; @@ -67,43 +58,13 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist { override public { - bool initialized = Lib_Bytes32Utils.toBool( - Lib_SafeExecutionManagerWrapper.safeSLOAD(KEY_INITIALIZED) - ); - if (initialized == true) { return; } - Lib_SafeExecutionManagerWrapper.safeSSTORE( - KEY_INITIALIZED, - Lib_Bytes32Utils.fromBool(true) - ); - Lib_SafeExecutionManagerWrapper.safeSSTORE( - KEY_OWNER, - Lib_Bytes32Utils.fromAddress(_owner) - ); - Lib_SafeExecutionManagerWrapper.safeSSTORE( - KEY_ALLOW_ARBITRARY_DEPLOYMENT, - Lib_Bytes32Utils.fromBool(_allowArbitraryDeployment) - ); - } - - /** - * Gets the owner of the whitelist. - */ - function getOwner() - override - public - returns( - address - ) - { - return Lib_Bytes32Utils.toAddress( - Lib_SafeExecutionManagerWrapper.safeSLOAD( - KEY_OWNER - ) - ); + initialized = true; + allowArbitraryDeployment = _allowArbitraryDeployment; + owner = _owner; } /** @@ -119,10 +80,7 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist { public onlyOwner { - Lib_SafeExecutionManagerWrapper.safeSSTORE( - Lib_Bytes32Utils.fromAddress(_deployer), - Lib_Bytes32Utils.fromBool(_isWhitelisted) - ); + whitelist[_deployer] = _isWhitelisted; } /** @@ -136,10 +94,7 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist { public onlyOwner { - Lib_SafeExecutionManagerWrapper.safeSSTORE( - KEY_OWNER, - Lib_Bytes32Utils.fromAddress(_owner) - ); + owner = _owner; } /** @@ -153,10 +108,7 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist { public onlyOwner { - Lib_SafeExecutionManagerWrapper.safeSSTORE( - KEY_ALLOW_ARBITRARY_DEPLOYMENT, - Lib_Bytes32Utils.fromBool(_allowArbitraryDeployment) - ); + allowArbitraryDeployment = _allowArbitraryDeployment; } /** @@ -182,31 +134,13 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist { override public returns ( - bool _allowed + bool ) { - bool initialized = Lib_Bytes32Utils.toBool( - Lib_SafeExecutionManagerWrapper.safeSLOAD(KEY_INITIALIZED) + return ( + initialized == false + || allowArbitraryDeployment == true + || whitelist[_deployer] ); - - if (initialized == false) { - return true; - } - - bool allowArbitraryDeployment = Lib_Bytes32Utils.toBool( - Lib_SafeExecutionManagerWrapper.safeSLOAD(KEY_ALLOW_ARBITRARY_DEPLOYMENT) - ); - - if (allowArbitraryDeployment == true) { - return true; - } - - bool isWhitelisted = Lib_Bytes32Utils.toBool( - Lib_SafeExecutionManagerWrapper.safeSLOAD( - Lib_Bytes32Utils.fromAddress(_deployer) - ) - ); - - return isWhitelisted; } } diff --git a/packages/contracts/contracts/optimistic-ethereum/iOVM/predeploys/iOVM_DeployerWhitelist.sol b/packages/contracts/contracts/optimistic-ethereum/iOVM/predeploys/iOVM_DeployerWhitelist.sol index 8274f6413eeb1..32d6e9fffe5dd 100644 --- a/packages/contracts/contracts/optimistic-ethereum/iOVM/predeploys/iOVM_DeployerWhitelist.sol +++ b/packages/contracts/contracts/optimistic-ethereum/iOVM/predeploys/iOVM_DeployerWhitelist.sol @@ -11,7 +11,7 @@ interface iOVM_DeployerWhitelist { ********************/ function initialize(address _owner, bool _allowArbitraryDeployment) external; - function getOwner() external returns (address _owner); + function owner() external returns (address _owner); function setWhitelistedDeployer(address _deployer, bool _isWhitelisted) external; function setOwner(address _newOwner) external; function setAllowArbitraryDeployment(bool _allowArbitraryDeployment) external; diff --git a/packages/contracts/src/contract-deployment/config.ts b/packages/contracts/src/contract-deployment/config.ts index db5c10b6b4d34..4461fa44a80fa 100644 --- a/packages/contracts/src/contract-deployment/config.ts +++ b/packages/contracts/src/contract-deployment/config.ts @@ -169,7 +169,7 @@ export const makeContractDeployConfig = async ( ], }, OVM_DeployerWhitelist: { - factory: getContractFactory('OVM_DeployerWhitelist'), + factory: getContractFactory('OVM_DeployerWhitelist', undefined, true), params: [], }, OVM_L1MessageSender: { diff --git a/packages/contracts/src/contract-dumps.ts b/packages/contracts/src/contract-dumps.ts index baffa384cffd9..9cc7786af56b9 100644 --- a/packages/contracts/src/contract-dumps.ts +++ b/packages/contracts/src/contract-dumps.ts @@ -166,6 +166,7 @@ export const makeStateDump = async (cfg: RollupDeployConfig): Promise => { 'OVM_L2CrossDomainMessenger', 'OVM_SequencerEntrypoint', 'Lib_AddressManager', + 'OVM_DeployerWhitelist', 'OVM_ETH', ] diff --git a/packages/contracts/test/contracts/OVM/execution/OVM_ExecutionManager/nuisance-gas.spec.ts b/packages/contracts/test/contracts/OVM/execution/OVM_ExecutionManager/nuisance-gas.spec.ts index 821ee3fd9b820..cfa5a449f38e5 100644 --- a/packages/contracts/test/contracts/OVM/execution/OVM_ExecutionManager/nuisance-gas.spec.ts +++ b/packages/contracts/test/contracts/OVM/execution/OVM_ExecutionManager/nuisance-gas.spec.ts @@ -188,7 +188,7 @@ const test_nuisanceGas: TestDefinition = { // This is because there is natural gas consumption between the ovmCALL(GAS/2) and ovmCREATE, which allots nuisance gas via _getNuisanceGasLimit. // This means that the ovmCREATE exception, DOES consumes all nuisance gas allotted, but that allotment // is less than the full OVM_TX_GAS_LIMIT / 2 which is alloted to the parent ovmCALL. - nuisanceGasLeft: 4184829, + nuisanceGasLeft: 0x3f9e7f, }, }, }, diff --git a/packages/contracts/test/contracts/OVM/execution/OVM_ExecutionManager/ovmCREATE.spec.ts b/packages/contracts/test/contracts/OVM/execution/OVM_ExecutionManager/ovmCREATE.spec.ts index 147fac7be9f0f..8281cd5516af3 100644 --- a/packages/contracts/test/contracts/OVM/execution/OVM_ExecutionManager/ovmCREATE.spec.ts +++ b/packages/contracts/test/contracts/OVM/execution/OVM_ExecutionManager/ovmCREATE.spec.ts @@ -24,14 +24,21 @@ const DUMMY_REVERT_DATA = '0xdeadbeef1e5420deadbeef1e5420deadbeef1e5420deadbeef1e5420deadbeef1e5420' const NON_WHITELISTED_DEPLOYER = '0x1234123412341234123412341234123412341234' -const NON_WHITELISTED_DEPLOYER_KEY = - '0x0000000000000000000000001234123412341234123412341234123412341234' +const NON_WHITELISTED_DEPLOYER_KEY = ethers.utils.keccak256( + '0x' + + '0000000000000000000000001234123412341234123412341234123412341234' + + '0000000000000000000000000000000000000000000000000000000000000001' +) const CREATED_BY_NON_WHITELISTED_DEPLOYER = '0x794e4aa3be128b0fc01ba12543b70bf9d77072fc' const WHITELISTED_DEPLOYER = '0x3456345634563456345634563456345634563456' -const WHITELISTED_DEPLOYER_KEY = - '0x0000000000000000000000003456345634563456345634563456345634563456' +const WHITELISTED_DEPLOYER_KEY = ethers.utils.keccak256( + '0x' + + '0000000000000000000000003456345634563456345634563456345634563456' + + '0000000000000000000000000000000000000000000000000000000000000001' +) + const CREATED_BY_WHITELISTED_DEPLOYER = '0x9f397a91ccb7cc924d1585f1053bc697d30f343f' @@ -766,13 +773,9 @@ const test_ovmCREATE: TestDefinition = { }, contractStorage: { ['0x4200000000000000000000000000000000000002']: { - // initialized? true - '0x0000000000000000000000000000000000000000000000000000000000000010': getStorageXOR( - '0x' + '00'.repeat(31) + '01' - ), - // allowArbitraryDeployment? false - '0x0000000000000000000000000000000000000000000000000000000000000012': getStorageXOR( - ethers.constants.HashZero + // initialized? true, allowArbitraryDeployment? false + '0x0000000000000000000000000000000000000000000000000000000000000000': getStorageXOR( + '0x0000000000000000000000000000000000000000000000000000000000000001' ), // non-whitelisted deployer is whitelisted? false [NON_WHITELISTED_DEPLOYER_KEY]: getStorageXOR( @@ -786,8 +789,7 @@ const test_ovmCREATE: TestDefinition = { }, verifiedContractStorage: { ['0x4200000000000000000000000000000000000002']: { - '0x0000000000000000000000000000000000000000000000000000000000000010': 1, - '0x0000000000000000000000000000000000000000000000000000000000000012': 1, + '0x0000000000000000000000000000000000000000000000000000000000000000': 1, [NON_WHITELISTED_DEPLOYER_KEY]: 1, [WHITELISTED_DEPLOYER_KEY]: 1, }, @@ -901,13 +903,9 @@ const test_ovmCREATE: TestDefinition = { }, contractStorage: { ['0x4200000000000000000000000000000000000002']: { - // initialized? true - '0x0000000000000000000000000000000000000000000000000000000000000010': getStorageXOR( - '0x' + '00'.repeat(31) + '01' - ), - // allowArbitraryDeployment? true - '0x0000000000000000000000000000000000000000000000000000000000000012': getStorageXOR( - '0x' + '00'.repeat(31) + '01' + // initialized? true, allowArbitraryDeployment? true + '0x0000000000000000000000000000000000000000000000000000000000000000': getStorageXOR( + '0x0000000000000000000000000000000000000000000000000000000000000101' ), // non-whitelisted deployer is whitelisted? false [NON_WHITELISTED_DEPLOYER_KEY]: getStorageXOR( @@ -921,8 +919,7 @@ const test_ovmCREATE: TestDefinition = { }, verifiedContractStorage: { ['0x4200000000000000000000000000000000000002']: { - '0x0000000000000000000000000000000000000000000000000000000000000010': 1, - '0x0000000000000000000000000000000000000000000000000000000000000012': 1, + '0x0000000000000000000000000000000000000000000000000000000000000000': 1, [NON_WHITELISTED_DEPLOYER_KEY]: 1, [WHITELISTED_DEPLOYER_KEY]: 1, }, diff --git a/packages/contracts/test/helpers/test-runner/test-runner.ts b/packages/contracts/test/helpers/test-runner/test-runner.ts index 91eb6f7e61ba0..8b46066aafa9b 100644 --- a/packages/contracts/test/helpers/test-runner/test-runner.ts +++ b/packages/contracts/test/helpers/test-runner/test-runner.ts @@ -37,6 +37,7 @@ import { } from '../constants' import { getStorageXOR } from '../' import { UNSAFE_BYTECODE } from '../dummy' +import { getContractFactory } from '../../../src' export class ExecutionManagerTestRunner { private snapshot: string @@ -68,14 +69,14 @@ export class ExecutionManagerTestRunner { }, contractStorage: { ['0x4200000000000000000000000000000000000002']: { - '0x0000000000000000000000000000000000000000000000000000000000000010': getStorageXOR( + '0x0000000000000000000000000000000000000000000000000000000000000000': getStorageXOR( ethers.constants.HashZero ), }, }, verifiedContractStorage: { ['0x4200000000000000000000000000000000000002']: { - '0x0000000000000000000000000000000000000000000000000000000000000010': true, + '0x0000000000000000000000000000000000000000000000000000000000000000': true, }, }, }, @@ -211,8 +212,10 @@ export class ExecutionManagerTestRunner { this.contracts.OVM_SafetyChecker.address ) - const DeployerWhitelist = await ( - await ethers.getContractFactory('OVM_DeployerWhitelist') + const DeployerWhitelist = await getContractFactory( + 'OVM_DeployerWhitelist', + AddressManager.signer, + true ).deploy() this.contracts.OVM_DeployerWhitelist = DeployerWhitelist