Skip to content

Commit

Permalink
fix(challenger): asterisc-kona trace type (#11789)
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby authored Sep 7, 2024
1 parent 1824499 commit 52336b4
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 50 deletions.
143 changes: 102 additions & 41 deletions op-challenger/cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,66 +264,117 @@ func TestPollInterval(t *testing.T) {
})
}

func TestAsteriscRequiredArgs(t *testing.T) {
for _, traceType := range []types.TraceType{types.TraceTypeAsterisc} {
traceType := traceType
t.Run(fmt.Sprintf("TestAsteriscBin-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(types.TraceTypeAlphabet, "--asterisc-bin"))
})
func TestAsteriscOpProgramRequiredArgs(t *testing.T) {
traceType := types.TraceTypeAsterisc
t.Run(fmt.Sprintf("TestAsteriscServer-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(types.TraceTypeAlphabet, "--asterisc-server"))
})

t.Run("Required", func(t *testing.T) {
verifyArgsInvalid(t, "flag asterisc-bin is required", addRequiredArgsExcept(traceType, "--asterisc-bin"))
})
t.Run("Required", func(t *testing.T) {
verifyArgsInvalid(t, "flag asterisc-server is required", addRequiredArgsExcept(traceType, "--asterisc-server"))
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--asterisc-bin", "--asterisc-bin=./asterisc"))
require.Equal(t, "./asterisc", cfg.Asterisc.VmBin)
})
t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--asterisc-server", "--asterisc-server=./op-program"))
require.Equal(t, "./op-program", cfg.Asterisc.Server)
})
})

t.Run(fmt.Sprintf("TestAsteriscServer-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(types.TraceTypeAlphabet, "--asterisc-server"))
})
t.Run(fmt.Sprintf("TestAsteriscAbsolutePrestate-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(types.TraceTypeAlphabet, "--asterisc-prestate"))
})

t.Run("Required", func(t *testing.T) {
verifyArgsInvalid(t, "flag asterisc-server is required", addRequiredArgsExcept(traceType, "--asterisc-server"))
})
t.Run("Required", func(t *testing.T) {
verifyArgsInvalid(t, "flag asterisc-prestates-url or asterisc-prestate is required", addRequiredArgsExcept(traceType, "--asterisc-prestate"))
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--asterisc-server", "--asterisc-server=./op-program"))
require.Equal(t, "./op-program", cfg.Asterisc.Server)
})
t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--asterisc-prestate", "--asterisc-prestate=./pre.json"))
require.Equal(t, "./pre.json", cfg.AsteriscAbsolutePreState)
})
})

t.Run(fmt.Sprintf("TestAsteriscAbsolutePrestate-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(types.TraceTypeAlphabet, "--asterisc-prestate"))
})
t.Run(fmt.Sprintf("TestAsteriscAbsolutePrestateBaseURL-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(types.TraceTypeAlphabet, "--asterisc-prestates-url"))
})

t.Run("Required", func(t *testing.T) {
verifyArgsInvalid(t, "flag asterisc-prestates-url or asterisc-prestate is required", addRequiredArgsExcept(traceType, "--asterisc-prestate"))
})
t.Run("Required", func(t *testing.T) {
verifyArgsInvalid(t, "flag asterisc-prestates-url or asterisc-prestate is required", addRequiredArgsExcept(traceType, "--asterisc-prestate"))
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--asterisc-prestate", "--asterisc-prestate=./pre.json"))
require.Equal(t, "./pre.json", cfg.AsteriscAbsolutePreState)
})
t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--asterisc-prestates-url", "--asterisc-prestates-url=http://localhost/bar"))
require.Equal(t, "http://localhost/bar", cfg.AsteriscAbsolutePreStateBaseURL.String())
})
})
}

