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
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;
}
}
......@@ -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;
......
......@@ -169,7 +169,7 @@ export const makeContractDeployConfig = async (
],
},
OVM_DeployerWhitelist: {
factory: getContractFactory('OVM_DeployerWhitelist'),
factory: getContractFactory('OVM_DeployerWhitelist', undefined, true),
params: [],
},
OVM_L1MessageSender: {
......
......@@ -166,6 +166,7 @@ export const makeStateDump = async (cfg: RollupDeployConfig): Promise<any> => {
'OVM_L2CrossDomainMessenger',
'OVM_SequencerEntrypoint',
'Lib_AddressManager',
'OVM_DeployerWhitelist',
'OVM_ETH',
'OVM_ECDSAContractAccount',
'OVM_ProxyEOA',
......
......@@ -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,
},
},
},
......
......@@ -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,
},
......
......@@ -75,14 +75,14 @@ export class ExecutionManagerTestRunner {
},
contractStorage: {
['0x4200000000000000000000000000000000000002']: {
'0x0000000000000000000000000000000000000000000000000000000000000010': getStorageXOR(
'0x0000000000000000000000000000000000000000000000000000000000000000': getStorageXOR(
ethers.constants.HashZero
),
},
},
verifiedContractStorage: {
['0x4200000000000000000000000000000000000002']: {
'0x0000000000000000000000000000000000000000000000000000000000000010': true,
'0x0000000000000000000000000000000000000000000000000000000000000000': true,
},
},
},
......@@ -218,8 +218,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
......
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