diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index 6b078e9b15af..f50ca66d656a 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -72,9 +72,11 @@ var AppHelpFlagGroups = []flagGroup{ utils.Eth1CanonicalTransactionChainDeployHeightFlag, utils.Eth1CanonicalTransactionChainAddressFlag, utils.Eth1SequencerDecompressionAddressFlag, + utils.Eth1L1CrossDomainMessengerAddressFlag, utils.Eth1ChainIdFlag, utils.Eth1NetworkIdFlag, utils.Eth1HTTPFlag, + utils.RollupAddressManagerOwnerAddressFlag, utils.RollupEnableVerifierFlag, }, }, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 9dbf6f3e5e1e..37fcf69a742d 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -808,6 +808,12 @@ var ( Value: "0x0000000000000000000000000000000000000000", EnvVar: "ETH1_ADDRESS_RESOLVER_ADDRESS", } + Eth1L1CrossDomainMessengerAddressFlag = cli.StringFlag{ + Name: "eth1.l1crossdomainmessengeraddress", + Usage: "Deployment address of the L1 cross domain messenger", + Value: "0x0000000000000000000000000000000000000000", + EnvVar: "ETH1_L1_CROSS_DOMAIN_MESSENGER_ADDRESS", + } Eth1ChainIdFlag = cli.Uint64Flag{ Name: "eth1.chainid", Usage: "Network identifier (integer, 1=Frontier, 2=Morden (disused), 3=Ropsten, 4=Rinkeby)", @@ -834,6 +840,12 @@ var ( Usage: "Enable the verifier", EnvVar: "ROLLUP_VERIFIER_ENABLE", } + RollupAddressManagerOwnerAddressFlag = cli.StringFlag{ + Name: "rollup.addressmanagerowneraddress", + Usage: "Owner address of the address manager", + Value: "0x0000000000000000000000000000000000000000", + EnvVar: "ROLLUP_ADDRESS_MANAGER_OWNER_ADDRESS", + } ) // MakeDataDir retrieves the currently requested data directory, terminating @@ -1075,6 +1087,10 @@ func setEth1(ctx *cli.Context, cfg *rollup.Config) { addr := ctx.GlobalString(Eth1SequencerDecompressionAddressFlag.Name) cfg.SequencerDecompressionAddress = common.HexToAddress(addr) } + if ctx.GlobalIsSet(Eth1L1CrossDomainMessengerAddressFlag.Name) { + addr := ctx.GlobalString(Eth1L1CrossDomainMessengerAddressFlag.Name) + cfg.L1CrossDomainMessengerAddress = common.HexToAddress(addr) + } if ctx.GlobalIsSet(Eth1ChainIdFlag.Name) { cfg.Eth1ChainId = ctx.GlobalUint64(Eth1ChainIdFlag.Name) } @@ -1098,6 +1114,10 @@ func setEth1(ctx *cli.Context, cfg *rollup.Config) { if ctx.GlobalIsSet(MinerGasTargetFlag.Name) { cfg.GasLimit = ctx.GlobalUint64(MinerGasTargetFlag.Name) } + if ctx.GlobalIsSet(RollupAddressManagerOwnerAddressFlag.Name) { + addr := ctx.GlobalString(RollupAddressManagerOwnerAddressFlag.Name) + cfg.AddressManagerOwnerAddress = common.HexToAddress(addr) + } if ctx.GlobalIsSet(RollupEnableVerifierFlag.Name) { cfg.IsVerifier = true } @@ -1670,7 +1690,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { } log.Info("Using developer account", "address", developer.Address) - cfg.Genesis = core.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address) + xdomainAddress := cfg.Rollup.L1CrossDomainMessengerAddress + addrManagerOwnerAddress := cfg.Rollup.AddressManagerOwnerAddress + cfg.Genesis = core.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address, xdomainAddress, addrManagerOwnerAddress) if !ctx.GlobalIsSet(MinerGasPriceFlag.Name) && !ctx.GlobalIsSet(MinerLegacyGasPriceFlag.Name) { cfg.Miner.GasPrice = big.NewInt(1) } diff --git a/console/console_test.go b/console/console_test.go index ec4d8156823f..c19eb3e3dd72 100644 --- a/console/console_test.go +++ b/console/console_test.go @@ -98,7 +98,7 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester { t.Fatalf("failed to create node: %v", err) } ethConf := ð.Config{ - Genesis: core.DeveloperGenesisBlock(15, common.Address{}), + Genesis: core.DeveloperGenesisBlock(15, common.Address{}, common.Address{}, common.Address{}), Miner: miner.Config{ Etherbase: common.HexToAddress(testAddress), }, diff --git a/core/genesis.go b/core/genesis.go index dda074fdafc1..e7bb1cad0119 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -63,6 +63,11 @@ type Genesis struct { Number uint64 `json:"number"` GasUsed uint64 `json:"gasUsed"` ParentHash common.Hash `json:"parentHash"` + + // OVM Specific, used to initialize the xDomainMessengerAddress + // in the genesis state + L1CrossDomainMessengerAddress common.Address `json:"-"` + AddressManagerOwnerAddress common.Address `json:"-"` } // GenesisAlloc specifies the initial state that is part of the genesis block. @@ -256,7 +261,7 @@ func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig { } // ApplyOvmStateToState applies the initial OVM state to a state object. -func ApplyOvmStateToState(statedb *state.StateDB) { +func ApplyOvmStateToState(statedb *state.StateDB, xDomainMessengerAddress, addrManagerOwnerAddress common.Address) { for _, account := range vm.OvmStateDump.Accounts { statedb.SetCode(account.Address, common.FromHex(account.Code)) statedb.SetNonce(account.Address, account.Nonce) @@ -264,6 +269,18 @@ func ApplyOvmStateToState(statedb *state.StateDB) { statedb.SetState(account.Address, key, common.HexToHash(val)) } } + AddressManager := vm.OvmStateDump.Accounts["Lib_AddressManager"] + // Set the owner of the address manager + ownerSlot := common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000") + ownerValue := common.BytesToHash(addrManagerOwnerAddress.Bytes()) + statedb.SetState(AddressManager.Address, ownerSlot, ownerValue) + log.Info("Setting AddressManager Owner", "owner", addrManagerOwnerAddress.Hex()) + // Set the storage slot associated with the cross domain messenger + // to the cross domain messenger address. + slot := common.HexToHash("0x515216935740e67dfdda5cf8e248ea32b3277787818ab59153061ac875c9385e") + value := common.BytesToHash(xDomainMessengerAddress.Bytes()) + statedb.SetState(AddressManager.Address, slot, value) + log.Info("Setting CrossDomainMessenger in AddressManager", "address", xDomainMessengerAddress.Hex()) } // ToBlock creates the genesis block and writes state of a genesis specification @@ -276,7 +293,7 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block { if os.Getenv("USING_OVM") == "true" { // OVM_ENABLED - ApplyOvmStateToState(statedb) + ApplyOvmStateToState(statedb, g.L1CrossDomainMessengerAddress, g.AddressManagerOwnerAddress) } for addr, account := range g.Alloc { @@ -403,7 +420,7 @@ func DefaultGoerliGenesisBlock() *Genesis { } // DeveloperGenesisBlock returns the 'geth --dev' genesis block. -func DeveloperGenesisBlock(period uint64, faucet common.Address) *Genesis { +func DeveloperGenesisBlock(period uint64, faucet, xDomainMessengerAddress, addrManagerOwnerAddress common.Address) *Genesis { // Override the default period to the user requested one config := *params.AllCliqueProtocolChanges config.Clique.Period = period @@ -424,6 +441,8 @@ func DeveloperGenesisBlock(period uint64, faucet common.Address) *Genesis { common.BytesToAddress([]byte{7}): {Balance: big.NewInt(1)}, // ECScalarMul common.BytesToAddress([]byte{8}): {Balance: big.NewInt(1)}, // ECPairing }, + L1CrossDomainMessengerAddress: xDomainMessengerAddress, + AddressManagerOwnerAddress: addrManagerOwnerAddress, } } diff --git a/eth/api_backend.go b/eth/api_backend.go index c22b9dc8468a..f917cf790af3 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -68,10 +68,11 @@ func (b *EthAPIBackend) GetLatestEth1Data() (common.Hash, uint64) { func (b *EthAPIBackend) GetRollupContractAddresses() map[string]*common.Address { return map[string]*common.Address{ - "addressResolver": &b.eth.syncService.AddressResolverAddress, - "canonicalTransactionChain": &b.eth.syncService.CanonicalTransactionChainAddress, - "sequencerDecompression": &b.eth.syncService.SequencerDecompressionAddress, - "stateCommitmentChain": &b.eth.syncService.StateCommitmentChainAddress, + "addressResolver": &b.eth.syncService.AddressResolverAddress, + "canonicalTransactionChain": &b.eth.syncService.CanonicalTransactionChainAddress, + "sequencerDecompression": &b.eth.syncService.SequencerDecompressionAddress, + "stateCommitmentChain": &b.eth.syncService.StateCommitmentChainAddress, + "l1CrossDomainMessengerAddress": &b.eth.syncService.L1CrossDomainMessengerAddress, } } diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 09e90210b366..359f368d2d2f 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1770,6 +1770,7 @@ type rollupAddresses struct { CanonicalTransactionChain string `json:"canonicalTransactionChain"` SequencerDecompression string `json:"sequencerDecompression"` StateCommitmentChain string `json:"stateCommitmentChain"` + L1CrossDomainMessenger string `json:"crossDomainMessenger"` } type rollupInfo struct { @@ -1809,6 +1810,10 @@ func (api *PublicRollupAPI) GetInfo(ctx context.Context) rollupInfo { if scc != nil { rollupAddrs.StateCommitmentChain = scc.Hex() } + xdomain := addrs["l1CrossDomainMesenger"] + if xdomain != nil { + rollupAddrs.L1CrossDomainMessenger = xdomain.Hex() + } return rollupInfo{ Signer: addr, diff --git a/rollup/config.go b/rollup/config.go index 774f6d162b43..7c7b1b19f538 100644 --- a/rollup/config.go +++ b/rollup/config.go @@ -38,6 +38,8 @@ type Config struct { CanonicalTransactionChainAddress common.Address L1ToL2TransactionQueueAddress common.Address SequencerDecompressionAddress common.Address + L1CrossDomainMessengerAddress common.Address + AddressManagerOwnerAddress common.Address // Deployment Height of the canonical transaction chain CanonicalTransactionChainDeployHeight *big.Int } diff --git a/rollup/sync_service.go b/rollup/sync_service.go index 9856272054db..f0d0169d4cee 100644 --- a/rollup/sync_service.go +++ b/rollup/sync_service.go @@ -174,6 +174,7 @@ type SyncService struct { CanonicalTransactionChainAddress common.Address SequencerDecompressionAddress common.Address StateCommitmentChainAddress common.Address + L1CrossDomainMessengerAddress common.Address ExecutionManagerAddress common.Address } @@ -207,6 +208,7 @@ func NewSyncService(ctx context.Context, cfg Config, txpool *core.TxPool, bc *co AddressResolverAddress: cfg.AddressResolverAddress, CanonicalTransactionChainAddress: cfg.CanonicalTransactionChainAddress, SequencerDecompressionAddress: cfg.SequencerDecompressionAddress, + L1CrossDomainMessengerAddress: cfg.L1CrossDomainMessengerAddress, confirmationDepth: cfg.Eth1ConfirmationDepth, signer: types.NewOVMSigner(chainID), key: *cfg.TxIngestionSignerKey,