diff --git a/op-chain-ops/genesis/check.go b/op-chain-ops/genesis/check.go index 04845ebffb3665e0913ee024f06532f99167d5b1..9dc0dffd5741d1de4c1116aac2ab074f1fb980ed 100644 --- a/op-chain-ops/genesis/check.go +++ b/op-chain-ops/genesis/check.go @@ -51,8 +51,8 @@ func PostCheckMigratedDB(ldb ethdb.Database, migrationData migration.MigrationDa header := rawdb.ReadHeader(ldb, hash, *num) log.Info("Read header from database", "number", *num) - if !bytes.Equal(header.Extra, bedrockTransitionBlockExtraData) { - return fmt.Errorf("expected extra data to be %x, but got %x", bedrockTransitionBlockExtraData, header.Extra) + if !bytes.Equal(header.Extra, BedrockTransitionBlockExtraData) { + return fmt.Errorf("expected extra data to be %x, but got %x", BedrockTransitionBlockExtraData, header.Extra) } prevHeader := rawdb.ReadHeader(ldb, header.ParentHash, *num-1) diff --git a/op-chain-ops/genesis/db_migration.go b/op-chain-ops/genesis/db_migration.go index fa4f880f1e923e22316f6c42af5342d7aa79e024..d9f59aa95d10b0d9b1e7e9d8f0ce957ed146443d 100644 --- a/op-chain-ops/genesis/db_migration.go +++ b/op-chain-ops/genesis/db_migration.go @@ -20,8 +20,11 @@ import ( ) var ( - abiTrue = common.Hash{31: 0x01} - bedrockTransitionBlockExtraData = []byte("BEDROCK") + abiTrue = common.Hash{31: 0x01} + // 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") ) type MigrationResult struct { @@ -42,7 +45,7 @@ func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, m header := rawdb.ReadHeader(ldb, hash, *num) log.Info("Read header from database", "number", *num) - if bytes.Equal(header.Extra, bedrockTransitionBlockExtraData) { + if bytes.Equal(header.Extra, BedrockTransitionBlockExtraData) { log.Info("Detected migration already happened", "root", header.Root, "blockhash", header.Hash()) return &MigrationResult{ @@ -143,6 +146,11 @@ func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, m // Set the amount of gas used so that EIP 1559 starts off stable gasUsed := (uint64)(config.L2GenesisBlockGasLimit) * config.EIP1559Elasticity + // Ensure that the extradata is valid + if size := len(BedrockTransitionBlockExtraData); size > 32 { + return nil, fmt.Errorf("transition block extradata too long: %d", size) + } + // Create the bedrock transition block bedrockHeader := &types.Header{ ParentHash: header.Hash(), @@ -157,7 +165,7 @@ func MigrateDB(ldb ethdb.Database, config *DeployConfig, l1Block *types.Block, m GasLimit: (uint64)(config.L2GenesisBlockGasLimit), GasUsed: gasUsed, Time: uint64(config.L2OutputOracleStartingTimestamp), - Extra: bedrockTransitionBlockExtraData, + Extra: BedrockTransitionBlockExtraData, MixDigest: common.Hash{}, Nonce: types.BlockNonce{}, BaseFee: big.NewInt(params.InitialBaseFee),