Commit d4ee2d7d authored by smartcontracts's avatar smartcontracts Committed by GitHub

refactor[contracts]: Port OVM_DeployerWhitelist to use ovm-solc (#548)

* Port OVM_DeployerWhitelist to use ovm-solc

* chore[contracts]: Add changeset

* Update packages/contracts/contracts/optimistic-ethereum/OVM/predeploys/OVM_DeployerWhitelist.sol
Co-authored-by: default avatarMaurelian <maurelian@protonmail.ch>
Co-authored-by: default avatarMaurelian <maurelian@protonmail.ch>
parent ce5d5967
---
"@eth-optimism/contracts": patch
---
Port OVM_DeployerWhitelist to use optimistic-solc.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity >0.5.0 <0.8.0; pragma solidity >0.5.0 <0.8.0;
/* Library Imports */
import { Lib_Bytes32Utils } from "../../libraries/utils/Lib_Bytes32Utils.sol";
/* Interface Imports */ /* Interface Imports */
import { iOVM_DeployerWhitelist } from "../../iOVM/predeploys/iOVM_DeployerWhitelist.sol"; import { iOVM_DeployerWhitelist } from "../../iOVM/predeploys/iOVM_DeployerWhitelist.sol";
import { Lib_SafeExecutionManagerWrapper } from "../../libraries/wrappers/Lib_SafeExecutionManagerWrapper.sol";
/** /**
* @title OVM_DeployerWhitelist * @title OVM_DeployerWhitelist
...@@ -15,7 +11,7 @@ import { Lib_SafeExecutionManagerWrapper } from "../../libraries/wrappers/Lib_Sa ...@@ -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 * 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. * ovmCREATE or ovmCREATE2 operation to proceed if the deployer's address whitelisted.
* *
* Compiler used: solc * Compiler used: optimistic-solc
* Runtime target: OVM * Runtime target: OVM
*/ */
contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist { contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist {
...@@ -23,10 +19,11 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist { ...@@ -23,10 +19,11 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist {
/********************** /**********************
* Contract Constants * * Contract Constants *
**********************/ **********************/
bytes32 internal constant KEY_INITIALIZED = 0x0000000000000000000000000000000000000000000000000000000000000010; bool public initialized;
bytes32 internal constant KEY_OWNER = 0x0000000000000000000000000000000000000000000000000000000000000011; bool public allowArbitraryDeployment;
bytes32 internal constant KEY_ALLOW_ARBITRARY_DEPLOYMENT = 0x0000000000000000000000000000000000000000000000000000000000000012; address override public owner;
mapping (address => bool) public whitelist;
/********************** /**********************
...@@ -37,14 +34,8 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist { ...@@ -37,14 +34,8 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist {
* Blocks functions to anyone except the contract owner. * Blocks functions to anyone except the contract owner.
*/ */
modifier onlyOwner() { modifier onlyOwner() {
address owner = Lib_Bytes32Utils.toAddress( require(
Lib_SafeExecutionManagerWrapper.safeSLOAD( msg.sender == owner,
KEY_OWNER
)
);
Lib_SafeExecutionManagerWrapper.safeREQUIRE(
Lib_SafeExecutionManagerWrapper.safeCALLER() == owner,
"Function can only be called by the owner of this contract." "Function can only be called by the owner of this contract."
); );
_; _;
...@@ -67,43 +58,13 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist { ...@@ -67,43 +58,13 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist {
override override
public public
{ {
bool initialized = Lib_Bytes32Utils.toBool(
Lib_SafeExecutionManagerWrapper.safeSLOAD(KEY_INITIALIZED)
);
if (initialized == true) { if (initialized == true) {
return; return;
} }
Lib_SafeExecutionManagerWrapper.safeSSTORE( initialized = true;
KEY_INITIALIZED, allowArbitraryDeployment = _allowArbitraryDeployment;
Lib_Bytes32Utils.fromBool(true) owner = _owner;
);
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
)
);
} }
/** /**
...@@ -119,10 +80,7 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist { ...@@ -119,10 +80,7 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist {
public public
onlyOwner onlyOwner
{ {
Lib_SafeExecutionManagerWrapper.safeSSTORE( whitelist[_deployer] = _isWhitelisted;
Lib_Bytes32Utils.fromAddress(_deployer),
Lib_Bytes32Utils.fromBool(_isWhitelisted)
);
} }
/** /**
...@@ -136,10 +94,7 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist { ...@@ -136,10 +94,7 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist {
public public
onlyOwner onlyOwner
{ {
Lib_SafeExecutionManagerWrapper.safeSSTORE( owner = _owner;
KEY_OWNER,
Lib_Bytes32Utils.fromAddress(_owner)
);
} }
/** /**
...@@ -153,10 +108,7 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist { ...@@ -153,10 +108,7 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist {
public public
onlyOwner onlyOwner
{ {
Lib_SafeExecutionManagerWrapper.safeSSTORE( allowArbitraryDeployment = _allowArbitraryDeployment;
KEY_ALLOW_ARBITRARY_DEPLOYMENT,
Lib_Bytes32Utils.fromBool(_allowArbitraryDeployment)
);
} }
/** /**
...@@ -182,31 +134,13 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist { ...@@ -182,31 +134,13 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist {
override override
public public
returns ( returns (
bool _allowed bool
) )
{ {
bool initialized = Lib_Bytes32Utils.toBool( return (
Lib_SafeExecutionManagerWrapper.safeSLOAD(KEY_INITIALIZED) 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;
} }
} }
...@@ -11,7 +11,7 @@ interface iOVM_DeployerWhitelist { ...@@ -11,7 +11,7 @@ interface iOVM_DeployerWhitelist {
********************/ ********************/
function initialize(address _owner, bool _allowArbitraryDeployment) external; 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 setWhitelistedDeployer(address _deployer, bool _isWhitelisted) external;
function setOwner(address _newOwner) external; function setOwner(address _newOwner) external;
function setAllowArbitraryDeployment(bool _allowArbitraryDeployment) external; function setAllowArbitraryDeployment(bool _allowArbitraryDeployment) external;
......
...@@ -169,7 +169,7 @@ export const makeContractDeployConfig = async ( ...@@ -169,7 +169,7 @@ export const makeContractDeployConfig = async (
], ],
}, },
OVM_DeployerWhitelist: { OVM_DeployerWhitelist: {
factory: getContractFactory('OVM_DeployerWhitelist'), factory: getContractFactory('OVM_DeployerWhitelist', undefined, true),
params: [], params: [],
}, },
OVM_L1MessageSender: { OVM_L1MessageSender: {
......
...@@ -166,6 +166,7 @@ export const makeStateDump = async (cfg: RollupDeployConfig): Promise<any> => { ...@@ -166,6 +166,7 @@ export const makeStateDump = async (cfg: RollupDeployConfig): Promise<any> => {
'OVM_L2CrossDomainMessenger', 'OVM_L2CrossDomainMessenger',
'OVM_SequencerEntrypoint', 'OVM_SequencerEntrypoint',
'Lib_AddressManager', 'Lib_AddressManager',
'OVM_DeployerWhitelist',
'OVM_ETH', 'OVM_ETH',
'OVM_ECDSAContractAccount', 'OVM_ECDSAContractAccount',
'OVM_ProxyEOA', 'OVM_ProxyEOA',
......
...@@ -188,7 +188,7 @@ const test_nuisanceGas: TestDefinition = { ...@@ -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 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 // 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. // is less than the full OVM_TX_GAS_LIMIT / 2 which is alloted to the parent ovmCALL.
nuisanceGasLeft: 4184829, nuisanceGasLeft: 0x3f9e7f,
}, },
}, },
}, },
......
...@@ -24,14 +24,21 @@ const DUMMY_REVERT_DATA = ...@@ -24,14 +24,21 @@ const DUMMY_REVERT_DATA =
'0xdeadbeef1e5420deadbeef1e5420deadbeef1e5420deadbeef1e5420deadbeef1e5420' '0xdeadbeef1e5420deadbeef1e5420deadbeef1e5420deadbeef1e5420deadbeef1e5420'
const NON_WHITELISTED_DEPLOYER = '0x1234123412341234123412341234123412341234' const NON_WHITELISTED_DEPLOYER = '0x1234123412341234123412341234123412341234'
const NON_WHITELISTED_DEPLOYER_KEY = const NON_WHITELISTED_DEPLOYER_KEY = ethers.utils.keccak256(
'0x0000000000000000000000001234123412341234123412341234123412341234' '0x' +
'0000000000000000000000001234123412341234123412341234123412341234' +
'0000000000000000000000000000000000000000000000000000000000000001'
)
const CREATED_BY_NON_WHITELISTED_DEPLOYER = const CREATED_BY_NON_WHITELISTED_DEPLOYER =
'0x794e4aa3be128b0fc01ba12543b70bf9d77072fc' '0x794e4aa3be128b0fc01ba12543b70bf9d77072fc'
const WHITELISTED_DEPLOYER = '0x3456345634563456345634563456345634563456' const WHITELISTED_DEPLOYER = '0x3456345634563456345634563456345634563456'
const WHITELISTED_DEPLOYER_KEY = const WHITELISTED_DEPLOYER_KEY = ethers.utils.keccak256(
'0x0000000000000000000000003456345634563456345634563456345634563456' '0x' +
'0000000000000000000000003456345634563456345634563456345634563456' +
'0000000000000000000000000000000000000000000000000000000000000001'
)
const CREATED_BY_WHITELISTED_DEPLOYER = const CREATED_BY_WHITELISTED_DEPLOYER =
'0x9f397a91ccb7cc924d1585f1053bc697d30f343f' '0x9f397a91ccb7cc924d1585f1053bc697d30f343f'
...@@ -766,13 +773,9 @@ const test_ovmCREATE: TestDefinition = { ...@@ -766,13 +773,9 @@ const test_ovmCREATE: TestDefinition = {
}, },
contractStorage: { contractStorage: {
['0x4200000000000000000000000000000000000002']: { ['0x4200000000000000000000000000000000000002']: {
// initialized? true // initialized? true, allowArbitraryDeployment? false
'0x0000000000000000000000000000000000000000000000000000000000000010': getStorageXOR( '0x0000000000000000000000000000000000000000000000000000000000000000': getStorageXOR(
'0x' + '00'.repeat(31) + '01' '0x0000000000000000000000000000000000000000000000000000000000000001'
),
// allowArbitraryDeployment? false
'0x0000000000000000000000000000000000000000000000000000000000000012': getStorageXOR(
ethers.constants.HashZero
), ),
// non-whitelisted deployer is whitelisted? false // non-whitelisted deployer is whitelisted? false
[NON_WHITELISTED_DEPLOYER_KEY]: getStorageXOR( [NON_WHITELISTED_DEPLOYER_KEY]: getStorageXOR(
...@@ -786,8 +789,7 @@ const test_ovmCREATE: TestDefinition = { ...@@ -786,8 +789,7 @@ const test_ovmCREATE: TestDefinition = {
}, },
verifiedContractStorage: { verifiedContractStorage: {
['0x4200000000000000000000000000000000000002']: { ['0x4200000000000000000000000000000000000002']: {
'0x0000000000000000000000000000000000000000000000000000000000000010': 1, '0x0000000000000000000000000000000000000000000000000000000000000000': 1,
'0x0000000000000000000000000000000000000000000000000000000000000012': 1,
[NON_WHITELISTED_DEPLOYER_KEY]: 1, [NON_WHITELISTED_DEPLOYER_KEY]: 1,
[WHITELISTED_DEPLOYER_KEY]: 1, [WHITELISTED_DEPLOYER_KEY]: 1,
}, },
...@@ -901,13 +903,9 @@ const test_ovmCREATE: TestDefinition = { ...@@ -901,13 +903,9 @@ const test_ovmCREATE: TestDefinition = {
}, },
contractStorage: { contractStorage: {
['0x4200000000000000000000000000000000000002']: { ['0x4200000000000000000000000000000000000002']: {
// initialized? true // initialized? true, allowArbitraryDeployment? true
'0x0000000000000000000000000000000000000000000000000000000000000010': getStorageXOR( '0x0000000000000000000000000000000000000000000000000000000000000000': getStorageXOR(
'0x' + '00'.repeat(31) + '01' '0x0000000000000000000000000000000000000000000000000000000000000101'
),
// allowArbitraryDeployment? true
'0x0000000000000000000000000000000000000000000000000000000000000012': getStorageXOR(
'0x' + '00'.repeat(31) + '01'
), ),
// non-whitelisted deployer is whitelisted? false // non-whitelisted deployer is whitelisted? false
[NON_WHITELISTED_DEPLOYER_KEY]: getStorageXOR( [NON_WHITELISTED_DEPLOYER_KEY]: getStorageXOR(
...@@ -921,8 +919,7 @@ const test_ovmCREATE: TestDefinition = { ...@@ -921,8 +919,7 @@ const test_ovmCREATE: TestDefinition = {
}, },
verifiedContractStorage: { verifiedContractStorage: {
['0x4200000000000000000000000000000000000002']: { ['0x4200000000000000000000000000000000000002']: {
'0x0000000000000000000000000000000000000000000000000000000000000010': 1, '0x0000000000000000000000000000000000000000000000000000000000000000': 1,
'0x0000000000000000000000000000000000000000000000000000000000000012': 1,
[NON_WHITELISTED_DEPLOYER_KEY]: 1, [NON_WHITELISTED_DEPLOYER_KEY]: 1,
[WHITELISTED_DEPLOYER_KEY]: 1, [WHITELISTED_DEPLOYER_KEY]: 1,
}, },
......
...@@ -75,14 +75,14 @@ export class ExecutionManagerTestRunner { ...@@ -75,14 +75,14 @@ export class ExecutionManagerTestRunner {
}, },
contractStorage: { contractStorage: {
['0x4200000000000000000000000000000000000002']: { ['0x4200000000000000000000000000000000000002']: {
'0x0000000000000000000000000000000000000000000000000000000000000010': getStorageXOR( '0x0000000000000000000000000000000000000000000000000000000000000000': getStorageXOR(
ethers.constants.HashZero ethers.constants.HashZero
), ),
}, },
}, },
verifiedContractStorage: { verifiedContractStorage: {
['0x4200000000000000000000000000000000000002']: { ['0x4200000000000000000000000000000000000002']: {
'0x0000000000000000000000000000000000000000000000000000000000000010': true, '0x0000000000000000000000000000000000000000000000000000000000000000': true,
}, },
}, },
}, },
...@@ -218,8 +218,10 @@ export class ExecutionManagerTestRunner { ...@@ -218,8 +218,10 @@ export class ExecutionManagerTestRunner {
this.contracts.OVM_SafetyChecker.address this.contracts.OVM_SafetyChecker.address
) )
const DeployerWhitelist = await ( const DeployerWhitelist = await getContractFactory(
await ethers.getContractFactory('OVM_DeployerWhitelist') 'OVM_DeployerWhitelist',
AddressManager.signer,
true
).deploy() ).deploy()
this.contracts.OVM_DeployerWhitelist = DeployerWhitelist this.contracts.OVM_DeployerWhitelist = DeployerWhitelist
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment