Commit caa68a1f authored by Mark Tyneway's avatar Mark Tyneway

op-chain-ops: handle proxy admin

parent b6fcc05f
......@@ -104,22 +104,26 @@ func NewDeployConfigWithNetwork(network, path string) (*DeployConfig, error) {
// NewL2ImmutableConfig will create an ImmutableConfig given an instance of a
// Hardhat and a DeployConfig.
func NewL2ImmutableConfig(config *DeployConfig, block *types.Block, proxyL1StandardBridge, proxyL1CrossDomainMessenger, proxyL1ERC721Bridge common.Address) (immutables.ImmutableConfig, error) {
func NewL2ImmutableConfig(config *DeployConfig, block *types.Block, l2Addrs *L2Addresses) (immutables.ImmutableConfig, error) {
immutable := make(immutables.ImmutableConfig)
if proxyL1ERC721Bridge == (common.Address{}) {
if l2Addrs == nil {
return immutable, errors.New("must pass L1 contract addresses")
}
if l2Addrs.ProxyL1ERC721Bridge == (common.Address{}) {
return immutable, errors.New("L1ERC721BridgeProxy cannot be address(0)")
}
immutable["L2StandardBridge"] = immutables.ImmutableValues{
"otherBridge": proxyL1StandardBridge,
"otherBridge": l2Addrs.L1StandardBridgeProxy,
}
immutable["L2CrossDomainMessenger"] = immutables.ImmutableValues{
"otherMessenger": proxyL1CrossDomainMessenger,
"otherMessenger": l2Addrs.L1CrossDomainMessengerProxy,
}
immutable["L2ERC721Bridge"] = immutables.ImmutableValues{
"messenger": predeploys.L2CrossDomainMessengerAddr,
"otherBridge": proxyL1ERC721Bridge,
"otherBridge": l2Addrs.ProxyL1ERC721Bridge,
}
immutable["OptimismMintableERC721Factory"] = immutables.ImmutableValues{
"bridge": predeploys.L2ERC721BridgeAddr,
......@@ -131,7 +135,7 @@ func NewL2ImmutableConfig(config *DeployConfig, block *types.Block, proxyL1Stand
// NewL2StorageConfig will create a StorageConfig given an instance of a
// Hardhat and a DeployConfig.
func NewL2StorageConfig(config *DeployConfig, block *types.Block, proxyL1StandardBridge common.Address, proxyL1CrossDomainMessenger common.Address) (state.StorageConfig, error) {
func NewL2StorageConfig(config *DeployConfig, block *types.Block, l2Addrs *L2Addresses) (state.StorageConfig, error) {
storage := make(state.StorageConfig)
if block.Number() == nil {
......@@ -140,6 +144,9 @@ func NewL2StorageConfig(config *DeployConfig, block *types.Block, proxyL1Standar
if block.BaseFee() == nil {
return storage, errors.New("block base fee not set")
}
if l2Addrs == nil {
return storage, errors.New("must pass L1 address info")
}
storage["L2ToL1MessagePasser"] = state.StorageValues{
"nonce": 0,
......@@ -188,8 +195,7 @@ func NewL2StorageConfig(config *DeployConfig, block *types.Block, proxyL1Standar
"_owner": common.Address{},
}
storage["ProxyAdmin"] = state.StorageValues{
// TODO: this needs to be configurable
"owner": common.Address{},
"owner": l2Addrs.ProxyAdmin,
}
return storage, nil
}
......@@ -9,6 +9,8 @@ import (
"github.com/ethereum/go-ethereum/core"
)
// L2Addresses represents L1 contract addresses
// that are required for the construction of an L2 state
type L2Addresses struct {
ProxyAdmin common.Address
L1StandardBridgeProxy common.Address
......@@ -31,6 +33,7 @@ func BuildL2DeveloperGenesis(config *DeployConfig, l1StartBlock *types.Block, l2
}
SetPrecompileBalances(db)
// Use the known developer addresses if they are not set
if l2Addrs == nil {
l2Addrs = &L2Addresses{
ProxyAdmin: predeploys.DevProxyAdminAddr,
......@@ -45,31 +48,16 @@ func BuildL2DeveloperGenesis(config *DeployConfig, l1StartBlock *types.Block, l2
// BuildL2Genesis will build the L2 Optimism Genesis Block
func BuildL2Genesis(db *state.MemoryStateDB, config *DeployConfig, l1Block *types.Block, l2Addrs *L2Addresses) (*core.Genesis, error) {
// TODO(tynes): need a function for clearing old, unused storage slots.
// Each deployed contract on L2 needs to have its existing storage
// inspected and then cleared if they are no longer used.
if err := SetL2Proxies(db, l2Addrs.ProxyAdmin); err != nil {
if err := SetL2Proxies(db); err != nil {
return nil, err
}
storage, err := NewL2StorageConfig(
config,
l1Block,
l2Addrs.L1StandardBridgeProxy,
l2Addrs.L1CrossDomainMessengerProxy,
)
storage, err := NewL2StorageConfig(config, l1Block, l2Addrs)
if err != nil {
return nil, err
}
immutable, err := NewL2ImmutableConfig(
config,
l1Block,
l2Addrs.L1StandardBridgeProxy,
l2Addrs.L1CrossDomainMessengerProxy,
l2Addrs.L1ERC721BridgeProxy,
)
immutable, err := NewL2ImmutableConfig(config, l1Block, l2Addrs)
if err != nil {
return nil, err
}
......
......@@ -25,8 +25,8 @@ func FundDevAccounts(db vm.StateDB) {
// a Proxy and ProxyAdmin deployment present so that the Proxy bytecode
// can be set in state and the ProxyAdmin can be set as the admin of the
// Proxy.
func SetL2Proxies(db vm.StateDB, proxyAdminAddr common.Address) error {
return setProxies(db, proxyAdminAddr, bigL2PredeployNamespace, 2048)
func SetL2Proxies(db vm.StateDB) error {
return setProxies(db, predeploys.ProxyAdminAddr, bigL2PredeployNamespace, 2048)
}
// SetL1Proxies will set each of the proxies in the state. It requires
......@@ -56,7 +56,7 @@ func setProxies(db vm.StateDB, proxyAdminAddr common.Address, namespace *big.Int
db.CreateAccount(addr)
db.SetCode(addr, depBytecode)
db.SetState(addr, AdminSlot, predeploys.ProxyAdminAddr.Hash())
db.SetState(addr, AdminSlot, proxyAdminAddr.Hash())
}
return nil
}
......@@ -71,7 +71,8 @@ func SetImplementations(db vm.StateDB, storage state.StorageConfig, immutable im
}
for name, address := range predeploys.Predeploys {
// Convert the address to the code address
// Convert the address to the code address unless it is
// designed to not be behind a proxy
var addr common.Address
switch *address {
case predeploys.GovernanceTokenAddr:
......
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