t.Run(fmt.Sprintf("TestAsteriscAbsolutePrestateBaseURL-%v", traceType), func(t *testing.T) {
func TestAsteriscKonaRequiredArgs(t *testing.T) {
traceType := types.TraceTypeAsteriscKona
t.Run(fmt.Sprintf("TestAsteriscServer-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(types.TraceTypeAlphabet, "--asterisc-kona-server"))
})

t.Run("Required", func(t *testing.T) {
verifyArgsInvalid(t, "flag asterisc-kona-server is required", addRequiredArgsExcept(traceType, "--asterisc-kona-server"))
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--asterisc-kona-server", "--asterisc-kona-server=./kona-host"))
require.Equal(t, "./kona-host", cfg.AsteriscKona.Server)
})
})

t.Run(fmt.Sprintf("TestAsteriscAbsolutePrestate-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(types.TraceTypeAlphabet, "--asterisc-kona-prestate"))
})

t.Run("Required", func(t *testing.T) {
verifyArgsInvalid(t, "flag asterisc-kona-prestates-url or asterisc-kona-prestate is required", addRequiredArgsExcept(traceType, "--asterisc-kona-prestate"))
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--asterisc-kona-prestate", "--asterisc-kona-prestate=./pre.json"))
require.Equal(t, "./pre.json", cfg.AsteriscKonaAbsolutePreState)
})
})

t.Run(fmt.Sprintf("TestAsteriscAbsolutePrestateBaseURL-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(types.TraceTypeAlphabet, "--asterisc-kona-prestates-url"))
})

t.Run("Required", func(t *testing.T) {
verifyArgsInvalid(t, "flag asterisc-kona-prestates-url or asterisc-kona-prestate is required", addRequiredArgsExcept(traceType, "--asterisc-kona-prestate"))
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--asterisc-kona-prestates-url", "--asterisc-kona-prestates-url=http://localhost/bar"))
require.Equal(t, "http://localhost/bar", cfg.AsteriscKonaAbsolutePreStateBaseURL.String())
})
})
}

func TestAsteriscBaseRequiredArgs(t *testing.T) {
for _, traceType := range []types.TraceType{types.TraceTypeAsterisc, types.TraceTypeAsteriscKona} {
traceType := traceType
t.Run(fmt.Sprintf("TestAsteriscBin-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(types.TraceTypeAlphabet, "--asterisc-prestates-url"))
configForArgs(t, addRequiredArgsExcept(types.TraceTypeAlphabet, "--asterisc-bin"))
})

t.Run("Required", func(t *testing.T) {
verifyArgsInvalid(t, "flag asterisc-prestates-url or asterisc-prestate is required", addRequiredArgsExcept(traceType, "--asterisc-prestate"))
verifyArgsInvalid(t, "flag asterisc-bin is required", addRequiredArgsExcept(traceType, "--asterisc-bin"))
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--asterisc-prestates-url", "--asterisc-prestates-url=http://localhost/bar"))
require.Equal(t, "http://localhost/bar", cfg.AsteriscAbsolutePreStateBaseURL.String())
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--asterisc-bin", "--asterisc-bin=./asterisc"))
require.Equal(t, "./asterisc", cfg.Asterisc.VmBin)
})
})

Expand Down Expand Up @@ -853,6 +904,8 @@ func requiredArgs(traceType types.TraceType) map[string]string {
addRequiredCannonArgs(args)
case types.TraceTypeAsterisc:
addRequiredAsteriscArgs(args)
case types.TraceTypeAsteriscKona:
addRequiredAsteriscKonaArgs(args)
}
return args
}
Expand All @@ -873,6 +926,14 @@ func addRequiredAsteriscArgs(args map[string]string) {
args["--l2-eth-rpc"] = l2EthRpc
}

func addRequiredAsteriscKonaArgs(args map[string]string) {
args["--asterisc-network"] = asteriscNetwork
args["--asterisc-bin"] = asteriscBin
args["--asterisc-kona-server"] = asteriscServer
args["--asterisc-kona-prestate"] = asteriscPreState
args["--l2-eth-rpc"] = l2EthRpc
}

