Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions op-challenger/cmd/list_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -56,7 +55,7 @@ func ListClaims(ctx *cli.Context) error {
}
defer l1Client.Close()

caller := batching.NewMultiCaller(l1Client.(*ethclient.Client).Client(), batching.DefaultBatchSize)
caller := batching.NewMultiCaller(l1Client.Client(), batching.DefaultBatchSize)
contract, err := contracts.NewFaultDisputeGameContract(ctx.Context, metrics.NoopContractMetrics, gameAddr, caller)
if err != nil {
return err
Expand Down
12 changes: 9 additions & 3 deletions op-challenger/cmd/list_games.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -71,7 +70,7 @@ func ListGames(ctx *cli.Context) error {
}
defer l1Client.Close()

caller := batching.NewMultiCaller(l1Client.(*ethclient.Client).Client(), batching.DefaultBatchSize)
caller := batching.NewMultiCaller(l1Client.Client(), batching.DefaultBatchSize)
contract := contracts.NewDisputeGameFactoryContract(metrics.NoopContractMetrics, factoryAddr, caller)
head, err := l1Client.HeaderByNumber(ctx.Context, nil)
if err != nil {
Expand All @@ -89,7 +88,14 @@ type gameInfo struct {
err error
}

func listGames(ctx context.Context, caller *batching.MultiCaller, factory *contracts.DisputeGameFactoryContract, block common.Hash, gameWindow time.Duration, sortBy, sortOrder string) error {
func listGames(
ctx context.Context,
caller *batching.MultiCaller,
factory *contracts.DisputeGameFactoryContract,
block common.Hash,
gameWindow time.Duration,
sortBy, sortOrder string,
) error {
earliestTimestamp := clock.MinCheckedTimestamp(clock.SystemClock, gameWindow)
games, err := factory.GetGamesAtOrAfter(ctx, block, earliestTimestamp)
if err != nil {
Expand Down
23 changes: 18 additions & 5 deletions op-challenger/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ import (
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/urfave/cli/v2"
)

type ContractCreator[T any] func(context.Context, contractMetrics.ContractMetricer, common.Address, *batching.MultiCaller) (T, error)
type ContractCreator[T any] func(
context.Context,
contractMetrics.ContractMetricer,
common.Address,
*batching.MultiCaller,
) (T, error)

func AddrFromFlag(flagName string) func(ctx *cli.Context) (common.Address, error) {
return func(ctx *cli.Context) (common.Address, error) {
Expand All @@ -29,7 +33,11 @@ func AddrFromFlag(flagName string) func(ctx *cli.Context) (common.Address, error
}

// NewContractWithTxMgr creates a new contract and a transaction manager.
func NewContractWithTxMgr[T any](ctx *cli.Context, getAddr func(ctx *cli.Context) (common.Address, error), creator ContractCreator[T]) (T, txmgr.TxManager, error) {
func NewContractWithTxMgr[T any](
ctx *cli.Context,
getAddr func(ctx *cli.Context) (common.Address, error),
creator ContractCreator[T],
) (T, txmgr.TxManager, error) {
var contract T
caller, txMgr, err := newClientsFromCLI(ctx)
if err != nil {
Expand All @@ -45,7 +53,12 @@ func NewContractWithTxMgr[T any](ctx *cli.Context, getAddr func(ctx *cli.Context
}

// newContractFromCLI creates a new contract from the CLI context.
func newContractFromCLI[T any](ctx *cli.Context, getAddr func(ctx *cli.Context) (common.Address, error), caller *batching.MultiCaller, creator ContractCreator[T]) (T, error) {
func newContractFromCLI[T any](
ctx *cli.Context,
getAddr func(ctx *cli.Context) (common.Address, error),
caller *batching.MultiCaller,
creator ContractCreator[T],
) (T, error) {
var contract T
gameAddr, err := getAddr(ctx)
if err != nil {
Expand Down Expand Up @@ -78,7 +91,7 @@ func newClientsFromCLI(ctx *cli.Context) (*batching.MultiCaller, txmgr.TxManager
}
defer l1Client.Close()

caller := batching.NewMultiCaller(l1Client.(*ethclient.Client).Client(), batching.DefaultBatchSize)
caller := batching.NewMultiCaller(l1Client.Client(), batching.DefaultBatchSize)
txMgrConfig := txmgr.ReadCLIConfig(ctx)
txMgr, err := txmgr.NewSimpleTxManager("challenger", logger, &metrics.NoopTxMetrics{}, txMgrConfig)
if err != nil {
Expand Down
13 changes: 9 additions & 4 deletions op-challenger/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ const (
TraceTypeCannon TraceType = "cannon"
TraceTypeAsterisc TraceType = "asterisc"
TraceTypePermissioned TraceType = "permissioned"
TraceTypeZK TraceType = "zk"
)

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

func (t TraceType) String() string {
return string(t)
Expand Down Expand Up @@ -152,9 +153,13 @@ type Config struct {

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

TxMgrConfig txmgr.CLIConfig
MetricsConfig opmetrics.CLIConfig
PprofConfig oppprof.CLIConfig
TxMgrConfig txmgr.CLIConfig
MetricsConfig opmetrics.CLIConfig
PprofConfig oppprof.CLIConfig
ZKDisputeGame bool
ZKChallengeByProof bool
ZKResponseChallengeByProof bool
ZKResponseChallengeClaimants []common.Address
}

func NewConfig(
Expand Down
47 changes: 46 additions & 1 deletion op-challenger/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,26 @@ var (
EnvVars: prefixEnvVars("UNSAFE_ALLOW_INVALID_PRESTATE"),
Hidden: true, // Hidden as this is an unsafe flag added only for testing purposes
}
ZKDisputeGameFlag = &cli.BoolFlag{
Name: "zk-dispute-game",
Usage: "Indicates that the current game type is zkDisputeGame",
EnvVars: prefixEnvVars("ZK_DISPUTE_GAME"),
}
ZKChallengeByProofFlag = &cli.BoolFlag{
Name: "zk-challenge-by-proof",
Usage: "Instruct the challenger to directly generate proof to initiate the challenge.",
EnvVars: prefixEnvVars("ZK_CHALLENGE_BY_PROOF"),
}
ZKResponseChallengeByProofFlag = &cli.BoolFlag{
Name: "zk-response-challenge-by-proof",
Usage: "Enable the automatic response feature for zk dispute game creators to reply to challenges",
EnvVars: prefixEnvVars("ZK_RESPONSE_CHALLENGE_BY_PROOF"),
}
ZKResponseChallengeClaimantsFlag = &cli.StringSliceFlag{
Name: "zk-response-challenge-claimants",
Usage: "Specify the list of claimants, only responding to challenges from ZK dispute games created by specific claimants.",
EnvVars: prefixEnvVars("ZK_RESPONSE_CHALLENGE_CLAIMANTS"),
}
)

// requiredFlags are checked by [CheckRequired]
Expand Down Expand Up @@ -260,6 +280,10 @@ var optionalFlags = []cli.Flag{
GameWindowFlag,
SelectiveClaimResolutionFlag,
UnsafeAllowInvalidPrestate,
ZKDisputeGameFlag,
ZKChallengeByProofFlag,
ZKResponseChallengeByProofFlag,
ZKResponseChallengeClaimantsFlag,
}

func init() {
Expand Down Expand Up @@ -348,6 +372,13 @@ func CheckRequired(ctx *cli.Context, traceTypes []config.TraceType) error {
if !ctx.IsSet(CannonL2Flag.Name) && !ctx.IsSet(L2EthRpcFlag.Name) {
return fmt.Errorf("flag %s is required", L2EthRpcFlag.Name)
}
if ctx.IsSet(ZKDisputeGameFlag.Name) {
for _, traceType := range traceTypes {
if traceType != config.TraceTypeZK {
return fmt.Errorf("flag %v is not allowed when the game type is zkDisputeGame", traceType)
}
}
}
for _, traceType := range traceTypes {
switch traceType {
case config.TraceTypeCannon, config.TraceTypePermissioned:
Expand All @@ -358,7 +389,7 @@ func CheckRequired(ctx *cli.Context, traceTypes []config.TraceType) error {
if err := CheckAsteriscFlags(ctx); err != nil {
return err
}
case config.TraceTypeAlphabet, config.TraceTypeFast:
case config.TraceTypeAlphabet, config.TraceTypeFast, config.TraceTypeZK:
default:
return fmt.Errorf("invalid trace type. must be one of %v", config.TraceTypes)
}
Expand Down Expand Up @@ -498,6 +529,16 @@ func NewConfigFromCLI(ctx *cli.Context, logger log.Logger) (*config.Config, erro
if ctx.IsSet(flags.NetworkFlagName) {
asteriscNetwork = ctx.String(flags.NetworkFlagName)
}
var zkClaimants []common.Address
if ctx.IsSet(ZKResponseChallengeClaimantsFlag.Name) {
for _, addrStr := range ctx.StringSlice(ZKResponseChallengeClaimantsFlag.Name) {
claimant, err := opservice.ParseAddress(addrStr)
if err != nil {
return nil, fmt.Errorf("invalid zk claimant: %w", err)
}
zkClaimants = append(zkClaimants, claimant)
}
}
return &config.Config{
// Required Flags
L1EthRpc: ctx.String(L1EthRpcFlag.Name),
Expand Down Expand Up @@ -536,5 +577,9 @@ func NewConfigFromCLI(ctx *cli.Context, logger log.Logger) (*config.Config, erro
PprofConfig: pprofConfig,
SelectiveClaimResolution: ctx.Bool(SelectiveClaimResolutionFlag.Name),
AllowInvalidPrestate: ctx.Bool(UnsafeAllowInvalidPrestate.Name),
ZKDisputeGame: ctx.Bool(ZKDisputeGameFlag.Name),
ZKChallengeByProof: ctx.Bool(ZKChallengeByProofFlag.Name),
ZKResponseChallengeByProof: ctx.Bool(ZKResponseChallengeByProofFlag.Name),
ZKResponseChallengeClaimants: zkClaimants,
}, nil
}
Loading