genesis

package
v0.10.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2023 License: MIT Imports: 43 Imported by: 14

Documentation

Index

Constants

View Source
const MaxSlotChecks = 1000

MaxSlotChecks is the maximum number of storage slots to check when validating the untouched predeploys. This limit is in place to bound execution time of the migration. We can parallelize this in the future.

Variables

View Source
var (
	L2XDMOwnerSlot      = common.Hash{31: 0x33}
	ProxyAdminOwnerSlot = common.Hash{}

	LegacyETHCheckSlots = map[common.Hash]common.Hash{

		common.Hash{31: 0x06}: common.HexToHash("0x0000000000000000000000004200000000000000000000000000000000000010"),

		common.Hash{31: 0x04}: common.HexToHash("0x4554480000000000000000000000000000000000000000000000000000000006"),

		common.Hash{31: 0x03}: common.HexToHash("0x457468657200000000000000000000000000000000000000000000000000000a"),

		common.Hash{31: 0x02}: {},
	}

	// ExpectedStorageSlots is a map of predeploy addresses to the storage slots and values that are
	// expected to be set in those predeploys after the migration. It does not include any predeploys
	// that were not wiped. It also accounts for the 2 EIP-1967 storage slots in each contract.
	// It does _not_ include L1Block. L1Block is checked separately.
	ExpectedStorageSlots = map[common.Address]StorageCheckMap{
		predeploys.L2CrossDomainMessengerAddr: {

			common.Hash{}: common.HexToHash("0x0000000000000000000000010000000000000000000000000000000000000000"),

			L2XDMOwnerSlot: common.HexToHash("0xbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbad0"),

			common.Hash{31: 0x97}: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000001"),

			common.Hash{31: 0xcc}: common.HexToHash("0x000000000000000000000000000000000000000000000000000000000000dead"),

			AdminSlot:          common.HexToHash("0x0000000000000000000000004200000000000000000000000000000000000018"),
			ImplementationSlot: common.HexToHash("0x000000000000000000000000c0d3c0d3c0d3c0d3c0d3c0d3c0d3c0d3c0d30007"),
		},
		predeploys.L2StandardBridgeAddr:             eip1967Slots(predeploys.L2StandardBridgeAddr),
		predeploys.SequencerFeeVaultAddr:            eip1967Slots(predeploys.SequencerFeeVaultAddr),
		predeploys.OptimismMintableERC20FactoryAddr: eip1967Slots(predeploys.OptimismMintableERC20FactoryAddr),
		predeploys.L1BlockNumberAddr:                eip1967Slots(predeploys.L1BlockNumberAddr),
		predeploys.GasPriceOracleAddr:               eip1967Slots(predeploys.GasPriceOracleAddr),

		predeploys.L2ERC721BridgeAddr:                eip1967Slots(predeploys.L2ERC721BridgeAddr),
		predeploys.OptimismMintableERC721FactoryAddr: eip1967Slots(predeploys.OptimismMintableERC721FactoryAddr),

		predeploys.ProxyAdminAddr: {

			ProxyAdminOwnerSlot: common.HexToHash("0xbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbad0"),

			AdminSlot:          common.HexToHash("0x0000000000000000000000004200000000000000000000000000000000000018"),
			ImplementationSlot: common.HexToHash("0x000000000000000000000000c0d3c0d3c0d3c0d3c0d3c0d3c0d3c0d3c0d30018"),
		},
		predeploys.BaseFeeVaultAddr: eip1967Slots(predeploys.BaseFeeVaultAddr),
		predeploys.L1FeeVaultAddr:   eip1967Slots(predeploys.L1FeeVaultAddr),
	}
)
View Source
var (

	// implementationSlot represents the EIP 1967 implementation storage slot
	ImplementationSlot = common.HexToHash("0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc")
	// implementationSlot represents the EIP 1967 admin storage slot
	AdminSlot = common.HexToHash("0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103")
)
View Source
var (
	// UntouchablePredeploys are addresses in the predeploy namespace
	// that should not be touched by the migration process.
	UntouchablePredeploys = map[common.Address]bool{
		predeploys.GovernanceTokenAddr: true,
		predeploys.WETH9Addr:           true,
	}

	// UntouchableCodeHashes represent the bytecode hashes of contracts
	// that should not be touched by the migration process.
	UntouchableCodeHashes = map[common.Address]ChainHashMap{
		predeploys.GovernanceTokenAddr: {
			1: common.HexToHash("0x8551d935f4e67ad3c98609f0d9f0f234740c4c4599f82674633b55204393e07f"),
			5: common.HexToHash("0xc4a213cf5f06418533e5168d8d82f7ccbcc97f27ab90197c2c051af6a4941cf9"),
		},
		predeploys.WETH9Addr: {
			1: common.HexToHash("0x779bbf2a738ef09d961c945116197e2ac764c1b39304b2b4418cd4e42668b173"),
			5: common.HexToHash("0x779bbf2a738ef09d961c945116197e2ac764c1b39304b2b4418cd4e42668b173"),
		},
	}

	// FrozenStoragePredeploys represents the set of predeploys that
	// will not have their storage wiped during the migration process.
	// It is very explicitly set in its own mapping to ensure that
	// changes elsewhere in the codebase do no alter the predeploys
	// that do not have their storage wiped. It is safe for all other
	// predeploys to have their storage wiped.
	FrozenStoragePredeploys = map[common.Address]bool{
		predeploys.GovernanceTokenAddr:     true,
		predeploys.WETH9Addr:               true,
		predeploys.LegacyMessagePasserAddr: true,
		predeploys.LegacyERC20ETHAddr:      true,
		predeploys.DeployerWhitelistAddr:   true,
	}
)
View Source
var (

	// BedrockTransitionBlockExtraData represents the extradata
	// set in the very first bedrock block. This value must be
	// less than 32 bytes long or it will create an invalid block.
	BedrockTransitionBlockExtraData = []byte("BEDROCK")
)
View Source
var DevAccounts = []common.Address{
	common.HexToAddress("0x14dC79964da2C08b23698B3D3cc7Ca32193d9955"),
	common.HexToAddress("0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65"),
	common.HexToAddress("0x1CBd3b2770909D4e10f157cABC84C7264073C9Ec"),
	common.HexToAddress("0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f"),
	common.HexToAddress("0x2546BcD3c84621e976D8185a91A922aE77ECEc30"),
	common.HexToAddress("0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC"),
	common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8"),
	common.HexToAddress("0x71bE63f3384f5fb98995898A86B02Fb2426c5788"),
	common.HexToAddress("0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199"),
	common.HexToAddress("0x90F79bf6EB2c4f870365E785982E1f101E93b906"),
	common.HexToAddress("0x976EA74026E726554dB657fA54763abd0C3a0aa9"),
	common.HexToAddress("0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc"),
	common.HexToAddress("0xBcd4042DE499D14e55001CcbB24a551F3b954096"),
	common.HexToAddress("0xFABB0ac9d68B0B445fB7357272Ff202C5651694a"),
	common.HexToAddress("0xa0Ee7A142d267C1f36714E4a8F75612F20a79720"),
	common.HexToAddress("0xbDA5747bFD65F08deb54cb465eB87D40e51B197E"),
	common.HexToAddress("0xcd3B766CCDd6AE721141F452C550Ca635964ce71"),
	common.HexToAddress("0xdD2FD4581271e230360230F9337D5c0430Bf44C0"),
	common.HexToAddress("0xdF3e18d64BC6A983f673Ab319CCaE4f1a57C7097"),
	common.HexToAddress("0xde3829a23df1479438622a08a116e8eb3f620bb5"),
	common.HexToAddress("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"),

	common.HexToAddress("0x71562b71999873DB5b286dF957af199Ec94617F7"),
}

