-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathoutput_cannon_test.go
More file actions
614 lines (512 loc) · 23 KB
/
Copy pathoutput_cannon_test.go
File metadata and controls
614 lines (512 loc) · 23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
package faultproofs
import (
"context"
"fmt"
"testing"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/trace/cannon"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
op_e2e "github.com/ethereum-optimism/optimism/op-e2e"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/challenger"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/disputegame"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/disputegame/preimage"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
func TestOutputCannonGame(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)
ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
t.Cleanup(sys.Close)
disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
game := disputeGameFactory.StartOutputCannonGame(ctx, "sequencer", 4, common.Hash{0x01})
game.LogGameData(ctx)
game.StartChallenger(ctx, "sequencer", "Challenger", challenger.WithPrivKey(sys.Cfg.Secrets.Alice))
game.LogGameData(ctx)
// Challenger should post an output root to counter claims down to the leaf level of the top game
claim := game.RootClaim(ctx)
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
claim = claim.WaitForCounterClaim(ctx)
game.LogGameData(ctx)
claim.RequireCorrectOutputRoot(ctx)
} else {
// Otherwise we should counter
claim = claim.Attack(ctx, common.Hash{0xaa})
game.LogGameData(ctx)
}
}
// Wait for the challenger to post the first claim in the cannon trace
claim = claim.WaitForCounterClaim(ctx)
game.LogGameData(ctx)
// Attack the root of the cannon trace subgame
claim = claim.Attack(ctx, common.Hash{0x00, 0xcc})
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})
game.LogGameData(ctx)
}
}
// Challenger should be able to call step and counter the leaf claim.
claim.WaitForCountered(ctx)
game.LogGameData(ctx)
sys.TimeTravelClock.AdvanceTime(game.GameDuration(ctx))
require.NoError(t, wait.ForNextBlock(ctx, l1Client))
game.WaitForGameStatus(ctx, disputegame.StatusChallengerWins)
}
func TestOutputCannon_ChallengeAllZeroClaim(t *testing.T) {
// The dishonest actor always posts claims with all zeros.
op_e2e.InitParallel(t, op_e2e.UsesCannon)
ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
t.Cleanup(sys.Close)
disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
game := disputeGameFactory.StartOutputCannonGame(ctx, "sequencer", 3, common.Hash{})
game.LogGameData(ctx)
claim := game.DisputeLastBlock(ctx)
game.StartChallenger(ctx, "sequencer", "Challenger", challenger.WithPrivKey(sys.Cfg.Secrets.Alice))
game.DefendClaim(ctx, claim, func(parent *disputegame.ClaimHelper) *disputegame.ClaimHelper {
if parent.IsBottomGameRoot(ctx) {
return parent.Attack(ctx, common.Hash{})
}
return parent.Defend(ctx, common.Hash{})
})
game.LogGameData(ctx)
sys.TimeTravelClock.AdvanceTime(game.GameDuration(ctx))
require.NoError(t, wait.ForNextBlock(ctx, l1Client))
game.WaitForGameStatus(ctx, disputegame.StatusChallengerWins)
game.LogGameData(ctx)
}
func TestOutputCannon_PublishCannonRootClaim(t *testing.T) {
tests := []struct {
disputeL2BlockNumber uint64
}{
{7}, // Post-state output root is invalid
{8}, // Post-state output root is valid
}
for _, test := range tests {
test := test
t.Run(fmt.Sprintf("Dispute_%v", test.disputeL2BlockNumber), func(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)
ctx := context.Background()
sys, _ := startFaultDisputeSystem(t)
disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
game := disputeGameFactory.StartOutputCannonGame(ctx, "sequencer", test.disputeL2BlockNumber, common.Hash{0x01})
game.DisputeLastBlock(ctx)
game.LogGameData(ctx)
game.StartChallenger(ctx, "sequencer", "Challenger", challenger.WithPrivKey(sys.Cfg.Secrets.Alice))
splitDepth := game.SplitDepth(ctx)
game.WaitForClaimAtDepth(ctx, splitDepth+1)
})
}
}
func TestOutputCannonDisputeGame(t *testing.T) {
tests := []struct {
name string
defendClaimDepth types.Depth
}{
{"StepFirst", 0},
{"StepMiddle", 28},
{"StepInExtension", 1},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)
ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
t.Cleanup(sys.Close)
disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
game := disputeGameFactory.StartOutputCannonGame(ctx, "sequencer", 1, common.Hash{0x01, 0xaa})
require.NotNil(t, game)
game.LogGameData(ctx)
outputClaim := game.DisputeLastBlock(ctx)
splitDepth := game.SplitDepth(ctx)
game.StartChallenger(ctx, "sequencer", "Challenger", challenger.WithPrivKey(sys.Cfg.Secrets.Alice))
game.DefendClaim(
ctx,
outputClaim,
func(claim *disputegame.ClaimHelper) *disputegame.ClaimHelper {
if claim.Depth()+1 == splitDepth+test.defendClaimDepth {
return claim.Defend(ctx, common.Hash{byte(claim.Depth())})
} else {
return claim.Attack(ctx, common.Hash{byte(claim.Depth())})
}
})
sys.TimeTravelClock.AdvanceTime(game.GameDuration(ctx))
require.NoError(t, wait.ForNextBlock(ctx, l1Client))
game.LogGameData(ctx)
game.WaitForGameStatus(ctx, disputegame.StatusChallengerWins)
})
}
}
func TestOutputCannonDefendStep(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)
ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
t.Cleanup(sys.Close)
disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
game := disputeGameFactory.StartOutputCannonGame(ctx, "sequencer", 1, common.Hash{0x01, 0xaa})
require.NotNil(t, game)
outputRootClaim := game.DisputeLastBlock(ctx)
game.LogGameData(ctx)
game.StartChallenger(ctx, "sequencer", "Challenger", challenger.WithPrivKey(sys.Cfg.Secrets.Alice))
correctTrace := game.CreateHonestActor(ctx, "sequencer", challenger.WithPrivKey(sys.Cfg.Secrets.Mallory))
maxDepth := game.MaxDepth(ctx)
game.DefendClaim(ctx, outputRootClaim, func(claim *disputegame.ClaimHelper) *disputegame.ClaimHelper {
// Post invalid claims for most steps to get down into the early part of the trace
if claim.Depth() < maxDepth-3 {
return claim.Attack(ctx, common.Hash{0xaa})
} else {
// Post our own counter but using the correct hash in low levels to force a defense step
return correctTrace.AttackClaim(ctx, claim)
}
})
sys.TimeTravelClock.AdvanceTime(game.GameDuration(ctx))
require.NoError(t, wait.ForNextBlock(ctx, l1Client))
game.WaitForInactivity(ctx, 10, true)
game.LogGameData(ctx)
require.EqualValues(t, disputegame.StatusChallengerWins, game.Status(ctx))
}
func TestOutputCannonStepWithLargePreimage(t *testing.T) {
// TODO(client-pod#525): Investigate and fix flakiness
t.Skip("Skipping until the flakiness can be resolved")
op_e2e.InitParallel(t, op_e2e.UsesCannon)
ctx := context.Background()
sys, _ := startFaultDisputeSystem(t, withLargeBatches())
t.Cleanup(sys.Close)
// Send a large l2 transaction and use the receipt block number as the l2 block number for the game
l2Client := sys.NodeClient("sequencer")
// Send a large, difficult to compress L2 transaction. This isn't read by op-program but the batcher has to include
// it in a batch which *is* read.
receipt := op_e2e.SendLargeL2Tx(t, sys.Cfg, l2Client, sys.Cfg.Secrets.Alice, func(opts *op_e2e.TxOpts) {
aliceAddr := sys.Cfg.Secrets.Addresses().Alice
startL2Nonce, err := l2Client.NonceAt(ctx, aliceAddr, nil)
require.NoError(t, err)
opts.Nonce = startL2Nonce
opts.ToAddr = &common.Address{}
// By default, the receipt status must be successful and is checked in the SendL2Tx function
})
l2BlockNumber := receipt.BlockNumber.Uint64()
disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
// Dispute any block - it will have to read the L1 batches to see if the block is reached
game := disputeGameFactory.StartOutputCannonGame(ctx, "sequencer", l2BlockNumber, common.Hash{0x01, 0xaa})
require.NotNil(t, game)
outputRootClaim := game.DisputeBlock(ctx, l2BlockNumber)
game.LogGameData(ctx)
game.StartChallenger(ctx, "sequencer", "Challenger", challenger.WithPrivKey(sys.Cfg.Secrets.Alice))
// Wait for the honest challenger to dispute the outputRootClaim.
// This creates a root of an execution game that we challenge by
// coercing a step at a preimage trace index.
outputRootClaim = outputRootClaim.WaitForCounterClaim(ctx)
game.LogGameData(ctx)
// Now the honest challenger is positioned as the defender of the
// execution game. We then move to challenge it to induce a large preimage load.
sender := sys.Cfg.Secrets.Addresses().Alice
preimageLoadCheck := game.CreateStepLargePreimageLoadCheck(ctx, sender)
game.ChallengeToPreimageLoad(ctx, outputRootClaim, sys.Cfg.Secrets.Alice, cannon.PreimageLargerThan(preimage.MinPreimageSize), preimageLoadCheck, false)
// The above method already verified the image was uploaded and step called successfully
// So we don't waste time resolving the game - that's tested elsewhere.
}
func TestOutputCannonStepWithPreimage(t *testing.T) {
testPreimageStep := func(t *testing.T, preloadPreimage bool) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)
ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
t.Cleanup(sys.Close)
disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
game := disputeGameFactory.StartOutputCannonGame(ctx, "sequencer", 1, common.Hash{0x01, 0xaa})
require.NotNil(t, game)
outputRootClaim := game.DisputeLastBlock(ctx)
game.LogGameData(ctx)
game.StartChallenger(ctx, "sequencer", "Challenger", challenger.WithPrivKey(sys.Cfg.Secrets.Alice))
// Wait for the honest challenger to dispute the outputRootClaim. This creates a root of an execution game that we challenge by coercing
// a step at a preimage trace index.
outputRootClaim = outputRootClaim.WaitForCounterClaim(ctx)
// Now the honest challenger is positioned as the defender of the execution game
// We then move to challenge it to induce a preimage load
preimageLoadCheck := game.CreateStepPreimageLoadCheck(ctx)
game.ChallengeToPreimageLoad(ctx, outputRootClaim, sys.Cfg.Secrets.Alice, cannon.FirstGlobalPreimageLoad(), preimageLoadCheck, preloadPreimage)
sys.TimeTravelClock.AdvanceTime(game.GameDuration(ctx))
require.NoError(t, wait.ForNextBlock(ctx, l1Client))
game.WaitForInactivity(ctx, 10, true)
game.LogGameData(ctx)
require.EqualValues(t, disputegame.StatusChallengerWins, game.Status(ctx))
}
t.Run("non-existing preimage", func(t *testing.T) {
testPreimageStep(t, false)
})
t.Run("preimage already exists", func(t *testing.T) {
testPreimageStep(t, true)
})
}
func TestOutputCannonProposedOutputRootValid(t *testing.T) {
// honestStepsFail attempts to perform both an attack and defend step using the correct trace.
honestStepsFail := func(ctx context.Context, game *disputegame.OutputCannonGameHelper, correctTrace *disputegame.OutputHonestHelper, parentClaimIdx int64) {
// Attack step should fail
correctTrace.StepFails(ctx, parentClaimIdx, true)
// Defending should fail too
correctTrace.StepFails(ctx, parentClaimIdx, false)
}
tests := []struct {
// name is the name of the test
name string
// performMove is called to respond to each claim posted by the honest op-challenger.
// It should either attack or defend the claim at parentClaimIdx
performMove func(ctx context.Context, game *disputegame.OutputCannonGameHelper, correctTrace *disputegame.OutputHonestHelper, claim *disputegame.ClaimHelper) *disputegame.ClaimHelper
// performStep is called once the maximum game depth is reached. It should perform a step to counter the
// claim at parentClaimIdx. Since the proposed output root is invalid, the step call should always revert.
performStep func(ctx context.Context, game *disputegame.OutputCannonGameHelper, correctTrace *disputegame.OutputHonestHelper, parentClaimIdx int64)
}{
{
name: "AttackWithCorrectTrace",
performMove: func(ctx context.Context, game *disputegame.OutputCannonGameHelper, correctTrace *disputegame.OutputHonestHelper, claim *disputegame.ClaimHelper) *disputegame.ClaimHelper {
// Attack everything but oddly using the correct hash.
// Except the root of the cannon game must have an invalid VM status code.
if claim.IsOutputRootLeaf(ctx) {
return claim.Attack(ctx, common.Hash{0x01})
}
return correctTrace.AttackClaim(ctx, claim)
},
performStep: honestStepsFail,
},
{
name: "DefendWithCorrectTrace",
performMove: func(ctx context.Context, game *disputegame.OutputCannonGameHelper, correctTrace *disputegame.OutputHonestHelper, claim *disputegame.ClaimHelper) *disputegame.ClaimHelper {
// Can only attack the root claim or the first cannon claim
if claim.IsRootClaim() {
return correctTrace.AttackClaim(ctx, claim)
}
// The root of the cannon game must have an invalid VM status code
// Attacking ensure we're running the cannon trace between two different blocks
// instead of being in the trace extension of the output root bisection
if claim.IsOutputRootLeaf(ctx) {
return claim.Attack(ctx, common.Hash{0x01})
}
// Otherwise, defend everything using the correct hash.
return correctTrace.DefendClaim(ctx, claim)
},
performStep: honestStepsFail,
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)
ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
t.Cleanup(sys.Close)
disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
game := disputeGameFactory.StartOutputCannonGameWithCorrectRoot(ctx, "sequencer", 1)
correctTrace := game.CreateHonestActor(ctx, "sequencer", challenger.WithPrivKey(sys.Cfg.Secrets.Mallory))
game.StartChallenger(ctx, "sequencer", "Challenger", challenger.WithPrivKey(sys.Cfg.Secrets.Alice))
// Now maliciously play the game and it should be impossible to win
game.ChallengeClaim(ctx,
game.RootClaim(ctx),
func(claim *disputegame.ClaimHelper) *disputegame.ClaimHelper {
return test.performMove(ctx, game, correctTrace, claim)
},
func(parentClaimIdx int64) {
test.performStep(ctx, game, correctTrace, parentClaimIdx)
})
// Time travel past when the game will be resolvable.
sys.TimeTravelClock.AdvanceTime(game.GameDuration(ctx))
require.NoError(t, wait.ForNextBlock(ctx, l1Client))
game.WaitForInactivity(ctx, 10, true)
game.LogGameData(ctx)
require.EqualValues(t, disputegame.StatusDefenderWins, game.Status(ctx))
})
}
}
func TestOutputCannonPoisonedPostState(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)
ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
t.Cleanup(sys.Close)
disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
// Root claim is dishonest
game := disputeGameFactory.StartOutputCannonGame(ctx, "sequencer", 1, common.Hash{0xaa})
correctTrace := game.CreateHonestActor(ctx, "sequencer", challenger.WithPrivKey(sys.Cfg.Secrets.Alice))
// Honest first attack at "honest" level
claim := correctTrace.AttackClaim(ctx, game.RootClaim(ctx))
// Honest defense at "dishonest" level
claim = correctTrace.DefendClaim(ctx, claim)
// Dishonest attack at "honest" level - honest move would be to ignore
claimToIgnore1 := claim.Attack(ctx, common.Hash{0x03, 0xaa})
// Honest attack at "dishonest" level - honest move would be to ignore
claimToIgnore2 := correctTrace.AttackClaim(ctx, claimToIgnore1)
game.LogGameData(ctx)
// Start the honest challenger
game.StartChallenger(ctx, "sequencer", "Honest", challenger.WithPrivKey(sys.Cfg.Secrets.Bob))
// Start dishonest challenger that posts correct claims
for {
game.LogGameData(ctx)
// Wait for the challenger to counter
// Note that we need to ignore claimToIgnore1 which already counters this...
claim = claim.WaitForCounterClaim(ctx, claimToIgnore1)
// Respond with our own move
if claim.IsBottomGameRoot(ctx) {
// Root of the cannon game must have the right VM status code (so it can't be honest).
// Note this occurs when there are splitDepth + 4 claims because there are multiple forks in this game.
claim = claim.Attack(ctx, common.Hash{0x01})
} else {
claim = correctTrace.DefendClaim(ctx, claim)
}
// Defender moves last. If we're at max depth, then we're done
if claim.IsMaxDepth(ctx) {
break
}
}
// Wait for the challenger to call step
claim.WaitForCountered(ctx)
// Verify that the challenger didn't challenge our poisoned claims
claimToIgnore1.RequireOnlyCounteredBy(ctx, claimToIgnore2)
claimToIgnore2.RequireOnlyCounteredBy(ctx /* nothing */)
// Time travel past when the game will be resolvable.
sys.TimeTravelClock.AdvanceTime(game.GameDuration(ctx))
require.NoError(t, wait.ForNextBlock(ctx, l1Client))
game.LogGameData(ctx)
game.WaitForGameStatus(ctx, disputegame.StatusChallengerWins)
}
func TestDisputeOutputRootBeyondProposedBlock_ValidOutputRoot(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)
ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
t.Cleanup(sys.Close)
disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
// Root claim is dishonest
game := disputeGameFactory.StartOutputCannonGameWithCorrectRoot(ctx, "sequencer", 1)
correctTrace := game.CreateHonestActor(ctx, "sequencer", challenger.WithPrivKey(sys.Cfg.Secrets.Alice))
// Start the honest challenger
game.StartChallenger(ctx, "sequencer", "Honest", challenger.WithPrivKey(sys.Cfg.Secrets.Bob))
claim := game.RootClaim(ctx)
// Attack the output root
claim = correctTrace.AttackClaim(ctx, claim)
// Wait for the challenger to respond
claim = claim.WaitForCounterClaim(ctx)
// Then defend until the split depth to force the game into the extension part of the output root bisection
// ie. the output root we wind up disputing is theoretically for a block after block number 1
for !claim.IsOutputRootLeaf(ctx) {
claim = correctTrace.DefendClaim(ctx, claim)
claim = claim.WaitForCounterClaim(ctx)
}
game.LogGameData(ctx)
// At this point we've reached the bottom of the output root bisection and every claim
// will have the same, valid, output root. We now need to post a cannon trace root that claims its invalid.
claim = claim.Defend(ctx, common.Hash{0x01, 0xaa})
// Now defend with the correct trace
for {
game.LogGameData(ctx)
claim = claim.WaitForCounterClaim(ctx)
if claim.IsMaxDepth(ctx) {
break
}
claim = correctTrace.DefendClaim(ctx, claim)
}
// Should not be able to step either attacking or defending
correctTrace.StepClaimFails(ctx, claim, true)
correctTrace.StepClaimFails(ctx, claim, false)
// Time travel past when the game will be resolvable.
sys.TimeTravelClock.AdvanceTime(game.GameDuration(ctx))
require.NoError(t, wait.ForNextBlock(ctx, l1Client))
game.WaitForGameStatus(ctx, disputegame.StatusDefenderWins)
game.LogGameData(ctx)
}
func TestDisputeOutputRootBeyondProposedBlock_InvalidOutputRoot(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)
ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
t.Cleanup(sys.Close)
disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
// Root claim is dishonest
game := disputeGameFactory.StartOutputCannonGame(ctx, "sequencer", 1, common.Hash{0xaa})
correctTrace := game.CreateHonestActor(ctx, "sequencer", challenger.WithPrivKey(sys.Cfg.Secrets.Alice))
// Start the honest challenger
game.StartChallenger(ctx, "sequencer", "Honest", challenger.WithPrivKey(sys.Cfg.Secrets.Bob))
claim := game.RootClaim(ctx)
// Wait for the honest challenger to counter the root
claim = claim.WaitForCounterClaim(ctx)
// Then defend until the split depth to force the game into the extension part of the output root bisection
// ie. the output root we wind up disputing is theoretically for a block after block number 1
// The dishonest actor challenges with the correct roots
for claim.IsOutputRoot(ctx) {
claim = correctTrace.DefendClaim(ctx, claim)
claim = claim.WaitForCounterClaim(ctx)
}
game.LogGameData(ctx)
// Now defend with the correct trace
for !claim.IsMaxDepth(ctx) {
game.LogGameData(ctx)
if claim.IsBottomGameRoot(ctx) {
claim = correctTrace.AttackClaim(ctx, claim)
} else {
claim = correctTrace.DefendClaim(ctx, claim)
}
if !claim.IsMaxDepth(ctx) {
// Have to attack the root of the cannon trace
claim = claim.WaitForCounterClaim(ctx)
}
}
// Wait for our final claim to be countered by the challenger calling step
claim.WaitForCountered(ctx)
// Time travel past when the game will be resolvable.
sys.TimeTravelClock.AdvanceTime(game.GameDuration(ctx))
require.NoError(t, wait.ForNextBlock(ctx, l1Client))
game.WaitForGameStatus(ctx, disputegame.StatusChallengerWins)
game.LogGameData(ctx)
}
func TestDisputeOutputRoot_ChangeClaimedOutputRoot(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon)
ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
t.Cleanup(sys.Close)
disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
// Root claim is dishonest
game := disputeGameFactory.StartOutputCannonGame(ctx, "sequencer", 1, common.Hash{0xaa})
correctTrace := game.CreateHonestActor(ctx, "sequencer", challenger.WithPrivKey(sys.Cfg.Secrets.Alice))
// Start the honest challenger
game.StartChallenger(ctx, "sequencer", "Honest", challenger.WithPrivKey(sys.Cfg.Secrets.Bob))
claim := game.RootClaim(ctx)
// Wait for the honest challenger to counter the root
claim = claim.WaitForCounterClaim(ctx)
// Then attack every claim until the leaf of output root bisection
for {
claim = claim.Attack(ctx, common.Hash{0xbb})
claim = claim.WaitForCounterClaim(ctx)
if claim.Depth() == game.SplitDepth(ctx)-1 {
// Post the correct output root as the leaf.
// This is for block 1 which is what the original output root was for too
claim = correctTrace.AttackClaim(ctx, claim)
// Challenger should post the first cannon trace
claim = claim.WaitForCounterClaim(ctx)
break
}
}
game.LogGameData(ctx)
// Now defend with the correct trace
for !claim.IsMaxDepth(ctx) {
game.LogGameData(ctx)
if claim.IsBottomGameRoot(ctx) {
claim = correctTrace.AttackClaim(ctx, claim)
} else {
claim = correctTrace.DefendClaim(ctx, claim)
}
if !claim.IsMaxDepth(ctx) {
// Have to attack the root of the cannon trace
claim = claim.WaitForCounterClaim(ctx)
}
}
// Wait for our final claim to be countered by the challenger calling step
claim.WaitForCountered(ctx)
// Time travel past when the game will be resolvable.
sys.TimeTravelClock.AdvanceTime(game.GameDuration(ctx))
require.NoError(t, wait.ForNextBlock(ctx, l1Client))
game.WaitForGameStatus(ctx, disputegame.StatusChallengerWins)
game.LogGameData(ctx)
}