Skip to content

Commit

Permalink
registry address list (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamdiallam authored Jul 26, 2024
1 parent 2be154a commit e740f57
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 66 deletions.
14 changes: 7 additions & 7 deletions config/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"strings"

"github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
registry "github.com/ethereum-optimism/superchain-registry/superchain"
"github.com/ethereum-optimism/supersim/genesisdeployment"
"github.com/ethereum-optimism/supersim/hdaccount"

Expand Down Expand Up @@ -35,8 +35,8 @@ var (
SecretsConfig: DefaultSecretsConfig,
GenesisJSON: genesisdeployment.GeneratedGenesisDeployment.L2s[0].GenesisJSON,
L2Config: &L2Config{
L1ChainID: genesisdeployment.GeneratedGenesisDeployment.L1.ChainID,
L1DeploymentAddresses: genesisdeployment.GeneratedGenesisDeployment.L2s[0].L1DeploymentAddresses,
L1ChainID: genesisdeployment.GeneratedGenesisDeployment.L1.ChainID,
L1Addresses: genesisdeployment.GeneratedGenesisDeployment.L2s[0].RegistryAddressList(),
},
},
{
Expand All @@ -45,8 +45,8 @@ var (
SecretsConfig: DefaultSecretsConfig,
GenesisJSON: genesisdeployment.GeneratedGenesisDeployment.L2s[1].GenesisJSON,
L2Config: &L2Config{
L1ChainID: genesisdeployment.GeneratedGenesisDeployment.L1.ChainID,
L1DeploymentAddresses: genesisdeployment.GeneratedGenesisDeployment.L2s[1].L1DeploymentAddresses,
L1ChainID: genesisdeployment.GeneratedGenesisDeployment.L1.ChainID,
L1Addresses: genesisdeployment.GeneratedGenesisDeployment.L2s[1].RegistryAddressList(),
},
},
}
Expand All @@ -64,8 +64,8 @@ type SecretsConfig struct {
}

type L2Config struct {
L1ChainID uint64
L1DeploymentAddresses *genesis.L1Deployments
L1ChainID uint64
L1Addresses *registry.AddressList
}

type ChainConfig struct {
Expand Down
59 changes: 40 additions & 19 deletions genesisdeployment/genesisdeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"

"github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
registry "github.com/ethereum-optimism/superchain-registry/superchain"
)

/*******************
Expand Down Expand Up @@ -50,6 +51,25 @@ var addresses904JSON []byte
//go:embed generated/addresses/905-addresses.json
var addresses905JSON []byte

var GeneratedGenesisDeployment = &GenesisDeployment{
L1: &L1GenesisDeployment{
ChainID: 900,
GenesisJSON: l1GenesisJSON,
},
L2s: []*L2GenesisDeployment{
newL2GenesisDeployment(901, addresses901JSON, l2Genesis901JSON),
newL2GenesisDeployment(902, addresses902JSON, l2Genesis902JSON),
newL2GenesisDeployment(903, addresses903JSON, l2Genesis903JSON),
newL2GenesisDeployment(904, addresses904JSON, l2Genesis904JSON),
newL2GenesisDeployment(905, addresses905JSON, l2Genesis905JSON),
},
}

type GenesisDeployment struct {
L1 *L1GenesisDeployment
L2s []*L2GenesisDeployment
}

type L1GenesisDeployment struct {
ChainID uint64
GenesisJSON []byte
Expand All @@ -61,6 +81,26 @@ type L2GenesisDeployment struct {
L1DeploymentAddresses *genesis.L1Deployments
}

// Unassigned contracts -- Fault Proof, Plasma, SuperchainConfig, Roles
//
// NOTE: We use the superchain registry AddressList as the canonical format for superchain
// addresses. Any experimental contracts will be managed externally from this list. The registry
// and op-chain-ops L1Deployments type will be consolidated in the future as well.
// - See: https://github.com/ethereum-optimism/optimism/blob/5be91416a3d017d3f8648140b3c41189b234ff6e/op-chain-ops/genesis/config.go#L693
func (d *L2GenesisDeployment) RegistryAddressList() *registry.AddressList {
return &registry.AddressList{
AddressManager: registry.Address(d.L1DeploymentAddresses.AddressManager),
L1CrossDomainMessengerProxy: registry.Address(d.L1DeploymentAddresses.L1CrossDomainMessengerProxy),
L1ERC721BridgeProxy: registry.Address(d.L1DeploymentAddresses.L1ERC721BridgeProxy),
L1StandardBridgeProxy: registry.Address(d.L1DeploymentAddresses.L1StandardBridgeProxy),
L2OutputOracleProxy: registry.Address(d.L1DeploymentAddresses.L2OutputOracleProxy),
OptimismMintableERC20FactoryProxy: registry.Address(d.L1DeploymentAddresses.OptimismMintableERC20FactoryProxy),
OptimismPortalProxy: registry.Address(d.L1DeploymentAddresses.OptimismPortalProxy),
SystemConfigProxy: registry.Address(d.L1DeploymentAddresses.SystemConfigProxy),
ProxyAdmin: registry.Address(d.L1DeploymentAddresses.ProxyAdmin),
}
}

func newL2GenesisDeployment(l2ChainID uint64, l1DeploymentAddressesJSON []byte, l2GenesisJSON []byte) *L2GenesisDeployment {
var l1DeploymentAddresses genesis.L1Deployments
if err := json.Unmarshal(l1DeploymentAddressesJSON, &l1DeploymentAddresses); err != nil {
Expand All @@ -73,22 +113,3 @@ func newL2GenesisDeployment(l2ChainID uint64, l1DeploymentAddressesJSON []byte,
GenesisJSON: l2GenesisJSON,
}
}

type GenesisDeployment struct {
L1 *L1GenesisDeployment
L2s []*L2GenesisDeployment
}

var GeneratedGenesisDeployment = &GenesisDeployment{
L1: &L1GenesisDeployment{
ChainID: 900,
GenesisJSON: l1GenesisJSON,
},
L2s: []*L2GenesisDeployment{
newL2GenesisDeployment(901, addresses901JSON, l2Genesis901JSON),
newL2GenesisDeployment(902, addresses902JSON, l2Genesis902JSON),
newL2GenesisDeployment(903, addresses903JSON, l2Genesis903JSON),
newL2GenesisDeployment(904, addresses904JSON, l2Genesis904JSON),
newL2GenesisDeployment(905, addresses905JSON, l2Genesis905JSON),
},
}
39 changes: 2 additions & 37 deletions orchestrator/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import (
"fmt"
"math/big"

"github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
registry "github.com/ethereum-optimism/superchain-registry/superchain"
"github.com/ethereum-optimism/supersim/config"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
)
Expand Down Expand Up @@ -49,7 +47,6 @@ func ChainConfigsFromForkCLIConfig(forkConfig *config.ForkCLIConfig) ([]config.C
// L2s
for _, chain := range forkConfig.Chains {
chainCfg := registry.OPChains[config.OpChainToId[chain]]
addressList := registry.Addresses[config.OpChainToId[chain]]
l2ForkHeight, err := latestL2HeightFromL1Header(chainCfg, l1Header)
if err != nil {
return nil, fmt.Errorf("failed to find right l2 height: %w", err)
Expand All @@ -66,8 +63,8 @@ func ChainConfigsFromForkCLIConfig(forkConfig *config.ForkCLIConfig) ([]config.C
},

L2Config: &config.L2Config{
L1ChainID: superchain.Config.L1.ChainID,
L1DeploymentAddresses: addressListToL1Deployments(addressList),
L1ChainID: superchain.Config.L1.ChainID,
L1Addresses: registry.Addresses[chainCfg.ChainID],
},
})
}
Expand Down Expand Up @@ -103,35 +100,3 @@ func latestL2HeightFromL1Header(l2Cfg *registry.ChainConfig, l1Header *types.Hea

return blockNum, nil
}

// This is temporarily needed until the the L1Deployments type is consolidated.
// see comment on https://github.com/ethereum-optimism/optimism/blob/5be91416a3d017d3f8648140b3c41189b234ff6e/op-chain-ops/genesis/config.go#L693
// Notes: Will add all fields later. For now, only setting the proxy addresses that are used / easily accessible in the registry
// - Skipping setting implementation contracts since those are not used in our code
// - Using L1Deployments instead of AddressList in supersim since the superchain registry one is still being updated
// - Once the types are consolidated, we will use AddressList directly
func addressListToL1Deployments(a *registry.AddressList) *genesis.L1Deployments {
return &genesis.L1Deployments{
AddressManager: common.Address(a.AddressManager),
// BlockOracle: common.Address(a.BlockOracle),
// DisputeGameFactory: common.Address(i.DisputeGameFactory.Address),
DisputeGameFactoryProxy: common.Address(a.DisputeGameFactoryProxy),
// L1CrossDomainMessenger: common.Address(i.L1CrossDomainMessenger.Address),
L1CrossDomainMessengerProxy: common.Address(a.L1CrossDomainMessengerProxy),
// L1ERC721Bridge: common.Address(i.L1ERC721Bridge.Address),
L1ERC721BridgeProxy: common.Address(a.L1ERC721BridgeProxy),
// L1StandardBridge: common.Address(i.L1StandardBridge.Address),
L1StandardBridgeProxy: common.Address(a.L1StandardBridgeProxy),
// L2OutputOracle: common.Address(i.L2OutputOracle.Address),
L2OutputOracleProxy: common.Address(a.L2OutputOracleProxy),
// OptimismMintableERC20Factory: common.Address(i.OptimismMintableERC20Factory.Address),
OptimismMintableERC20FactoryProxy: common.Address(a.OptimismMintableERC20FactoryProxy),
// OptimismPortal: common.Address(i.OptimismPortal.Address),
OptimismPortalProxy: common.Address(a.OptimismPortalProxy),
ProxyAdmin: common.Address(a.ProxyAdmin),
// SystemConfig: common.Address(i.SystemConfig.Address),
SystemConfigProxy: common.Address(a.SystemConfigProxy),
// ProtocolVersions: common.Address(i.ProtocolVersions.Address),
// ProtocolVersionsProxy: common.Address(a.ProtocolVersionsProxy),
}
}
6 changes: 3 additions & 3 deletions supersim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum-optimism/supersim/config"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
Expand Down Expand Up @@ -99,12 +100,11 @@ func TestL1GenesisState(t *testing.T) {
require.True(t, len(testSuite.Supersim.Orchestrator.OpSimInstances) > 0)

for _, l2OpSim := range testSuite.Supersim.Orchestrator.OpSimInstances {

var code []byte
code, _ = testSuite.Supersim.Orchestrator.L1Anvil().EthGetCode(context.Background(), l2OpSim.L2Config.L1DeploymentAddresses.AddressManager)
code, _ = testSuite.Supersim.Orchestrator.L1Anvil().EthGetCode(context.Background(), common.Address(l2OpSim.L2Config.L1Addresses.AddressManager))
require.NotEqual(t, emptyCode, code, "AddressManager is not deployed")

code, _ = testSuite.Supersim.Orchestrator.L1Anvil().EthGetCode(context.Background(), l2OpSim.L2Config.L1DeploymentAddresses.OptimismPortalProxy)
code, _ = testSuite.Supersim.Orchestrator.L1Anvil().EthGetCode(context.Background(), common.Address(l2OpSim.L2Config.L1Addresses.OptimismPortalProxy))
require.NotEqual(t, emptyCode, code, "OptimismPortalProxy is not deployed")
}
}
Expand Down

0 comments on commit e740f57

Please sign in to comment.