DevAccounts represent the standard hardhat development accounts. These are funded if the deploy config has funding development accounts enabled.

View Source
var ErrInvalidDeployConfig = errors.New("invalid deploy config")

Functions

func AddressToCodeNamespace

func AddressToCodeNamespace(addr common.Address) (common.Address, error)

AddressToCodeNamespace takes a predeploy address and computes the implementation address that the implementation should be deployed at

func BuildL1DeveloperGenesis

func BuildL1DeveloperGenesis(config *DeployConfig) (*core.Genesis, error)

func BuildL2DeveloperGenesis

func BuildL2DeveloperGenesis(config *DeployConfig, l1StartBlock *types.Block) (*core.Genesis, error)

BuildL2DeveloperGenesis will build the developer Optimism Genesis Block. Suitable for devnets.

func CheckWithdrawalsAfter added in v0.10.5

func CheckWithdrawalsAfter(db vm.StateDB, data migration.MigrationData, l1CrossDomainMessenger *common.Address) error

func FundDevAccounts

func FundDevAccounts(db vm.StateDB)

FundDevAccounts will fund each of the development accounts.

func GetBlockFromTag

func GetBlockFromTag(chain ethereum.ChainReader, tag *rpc.BlockNumberOrHash) (*types.Block, error)

GetBlockFromTag will resolve a Block given an rpc block tag

