Skip to content

Commit

Permalink
feat(challenger): AsteriscKona trace type (#11140)
Browse files Browse the repository at this point in the history
* feat(challenger): `AsteriscKona` trace type

Adds support for the new `asterisc-kona` game type in the
`op-challenger`

* feat: add `kona-host` `--l2-chain-id` flag

* op-challenger: Separate oracle server executor (#11348)

* fix(op-challenger): run trace cmd

* fix(op-challenger): lints

---------

Co-authored-by: Adrian Sutton <adrian@oplabs.co>
Co-authored-by: refcell <abigger87@gmail.com>
  • Loading branch information
3 people authored Aug 6, 2024
1 parent 0681bfc commit 5b7d2b9
Show file tree
Hide file tree
Showing 17 changed files with 349 additions and 54 deletions.
17 changes: 14 additions & 3 deletions op-challenger/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,12 @@ type Config struct {
CannonAbsolutePreStateBaseURL *url.URL // Base URL to retrieve absolute pre-states for Cannon traces from

// Specific to the asterisc trace provider
Asterisc vm.Config
AsteriscAbsolutePreState string // File to load the absolute pre-state for Asterisc traces from
AsteriscAbsolutePreStateBaseURL *url.URL // Base URL to retrieve absolute pre-states for Asterisc traces from
Asterisc vm.Config
AsteriscAbsolutePreState string // File to load the absolute pre-state for Asterisc traces from
AsteriscAbsolutePreStateBaseURL *url.URL // Base URL to retrieve absolute pre-states for Asterisc traces from
AsteriscKona vm.Config
AsteriscKonaAbsolutePreState string // File to load the absolute pre-state for AsteriscKona traces from
AsteriscKonaAbsolutePreStateBaseURL *url.URL // Base URL to retrieve absolute pre-states for AsteriscKona traces from

MaxPendingTx uint64 // Maximum number of pending transactions (0 == no limit)

Expand Down Expand Up @@ -152,6 +155,14 @@ func NewConfig(
SnapshotFreq: DefaultAsteriscSnapshotFreq,
InfoFreq: DefaultAsteriscInfoFreq,
},
AsteriscKona: vm.Config{
VmType: types.TraceTypeAsteriscKona,
L1: l1EthRpc,
L1Beacon: l1BeaconApi,
L2: l2EthRpc,
SnapshotFreq: DefaultAsteriscSnapshotFreq,
InfoFreq: DefaultAsteriscInfoFreq,
},
GameWindow: DefaultGameWindow,
}
}
Expand Down
52 changes: 47 additions & 5 deletions op-challenger/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,33 @@ var (
Usage: "Path to executable to use as pre-image oracle server when generating trace data (asterisc trace type only)",
EnvVars: prefixEnvVars("ASTERISC_SERVER"),
}
AsteriscKonaServerFlag = &cli.StringFlag{
Name: "asterisc-kona-server",
Usage: "Path to kona executable to use as pre-image oracle server when generating trace data (asterisc-kona trace type only)",
EnvVars: prefixEnvVars("ASTERISC_KONA_SERVER"),
}
AsteriscPreStateFlag = &cli.StringFlag{
Name: "asterisc-prestate",
Usage: "Path to absolute prestate to use when generating trace data (asterisc trace type only)",
EnvVars: prefixEnvVars("ASTERISC_PRESTATE"),
}
AsteriscKonaPreStateFlag = &cli.StringFlag{
Name: "asterisc-kona-prestate",
Usage: "Path to absolute prestate to use when generating trace data (asterisc-kona trace type only)",
EnvVars: prefixEnvVars("ASTERISC_KONA_PRESTATE"),
}
AsteriscPreStatesURLFlag = &cli.StringFlag{
Name: "asterisc-prestates-url",
Usage: "Base URL to absolute prestates to use when generating trace data. " +
"Prestates in this directory should be name as <commitment>.json (asterisc trace type only)",
EnvVars: prefixEnvVars("ASTERISC_PRESTATES_URL"),
}
AsteriscKonaPreStatesURLFlag = &cli.StringFlag{
Name: "asterisc-kona-prestates-url",
Usage: "Base URL to absolute prestates to use when generating trace data. " +
"Prestates in this directory should be name as <commitment>.json (asterisc-kona trace type only)",
EnvVars: prefixEnvVars("ASTERISC_KONA_PRESTATES_URL"),
}
AsteriscSnapshotFreqFlag = &cli.UintFlag{
Name: "asterisc-snapshot-freq",
Usage: "Frequency of asterisc snapshots to generate in VM steps (asterisc trace type only)",
Expand Down Expand Up @@ -255,8 +271,11 @@ var optionalFlags = []cli.Flag{
AsteriscL2GenesisFlag,
AsteriscBinFlag,
AsteriscServerFlag,
AsteriscKonaServerFlag,
AsteriscPreStateFlag,
AsteriscKonaPreStateFlag,
AsteriscPreStatesURLFlag,
AsteriscKonaPreStatesURLFlag,
AsteriscSnapshotFreqFlag,
AsteriscInfoFreqFlag,
GameWindowFlag,
Expand Down Expand Up @@ -486,6 +505,14 @@ func NewConfigFromCLI(ctx *cli.Context, logger log.Logger) (*config.Config, erro
}
asteriscPreStatesURL = parsed
}
var asteriscKonaPreStatesURL *url.URL
if ctx.IsSet(AsteriscKonaPreStatesURLFlag.Name) {
parsed, err := url.Parse(ctx.String(AsteriscKonaPreStatesURLFlag.Name))
if err != nil {
return nil, fmt.Errorf("invalid asterisc-kona pre states url (%v): %w", ctx.String(AsteriscKonaPreStatesURLFlag.Name), err)
}
asteriscKonaPreStatesURL = parsed
}
l2Rpc, err := getL2Rpc(ctx, logger)
if err != nil {
return nil, err
Expand Down Expand Up @@ -546,10 +573,25 @@ func NewConfigFromCLI(ctx *cli.Context, logger log.Logger) (*config.Config, erro
},
AsteriscAbsolutePreState: ctx.String(AsteriscPreStateFlag.Name),
AsteriscAbsolutePreStateBaseURL: asteriscPreStatesURL,
TxMgrConfig: txMgrConfig,
MetricsConfig: metricsConfig,
PprofConfig: pprofConfig,
SelectiveClaimResolution: ctx.Bool(SelectiveClaimResolutionFlag.Name),
AllowInvalidPrestate: ctx.Bool(UnsafeAllowInvalidPrestate.Name),
AsteriscKona: vm.Config{
VmType: types.TraceTypeAsteriscKona,
L1: l1EthRpc,
L1Beacon: l1Beacon,
L2: l2Rpc,
VmBin: ctx.String(AsteriscBinFlag.Name),
Server: ctx.String(AsteriscKonaServerFlag.Name),
Network: asteriscNetwork,
RollupConfigPath: ctx.String(AsteriscRollupConfigFlag.Name),
L2GenesisPath: ctx.String(AsteriscL2GenesisFlag.Name),
SnapshotFreq: ctx.Uint(AsteriscSnapshotFreqFlag.Name),
InfoFreq: ctx.Uint(AsteriscInfoFreqFlag.Name),
},
AsteriscKonaAbsolutePreState: ctx.String(AsteriscKonaPreStateFlag.Name),
AsteriscKonaAbsolutePreStateBaseURL: asteriscKonaPreStatesURL,
TxMgrConfig: txMgrConfig,
MetricsConfig: metricsConfig,
PprofConfig: pprofConfig,
SelectiveClaimResolution: ctx.Bool(SelectiveClaimResolutionFlag.Name),
AllowInvalidPrestate: ctx.Bool(UnsafeAllowInvalidPrestate.Name),
}, nil
}
23 changes: 17 additions & 6 deletions op-challenger/game/fault/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/trace/outputs"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/trace/prestates"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/trace/utils"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/trace/vm"
faultTypes "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/scheduler"
Expand Down Expand Up @@ -74,20 +75,29 @@ func RegisterGameTypes(
syncValidator := newSyncStatusValidator(rollupClient)

if cfg.TraceTypeEnabled(faultTypes.TraceTypeCannon) {
if err := registerCannon(faultTypes.CannonGameType, registry, oracles, ctx, systemClock, l1Clock, logger, m, cfg, syncValidator, rollupClient, txSender, gameFactory, caller, l2Client, l1HeaderSource, selective, claimants); err != nil {
vmConfig := vm.NewOpProgramVmConfig()
if err := registerCannon(faultTypes.CannonGameType, registry, oracles, ctx, systemClock, l1Clock, logger, m, cfg, vmConfig, syncValidator, rollupClient, txSender, gameFactory, caller, l2Client, l1HeaderSource, selective, claimants); err != nil {
return nil, fmt.Errorf("failed to register cannon game type: %w", err)
}
}
if cfg.TraceTypeEnabled(faultTypes.TraceTypePermissioned) {
if err := registerCannon(faultTypes.PermissionedGameType, registry, oracles, ctx, systemClock, l1Clock, logger, m, cfg, syncValidator, rollupClient, txSender, gameFactory, caller, l2Client, l1HeaderSource, selective, claimants); err != nil {
vmConfig := vm.NewOpProgramVmConfig()
if err := registerCannon(faultTypes.PermissionedGameType, registry, oracles, ctx, systemClock, l1Clock, logger, m, cfg, vmConfig, syncValidator, rollupClient, txSender, gameFactory, caller, l2Client, l1HeaderSource, selective, claimants); err != nil {
return nil, fmt.Errorf("failed to register permissioned cannon game type: %w", err)
}
}
if cfg.TraceTypeEnabled(faultTypes.TraceTypeAsterisc) {
if err := registerAsterisc(faultTypes.AsteriscGameType, registry, oracles, ctx, systemClock, l1Clock, logger, m, cfg, syncValidator, rollupClient, txSender, gameFactory, caller, l2Client, l1HeaderSource, selective, claimants); err != nil {
vmConfig := vm.NewOpProgramVmConfig()
if err := registerAsterisc(faultTypes.AsteriscGameType, registry, oracles, ctx, systemClock, l1Clock, logger, m, cfg, vmConfig, syncValidator, rollupClient, txSender, gameFactory, caller, l2Client, l1HeaderSource, selective, claimants); err != nil {
return nil, fmt.Errorf("failed to register asterisc game type: %w", err)
}
}
if cfg.TraceTypeEnabled(faultTypes.TraceTypeAsteriscKona) {
vmConfig := vm.NewKonaVmConfig()
if err := registerAsterisc(faultTypes.AsteriscKonaGameType, registry, oracles, ctx, systemClock, l1Clock, logger, m, cfg, vmConfig, syncValidator, rollupClient, txSender, gameFactory, caller, l2Client, l1HeaderSource, selective, claimants); err != nil {
return nil, fmt.Errorf("failed to register asterisc kona game type: %w", err)
}
}
if cfg.TraceTypeEnabled(faultTypes.TraceTypeFast) {
if err := registerAlphabet(faultTypes.FastGameType, registry, oracles, ctx, systemClock, l1Clock, logger, m, syncValidator, rollupClient, l2Client, txSender, gameFactory, caller, l1HeaderSource, selective, claimants); err != nil {
return nil, fmt.Errorf("failed to register fast game type: %w", err)
Expand Down Expand Up @@ -194,6 +204,7 @@ func registerAsterisc(
logger log.Logger,
m metrics.Metricer,
cfg *config.Config,
vmCfg vm.OracleServerExecutor,
syncValidator SyncValidator,
rollupClient outputs.OutputRollupClient,
txSender TxSender,
Expand Down Expand Up @@ -249,7 +260,7 @@ func registerAsterisc(
if err != nil {
return nil, fmt.Errorf("failed to get asterisc prestate: %w", err)
}
accessor, err := outputs.NewOutputAsteriscTraceAccessor(logger, m, cfg.Asterisc, l2Client, prestateProvider, asteriscPrestate, rollupClient, dir, l1HeadID, splitDepth, prestateBlock, poststateBlock)
accessor, err := outputs.NewOutputAsteriscTraceAccessor(logger, m, cfg.Asterisc, vmCfg, l2Client, prestateProvider, asteriscPrestate, rollupClient, dir, l1HeadID, splitDepth, prestateBlock, poststateBlock)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -282,6 +293,7 @@ func registerCannon(
logger log.Logger,
m metrics.Metricer,
cfg *config.Config,
vmCfg vm.OracleServerExecutor,
syncValidator SyncValidator,
rollupClient outputs.OutputRollupClient,
txSender TxSender,
Expand Down Expand Up @@ -311,7 +323,6 @@ func registerCannon(
}

cannonPrestateProvider, err := prestateProviderCache.GetOrCreate(requiredPrestatehash)

if err != nil {
return nil, fmt.Errorf("required prestate %v not available for game %v: %w", requiredPrestatehash, game.Proxy, err)
}
Expand Down Expand Up @@ -339,7 +350,7 @@ func registerCannon(
if err != nil {
return nil, fmt.Errorf("failed to get cannon prestate: %w", err)
}
accessor, err := outputs.NewOutputCannonTraceAccessor(logger, m, cfg.Cannon, l2Client, prestateProvider, cannonPrestate, rollupClient, dir, l1HeadID, splitDepth, prestateBlock, poststateBlock)
accessor, err := outputs.NewOutputCannonTraceAccessor(logger, m, cfg.Cannon, vmCfg, l2Client, prestateProvider, cannonPrestate, rollupClient, dir, l1HeadID, splitDepth, prestateBlock, poststateBlock)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions op-challenger/game/fault/trace/asterisc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ type AsteriscTraceProvider struct {
lastStep uint64
}

func NewTraceProvider(logger log.Logger, m vm.Metricer, cfg vm.Config, prestateProvider types.PrestateProvider, asteriscPrestate string, localInputs utils.LocalGameInputs, dir string, gameDepth types.Depth) *AsteriscTraceProvider {
func NewTraceProvider(logger log.Logger, m vm.Metricer, cfg vm.Config, vmCfg vm.OracleServerExecutor, prestateProvider types.PrestateProvider, asteriscPrestate string, localInputs utils.LocalGameInputs, dir string, gameDepth types.Depth) *AsteriscTraceProvider {
return &AsteriscTraceProvider{
logger: logger,
dir: dir,
prestate: asteriscPrestate,
generator: vm.NewExecutor(logger, m, cfg, asteriscPrestate, localInputs),
generator: vm.NewExecutor(logger, m, cfg, vmCfg, asteriscPrestate, localInputs),
gameDepth: gameDepth,
preimageLoader: utils.NewPreimageLoader(kvstore.NewDiskKV(vm.PreimageDir(dir)).Get),
PrestateProvider: prestateProvider,
Expand Down Expand Up @@ -177,7 +177,7 @@ func NewTraceProviderForTest(logger log.Logger, m vm.Metricer, cfg *config.Confi
logger: logger,
dir: dir,
prestate: cfg.AsteriscAbsolutePreState,
generator: vm.NewExecutor(logger, m, cfg.Asterisc, cfg.AsteriscAbsolutePreState, localInputs),
generator: vm.NewExecutor(logger, m, cfg.Asterisc, vm.NewOpProgramVmConfig(), cfg.AsteriscAbsolutePreState, localInputs),
gameDepth: gameDepth,
preimageLoader: utils.NewPreimageLoader(kvstore.NewDiskKV(vm.PreimageDir(dir)).Get),
}
Expand Down
6 changes: 3 additions & 3 deletions op-challenger/game/fault/trace/cannon/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ type CannonTraceProvider struct {
lastStep uint64
}

func NewTraceProvider(logger log.Logger, m vm.Metricer, cfg vm.Config, prestateProvider types.PrestateProvider, prestate string, localInputs utils.LocalGameInputs, dir string, gameDepth types.Depth) *CannonTraceProvider {
func NewTraceProvider(logger log.Logger, m vm.Metricer, cfg vm.Config, vmCfg vm.OracleServerExecutor, prestateProvider types.PrestateProvider, prestate string, localInputs utils.LocalGameInputs, dir string, gameDepth types.Depth) *CannonTraceProvider {
return &CannonTraceProvider{
logger: logger,
dir: dir,
prestate: prestate,
generator: vm.NewExecutor(logger, m, cfg, prestate, localInputs),
generator: vm.NewExecutor(logger, m, cfg, vmCfg, prestate, localInputs),
gameDepth: gameDepth,
preimageLoader: utils.NewPreimageLoader(kvstore.NewDiskKV(vm.PreimageDir(dir)).Get),
PrestateProvider: prestateProvider,
Expand Down Expand Up @@ -181,7 +181,7 @@ func NewTraceProviderForTest(logger log.Logger, m vm.Metricer, cfg *config.Confi
logger: logger,
dir: dir,
prestate: cfg.CannonAbsolutePreState,
generator: vm.NewExecutor(logger, m, cfg.Cannon, cfg.CannonAbsolutePreState, localInputs),
generator: vm.NewExecutor(logger, m, cfg.Cannon, vm.NewOpProgramVmConfig(), cfg.CannonAbsolutePreState, localInputs),
gameDepth: gameDepth,
preimageLoader: utils.NewPreimageLoader(kvstore.NewDiskKV(vm.PreimageDir(dir)).Get),
}
Expand Down
3 changes: 2 additions & 1 deletion op-challenger/game/fault/trace/outputs/output_asterisc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func NewOutputAsteriscTraceAccessor(
logger log.Logger,
m metrics.Metricer,
cfg vm.Config,
vmCfg vm.OracleServerExecutor,
l2Client utils.L2HeaderSource,
prestateProvider types.PrestateProvider,
asteriscPrestate string,
Expand All @@ -40,7 +41,7 @@ func NewOutputAsteriscTraceAccessor(
if err != nil {
return nil, fmt.Errorf("failed to fetch asterisc local inputs: %w", err)
}
provider := asterisc.NewTraceProvider(logger, m, cfg, prestateProvider, asteriscPrestate, localInputs, subdir, depth)
provider := asterisc.NewTraceProvider(logger, m, cfg, vmCfg, prestateProvider, asteriscPrestate, localInputs, subdir, depth)
return provider, nil
}

Expand Down
3 changes: 2 additions & 1 deletion op-challenger/game/fault/trace/outputs/output_cannon.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func NewOutputCannonTraceAccessor(
logger log.Logger,
m metrics.Metricer,
cfg vm.Config,
vmCfg vm.OracleServerExecutor,
l2Client utils.L2HeaderSource,
prestateProvider types.PrestateProvider,
cannonPrestate string,
Expand All @@ -40,7 +41,7 @@ func NewOutputCannonTraceAccessor(
if err != nil {
return nil, fmt.Errorf("failed to fetch cannon local inputs: %w", err)
}
provider := cannon.NewTraceProvider(logger, m, cfg, prestateProvider, cannonPrestate, localInputs, subdir, depth)
provider := cannon.NewTraceProvider(logger, m, cfg, vmCfg, prestateProvider, cannonPrestate, localInputs, subdir, depth)
return provider, nil
}

Expand Down
47 changes: 20 additions & 27 deletions op-challenger/game/fault/trace/vm/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,30 @@ type Metricer interface {
}

type Config struct {
VmType types.TraceType
// VM Configuration
VmType types.TraceType
VmBin string // Path to the vm executable to run when generating trace data
SnapshotFreq uint // Frequency of snapshots to create when executing (in VM instructions)
InfoFreq uint // Frequency of progress log messages (in VM instructions)
DebugInfo bool

// Host Configuration
L1 string
L1Beacon string
L2 string
VmBin string // Path to the vm executable to run when generating trace data
Server string // Path to the executable that provides the pre-image oracle server
Network string
RollupConfigPath string
L2GenesisPath string
SnapshotFreq uint // Frequency of snapshots to create when executing (in VM instructions)
InfoFreq uint // Frequency of progress log messages (in VM instructions)
DebugInfo bool
}

type OracleServerExecutor interface {
OracleCommand(cfg Config, dataDir string, inputs utils.LocalGameInputs) ([]string, error)
}

type Executor struct {
cfg Config
oracleServer OracleServerExecutor
logger log.Logger
metrics Metricer
absolutePreState string
Expand All @@ -51,9 +59,10 @@ type Executor struct {
cmdExecutor CmdExecutor
}

func NewExecutor(logger log.Logger, m Metricer, cfg Config, prestate string, inputs utils.LocalGameInputs) *Executor {
func NewExecutor(logger log.Logger, m Metricer, cfg Config, oracleServer OracleServerExecutor, prestate string, inputs utils.LocalGameInputs) *Executor {
return &Executor{
cfg: cfg,
oracleServer: oracleServer,
logger: logger,
metrics: m,
inputs: inputs,
Expand Down Expand Up @@ -98,28 +107,12 @@ func (e *Executor) DoGenerateProof(ctx context.Context, dir string, begin uint64
args = append(args, "--debug-info", filepath.Join(dataDir, debugFilename))
}
args = append(args, extraVmArgs...)
args = append(args,
"--",
e.cfg.Server, "--server",
"--l1", e.cfg.L1,
"--l1.beacon", e.cfg.L1Beacon,
"--l2", e.cfg.L2,
"--datadir", dataDir,
"--l1.head", e.inputs.L1Head.Hex(),
"--l2.head", e.inputs.L2Head.Hex(),
"--l2.outputroot", e.inputs.L2OutputRoot.Hex(),
"--l2.claim", e.inputs.L2Claim.Hex(),
"--l2.blocknumber", e.inputs.L2BlockNumber.Text(10),
)
if e.cfg.Network != "" {
args = append(args, "--network", e.cfg.Network)
}
if e.cfg.RollupConfigPath != "" {
args = append(args, "--rollup.config", e.cfg.RollupConfigPath)
}
if e.cfg.L2GenesisPath != "" {
args = append(args, "--l2.genesis", e.cfg.L2GenesisPath)
args = append(args, "--")
oracleArgs, err := e.oracleServer.OracleCommand(e.cfg, dataDir, e.inputs)
if err != nil {
return err
}
args = append(args, oracleArgs...)

if err := os.MkdirAll(snapshotDir, 0755); err != nil {
return fmt.Errorf("could not create snapshot directory %v: %w", snapshotDir, err)
Expand Down
2 changes: 1 addition & 1 deletion op-challenger/game/fault/trace/vm/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestGenerateProof(t *testing.T) {
}
captureExec := func(t *testing.T, cfg Config, proofAt uint64) (string, string, map[string]string) {
m := &stubVmMetrics{}
executor := NewExecutor(testlog.Logger(t, log.LevelInfo), m, cfg, prestate, inputs)
executor := NewExecutor(testlog.Logger(t, log.LevelInfo), m, cfg, NewOpProgramVmConfig(), prestate, inputs)
executor.selectSnapshot = func(logger log.Logger, dir string, absolutePreState string, i uint64) (string, error) {
return input, nil
}
Expand Down
Loading

0 comments on commit 5b7d2b9

Please sign in to comment.