Skip to content
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
6 changes: 4 additions & 2 deletions op-challenger2/game/fault/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (a *Agent) performAction(ctx context.Context, wg *sync.WaitGroup, action ty
containsOracleData := action.OracleData != nil
isLocal := containsOracleData && action.OracleData.IsLocal
actionLog = actionLog.New(
"is_attack", action.IsAttack,
"attackBranch", action.AttackBranch,
"parent", action.ParentClaim.ContractIndex,
"prestate", common.Bytes2Hex(action.PreState),
"proof", common.Bytes2Hex(action.ProofData),
Expand All @@ -134,12 +134,14 @@ func (a *Agent) performAction(ctx context.Context, wg *sync.WaitGroup, action ty
actionLog = actionLog.New("oracleKey", common.Bytes2Hex(action.OracleData.OracleKey))
}
} else if action.Type == types.ActionTypeMove {
actionLog = actionLog.New("is_attack", action.IsAttack, "parent", action.ParentClaim.ContractIndex, "value", action.Value)
actionLog = actionLog.New("attackBranch", action.AttackBranch, "parent", action.ParentClaim.ContractIndex, "value", action.Value)
}

switch action.Type {
case types.ActionTypeMove:
a.metrics.RecordGameMove()
case types.ActionTypeAttackV2:
a.metrics.RecordGameAttackV2()
case types.ActionTypeStep:
a.metrics.RecordGameStep()
case types.ActionTypeChallengeL2BlockNumber:
Expand Down
17 changes: 16 additions & 1 deletion op-challenger2/game/fault/responder/responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"math/big"

"github.com/ethereum-optimism/optimism/op-challenger2/game/fault/preimages"
"github.com/ethereum-optimism/optimism/op-challenger2/game/fault/types"
Expand All @@ -19,8 +20,10 @@ type GameContract interface {
CallResolveClaim(ctx context.Context, claimIdx uint64) error
ResolveClaimTx(claimIdx uint64) (txmgr.TxCandidate, error)
AttackTx(ctx context.Context, parent types.Claim, pivot common.Hash) (txmgr.TxCandidate, error)
AttackV2Tx(ctx context.Context, parent types.Claim, attackBranch uint64, daType uint64, claims []byte) (txmgr.TxCandidate, error)
DefendTx(ctx context.Context, parent types.Claim, pivot common.Hash) (txmgr.TxCandidate, error)
StepTx(claimIdx uint64, isAttack bool, stateData []byte, proof []byte) (txmgr.TxCandidate, error)
StepV2Tx(claimIdx uint64, attackBranch uint64, stateData []byte, proof types.StepProof) (txmgr.TxCandidate, error)
ChallengeL2BlockNumberTx(challenge *types.InvalidL2BlockNumberChallenge) (txmgr.TxCandidate, error)
}

Expand Down Expand Up @@ -117,8 +120,20 @@ func (r *FaultResponder) PerformAction(ctx context.Context, action types.Action)
} else {
candidate, err = r.contract.DefendTx(ctx, action.ParentClaim, action.Value)
}
case types.ActionTypeAttackV2:
subValues := make([]byte, 0, len(*action.SubValues))
for _, subValue := range *action.SubValues {
subValues = append(subValues, subValue[:]...)
}
daTypeUint64 := (*big.Int)(action.DAType).Uint64()
candidate, err = r.contract.AttackV2Tx(ctx, action.ParentClaim, action.AttackBranch, daTypeUint64, subValues)
case types.ActionTypeStep:
candidate, err = r.contract.StepTx(uint64(action.ParentClaim.ContractIndex), action.IsAttack, action.PreState, action.ProofData)
stepProof := types.StepProof{
PreStateItem: action.OracleData.VMStateDA.PreDA,
PostStateItem: action.OracleData.VMStateDA.PostDA,
VmProof: action.ProofData,
}
candidate, err = r.contract.StepV2Tx(uint64(action.ParentClaim.ContractIndex), action.AttackBranch, action.PreState, stepProof)
case types.ActionTypeChallengeL2BlockNumber:
candidate, err = r.contract.ChallengeL2BlockNumberTx(action.InvalidL2BlockNumberChallenge)
}
Expand Down
76 changes: 45 additions & 31 deletions op-challenger2/game/fault/solver/game_solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewGameSolver(gameDepth types.Depth, trace types.TraceAccessor, daType type
}

func (s *GameSolver) AgreeWithRootClaim(ctx context.Context, game types.Game) (bool, error) {
return s.claimSolver.agreeWithClaim(ctx, game, game.Claims()[0])
return s.claimSolver.agreeWithClaimV2(ctx, game, game.Claims()[0], 0)
}

func (s *GameSolver) CalculateNextActions(ctx context.Context, game types.Game) ([]types.Action, error) {
Expand Down Expand Up @@ -77,39 +77,53 @@ func (s *GameSolver) calculateStep(ctx context.Context, game types.Game, claim t
if claim.CounteredBy != (common.Address{}) {
return nil, nil
}
step, err := s.claimSolver.AttemptStep(ctx, game, claim, agreedClaims)
if err != nil {
return nil, err
}
if step == nil {
return nil, nil
for branch := range *claim.SubValues {
step, err := s.claimSolver.AttemptStep(ctx, game, claim, agreedClaims, uint64(branch))
if err != nil {
return nil, err
}
if step == nil {
continue
}
return &types.Action{
Type: types.ActionTypeStep,
ParentClaim: step.LeafClaim,
AttackBranch: step.AttackBranch,
PreState: step.PreState,
ProofData: step.ProofData,
OracleData: step.OracleData,
}, nil
}
return &types.Action{
Type: types.ActionTypeStep,
ParentClaim: step.LeafClaim,
IsAttack: step.IsAttack,
PreState: step.PreState,
ProofData: step.ProofData,
OracleData: step.OracleData,
}, nil
return nil, nil
}

func (s *GameSolver) calculateMove(ctx context.Context, game types.Game, claim types.Claim, honestClaims *honestClaimTracker) (*types.Action, error) {
move, err := s.claimSolver.NextMove(ctx, claim, game, honestClaims)
if err != nil {
return nil, fmt.Errorf("failed to calculate next move for claim index %v: %w", claim.ContractIndex, err)
}
if move == nil {
return nil, nil
}
honestClaims.AddHonestClaim(claim, *move)
if game.IsDuplicate(*move) {
return nil, nil
for branch := range *claim.SubValues {
if claim.Position.Depth() == game.SplitDepth()+types.Depth(game.NBits()) && branch != 0 {
continue
}
if claim.IsRoot() && branch != 0 {
continue
}
move, err := s.claimSolver.NextMove(ctx, claim, game, honestClaims, uint64(branch))
if err != nil {
return nil, fmt.Errorf("failed to calculate next move for claim index %v: %w", claim.ContractIndex, err)
}
if move == nil {
continue
}
honestClaims.AddHonestClaim(claim, *move)
if game.IsDuplicate(*move) {
break
}
return &types.Action{
Type: types.ActionTypeAttackV2,
ParentClaim: game.Claims()[move.ParentContractIndex],
Value: move.Value,
SubValues: move.SubValues,
AttackBranch: move.AttackBranch,
DAType: s.claimSolver.daType,
}, nil
}
return &types.Action{
Type: types.ActionTypeMove,
IsAttack: !game.DefendsParent(*move),
ParentClaim: game.Claims()[move.ParentContractIndex],
Value: move.Value,
}, nil
return nil, nil
}
Loading