func IsL1DevPredeploy

func IsL1DevPredeploy(addr common.Address) bool

func IsL2DevPredeploy

func IsL2DevPredeploy(addr common.Address) bool

func NewL1Genesis

func NewL1Genesis(config *DeployConfig) (*core.Genesis, error)

NewL1Genesis will create a new L1 genesis config

func NewL2Genesis

func NewL2Genesis(config *DeployConfig, block *types.Block) (*core.Genesis, error)

NewL2Genesis will create a new L2 genesis

func NewL2ImmutableConfig

func NewL2ImmutableConfig(config *DeployConfig, block *types.Block) (immutables.ImmutableConfig, error)

NewL2ImmutableConfig will create an ImmutableConfig given an instance of a Hardhat and a DeployConfig.

func NewL2StorageConfig

func NewL2StorageConfig(config *DeployConfig, block *types.Block) (state.StorageConfig, error)

NewL2StorageConfig will create a StorageConfig given an instance of a Hardhat and a DeployConfig.

func PostCheckL1Block added in v0.10.7

func PostCheckL1Block(db vm.StateDB, info *derive.L1BlockInfo) error

PostCheckL1Block checks that the L1Block contract was properly set to the L1 origin.

func PostCheckLegacyETH added in v0.10.5

func PostCheckLegacyETH(db vm.StateDB) error

PostCheckLegacyETH checks that the legacy eth migration was successful. It currently only checks that the total supply was set to 0.

func PostCheckMigratedDB added in v0.10.5

func PostCheckMigratedDB(
	ldb ethdb.Database,
	migrationData migration.MigrationData,
	l1XDM *common.Address,
	l1ChainID uint64,
	finalSystemOwner common.Address,
	proxyAdminOwner common.Address,
	info *derive.L1BlockInfo,
) error

PostCheckMigratedDB will check that the migration was performed correctly

func PostCheckPredeployStorage added in v0.10.7

func PostCheckPredeployStorage(db vm.StateDB, finalSystemOwner common.Address, proxyAdminOwner common.Address) error

PostCheckPredeployStorage will ensure that the predeploys had their storage wiped correctly.

func PostCheckPredeploys added in v0.10.5

func PostCheckPredeploys(prevDB, currDB *state.StateDB) error

PostCheckPredeploys will check that there is code at each predeploy address

func PostCheckUntouchables added in v0.10.5

func PostCheckUntouchables(udb state.Database, currDB *state.StateDB, prevRoot common.Hash, l1ChainID uint64) error

PostCheckUntouchables will check that the untouchable contracts have not been modified by the migration process.

func SetDevOnlyL2Implementations added in v0.10.5

func SetDevOnlyL2Implementations(db vm.StateDB, storage state.StorageConfig, immutable immutables.ImmutableConfig) error

func SetImplementations

func SetImplementations(db vm.StateDB, storage state.StorageConfig, immutable immutables.ImmutableConfig) error

SetImplementations will set the implementations of the contracts in the state and configure the proxies to point to the implementations. It also sets the appropriate storage values for each contract at the proxy address.

func SetL1Proxies

func SetL1Proxies(db vm.StateDB, proxyAdminAddr common.Address) error

SetL1Proxies will set each of the proxies in the state. It requires 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 Proxy.

func SetL2Proxies

func SetL2Proxies(db vm.StateDB) error

SetL2Proxies will set each of the proxies in the state. It requires 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 Proxy.

func SetLegacyETH added in v0.10.5

func SetLegacyETH(db vm.StateDB, storage state.StorageConfig, immutable immutables.ImmutableConfig) error

func SetPrecompileBalances

func SetPrecompileBalances(db vm.StateDB)

SetPrecompileBalances will set a single wei at each precompile address. This is an optimization to make calling them cheaper. This should only be used for devnets.

func Untar

func Untar(tarball, target string) error

func WipePredeployStorage added in v0.10.7

