disputegame

package
v1.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2024 License: MIT Imports: 50 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// TestKey is the same test key that geth uses
	TestKey, _  = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
	TestAddress = crypto.PubkeyToAddress(TestKey.PublicKey)
)

Functions

This section is empty.

Types

type ClaimHelper

type ClaimHelper struct {
	Index       int64
	ParentIndex int
	Position    types.Position
	// contains filtered or unexported fields
}

func (*ClaimHelper) AgreesWithOutputRoot

func (c *ClaimHelper) AgreesWithOutputRoot() bool

func (*ClaimHelper) Attack

func (c *ClaimHelper) Attack(ctx context.Context, value common.Hash, opts ...MoveOpt) *ClaimHelper

func (*ClaimHelper) Defend

func (c *ClaimHelper) Defend(ctx context.Context, value common.Hash, opts ...MoveOpt) *ClaimHelper

func (*ClaimHelper) Depth

func (c *ClaimHelper) Depth() types.Depth

func (*ClaimHelper) IsBottomGameRoot

func (c *ClaimHelper) IsBottomGameRoot(ctx context.Context) bool

func (*ClaimHelper) IsMaxDepth

func (c *ClaimHelper) IsMaxDepth(ctx context.Context) bool

func (*ClaimHelper) IsOutputRoot

func (c *ClaimHelper) IsOutputRoot(ctx context.Context) bool

func (*ClaimHelper) IsOutputRootLeaf

func (c *ClaimHelper) IsOutputRootLeaf(ctx context.Context) bool

func (*ClaimHelper) IsRootClaim

func (c *ClaimHelper) IsRootClaim() bool

func (*ClaimHelper) RequireCorrectOutputRoot

func (c *ClaimHelper) RequireCorrectOutputRoot(ctx context.Context)

func (*ClaimHelper) RequireDifferentClaimValue

func (c *ClaimHelper) RequireDifferentClaimValue(other *ClaimHelper)

func (*ClaimHelper) RequireInvalidStatusCode

func (c *ClaimHelper) RequireInvalidStatusCode()

func (*ClaimHelper) RequireOnlyCounteredBy

func (c *ClaimHelper) RequireOnlyCounteredBy(ctx context.Context, expected ...*ClaimHelper)

func (*ClaimHelper) WaitForCounterClaim

func (c *ClaimHelper) WaitForCounterClaim(ctx context.Context, ignoreClaims ...*ClaimHelper) *ClaimHelper

WaitForCounterClaim waits for the claim to be countered by another claim being posted. It returns a helper for the claim that countered this one.

func (*ClaimHelper) WaitForCountered

func (c *ClaimHelper) WaitForCountered(ctx context.Context)

WaitForCountered waits until the claim is countered either by a child claim or by a step call.

type ContractClaim

type ContractClaim struct {
	ParentIndex uint32
	CounteredBy common.Address
	Claimant    common.Address
	Bond        *big.Int
	Claim       [32]byte
	Position    *big.Int
	Clock       *big.Int
}

type DefendClaimOpt

type DefendClaimOpt func(cfg *defendClaimCfg)

func WithoutWaitingForStep

func WithoutWaitingForStep() DefendClaimOpt

type DishonestHelper

type DishonestHelper struct {
	*OutputGameHelper
	*OutputHonestHelper
	// contains filtered or unexported fields
}

func (*DishonestHelper) ExhaustDishonestClaims

func (d *DishonestHelper) ExhaustDishonestClaims(ctx context.Context, rootClaim *ClaimHelper)

