Skip to content

Commit

Permalink
op-chain-ops/interopgen: experimental interop genesis-state generation
Browse files Browse the repository at this point in the history
  • Loading branch information
protolambda committed Aug 25, 2024
1 parent f20b92d commit 12b253c
Show file tree
Hide file tree
Showing 15 changed files with 1,196 additions and 18 deletions.
4 changes: 4 additions & 0 deletions op-chain-ops/devkeys/devkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ const (
SuperchainConfigGuardianKey SuperchainOperatorRole = 1
// DependencySetManagerKey is the key used to manage the dependency set of a superchain.
DependencySetManagerKey SuperchainOperatorRole = 2
// SuperchainProxyAdminOwner is the key that owns the superchain ProxyAdmin
SuperchainProxyAdminOwner SuperchainOperatorRole = 3
// SuperchainFinalSystemOwner is the key that ownership is transferred to after deployment.
SuperchainFinalSystemOwner SuperchainOperatorRole = 4
)

func (role SuperchainOperatorRole) String() string {
Expand Down
12 changes: 6 additions & 6 deletions op-chain-ops/genesis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ type GasPriceOracleDeployConfig struct {
// Deprecated: Since Ecotone, this field is superseded by GasPriceOracleBaseFeeScalar and GasPriceOracleBlobBaseFeeScalar.
GasPriceOracleScalar uint64 `json:"gasPriceOracleScalar"`
// GasPriceOracleBaseFeeScalar represents the value of the base fee scalar used for fee calculations.
GasPriceOracleBaseFeeScalar uint32 `json:"gasPriceOracleBaseFeeScalar"`
GasPriceOracleBaseFeeScalar uint32 `json:"gasPriceOracleBaseFeeScalar" evm:"basefeeScalar"`
// GasPriceOracleBlobBaseFeeScalar represents the value of the blob base fee scalar used for fee calculations.
GasPriceOracleBlobBaseFeeScalar uint32 `json:"gasPriceOracleBlobBaseFeeScalar"`
GasPriceOracleBlobBaseFeeScalar uint32 `json:"gasPriceOracleBlobBaseFeeScalar" evm:"blobbasefeeScalar"`
}

var _ ConfigChecker = (*GasPriceOracleDeployConfig)(nil)
Expand Down Expand Up @@ -282,7 +282,7 @@ func (d *GasTokenDeployConfig) Check(log log.Logger) error {
// OperatorDeployConfig configures the hot-key addresses for operations such as sequencing and batch-submission.
type OperatorDeployConfig struct {
// P2PSequencerAddress is the address of the key the sequencer uses to sign blocks on the P2P layer.
P2PSequencerAddress common.Address `json:"p2pSequencerAddress"`
P2PSequencerAddress common.Address `json:"p2pSequencerAddress" evm:"p2pSequencerAddress"`
// BatchSenderAddress represents the initial sequencer account that authorizes batches.
// Transactions sent from this account to the batch inbox address are considered valid.
BatchSenderAddress common.Address `json:"batchSenderAddress"`
Expand Down Expand Up @@ -627,7 +627,7 @@ type OutputOracleDeployConfig struct {
L2OutputOracleSubmissionInterval uint64 `json:"l2OutputOracleSubmissionInterval"`
// L2OutputOracleStartingTimestamp is the starting timestamp for the L2OutputOracle.
// MUST be the same as the timestamp of the L2OO start block.
L2OutputOracleStartingTimestamp int `json:"l2OutputOracleStartingTimestamp"`
L2OutputOracleStartingTimestamp int64 `json:"l2OutputOracleStartingTimestamp"`
// L2OutputOracleStartingBlockNumber is the starting block number for the L2OutputOracle.
// Must be greater than or equal to the first Bedrock block. The first L2 output will correspond
// to this value plus the submission interval.
Expand Down Expand Up @@ -808,7 +808,7 @@ type DeployConfig struct {
// The L2 genesis timestamp does not affect the initial L2 account state:
// the storage of the L1Block contract at genesis is zeroed, since the adoption of
// the L2-genesis allocs-generation through solidity script.
L1StartingBlockTag *MarshalableRPCBlockNumberOrHash `json:"l1StartingBlockTag"`
L1StartingBlockTag *MarshalableRPCBlockNumberOrHash `json:"l1StartingBlockTag" evm:"-"`

// L1 contracts configuration.
// The deployer of the contracts chooses which sub-systems to deploy.
Expand All @@ -820,7 +820,7 @@ type DeployConfig struct {
L1DependenciesConfig

// Legacy, ignored, here for strict-JSON decoding to be accepted.
LegacyDeployConfig
LegacyDeployConfig `evm:"-"`
}

// Copy will deeply copy the DeployConfig. This does a JSON roundtrip to copy
Expand Down
7 changes: 7 additions & 0 deletions op-chain-ops/genesis/withdrawal_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/json"
"fmt"
"strconv"

"github.com/holiman/uint256"
)

// WithdrawalNetwork represents the network that withdrawals are sent to.
Expand Down Expand Up @@ -32,6 +34,11 @@ func (w *WithdrawalNetwork) ToUint8() uint8 {
}
}

func (w WithdrawalNetwork) ToABI() []byte {
out := uint256.NewInt(uint64(w.ToUint8())).Bytes32()
return out[:]
}

// FromUint8 converts a uint8 to a WithdrawalNetwork.
func FromUint8(i uint8) WithdrawalNetwork {
switch i {
Expand Down
92 changes: 92 additions & 0 deletions op-chain-ops/interopgen/configs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package interopgen

import (
"errors"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"

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

type L1Config struct {
ChainID *big.Int
genesis.DevL1DeployConfig
Prefund map[common.Address]*big.Int
}

func (c *L1Config) Check(log log.Logger) error {
if c.ChainID == nil {
return errors.New("missing L1 chain ID")
}
// nothing to check on c.DevL1DeployConfig
return nil
}

type SuperchainConfig struct {
Deployer common.Address

FinalSystemOwner common.Address
ProxyAdminOwner common.Address

genesis.SuperchainL1DeployConfig
}

func (c *SuperchainConfig) Check(log log.Logger) error {
if c.Deployer == (common.Address{}) {
return errors.New("missing superchain deployer address")
}
if c.ProxyAdminOwner == (common.Address{}) {
return errors.New("missing superchain ProxyAdminOwner address")
}
if err := c.SuperchainL1DeployConfig.Check(log); err != nil {
return err
}
return nil
}

type L2Config struct {
Deployer common.Address // account used to deploy contracts to L2
genesis.L2InitializationConfig
genesis.FaultProofDeployConfig
Prefund map[common.Address]*big.Int
}

func (c *L2Config) Check(log log.Logger) error {
if c.Deployer == (common.Address{}) {
return errors.New("missing L2 deployer address")
}
if err := c.L2InitializationConfig.Check(log); err != nil {
return err
}
if !c.FaultProofDeployConfig.UseFaultProofs {
return errors.New("must set UseFaultProofs: legacy output oracle is not supported")
}
if err := c.FaultProofDeployConfig.Check(log); err != nil {
return err
}
return nil
}

type WorldConfig struct {
L1 *L1Config
Superchain *SuperchainConfig
L2s map[string]*L2Config
}

func (c *WorldConfig) Check(log log.Logger) error {
if err := c.L1.Check(log); err != nil {
return fmt.Errorf("invalid L1 config: %w", err)
}
if err := c.Superchain.Check(log); err != nil {
return fmt.Errorf("invalid Superchain config: %w", err)
}
for l2ChainID, l2Cfg := range c.L2s {
if err := l2Cfg.Check(log.New("l2", &l2ChainID)); err != nil {
return fmt.Errorf("invalid L2 (chain ID %s) config: %w", l2ChainID, err)
}
}
return nil
}
Loading

0 comments on commit 12b253c

Please sign in to comment.