11package superfaultproofs
22
33import (
4+ "context"
45 "math/big"
6+ "math/rand"
57 "os"
68 "os/exec"
79 "path/filepath"
810 "slices"
11+ "strings"
912 "time"
1013
1114 "github.com/ethereum-optimism/optimism/op-challenger/game/fault/trace/super"
@@ -19,6 +22,7 @@ import (
1922 "github.com/ethereum-optimism/optimism/op-node/rollup"
2023 interopTypes "github.com/ethereum-optimism/optimism/op-program/client/interop/types"
2124 "github.com/ethereum-optimism/optimism/op-service/apis"
25+ "github.com/ethereum-optimism/optimism/op-service/bigs"
2226 "github.com/ethereum-optimism/optimism/op-service/eth"
2327 "github.com/ethereum/go-ethereum/common"
2428 "github.com/ethereum/go-ethereum/crypto"
@@ -175,7 +179,10 @@ func runKonaInteropProgram(t devtest.T, cfg vm.Config, l1Head common.Hash, agree
175179
176180 exePath , err := filepath .Abs (argv [0 ])
177181 t .Require ().NoError (err )
178- cmd := exec .Command (exePath , argv [1 :]... )
182+ t .Logf ("Executing kona interop program: %s" , strings .Join (argv , " " ))
183+ ctx , cancel := context .WithTimeout (t .Ctx (), 2 * time .Minute )
184+ defer cancel ()
185+ cmd := exec .CommandContext (ctx , exePath , argv [1 :]... )
179186 cmd .Dir = tmpDir
180187 cmd .Env = append (append (cmd .Env , os .Environ ()... ), "NO_COLOR=1" )
181188
@@ -518,3 +525,69 @@ func RunSuperFaultProofTest(t devtest.T, sys *presets.SimpleInterop) {
518525 })
519526 }
520527}
528+
529+ func RunConsolidateValidCrossChainMessageTest (t devtest.T , sys * presets.SimpleInterop ) {
530+ t .Require ().NotNil (sys .SuperRoots , "supernode is required for this test" )
531+ rng := rand .New (rand .NewSource (1234 ))
532+
533+ chains := orderedChains (sys )
534+ t .Require ().Len (chains , 2 , "expected exactly 2 interop chains" )
535+
536+ aliceA := sys .FunderA .NewFundedEOA (eth .OneEther )
537+ aliceB := aliceA .AsEL (sys .L2ELB )
538+ sys .FunderB .Fund (aliceB , eth .OneEther )
539+
540+ eventLogger := aliceA .DeployEventLogger ()
541+ initMsg := aliceA .SendRandomInitMessage (rng , eventLogger , 2 , 10 )
542+ execMsg := aliceB .SendExecMessage (initMsg )
543+
544+ endTimestamp := sys .L2ChainB .TimestampForBlockNum (bigs .Uint64Strict (execMsg .BlockNumber ()))
545+ startTimestamp := endTimestamp - 1
546+
547+ sys .SuperRoots .AwaitValidatedTimestamp (endTimestamp )
548+ l1HeadCurrent := latestRequiredL1 (sys .SuperRoots .SuperRootAtTimestamp (endTimestamp ))
549+
550+ start := superRootAtTimestamp (t , chains , startTimestamp )
551+ end := superRootAtTimestamp (t , chains , endTimestamp )
552+
553+ firstOptimistic := optimisticBlockAtTimestamp (t , chains [0 ], endTimestamp )
554+ secondOptimistic := optimisticBlockAtTimestamp (t , chains [1 ], endTimestamp )
555+ paddingStep := func (step uint64 ) []byte {
556+ return marshalTransition (start , step , firstOptimistic , secondOptimistic )
557+ }
558+
559+ tests := []* transitionTest {
560+ {
561+ Name : "Consolidate-AllValid" ,
562+ AgreedClaim : paddingStep (consolidateStep ),
563+ DisputedClaim : end .Marshal (),
564+ DisputedTraceIndex : consolidateStep ,
565+ ExpectValid : true ,
566+ L1Head : l1HeadCurrent ,
567+ ClaimTimestamp : endTimestamp ,
568+ },
569+ {
570+ Name : "Consolidate-AllValid-InvalidNoChange" ,
571+ AgreedClaim : paddingStep (consolidateStep ),
572+ DisputedClaim : paddingStep (consolidateStep ),
573+ DisputedTraceIndex : consolidateStep ,
574+ ExpectValid : false ,
575+ L1Head : l1HeadCurrent ,
576+ ClaimTimestamp : endTimestamp ,
577+ },
578+ }
579+
580+ challengerCfg := sys .L2ChainA .Escape ().L2Challengers ()[0 ].Config ()
581+ gameDepth := sys .DisputeGameFactory ().GameImpl (gameTypes .SuperCannonKonaGameType ).SplitDepth ()
582+ for _ , test := range tests {
583+ t .Run (test .Name + "-fpp" , func (t devtest.T ) {
584+ runKonaInteropProgram (t , challengerCfg .CannonKona , test .L1Head .Hash ,
585+ test .AgreedClaim , crypto .Keccak256Hash (test .DisputedClaim ),
586+ test .ClaimTimestamp , test .ExpectValid )
587+ })
588+
589+ t .Run (test .Name + "-challenger" , func (t devtest.T ) {
590+ runChallengerProviderTest (t , sys .SuperRoots .QueryAPI (), gameDepth , startTimestamp , test .ClaimTimestamp , test )
591+ })
592+ }
593+ }
0 commit comments