ExhaustDishonestClaims makes all possible significant moves (mod honest challenger's) in a game. It is very inefficient and should NOT be used on games with large depths

type DisputeSystem

type DisputeSystem interface {
	L1BeaconEndpoint() endpoint.RestHTTP
	NodeEndpoint(name string) endpoint.RPC
	NodeClient(name string) *ethclient.Client
	RollupEndpoint(name string) endpoint.RPC
	RollupClient(name string) *sources.RollupClient

	L1Deployments() *genesis.L1Deployments
	RollupCfg() *rollup.Config
	L2Genesis() *core.Genesis

	AdvanceTime(time.Duration)
}

type FactoryHelper

type FactoryHelper struct {
	T           *testing.T
	Require     *require.Assertions
	System      DisputeSystem
	Client      *ethclient.Client
	Opts        *bind.TransactOpts
	PrivKey     *ecdsa.PrivateKey
	FactoryAddr common.Address
	Factory     *bindings.DisputeGameFactory
}

func NewFactoryHelper

func NewFactoryHelper(t *testing.T, ctx context.Context, system DisputeSystem) *FactoryHelper

func (*FactoryHelper) CreateBisectionGameExtraData

func (h *FactoryHelper) CreateBisectionGameExtraData(l2Node string, l2BlockNumber uint64, cfg *GameCfg) []byte

func (*FactoryHelper) GetL1Head

func (*FactoryHelper) PreimageHelper

func (h *FactoryHelper) PreimageHelper(ctx context.Context) *preimage.Helper

func (*FactoryHelper) StartChallenger

func (h *FactoryHelper) StartChallenger(ctx context.Context, name string, options ...challenger.Option) *challenger.Helper

func (*FactoryHelper) StartOutputAlphabetGame

func (h *FactoryHelper) StartOutputAlphabetGame(ctx context.Context, l2Node string, l2BlockNumber uint64, rootClaim common.Hash, opts ...GameOpt) *OutputAlphabetGameHelper

func (*FactoryHelper) StartOutputAlphabetGameWithCorrectRoot

func (h *FactoryHelper) StartOutputAlphabetGameWithCorrectRoot(ctx context.Context, l2Node string, l2BlockNumber uint64, opts ...GameOpt) *OutputAlphabetGameHelper

func (*FactoryHelper) StartOutputCannonGame

func (h *FactoryHelper) StartOutputCannonGame(ctx context.Context, l2Node string, l2BlockNumber uint64, rootClaim common.Hash, opts ...GameOpt) *OutputCannonGameHelper

func (*FactoryHelper) StartOutputCannonGameWithCorrectRoot

func (h *FactoryHelper) StartOutputCannonGameWithCorrectRoot(ctx context.Context, l2Node string, l2BlockNumber uint64, opts ...GameOpt) *OutputCannonGameHelper

func (*FactoryHelper) WaitForBlock

func (h *FactoryHelper) WaitForBlock(l2Node string, l2BlockNumber uint64, cfg *GameCfg)

type GameCfg

type GameCfg struct {
	// contains filtered or unexported fields
}

func NewGameCfg

func NewGameCfg(opts ...GameOpt) *GameCfg

type GameOpt

type GameOpt interface {
	Apply(cfg *GameCfg)
}

func WithFutureProposal

func WithFutureProposal() GameOpt

func WithUnsafeProposal

func WithUnsafeProposal() GameOpt

type HonestActorOpt

type HonestActorOpt func(cfg *honestActorConfig)

func WithClaimedL2BlockNumber

func WithClaimedL2BlockNumber(num uint64) HonestActorOpt

func WithPrivKey

func WithPrivKey(privKey *ecdsa.PrivateKey) HonestActorOpt

type MoveOpt

type MoveOpt interface {
	Apply(cfg *moveCfg)
}

func WithIgnoreDuplicates

func WithIgnoreDuplicates() MoveOpt

func WithTransactOpts

func WithTransactOpts(Opts *bind.TransactOpts) MoveOpt

type Mover

type Mover func(parent *ClaimHelper) *ClaimHelper

Mover is a function that either attacks or defends the claim at parentClaimIdx

type OutputAlphabetGameHelper

type OutputAlphabetGameHelper struct {
	OutputGameHelper
}

func (*OutputAlphabetGameHelper) CreateDishonestHelper

func (g *OutputAlphabetGameHelper) CreateDishonestHelper(ctx context.Context, l2Node string, defender bool) *DishonestHelper

func (*OutputAlphabetGameHelper) CreateHonestActor

func (g *OutputAlphabetGameHelper) CreateHonestActor(ctx context.Context, l2Node string) *OutputHonestHelper

func (*OutputAlphabetGameHelper) StartChallenger

func (g *OutputAlphabetGameHelper) StartChallenger(
	ctx context.Context,
	l2Node string,
	name string,
	options ...challenger.Option,
) *challenger.Helper

type OutputCannonGameHelper

type OutputCannonGameHelper struct {
	OutputGameHelper
}

func (*OutputCannonGameHelper) ChallengeToPreimageLoad added in v1.5.1

func (g *OutputCannonGameHelper) ChallengeToPreimageLoad(ctx context.Context, outputRootClaim *ClaimHelper, challengerKey *ecdsa.PrivateKey, preimage utils.PreimageOpt, preimageCheck PreimageLoadCheck, preloadPreimage bool)

ChallengeToPreimageLoad challenges the supplied execution root claim by inducing a step that requires a preimage to be loaded It does this by: 1. Identifying the first state transition that loads a global preimage 2. Descending the execution game tree to reach the step that loads the preimage 3. Asserting that the preimage was indeed loaded by an honest challenger (assuming the preimage is not preloaded) This expects an odd execution game depth in order for the honest challenger to step on our leaf claim

func (*OutputCannonGameHelper) CreateHonestActor

func (g *OutputCannonGameHelper) CreateHonestActor(ctx context.Context, l2Node string, options ...HonestActorOpt) *OutputHonestHelper

func (*OutputCannonGameHelper) CreateStepLargePreimageLoadCheck added in v1.5.1

func (g *OutputCannonGameHelper) CreateStepLargePreimageLoadCheck(ctx context.Context, sender common.Address) PreimageLoadCheck

func (*OutputCannonGameHelper) CreateStepPreimageLoadCheck added in v1.5.1

func (g *OutputCannonGameHelper) CreateStepPreimageLoadCheck(ctx context.Context) PreimageLoadCheck

func (*OutputCannonGameHelper) StartChallenger added in v1.4.2

func (g *OutputCannonGameHelper) StartChallenger(ctx context.Context, name string, options ...challenger.Option) *challenger.Helper

func (*OutputCannonGameHelper) VerifyPreimage added in v1.7.2

func (g *OutputCannonGameHelper) VerifyPreimage(ctx context.Context, outputRootClaim *ClaimHelper, preimageKey preimage.Key)

type OutputGameHelper

type OutputGameHelper struct {
	T                     *testing.T
	Require               *require.Assertions
	Client                *ethclient.Client
	Opts                  *bind.TransactOpts
	PrivKey               *ecdsa.PrivateKey
	Game                  contracts.FaultDisputeGameContract
	FactoryAddr           common.Address
	Addr                  common.Address
	CorrectOutputProvider *outputs.OutputTraceProvider
	System                DisputeSystem
}

func NewOutputGameHelper

func NewOutputGameHelper(t *testing.T, require *require.Assertions, client *ethclient.Client, opts *bind.TransactOpts, privKey *ecdsa.PrivateKey,
	game contracts.FaultDisputeGameContract, factoryAddr common.Address, addr common.Address, correctOutputProvider *outputs.OutputTraceProvider, system DisputeSystem) *OutputGameHelper

func (*OutputGameHelper) Attack added in v1.4.2

func (g *OutputGameHelper) Attack(ctx context.Context, claimIdx int64, claim common.Hash, Opts ...MoveOpt)

func (*OutputGameHelper) AvailableCredit added in v1.7.2

func (g *OutputGameHelper) AvailableCredit(ctx context.Context, addr common.Address) *big.Int

func (*OutputGameHelper) ChallengeClaim added in v1.4.3

func (g *OutputGameHelper) ChallengeClaim(ctx context.Context, claim *ClaimHelper, performMove Mover, attemptStep Stepper)

ChallengeClaim uses the supplied functions to perform moves and steps in an attempt to challenge the supplied claim. It is assumed that the claim being disputed is valid and that an honest op-challenger is already running. When the game has reached the maximum depth it calls the Stepper to attempt to counter the leaf claim. Since the output root is valid, it should not be possible for the Stepper to call step successfully.

func (*OutputGameHelper) ChallengePeriod added in v1.5.1

func (g *OutputGameHelper) ChallengePeriod(ctx context.Context) uint64

ChallengePeriod returns the challenge period fetched from the PreimageOracle contract. The returned uint64 value is the number of seconds for the challenge period.

func (*OutputGameHelper) ChallengePeriodStartTime added in v1.5.1

func (g *OutputGameHelper) ChallengePeriodStartTime(ctx context.Context, sender common.Address, data *types.PreimageOracleData) uint64

ChallengePeriodStartTime returns the start time of the challenge period for a given large preimage claim. If the returned start time is 0, the challenge period has not started.

func (*OutputGameHelper) Credit added in v1.5.1

func (g *OutputGameHelper) Credit(ctx context.Context, addr common.Address) *big.Int

func (*OutputGameHelper) CreditUnlockDuration added in v1.7.2

func (g *OutputGameHelper) CreditUnlockDuration(ctx context.Context) time.Duration

func (*OutputGameHelper) Defend added in v1.4.2

func (g *OutputGameHelper) Defend(ctx context.Context, claimIdx int64, claim common.Hash, Opts ...MoveOpt)

func (*OutputGameHelper) DefendClaim added in v1.4.3

func (g *OutputGameHelper) DefendClaim(ctx context.Context, claim *ClaimHelper, performMove Mover, Opts ...DefendClaimOpt) *ClaimHelper

DefendClaim uses the supplied Mover to perform moves in an attempt to defend the supplied claim. It is assumed that the specified claim is invalid and that an honest op-challenger is already running. When the game has reached the maximum depth it waits for the honest challenger to counter the leaf claim with step. Returns the final leaf claim

func (*OutputGameHelper) DisputeBlock added in v1.5.1

func (g *OutputGameHelper) DisputeBlock(ctx context.Context, disputeBlockNum uint64) *ClaimHelper

DisputeBlock posts claims from both the honest and dishonest actor to progress the output root part of the game through to the split depth and the claims are setup such that the last block in the game range is the block to execute cannon on. ie the first block the honest and dishonest actors disagree about is the l2 block of the game.

func (*OutputGameHelper) DisputeLastBlock added in v1.4.2

func (g *OutputGameHelper) DisputeLastBlock(ctx context.Context) *ClaimHelper

func (*OutputGameHelper) ExecDepth added in v1.5.0

func (g *OutputGameHelper) ExecDepth(ctx context.Context) types.Depth

func (*OutputGameHelper) GameData added in v1.7.6

func (g *OutputGameHelper) GameData(ctx context.Context) string

func (*OutputGameHelper) GetClaimValue added in v1.4.2

func (g *OutputGameHelper) GetClaimValue(ctx context.Context, claimIdx int64) common.Hash

func (*OutputGameHelper) GetL1Head added in v1.7.6

func (g *OutputGameHelper) GetL1Head(ctx context.Context) eth.BlockID

func (*OutputGameHelper) L2BlockNum added in v1.4.2

func (g *OutputGameHelper) L2BlockNum(ctx context.Context) uint64

func (*OutputGameHelper) LogGameData added in v1.4.2

func (g *OutputGameHelper) LogGameData(ctx context.Context)

func (*OutputGameHelper) MaxClockDuration added in v1.7.4

func (g *OutputGameHelper) MaxClockDuration(ctx context.Context) time.Duration

func (*OutputGameHelper) MaxDepth added in v1.4.2

func (g *OutputGameHelper) MaxDepth(ctx context.Context) types.Depth

func (*OutputGameHelper) Resolve added in v1.4.2

func (g *OutputGameHelper) Resolve(ctx context.Context)

func (*OutputGameHelper) ResolveClaim added in v1.4.2

func (g *OutputGameHelper) ResolveClaim(ctx context.Context, claimIdx int64)

ResolveClaim resolves a single subgame

func (*OutputGameHelper) RootClaim added in v1.4.2

func (g *OutputGameHelper) RootClaim(ctx context.Context) *ClaimHelper

func (*OutputGameHelper) SplitDepth added in v1.4.2

func (g *OutputGameHelper) SplitDepth(ctx context.Context) types.Depth

func (*OutputGameHelper) StartingBlockNum

func (g *OutputGameHelper) StartingBlockNum(ctx context.Context) uint64

func (*OutputGameHelper) Status added in v1.4.2

func (*OutputGameHelper) StepFails added in v1.4.2

func (g *OutputGameHelper) StepFails(ctx context.Context, claimIdx int64, isAttack bool, stateData []byte, proof []byte)

StepFails attempts to call step and verifies that it fails with ValidStep()

func (*OutputGameHelper) UploadPreimage added in v1.7.6

func (g *OutputGameHelper) UploadPreimage(ctx context.Context, data *types.PreimageOracleData)

func (*OutputGameHelper) WaitForAllClaimsCountered added in v1.4.2

func (g *OutputGameHelper) WaitForAllClaimsCountered(ctx context.Context)

func (*OutputGameHelper) WaitForChallengePeriodStart added in v1.5.1

func (g *OutputGameHelper) WaitForChallengePeriodStart(ctx context.Context, sender common.Address, data *types.PreimageOracleData)

WaitForChallengePeriodStart waits for the challenge period to start for a given large preimage claim.

func (*OutputGameHelper) WaitForClaimAtDepth added in v1.4.2

func (g *OutputGameHelper) WaitForClaimAtDepth(ctx context.Context, depth types.Depth)

func (*OutputGameHelper) WaitForClaimAtMaxDepth added in v1.4.2

func (g *OutputGameHelper) WaitForClaimAtMaxDepth(ctx context.Context, countered bool)

func (*OutputGameHelper) WaitForClaimCount added in v1.4.2

func (g *OutputGameHelper) WaitForClaimCount(ctx context.Context, count int64)

WaitForClaimCount waits until there are at least count claims in the game. This does not check that the number of claims is exactly the specified count to avoid intermittent failures where a challenger posts an additional claim before this method sees the number of claims it was waiting for.

func (*OutputGameHelper) WaitForCorrectOutputRoot added in v1.4.2

func (g *OutputGameHelper) WaitForCorrectOutputRoot(ctx context.Context, claimIdx int64)

func (*OutputGameHelper) WaitForGameStatus added in v1.4.2

func (g *OutputGameHelper) WaitForGameStatus(ctx context.Context, expected gameTypes.GameStatus)

func (*OutputGameHelper) WaitForInactivity added in v1.4.2

func (g *OutputGameHelper) WaitForInactivity(ctx context.Context, numInactiveBlocks int, untilGameEnds bool)

func (*OutputGameHelper) WaitForL2BlockNumberChallenged

func (g *OutputGameHelper) WaitForL2BlockNumberChallenged(ctx context.Context)

func (*OutputGameHelper) WaitForNewClaim added in v1.4.2

func (g *OutputGameHelper) WaitForNewClaim(ctx context.Context, checkPoint int64) (int64, error)

func (*OutputGameHelper) WaitForNoAvailableCredit added in v1.7.2

func (g *OutputGameHelper) WaitForNoAvailableCredit(ctx context.Context, addr common.Address)

func (*OutputGameHelper) WaitForPreimageInOracle added in v1.7.6

func (g *OutputGameHelper) WaitForPreimageInOracle(ctx context.Context, data *types.PreimageOracleData)

func (*OutputGameHelper) WethBalance added in v1.7.2

func (g *OutputGameHelper) WethBalance(ctx context.Context, addr common.Address) *big.Int

type OutputHonestHelper

type OutputHonestHelper struct {
	// contains filtered or unexported fields
}

func NewOutputHonestHelper

func NewOutputHonestHelper(t *testing.T, require *require.Assertions, game *OutputGameHelper, contract contracts.FaultDisputeGameContract, correctTrace types.TraceAccessor) *OutputHonestHelper

func (*OutputHonestHelper) Attack

func (h *OutputHonestHelper) Attack(ctx context.Context, claimIdx int64, opts ...MoveOpt)

func (*OutputHonestHelper) AttackClaim

func (h *OutputHonestHelper) AttackClaim(ctx context.Context, claim *ClaimHelper, opts ...MoveOpt) *ClaimHelper

func (*OutputHonestHelper) CounterClaim

func (h *OutputHonestHelper) CounterClaim(ctx context.Context, claim *ClaimHelper, opts ...MoveOpt) *ClaimHelper

func (*OutputHonestHelper) Defend

func (h *OutputHonestHelper) Defend(ctx context.Context, claimIdx int64, opts ...MoveOpt)

func (*OutputHonestHelper) DefendClaim

func (h *OutputHonestHelper) DefendClaim(ctx context.Context, claim *ClaimHelper, opts ...MoveOpt) *ClaimHelper

func (*OutputHonestHelper) StepClaimFails

func (h *OutputHonestHelper) StepClaimFails(ctx context.Context, claim *ClaimHelper, isAttack bool)

func (*OutputHonestHelper) StepFails

func (h *OutputHonestHelper) StepFails(ctx context.Context, claimIdx int64, isAttack bool)

type PreimageLoadCheck

type PreimageLoadCheck func(types.TraceProvider, uint64) error

type Stepper

type Stepper func(parentClaimIdx int64)

Stepper is a function that attempts to perform a step against the claim at parentClaimIdx

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL