Skip to content

Commit

Permalink
feat[contracts]: enable initiating L2 upgrade via L1 to L2 message (#887
Browse files Browse the repository at this point in the history
)

* feat[contracts]: enable initiating L2 upgrade via L1 to L2 message

* chore: add changeset
  • Loading branch information
smartcontracts authored May 17, 2021
1 parent 2f8ae44 commit 422e608
Show file tree
Hide file tree
Showing 7 changed files with 362 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/polite-wasps-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/contracts': patch
---

enables l2 upgrades to be initiated by an l1 to l2 message
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ contract L2ChugSplashDeployer is Ownable {
/***************
* Constructor *
***************/

/**
* @param _owner Address that will initially own the L2ChugSplashDeployer.
*/
Expand Down
114 changes: 114 additions & 0 deletions packages/contracts/contracts/chugsplash/L2ChugSplashOwner.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// SPDX-License-Identifier: MIT
pragma solidity >0.5.0 <0.8.0;

/* Library Imports */
import { OVM_CrossDomainEnabled } from "../optimistic-ethereum/libraries/bridge/OVM_CrossDomainEnabled.sol";

/**
* @title L2ChugSplashOwner
* @dev This contract will be the owner of the L2ChugSplashDeployer contract on deployed networks.
* By separating this from the L2ChugSplashDeployer, we can more easily test the core ChugSplash
* logic. It's effectively just a proxy to the L2ChugSplashDeployer.
*/
contract L2ChugSplashOwner is OVM_CrossDomainEnabled {

/**********
* Events *
**********/

event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);


/*************
* Variables *
*************/

address public owner;


/***************
* Constructor *
***************/

/**
* @param _owner Address that will initially own the L2ChugSplashOwner.
*/
constructor(
address _owner
)
public
OVM_CrossDomainEnabled(0x4200000000000000000000000000000000000007)
{
// Need to replicate the code from transferOwnership because transferOwnership can only be
// called via an L1 => L2 message.
require(
_owner != address(0),
"L2ChugSplashOwner: new owner is the zero address"
);

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


/********************
* Public Functions *
********************/

/**
* Leaves the contract without owner.
*/
function renounceOwnership()
public
onlyFromCrossDomainAccount(owner)
{
emit OwnershipTransferred(owner, address(0));
owner = address(0);
}

/**
* Transfers ownership to a new address.
* @param _newOwner Address of the new owner.
*/
function transferOwnership(
address _newOwner
)
public
onlyFromCrossDomainAccount(owner)
{
require(
_newOwner != address(0),
"L2ChugSplashOwner: new owner is the zero address"
);

emit OwnershipTransferred(owner, _newOwner);
owner = _newOwner;
}


/*********************
* Fallback Function *
*********************/

fallback()
external
onlyFromCrossDomainAccount(owner)
{
(bool success, bytes memory returndata) = address(
0x420000000000000000000000000000000000000D
).call(msg.data);

if (success) {
assembly {
return(add(returndata, 0x20), mload(returndata))
}
} else {
assembly {
revert(add(returndata, 0x20), mload(returndata))
}
}
}
}
5 changes: 5 additions & 0 deletions packages/contracts/src/contract-deployment/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Overrides } from '@ethersproject/contracts'

/* Internal Imports */
import { getContractFactory } from '../contract-defs'
import { predeploys } from '../predeploys'

export interface RollupDeployConfig {
deploymentSigner: Signer
Expand Down Expand Up @@ -260,6 +261,10 @@ export const makeContractDeployConfig = async (
),
},
L2ChugSplashDeployer: {
factory: getContractFactory('L2ChugSplashDeployer'),
params: [predeploys.L2ChugSplashOwner],
},
L2ChugSplashOwner: {
factory: getContractFactory('L2ChugSplashDeployer'),
params: [config.l2ChugSplashDeployerOwner],
},
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/src/contract-dumps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export const makeStateDump = async (cfg: RollupDeployConfig): Promise<any> => {
'OVM_ETH',
'OVM_ExecutionManagerWrapper',
'L2ChugSplashDeployer',
'L2ChugSplashOwner',
],
deployOverrides: {},
waitForReceipts: false,
Expand All @@ -173,6 +174,7 @@ export const makeStateDump = async (cfg: RollupDeployConfig): Promise<any> => {
'OVM_ProxyEOA',
'OVM_ExecutionManagerWrapper',
'L2ChugSplashDeployer',
'L2ChugSplashOwner',
]

const deploymentResult = await deploy(config)
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/src/predeploys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ export const predeploys = {
OVM_ProxyEOA: '0x4200000000000000000000000000000000000009',
OVM_ExecutionManagerWrapper: '0x420000000000000000000000000000000000000B',
L2ChugSplashDeployer: '0x420000000000000000000000000000000000000D',
L2ChugSplashOwner: '0x420000000000000000000000000000000000000E',
ERC1820Registry: '0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24',
}
Loading

0 comments on commit 422e608

Please sign in to comment.