types

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrGameDepthReached = errors.New("game depth reached")

	// NoLocalContext is the LocalContext value used when the cannon trace provider is used alone instead of as part
	// of a split game.
	NoLocalContext = common.Hash{}
)
View Source
var (
	// ErrClaimNotFound is returned when a claim does not exist in the game state.
	ErrClaimNotFound = errors.New("claim not found in game state")
)
View Source
var (
	ErrPositionDepthTooSmall = errors.New("position depth is too small")
)

Functions

func NewGameState

func NewGameState(claims []Claim, depth uint64) *gameState

NewGameState returns a new game state. The provided Claim is used as the root node.

Types

type Action

type Action struct {
	Type      ActionType
	ParentIdx int
	IsAttack  bool

	// Moves
	Value common.Hash

	// Steps
	PreState   []byte
	ProofData  []byte
	OracleData *PreimageOracleData
}

type ActionType

type ActionType string
const (
	ActionTypeMove ActionType = "move"
	ActionTypeStep ActionType = "step"
)

func (ActionType) String

func (a ActionType) String() string

type Claim

type Claim struct {
	ClaimData
	// WARN: Countered is a mutable field in the FaultDisputeGame contract
	//       and rely on it for determining whether to step on leaf claims.
	//       When caching is implemented for the Challenger, this will need
	//       to be changed/removed to avoid invalid/stale contract state.
	Countered bool
	Clock     uint64
	// Location of the claim & it's parent inside the contract. Does not exist
	// for claims that have not made it to the contract.
	ContractIndex       int
	ParentContractIndex int
}

Claim extends ClaimData with information about the relationship between two claims. It uses ClaimData to break cyclicity without using pointers. If the position of the game is Depth 0, IndexAtDepth 0 it is the root claim and the Parent field is empty & meaningless.

func (*Claim) IsRoot

func (c *Claim) IsRoot() bool

IsRoot returns true if this claim is the root claim.

type ClaimData

type ClaimData struct {
	Value common.Hash
	Position
}

ClaimData is the core of a claim. It must be unique inside a specific game.

func (*ClaimData) ValueBytes

func (c *ClaimData) ValueBytes() [32]byte

type Game

type Game interface {
	// Claims returns all of the claims in the game.
	Claims() []Claim

	// GetParent returns the parent of the provided claim.
	GetParent(claim Claim) (Claim, error)

	// DefendsParent returns true if and only if the claim is a defense (i.e. goes right) of
	// its parent.
	DefendsParent(claim Claim) bool

	// IsDuplicate returns true if the provided [Claim] already exists in the game state
	// referencing the same parent claim
	IsDuplicate(claim Claim) bool

	// AgreeWithClaimLevel returns if the game state agrees with the provided claim level.
	AgreeWithClaimLevel(claim Claim, agreeWithRootClaim bool) bool

	MaxDepth() uint64
}

Game is an interface that represents the state of a dispute game.

type Position

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

Position is a golang wrapper around the dispute game Position type.

func NewPosition

func NewPosition(depth int, indexAtDepth *big.Int) Position

func NewPositionFromGIndex

func NewPositionFromGIndex(x *big.Int) Position

func (Position) Attack

func (p Position) Attack() Position

Attack creates a new position which is the attack position of this one.

func (Position) Defend

func (p Position) Defend() Position

Defend creates a new position which is the defend position of this one.

func (Position) Depth

func (p Position) Depth() int

func (Position) IndexAtDepth

func (p Position) IndexAtDepth() *big.Int

func (Position) IsRootPosition

func (p Position) IsRootPosition() bool

func (Position) MoveRight added in v1.2.0

func (p Position) MoveRight() Position

func (Position) Print

func (p Position) Print(maxDepth int)

func (Position) RelativeToAncestorAtDepth added in v1.2.0

func (p Position) RelativeToAncestorAtDepth(ancestor uint64) (Position, error)

RelativeToAncestorAtDepth returns a new position for a subtree. [ancestor] is the depth of the subtree root node.

func (Position) RightOf added in v1.2.0

func (p Position) RightOf(parent Position) bool

func (Position) String added in v1.4.2

func (p Position) String() string

func (Position) ToGIndex

func (p Position) ToGIndex() *big.Int

func (Position) TraceIndex

func (p Position) TraceIndex(maxDepth int) *big.Int

TraceIndex calculates the what the index of the claim value would be inside the trace. It is equivalent to going right until the final depth has been reached.

type PreimageOracleData

type PreimageOracleData struct {
	IsLocal      bool
	OracleKey    []byte
	OracleData   []byte
	OracleOffset uint32
}

PreimageOracleData encapsulates the preimage oracle data to load into the onchain oracle.

func NewPreimageOracleData

func NewPreimageOracleData(key []byte, data []byte, offset uint32) *PreimageOracleData

NewPreimageOracleData creates a new PreimageOracleData instance.

func (*PreimageOracleData) GetIdent

func (p *PreimageOracleData) GetIdent() *big.Int

GetIdent returns the ident for the preimage oracle data.

func (*PreimageOracleData) GetPreimageWithoutSize

func (p *PreimageOracleData) GetPreimageWithoutSize() []byte

GetPreimageWithoutSize returns the preimage for the preimage oracle data.

type PrestateProvider added in v1.4.2

type PrestateProvider interface {
	// AbsolutePreStateCommitment is the commitment of the pre-image value of the trace that transitions to the trace value at index 0
	AbsolutePreStateCommitment(ctx context.Context) (hash common.Hash, err error)
}

PrestateProvider defines an interface to request the absolute prestate.

type StepCallData

type StepCallData struct {
	ClaimIndex uint64
	IsAttack   bool
	StateData  []byte
	Proof      []byte
}

StepCallData encapsulates the data needed to perform a step.

type TraceAccessor added in v1.4.2

type TraceAccessor interface {
	// Get returns the claim value at the requested position, evaluated in the context of the specified claim (ref).
	Get(ctx context.Context, game Game, ref Claim, pos Position) (common.Hash, error)

	// GetStepData returns the data required to execute the step at the specified position,
	// evaluated in the context of the specified claim (ref).
	GetStepData(ctx context.Context, game Game, ref Claim, pos Position) (prestate []byte, proofData []byte, preimageData *PreimageOracleData, err error)
}

TraceAccessor defines an interface to request data from a TraceProvider with additional context for the game position. This can be used to implement split games where lower layers of the game may have different values depending on claims at higher levels in the game.

type TraceProvider

type TraceProvider interface {
	PrestateProvider

	// Get returns the claim value at the requested index.
	// Get(i) = Keccak256(GetPreimage(i))
	Get(ctx context.Context, i Position) (common.Hash, error)

	// GetStepData returns the data required to execute the step at the specified trace index.
	// This includes the pre-state of the step (not hashed), the proof data required during step execution
	// and any pre-image data that needs to be loaded into the oracle prior to execution (may be nil)
	// The prestate returned from GetStepData for trace 10 should be the pre-image of the claim from trace 9
	GetStepData(ctx context.Context, i Position) (prestate []byte, proofData []byte, preimageData *PreimageOracleData, err error)
}

TraceProvider is a generic way to get a claim value at a specific step in the trace.

Jump to

Keyboard shortcuts

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