Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/three-timers-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eth-optimism/contracts": patch
---

Port OVM_DeployerWhitelist to use optimistic-solc.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,18 +11,19 @@ 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 {

/**********************
* 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;


/**********************
Expand All @@ -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."
);
_;
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -136,10 +94,7 @@ contract OVM_DeployerWhitelist is iOVM_DeployerWhitelist {
public
onlyOwner
{
Lib_SafeExecutionManagerWrapper.safeSSTORE(
KEY_OWNER,
Lib_Bytes32Utils.fromAddress(_owner)
);
owner = _owner;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/contract-deployment/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export const makeContractDeployConfig = async (
],
},
OVM_DeployerWhitelist: {
factory: getContractFactory('OVM_DeployerWhitelist'),
factory: getContractFactory('OVM_DeployerWhitelist', undefined, true),
params: [],
},
OVM_L1MessageSender: {
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/src/contract-dumps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export const makeStateDump = async (cfg: RollupDeployConfig): Promise<any> => {
'OVM_L2CrossDomainMessenger',
'OVM_SequencerEntrypoint',
'Lib_AddressManager',
'OVM_DeployerWhitelist',
'OVM_ETH',
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming that this can't be easily done because it lives in smock right now, but this should really be a call to a utility function. Took me a sec to realize this was here to handle the new solidity storage layout.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, very true!

'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'

Expand Down Expand Up @@ -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(
Expand All @@ -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,
},
Expand Down Expand Up @@ -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(
Expand All @@ -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,
},
Expand Down
11 changes: 7 additions & 4 deletions packages/contracts/test/helpers/test-runner/test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,14 +69,14 @@ export class ExecutionManagerTestRunner {
},
contractStorage: {
['0x4200000000000000000000000000000000000002']: {
'0x0000000000000000000000000000000000000000000000000000000000000010': getStorageXOR(
'0x0000000000000000000000000000000000000000000000000000000000000000': getStorageXOR(
ethers.constants.HashZero
),
},
},
verifiedContractStorage: {
['0x4200000000000000000000000000000000000002']: {
'0x0000000000000000000000000000000000000000000000000000000000000010': true,
'0x0000000000000000000000000000000000000000000000000000000000000000': true,
},
},
},
Expand Down Expand Up @@ -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
Expand Down