Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ func TestProposer(gt *testing.T) {
rootClaim := newGame.RootClaim().Value()
l2SequenceNumber := newGame.L2SequenceNumber()

superRoot := sys.Supervisor.FetchSuperRootAtTimestamp(l2SequenceNumber.Uint64())
superRoot := sys.Supervisor.FetchSuperRootAtTimestamp(l2SequenceNumber)
t.Require().Equal(superRoot.SuperRoot[:], rootClaim[:])
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ func TestProposer(gt *testing.T) {
rootClaim := newGame.RootClaim().Value()
l2SequenceNumber := newGame.L2SequenceNumber()

superRoot := sys.Supervisor.FetchSuperRootAtTimestamp(l2SequenceNumber.Uint64())
superRoot := sys.Supervisor.FetchSuperRootAtTimestamp(l2SequenceNumber)
t.Require().Equal(superRoot.SuperRoot[:], rootClaim[:])
}
18 changes: 18 additions & 0 deletions op-acceptance-tests/tests/proofs/cannon/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cannon

import (
"testing"

"github.com/ethereum-optimism/optimism/op-devstack/compat"
"github.com/ethereum-optimism/optimism/op-devstack/presets"
)

func TestMain(m *testing.M) {
presets.DoMain(m,
presets.WithProofs(),
presets.WithJovianAtGenesis(),
presets.WithSafeDBEnabled(),
// Requires access to a challenger config which only sysgo provides
// These tests would also be exceptionally slow on real L1s
presets.WithCompatibleTypes(compat.SysGo))
}
28 changes: 28 additions & 0 deletions op-acceptance-tests/tests/proofs/cannon/step_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cannon

import (
"testing"

"github.com/ethereum-optimism/optimism/op-devstack/devtest"
"github.com/ethereum-optimism/optimism/op-devstack/dsl/proofs"
"github.com/ethereum-optimism/optimism/op-devstack/presets"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-supervisor/supervisor/types"
)

func TestExecuteStep(gt *testing.T) {
t := devtest.ParallelT(gt)
sys := presets.NewMinimal(t)

l1User := sys.FunderL1.NewFundedEOA(eth.ThousandEther)
blockNum := uint64(3)
sys.L2CL.Reached(types.LocalSafe, blockNum, 30)

game := sys.DisputeGameFactory().StartCannonGame(l1User, proofs.WithL2SequenceNumber(blockNum))
claim := game.DisputeL2SequenceNumber(l1User, game.RootClaim(), blockNum)
game.LogGameData()
claim = claim.WaitForCounterClaim() // Wait for the honest challenger to counter
claim = game.DisputeToStep(l1User, claim, 1000) // Skip down to max depth
game.LogGameData()
claim.WaitForCountered()
}
49 changes: 47 additions & 2 deletions op-devstack/dsl/proofs/claim.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package proofs

import (
"context"
"fmt"
"math/big"
"slices"
"time"

"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -43,12 +47,35 @@ func (c *Claim) Value() common.Hash {
return c.claim.Value
}

func (c *Claim) Bond() *big.Int {
return c.claim.Bond
}

func (c *Claim) Position() types.Position {
return c.claim.Position
}

func (c *Claim) Claimant() common.Address {
return c.claim.Claimant
}

func (c *Claim) Depth() uint64 {
return uint64(c.claim.Depth())
func (c *Claim) Depth() types.Depth {
return c.claim.Depth()
}

func (c *Claim) asChallengerClaim() types.Claim {
return types.Claim{
ClaimData: types.ClaimData{
Value: c.claim.Value,
Bond: c.claim.Bond,
Position: c.claim.Position,
},
CounteredBy: c.claim.CounteredBy,
Claimant: c.claim.Claimant,
Clock: c.claim.Clock,
ContractIndex: int(c.Index),
ParentContractIndex: int(c.claim.ParentContractIndex),
}
}

// WaitForCounterClaim waits for the claim to be countered by another claim being posted.
Expand All @@ -60,6 +87,19 @@ func (c *Claim) WaitForCounterClaim(ignoreClaims ...*Claim) *Claim {
return newClaim(c.t, c.require, counterIdx, counterClaim, c.game)
}

// WaitForCountered waits until the claim is countered either by a child claim or by a step call.
func (c *Claim) WaitForCountered() {
timedCtx, cancel := context.WithTimeout(c.t.Ctx(), defaultTimeout)
defer cancel()
err := wait.For(timedCtx, time.Second, func() (bool, error) {
claim := c.game.claimAtIndex(c.Index)
return claim.CounteredBy != common.Address{}, nil
})
if err != nil { // Avoid waiting time capturing game data when there's no error
c.require.NoErrorf(err, "Claim %v was not countered\n%v", c.Index, c.game.GameData())
}
}

func (c *Claim) VerifyNoCounterClaim() {
for i, claim := range c.game.allClaims() {
c.require.NotEqualValuesf(c.Index, claim.ParentContractIndex, "Found unexpected counter-claim at index %v: %v", i, claim)
Expand All @@ -71,6 +111,11 @@ func (c *Claim) Attack(eoa *dsl.EOA, newClaim common.Hash) *Claim {
return c.WaitForCounterClaim()
}

func (c *Claim) Defend(eoa *dsl.EOA, newClaim common.Hash) *Claim {
c.game.Defend(eoa, c.Index, newClaim)
return c.WaitForCounterClaim()
}

func containsClaim(claimIdx uint64, haystack []*Claim) bool {
return slices.ContainsFunc(haystack, func(candidate *Claim) bool {
return candidate.Index == claimIdx
Expand Down
Loading