func WipePredeployStorage(db vm.StateDB) error

WipePredeployStorage will wipe the storage of all L2 predeploys expect for predeploys that must not have their storage altered.

Types

type ChainHashMap added in v0.10.5

type ChainHashMap map[uint64]common.Hash

UntouchableCodeHashes contains code hashes of all the contracts that should not be touched by the migration process.

type DeployConfig

type DeployConfig struct {
	L1StartingBlockTag *MarshalableRPCBlockNumberOrHash `json:"l1StartingBlockTag"`
	L1ChainID          uint64                           `json:"l1ChainID"`
	L2ChainID          uint64                           `json:"l2ChainID"`
	L2BlockTime        uint64                           `json:"l2BlockTime"`

	FinalizationPeriodSeconds uint64         `json:"finalizationPeriodSeconds"`
	MaxSequencerDrift         uint64         `json:"maxSequencerDrift"`
	SequencerWindowSize       uint64         `json:"sequencerWindowSize"`
	ChannelTimeout            uint64         `json:"channelTimeout"`
	P2PSequencerAddress       common.Address `json:"p2pSequencerAddress"`
	BatchInboxAddress         common.Address `json:"batchInboxAddress"`
	BatchSenderAddress        common.Address `json:"batchSenderAddress"`

	L2OutputOracleSubmissionInterval uint64         `json:"l2OutputOracleSubmissionInterval"`
	L2OutputOracleStartingTimestamp  int            `json:"l2OutputOracleStartingTimestamp"`
	L2OutputOracleProposer           common.Address `json:"l2OutputOracleProposer"`
	L2OutputOracleChallenger         common.Address `json:"l2OutputOracleChallenger"`

	L1BlockTime                 uint64         `json:"l1BlockTime"`
	L1GenesisBlockTimestamp     hexutil.Uint64 `json:"l1GenesisBlockTimestamp"`
	L1GenesisBlockNonce         hexutil.Uint64 `json:"l1GenesisBlockNonce"`
	CliqueSignerAddress         common.Address `json:"cliqueSignerAddress"` // proof of stake genesis if left zeroed.
	L1GenesisBlockGasLimit      hexutil.Uint64 `json:"l1GenesisBlockGasLimit"`
	L1GenesisBlockDifficulty    *hexutil.Big   `json:"l1GenesisBlockDifficulty"`
	L1GenesisBlockMixHash       common.Hash    `json:"l1GenesisBlockMixHash"`
	L1GenesisBlockCoinbase      common.Address `json:"l1GenesisBlockCoinbase"`
	L1GenesisBlockNumber        hexutil.Uint64 `json:"l1GenesisBlockNumber"`
	L1GenesisBlockGasUsed       hexutil.Uint64 `json:"l1GenesisBlockGasUsed"`
	L1GenesisBlockParentHash    common.Hash    `json:"l1GenesisBlockParentHash"`
	L1GenesisBlockBaseFeePerGas *hexutil.Big   `json:"l1GenesisBlockBaseFeePerGas"`

	L2GenesisBlockNonce         hexutil.Uint64 `json:"l2GenesisBlockNonce"`
	L2GenesisBlockGasLimit      hexutil.Uint64 `json:"l2GenesisBlockGasLimit"`
	L2GenesisBlockDifficulty    *hexutil.Big   `json:"l2GenesisBlockDifficulty"`
	L2GenesisBlockMixHash       common.Hash    `json:"l2GenesisBlockMixHash"`
	L2GenesisBlockNumber        hexutil.Uint64 `json:"l2GenesisBlockNumber"`
	L2GenesisBlockGasUsed       hexutil.Uint64 `json:"l2GenesisBlockGasUsed"`
	L2GenesisBlockParentHash    common.Hash    `json:"l2GenesisBlockParentHash"`
	L2GenesisBlockBaseFeePerGas *hexutil.Big   `json:"l2GenesisBlockBaseFeePerGas"`

	// Owner of the ProxyAdmin predeploy
	ProxyAdminOwner common.Address `json:"proxyAdminOwner"`
	// Owner of the system on L1
	FinalSystemOwner common.Address `json:"finalSystemOwner"`
	// L1 recipient of fees accumulated in the BaseFeeVault
	BaseFeeVaultRecipient common.Address `json:"baseFeeVaultRecipient"`
	// L1 recipient of fees accumulated in the L1FeeVault
	L1FeeVaultRecipient common.Address `json:"l1FeeVaultRecipient"`
	// L1 recipient of fees accumulated in the SequencerFeeVault
	SequencerFeeVaultRecipient common.Address `json:"sequencerFeeVaultRecipient"`
	// L1StandardBridge proxy address on L1
	L1StandardBridgeProxy common.Address `json:"l1StandardBridgeProxy"`
	// L1CrossDomainMessenger proxy address on L1
	L1CrossDomainMessengerProxy common.Address `json:"l1CrossDomainMessengerProxy"`
	// L1ERC721Bridge proxy address on L1
	L1ERC721BridgeProxy common.Address `json:"l1ERC721BridgeProxy"`
	// SystemConfig proxy address on L1
	SystemConfigProxy common.Address `json:"systemConfigProxy"`
	// OptimismPortal proxy address on L1
	OptimismPortalProxy common.Address `json:"optimismPortalProxy"`
	// The initial value of the gas overhead
	GasPriceOracleOverhead uint64 `json:"gasPriceOracleOverhead"`
	// The initial value of the gas scalar
	GasPriceOracleScalar uint64 `json:"gasPriceOracleScalar"`
	// The ERC20 symbol of the GovernanceToken
	GovernanceTokenSymbol string `json:"governanceTokenSymbol"`
	// The ERC20 name of the GovernanceToken
	GovernanceTokenName string `json:"governanceTokenName"`
	// The owner of the GovernanceToken
	GovernanceTokenOwner common.Address `json:"governanceTokenOwner"`

	DeploymentWaitConfirmations int `json:"deploymentWaitConfirmations"`

	EIP1559Elasticity  uint64 `json:"eip1559Elasticity"`
	EIP1559Denominator uint64 `json:"eip1559Denominator"`

	FundDevAccounts bool `json:"fundDevAccounts"`
}

