Skip to content

Commit

Permalink
xdomain: add xdomain messenger address + addr manager owner (ethereum…
Browse files Browse the repository at this point in the history
…#109)

* xdomain: add xdomain messenger address

* comment: remove

* xdomain: fix signer

* genesis: add address manager owner address

* test: fix

* cli: cleanup
  • Loading branch information
tynes authored Nov 19, 2020
1 parent a6d53b6 commit 48e5f99
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 9 deletions.
2 changes: 2 additions & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand Down
24 changes: 23 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion console/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester {
t.Fatalf("failed to create node: %v", err)
}
ethConf := &eth.Config{
Genesis: core.DeveloperGenesisBlock(15, common.Address{}),
Genesis: core.DeveloperGenesisBlock(15, common.Address{}, common.Address{}, common.Address{}),
Miner: miner.Config{
Etherbase: common.HexToAddress(testAddress),
},
Expand Down
25 changes: 22 additions & 3 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -256,14 +261,26 @@ 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)
for key, val := range account.Storage {
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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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,
}
}

Expand Down
9 changes: 5 additions & 4 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
5 changes: 5 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions rollup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions rollup/sync_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ type SyncService struct {
CanonicalTransactionChainAddress common.Address
SequencerDecompressionAddress common.Address
StateCommitmentChainAddress common.Address
L1CrossDomainMessengerAddress common.Address
ExecutionManagerAddress common.Address
}

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 48e5f99

Please sign in to comment.