@@ -326,68 +326,12 @@ func (g *CannonHelper) ChallengeToPreimageLoadAtTarget(ctx context.Context, cann
326
326
g .WaitForPreimageInOracle (ctx , preimageData )
327
327
}
328
328
329
- // Descending the execution game tree to reach the step that loads the preimage
330
329
bisectTraceIndex := func (claim * ClaimHelper ) * ClaimHelper {
331
- execClaimPosition , err := claim .Position .RelativeToAncestorAtDepth (splitDepth + 1 )
332
- g .require .NoError (err )
333
-
334
- claimTraceIndex := execClaimPosition .TraceIndex (execDepth ).Uint64 ()
335
- g .t .Logf ("Bisecting: Into targetTraceIndex %v: claimIndex=%v at depth=%v. claimPosition=%v execClaimPosition=%v claimTraceIndex=%v" ,
336
- targetTraceIndex , claim .Index , claim .Depth (), claim .Position , execClaimPosition , claimTraceIndex )
337
-
338
- // We always want to position ourselves such that the challenger generates proofs for the targetTraceIndex as prestate
339
- if execClaimPosition .Depth () == execDepth - 1 {
340
- if execClaimPosition .TraceIndex (execDepth ).Uint64 () == targetTraceIndex {
341
- newPosition := execClaimPosition .Attack ()
342
- correct , err := provider .Get (ctx , newPosition )
343
- g .require .NoError (err )
344
- g .t .Logf ("Bisecting: Attack correctly for step at newPosition=%v execIndexAtDepth=%v" , newPosition , newPosition .TraceIndex (execDepth ))
345
- return claim .Attack (ctx , correct )
346
- } else if execClaimPosition .TraceIndex (execDepth ).Uint64 () > targetTraceIndex {
347
- g .t .Logf ("Bisecting: Attack incorrectly for step" )
348
- return claim .Attack (ctx , common.Hash {0xdd })
349
- } else if execClaimPosition .TraceIndex (execDepth ).Uint64 ()+ 1 == targetTraceIndex {
350
- g .t .Logf ("Bisecting: Defend incorrectly for step" )
351
- return claim .Defend (ctx , common.Hash {0xcc })
352
- } else {
353
- newPosition := execClaimPosition .Defend ()
354
- correct , err := provider .Get (ctx , newPosition )
355
- g .require .NoError (err )
356
- g .t .Logf ("Bisecting: Defend correctly for step at newPosition=%v execIndexAtDepth=%v" , newPosition , newPosition .TraceIndex (execDepth ))
357
- return claim .Defend (ctx , correct )
358
- }
359
- }
360
-
361
- // Attack or Defend depending on whether the claim we're responding to is to the left or right of the trace index
362
- // Induce the honest challenger to attack or defend depending on whether our new position will be to the left or right of the trace index
363
- if execClaimPosition .TraceIndex (execDepth ).Uint64 () < targetTraceIndex && claim .Depth () != splitDepth + 1 {
364
- newPosition := execClaimPosition .Defend ()
365
- if newPosition .TraceIndex (execDepth ).Uint64 () < targetTraceIndex {
366
- g .t .Logf ("Bisecting: Defend correct. newPosition=%v execIndexAtDepth=%v" , newPosition , newPosition .TraceIndex (execDepth ))
367
- correct , err := provider .Get (ctx , newPosition )
368
- g .require .NoError (err )
369
- return claim .Defend (ctx , correct )
370
- } else {
371
- g .t .Logf ("Bisecting: Defend incorrect. newPosition=%v execIndexAtDepth=%v" , newPosition , newPosition .TraceIndex (execDepth ))
372
- return claim .Defend (ctx , common.Hash {0xaa })
373
- }
374
- } else {
375
- newPosition := execClaimPosition .Attack ()
376
- if newPosition .TraceIndex (execDepth ).Uint64 () < targetTraceIndex {
377
- g .t .Logf ("Bisecting: Attack correct. newPosition=%v execIndexAtDepth=%v" , newPosition , newPosition .TraceIndex (execDepth ))
378
- correct , err := provider .Get (ctx , newPosition )
379
- g .require .NoError (err )
380
- return claim .Attack (ctx , correct )
381
- } else {
382
- g .t .Logf ("Bisecting: Attack incorrect. newPosition=%v execIndexAtDepth=%v" , newPosition , newPosition .TraceIndex (execDepth ))
383
- return claim .Attack (ctx , common.Hash {0xbb })
384
- }
385
- }
330
+ return traceBisection (g .t , ctx , claim , splitDepth , execDepth , targetTraceIndex , provider )
386
331
}
387
-
388
- g .splitGame .LogGameData (ctx )
389
332
// Initial bisect to put us on defense
390
333
mover := bisectTraceIndex (outputRootClaim )
334
+ // Descending the execution game tree to reach the step that loads the preimage
391
335
leafClaim := g .splitGame .DefendClaim (ctx , mover , bisectTraceIndex , WithoutWaitingForStep ())
392
336
393
337
// Validate that the preimage was loaded correctly
@@ -533,3 +477,70 @@ func (g *CannonHelper) createCannonTraceProvider(ctx context.Context, l2Node str
533
477
translatingProvider := provider .(* trace.TranslatingProvider )
534
478
return translatingProvider .Original ().(* cannon.CannonTraceProviderForTest ), localContext
535
479
}
480
+
481
+ // traceBisection performs a bisection of the trace to the desired targetTraceIndex
482
+ func traceBisection (
483
+ t * testing.T ,
484
+ ctx context.Context ,
485
+ claim * ClaimHelper ,
486
+ splitDepth types.Depth ,
487
+ execDepth types.Depth ,
488
+ targetTraceIndex uint64 ,
489
+ provider * cannon.CannonTraceProviderForTest ,
490
+ ) * ClaimHelper {
491
+ execClaimPosition , err := claim .Position .RelativeToAncestorAtDepth (splitDepth + 1 )
492
+ require .NoError (t , err )
493
+
494
+ claimTraceIndex := execClaimPosition .TraceIndex (execDepth ).Uint64 ()
495
+ t .Logf ("Bisecting: Into targetTraceIndex %v: claimIndex=%v at depth=%v. claimPosition=%v execClaimPosition=%v claimTraceIndex=%v" ,
496
+ targetTraceIndex , claim .Index , claim .Depth (), claim .Position , execClaimPosition , claimTraceIndex )
497
+
498
+ // We always want to position ourselves such that the challenger generates proofs for the targetTraceIndex as prestate
499
+ if execClaimPosition .Depth () == execDepth - 1 {
500
+ if execClaimPosition .TraceIndex (execDepth ).Uint64 () == targetTraceIndex {
501
+ newPosition := execClaimPosition .Attack ()
502
+ correct , err := provider .Get (ctx , newPosition )
503
+ require .NoError (t , err )
504
+ t .Logf ("Bisecting: Attack correctly for step at newPosition=%v execIndexAtDepth=%v" , newPosition , newPosition .TraceIndex (execDepth ))
505
+ return claim .Attack (ctx , correct )
506
+ } else if execClaimPosition .TraceIndex (execDepth ).Uint64 () > targetTraceIndex {
507
+ t .Logf ("Bisecting: Attack incorrectly for step" )
508
+ return claim .Attack (ctx , common.Hash {0xdd })
509
+ } else if execClaimPosition .TraceIndex (execDepth ).Uint64 ()+ 1 == targetTraceIndex {
510
+ t .Logf ("Bisecting: Defend incorrectly for step" )
511
+ return claim .Defend (ctx , common.Hash {0xcc })
512
+ } else {
513
+ newPosition := execClaimPosition .Defend ()
514
+ correct , err := provider .Get (ctx , newPosition )
515
+ require .NoError (t , err )
516
+ t .Logf ("Bisecting: Defend correctly for step at newPosition=%v execIndexAtDepth=%v" , newPosition , newPosition .TraceIndex (execDepth ))
517
+ return claim .Defend (ctx , correct )
518
+ }
519
+ }
520
+
521
+ // Attack or Defend depending on whether the claim we're responding to is to the left or right of the trace index
522
+ // Induce the honest challenger to attack or defend depending on whether our new position will be to the left or right of the trace index
523
+ if execClaimPosition .TraceIndex (execDepth ).Uint64 () < targetTraceIndex && claim .Depth () != splitDepth + 1 {
524
+ newPosition := execClaimPosition .Defend ()
525
+ if newPosition .TraceIndex (execDepth ).Uint64 () < targetTraceIndex {
526
+ t .Logf ("Bisecting: Defend correct. newPosition=%v execIndexAtDepth=%v" , newPosition , newPosition .TraceIndex (execDepth ))
527
+ correct , err := provider .Get (ctx , newPosition )
528
+ require .NoError (t , err )
529
+ return claim .Defend (ctx , correct )
530
+ } else {
531
+ t .Logf ("Bisecting: Defend incorrect. newPosition=%v execIndexAtDepth=%v" , newPosition , newPosition .TraceIndex (execDepth ))
532
+ return claim .Defend (ctx , common.Hash {0xaa })
533
+ }
534
+ } else {
535
+ newPosition := execClaimPosition .Attack ()
536
+ if newPosition .TraceIndex (execDepth ).Uint64 () < targetTraceIndex {
537
+ t .Logf ("Bisecting: Attack correct. newPosition=%v execIndexAtDepth=%v" , newPosition , newPosition .TraceIndex (execDepth ))
538
+ correct , err := provider .Get (ctx , newPosition )
539
+ require .NoError (t , err )
540
+ return claim .Attack (ctx , correct )
541
+ } else {
542
+ t .Logf ("Bisecting: Attack incorrect. newPosition=%v execIndexAtDepth=%v" , newPosition , newPosition .TraceIndex (execDepth ))
543
+ return claim .Attack (ctx , common.Hash {0xbb })
544
+ }
545
+ }
546
+ }
0 commit comments