Skip to content

Commit

Permalink
test(op-e2e): add cannon MSDFG test
Browse files Browse the repository at this point in the history
  • Loading branch information
dajuguan committed Dec 5, 2024
1 parent c1513a0 commit 5ed755e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion op-challenger2/game/fault/responder/responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (r *FaultResponder) ResolveClaims(claimIdxs ...uint64) error {
}

func (r *FaultResponder) PerformAction(ctx context.Context, action types.Action) error {
if action.OracleData != nil {
if action.OracleData != nil && action.OracleData.OracleKey != nil {
var preimageExists bool
var err error
if !action.OracleData.IsLocal {
Expand Down
11 changes: 8 additions & 3 deletions op-challenger2/game/fault/solver/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,13 @@ func (s *claimSolver) AttemptStep(ctx context.Context, game types.Game, claim ty
if err != nil {
return nil, err
}
oracleData.OutputRootDAItem.DaType = s.daType
oracleData.VMStateDA.PreDA.DaType = s.daType
oracleData.VMStateDA.PostDA.DaType = s.daType

if oracleData != nil {
oracleData.OutputRootDAItem.DaType = s.daType
oracleData.VMStateDA.PreDA.DaType = s.daType
oracleData.VMStateDA.PostDA.DaType = s.daType
}

return &StepData{
LeafClaim: claim,
AttackBranch: attackBranch,
Expand All @@ -170,6 +174,7 @@ func (s *claimSolver) attackV2(ctx context.Context, game types.Game, claim types
var value common.Hash
var values []common.Hash
maxAttackBranch := game.MaxAttackBranch()
fmt.Println("attackV2===============", branch, maxAttackBranch)
position := claim.MoveN(game.NBits(), branch)
for i := uint64(0); i < maxAttackBranch; i++ {
tmpPosition := position.MoveRightN(i)
Expand Down
3 changes: 3 additions & 0 deletions op-challenger2/game/fault/trace/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ func (t *Accessor) GetStepData2(ctx context.Context, game types.Game, ref types.
PostDA: postStateDaItem,
}

if preimageData == nil {
preimageData = &types.PreimageOracleData{}
}
preimageData.VMStateDA = stateData
addlocalDataDaItem := types.DAItem{}

Expand Down
2 changes: 1 addition & 1 deletion op-e2e2/e2eutils/disputegame/output_game_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ func (g *OutputGameHelper) oracle(ctx context.Context) *contracts.PreimageOracle
func (g *OutputGameHelper) GameData(ctx context.Context) string {
maxDepth := g.MaxDepth(ctx)
splitDepth := g.SplitDepth(ctx)
claims, err := g.Game.GetAllClaims(ctx, rpcblock.Latest)
claims, err := g.Game.GetAllClaimsWithSubValues(ctx)
g.Require.NoError(err, "Fetching claims")
info := fmt.Sprintf("Claim count: %v\n", len(claims))
for i, claim := range claims {
Expand Down
24 changes: 16 additions & 8 deletions op-e2e2/faultproofs/output_cannon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func TestOutputCannonGame(t *testing.T) {

// Challenger should post an output root to counter claims down to the leaf level of the top game
claim := game.RootClaim(ctx)
maxAttackBranch := 1<<game.Nbits - 1
incorrectValues := setIncorrectValues(common.Hash{0xaa}, maxAttackBranch)
for claim.IsOutputRoot(ctx) && !claim.IsOutputRootLeaf(ctx) {
if claim.AgreesWithOutputRoot() {
// If the latest claim agrees with the output root, expect the honest challenger to counter it
Expand All @@ -43,31 +45,37 @@ func TestOutputCannonGame(t *testing.T) {
claim.RequireCorrectOutputRoot(ctx)
} else {
// Otherwise we should counter
claim = claim.Attack(ctx, common.Hash{0xaa})
claim = claim.Attack2(ctx, 0, incorrectValues)
game.LogGameData(ctx)
}
}

// Wait for the challenger to post the first claim in the cannon trace
claim = claim.WaitForCounterClaim(ctx)
game.LogGameData(ctx)
if claim.Depth()%(types.Depth(2*game.Nbits)) == 0 {
claim = claim.WaitForCounterClaim(ctx)
game.LogGameData(ctx)
}

// Attack the root of the cannon trace subgame
claim = claim.Attack(ctx, common.Hash{0x00, 0xcc})
claim = claim.Attack2(ctx, 0, []common.Hash{{0x02, 0xcc}})
incorrectVMValues := setIncorrectValues(common.Hash{0x00, 0xdd}, maxAttackBranch)
for !claim.IsMaxDepth(ctx) {
if claim.AgreesWithOutputRoot() {
// If the latest claim supports the output root, wait for the honest challenger to respond
claim = claim.WaitForCounterClaim(ctx)
game.LogGameData(ctx)
} else {
// Otherwise we need to counter the honest claim
claim = claim.Defend(ctx, common.Hash{0x00, 0xdd})
claim = claim.Attack2(ctx, uint64(maxAttackBranch), incorrectVMValues)
game.LogGameData(ctx)
}
}
// Challenger should be able to call step and counter the leaf claim.
claim.WaitForCountered(ctx)
game.LogGameData(ctx)
// Challenger should be able to call step and counter the leaf claim by dishonest sequencer.
// SplitDepth should be changed in Deploy.s.sol to test the stepV2 function.
if claim.Depth()%(types.Depth(2*game.Nbits)) == 0 {
claim.WaitForCountered(ctx)
game.LogGameData(ctx)
}

sys.TimeTravelClock.AdvanceTime(game.MaxClockDuration(ctx))
require.NoError(t, wait.ForNextBlock(ctx, l1Client))
Expand Down

0 comments on commit 5ed755e

Please sign in to comment.