Commit d895830a authored by Adrian Sutton's avatar Adrian Sutton Committed by GitHub

op-program: Move towards using eth.ChainID instead of uint64 (#13850)

* op-program: Move towards using eth.ChainID instead of uint64

* op-program: Move oracle API over to ChainID

* Review feedback
parent 0a327e67
...@@ -5,7 +5,7 @@ import "github.com/ethereum-optimism/optimism/op-service/eth" ...@@ -5,7 +5,7 @@ import "github.com/ethereum-optimism/optimism/op-service/eth"
func responseToSuper(prevRoot eth.SuperRootResponse) *eth.SuperV1 { func responseToSuper(prevRoot eth.SuperRootResponse) *eth.SuperV1 {
prevChainOutputs := make([]eth.ChainIDAndOutput, 0, len(prevRoot.Chains)) prevChainOutputs := make([]eth.ChainIDAndOutput, 0, len(prevRoot.Chains))
for _, chain := range prevRoot.Chains { for _, chain := range prevRoot.Chains {
prevChainOutputs = append(prevChainOutputs, eth.ChainIDAndOutput{ChainID: chain.ChainID.ToBig().Uint64(), Output: chain.Canonical}) prevChainOutputs = append(prevChainOutputs, eth.ChainIDAndOutput{ChainID: chain.ChainID, Output: chain.Canonical})
} }
superV1 := eth.NewSuperV1(prevRoot.Timestamp, prevChainOutputs...) superV1 := eth.NewSuperV1(prevRoot.Timestamp, prevChainOutputs...)
return superV1 return superV1
......
...@@ -23,7 +23,7 @@ func TestResponseToSuper(t *testing.T) { ...@@ -23,7 +23,7 @@ func TestResponseToSuper(t *testing.T) {
expected := &eth.SuperV1{ expected := &eth.SuperV1{
Timestamp: 4978924, Timestamp: 4978924,
Chains: []eth.ChainIDAndOutput{ Chains: []eth.ChainIDAndOutput{
{ChainID: 2987, Output: eth.Bytes32{0x88}}, {ChainID: eth.ChainIDFromUInt64(2987), Output: eth.Bytes32{0x88}},
}, },
} }
actual := responseToSuper(input) actual := responseToSuper(input)
...@@ -50,8 +50,8 @@ func TestResponseToSuper(t *testing.T) { ...@@ -50,8 +50,8 @@ func TestResponseToSuper(t *testing.T) {
expected := &eth.SuperV1{ expected := &eth.SuperV1{
Timestamp: 4978924, Timestamp: 4978924,
Chains: []eth.ChainIDAndOutput{ Chains: []eth.ChainIDAndOutput{
{ChainID: 100, Output: eth.Bytes32{0x10}}, {ChainID: eth.ChainIDFromUInt64(100), Output: eth.Bytes32{0x10}},
{ChainID: 2987, Output: eth.Bytes32{0x88}}, {ChainID: eth.ChainIDFromUInt64(2987), Output: eth.Bytes32{0x88}},
}, },
} }
actual := responseToSuper(input) actual := responseToSuper(input)
......
...@@ -75,11 +75,11 @@ func TestGet(t *testing.T) { ...@@ -75,11 +75,11 @@ func TestGet(t *testing.T) {
outputB2 := testutils.RandomOutputV0(rng) outputB2 := testutils.RandomOutputV0(rng)
superRoot1 := eth.NewSuperV1( superRoot1 := eth.NewSuperV1(
prestateTimestamp, prestateTimestamp,
eth.ChainIDAndOutput{ChainID: 1, Output: eth.OutputRoot(outputA1)}, eth.ChainIDAndOutput{ChainID: eth.ChainIDFromUInt64(1), Output: eth.OutputRoot(outputA1)},
eth.ChainIDAndOutput{ChainID: 2, Output: eth.OutputRoot(outputB1)}) eth.ChainIDAndOutput{ChainID: eth.ChainIDFromUInt64(2), Output: eth.OutputRoot(outputB1)})
superRoot2 := eth.NewSuperV1(prestateTimestamp+1, superRoot2 := eth.NewSuperV1(prestateTimestamp+1,
eth.ChainIDAndOutput{ChainID: 1, Output: eth.OutputRoot(outputA2)}, eth.ChainIDAndOutput{ChainID: eth.ChainIDFromUInt64(1), Output: eth.OutputRoot(outputA2)},
eth.ChainIDAndOutput{ChainID: 2, Output: eth.OutputRoot(outputB2)}) eth.ChainIDAndOutput{ChainID: eth.ChainIDFromUInt64(2), Output: eth.OutputRoot(outputB2)})
stubSupervisor.Add(eth.SuperRootResponse{ stubSupervisor.Add(eth.SuperRootResponse{
Timestamp: prestateTimestamp, Timestamp: prestateTimestamp,
SuperRoot: eth.SuperRoot(superRoot1), SuperRoot: eth.SuperRoot(superRoot1),
......
...@@ -3,7 +3,6 @@ package interop ...@@ -3,7 +3,6 @@ package interop
import ( import (
"context" "context"
"fmt" "fmt"
"math/big"
"slices" "slices"
"github.com/ethereum-optimism/optimism/op-node/rollup" "github.com/ethereum-optimism/optimism/op-node/rollup"
...@@ -16,7 +15,7 @@ type OutputRootSource interface { ...@@ -16,7 +15,7 @@ type OutputRootSource interface {
} }
type chainInfo struct { type chainInfo struct {
chainID *big.Int chainID eth.ChainID
source OutputRootSource source OutputRootSource
config *rollup.Config config *rollup.Config
} }
...@@ -33,7 +32,7 @@ func NewSuperRootSource(ctx context.Context, sources ...OutputRootSource) (*Supe ...@@ -33,7 +32,7 @@ func NewSuperRootSource(ctx context.Context, sources ...OutputRootSource) (*Supe
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to load rollup config: %w", err) return nil, fmt.Errorf("failed to load rollup config: %w", err)
} }
chainID := config.L2ChainID chainID := eth.ChainIDFromBig(config.L2ChainID)
chains = append(chains, &chainInfo{ chains = append(chains, &chainInfo{
chainID: chainID, chainID: chainID,
source: source, source: source,
...@@ -57,7 +56,7 @@ func (s *SuperRootSource) CreateSuperRoot(ctx context.Context, timestamp uint64) ...@@ -57,7 +56,7 @@ func (s *SuperRootSource) CreateSuperRoot(ctx context.Context, timestamp uint64)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to load output root for chain %v at block %v: %w", chain.chainID, blockNum, err) return nil, fmt.Errorf("failed to load output root for chain %v at block %v: %w", chain.chainID, blockNum, err)
} }
chains[i] = eth.ChainIDAndOutput{ChainID: chain.chainID.Uint64(), Output: output.OutputRoot} chains[i] = eth.ChainIDAndOutput{ChainID: chain.chainID, Output: output.OutputRoot}
} }
output := eth.SuperV1{ output := eth.SuperV1{
Timestamp: timestamp, Timestamp: timestamp,
......
...@@ -2,6 +2,7 @@ package helpers ...@@ -2,6 +2,7 @@ package helpers
import ( import (
"github.com/ethereum-optimism/optimism/op-e2e/actions/helpers" "github.com/ethereum-optimism/optimism/op-e2e/actions/helpers"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
) )
...@@ -23,7 +24,7 @@ type FixtureInputs struct { ...@@ -23,7 +24,7 @@ type FixtureInputs struct {
L2Claim common.Hash `toml:"l2-claim"` L2Claim common.Hash `toml:"l2-claim"`
L2Head common.Hash `toml:"l2-head"` L2Head common.Hash `toml:"l2-head"`
L2OutputRoot common.Hash `toml:"l2-output-root"` L2OutputRoot common.Hash `toml:"l2-output-root"`
L2ChainID uint64 `toml:"l2-chain-id"` L2ChainID eth.ChainID `toml:"l2-chain-id"`
L1Head common.Hash `toml:"l1-head"` L1Head common.Hash `toml:"l1-head"`
AgreedPrestate []byte `toml:"agreed-prestate"` AgreedPrestate []byte `toml:"agreed-prestate"`
InteropEnabled bool `toml:"use-interop"` InteropEnabled bool `toml:"use-interop"`
......
...@@ -13,6 +13,7 @@ import ( ...@@ -13,6 +13,7 @@ import (
"github.com/ethereum-optimism/optimism/op-program/host/kvstore" "github.com/ethereum-optimism/optimism/op-program/host/kvstore"
"github.com/ethereum-optimism/optimism/op-program/host/prefetcher" "github.com/ethereum-optimism/optimism/op-program/host/prefetcher"
"github.com/ethereum-optimism/optimism/op-service/client" "github.com/ethereum-optimism/optimism/op-service/client"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/sources" "github.com/ethereum-optimism/optimism/op-service/sources"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
...@@ -44,7 +45,7 @@ func WithPreInteropDefaults(t helpers.Testing, l2ClaimBlockNum uint64, l2 *helpe ...@@ -44,7 +45,7 @@ func WithPreInteropDefaults(t helpers.Testing, l2ClaimBlockNum uint64, l2 *helpe
f.L2Claim = common.Hash(claimRoot.OutputRoot) f.L2Claim = common.Hash(claimRoot.OutputRoot)
f.L2Head = preRoot.BlockRef.Hash f.L2Head = preRoot.BlockRef.Hash
f.L2OutputRoot = common.Hash(preRoot.OutputRoot) f.L2OutputRoot = common.Hash(preRoot.OutputRoot)
f.L2ChainID = l2.RollupCfg.L2ChainID.Uint64() f.L2ChainID = eth.ChainIDFromBig(l2.RollupCfg.L2ChainID)
f.L2Sources = []*FaultProofProgramL2Source{ f.L2Sources = []*FaultProofProgramL2Source{
{ {
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"github.com/ethereum-optimism/optimism/op-node/chaincfg" "github.com/ethereum-optimism/optimism/op-node/chaincfg"
"github.com/ethereum-optimism/optimism/op-node/rollup" "github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
) )
...@@ -21,21 +22,21 @@ func OPSepoliaChainConfig() *params.ChainConfig { ...@@ -21,21 +22,21 @@ func OPSepoliaChainConfig() *params.ChainConfig {
//go:embed configs/*json //go:embed configs/*json
var customChainConfigFS embed.FS var customChainConfigFS embed.FS
func RollupConfigByChainID(chainID uint64) (*rollup.Config, error) { func RollupConfigByChainID(chainID eth.ChainID) (*rollup.Config, error) {
config, err := rollup.LoadOPStackRollupConfig(chainID) config, err := rollup.LoadOPStackRollupConfig(eth.EvilChainIDToUInt64(chainID))
if err == nil { if err == nil {
return config, err return config, err
} }
return rollupConfigByChainID(chainID, customChainConfigFS) return rollupConfigByChainID(chainID, customChainConfigFS)
} }
func rollupConfigByChainID(chainID uint64, customChainFS embed.FS) (*rollup.Config, error) { func rollupConfigByChainID(chainID eth.ChainID, customChainFS embed.FS) (*rollup.Config, error) {
// Load custom rollup configs from embed FS // Load custom rollup configs from embed FS
file, err := customChainFS.Open(fmt.Sprintf("configs/%d-rollup.json", chainID)) file, err := customChainFS.Open(fmt.Sprintf("configs/%v-rollup.json", chainID))
if errors.Is(err, os.ErrNotExist) { if errors.Is(err, os.ErrNotExist) {
return nil, fmt.Errorf("no rollup config available for chain ID: %d", chainID) return nil, fmt.Errorf("no rollup config available for chain ID: %d", chainID)
} else if err != nil { } else if err != nil {
return nil, fmt.Errorf("failed to get rollup config for chain ID %d: %w", chainID, err) return nil, fmt.Errorf("failed to get rollup config for chain ID %v: %w", chainID, err)
} }
defer file.Close() defer file.Close()
...@@ -43,26 +44,26 @@ func rollupConfigByChainID(chainID uint64, customChainFS embed.FS) (*rollup.Conf ...@@ -43,26 +44,26 @@ func rollupConfigByChainID(chainID uint64, customChainFS embed.FS) (*rollup.Conf
return &customRollupConfig, customRollupConfig.ParseRollupConfig(file) return &customRollupConfig, customRollupConfig.ParseRollupConfig(file)
} }
func ChainConfigByChainID(chainID uint64) (*params.ChainConfig, error) { func ChainConfigByChainID(chainID eth.ChainID) (*params.ChainConfig, error) {
config, err := params.LoadOPStackChainConfig(chainID) config, err := params.LoadOPStackChainConfig(eth.EvilChainIDToUInt64(chainID))
if err == nil { if err == nil {
return config, err return config, err
} }
return chainConfigByChainID(chainID, customChainConfigFS) return chainConfigByChainID(chainID, customChainConfigFS)
} }
func chainConfigByChainID(chainID uint64, customChainFS embed.FS) (*params.ChainConfig, error) { func chainConfigByChainID(chainID eth.ChainID, customChainFS embed.FS) (*params.ChainConfig, error) {
// Load from custom chain configs from embed FS // Load from custom chain configs from embed FS
data, err := customChainFS.ReadFile(fmt.Sprintf("configs/%d-genesis-l2.json", chainID)) data, err := customChainFS.ReadFile(fmt.Sprintf("configs/%v-genesis-l2.json", chainID))
if errors.Is(err, os.ErrNotExist) { if errors.Is(err, os.ErrNotExist) {
return nil, fmt.Errorf("no chain config available for chain ID: %d", chainID) return nil, fmt.Errorf("no chain config available for chain ID: %d", chainID)
} else if err != nil { } else if err != nil {
return nil, fmt.Errorf("failed to get chain config for chain ID %d: %w", chainID, err) return nil, fmt.Errorf("failed to get chain config for chain ID %v: %w", chainID, err)
} }
var genesis core.Genesis var genesis core.Genesis
err = json.Unmarshal(data, &genesis) err = json.Unmarshal(data, &genesis)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to parse chain config for chain ID %d: %w", chainID, err) return nil, fmt.Errorf("failed to parse chain config for chain ID %v: %w", chainID, err)
} }
return genesis.Config, nil return genesis.Config, nil
} }
...@@ -72,7 +73,7 @@ func mustLoadChainConfig(name string) *params.ChainConfig { ...@@ -72,7 +73,7 @@ func mustLoadChainConfig(name string) *params.ChainConfig {
if chainCfg == nil { if chainCfg == nil {
panic(fmt.Errorf("unknown chain config %q", name)) panic(fmt.Errorf("unknown chain config %q", name))
} }
cfg, err := ChainConfigByChainID(chainCfg.ChainID) cfg, err := ChainConfigByChainID(eth.ChainIDFromUInt64(chainCfg.ChainID))
if err != nil { if err != nil {
panic(fmt.Errorf("failed to load rollup config: %q: %w", name, err)) panic(fmt.Errorf("failed to load rollup config: %q: %w", name, err))
} }
......
...@@ -4,26 +4,27 @@ import ( ...@@ -4,26 +4,27 @@ import (
"testing" "testing"
"github.com/ethereum-optimism/optimism/op-program/chainconfig/test" "github.com/ethereum-optimism/optimism/op-program/chainconfig/test"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
// TestGetCustomRollupConfig tests loading the custom rollup configs from test embed FS. // TestGetCustomRollupConfig tests loading the custom rollup configs from test embed FS.
func TestGetCustomRollupConfig(t *testing.T) { func TestGetCustomRollupConfig(t *testing.T) {
config, err := rollupConfigByChainID(901, test.TestCustomChainConfigFS) config, err := rollupConfigByChainID(eth.ChainIDFromUInt64(901), test.TestCustomChainConfigFS)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, config.L1ChainID.Uint64(), uint64(900)) require.Equal(t, config.L1ChainID.Uint64(), uint64(900))
require.Equal(t, config.L2ChainID.Uint64(), uint64(901)) require.Equal(t, config.L2ChainID.Uint64(), uint64(901))
_, err = rollupConfigByChainID(900, test.TestCustomChainConfigFS) _, err = rollupConfigByChainID(eth.ChainIDFromUInt64(900), test.TestCustomChainConfigFS)
require.Error(t, err) require.Error(t, err)
} }
// TestGetCustomChainConfig tests loading the custom chain configs from test embed FS. // TestGetCustomChainConfig tests loading the custom chain configs from test embed FS.
func TestGetCustomChainConfig(t *testing.T) { func TestGetCustomChainConfig(t *testing.T) {
config, err := chainConfigByChainID(901, test.TestCustomChainConfigFS) config, err := chainConfigByChainID(eth.ChainIDFromUInt64(901), test.TestCustomChainConfigFS)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, config.ChainID.Uint64(), uint64(901)) require.Equal(t, config.ChainID.Uint64(), uint64(901))
_, err = chainConfigByChainID(900, test.TestCustomChainConfigFS) _, err = chainConfigByChainID(eth.ChainIDFromUInt64(900), test.TestCustomChainConfigFS)
require.Error(t, err) require.Error(t, err)
} }
...@@ -7,19 +7,20 @@ import ( ...@@ -7,19 +7,20 @@ import (
"github.com/ethereum-optimism/optimism/op-node/rollup" "github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-program/chainconfig" "github.com/ethereum-optimism/optimism/op-program/chainconfig"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
) )
// CustomChainIDIndicator is used to detect when the program should load custom chain configuration // CustomChainIDIndicator is used to detect when the program should load custom chain configuration
const CustomChainIDIndicator = uint64(math.MaxUint64) var CustomChainIDIndicator = eth.ChainIDFromUInt64(uint64(math.MaxUint64))
type BootInfo struct { type BootInfo struct {
L1Head common.Hash L1Head common.Hash
L2OutputRoot common.Hash L2OutputRoot common.Hash
L2Claim common.Hash L2Claim common.Hash
L2ClaimBlockNumber uint64 L2ClaimBlockNumber uint64
L2ChainID uint64 L2ChainID eth.ChainID
L2ChainConfig *params.ChainConfig L2ChainConfig *params.ChainConfig
RollupConfig *rollup.Config RollupConfig *rollup.Config
...@@ -38,7 +39,7 @@ func (br *BootstrapClient) BootInfo() *BootInfo { ...@@ -38,7 +39,7 @@ func (br *BootstrapClient) BootInfo() *BootInfo {
l2OutputRoot := common.BytesToHash(br.r.Get(L2OutputRootLocalIndex)) l2OutputRoot := common.BytesToHash(br.r.Get(L2OutputRootLocalIndex))
l2Claim := common.BytesToHash(br.r.Get(L2ClaimLocalIndex)) l2Claim := common.BytesToHash(br.r.Get(L2ClaimLocalIndex))
l2ClaimBlockNumber := binary.BigEndian.Uint64(br.r.Get(L2ClaimBlockNumberLocalIndex)) l2ClaimBlockNumber := binary.BigEndian.Uint64(br.r.Get(L2ClaimBlockNumberLocalIndex))
l2ChainID := binary.BigEndian.Uint64(br.r.Get(L2ChainIDLocalIndex)) l2ChainID := eth.ChainIDFromUInt64(binary.BigEndian.Uint64(br.r.Get(L2ChainIDLocalIndex)))
var l2ChainConfig *params.ChainConfig var l2ChainConfig *params.ChainConfig
var rollupConfig *rollup.Config var rollupConfig *rollup.Config
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"github.com/ethereum-optimism/optimism/op-node/rollup" "github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-program/chainconfig" "github.com/ethereum-optimism/optimism/op-program/chainconfig"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
) )
...@@ -26,19 +27,19 @@ type BootInfoInterop struct { ...@@ -26,19 +27,19 @@ type BootInfoInterop struct {
} }
type ConfigSource interface { type ConfigSource interface {
RollupConfig(chainID uint64) (*rollup.Config, error) RollupConfig(chainID eth.ChainID) (*rollup.Config, error)
ChainConfig(chainID uint64) (*params.ChainConfig, error) ChainConfig(chainID eth.ChainID) (*params.ChainConfig, error)
} }
type OracleConfigSource struct { type OracleConfigSource struct {
oracle oracleClient oracle oracleClient
customConfigsLoaded bool customConfigsLoaded bool
l2ChainConfigs map[uint64]*params.ChainConfig l2ChainConfigs map[eth.ChainID]*params.ChainConfig
rollupConfigs map[uint64]*rollup.Config rollupConfigs map[eth.ChainID]*rollup.Config
} }
func (c *OracleConfigSource) RollupConfig(chainID uint64) (*rollup.Config, error) { func (c *OracleConfigSource) RollupConfig(chainID eth.ChainID) (*rollup.Config, error) {
if cfg, ok := c.rollupConfigs[chainID]; ok { if cfg, ok := c.rollupConfigs[chainID]; ok {
return cfg, nil return cfg, nil
} }
...@@ -57,7 +58,7 @@ func (c *OracleConfigSource) RollupConfig(chainID uint64) (*rollup.Config, error ...@@ -57,7 +58,7 @@ func (c *OracleConfigSource) RollupConfig(chainID uint64) (*rollup.Config, error
return cfg, nil return cfg, nil
} }
func (c *OracleConfigSource) ChainConfig(chainID uint64) (*params.ChainConfig, error) { func (c *OracleConfigSource) ChainConfig(chainID eth.ChainID) (*params.ChainConfig, error) {
if cfg, ok := c.l2ChainConfigs[chainID]; ok { if cfg, ok := c.l2ChainConfigs[chainID]; ok {
return cfg, nil return cfg, nil
} }
...@@ -83,7 +84,7 @@ func (c *OracleConfigSource) loadCustomConfigs() { ...@@ -83,7 +84,7 @@ func (c *OracleConfigSource) loadCustomConfigs() {
panic("failed to bootstrap rollup configs") panic("failed to bootstrap rollup configs")
} }
for _, config := range rollupConfigs { for _, config := range rollupConfigs {
c.rollupConfigs[config.L2ChainID.Uint64()] = config c.rollupConfigs[eth.ChainIDFromBig(config.L2ChainID)] = config
} }
var chainConfigs []*params.ChainConfig var chainConfigs []*params.ChainConfig
...@@ -92,7 +93,7 @@ func (c *OracleConfigSource) loadCustomConfigs() { ...@@ -92,7 +93,7 @@ func (c *OracleConfigSource) loadCustomConfigs() {
panic("failed to bootstrap chain configs") panic("failed to bootstrap chain configs")
} }
for _, config := range chainConfigs { for _, config := range chainConfigs {
c.l2ChainConfigs[config.ChainID.Uint64()] = config c.l2ChainConfigs[eth.ChainIDFromBig(config.ChainID)] = config
} }
c.customConfigsLoaded = true c.customConfigsLoaded = true
} }
...@@ -106,8 +107,8 @@ func BootstrapInterop(r oracleClient) *BootInfoInterop { ...@@ -106,8 +107,8 @@ func BootstrapInterop(r oracleClient) *BootInfoInterop {
return &BootInfoInterop{ return &BootInfoInterop{
Configs: &OracleConfigSource{ Configs: &OracleConfigSource{
oracle: r, oracle: r,
l2ChainConfigs: make(map[uint64]*params.ChainConfig), l2ChainConfigs: make(map[eth.ChainID]*params.ChainConfig),
rollupConfigs: make(map[uint64]*rollup.Config), rollupConfigs: make(map[eth.ChainID]*rollup.Config),
}, },
L1Head: l1Head, L1Head: l1Head,
AgreedPrestate: agreedPrestate, AgreedPrestate: agreedPrestate,
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"github.com/ethereum-optimism/optimism/op-node/rollup" "github.com/ethereum-optimism/optimism/op-node/rollup"
preimage "github.com/ethereum-optimism/optimism/op-preimage" preimage "github.com/ethereum-optimism/optimism/op-preimage"
"github.com/ethereum-optimism/optimism/op-program/chainconfig" "github.com/ethereum-optimism/optimism/op-program/chainconfig"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
...@@ -40,7 +41,7 @@ func TestInteropBootstrap_RollupConfigBuiltIn(t *testing.T) { ...@@ -40,7 +41,7 @@ func TestInteropBootstrap_RollupConfigBuiltIn(t *testing.T) {
} }
mockOracle := newMockInteropBootstrapOracle(expected, false) mockOracle := newMockInteropBootstrapOracle(expected, false)
actual := BootstrapInterop(mockOracle) actual := BootstrapInterop(mockOracle)
actualCfg, err := actual.Configs.RollupConfig(expectedCfg.L2ChainID.Uint64()) actualCfg, err := actual.Configs.RollupConfig(eth.ChainIDFromBig(expectedCfg.L2ChainID))
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, expectedCfg, actualCfg) require.Equal(t, expectedCfg, actualCfg)
} }
...@@ -57,11 +58,11 @@ func TestInteropBootstrap_RollupConfigCustom(t *testing.T) { ...@@ -57,11 +58,11 @@ func TestInteropBootstrap_RollupConfigCustom(t *testing.T) {
mockOracle := newMockInteropBootstrapOracle(source, true) mockOracle := newMockInteropBootstrapOracle(source, true)
mockOracle.rollupCfgs = []*rollup.Config{config1, config2} mockOracle.rollupCfgs = []*rollup.Config{config1, config2}
actual := BootstrapInterop(mockOracle) actual := BootstrapInterop(mockOracle)
actualCfg, err := actual.Configs.RollupConfig(config1.L2ChainID.Uint64()) actualCfg, err := actual.Configs.RollupConfig(eth.ChainIDFromBig(config1.L2ChainID))
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, config1, actualCfg) require.Equal(t, config1, actualCfg)
actualCfg, err = actual.Configs.RollupConfig(config2.L2ChainID.Uint64()) actualCfg, err = actual.Configs.RollupConfig(eth.ChainIDFromBig(config2.L2ChainID))
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, config2, actualCfg) require.Equal(t, config2, actualCfg)
} }
...@@ -76,7 +77,7 @@ func TestInteropBootstrap_ChainConfigBuiltIn(t *testing.T) { ...@@ -76,7 +77,7 @@ func TestInteropBootstrap_ChainConfigBuiltIn(t *testing.T) {
} }
mockOracle := newMockInteropBootstrapOracle(expected, false) mockOracle := newMockInteropBootstrapOracle(expected, false)
actual := BootstrapInterop(mockOracle) actual := BootstrapInterop(mockOracle)
actualCfg, err := actual.Configs.ChainConfig(expectedCfg.ChainID.Uint64()) actualCfg, err := actual.Configs.ChainConfig(eth.ChainIDFromBig(expectedCfg.ChainID))
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, expectedCfg, actualCfg) require.Equal(t, expectedCfg, actualCfg)
} }
...@@ -94,11 +95,11 @@ func TestInteropBootstrap_ChainConfigCustom(t *testing.T) { ...@@ -94,11 +95,11 @@ func TestInteropBootstrap_ChainConfigCustom(t *testing.T) {
mockOracle.chainCfgs = []*params.ChainConfig{config1, config2} mockOracle.chainCfgs = []*params.ChainConfig{config1, config2}
actual := BootstrapInterop(mockOracle) actual := BootstrapInterop(mockOracle)
actualCfg, err := actual.Configs.ChainConfig(config1.ChainID.Uint64()) actualCfg, err := actual.Configs.ChainConfig(eth.ChainIDFromBig(config1.ChainID))
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, config1, actualCfg) require.Equal(t, config1, actualCfg)
actualCfg, err = actual.Configs.ChainConfig(config2.ChainID.Uint64()) actualCfg, err = actual.Configs.ChainConfig(eth.ChainIDFromBig(config2.ChainID))
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, config2, actualCfg) require.Equal(t, config2, actualCfg)
} }
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"github.com/ethereum-optimism/optimism/op-node/chaincfg" "github.com/ethereum-optimism/optimism/op-node/chaincfg"
preimage "github.com/ethereum-optimism/optimism/op-preimage" preimage "github.com/ethereum-optimism/optimism/op-preimage"
"github.com/ethereum-optimism/optimism/op-program/chainconfig" "github.com/ethereum-optimism/optimism/op-program/chainconfig"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
...@@ -20,7 +21,7 @@ func TestBootstrapClient(t *testing.T) { ...@@ -20,7 +21,7 @@ func TestBootstrapClient(t *testing.T) {
L2OutputRoot: common.HexToHash("0x2222"), L2OutputRoot: common.HexToHash("0x2222"),
L2Claim: common.HexToHash("0x3333"), L2Claim: common.HexToHash("0x3333"),
L2ClaimBlockNumber: 1, L2ClaimBlockNumber: 1,
L2ChainID: rollupCfg.L2ChainID.Uint64(), L2ChainID: eth.ChainIDFromBig(rollupCfg.L2ChainID),
L2ChainConfig: chainconfig.OPSepoliaChainConfig(), L2ChainConfig: chainconfig.OPSepoliaChainConfig(),
RollupConfig: rollupCfg, RollupConfig: rollupCfg,
} }
...@@ -50,7 +51,7 @@ func TestBootstrapClient_UnknownChainPanics(t *testing.T) { ...@@ -50,7 +51,7 @@ func TestBootstrapClient_UnknownChainPanics(t *testing.T) {
L2OutputRoot: common.HexToHash("0x2222"), L2OutputRoot: common.HexToHash("0x2222"),
L2Claim: common.HexToHash("0x3333"), L2Claim: common.HexToHash("0x3333"),
L2ClaimBlockNumber: 1, L2ClaimBlockNumber: 1,
L2ChainID: uint64(0xdead), L2ChainID: eth.ChainID{0xdead},
} }
mockOracle := newMockPreinteropBootstrapOracle(bootInfo, false) mockOracle := newMockPreinteropBootstrapOracle(bootInfo, false)
client := NewBootstrapClient(mockOracle) client := NewBootstrapClient(mockOracle)
...@@ -79,7 +80,7 @@ type mockPreinteropBoostrapOracle struct { ...@@ -79,7 +80,7 @@ type mockPreinteropBoostrapOracle struct {
func (o *mockPreinteropBoostrapOracle) Get(key preimage.Key) []byte { func (o *mockPreinteropBoostrapOracle) Get(key preimage.Key) []byte {
switch key.PreimageKey() { switch key.PreimageKey() {
case L2ChainIDLocalIndex.PreimageKey(): case L2ChainIDLocalIndex.PreimageKey():
return binary.BigEndian.AppendUint64(nil, o.b.L2ChainID) return binary.BigEndian.AppendUint64(nil, eth.EvilChainIDToUInt64(o.b.L2ChainID))
case L2ChainConfigLocalIndex.PreimageKey(): case L2ChainConfigLocalIndex.PreimageKey():
if !o.custom { if !o.custom {
panic(fmt.Sprintf("unexpected oracle request for preimage key %x", key.PreimageKey())) panic(fmt.Sprintf("unexpected oracle request for preimage key %x", key.PreimageKey()))
......
...@@ -55,7 +55,7 @@ func RunConsolidation(deps ConsolidateCheckDeps, ...@@ -55,7 +55,7 @@ func RunConsolidation(deps ConsolidateCheckDeps,
Number: block.NumberU64(), Number: block.NumberU64(),
Timestamp: block.Time(), Timestamp: block.Time(),
} }
if err := checkHazards(deps, candidate, eth.ChainIDFromUInt64(chain.ChainID), execMsgs); err != nil { if err := checkHazards(deps, candidate, chain.ChainID, execMsgs); err != nil {
// TODO(#13776): replace with deposit-only block if ErrConflict, ErrCycle, or ErrFuture // TODO(#13776): replace with deposit-only block if ErrConflict, ErrCycle, or ErrFuture
return eth.Bytes32{}, err return eth.Bytes32{}, err
} }
...@@ -106,7 +106,7 @@ func checkHazards( ...@@ -106,7 +106,7 @@ func checkHazards(
type consolidateCheckDeps struct { type consolidateCheckDeps struct {
oracle l2.Oracle oracle l2.Oracle
depset depset.DependencySet depset depset.DependencySet
canonBlocks map[uint64]*l2.CanonicalBlockHeaderOracle canonBlocks map[eth.ChainID]*l2.CanonicalBlockHeaderOracle
} }
func newConsolidateCheckDeps(chains []eth.ChainIDAndOutput, oracle l2.Oracle) (*consolidateCheckDeps, error) { func newConsolidateCheckDeps(chains []eth.ChainIDAndOutput, oracle l2.Oracle) (*consolidateCheckDeps, error) {
...@@ -114,14 +114,14 @@ func newConsolidateCheckDeps(chains []eth.ChainIDAndOutput, oracle l2.Oracle) (* ...@@ -114,14 +114,14 @@ func newConsolidateCheckDeps(chains []eth.ChainIDAndOutput, oracle l2.Oracle) (*
// TODO: Also replace dep set stubs with the actual dependency set in the RollupConfig. // TODO: Also replace dep set stubs with the actual dependency set in the RollupConfig.
deps := make(map[eth.ChainID]*depset.StaticConfigDependency) deps := make(map[eth.ChainID]*depset.StaticConfigDependency)
for i, chain := range chains { for i, chain := range chains {
deps[eth.ChainIDFromUInt64(chain.ChainID)] = &depset.StaticConfigDependency{ deps[chain.ChainID] = &depset.StaticConfigDependency{
ChainIndex: supervisortypes.ChainIndex(i), ChainIndex: supervisortypes.ChainIndex(i),
ActivationTime: 0, ActivationTime: 0,
HistoryMinTime: 0, HistoryMinTime: 0,
} }
} }
canonBlocks := make(map[uint64]*l2.CanonicalBlockHeaderOracle) canonBlocks := make(map[eth.ChainID]*l2.CanonicalBlockHeaderOracle)
for _, chain := range chains { for _, chain := range chains {
output := oracle.OutputByRoot(common.Hash(chain.Output), chain.ChainID) output := oracle.OutputByRoot(common.Hash(chain.Output), chain.ChainID)
outputV0, ok := output.(*eth.OutputV0) outputV0, ok := output.(*eth.OutputV0)
...@@ -155,7 +155,7 @@ func (d *consolidateCheckDeps) Check( ...@@ -155,7 +155,7 @@ func (d *consolidateCheckDeps) Check(
logHash common.Hash, logHash common.Hash,
) (includedIn supervisortypes.BlockSeal, err error) { ) (includedIn supervisortypes.BlockSeal, err error) {
// We can assume the oracle has the block the executing message is in // We can assume the oracle has the block the executing message is in
block, err := d.BlockByNumber(d.oracle, blockNum, chain.ToBig().Uint64()) block, err := d.BlockByNumber(d.oracle, blockNum, chain)
if err != nil { if err != nil {
return supervisortypes.BlockSeal{}, err return supervisortypes.BlockSeal{}, err
} }
...@@ -177,7 +177,7 @@ func (d *consolidateCheckDeps) IsLocalUnsafe(chainID eth.ChainID, block eth.Bloc ...@@ -177,7 +177,7 @@ func (d *consolidateCheckDeps) IsLocalUnsafe(chainID eth.ChainID, block eth.Bloc
} }
func (d *consolidateCheckDeps) ParentBlock(chainID eth.ChainID, parentOf eth.BlockID) (parent eth.BlockID, err error) { func (d *consolidateCheckDeps) ParentBlock(chainID eth.ChainID, parentOf eth.BlockID) (parent eth.BlockID, err error) {
block, err := d.BlockByNumber(d.oracle, parentOf.Number-1, chainID.ToBig().Uint64()) block, err := d.BlockByNumber(d.oracle, parentOf.Number-1, chainID)
if err != nil { if err != nil {
return eth.BlockID{}, err return eth.BlockID{}, err
} }
...@@ -191,7 +191,7 @@ func (d *consolidateCheckDeps) OpenBlock( ...@@ -191,7 +191,7 @@ func (d *consolidateCheckDeps) OpenBlock(
chainID eth.ChainID, chainID eth.ChainID,
blockNum uint64, blockNum uint64,
) (ref eth.BlockRef, logCount uint32, execMsgs map[uint32]*supervisortypes.ExecutingMessage, err error) { ) (ref eth.BlockRef, logCount uint32, execMsgs map[uint32]*supervisortypes.ExecutingMessage, err error) {
block, err := d.BlockByNumber(d.oracle, blockNum, chainID.ToBig().Uint64()) block, err := d.BlockByNumber(d.oracle, blockNum, chainID)
if err != nil { if err != nil {
return eth.BlockRef{}, 0, nil, err return eth.BlockRef{}, 0, nil, err
} }
...@@ -199,7 +199,7 @@ func (d *consolidateCheckDeps) OpenBlock( ...@@ -199,7 +199,7 @@ func (d *consolidateCheckDeps) OpenBlock(
Hash: block.Hash(), Hash: block.Hash(),
Number: block.NumberU64(), Number: block.NumberU64(),
} }
_, receipts := d.oracle.ReceiptsByBlockHash(block.Hash(), chainID.ToBig().Uint64()) _, receipts := d.oracle.ReceiptsByBlockHash(block.Hash(), chainID)
execs, logCount, err := ReceiptsToExecutingMessages(d.depset, receipts) execs, logCount, err := ReceiptsToExecutingMessages(d.depset, receipts)
if err != nil { if err != nil {
return eth.BlockRef{}, 0, nil, err return eth.BlockRef{}, 0, nil, err
...@@ -215,7 +215,7 @@ func (d *consolidateCheckDeps) DependencySet() depset.DependencySet { ...@@ -215,7 +215,7 @@ func (d *consolidateCheckDeps) DependencySet() depset.DependencySet {
return d.depset return d.depset
} }
func (d *consolidateCheckDeps) BlockByNumber(oracle l2.Oracle, blockNum uint64, chainID uint64) (*ethtypes.Block, error) { func (d *consolidateCheckDeps) BlockByNumber(oracle l2.Oracle, blockNum uint64, chainID eth.ChainID) (*ethtypes.Block, error) {
head := d.canonBlocks[chainID].GetHeaderByNumber(blockNum) head := d.canonBlocks[chainID].GetHeaderByNumber(blockNum)
if head == nil { if head == nil {
return nil, fmt.Errorf("head not found for chain %v", chainID) return nil, fmt.Errorf("head not found for chain %v", chainID)
......
...@@ -36,8 +36,8 @@ func setupTwoChains() (*staticConfigSource, *eth.SuperV1, stubTasks) { ...@@ -36,8 +36,8 @@ func setupTwoChains() (*staticConfigSource, *eth.SuperV1, stubTasks) {
agreedSuperRoot := &eth.SuperV1{ agreedSuperRoot := &eth.SuperV1{
Timestamp: rollupCfg1.Genesis.L2Time + 1234, Timestamp: rollupCfg1.Genesis.L2Time + 1234,
Chains: []eth.ChainIDAndOutput{ Chains: []eth.ChainIDAndOutput{
{ChainID: rollupCfg1.L2ChainID.Uint64(), Output: eth.OutputRoot(&eth.OutputV0{BlockHash: common.Hash{0x11}})}, {ChainID: eth.ChainIDFromBig(rollupCfg1.L2ChainID), Output: eth.OutputRoot(&eth.OutputV0{BlockHash: common.Hash{0x11}})},
{ChainID: rollupCfg2.L2ChainID.Uint64(), Output: eth.OutputRoot(&eth.OutputV0{BlockHash: common.Hash{0x22}})}, {ChainID: eth.ChainIDFromBig(rollupCfg2.L2ChainID), Output: eth.OutputRoot(&eth.OutputV0{BlockHash: common.Hash{0x22}})},
}, },
} }
configSource := &staticConfigSource{ configSource := &staticConfigSource{
...@@ -152,11 +152,11 @@ func TestDeriveBlockForConsolidateStep(t *testing.T) { ...@@ -152,11 +152,11 @@ func TestDeriveBlockForConsolidateStep(t *testing.T) {
Timestamp: agreedSuperRoot.Timestamp + 1, Timestamp: agreedSuperRoot.Timestamp + 1,
Chains: []eth.ChainIDAndOutput{ Chains: []eth.ChainIDAndOutput{
{ {
ChainID: configSource.rollupCfgs[0].L2ChainID.Uint64(), ChainID: eth.ChainIDFromBig(configSource.rollupCfgs[0].L2ChainID),
Output: agreedTransitionState.PendingProgress[0].OutputRoot, Output: agreedTransitionState.PendingProgress[0].OutputRoot,
}, },
{ {
ChainID: configSource.rollupCfgs[1].L2ChainID.Uint64(), ChainID: eth.ChainIDFromBig(configSource.rollupCfgs[1].L2ChainID),
Output: agreedTransitionState.PendingProgress[1].OutputRoot, Output: agreedTransitionState.PendingProgress[1].OutputRoot,
}, },
}, },
...@@ -248,18 +248,18 @@ type staticConfigSource struct { ...@@ -248,18 +248,18 @@ type staticConfigSource struct {
chainConfigs []*params.ChainConfig chainConfigs []*params.ChainConfig
} }
func (s *staticConfigSource) RollupConfig(chainID uint64) (*rollup.Config, error) { func (s *staticConfigSource) RollupConfig(chainID eth.ChainID) (*rollup.Config, error) {
for _, cfg := range s.rollupCfgs { for _, cfg := range s.rollupCfgs {
if cfg.L2ChainID.Uint64() == chainID { if eth.ChainIDFromBig(cfg.L2ChainID) == chainID {
return cfg, nil return cfg, nil
} }
} }
return nil, fmt.Errorf("no rollup config found for chain %d", chainID) return nil, fmt.Errorf("no rollup config found for chain %d", chainID)
} }
func (s *staticConfigSource) ChainConfig(chainID uint64) (*params.ChainConfig, error) { func (s *staticConfigSource) ChainConfig(chainID eth.ChainID) (*params.ChainConfig, error) {
for _, cfg := range s.chainConfigs { for _, cfg := range s.chainConfigs {
if cfg.ChainID.Uint64() == chainID { if eth.ChainIDFromBig(cfg.ChainID) == chainID {
return cfg, nil return cfg, nil
} }
} }
......
...@@ -13,8 +13,8 @@ func TestTransitionStateCodec(t *testing.T) { ...@@ -13,8 +13,8 @@ func TestTransitionStateCodec(t *testing.T) {
superRoot := &eth.SuperV1{ superRoot := &eth.SuperV1{
Timestamp: 9842494, Timestamp: 9842494,
Chains: []eth.ChainIDAndOutput{ Chains: []eth.ChainIDAndOutput{
{ChainID: 34, Output: eth.Bytes32{0x01}}, {ChainID: eth.ChainIDFromUInt64(34), Output: eth.Bytes32{0x01}},
{ChainID: 35, Output: eth.Bytes32{0x02}}, {ChainID: eth.ChainIDFromUInt64(35), Output: eth.Bytes32{0x02}},
}, },
} }
state := &TransitionState{ state := &TransitionState{
...@@ -35,8 +35,8 @@ func TestTransitionStateCodec(t *testing.T) { ...@@ -35,8 +35,8 @@ func TestTransitionStateCodec(t *testing.T) {
superRoot := &eth.SuperV1{ superRoot := &eth.SuperV1{
Timestamp: 9842494, Timestamp: 9842494,
Chains: []eth.ChainIDAndOutput{ Chains: []eth.ChainIDAndOutput{
{ChainID: 34, Output: eth.Bytes32{0x01}}, {ChainID: eth.ChainIDFromUInt64(34), Output: eth.Bytes32{0x01}},
{ChainID: 35, Output: eth.Bytes32{0x02}}, {ChainID: eth.ChainIDFromUInt64(35), Output: eth.Bytes32{0x02}},
}, },
} }
expected := &TransitionState{ expected := &TransitionState{
......
...@@ -40,7 +40,7 @@ func NewCachingOracle(oracle Oracle) *CachingOracle { ...@@ -40,7 +40,7 @@ func NewCachingOracle(oracle Oracle) *CachingOracle {
} }
} }
func (o *CachingOracle) NodeByHash(nodeHash common.Hash, chainID uint64) []byte { func (o *CachingOracle) NodeByHash(nodeHash common.Hash, chainID eth.ChainID) []byte {
node, ok := o.nodes.Get(nodeHash) node, ok := o.nodes.Get(nodeHash)
if ok { if ok {
return node return node
...@@ -50,7 +50,7 @@ func (o *CachingOracle) NodeByHash(nodeHash common.Hash, chainID uint64) []byte ...@@ -50,7 +50,7 @@ func (o *CachingOracle) NodeByHash(nodeHash common.Hash, chainID uint64) []byte
return node return node
} }
func (o *CachingOracle) ReceiptsByBlockHash(blockHash common.Hash, chainID uint64) (*types.Block, types.Receipts) { func (o *CachingOracle) ReceiptsByBlockHash(blockHash common.Hash, chainID eth.ChainID) (*types.Block, types.Receipts) {
rcpts, ok := o.rcpts.Get(blockHash) rcpts, ok := o.rcpts.Get(blockHash)
if ok { if ok {
return o.BlockByHash(blockHash, chainID), rcpts return o.BlockByHash(blockHash, chainID), rcpts
...@@ -61,7 +61,7 @@ func (o *CachingOracle) ReceiptsByBlockHash(blockHash common.Hash, chainID uint6 ...@@ -61,7 +61,7 @@ func (o *CachingOracle) ReceiptsByBlockHash(blockHash common.Hash, chainID uint6
return block, rcpts return block, rcpts
} }
func (o *CachingOracle) CodeByHash(codeHash common.Hash, chainID uint64) []byte { func (o *CachingOracle) CodeByHash(codeHash common.Hash, chainID eth.ChainID) []byte {
code, ok := o.codes.Get(codeHash) code, ok := o.codes.Get(codeHash)
if ok { if ok {
return code return code
...@@ -71,7 +71,7 @@ func (o *CachingOracle) CodeByHash(codeHash common.Hash, chainID uint64) []byte ...@@ -71,7 +71,7 @@ func (o *CachingOracle) CodeByHash(codeHash common.Hash, chainID uint64) []byte
return code return code
} }
func (o *CachingOracle) BlockByHash(blockHash common.Hash, chainID uint64) *types.Block { func (o *CachingOracle) BlockByHash(blockHash common.Hash, chainID eth.ChainID) *types.Block {
block, ok := o.blocks.Get(blockHash) block, ok := o.blocks.Get(blockHash)
if ok { if ok {
return block return block
...@@ -81,7 +81,7 @@ func (o *CachingOracle) BlockByHash(blockHash common.Hash, chainID uint64) *type ...@@ -81,7 +81,7 @@ func (o *CachingOracle) BlockByHash(blockHash common.Hash, chainID uint64) *type
return block return block
} }
func (o *CachingOracle) OutputByRoot(root common.Hash, chainID uint64) eth.Output { func (o *CachingOracle) OutputByRoot(root common.Hash, chainID eth.ChainID) eth.Output {
output, ok := o.outputs.Get(root) output, ok := o.outputs.Get(root)
if ok { if ok {
return output return output
...@@ -91,7 +91,7 @@ func (o *CachingOracle) OutputByRoot(root common.Hash, chainID uint64) eth.Outpu ...@@ -91,7 +91,7 @@ func (o *CachingOracle) OutputByRoot(root common.Hash, chainID uint64) eth.Outpu
return output return output
} }
func (o *CachingOracle) BlockDataByHash(agreedBlockHash, blockHash common.Hash, chainID uint64) *types.Block { func (o *CachingOracle) BlockDataByHash(agreedBlockHash, blockHash common.Hash, chainID eth.ChainID) *types.Block {
// Always request from the oracle even on cache hit. as we want the effects of the host oracle hinting // Always request from the oracle even on cache hit. as we want the effects of the host oracle hinting
block := o.oracle.BlockDataByHash(agreedBlockHash, blockHash, chainID) block := o.oracle.BlockDataByHash(agreedBlockHash, blockHash, chainID)
o.blocks.Add(blockHash, block) o.blocks.Add(blockHash, block)
......
...@@ -24,12 +24,12 @@ func TestBlockByHash(t *testing.T) { ...@@ -24,12 +24,12 @@ func TestBlockByHash(t *testing.T) {
// Initial call retrieves from the stub // Initial call retrieves from the stub
stub.Blocks[block.Hash()] = block stub.Blocks[block.Hash()] = block
actual := oracle.BlockByHash(block.Hash(), chainID) actual := oracle.BlockByHash(block.Hash(), eth.ChainIDFromUInt64(chainID))
require.Equal(t, block, actual) require.Equal(t, block, actual)
// Later calls should retrieve from cache (even if chain ID is different) // Later calls should retrieve from cache (even if chain ID is different)
delete(stub.Blocks, block.Hash()) delete(stub.Blocks, block.Hash())
actual = oracle.BlockByHash(block.Hash(), 9982) actual = oracle.BlockByHash(block.Hash(), eth.ChainIDFromUInt64(9982))
require.Equal(t, block, actual) require.Equal(t, block, actual)
} }
...@@ -42,17 +42,17 @@ func TestNodeByHash(t *testing.T) { ...@@ -42,17 +42,17 @@ func TestNodeByHash(t *testing.T) {
// Initial call retrieves from the stub // Initial call retrieves from the stub
stateStub.Data[hash] = node stateStub.Data[hash] = node
actual := oracle.NodeByHash(hash, 1234) actual := oracle.NodeByHash(hash, eth.ChainIDFromUInt64(1234))
require.Equal(t, node, actual) require.Equal(t, node, actual)
// Later calls should retrieve from cache (even if chain ID is different) // Later calls should retrieve from cache (even if chain ID is different)
delete(stateStub.Data, hash) delete(stateStub.Data, hash)
actual = oracle.NodeByHash(hash, 997845) actual = oracle.NodeByHash(hash, eth.ChainIDFromUInt64(997845))
require.Equal(t, node, actual) require.Equal(t, node, actual)
} }
func TestReceiptsByBlockHash(t *testing.T) { func TestReceiptsByBlockHash(t *testing.T) {
chainID := uint64(48294) chainID := eth.ChainIDFromUInt64(48294)
stub, _ := test.NewStubOracle(t) stub, _ := test.NewStubOracle(t)
oracle := NewCachingOracle(stub) oracle := NewCachingOracle(stub)
...@@ -69,7 +69,7 @@ func TestReceiptsByBlockHash(t *testing.T) { ...@@ -69,7 +69,7 @@ func TestReceiptsByBlockHash(t *testing.T) {
// Later calls should retrieve from cache (even if chain ID is different) // Later calls should retrieve from cache (even if chain ID is different)
delete(stub.Blocks, block.Hash()) delete(stub.Blocks, block.Hash())
delete(stub.Receipts, block.Hash()) delete(stub.Receipts, block.Hash())
actualBlock, actualRcpts = oracle.ReceiptsByBlockHash(block.Hash(), 9982) actualBlock, actualRcpts = oracle.ReceiptsByBlockHash(block.Hash(), eth.ChainIDFromUInt64(9982))
require.EqualValues(t, block, actualBlock) require.EqualValues(t, block, actualBlock)
require.EqualValues(t, rcpts, actualRcpts) require.EqualValues(t, rcpts, actualRcpts)
} }
...@@ -83,12 +83,12 @@ func TestCodeByHash(t *testing.T) { ...@@ -83,12 +83,12 @@ func TestCodeByHash(t *testing.T) {
// Initial call retrieves from the stub // Initial call retrieves from the stub
stateStub.Code[hash] = node stateStub.Code[hash] = node
actual := oracle.CodeByHash(hash, 342) actual := oracle.CodeByHash(hash, eth.ChainIDFromUInt64(342))
require.Equal(t, node, actual) require.Equal(t, node, actual)
// Later calls should retrieve from cache (even if the chain ID is different) // Later calls should retrieve from cache (even if the chain ID is different)
delete(stateStub.Code, hash) delete(stateStub.Code, hash)
actual = oracle.CodeByHash(hash, 986776) actual = oracle.CodeByHash(hash, eth.ChainIDFromUInt64(986776))
require.Equal(t, node, actual) require.Equal(t, node, actual)
} }
...@@ -102,11 +102,11 @@ func TestOutputByRoot(t *testing.T) { ...@@ -102,11 +102,11 @@ func TestOutputByRoot(t *testing.T) {
// Initial call retrieves from the stub // Initial call retrieves from the stub
root := common.Hash(eth.OutputRoot(output)) root := common.Hash(eth.OutputRoot(output))
stub.Outputs[root] = output stub.Outputs[root] = output
actual := oracle.OutputByRoot(root, 59284) actual := oracle.OutputByRoot(root, eth.ChainIDFromUInt64(59284))
require.Equal(t, output, actual) require.Equal(t, output, actual)
// Later calls should retrieve from cache (even if the chain ID is different) // Later calls should retrieve from cache (even if the chain ID is different)
delete(stub.Outputs, root) delete(stub.Outputs, root)
actual = oracle.OutputByRoot(root, 9193) actual = oracle.OutputByRoot(root, eth.ChainIDFromUInt64(9193))
require.Equal(t, output, actual) require.Equal(t, output, actual)
} }
...@@ -3,6 +3,7 @@ package l2 ...@@ -3,6 +3,7 @@ package l2
import ( import (
"testing" "testing"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
...@@ -21,7 +22,7 @@ func TestCanonicalBlockNumberOracle_GetHeaderByNumber(t *testing.T) { ...@@ -21,7 +22,7 @@ func TestCanonicalBlockNumberOracle_GetHeaderByNumber(t *testing.T) {
t.Fatalf("Requested duplicate block: %v", hash) t.Fatalf("Requested duplicate block: %v", hash)
} }
requestedBlocks[hash] = true requestedBlocks[hash] = true
return oracle.BlockByHash(hash, chainCfg.ChainID.Uint64()) return oracle.BlockByHash(hash, eth.ChainIDFromBig(chainCfg.ChainID))
} }
canon := NewCanonicalBlockHeaderOracle(head, blockByHash) canon := NewCanonicalBlockHeaderOracle(head, blockByHash)
require.Equal(t, head.Hash(), canon.CurrentHeader().Hash()) require.Equal(t, head.Hash(), canon.CurrentHeader().Hash())
...@@ -63,7 +64,7 @@ func TestCanonicalBlockNumberOracle_SetCanonical(t *testing.T) { ...@@ -63,7 +64,7 @@ func TestCanonicalBlockNumberOracle_SetCanonical(t *testing.T) {
blockRequestCount := 0 blockRequestCount := 0
blockByHash := func(hash common.Hash) *types.Block { blockByHash := func(hash common.Hash) *types.Block {
blockRequestCount++ blockRequestCount++
return oracle.BlockByHash(hash, chainCfg.ChainID.Uint64()) return oracle.BlockByHash(hash, eth.ChainIDFromBig(chainCfg.ChainID))
} }
canon := NewCanonicalBlockHeaderOracle(head, blockByHash) canon := NewCanonicalBlockHeaderOracle(head, blockByHash)
oracle.Blocks[blocks[2].Hash()] = blocks[2] oracle.Blocks[blocks[2].Hash()] = blocks[2]
...@@ -100,7 +101,7 @@ func TestCanonicalBlockNumberOracle_SetCanonical(t *testing.T) { ...@@ -100,7 +101,7 @@ func TestCanonicalBlockNumberOracle_SetCanonical(t *testing.T) {
head := blocks[headBlockNumber].Header() head := blocks[headBlockNumber].Header()
blockByHash := func(hash common.Hash) *types.Block { blockByHash := func(hash common.Hash) *types.Block {
return oracle.BlockByHash(hash, chainCfg.ChainID.Uint64()) return oracle.BlockByHash(hash, eth.ChainIDFromBig(chainCfg.ChainID))
} }
canon := NewCanonicalBlockHeaderOracle(head, blockByHash) canon := NewCanonicalBlockHeaderOracle(head, blockByHash)
oracle.Blocks[blocks[2].Hash()] = blocks[2] oracle.Blocks[blocks[2].Hash()] = blocks[2]
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
...@@ -18,10 +19,10 @@ var ErrInvalidKeyLength = errors.New("pre-images must be identified by 32-byte h ...@@ -18,10 +19,10 @@ var ErrInvalidKeyLength = errors.New("pre-images must be identified by 32-byte h
type OracleKeyValueStore struct { type OracleKeyValueStore struct {
db ethdb.KeyValueStore db ethdb.KeyValueStore
oracle StateOracle oracle StateOracle
chainID uint64 chainID eth.ChainID
} }
func NewOracleBackedDB(oracle StateOracle, chainID uint64) *OracleKeyValueStore { func NewOracleBackedDB(oracle StateOracle, chainID eth.ChainID) *OracleKeyValueStore {
return &OracleKeyValueStore{ return &OracleKeyValueStore{
db: memorydb.New(), db: memorydb.New(),
oracle: oracle, oracle: oracle,
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"testing" "testing"
"github.com/ethereum-optimism/optimism/op-program/client/l2/test" "github.com/ethereum-optimism/optimism/op-program/client/l2/test"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
...@@ -34,7 +35,7 @@ var _ ethdb.KeyValueStore = (*OracleKeyValueStore)(nil) ...@@ -34,7 +35,7 @@ var _ ethdb.KeyValueStore = (*OracleKeyValueStore)(nil)
func TestGet(t *testing.T) { func TestGet(t *testing.T) {
t.Run("IncorrectLengthKey", func(t *testing.T) { t.Run("IncorrectLengthKey", func(t *testing.T) {
oracle := test.NewStubStateOracle(t) oracle := test.NewStubStateOracle(t)
db := NewOracleBackedDB(oracle, 1234) db := NewOracleBackedDB(oracle, eth.ChainIDFromUInt64(1234))
val, err := db.Get([]byte{1, 2, 3}) val, err := db.Get([]byte{1, 2, 3})
require.ErrorIs(t, err, ErrInvalidKeyLength) require.ErrorIs(t, err, ErrInvalidKeyLength)
require.Nil(t, val) require.Nil(t, val)
...@@ -42,7 +43,7 @@ func TestGet(t *testing.T) { ...@@ -42,7 +43,7 @@ func TestGet(t *testing.T) {
t.Run("KeyWithCodePrefix", func(t *testing.T) { t.Run("KeyWithCodePrefix", func(t *testing.T) {
oracle := test.NewStubStateOracle(t) oracle := test.NewStubStateOracle(t)
db := NewOracleBackedDB(oracle, 1234) db := NewOracleBackedDB(oracle, eth.ChainIDFromUInt64(1234))
key := common.HexToHash("0x12345678") key := common.HexToHash("0x12345678")
prefixedKey := append(rawdb.CodePrefix, key.Bytes()...) prefixedKey := append(rawdb.CodePrefix, key.Bytes()...)
...@@ -56,7 +57,7 @@ func TestGet(t *testing.T) { ...@@ -56,7 +57,7 @@ func TestGet(t *testing.T) {
t.Run("NormalKeyThatHappensToStartWithCodePrefix", func(t *testing.T) { t.Run("NormalKeyThatHappensToStartWithCodePrefix", func(t *testing.T) {
oracle := test.NewStubStateOracle(t) oracle := test.NewStubStateOracle(t)
db := NewOracleBackedDB(oracle, 1234) db := NewOracleBackedDB(oracle, eth.ChainIDFromUInt64(1234))
key := make([]byte, common.HashLength) key := make([]byte, common.HashLength)
copy(rawdb.CodePrefix, key) copy(rawdb.CodePrefix, key)
fmt.Println(key[0]) fmt.Println(key[0])
...@@ -73,7 +74,7 @@ func TestGet(t *testing.T) { ...@@ -73,7 +74,7 @@ func TestGet(t *testing.T) {
expected := []byte{2, 6, 3, 8} expected := []byte{2, 6, 3, 8}
oracle := test.NewStubStateOracle(t) oracle := test.NewStubStateOracle(t)
oracle.Data[key] = expected oracle.Data[key] = expected
db := NewOracleBackedDB(oracle, 1234) db := NewOracleBackedDB(oracle, eth.ChainIDFromUInt64(1234))
val, err := db.Get(key.Bytes()) val, err := db.Get(key.Bytes())
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, expected, val) require.Equal(t, expected, val)
...@@ -83,7 +84,7 @@ func TestGet(t *testing.T) { ...@@ -83,7 +84,7 @@ func TestGet(t *testing.T) {
func TestPut(t *testing.T) { func TestPut(t *testing.T) {
t.Run("NewKey", func(t *testing.T) { t.Run("NewKey", func(t *testing.T) {
oracle := test.NewStubStateOracle(t) oracle := test.NewStubStateOracle(t)
db := NewOracleBackedDB(oracle, 1234) db := NewOracleBackedDB(oracle, eth.ChainIDFromUInt64(1234))
key := common.HexToHash("0xAA4488") key := common.HexToHash("0xAA4488")
value := []byte{2, 6, 3, 8} value := []byte{2, 6, 3, 8}
err := db.Put(key.Bytes(), value) err := db.Put(key.Bytes(), value)
...@@ -95,7 +96,7 @@ func TestPut(t *testing.T) { ...@@ -95,7 +96,7 @@ func TestPut(t *testing.T) {
}) })
t.Run("ReplaceKey", func(t *testing.T) { t.Run("ReplaceKey", func(t *testing.T) {
oracle := test.NewStubStateOracle(t) oracle := test.NewStubStateOracle(t)
db := NewOracleBackedDB(oracle, 1234) db := NewOracleBackedDB(oracle, eth.ChainIDFromUInt64(1234))
key := common.HexToHash("0xAA4488") key := common.HexToHash("0xAA4488")
value1 := []byte{2, 6, 3, 8} value1 := []byte{2, 6, 3, 8}
value2 := []byte{1, 2, 3} value2 := []byte{1, 2, 3}
...@@ -117,13 +118,13 @@ func TestSupportsStateDBOperations(t *testing.T) { ...@@ -117,13 +118,13 @@ func TestSupportsStateDBOperations(t *testing.T) {
genesisBlock := l2Genesis.MustCommit(realDb, trieDB) genesisBlock := l2Genesis.MustCommit(realDb, trieDB)
loader := test.NewKvStateOracle(t, realDb) loader := test.NewKvStateOracle(t, realDb)
assertStateDataAvailable(t, NewOracleBackedDB(loader, 1234), l2Genesis, genesisBlock) assertStateDataAvailable(t, NewOracleBackedDB(loader, eth.ChainIDFromUInt64(1234)), l2Genesis, genesisBlock)
} }
func TestUpdateState(t *testing.T) { func TestUpdateState(t *testing.T) {
l2Genesis := createGenesis() l2Genesis := createGenesis()
oracle := test.NewStubStateOracle(t) oracle := test.NewStubStateOracle(t)
db := rawdb.NewDatabase(NewOracleBackedDB(oracle, 1234)) db := rawdb.NewDatabase(NewOracleBackedDB(oracle, eth.ChainIDFromUInt64(1234)))
trieDB := triedb.NewDatabase(db, &triedb.Config{HashDB: hashdb.Defaults}) trieDB := triedb.NewDatabase(db, &triedb.Config{HashDB: hashdb.Defaults})
genesisBlock := l2Genesis.MustCommit(db, trieDB) genesisBlock := l2Genesis.MustCommit(db, trieDB)
......
...@@ -42,7 +42,7 @@ type OracleBackedL2Chain struct { ...@@ -42,7 +42,7 @@ type OracleBackedL2Chain struct {
var _ engineapi.CachingEngineBackend = (*OracleBackedL2Chain)(nil) var _ engineapi.CachingEngineBackend = (*OracleBackedL2Chain)(nil)
func NewOracleBackedL2Chain(logger log.Logger, oracle Oracle, precompileOracle engineapi.PrecompileOracle, chainCfg *params.ChainConfig, l2OutputRoot common.Hash) (*OracleBackedL2Chain, error) { func NewOracleBackedL2Chain(logger log.Logger, oracle Oracle, precompileOracle engineapi.PrecompileOracle, chainCfg *params.ChainConfig, l2OutputRoot common.Hash) (*OracleBackedL2Chain, error) {
chainID := chainCfg.ChainID.Uint64() chainID := eth.ChainIDFromBig(chainCfg.ChainID)
output := oracle.OutputByRoot(l2OutputRoot, chainID) output := oracle.OutputByRoot(l2OutputRoot, chainID)
outputV0, ok := output.(*eth.OutputV0) outputV0, ok := output.(*eth.OutputV0)
if !ok { if !ok {
...@@ -107,7 +107,7 @@ func (o *OracleBackedL2Chain) GetBlockByHash(hash common.Hash) *types.Block { ...@@ -107,7 +107,7 @@ func (o *OracleBackedL2Chain) GetBlockByHash(hash common.Hash) *types.Block {
return block return block
} }
// Retrieve from the oracle // Retrieve from the oracle
return o.oracle.BlockByHash(hash, o.chainCfg.ChainID.Uint64()) return o.oracle.BlockByHash(hash, eth.ChainIDFromBig(o.chainCfg.ChainID))
} }
func (o *OracleBackedL2Chain) GetBlock(hash common.Hash, number uint64) *types.Block { func (o *OracleBackedL2Chain) GetBlock(hash common.Hash, number uint64) *types.Block {
......
...@@ -378,7 +378,7 @@ func createBlock(t *testing.T, chain *OracleBackedL2Chain, opts ...blockCreateOp ...@@ -378,7 +378,7 @@ func createBlock(t *testing.T, chain *OracleBackedL2Chain, opts ...blockCreateOp
require.NoError(t, err) require.NoError(t, err)
nonce := parentDB.GetNonce(fundedAddress) nonce := parentDB.GetNonce(fundedAddress)
config := chain.Config() config := chain.Config()
db := rawdb.NewDatabase(NewOracleBackedDB(chain.oracle, config.ChainID.Uint64())) db := rawdb.NewDatabase(NewOracleBackedDB(chain.oracle, eth.ChainIDFromBig(config.ChainID)))
blocks, _ := core.GenerateChain(config, parent, chain.Engine(), db, 1, func(i int, gen *core.BlockGen) { blocks, _ := core.GenerateChain(config, parent, chain.Engine(), db, 1, func(i int, gen *core.BlockGen) {
rawTx := &types.DynamicFeeTx{ rawTx := &types.DynamicFeeTx{
ChainID: config.ChainID, ChainID: config.ChainID,
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
...@@ -31,13 +32,13 @@ func (l LegacyBlockHeaderHint) Hint() string { ...@@ -31,13 +32,13 @@ func (l LegacyBlockHeaderHint) Hint() string {
type HashAndChainID struct { type HashAndChainID struct {
Hash common.Hash Hash common.Hash
ChainID uint64 ChainID eth.ChainID
} }
func (h HashAndChainID) Marshal() []byte { func (h HashAndChainID) Marshal() []byte {
d := make([]byte, 32+8) d := make([]byte, 32+8)
copy(d[:32], h.Hash[:]) copy(d[:32], h.Hash[:])
binary.BigEndian.PutUint64(d[32:], h.ChainID) binary.BigEndian.PutUint64(d[32:], eth.EvilChainIDToUInt64(h.ChainID))
return d return d
} }
...@@ -124,7 +125,7 @@ func (l LegacyL2OutputHint) Hint() string { ...@@ -124,7 +125,7 @@ func (l LegacyL2OutputHint) Hint() string {
type L2BlockDataHint struct { type L2BlockDataHint struct {
AgreedBlockHash common.Hash AgreedBlockHash common.Hash
BlockHash common.Hash BlockHash common.Hash
ChainID uint64 ChainID eth.ChainID
} }
var _ preimage.Hint = L2BlockDataHint{} var _ preimage.Hint = L2BlockDataHint{}
...@@ -133,7 +134,7 @@ func (l L2BlockDataHint) Hint() string { ...@@ -133,7 +134,7 @@ func (l L2BlockDataHint) Hint() string {
hintBytes := make([]byte, 32+32+8) hintBytes := make([]byte, 32+32+8)
copy(hintBytes[:32], (common.Hash)(l.AgreedBlockHash).Bytes()) copy(hintBytes[:32], (common.Hash)(l.AgreedBlockHash).Bytes())
copy(hintBytes[32:64], (common.Hash)(l.BlockHash).Bytes()) copy(hintBytes[32:64], (common.Hash)(l.BlockHash).Bytes())
binary.BigEndian.PutUint64(hintBytes[64:], l.ChainID) binary.BigEndian.PutUint64(hintBytes[64:], eth.EvilChainIDToUInt64(l.ChainID))
return fmt.Sprintf("%s 0x%s", HintL2BlockData, common.Bytes2Hex(hintBytes)) return fmt.Sprintf("%s 0x%s", HintL2BlockData, common.Bytes2Hex(hintBytes))
} }
......
...@@ -19,11 +19,11 @@ type StateOracle interface { ...@@ -19,11 +19,11 @@ type StateOracle interface {
// NodeByHash retrieves the merkle-patricia trie node pre-image for a given hash. // NodeByHash retrieves the merkle-patricia trie node pre-image for a given hash.
// Trie nodes may be from the world state trie or any account storage trie. // Trie nodes may be from the world state trie or any account storage trie.
// Contract code is not stored as part of the trie and must be retrieved via CodeByHash // Contract code is not stored as part of the trie and must be retrieved via CodeByHash
NodeByHash(nodeHash common.Hash, chainID uint64) []byte NodeByHash(nodeHash common.Hash, chainID eth.ChainID) []byte
// CodeByHash retrieves the contract code pre-image for a given hash. // CodeByHash retrieves the contract code pre-image for a given hash.
// codeHash should be retrieved from the world state account for a contract. // codeHash should be retrieved from the world state account for a contract.
CodeByHash(codeHash common.Hash, chainID uint64) []byte CodeByHash(codeHash common.Hash, chainID eth.ChainID) []byte
} }
// Oracle defines the high-level API used to retrieve L2 data. // Oracle defines the high-level API used to retrieve L2 data.
...@@ -32,16 +32,16 @@ type Oracle interface { ...@@ -32,16 +32,16 @@ type Oracle interface {
StateOracle StateOracle
// BlockByHash retrieves the block with the given hash. // BlockByHash retrieves the block with the given hash.
BlockByHash(blockHash common.Hash, chainID uint64) *types.Block BlockByHash(blockHash common.Hash, chainID eth.ChainID) *types.Block
OutputByRoot(root common.Hash, chainID uint64) eth.Output OutputByRoot(root common.Hash, chainID eth.ChainID) eth.Output
// BlockDataByHash retrieves the block, including all data used to construct it. // BlockDataByHash retrieves the block, including all data used to construct it.
BlockDataByHash(agreedBlockHash, blockHash common.Hash, chainID uint64) *types.Block BlockDataByHash(agreedBlockHash, blockHash common.Hash, chainID eth.ChainID) *types.Block
TransitionStateByRoot(root common.Hash) *interopTypes.TransitionState TransitionStateByRoot(root common.Hash) *interopTypes.TransitionState
ReceiptsByBlockHash(blockHash common.Hash, chainID uint64) (*types.Block, types.Receipts) ReceiptsByBlockHash(blockHash common.Hash, chainID eth.ChainID) (*types.Block, types.Receipts)
} }
// PreimageOracle implements Oracle using by interfacing with the pure preimage.Oracle // PreimageOracle implements Oracle using by interfacing with the pure preimage.Oracle
...@@ -62,7 +62,7 @@ func NewPreimageOracle(raw preimage.Oracle, hint preimage.Hinter, hintL2ChainIDs ...@@ -62,7 +62,7 @@ func NewPreimageOracle(raw preimage.Oracle, hint preimage.Hinter, hintL2ChainIDs
} }
} }
func (p *PreimageOracle) headerByBlockHash(blockHash common.Hash, chainID uint64) *types.Header { func (p *PreimageOracle) headerByBlockHash(blockHash common.Hash, chainID eth.ChainID) *types.Header {
if p.hintL2ChainIDs { if p.hintL2ChainIDs {
p.hint.Hint(BlockHeaderHint{Hash: blockHash, ChainID: chainID}) p.hint.Hint(BlockHeaderHint{Hash: blockHash, ChainID: chainID})
} else { } else {
...@@ -76,14 +76,14 @@ func (p *PreimageOracle) headerByBlockHash(blockHash common.Hash, chainID uint64 ...@@ -76,14 +76,14 @@ func (p *PreimageOracle) headerByBlockHash(blockHash common.Hash, chainID uint64
return &header return &header
} }
func (p *PreimageOracle) BlockByHash(blockHash common.Hash, chainID uint64) *types.Block { func (p *PreimageOracle) BlockByHash(blockHash common.Hash, chainID eth.ChainID) *types.Block {
header := p.headerByBlockHash(blockHash, chainID) header := p.headerByBlockHash(blockHash, chainID)
txs := p.LoadTransactions(blockHash, header.TxHash, chainID) txs := p.LoadTransactions(blockHash, header.TxHash, chainID)
return types.NewBlockWithHeader(header).WithBody(types.Body{Transactions: txs}) return types.NewBlockWithHeader(header).WithBody(types.Body{Transactions: txs})
} }
func (p *PreimageOracle) LoadTransactions(blockHash common.Hash, txHash common.Hash, chainID uint64) []*types.Transaction { func (p *PreimageOracle) LoadTransactions(blockHash common.Hash, txHash common.Hash, chainID eth.ChainID) []*types.Transaction {
if p.hintL2ChainIDs { if p.hintL2ChainIDs {
p.hint.Hint(TransactionsHint{Hash: blockHash, ChainID: chainID}) p.hint.Hint(TransactionsHint{Hash: blockHash, ChainID: chainID})
} else { } else {
...@@ -101,7 +101,7 @@ func (p *PreimageOracle) LoadTransactions(blockHash common.Hash, txHash common.H ...@@ -101,7 +101,7 @@ func (p *PreimageOracle) LoadTransactions(blockHash common.Hash, txHash common.H
return txs return txs
} }
func (p *PreimageOracle) NodeByHash(nodeHash common.Hash, chainID uint64) []byte { func (p *PreimageOracle) NodeByHash(nodeHash common.Hash, chainID eth.ChainID) []byte {
if p.hintL2ChainIDs { if p.hintL2ChainIDs {
p.hint.Hint(StateNodeHint{Hash: nodeHash, ChainID: chainID}) p.hint.Hint(StateNodeHint{Hash: nodeHash, ChainID: chainID})
} else { } else {
...@@ -110,7 +110,7 @@ func (p *PreimageOracle) NodeByHash(nodeHash common.Hash, chainID uint64) []byte ...@@ -110,7 +110,7 @@ func (p *PreimageOracle) NodeByHash(nodeHash common.Hash, chainID uint64) []byte
return p.oracle.Get(preimage.Keccak256Key(nodeHash)) return p.oracle.Get(preimage.Keccak256Key(nodeHash))
} }
func (p *PreimageOracle) CodeByHash(codeHash common.Hash, chainID uint64) []byte { func (p *PreimageOracle) CodeByHash(codeHash common.Hash, chainID eth.ChainID) []byte {
if p.hintL2ChainIDs { if p.hintL2ChainIDs {
p.hint.Hint(CodeHint{Hash: codeHash, ChainID: chainID}) p.hint.Hint(CodeHint{Hash: codeHash, ChainID: chainID})
} else { } else {
...@@ -119,7 +119,7 @@ func (p *PreimageOracle) CodeByHash(codeHash common.Hash, chainID uint64) []byte ...@@ -119,7 +119,7 @@ func (p *PreimageOracle) CodeByHash(codeHash common.Hash, chainID uint64) []byte
return p.oracle.Get(preimage.Keccak256Key(codeHash)) return p.oracle.Get(preimage.Keccak256Key(codeHash))
} }
func (p *PreimageOracle) OutputByRoot(l2OutputRoot common.Hash, chainID uint64) eth.Output { func (p *PreimageOracle) OutputByRoot(l2OutputRoot common.Hash, chainID eth.ChainID) eth.Output {
if p.hintL2ChainIDs { if p.hintL2ChainIDs {
p.hint.Hint(L2OutputHint{Hash: l2OutputRoot, ChainID: chainID}) p.hint.Hint(L2OutputHint{Hash: l2OutputRoot, ChainID: chainID})
} else { } else {
...@@ -133,7 +133,7 @@ func (p *PreimageOracle) OutputByRoot(l2OutputRoot common.Hash, chainID uint64) ...@@ -133,7 +133,7 @@ func (p *PreimageOracle) OutputByRoot(l2OutputRoot common.Hash, chainID uint64)
return output return output
} }
func (p *PreimageOracle) BlockDataByHash(agreedBlockHash, blockHash common.Hash, chainID uint64) *types.Block { func (p *PreimageOracle) BlockDataByHash(agreedBlockHash, blockHash common.Hash, chainID eth.ChainID) *types.Block {
hint := L2BlockDataHint{ hint := L2BlockDataHint{
AgreedBlockHash: agreedBlockHash, AgreedBlockHash: agreedBlockHash,
BlockHash: blockHash, BlockHash: blockHash,
...@@ -155,7 +155,7 @@ func (p *PreimageOracle) TransitionStateByRoot(root common.Hash) *interopTypes.T ...@@ -155,7 +155,7 @@ func (p *PreimageOracle) TransitionStateByRoot(root common.Hash) *interopTypes.T
return output return output
} }
func (p *PreimageOracle) ReceiptsByBlockHash(blockHash common.Hash, chainID uint64) (*types.Block, types.Receipts) { func (p *PreimageOracle) ReceiptsByBlockHash(blockHash common.Hash, chainID eth.ChainID) (*types.Block, types.Receipts) {
block := p.BlockByHash(blockHash, chainID) block := p.BlockByHash(blockHash, chainID)
p.hint.Hint(ReceiptsHint{Hash: blockHash, ChainID: chainID}) p.hint.Hint(ReceiptsHint{Hash: blockHash, ChainID: chainID})
opaqueReceipts := mpt.ReadTrie(block.ReceiptHash(), func(key common.Hash) []byte { opaqueReceipts := mpt.ReadTrie(block.ReceiptHash(), func(key common.Hash) []byte {
......
...@@ -52,7 +52,7 @@ func testBlock(t *testing.T, block *types.Block, hintL2ChainIDs bool) { ...@@ -52,7 +52,7 @@ func testBlock(t *testing.T, block *types.Block, hintL2ChainIDs bool) {
preimages[preimage.Keccak256Key(crypto.Keccak256Hash(p)).PreimageKey()] = p preimages[preimage.Keccak256Key(crypto.Keccak256Hash(p)).PreimageKey()] = p
} }
chainID := uint64(4924) chainID := eth.ChainIDFromUInt64(4924)
// Prepare a raw mock pre-image oracle that will serve the pre-image data and handle hints // Prepare a raw mock pre-image oracle that will serve the pre-image data and handle hints
...@@ -94,7 +94,7 @@ func TestPreimageOracleNodeByHash(t *testing.T) { ...@@ -94,7 +94,7 @@ func TestPreimageOracleNodeByHash(t *testing.T) {
rng := rand.New(rand.NewSource(123)) rng := rand.New(rand.NewSource(123))
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
chainID := rng.Uint64() chainID := eth.ChainIDFromUInt64(rng.Uint64())
t.Run(fmt.Sprintf("legacy_node_%d", i), func(t *testing.T) { t.Run(fmt.Sprintf("legacy_node_%d", i), func(t *testing.T) {
po, hints, preimages := mockPreimageOracle(t, false) po, hints, preimages := mockPreimageOracle(t, false)
...@@ -131,7 +131,7 @@ func TestPreimageOracleCodeByHash(t *testing.T) { ...@@ -131,7 +131,7 @@ func TestPreimageOracleCodeByHash(t *testing.T) {
rng := rand.New(rand.NewSource(123)) rng := rand.New(rand.NewSource(123))
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
chainID := rng.Uint64() chainID := eth.ChainIDFromUInt64(rng.Uint64())
t.Run(fmt.Sprintf("legacy_code_%d", i), func(t *testing.T) { t.Run(fmt.Sprintf("legacy_code_%d", i), func(t *testing.T) {
po, hints, preimages := mockPreimageOracle(t, false) po, hints, preimages := mockPreimageOracle(t, false)
...@@ -168,7 +168,7 @@ func TestPreimageOracleOutputByRoot(t *testing.T) { ...@@ -168,7 +168,7 @@ func TestPreimageOracleOutputByRoot(t *testing.T) {
rng := rand.New(rand.NewSource(123)) rng := rand.New(rand.NewSource(123))
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
chainID := rng.Uint64() chainID := eth.ChainIDFromUInt64(rng.Uint64())
t.Run(fmt.Sprintf("legacy_output_%d", i), func(t *testing.T) { t.Run(fmt.Sprintf("legacy_output_%d", i), func(t *testing.T) {
po, hints, preimages := mockPreimageOracle(t, false) po, hints, preimages := mockPreimageOracle(t, false)
output := testutils.RandomOutputV0(rng) output := testutils.RandomOutputV0(rng)
......
...@@ -15,8 +15,8 @@ import ( ...@@ -15,8 +15,8 @@ import (
// Same as l2.StateOracle but need to use our own copy to avoid dependency loops // Same as l2.StateOracle but need to use our own copy to avoid dependency loops
type stateOracle interface { type stateOracle interface {
NodeByHash(nodeHash common.Hash, chainID uint64) []byte NodeByHash(nodeHash common.Hash, chainID eth.ChainID) []byte
CodeByHash(codeHash common.Hash, chainID uint64) []byte CodeByHash(codeHash common.Hash, chainID eth.ChainID) []byte
} }
type StubBlockOracle struct { type StubBlockOracle struct {
...@@ -58,7 +58,7 @@ func NewStubOracleWithBlocks(t *testing.T, chain []*gethTypes.Block, outputs []e ...@@ -58,7 +58,7 @@ func NewStubOracleWithBlocks(t *testing.T, chain []*gethTypes.Block, outputs []e
} }
} }
func (o StubBlockOracle) BlockByHash(blockHash common.Hash, chainID uint64) *gethTypes.Block { func (o StubBlockOracle) BlockByHash(blockHash common.Hash, chainID eth.ChainID) *gethTypes.Block {
block, ok := o.Blocks[blockHash] block, ok := o.Blocks[blockHash]
if !ok { if !ok {
o.t.Fatalf("requested unknown block %s", blockHash) o.t.Fatalf("requested unknown block %s", blockHash)
...@@ -66,7 +66,7 @@ func (o StubBlockOracle) BlockByHash(blockHash common.Hash, chainID uint64) *get ...@@ -66,7 +66,7 @@ func (o StubBlockOracle) BlockByHash(blockHash common.Hash, chainID uint64) *get
return block return block
} }
func (o StubBlockOracle) OutputByRoot(root common.Hash, chainID uint64) eth.Output { func (o StubBlockOracle) OutputByRoot(root common.Hash, chainID eth.ChainID) eth.Output {
output, ok := o.Outputs[root] output, ok := o.Outputs[root]
if !ok { if !ok {
o.t.Fatalf("requested unknown output root %s", root) o.t.Fatalf("requested unknown output root %s", root)
...@@ -81,7 +81,7 @@ func (o StubBlockOracle) TransitionStateByRoot(root common.Hash) *interopTypes.T ...@@ -81,7 +81,7 @@ func (o StubBlockOracle) TransitionStateByRoot(root common.Hash) *interopTypes.T
return output return output
} }
func (o StubBlockOracle) BlockDataByHash(agreedBlockHash, blockHash common.Hash, chainID uint64) *gethTypes.Block { func (o StubBlockOracle) BlockDataByHash(agreedBlockHash, blockHash common.Hash, chainID eth.ChainID) *gethTypes.Block {
block, ok := o.Blocks[blockHash] block, ok := o.Blocks[blockHash]
if !ok { if !ok {
o.t.Fatalf("requested unknown block %s", blockHash) o.t.Fatalf("requested unknown block %s", blockHash)
...@@ -89,7 +89,7 @@ func (o StubBlockOracle) BlockDataByHash(agreedBlockHash, blockHash common.Hash, ...@@ -89,7 +89,7 @@ func (o StubBlockOracle) BlockDataByHash(agreedBlockHash, blockHash common.Hash,
return block return block
} }
func (o StubBlockOracle) ReceiptsByBlockHash(blockHash common.Hash, chainID uint64) (*gethTypes.Block, gethTypes.Receipts) { func (o StubBlockOracle) ReceiptsByBlockHash(blockHash common.Hash, chainID eth.ChainID) (*gethTypes.Block, gethTypes.Receipts) {
receipts, ok := o.Receipts[blockHash] receipts, ok := o.Receipts[blockHash]
if !ok { if !ok {
o.t.Fatalf("requested unknown receipts for block %s", blockHash) o.t.Fatalf("requested unknown receipts for block %s", blockHash)
...@@ -110,7 +110,7 @@ func NewKvStateOracle(t *testing.T, db ethdb.KeyValueStore) *KvStateOracle { ...@@ -110,7 +110,7 @@ func NewKvStateOracle(t *testing.T, db ethdb.KeyValueStore) *KvStateOracle {
} }
} }
func (o *KvStateOracle) NodeByHash(nodeHash common.Hash, chainID uint64) []byte { func (o *KvStateOracle) NodeByHash(nodeHash common.Hash, chainID eth.ChainID) []byte {
val, err := o.Source.Get(nodeHash.Bytes()) val, err := o.Source.Get(nodeHash.Bytes())
if err != nil { if err != nil {
o.t.Fatalf("error retrieving node %v: %v", nodeHash, err) o.t.Fatalf("error retrieving node %v: %v", nodeHash, err)
...@@ -118,7 +118,7 @@ func (o *KvStateOracle) NodeByHash(nodeHash common.Hash, chainID uint64) []byte ...@@ -118,7 +118,7 @@ func (o *KvStateOracle) NodeByHash(nodeHash common.Hash, chainID uint64) []byte
return val return val
} }
func (o *KvStateOracle) CodeByHash(hash common.Hash, chainID uint64) []byte { func (o *KvStateOracle) CodeByHash(hash common.Hash, chainID eth.ChainID) []byte {
return rawdb.ReadCode(o.Source, hash) return rawdb.ReadCode(o.Source, hash)
} }
...@@ -137,7 +137,7 @@ type StubStateOracle struct { ...@@ -137,7 +137,7 @@ type StubStateOracle struct {
Code map[common.Hash][]byte Code map[common.Hash][]byte
} }
func (o *StubStateOracle) NodeByHash(nodeHash common.Hash, chainID uint64) []byte { func (o *StubStateOracle) NodeByHash(nodeHash common.Hash, chainID eth.ChainID) []byte {
data, ok := o.Data[nodeHash] data, ok := o.Data[nodeHash]
if !ok { if !ok {
o.t.Fatalf("no value for node %v", nodeHash) o.t.Fatalf("no value for node %v", nodeHash)
...@@ -145,7 +145,7 @@ func (o *StubStateOracle) NodeByHash(nodeHash common.Hash, chainID uint64) []byt ...@@ -145,7 +145,7 @@ func (o *StubStateOracle) NodeByHash(nodeHash common.Hash, chainID uint64) []byt
return data return data
} }
func (o *StubStateOracle) CodeByHash(hash common.Hash, chainID uint64) []byte { func (o *StubStateOracle) CodeByHash(hash common.Hash, chainID eth.ChainID) []byte {
data, ok := o.Code[hash] data, ok := o.Code[hash]
if !ok { if !ok {
o.t.Fatalf("no value for code %v", hash) o.t.Fatalf("no value for code %v", hash)
......
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
"github.com/ethereum-optimism/optimism/op-program/client/boot" "github.com/ethereum-optimism/optimism/op-program/client/boot"
"github.com/ethereum-optimism/optimism/op-program/host/config" "github.com/ethereum-optimism/optimism/op-program/host/config"
"github.com/ethereum-optimism/optimism/op-program/host/types" "github.com/ethereum-optimism/optimism/op-program/host/types"
"github.com/ethereum-optimism/optimism/op-service/eth"
oplog "github.com/ethereum-optimism/optimism/op-service/log" oplog "github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum-optimism/optimism/op-service/sources" "github.com/ethereum-optimism/optimism/op-service/sources"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
...@@ -206,14 +207,14 @@ func TestMultipleNetworkConfigs(t *testing.T) { ...@@ -206,14 +207,14 @@ func TestMultipleNetworkConfigs(t *testing.T) {
func TestL2ChainID(t *testing.T) { func TestL2ChainID(t *testing.T) {
t.Run("DefaultToNetworkChainID", func(t *testing.T) { t.Run("DefaultToNetworkChainID", func(t *testing.T) {
cfg := configForArgs(t, replaceRequiredArg("--network", "op-mainnet")) cfg := configForArgs(t, replaceRequiredArg("--network", "op-mainnet"))
require.Equal(t, uint64(10), cfg.L2ChainID) require.Equal(t, eth.ChainIDFromUInt64(10), cfg.L2ChainID)
}) })
t.Run("DefaultToGenesisChainID", func(t *testing.T) { t.Run("DefaultToGenesisChainID", func(t *testing.T) {
rollupCfgFile := writeValidRollupConfig(t) rollupCfgFile := writeValidRollupConfig(t)
genesisFile := writeValidGenesis(t) genesisFile := writeValidGenesis(t)
cfg := configForArgs(t, addRequiredArgsExcept("--network", "--rollup.config", rollupCfgFile, "--l2.genesis", genesisFile)) cfg := configForArgs(t, addRequiredArgsExcept("--network", "--rollup.config", rollupCfgFile, "--l2.genesis", genesisFile))
require.Equal(t, l2GenesisConfig.ChainID.Uint64(), cfg.L2ChainID) require.Equal(t, eth.ChainIDFromBig(l2GenesisConfig.ChainID), cfg.L2ChainID)
}) })
t.Run("OverrideToCustomIndicator", func(t *testing.T) { t.Run("OverrideToCustomIndicator", func(t *testing.T) {
......
...@@ -6,12 +6,12 @@ import ( ...@@ -6,12 +6,12 @@ import (
"fmt" "fmt"
"os" "os"
"slices" "slices"
"strconv"
"github.com/ethereum-optimism/optimism/op-node/chaincfg" "github.com/ethereum-optimism/optimism/op-node/chaincfg"
"github.com/ethereum-optimism/optimism/op-program/chainconfig" "github.com/ethereum-optimism/optimism/op-program/chainconfig"
"github.com/ethereum-optimism/optimism/op-program/client/boot" "github.com/ethereum-optimism/optimism/op-program/client/boot"
"github.com/ethereum-optimism/optimism/op-program/host/types" "github.com/ethereum-optimism/optimism/op-program/host/types"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum-optimism/optimism/op-node/rollup" "github.com/ethereum-optimism/optimism/op-node/rollup"
...@@ -46,7 +46,7 @@ var ( ...@@ -46,7 +46,7 @@ var (
) )
type Config struct { type Config struct {
L2ChainID uint64 // TODO: Forbid for interop L2ChainID eth.ChainID // TODO: Forbid for interop
Rollups []*rollup.Config Rollups []*rollup.Config
// DataDir is the directory to read/write pre-image data from/to. // DataDir is the directory to read/write pre-image data from/to.
// If not set, an in-memory key-value store is used and fetching data must be enabled // If not set, an in-memory key-value store is used and fetching data must be enabled
...@@ -97,7 +97,7 @@ type Config struct { ...@@ -97,7 +97,7 @@ type Config struct {
} }
func (c *Config) Check() error { func (c *Config) Check() error {
if !c.InteropEnabled && c.L2ChainID == 0 { if !c.InteropEnabled && c.L2ChainID == (eth.ChainID{}) {
return ErrMissingL2ChainID return ErrMissingL2ChainID
} }
if len(c.Rollups) == 0 { if len(c.Rollups) == 0 {
...@@ -183,8 +183,8 @@ func NewSingleChainConfig( ...@@ -183,8 +183,8 @@ func NewSingleChainConfig(
l2Claim common.Hash, l2Claim common.Hash,
l2ClaimBlockNum uint64, l2ClaimBlockNum uint64,
) *Config { ) *Config {
l2ChainID := l2ChainConfig.ChainID.Uint64() l2ChainID := eth.ChainIDFromBig(l2ChainConfig.ChainID)
_, err := params.LoadOPStackChainConfig(l2ChainID) _, err := params.LoadOPStackChainConfig(eth.EvilChainIDToUInt64(l2ChainID))
if err != nil { if err != nil {
// Unknown chain ID so assume it is custom // Unknown chain ID so assume it is custom
l2ChainID = boot.CustomChainIDIndicator l2ChainID = boot.CustomChainIDIndicator
...@@ -268,16 +268,16 @@ func NewConfigFromCLI(log log.Logger, ctx *cli.Context) (*Config, error) { ...@@ -268,16 +268,16 @@ func NewConfigFromCLI(log log.Logger, ctx *cli.Context) (*Config, error) {
var err error var err error
var rollupCfgs []*rollup.Config var rollupCfgs []*rollup.Config
var l2ChainConfigs []*params.ChainConfig var l2ChainConfigs []*params.ChainConfig
var l2ChainID uint64 var l2ChainID eth.ChainID
networkNames := ctx.StringSlice(flags.Network.Name) networkNames := ctx.StringSlice(flags.Network.Name)
for _, networkName := range networkNames { for _, networkName := range networkNames {
var chainID uint64 var chainID eth.ChainID
if chainID, err = strconv.ParseUint(networkName, 10, 64); err != nil { if chainID, err = eth.ParseDecimalChainID(networkName); err != nil {
ch := chaincfg.ChainByName(networkName) ch := chaincfg.ChainByName(networkName)
if ch == nil { if ch == nil {
return nil, fmt.Errorf("invalid network: %q", networkName) return nil, fmt.Errorf("invalid network: %q", networkName)
} }
chainID = ch.ChainID chainID = eth.ChainIDFromUInt64(ch.ChainID)
} }
l2ChainConfig, err := chainconfig.ChainConfigByChainID(chainID) l2ChainConfig, err := chainconfig.ChainConfigByChainID(chainID)
...@@ -300,7 +300,7 @@ func NewConfigFromCLI(log log.Logger, ctx *cli.Context) (*Config, error) { ...@@ -300,7 +300,7 @@ func NewConfigFromCLI(log log.Logger, ctx *cli.Context) (*Config, error) {
return nil, fmt.Errorf("invalid genesis: %w", err) return nil, fmt.Errorf("invalid genesis: %w", err)
} }
l2ChainConfigs = append(l2ChainConfigs, l2ChainConfig) l2ChainConfigs = append(l2ChainConfigs, l2ChainConfig)
l2ChainID = l2ChainConfig.ChainID.Uint64() l2ChainID = eth.ChainIDFromBig(l2ChainConfig.ChainID)
} }
rollupPaths := ctx.StringSlice(flags.RollupConfig.Name) rollupPaths := ctx.StringSlice(flags.RollupConfig.Name)
...@@ -317,7 +317,7 @@ func NewConfigFromCLI(log log.Logger, ctx *cli.Context) (*Config, error) { ...@@ -317,7 +317,7 @@ func NewConfigFromCLI(log log.Logger, ctx *cli.Context) (*Config, error) {
l2ChainID = boot.CustomChainIDIndicator l2ChainID = boot.CustomChainIDIndicator
} else if len(rollupCfgs) > 1 { } else if len(rollupCfgs) > 1 {
// L2ChainID is not applicable when multiple L2 sources are used and not using custom configs // L2ChainID is not applicable when multiple L2 sources are used and not using custom configs
l2ChainID = 0 l2ChainID = eth.ChainID{}
} }
dbFormat := types.DataFormat(ctx.String(flags.DataFormat.Name)) dbFormat := types.DataFormat(ctx.String(flags.DataFormat.Name))
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"github.com/ethereum-optimism/optimism/op-program/chainconfig" "github.com/ethereum-optimism/optimism/op-program/chainconfig"
"github.com/ethereum-optimism/optimism/op-program/client/boot" "github.com/ethereum-optimism/optimism/op-program/client/boot"
"github.com/ethereum-optimism/optimism/op-program/host/types" "github.com/ethereum-optimism/optimism/op-program/host/types"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
...@@ -42,13 +43,13 @@ func TestValidInteropConfigIsValid(t *testing.T) { ...@@ -42,13 +43,13 @@ func TestValidInteropConfigIsValid(t *testing.T) {
func TestL2BlockNum(t *testing.T) { func TestL2BlockNum(t *testing.T) {
t.Run("RequiredForPreInterop", func(t *testing.T) { t.Run("RequiredForPreInterop", func(t *testing.T) {
cfg := validConfig() cfg := validConfig()
cfg.L2ChainID = 0 cfg.L2ChainID = eth.ChainID{}
require.ErrorIs(t, cfg.Check(), ErrMissingL2ChainID) require.ErrorIs(t, cfg.Check(), ErrMissingL2ChainID)
}) })
t.Run("NotRequiredForInterop", func(t *testing.T) { t.Run("NotRequiredForInterop", func(t *testing.T) {
cfg := validInteropConfig() cfg := validInteropConfig()
cfg.L2ChainID = 0 cfg.L2ChainID = eth.ChainID{}
require.NoError(t, cfg.Check()) require.NoError(t, cfg.Check())
}) })
} }
...@@ -221,7 +222,7 @@ func TestRejectExecAndServerMode(t *testing.T) { ...@@ -221,7 +222,7 @@ func TestRejectExecAndServerMode(t *testing.T) {
func TestCustomL2ChainID(t *testing.T) { func TestCustomL2ChainID(t *testing.T) {
t.Run("nonCustom", func(t *testing.T) { t.Run("nonCustom", func(t *testing.T) {
cfg := validConfig() cfg := validConfig()
require.Equal(t, cfg.L2ChainID, validL2Genesis.ChainID.Uint64()) require.Equal(t, cfg.L2ChainID, eth.ChainIDFromBig(validL2Genesis.ChainID))
}) })
t.Run("custom", func(t *testing.T) { t.Run("custom", func(t *testing.T) {
customChainConfig := &params.ChainConfig{ChainID: big.NewInt(0x1212121212)} customChainConfig := &params.ChainConfig{ChainID: big.NewInt(0x1212121212)}
......
...@@ -14,6 +14,7 @@ import ( ...@@ -14,6 +14,7 @@ import (
opservice "github.com/ethereum-optimism/optimism/op-service" opservice "github.com/ethereum-optimism/optimism/op-service"
"github.com/ethereum-optimism/optimism/op-service/client" "github.com/ethereum-optimism/optimism/op-service/client"
"github.com/ethereum-optimism/optimism/op-service/ctxinterrupt" "github.com/ethereum-optimism/optimism/op-service/ctxinterrupt"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/sources" "github.com/ethereum-optimism/optimism/op-service/sources"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
...@@ -98,7 +99,7 @@ func makeDefaultPrefetcher(ctx context.Context, logger log.Logger, kv kvstore.KV ...@@ -98,7 +99,7 @@ func makeDefaultPrefetcher(ctx context.Context, logger log.Logger, kv kvstore.KV
} }
executor := MakeProgramExecutor(logger, cfg) executor := MakeProgramExecutor(logger, cfg)
return prefetcher.NewPrefetcher(logger, l1Cl, l1BlobFetcher, cfg.Rollups[0].L2ChainID.Uint64(), sources, kv, executor, cfg.L2Head, cfg.AgreedPrestate), nil return prefetcher.NewPrefetcher(logger, l1Cl, l1BlobFetcher, eth.ChainIDFromBig(cfg.Rollups[0].L2ChainID), sources, kv, executor, cfg.L2Head, cfg.AgreedPrestate), nil
} }
type programExecutor struct { type programExecutor struct {
...@@ -110,7 +111,7 @@ func (p *programExecutor) RunProgram( ...@@ -110,7 +111,7 @@ func (p *programExecutor) RunProgram(
ctx context.Context, ctx context.Context,
prefetcher hostcommon.Prefetcher, prefetcher hostcommon.Prefetcher,
blockNum uint64, blockNum uint64,
chainID uint64, chainID eth.ChainID,
) error { ) error {
newCfg := *p.cfg newCfg := *p.cfg
newCfg.L2ChainID = chainID newCfg.L2ChainID = chainID
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"github.com/ethereum-optimism/optimism/op-program/client/boot" "github.com/ethereum-optimism/optimism/op-program/client/boot"
"github.com/ethereum-optimism/optimism/op-program/host/config" "github.com/ethereum-optimism/optimism/op-program/host/config"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
) )
...@@ -38,7 +39,7 @@ func (s *LocalPreimageSource) Get(key common.Hash) ([]byte, error) { ...@@ -38,7 +39,7 @@ func (s *LocalPreimageSource) Get(key common.Hash) ([]byte, error) {
case l2ClaimBlockNumberKey: case l2ClaimBlockNumberKey:
return binary.BigEndian.AppendUint64(nil, s.config.L2ClaimBlockNumber), nil return binary.BigEndian.AppendUint64(nil, s.config.L2ClaimBlockNumber), nil
case l2ChainIDKey: case l2ChainIDKey:
return binary.BigEndian.AppendUint64(nil, s.config.L2ChainID), nil return binary.BigEndian.AppendUint64(nil, eth.EvilChainIDToUInt64(s.config.L2ChainID)), nil
case l2ChainConfigKey: case l2ChainConfigKey:
if s.config.L2ChainID != boot.CustomChainIDIndicator { if s.config.L2ChainID != boot.CustomChainIDIndicator {
return nil, ErrNotFound return nil, ErrNotFound
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
preimage "github.com/ethereum-optimism/optimism/op-preimage" preimage "github.com/ethereum-optimism/optimism/op-preimage"
"github.com/ethereum-optimism/optimism/op-program/client/boot" "github.com/ethereum-optimism/optimism/op-program/client/boot"
"github.com/ethereum-optimism/optimism/op-program/host/config" "github.com/ethereum-optimism/optimism/op-program/host/config"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
...@@ -18,7 +19,7 @@ import ( ...@@ -18,7 +19,7 @@ import (
func TestLocalPreimageSource(t *testing.T) { func TestLocalPreimageSource(t *testing.T) {
cfg := &config.Config{ cfg := &config.Config{
L2ChainID: 86, L2ChainID: eth.ChainIDFromUInt64(86),
Rollups: []*rollup.Config{chaincfg.OPSepolia()}, Rollups: []*rollup.Config{chaincfg.OPSepolia()},
L1Head: common.HexToHash("0x1111"), L1Head: common.HexToHash("0x1111"),
L2OutputRoot: common.HexToHash("0x2222"), L2OutputRoot: common.HexToHash("0x2222"),
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"github.com/ethereum-optimism/optimism/op-program/host/common" "github.com/ethereum-optimism/optimism/op-program/host/common"
"github.com/ethereum-optimism/optimism/op-program/host/types" "github.com/ethereum-optimism/optimism/op-program/host/types"
"github.com/ethereum-optimism/optimism/op-service/client" "github.com/ethereum-optimism/optimism/op-service/client"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )
...@@ -25,7 +26,7 @@ var ( ...@@ -25,7 +26,7 @@ var (
) )
type RetryingL2Sources struct { type RetryingL2Sources struct {
Sources map[uint64]*RetryingL2Source Sources map[eth.ChainID]*RetryingL2Source
} }
func NewRetryingL2SourcesFromURLs(ctx context.Context, logger log.Logger, configs []*rollup.Config, l2URLs []string, l2ExperimentalURLs []string) (*RetryingL2Sources, error) { func NewRetryingL2SourcesFromURLs(ctx context.Context, logger log.Logger, configs []*rollup.Config, l2URLs []string, l2ExperimentalURLs []string) (*RetryingL2Sources, error) {
...@@ -58,11 +59,11 @@ func NewRetryingL2Sources(ctx context.Context, logger log.Logger, configs []*rol ...@@ -58,11 +59,11 @@ func NewRetryingL2Sources(ctx context.Context, logger log.Logger, configs []*rol
if len(configs) == 0 { if len(configs) == 0 {
return nil, ErrNoSources return nil, ErrNoSources
} }
rollupConfigs := make(map[uint64]*rollup.Config) rollupConfigs := make(map[eth.ChainID]*rollup.Config)
for _, rollupCfg := range configs { for _, rollupCfg := range configs {
rollupConfigs[rollupCfg.L2ChainID.Uint64()] = rollupCfg rollupConfigs[eth.ChainIDFromBig(rollupCfg.L2ChainID)] = rollupCfg
} }
l2RPCs := make(map[uint64]client.RPC) l2RPCs := make(map[eth.ChainID]client.RPC)
for _, rpc := range l2Clients { for _, rpc := range l2Clients {
chainID, err := loadChainID(ctx, rpc) chainID, err := loadChainID(ctx, rpc)
if err != nil { if err != nil {
...@@ -77,7 +78,7 @@ func NewRetryingL2Sources(ctx context.Context, logger log.Logger, configs []*rol ...@@ -77,7 +78,7 @@ func NewRetryingL2Sources(ctx context.Context, logger log.Logger, configs []*rol
} }
} }
l2ExperimentalRPCs := make(map[uint64]client.RPC) l2ExperimentalRPCs := make(map[eth.ChainID]client.RPC)
for _, rpc := range l2ExperimentalClients { for _, rpc := range l2ExperimentalClients {
chainID, err := loadChainID(ctx, rpc) chainID, err := loadChainID(ctx, rpc)
if err != nil { if err != nil {
...@@ -92,9 +93,9 @@ func NewRetryingL2Sources(ctx context.Context, logger log.Logger, configs []*rol ...@@ -92,9 +93,9 @@ func NewRetryingL2Sources(ctx context.Context, logger log.Logger, configs []*rol
} }
} }
sources := make(map[uint64]*RetryingL2Source, len(configs)) sources := make(map[eth.ChainID]*RetryingL2Source, len(configs))
for _, rollupCfg := range rollupConfigs { for _, rollupCfg := range rollupConfigs {
chainID := rollupCfg.L2ChainID.Uint64() chainID := eth.ChainIDFromBig(rollupCfg.L2ChainID)
l2RPC, ok := l2RPCs[chainID] l2RPC, ok := l2RPCs[chainID]
if !ok { if !ok {
return nil, fmt.Errorf("%w: %v", ErrNoL2ForRollup, chainID) return nil, fmt.Errorf("%w: %v", ErrNoL2ForRollup, chainID)
...@@ -112,7 +113,7 @@ func NewRetryingL2Sources(ctx context.Context, logger log.Logger, configs []*rol ...@@ -112,7 +113,7 @@ func NewRetryingL2Sources(ctx context.Context, logger log.Logger, configs []*rol
}, nil }, nil
} }
func (s *RetryingL2Sources) ForChainID(chainID uint64) (types.L2Source, error) { func (s *RetryingL2Sources) ForChainID(chainID eth.ChainID) (types.L2Source, error) {
source, ok := s.Sources[chainID] source, ok := s.Sources[chainID]
if !ok { if !ok {
return nil, fmt.Errorf("no source available for chain ID: %v", chainID) return nil, fmt.Errorf("no source available for chain ID: %v", chainID)
...@@ -120,7 +121,7 @@ func (s *RetryingL2Sources) ForChainID(chainID uint64) (types.L2Source, error) { ...@@ -120,7 +121,7 @@ func (s *RetryingL2Sources) ForChainID(chainID uint64) (types.L2Source, error) {
return source, nil return source, nil
} }
func (s *RetryingL2Sources) ForChainIDWithoutRetries(chainID uint64) (types.L2Source, error) { func (s *RetryingL2Sources) ForChainIDWithoutRetries(chainID eth.ChainID) (types.L2Source, error) {
retrying, ok := s.Sources[chainID] retrying, ok := s.Sources[chainID]
if !ok { if !ok {
return nil, fmt.Errorf("no source available for chain ID: %v", chainID) return nil, fmt.Errorf("no source available for chain ID: %v", chainID)
...@@ -128,11 +129,11 @@ func (s *RetryingL2Sources) ForChainIDWithoutRetries(chainID uint64) (types.L2So ...@@ -128,11 +129,11 @@ func (s *RetryingL2Sources) ForChainIDWithoutRetries(chainID uint64) (types.L2So
return retrying.source, nil return retrying.source, nil
} }
func loadChainID(ctx context.Context, rpc client.RPC) (uint64, error) { func loadChainID(ctx context.Context, rpc client.RPC) (eth.ChainID, error) {
var id hexutil.Big var id hexutil.Big
err := rpc.CallContext(ctx, &id, "eth_chainId") err := rpc.CallContext(ctx, &id, "eth_chainId")
if err != nil { if err != nil {
return 0, err return eth.ChainID{}, err
} }
return (*big.Int)(&id).Uint64(), nil return eth.ChainIDFromBig((*big.Int)(&id)), nil
} }
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"github.com/ethereum-optimism/optimism/op-node/rollup" "github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-service/client" "github.com/ethereum-optimism/optimism/op-service/client"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/testlog" "github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
...@@ -32,7 +33,7 @@ func TestNewL2Sources(t *testing.T) { ...@@ -32,7 +33,7 @@ func TestNewL2Sources(t *testing.T) {
[]client.RPC{experimentalRpc}) []client.RPC{experimentalRpc})
require.NoError(t, err) require.NoError(t, err)
require.Len(t, src.Sources, 1) require.Len(t, src.Sources, 1)
require.True(t, src.Sources[uint64(4)].ExperimentalEnabled()) require.True(t, src.Sources[eth.ChainIDFromUInt64(4)].ExperimentalEnabled())
}) })
t.Run("MultipleSources", func(t *testing.T) { t.Run("MultipleSources", func(t *testing.T) {
...@@ -45,8 +46,8 @@ func TestNewL2Sources(t *testing.T) { ...@@ -45,8 +46,8 @@ func TestNewL2Sources(t *testing.T) {
[]client.RPC{experimentalRpc1, experimentalRpc2}) []client.RPC{experimentalRpc1, experimentalRpc2})
require.NoError(t, err) require.NoError(t, err)
require.Len(t, src.Sources, 2) require.Len(t, src.Sources, 2)
require.True(t, src.Sources[uint64(1)].ExperimentalEnabled()) require.True(t, src.Sources[eth.ChainIDFromUInt64(1)].ExperimentalEnabled())
require.True(t, src.Sources[uint64(2)].ExperimentalEnabled()) require.True(t, src.Sources[eth.ChainIDFromUInt64(2)].ExperimentalEnabled())
}) })
t.Run("ExperimentalRPCsAreOptional", func(t *testing.T) { t.Run("ExperimentalRPCsAreOptional", func(t *testing.T) {
...@@ -59,11 +60,11 @@ func TestNewL2Sources(t *testing.T) { ...@@ -59,11 +60,11 @@ func TestNewL2Sources(t *testing.T) {
[]client.RPC{experimentalRpc2}) []client.RPC{experimentalRpc2})
require.NoError(t, err) require.NoError(t, err)
require.Len(t, src.Sources, 2) require.Len(t, src.Sources, 2)
require.Same(t, src.Sources[uint64(1)].RollupConfig(), config1) require.Same(t, src.Sources[eth.ChainIDFromUInt64(1)].RollupConfig(), config1)
require.False(t, src.Sources[uint64(1)].ExperimentalEnabled()) require.False(t, src.Sources[eth.ChainIDFromUInt64(1)].ExperimentalEnabled())
require.Same(t, src.Sources[uint64(2)].RollupConfig(), config2) require.Same(t, src.Sources[eth.ChainIDFromUInt64(2)].RollupConfig(), config2)
require.True(t, src.Sources[uint64(2)].ExperimentalEnabled()) require.True(t, src.Sources[eth.ChainIDFromUInt64(2)].ExperimentalEnabled())
}) })
t.Run("RollupMissingL2URL", func(t *testing.T) { t.Run("RollupMissingL2URL", func(t *testing.T) {
......
...@@ -53,7 +53,7 @@ type Prefetcher struct { ...@@ -53,7 +53,7 @@ type Prefetcher struct {
logger log.Logger logger log.Logger
l1Fetcher L1Source l1Fetcher L1Source
l1BlobFetcher L1BlobSource l1BlobFetcher L1BlobSource
defaultChainID uint64 defaultChainID eth.ChainID
l2Sources hosttypes.L2Sources l2Sources hosttypes.L2Sources
lastHint string lastHint string
kvStore kvstore.KV kvStore kvstore.KV
...@@ -69,7 +69,7 @@ func NewPrefetcher( ...@@ -69,7 +69,7 @@ func NewPrefetcher(
logger log.Logger, logger log.Logger,
l1Fetcher L1Source, l1Fetcher L1Source,
l1BlobFetcher L1BlobSource, l1BlobFetcher L1BlobSource,
defaultChainID uint64, defaultChainID eth.ChainID,
l2Sources hosttypes.L2Sources, l2Sources hosttypes.L2Sources,
kvStore kvstore.KV, kvStore kvstore.KV,
executor ProgramExecutor, executor ProgramExecutor,
...@@ -373,7 +373,7 @@ func (p *Prefetcher) prefetch(ctx context.Context, hint string) error { ...@@ -373,7 +373,7 @@ func (p *Prefetcher) prefetch(ctx context.Context, hint string) error {
} }
agreedBlockHash := common.Hash(hintBytes[:32]) agreedBlockHash := common.Hash(hintBytes[:32])
blockHash := common.Hash(hintBytes[32:64]) blockHash := common.Hash(hintBytes[32:64])
chainID := binary.BigEndian.Uint64(hintBytes[64:72]) chainID := eth.ChainIDFromUInt64(binary.BigEndian.Uint64(hintBytes[64:72]))
key := BlockDataKey(blockHash) key := BlockDataKey(blockHash)
if _, err := p.kvStore.Get(key.Key()); err == nil { if _, err := p.kvStore.Get(key.Key()); err == nil {
return nil return nil
...@@ -392,14 +392,14 @@ func (p *Prefetcher) prefetch(ctx context.Context, hint string) error { ...@@ -392,14 +392,14 @@ func (p *Prefetcher) prefetch(ctx context.Context, hint string) error {
return fmt.Errorf("unknown hint type: %v", hintType) return fmt.Errorf("unknown hint type: %v", hintType)
} }
func (p *Prefetcher) parseHashAndChainID(hintType string, hintBytes []byte) (common.Hash, uint64, error) { func (p *Prefetcher) parseHashAndChainID(hintType string, hintBytes []byte) (common.Hash, eth.ChainID, error) {
switch len(hintBytes) { switch len(hintBytes) {
case 32: case 32:
return common.Hash(hintBytes), p.defaultChainID, nil return common.Hash(hintBytes), p.defaultChainID, nil
case 40: case 40:
return common.Hash(hintBytes[0:32]), binary.BigEndian.Uint64(hintBytes[32:]), nil return common.Hash(hintBytes[0:32]), eth.ChainIDFromUInt64(binary.BigEndian.Uint64(hintBytes[32:])), nil
default: default:
return common.Hash{}, 0, fmt.Errorf("invalid %s hint: %x", hintType, hintBytes) return common.Hash{}, eth.ChainID{}, fmt.Errorf("invalid %s hint: %x", hintType, hintBytes)
} }
} }
......
...@@ -34,7 +34,7 @@ import ( ...@@ -34,7 +34,7 @@ import (
var ( var (
ecRecoverInput = common.FromHex("18c547e4f7b0f325ad1e56f57e26c745b09a3e503d86e00e5255ff7f715d3d1c000000000000000000000000000000000000000000000000000000000000001c73b1693892219d736caba55bdb67216e485557ea6b6af75f37096c9aa6a5a75feeb940b1d03b21e36b0e47e79769f095fe2ab855bd91e3a38756b7d75a9c4549") ecRecoverInput = common.FromHex("18c547e4f7b0f325ad1e56f57e26c745b09a3e503d86e00e5255ff7f715d3d1c000000000000000000000000000000000000000000000000000000000000001c73b1693892219d736caba55bdb67216e485557ea6b6af75f37096c9aa6a5a75feeb940b1d03b21e36b0e47e79769f095fe2ab855bd91e3a38756b7d75a9c4549")
kzgPointEvalInput = common.FromHex("01e798154708fe7789429634053cbf9f99b619f9f084048927333fce637f549b564c0a11a0f704f4fc3e8acfe0f8245f0ad1347b378fbf96e206da11a5d3630624d25032e67a7e6a4910df5834b8fe70e6bcfeeac0352434196bdf4b2485d5a18f59a8d2a1a625a17f3fea0fe5eb8c896db3764f3185481bc22f91b4aaffcca25f26936857bc3a7c2539ea8ec3a952b7873033e038326e87ed3e1276fd140253fa08e9fc25fb2d9a98527fc22a2c9612fbeafdad446cbc7bcdbdcd780af2c16a") kzgPointEvalInput = common.FromHex("01e798154708fe7789429634053cbf9f99b619f9f084048927333fce637f549b564c0a11a0f704f4fc3e8acfe0f8245f0ad1347b378fbf96e206da11a5d3630624d25032e67a7e6a4910df5834b8fe70e6bcfeeac0352434196bdf4b2485d5a18f59a8d2a1a625a17f3fea0fe5eb8c896db3764f3185481bc22f91b4aaffcca25f26936857bc3a7c2539ea8ec3a952b7873033e038326e87ed3e1276fd140253fa08e9fc25fb2d9a98527fc22a2c9612fbeafdad446cbc7bcdbdcd780af2c16a")
defaultChainID = uint64(14) defaultChainID = eth.ChainIDFromUInt64(14)
) )
func TestNoHint(t *testing.T) { func TestNoHint(t *testing.T) {
...@@ -416,7 +416,7 @@ func TestRestrictedPrecompileContracts(t *testing.T) { ...@@ -416,7 +416,7 @@ func TestRestrictedPrecompileContracts(t *testing.T) {
func TestFetchL2Block(t *testing.T) { func TestFetchL2Block(t *testing.T) {
rng := rand.New(rand.NewSource(123)) rng := rand.New(rand.NewSource(123))
chainID := uint64(482948) chainID := eth.ChainIDFromUInt64(482948)
block, rcpts := testutils.RandomBlock(rng, 10) block, rcpts := testutils.RandomBlock(rng, 10)
hash := block.Hash() hash := block.Hash()
...@@ -443,13 +443,13 @@ func TestFetchL2Block(t *testing.T) { ...@@ -443,13 +443,13 @@ func TestFetchL2Block(t *testing.T) {
}) })
t.Run("WithChainID", func(t *testing.T) { t.Run("WithChainID", func(t *testing.T) {
prefetcher, _, _, l2Cls, _ := createPrefetcher(t, 5, 7, 10) prefetcher, _, _, l2Cls, _ := createPrefetcher(t, eth.ChainIDFromUInt64(5), eth.ChainIDFromUInt64(7), eth.ChainIDFromUInt64(10))
l2Cl := l2Cls.sources[7] l2Cl := l2Cls.sources[eth.ChainIDFromUInt64(7)]
l2Cl.ExpectInfoAndTxsByHash(hash, eth.BlockToInfo(block), block.Transactions(), nil) l2Cl.ExpectInfoAndTxsByHash(hash, eth.BlockToInfo(block), block.Transactions(), nil)
defer assertAllClientExpectations(t, l2Cls) defer assertAllClientExpectations(t, l2Cls)
oracle := l2.NewPreimageOracle(asOracleFn(t, prefetcher), asHinter(t, prefetcher), true) oracle := l2.NewPreimageOracle(asOracleFn(t, prefetcher), asHinter(t, prefetcher), true)
result := oracle.BlockByHash(hash, 7) result := oracle.BlockByHash(hash, eth.ChainIDFromUInt64(7))
require.EqualValues(t, block.Header(), result.Header()) require.EqualValues(t, block.Header(), result.Header())
assertTransactionsEqual(t, block.Transactions(), result.Transactions()) assertTransactionsEqual(t, block.Transactions(), result.Transactions())
}) })
...@@ -459,7 +459,7 @@ func TestFetchL2Transactions(t *testing.T) { ...@@ -459,7 +459,7 @@ func TestFetchL2Transactions(t *testing.T) {
rng := rand.New(rand.NewSource(123)) rng := rand.New(rand.NewSource(123))
block, rcpts := testutils.RandomBlock(rng, 10) block, rcpts := testutils.RandomBlock(rng, 10)
hash := block.Hash() hash := block.Hash()
chainID := rng.Uint64() chainID := eth.ChainIDFromUInt64(rng.Uint64())
t.Run("AlreadyKnown", func(t *testing.T) { t.Run("AlreadyKnown", func(t *testing.T) {
prefetcher, _, _, _, kv := createPrefetcher(t) prefetcher, _, _, _, kv := createPrefetcher(t)
...@@ -482,13 +482,13 @@ func TestFetchL2Transactions(t *testing.T) { ...@@ -482,13 +482,13 @@ func TestFetchL2Transactions(t *testing.T) {
}) })
t.Run("WithChainID", func(t *testing.T) { t.Run("WithChainID", func(t *testing.T) {
prefetcher, _, _, l2Cls, _ := createPrefetcher(t, 5, 7, 10) prefetcher, _, _, l2Cls, _ := createPrefetcher(t, eth.ChainIDFromUInt64(5), eth.ChainIDFromUInt64(7), eth.ChainIDFromUInt64(10))
l2Cl := l2Cls.sources[7] l2Cl := l2Cls.sources[eth.ChainIDFromUInt64(7)]
l2Cl.ExpectInfoAndTxsByHash(hash, eth.BlockToInfo(block), block.Transactions(), nil) l2Cl.ExpectInfoAndTxsByHash(hash, eth.BlockToInfo(block), block.Transactions(), nil)
defer assertAllClientExpectations(t, l2Cls) defer assertAllClientExpectations(t, l2Cls)
oracle := l2.NewPreimageOracle(asOracleFn(t, prefetcher), asHinter(t, prefetcher), true) oracle := l2.NewPreimageOracle(asOracleFn(t, prefetcher), asHinter(t, prefetcher), true)
result := oracle.LoadTransactions(hash, block.TxHash(), 7) result := oracle.LoadTransactions(hash, block.TxHash(), eth.ChainIDFromUInt64(7))
assertTransactionsEqual(t, block.Transactions(), result) assertTransactionsEqual(t, block.Transactions(), result)
}) })
} }
...@@ -498,7 +498,7 @@ func TestFetchL2Node(t *testing.T) { ...@@ -498,7 +498,7 @@ func TestFetchL2Node(t *testing.T) {
node := testutils.RandomData(rng, 30) node := testutils.RandomData(rng, 30)
hash := crypto.Keccak256Hash(node) hash := crypto.Keccak256Hash(node)
key := preimage.Keccak256Key(hash).PreimageKey() key := preimage.Keccak256Key(hash).PreimageKey()
chainID := rng.Uint64() chainID := eth.ChainIDFromUInt64(rng.Uint64())
t.Run("AlreadyKnown", func(t *testing.T) { t.Run("AlreadyKnown", func(t *testing.T) {
prefetcher, _, _, _, kv := createPrefetcher(t) prefetcher, _, _, _, kv := createPrefetcher(t)
...@@ -521,13 +521,13 @@ func TestFetchL2Node(t *testing.T) { ...@@ -521,13 +521,13 @@ func TestFetchL2Node(t *testing.T) {
}) })
t.Run("WithChainID", func(t *testing.T) { t.Run("WithChainID", func(t *testing.T) {
prefetcher, _, _, l2Cls, _ := createPrefetcher(t, 5, 9, 99) prefetcher, _, _, l2Cls, _ := createPrefetcher(t, eth.ChainIDFromUInt64(5), eth.ChainIDFromUInt64(9), eth.ChainIDFromUInt64(99))
l2Cl := l2Cls.sources[9] l2Cl := l2Cls.sources[eth.ChainIDFromUInt64(9)]
l2Cl.ExpectNodeByHash(hash, node, nil) l2Cl.ExpectNodeByHash(hash, node, nil)
defer assertAllClientExpectations(t, l2Cls) defer assertAllClientExpectations(t, l2Cls)
oracle := l2.NewPreimageOracle(asOracleFn(t, prefetcher), asHinter(t, prefetcher), true) oracle := l2.NewPreimageOracle(asOracleFn(t, prefetcher), asHinter(t, prefetcher), true)
result := oracle.NodeByHash(hash, 9) result := oracle.NodeByHash(hash, eth.ChainIDFromUInt64(9))
require.EqualValues(t, node, result) require.EqualValues(t, node, result)
}) })
} }
...@@ -537,7 +537,7 @@ func TestFetchL2Code(t *testing.T) { ...@@ -537,7 +537,7 @@ func TestFetchL2Code(t *testing.T) {
code := testutils.RandomData(rng, 30) code := testutils.RandomData(rng, 30)
hash := crypto.Keccak256Hash(code) hash := crypto.Keccak256Hash(code)
key := preimage.Keccak256Key(hash).PreimageKey() key := preimage.Keccak256Key(hash).PreimageKey()
chainID := rng.Uint64() chainID := eth.ChainIDFromUInt64(rng.Uint64())
t.Run("AlreadyKnown", func(t *testing.T) { t.Run("AlreadyKnown", func(t *testing.T) {
prefetcher, _, _, _, kv := createPrefetcher(t) prefetcher, _, _, _, kv := createPrefetcher(t)
...@@ -560,13 +560,13 @@ func TestFetchL2Code(t *testing.T) { ...@@ -560,13 +560,13 @@ func TestFetchL2Code(t *testing.T) {
}) })
t.Run("WithChainID", func(t *testing.T) { t.Run("WithChainID", func(t *testing.T) {
prefetcher, _, _, l2Cls, _ := createPrefetcher(t, 8, 45, 98, 55) prefetcher, _, _, l2Cls, _ := createPrefetcher(t, eth.ChainIDFromUInt64(8), eth.ChainIDFromUInt64(45), eth.ChainIDFromUInt64(98), eth.ChainIDFromUInt64(55))
l2Cl := l2Cls.sources[98] l2Cl := l2Cls.sources[eth.ChainIDFromUInt64(98)]
l2Cl.ExpectCodeByHash(hash, code, nil) l2Cl.ExpectCodeByHash(hash, code, nil)
defer assertAllClientExpectations(t, l2Cls) defer assertAllClientExpectations(t, l2Cls)
oracle := l2.NewPreimageOracle(asOracleFn(t, prefetcher), asHinter(t, prefetcher), true) oracle := l2.NewPreimageOracle(asOracleFn(t, prefetcher), asHinter(t, prefetcher), true)
result := oracle.CodeByHash(hash, 98) result := oracle.CodeByHash(hash, eth.ChainIDFromUInt64(98))
require.EqualValues(t, code, result) require.EqualValues(t, code, result)
}) })
} }
...@@ -581,7 +581,7 @@ func TestFetchL2Output(t *testing.T) { ...@@ -581,7 +581,7 @@ func TestFetchL2Output(t *testing.T) {
require.NoError(t, kv.Put(key, output.Marshal())) require.NoError(t, kv.Put(key, output.Marshal()))
oracle := l2.NewPreimageOracle(asOracleFn(t, prefetcher), asHinter(t, prefetcher), false) oracle := l2.NewPreimageOracle(asOracleFn(t, prefetcher), asHinter(t, prefetcher), false)
result := oracle.OutputByRoot(hash, rng.Uint64()) result := oracle.OutputByRoot(hash, eth.ChainIDFromUInt64(rng.Uint64()))
require.EqualValues(t, output, result) require.EqualValues(t, output, result)
}) })
...@@ -592,7 +592,7 @@ func TestFetchL2Output(t *testing.T) { ...@@ -592,7 +592,7 @@ func TestFetchL2Output(t *testing.T) {
l2Cl.ExpectOutputByRoot(prefetcher.l2Head, output, nil) l2Cl.ExpectOutputByRoot(prefetcher.l2Head, output, nil)
defer assertAllClientExpectations(t, l2Cls) defer assertAllClientExpectations(t, l2Cls)
oracle := l2.NewPreimageOracle(asOracleFn(t, prefetcher), asHinter(t, prefetcher), false) oracle := l2.NewPreimageOracle(asOracleFn(t, prefetcher), asHinter(t, prefetcher), false)
result := oracle.OutputByRoot(hash, rng.Uint64()) result := oracle.OutputByRoot(hash, eth.ChainIDFromUInt64(rng.Uint64()))
require.EqualValues(t, output, result) require.EqualValues(t, output, result)
}) })
...@@ -603,26 +603,26 @@ func TestFetchL2Output(t *testing.T) { ...@@ -603,26 +603,26 @@ func TestFetchL2Output(t *testing.T) {
superV1 := eth.SuperV1{ superV1 := eth.SuperV1{
Timestamp: timestamp, Timestamp: timestamp,
Chains: []eth.ChainIDAndOutput{ Chains: []eth.ChainIDAndOutput{
{ChainID: 6, Output: eth.OutputRoot(chain6Output)}, {ChainID: eth.ChainIDFromUInt64(6), Output: eth.OutputRoot(chain6Output)},
{ChainID: 78, Output: eth.OutputRoot(output)}, {ChainID: eth.ChainIDFromUInt64(78), Output: eth.OutputRoot(output)},
{ChainID: 99, Output: eth.OutputRoot(chain99Output)}, {ChainID: eth.ChainIDFromUInt64(99), Output: eth.OutputRoot(chain99Output)},
}, },
} }
prefetcher, _, _, l2Cls, _ := createPrefetcherWithAgreedPrestate(t, superV1.Marshal(), 6, 78, 99) prefetcher, _, _, l2Cls, _ := createPrefetcherWithAgreedPrestate(t, superV1.Marshal(), eth.ChainIDFromUInt64(6), eth.ChainIDFromUInt64(78), eth.ChainIDFromUInt64(99))
l2Cl := l2Cls.sources[78] l2Cl := l2Cls.sources[eth.ChainIDFromUInt64(78)]
blockNum, err := l2Cls.sources[78].RollupConfig().TargetBlockNumber(timestamp) blockNum, err := l2Cls.sources[eth.ChainIDFromUInt64(78)].RollupConfig().TargetBlockNumber(timestamp)
require.NoError(t, err) require.NoError(t, err)
l2Cl.ExpectOutputByNumber(blockNum, output, nil) l2Cl.ExpectOutputByNumber(blockNum, output, nil)
defer assertAllClientExpectations(t, l2Cls) defer assertAllClientExpectations(t, l2Cls)
oracle := l2.NewPreimageOracle(asOracleFn(t, prefetcher), asHinter(t, prefetcher), true) oracle := l2.NewPreimageOracle(asOracleFn(t, prefetcher), asHinter(t, prefetcher), true)
result := oracle.OutputByRoot(hash, 78) result := oracle.OutputByRoot(hash, eth.ChainIDFromUInt64(78))
require.EqualValues(t, output, result) require.EqualValues(t, output, result)
}) })
} }
func TestFetchL2BlockData(t *testing.T) { func TestFetchL2BlockData(t *testing.T) {
chainID := uint64(14) chainID := eth.ChainIDFromUInt64(14)
testBlockExec := func(t *testing.T, clientErrs []error) { testBlockExec := func(t *testing.T, clientErrs []error) {
require.NotEmpty(t, clientErrs) require.NotEmpty(t, clientErrs)
...@@ -767,15 +767,15 @@ func TestRetryWhenNotAvailableAfterPrefetching(t *testing.T) { ...@@ -767,15 +767,15 @@ func TestRetryWhenNotAvailableAfterPrefetching(t *testing.T) {
rng := rand.New(rand.NewSource(123)) rng := rand.New(rand.NewSource(123))
node := testutils.RandomData(rng, 30) node := testutils.RandomData(rng, 30)
hash := crypto.Keccak256Hash(node) hash := crypto.Keccak256Hash(node)
chainID := rng.Uint64() chainID := eth.ChainIDFromUInt64(rng.Uint64())
_, l1Source, l1BlobSource, l2Cls, kv := createPrefetcher(t) _, l1Source, l1BlobSource, l2Cls, kv := createPrefetcher(t)
putsToIgnore := 2 putsToIgnore := 2
kv = &unreliableKvStore{KV: kv, putsToIgnore: putsToIgnore} kv = &unreliableKvStore{KV: kv, putsToIgnore: putsToIgnore}
sources := &l2Clients{sources: map[uint64]*l2Client{6: l2Cls.sources[defaultChainID]}} sources := &l2Clients{sources: map[eth.ChainID]*l2Client{eth.ChainIDFromUInt64(6): l2Cls.sources[defaultChainID]}}
prefetcher := NewPrefetcher(testlog.Logger(t, log.LevelInfo), l1Source, l1BlobSource, 6, sources, kv, nil, common.Hash{}, nil) prefetcher := NewPrefetcher(testlog.Logger(t, log.LevelInfo), l1Source, l1BlobSource, eth.ChainIDFromUInt64(6), sources, kv, nil, common.Hash{}, nil)
l2Cl := sources.sources[6] l2Cl := sources.sources[eth.ChainIDFromUInt64(6)]
// Expect one call for each ignored put, plus one more request for when the put succeeds // Expect one call for each ignored put, plus one more request for when the put succeeds
for i := 0; i < putsToIgnore+1; i++ { for i := 0; i < putsToIgnore+1; i++ {
l2Cl.ExpectNodeByHash(hash, node, nil) l2Cl.ExpectNodeByHash(hash, node, nil)
...@@ -802,10 +802,10 @@ func (s *unreliableKvStore) Put(k common.Hash, v []byte) error { ...@@ -802,10 +802,10 @@ func (s *unreliableKvStore) Put(k common.Hash, v []byte) error {
} }
type l2Clients struct { type l2Clients struct {
sources map[uint64]*l2Client sources map[eth.ChainID]*l2Client
} }
func (l *l2Clients) ForChainID(id uint64) (hostTypes.L2Source, error) { func (l *l2Clients) ForChainID(id eth.ChainID) (hostTypes.L2Source, error) {
source, ok := l.sources[id] source, ok := l.sources[id]
if !ok { if !ok {
return nil, fmt.Errorf("no such source for chain %d", id) return nil, fmt.Errorf("no such source for chain %d", id)
...@@ -813,7 +813,7 @@ func (l *l2Clients) ForChainID(id uint64) (hostTypes.L2Source, error) { ...@@ -813,7 +813,7 @@ func (l *l2Clients) ForChainID(id uint64) (hostTypes.L2Source, error) {
return source, nil return source, nil
} }
func (l *l2Clients) ForChainIDWithoutRetries(id uint64) (hostTypes.L2Source, error) { func (l *l2Clients) ForChainIDWithoutRetries(id eth.ChainID) (hostTypes.L2Source, error) {
return l.ForChainID(id) return l.ForChainID(id)
} }
...@@ -849,11 +849,11 @@ func (m *l2Client) ExpectOutputByNumber(blockNum uint64, output eth.Output, err ...@@ -849,11 +849,11 @@ func (m *l2Client) ExpectOutputByNumber(blockNum uint64, output eth.Output, err
m.Mock.On("OutputByNumber", blockNum).Once().Return(output, &err) m.Mock.On("OutputByNumber", blockNum).Once().Return(output, &err)
} }
func createPrefetcher(t *testing.T, chainIDs ...uint64) (*Prefetcher, *testutils.MockL1Source, *testutils.MockBlobsFetcher, *l2Clients, kvstore.KV) { func createPrefetcher(t *testing.T, chainIDs ...eth.ChainID) (*Prefetcher, *testutils.MockL1Source, *testutils.MockBlobsFetcher, *l2Clients, kvstore.KV) {
return createPrefetcherWithAgreedPrestate(t, nil, chainIDs...) return createPrefetcherWithAgreedPrestate(t, nil, chainIDs...)
} }
func createPrefetcherWithAgreedPrestate(t *testing.T, agreedPrestate []byte, chainIDs ...uint64) (*Prefetcher, *testutils.MockL1Source, *testutils.MockBlobsFetcher, *l2Clients, kvstore.KV) { func createPrefetcherWithAgreedPrestate(t *testing.T, agreedPrestate []byte, chainIDs ...eth.ChainID) (*Prefetcher, *testutils.MockL1Source, *testutils.MockBlobsFetcher, *l2Clients, kvstore.KV) {
logger := testlog.Logger(t, log.LevelDebug) logger := testlog.Logger(t, log.LevelDebug)
kv := kvstore.NewMemKV() kv := kvstore.NewMemKV()
...@@ -862,10 +862,10 @@ func createPrefetcherWithAgreedPrestate(t *testing.T, agreedPrestate []byte, cha ...@@ -862,10 +862,10 @@ func createPrefetcherWithAgreedPrestate(t *testing.T, agreedPrestate []byte, cha
// Provide a default chain if none specified. // Provide a default chain if none specified.
if len(chainIDs) == 0 { if len(chainIDs) == 0 {
chainIDs = []uint64{defaultChainID} chainIDs = []eth.ChainID{defaultChainID}
} }
l2Sources := &l2Clients{sources: make(map[uint64]*l2Client)} l2Sources := &l2Clients{sources: make(map[eth.ChainID]*l2Client)}
for i, chainID := range chainIDs { for i, chainID := range chainIDs {
l2Source := &l2Client{ l2Source := &l2Client{
rollupCfg: &rollup.Config{ rollupCfg: &rollup.Config{
...@@ -985,11 +985,11 @@ func (o *legacyPrecompileOracle) Precompile(address common.Address, input []byte ...@@ -985,11 +985,11 @@ func (o *legacyPrecompileOracle) Precompile(address common.Address, input []byte
type mockExecutor struct { type mockExecutor struct {
invoked bool invoked bool
blockNumber uint64 blockNumber uint64
chainID uint64 chainID eth.ChainID
} }
func (m *mockExecutor) RunProgram( func (m *mockExecutor) RunProgram(
ctx context.Context, prefetcher hostcommon.Prefetcher, blockNumber uint64, chainID uint64) error { ctx context.Context, prefetcher hostcommon.Prefetcher, blockNumber uint64, chainID eth.ChainID) error {
m.invoked = true m.invoked = true
m.blockNumber = blockNumber m.blockNumber = blockNumber
m.chainID = chainID m.chainID = chainID
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"errors" "errors"
hostcommon "github.com/ethereum-optimism/optimism/op-program/host/common" hostcommon "github.com/ethereum-optimism/optimism/op-program/host/common"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/retry" "github.com/ethereum-optimism/optimism/op-service/retry"
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -12,14 +13,14 @@ import ( ...@@ -12,14 +13,14 @@ import (
type ProgramExecutor interface { type ProgramExecutor interface {
// RunProgram derives the block at the specified blockNumber // RunProgram derives the block at the specified blockNumber
RunProgram(ctx context.Context, prefetcher hostcommon.Prefetcher, blockNumber uint64, chainID uint64) error RunProgram(ctx context.Context, prefetcher hostcommon.Prefetcher, blockNumber uint64, chainID eth.ChainID) error
} }
// nativeReExecuteBlock is a helper function that re-executes a block natively. // nativeReExecuteBlock is a helper function that re-executes a block natively.
// It is used to populate the kv store with the data needed for the program to // It is used to populate the kv store with the data needed for the program to
// re-derive the block. // re-derive the block.
func (p *Prefetcher) nativeReExecuteBlock( func (p *Prefetcher) nativeReExecuteBlock(
ctx context.Context, agreedBlockHash, blockHash common.Hash, chainID uint64) error { ctx context.Context, agreedBlockHash, blockHash common.Hash, chainID eth.ChainID) error {
// Avoid using the retrying source to prevent indefinite retries as the block may not be canonical and unavailable // Avoid using the retrying source to prevent indefinite retries as the block may not be canonical and unavailable
source, err := p.l2Sources.ForChainIDWithoutRetries(chainID) source, err := p.l2Sources.ForChainIDWithoutRetries(chainID)
if err != nil { if err != nil {
......
...@@ -31,6 +31,6 @@ type L2Source interface { ...@@ -31,6 +31,6 @@ type L2Source interface {
} }
type L2Sources interface { type L2Sources interface {
ForChainID(chainID uint64) (L2Source, error) ForChainID(chainID eth.ChainID) (L2Source, error)
ForChainIDWithoutRetries(chainID uint64) (L2Source, error) ForChainIDWithoutRetries(chainID eth.ChainID) (L2Source, error)
} }
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"os" "os"
"github.com/ethereum-optimism/optimism/op-program/verify" "github.com/ethereum-optimism/optimism/op-program/verify"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
) )
...@@ -44,7 +45,7 @@ func main() { ...@@ -44,7 +45,7 @@ func main() {
} }
// Apply the custom configs by running op-program // Apply the custom configs by running op-program
runner, err := verify.NewRunner(l1RpcUrl, l1RpcKind, l1BeaconUrl, l2RpcUrl, dataDir, "901", 901, false) runner, err := verify.NewRunner(l1RpcUrl, l1RpcKind, l1BeaconUrl, l2RpcUrl, dataDir, "901", eth.ChainIDFromUInt64(901), false)
if err != nil { if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Failed to create runner: %v\n", err.Error()) _, _ = fmt.Fprintf(os.Stderr, "Failed to create runner: %v\n", err.Error())
os.Exit(1) os.Exit(1)
......
...@@ -7,10 +7,11 @@ import ( ...@@ -7,10 +7,11 @@ import (
"os" "os"
"github.com/ethereum-optimism/optimism/op-program/verify" "github.com/ethereum-optimism/optimism/op-program/verify"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
) )
const opMainnetChainID = 10 var opMainnetChainID = eth.ChainIDFromUInt64(10)
func main() { func main() {
var l1RpcUrl string var l1RpcUrl string
......
...@@ -7,10 +7,11 @@ import ( ...@@ -7,10 +7,11 @@ import (
"os" "os"
"github.com/ethereum-optimism/optimism/op-program/verify" "github.com/ethereum-optimism/optimism/op-program/verify"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
) )
const opSepoliaChainID = 11155420 var opSepoliaChainID = eth.ChainIDFromUInt64(11155420)
func main() { func main() {
var l1RpcUrl string var l1RpcUrl string
......
...@@ -43,7 +43,7 @@ type Runner struct { ...@@ -43,7 +43,7 @@ type Runner struct {
runInProcess bool runInProcess bool
} }
func NewRunner(l1RpcUrl string, l1RpcKind string, l1BeaconUrl string, l2RpcUrl string, dataDir string, network string, chainID uint64, runInProcess bool) (*Runner, error) { func NewRunner(l1RpcUrl string, l1RpcKind string, l1BeaconUrl string, l2RpcUrl string, dataDir string, network string, chainID eth.ChainID, runInProcess bool) (*Runner, error) {
ctx := context.Background() ctx := context.Background()
logCfg := oplog.DefaultCLIConfig() logCfg := oplog.DefaultCLIConfig()
logCfg.Level = log.LevelDebug logCfg.Level = log.LevelDebug
......
...@@ -18,6 +18,19 @@ func ChainIDFromUInt64(i uint64) ChainID { ...@@ -18,6 +18,19 @@ func ChainIDFromUInt64(i uint64) ChainID {
return ChainID(*uint256.NewInt(i)) return ChainID(*uint256.NewInt(i))
} }
func ChainIDFromBytes32(b [32]byte) ChainID {
val := new(uint256.Int).SetBytes(b[:])
return ChainID(*val)
}
func ParseDecimalChainID(chainID string) (ChainID, error) {
v, err := uint256.FromDecimal(chainID)
if err != nil {
return ChainID{}, err
}
return ChainID(*v), nil
}
func (id ChainID) String() string { func (id ChainID) String() string {
return ((*uint256.Int)(&id)).Dec() return ((*uint256.Int)(&id)).Dec()
} }
...@@ -34,6 +47,22 @@ func (id ChainID) ToUInt32() (uint32, error) { ...@@ -34,6 +47,22 @@ func (id ChainID) ToUInt32() (uint32, error) {
return uint32(v64), nil return uint32(v64), nil
} }
func (id ChainID) Bytes32() [32]byte {
return (*uint256.Int)(&id).Bytes32()
}
// EvilChainIDToUInt64 converts a ChainID to a uint64 and panic's if the ChainID is too large for a UInt64
// It is "evil" because 32 byte ChainIDs should be universally supported which this method breaks. It is provided
// for legacy purposes to facilitate a transition to full 32 byte chain ID support and should not be used in new code.
// Existing calls should be replaced with full 32 byte support whenever possible.
func EvilChainIDToUInt64(id ChainID) uint64 {
v := (*uint256.Int)(&id)
if !v.IsUint64() {
panic(fmt.Errorf("ChainID too large for uint64: %v", id))
}
return v.Uint64()
}
func (id *ChainID) ToBig() *big.Int { func (id *ChainID) ToBig() *big.Int {
return (*uint256.Int)(id).ToBig() return (*uint256.Int)(id).ToBig()
} }
......
package eth package eth
import ( import (
"cmp"
"encoding/binary" "encoding/binary"
"encoding/json" "encoding/json"
"errors" "errors"
...@@ -35,20 +34,21 @@ func SuperRoot(super Super) Bytes32 { ...@@ -35,20 +34,21 @@ func SuperRoot(super Super) Bytes32 {
} }
type ChainIDAndOutput struct { type ChainIDAndOutput struct {
ChainID uint64 ChainID ChainID
Output Bytes32 Output Bytes32
} }
func (c *ChainIDAndOutput) Marshal() []byte { func (c *ChainIDAndOutput) Marshal() []byte {
d := make([]byte, 64) d := make([]byte, 64)
binary.BigEndian.PutUint64(d[24:32], c.ChainID) chainID := c.ChainID.Bytes32()
copy(d[0:32], chainID[:])
copy(d[32:], c.Output[:]) copy(d[32:], c.Output[:])
return d return d
} }
func NewSuperV1(timestamp uint64, chains ...ChainIDAndOutput) *SuperV1 { func NewSuperV1(timestamp uint64, chains ...ChainIDAndOutput) *SuperV1 {
slices.SortFunc(chains, func(a, b ChainIDAndOutput) int { slices.SortFunc(chains, func(a, b ChainIDAndOutput) int {
return cmp.Compare(a.ChainID, b.ChainID) return a.ChainID.Cmp(b.ChainID)
}) })
return &SuperV1{ return &SuperV1{
Timestamp: timestamp, Timestamp: timestamp,
...@@ -103,7 +103,7 @@ func unmarshalSuperRootV1(data []byte) (*SuperV1, error) { ...@@ -103,7 +103,7 @@ func unmarshalSuperRootV1(data []byte) (*SuperV1, error) {
output.Timestamp = binary.BigEndian.Uint64(data[1:9]) output.Timestamp = binary.BigEndian.Uint64(data[1:9])
for i := 9; i < len(data); i += 64 { for i := 9; i < len(data); i += 64 {
chainOutput := ChainIDAndOutput{ chainOutput := ChainIDAndOutput{
ChainID: binary.BigEndian.Uint64(data[i+24 : i+32]), ChainID: ChainIDFromBytes32([32]byte(data[i : i+32])),
Output: Bytes32(data[i+32 : i+64]), Output: Bytes32(data[i+32 : i+64]),
} }
output.Chains = append(output.Chains, chainOutput) output.Chains = append(output.Chains, chainOutput)
......
...@@ -19,9 +19,9 @@ func TestUnmarshalSuperRoot_TooShortForVersion(t *testing.T) { ...@@ -19,9 +19,9 @@ func TestUnmarshalSuperRoot_TooShortForVersion(t *testing.T) {
func TestSuperRootV1Codec(t *testing.T) { func TestSuperRootV1Codec(t *testing.T) {
t.Run("Valid", func(t *testing.T) { t.Run("Valid", func(t *testing.T) {
chainA := ChainIDAndOutput{ChainID: 11, Output: Bytes32{0x01}} chainA := ChainIDAndOutput{ChainID: ChainIDFromUInt64(11), Output: Bytes32{0x01}}
chainB := ChainIDAndOutput{ChainID: 12, Output: Bytes32{0x02}} chainB := ChainIDAndOutput{ChainID: ChainIDFromUInt64(12), Output: Bytes32{0x02}}
chainC := ChainIDAndOutput{ChainID: 13, Output: Bytes32{0x03}} chainC := ChainIDAndOutput{ChainID: ChainIDFromUInt64(13), Output: Bytes32{0x03}}
superRoot := SuperV1{ superRoot := SuperV1{
Timestamp: 7000, Timestamp: 7000,
Chains: []ChainIDAndOutput{chainA, chainB, chainC}, Chains: []ChainIDAndOutput{chainA, chainB, chainC},
......
...@@ -540,7 +540,7 @@ func (su *SupervisorBackend) SuperRootAtTimestamp(ctx context.Context, timestamp ...@@ -540,7 +540,7 @@ func (su *SupervisorBackend) SuperRootAtTimestamp(ctx context.Context, timestamp
Canonical: canonicalRoot, Canonical: canonicalRoot,
Pending: pending.Marshal(), Pending: pending.Marshal(),
} }
superRootChains[i] = eth.ChainIDAndOutput{ChainID: chainID.ToBig().Uint64(), Output: canonicalRoot} superRootChains[i] = eth.ChainIDAndOutput{ChainID: chainID, Output: canonicalRoot}
} }
superRoot := eth.SuperRoot(&eth.SuperV1{ superRoot := eth.SuperRoot(&eth.SuperV1{
Timestamp: uint64(timestamp), Timestamp: uint64(timestamp),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment