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