fault

package
v0.0.0-...-eb934a0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClaimExists is returned when a claim already exists in the game state.
	ErrClaimExists = errors.New("claim exists in game state")

	// 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 (
	ErrNegativeIndex = errors.New("index cannot be negative")
	ErrIndexTooLarge = errors.New("index is larger than the maximum index")
)

Functions

func IndexToBytes

func IndexToBytes(i uint64) []byte

IndexToBytes converts an index to a byte slice big endian

func MSBIndex

func MSBIndex(x uint64) int

MSBIndex returns the index of the most significant bit

func NewFaultResponder

func NewFaultResponder(logger log.Logger, txManagr txmgr.TxManager, fdgAddr common.Address) (*faultResponder, error)

NewFaultResponder returns a new [faultResponder].

func NewGameState

func NewGameState(root Claim, depth uint64) *gameState

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

func NewLoader

func NewLoader(log log.Logger, state Game, claimFetcher ClaimFetcher) *loader

NewLoader creates a new [loader].

Types

type Agent

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

func NewAgent

func NewAgent(game Game, maxDepth int, trace TraceProvider, responder Responder, log log.Logger) Agent

func (*Agent) AddClaim

func (a *Agent) AddClaim(claim Claim) error

AddClaim stores a claim in the local state. This function shares a lock with PerformActions.

func (*Agent) PerformActions

func (a *Agent) PerformActions()

PerformActions iterates the game & performs all of the next actions. Note: PerformActions & AddClaim share a lock so the responder cannot call AddClaim on the same thread.

type AlphabetProvider

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

AlphabetProvider is a TraceProvider that provides claims for specific indices in the given trace.

func NewAlphabetProvider

func NewAlphabetProvider(state string, depth uint64) *AlphabetProvider

NewAlphabetProvider returns a new AlphabetProvider.

func (*AlphabetProvider) Get

func (ap *AlphabetProvider) Get(i uint64) (common.Hash, error)

Get returns the claim value at the given index in the trace.

func (*AlphabetProvider) GetPreimage

func (ap *AlphabetProvider) GetPreimage(i uint64) ([]byte, error)

GetPreimage returns the preimage for the given hash.

type Claim

type Claim struct {
	ClaimData
	Parent ClaimData
	// 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) DefendsParent

func (c *Claim) DefendsParent() bool

DefendsParent returns true if the the claim is a defense (i.e. goes right) of the parent. It returns false if the claim is an attack (i.e. goes left) of the parent.

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 ClaimFetcher

type ClaimFetcher interface {
	ClaimData(opts *bind.CallOpts, arg0 *big.Int) (struct {
		ParentIndex uint32
		Countered   bool
		Claim       [32]byte
		Position    *big.Int
		Clock       *big.Int
	}, error)
	ClaimDataLen(opts *bind.CallOpts) (*big.Int, error)
}

ClaimFetcher is a minimal interface around bindings.FaultDisputeGameCaller. This needs to be updated if the bindings.FaultDisputeGameCaller interface changes.

type Game

type Game interface {
	// Put adds a claim into the game state.
	Put(claim Claim) error

	// PutAll adds a list of claims into the game state.
	PutAll(claims []Claim) error

	// Claims returns all of the claims in the game.
	Claims() []Claim

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

	// PreStateClaim gets the claim which commits to the pre-state of this specific claim.
	// This will return an error if it is called with a non-leaf claim.
	PreStateClaim(claim Claim) (Claim, error)

	// PostStateClaim gets the claim which commits to the post-state of this specific claim.
	// This will return an error if it is called with a non-leaf claim.
	PostStateClaim(claim Claim) (Claim, error)
}

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

type Loader

type Loader interface {
	FetchClaims(ctx context.Context) ([]Claim, error)
}

Loader is a minimal interface for loading onchain Claim data.

type Orchestrator

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

func NewOrchestrator

func NewOrchestrator(maxDepth uint64, traces []TraceProvider, names []string, root Claim) Orchestrator

func (*Orchestrator) Respond

func (o *Orchestrator) Respond(_ context.Context, response Claim) error

func (*Orchestrator) Start

func (o *Orchestrator) Start()

func (*Orchestrator) Step

func (o *Orchestrator) Step(ctx context.Context, stepData StepCallData) error

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, indexAtDepth int) Position

func NewPositionFromGIndex

func NewPositionFromGIndex(x uint64) 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() int

func (*Position) IsRootPosition

func (p *Position) IsRootPosition() bool

func (*Position) Print

func (p *Position) Print(maxDepth int)

func (*Position) ToGIndex

func (p *Position) ToGIndex() uint64

func (*Position) TraceIndex

func (p *Position) TraceIndex(maxDepth int) uint64

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 Responder

type Responder interface {
	Respond(ctx context.Context, response Claim) error
	Step(ctx context.Context, stepData StepCallData) error
}

Responder takes a response action & executes. For full op-challenger this means executing the transaction on chain.

type Solver

type Solver struct {
	TraceProvider
	// contains filtered or unexported fields
}

Solver uses a TraceProvider to determine the moves to make in a dispute game.

func NewSolver

func NewSolver(gameDepth int, traceProvider TraceProvider) *Solver

NewSolver creates a new Solver using the provided TraceProvider.

func (*Solver) AttemptStep

func (s *Solver) AttemptStep(claim Claim, state Game) (StepData, error)

AttemptStep determines what step should occur for a given leaf claim. An error will be returned if the claim is not at the max depth.

func (*Solver) NextMove

func (s *Solver) NextMove(claim Claim) (*Claim, error)

NextMove returns the next move to make given the current state of the game.

type StepCallData

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

StepCallData encapsulates the data needed to perform a step.

type StepData

type StepData struct {
	LeafClaim  Claim
	StateClaim Claim
	IsAttack   bool
}

type TraceProvider

type TraceProvider interface {
	Get(i uint64) (common.Hash, error)
	GetPreimage(i uint64) ([]byte, error)
}

TraceProvider is a generic way to get a claim value at a specific step in the trace. The AlphabetProvider is a minimal implementation of this interface.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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