Skip to content

Commit

Permalink
feat(challenger): AsteriscKona trace type
Browse files Browse the repository at this point in the history
Adds support for the new `asterisc-kona` game type in the
`op-challenger`
  • Loading branch information
clabby committed Jul 12, 2024
1 parent 89f7554 commit 0438f3d
Show file tree
Hide file tree
Showing 16 changed files with 347 additions and 51 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 @@ -151,6 +154,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 @@ -545,10 +572,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(cfg.Cannon)
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(cfg.Cannon)
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(cfg.Asterisc)
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(cfg.Asterisc)
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.VmConfig,
syncValidator SyncValidator,
rollupClient outputs.OutputRollupClient,
txSender TxSender,
Expand Down Expand Up @@ -254,7 +265,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, vmCfg, l2Client, prestateProvider, asteriscPrestate, rollupClient, dir, l1HeadID, splitDepth, prestateBlock, poststateBlock)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -287,6 +298,7 @@ func registerCannon(
logger log.Logger,
m metrics.Metricer,
cfg *config.Config,
vmCfg vm.VmConfig,
syncValidator SyncValidator,
rollupClient outputs.OutputRollupClient,
txSender TxSender,
Expand Down Expand Up @@ -321,7 +333,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 @@ -349,7 +360,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, vmCfg, l2Client, prestateProvider, cannonPrestate, rollupClient, dir, l1HeadID, splitDepth, prestateBlock, poststateBlock)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions op-challenger/game/fault/trace/asterisc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ 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.VmConfig, prestateProvider types.PrestateProvider, asteriscPrestate string, localInputs utils.LocalGameInputs, dir string, gameDepth types.Depth) *AsteriscTraceProvider {
return &AsteriscTraceProvider{
logger: logger,
dir: dir,
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, vm.NewOpProgramVmConfig(cfg.Asterisc), cfg.AsteriscAbsolutePreState, localInputs),
gameDepth: gameDepth,
preimageLoader: utils.NewPreimageLoader(kvstore.NewDiskKV(vm.PreimageDir(dir)).Get),
}
Expand Down
4 changes: 2 additions & 2 deletions op-challenger/game/fault/trace/cannon/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ 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.VmConfig, prestateProvider types.PrestateProvider, prestate string, localInputs utils.LocalGameInputs, dir string, gameDepth types.Depth) *CannonTraceProvider {
return &CannonTraceProvider{
logger: logger,
dir: dir,
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, vm.NewOpProgramVmConfig(cfg.Cannon), cfg.CannonAbsolutePreState, localInputs),
gameDepth: gameDepth,
preimageLoader: utils.NewPreimageLoader(kvstore.NewDiskKV(vm.PreimageDir(dir)).Get),
}
Expand Down
2 changes: 1 addition & 1 deletion op-challenger/game/fault/trace/outputs/output_asterisc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
func NewOutputAsteriscTraceAccessor(
logger log.Logger,
m metrics.Metricer,
cfg vm.Config,
cfg vm.VmConfig,
l2Client utils.L2HeaderSource,
prestateProvider types.PrestateProvider,
asteriscPrestate string,
Expand Down
2 changes: 1 addition & 1 deletion op-challenger/game/fault/trace/outputs/output_cannon.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
func NewOutputCannonTraceAccessor(
logger log.Logger,
m metrics.Metricer,
cfg vm.Config,
cfg vm.VmConfig,
l2Client utils.L2HeaderSource,
prestateProvider types.PrestateProvider,
cannonPrestate string,
Expand Down
43 changes: 15 additions & 28 deletions op-challenger/game/fault/trace/vm/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ type Config struct {
InfoFreq uint // Frequency of progress log messages (in VM instructions)
}

type VmConfig interface {
Cfg() Config
FillHostCommand(args []string, dataDir string, inputs utils.LocalGameInputs) ([]string, error)
}

type Executor struct {
cfg Config
cfg VmConfig
logger log.Logger
metrics Metricer
absolutePreState string
Expand All @@ -43,7 +48,7 @@ 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 VmConfig, prestate string, inputs utils.LocalGameInputs) *Executor {
return &Executor{
cfg: cfg,
logger: logger,
Expand Down Expand Up @@ -77,37 +82,19 @@ func (e *Executor) DoGenerateProof(ctx context.Context, dir string, begin uint64
"--input", start,
"--output", lastGeneratedState,
"--meta", "",
"--info-at", "%" + strconv.FormatUint(uint64(e.cfg.InfoFreq), 10),
"--info-at", "%" + strconv.FormatUint(uint64(e.cfg.Cfg().InfoFreq), 10),
"--proof-at", "=" + strconv.FormatUint(end, 10),
"--proof-fmt", filepath.Join(proofDir, "%d.json.gz"),
"--snapshot-at", "%" + strconv.FormatUint(uint64(e.cfg.SnapshotFreq), 10),
"--snapshot-at", "%" + strconv.FormatUint(uint64(e.cfg.Cfg().SnapshotFreq), 10),
"--snapshot-fmt", filepath.Join(snapshotDir, "%d.json.gz"),
}
if end < math.MaxUint64 {
args = append(args, "--stop-at", "="+strconv.FormatUint(end+1, 10))
}
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, err = e.cfg.FillHostCommand(args, dataDir, e.inputs)
if err != nil {
return err
}

if err := os.MkdirAll(snapshotDir, 0755); err != nil {
Expand All @@ -119,9 +106,9 @@ func (e *Executor) DoGenerateProof(ctx context.Context, dir string, begin uint64
if err := os.MkdirAll(proofDir, 0755); err != nil {
return fmt.Errorf("could not create proofs directory %v: %w", proofDir, err)
}
e.logger.Info("Generating trace", "proof", end, "cmd", e.cfg.VmBin, "args", strings.Join(args, ", "))
e.logger.Info("Generating trace", "proof", end, "cmd", e.cfg.Cfg().VmBin, "args", strings.Join(args, ", "))
execStart := time.Now()
err = e.cmdExecutor(ctx, e.logger.New("proof", end), e.cfg.VmBin, args...)
e.metrics.RecordVmExecutionTime(e.cfg.VmType.String(), time.Since(execStart))
err = e.cmdExecutor(ctx, e.logger.New("proof", end), e.cfg.Cfg().VmBin, args...)
e.metrics.RecordVmExecutionTime(e.cfg.Cfg().VmType.String(), time.Since(execStart))
return err
}
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, NewOpProgramVmConfig(cfg), prestate, inputs)
executor.selectSnapshot = func(logger log.Logger, dir string, absolutePreState string, i uint64) (string, error) {
return input, nil
}
Expand Down
44 changes: 44 additions & 0 deletions op-challenger/game/fault/trace/vm/kona_vm_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package vm

import (
"errors"

"github.com/ethereum-optimism/optimism/op-challenger/game/fault/trace/utils"
)

type KonaVmConfig struct {
Config
}

var _ VmConfig = (*KonaVmConfig)(nil)

func NewKonaVmConfig(vmConfig Config) *KonaVmConfig {
return &KonaVmConfig{
vmConfig,
}
}

func (s *KonaVmConfig) Cfg() Config {
return s.Config
}

func (s *KonaVmConfig) FillHostCommand(args []string, dataDir string, inputs utils.LocalGameInputs) ([]string, error) {
if args == nil {
return nil, errors.New("args is nil")
}

args = append(args,
"--",
s.Cfg().Server, "--server",
"--l1-node-address", s.Cfg().L1,
"--l1-beacon-address", s.Cfg().L1Beacon,
"--l2-node-address", s.Cfg().L2,
"--data-dir", dataDir,
"--l1-head", inputs.L1Head.Hex(),
"--l2-head", inputs.L2Head.Hex(),
"--l2-output-root", inputs.L2OutputRoot.Hex(),
"--l2-claim", inputs.L2Claim.Hex(),
"--l2-block-number", inputs.L2BlockNumber.Text(10),
)
return args, nil
}
Loading

0 comments on commit 0438f3d

Please sign in to comment.