func toArgList(req map[string]string) []string {
var combined []string
for name, value := range req {
Expand Down
26 changes: 25 additions & 1 deletion op-challenger/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func CheckCannonFlags(ctx *cli.Context) error {
return nil
}

func CheckAsteriscFlags(ctx *cli.Context) error {
func CheckAsteriscBaseFlags(ctx *cli.Context) error {
if ctx.IsSet(AsteriscNetworkFlag.Name) && ctx.IsSet(flags.NetworkFlagName) {
return fmt.Errorf("flag %v can not be used with %v", AsteriscNetworkFlag.Name, flags.NetworkFlagName)
}
Expand All @@ -350,6 +350,13 @@ func CheckAsteriscFlags(ctx *cli.Context) error {
if !ctx.IsSet(AsteriscBinFlag.Name) {
return fmt.Errorf("flag %s is required", AsteriscBinFlag.Name)
}
return nil
}

func CheckAsteriscFlags(ctx *cli.Context) error {
if err := CheckAsteriscBaseFlags(ctx); err != nil {
return err
}
if !ctx.IsSet(AsteriscServerFlag.Name) {
return fmt.Errorf("flag %s is required", AsteriscServerFlag.Name)
}
Expand All @@ -359,6 +366,19 @@ func CheckAsteriscFlags(ctx *cli.Context) error {
return nil
}

func CheckAsteriscKonaFlags(ctx *cli.Context) error {
if err := CheckAsteriscBaseFlags(ctx); err != nil {
return err
}
if !ctx.IsSet(AsteriscKonaServerFlag.Name) {
return fmt.Errorf("flag %s is required", AsteriscKonaServerFlag.Name)
}
if !ctx.IsSet(AsteriscKonaPreStateFlag.Name) && !ctx.IsSet(AsteriscKonaPreStatesURLFlag.Name) {
return fmt.Errorf("flag %s or %s is required", AsteriscKonaPreStatesURLFlag.Name, AsteriscKonaPreStateFlag.Name)
}
return nil
}

func CheckRequired(ctx *cli.Context, traceTypes []types.TraceType) error {
for _, f := range requiredFlags {
if !ctx.IsSet(f.Names()[0]) {
Expand All @@ -379,6 +399,10 @@ func CheckRequired(ctx *cli.Context, traceTypes []types.TraceType) error {
if err := CheckAsteriscFlags(ctx); err != nil {
return err
}
case types.TraceTypeAsteriscKona:
if err := CheckAsteriscKonaFlags(ctx); err != nil {
return err
}
case types.TraceTypeAlphabet, types.TraceTypeFast:
default:
return fmt.Errorf("invalid trace type %v. must be one of %v", traceType, types.TraceTypes)
Expand Down
2 changes: 1 addition & 1 deletion op-challenger/game/fault/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func RegisterGameTypes(
registerTasks = append(registerTasks, NewAsteriscRegisterTask(faultTypes.AsteriscGameType, cfg, m, vm.NewOpProgramServerExecutor()))
}
if cfg.TraceTypeEnabled(faultTypes.TraceTypeAsteriscKona) {
registerTasks = append(registerTasks, NewAsteriscRegisterTask(faultTypes.AsteriscKonaGameType, cfg, m, vm.NewKonaServerExecutor()))
registerTasks = append(registerTasks, NewAsteriscKonaRegisterTask(faultTypes.AsteriscKonaGameType, cfg, m, vm.NewKonaServerExecutor()))
}
if cfg.TraceTypeEnabled(faultTypes.TraceTypeFast) {
registerTasks = append(registerTasks, NewAlphabetRegisterTask(faultTypes.FastGameType))
Expand Down
30 changes: 30 additions & 0 deletions op-challenger/game/fault/register_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,36 @@ func NewAsteriscRegisterTask(gameType faultTypes.GameType, cfg *config.Config, m
}
}

func NewAsteriscKonaRegisterTask(gameType faultTypes.GameType, cfg *config.Config, m caching.Metrics, serverExecutor vm.OracleServerExecutor) *RegisterTask {
return &RegisterTask{
gameType: gameType,
getPrestateProvider: cachePrestates(
gameType,
m,
cfg.AsteriscKonaAbsolutePreStateBaseURL,
cfg.AsteriscKonaAbsolutePreState,
filepath.Join(cfg.Datadir, "asterisc-kona-prestates"),
func(path string) faultTypes.PrestateProvider {
return vm.NewPrestateProvider(path, asterisc.NewStateConverter())
}),
newTraceAccessor: func(
logger log.Logger,
m metrics.Metricer,
l2Client utils.L2HeaderSource,
prestateProvider faultTypes.PrestateProvider,
vmPrestateProvider faultTypes.PrestateProvider,
rollupClient outputs.OutputRollupClient,
dir string,
l1Head eth.BlockID,
splitDepth faultTypes.Depth,
prestateBlock uint64,
poststateBlock uint64) (*trace.Accessor, error) {
provider := vmPrestateProvider.(*vm.PrestateProvider)
return outputs.NewOutputAsteriscTraceAccessor(logger, m, cfg.AsteriscKona, serverExecutor, l2Client, prestateProvider, provider.PrestatePath(), rollupClient, dir, l1Head, splitDepth, prestateBlock, poststateBlock)
},
}
}

func NewAlphabetRegisterTask(gameType faultTypes.GameType) *RegisterTask {
return &RegisterTask{
gameType: gameType,
Expand Down
12 changes: 8 additions & 4 deletions op-challenger/game/fault/trace/vm/kona_server_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"github.com/ethereum-optimism/optimism/op-node/chaincfg"
)

type KonaServerExecutor struct {
}
type KonaServerExecutor struct{}

var _ OracleServerExecutor = (*KonaServerExecutor)(nil)

Expand All @@ -23,7 +22,7 @@ func (s *KonaServerExecutor) OracleCommand(cfg Config, dataDir string, inputs ut
}

chainCfg := chaincfg.ChainByName(cfg.Network)
return []string{
args := []string{
cfg.Server, "--server",
"--l1-node-address", cfg.L1,
"--l1-beacon-address", cfg.L1Beacon,
Expand All @@ -35,5 +34,10 @@ func (s *KonaServerExecutor) OracleCommand(cfg Config, dataDir string, inputs ut
"--l2-output-root", inputs.L2OutputRoot.Hex(),
"--l2-claim", inputs.L2Claim.Hex(),
"--l2-block-number", inputs.L2BlockNumber.Text(10),
}, nil
}
if cfg.RollupConfigPath != "" {
args = append(args, "--rollup-config-path", cfg.RollupConfigPath)
}

return args, nil
}
4 changes: 3 additions & 1 deletion op-challenger/game/fault/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const (
TraceTypePermissioned TraceType = "permissioned"
)

var TraceTypes = []TraceType{TraceTypeAlphabet, TraceTypeCannon, TraceTypePermissioned, TraceTypeAsterisc, TraceTypeFast}
var TraceTypes = []TraceType{TraceTypeAlphabet, TraceTypeCannon, TraceTypePermissioned, TraceTypeAsterisc, TraceTypeAsteriscKona, TraceTypeFast}

func (t TraceType) String() string {
return string(t)
Expand Down Expand Up @@ -104,6 +104,8 @@ func (t TraceType) GameType() GameType {
return PermissionedGameType
case TraceTypeAsterisc:
return AsteriscGameType
case TraceTypeAsteriscKona:
return AsteriscKonaGameType
case TraceTypeFast:
return FastGameType
case TraceTypeAlphabet:
Expand Down
4 changes: 2 additions & 2 deletions op-challenger/runner/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ func createTraceProvider(
return asterisc.NewTraceProvider(logger, m, cfg.Asterisc, vmConfig, prestateProvider, prestate, localInputs, dir, 42), nil
case types.TraceTypeAsteriscKona:
vmConfig := vm.NewKonaServerExecutor()
prestate, err := getPrestate(prestateHash, cfg.AsteriscAbsolutePreStateBaseURL, cfg.AsteriscAbsolutePreState, dir)
prestate, err := getPrestate(prestateHash, cfg.AsteriscKonaAbsolutePreStateBaseURL, cfg.AsteriscKonaAbsolutePreState, dir)
if err != nil {
return nil, err
}
prestateProvider := vm.NewPrestateProvider(prestate, asterisc.NewStateConverter())
return asterisc.NewTraceProvider(logger, m, cfg.Asterisc, vmConfig, prestateProvider, prestate, localInputs, dir, 42), nil
return asterisc.NewTraceProvider(logger, m, cfg.AsteriscKona, vmConfig, prestateProvider, prestate, localInputs, dir, 42), nil
}
return nil, errors.New("invalid trace type")
}
Expand Down

0 comments on commit 52336b4

Please sign in to comment.