DeployConfig represents the deployment configuration for Optimism

func NewDeployConfig

func NewDeployConfig(path string) (*DeployConfig, error)

NewDeployConfig reads a config file given a path on the filesystem.

func NewDeployConfigWithNetwork

func NewDeployConfigWithNetwork(network, path string) (*DeployConfig, error)

NewDeployConfigWithNetwork takes a path to a deploy config directory and the network name. The config file in the deploy config directory must match the network name and be a JSON file.

func (*DeployConfig) Check

func (d *DeployConfig) Check() error

Check will ensure that the config is sane and return an error when it is not

func (*DeployConfig) GetDeployedAddresses

func (d *DeployConfig) GetDeployedAddresses(hh *hardhat.Hardhat) error

GetDeployedAddresses will get the deployed addresses of deployed L1 contracts required for the L2 genesis creation. Legacy systems use the `Proxy__` prefix while modern systems use the `Proxy` suffix. First check for the legacy deployments so that this works with upgrading a system.

func (*DeployConfig) InitDeveloperDeployedAddresses

func (d *DeployConfig) InitDeveloperDeployedAddresses() error

InitDeveloperDeployedAddresses will set the dev addresses on the DeployConfig

func (*DeployConfig) RollupConfig

func (d *DeployConfig) RollupConfig(l1StartBlock *types.Block, l2GenesisBlockHash common.Hash, l2GenesisBlockNumber uint64) (*rollup.Config, error)

RollupConfig converts a DeployConfig to a rollup.Config

type MarshalableRPCBlockNumberOrHash

type MarshalableRPCBlockNumberOrHash rpc.BlockNumberOrHash

func (*MarshalableRPCBlockNumberOrHash) MarshalJSON

func (m *MarshalableRPCBlockNumberOrHash) MarshalJSON() ([]byte, error)

func (*MarshalableRPCBlockNumberOrHash) UnmarshalJSON

func (m *MarshalableRPCBlockNumberOrHash) UnmarshalJSON(b []byte) error

type MigrationResult

type MigrationResult struct {
	TransitionHeight    uint64
	TransitionTimestamp uint64
	TransitionBlockHash common.Hash
}

func MigrateDB

func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, migrationData *migration.MigrationData, commit, noCheck bool) (*MigrationResult, error)

MigrateDB will migrate an l2geth legacy Optimism database to a Bedrock database.

type StorageCheckMap added in v0.10.7

type StorageCheckMap = map[common.Hash]common.Hash

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL