Skip to content

Commit

Permalink
op-challenger: Fix prestate loading for asterisc in run-trace (#11363)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajsutton authored Aug 6, 2024
1 parent 052ca79 commit 0681bfc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
29 changes: 23 additions & 6 deletions op-challenger/runner/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package runner
import (
"errors"
"fmt"
"net/url"
"path/filepath"

"github.com/ethereum-optimism/optimism/op-challenger/config"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/trace/asterisc"
Expand All @@ -19,24 +21,39 @@ func createTraceProvider(
logger log.Logger,
m vm.Metricer,
cfg *config.Config,
prestateSource prestates.PrestateSource,
prestateHash common.Hash,
traceType types.TraceType,
localInputs utils.LocalGameInputs,
dir string,
) (types.TraceProvider, error) {
prestate, err := prestateSource.PrestatePath(prestateHash)
if err != nil {
return nil, fmt.Errorf("failed to get prestate %v: %w", prestateHash, err)
}

switch traceType {
case types.TraceTypeCannon:
prestate, err := getPrestate(prestateHash, cfg.CannonAbsolutePreStateBaseURL, cfg.CannonAbsolutePreState, dir)
if err != nil {
return nil, err
}
prestateProvider := cannon.NewPrestateProvider(prestate)
return cannon.NewTraceProvider(logger, m, cfg.Cannon, prestateProvider, prestate, localInputs, dir, 42), nil
case types.TraceTypeAsterisc:
prestate, err := getPrestate(prestateHash, cfg.AsteriscAbsolutePreStateBaseURL, cfg.AsteriscAbsolutePreState, dir)
if err != nil {
return nil, err
}
prestateProvider := asterisc.NewPrestateProvider(prestate)
return asterisc.NewTraceProvider(logger, m, cfg.Asterisc, prestateProvider, prestate, localInputs, dir, 42), nil
}
return nil, errors.New("invalid trace type")
}

func getPrestate(prestateHash common.Hash, prestateBaseUrl *url.URL, prestatePath string, dataDir string) (string, error) {
prestateSource := prestates.NewPrestateSource(
prestateBaseUrl,
prestatePath,
filepath.Join(dataDir, "prestates"))

prestate, err := prestateSource.PrestatePath(prestateHash)
if err != nil {
return "", fmt.Errorf("failed to get prestate %v: %w", prestateHash, err)
}
return prestate, nil
}
10 changes: 4 additions & 6 deletions op-challenger/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/config"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts"
contractMetrics "github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts/metrics"
"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"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
Expand Down Expand Up @@ -130,12 +129,8 @@ func (r *Runner) runOnce(ctx context.Context, traceType types.TraceType, client
if err != nil {
return err
}
prestateSource := prestates.NewPrestateSource(
r.cfg.CannonAbsolutePreStateBaseURL,
r.cfg.CannonAbsolutePreState,
filepath.Join(dir, "prestates"))
logger := r.log.New("l1", localInputs.L1Head, "l2", localInputs.L2Head, "l2Block", localInputs.L2BlockNumber, "claim", localInputs.L2Claim, "type", traceType)
provider, err := createTraceProvider(logger, r.m, r.cfg, prestateSource, prestateHash, traceType, localInputs, dir)
provider, err := createTraceProvider(logger, r.m, r.cfg, prestateHash, traceType, localInputs, dir)
if err != nil {
return fmt.Errorf("failed to create trace provider: %w", err)
}
Expand Down Expand Up @@ -203,6 +198,9 @@ func (r *Runner) getPrestateHash(ctx context.Context, traceType types.TraceType,
if err != nil {
return common.Hash{}, fmt.Errorf("failed to load game impl: %w", err)
}
if gameImplAddr == (common.Address{}) {
return common.Hash{}, nil // No prestate is set, will only work if a single prestate is specified
}
gameImpl, err := contracts.NewFaultDisputeGameContract(ctx, r.m, gameImplAddr, caller)
if err != nil {
return common.Hash{}, fmt.Errorf("failed to create fault dispute game contract bindings for %v: %w", gameImplAddr, err)
Expand Down

0 comments on commit 0681bfc

Please sign in to comment.