fraud

package
v0.3.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OnBEFP

func OnBEFP(ctx context.Context, s Subscriber, stop func(context.Context) error)

OnBEFP listens to Bad Encoding Fraud Proof and stops services immediately if it is received.

Types

type BadEncodingProof

type BadEncodingProof struct {
	BlockHeight uint64
	// ShareWithProof contains all shares from row or col.
	// Shares that did not pass verification in rmst2d will be nil.
	// For non-nil shares MerkleProofs are computed.
	Shares []*ipld.ShareWithProof
	// Index represents the row/col index where ErrByzantineRow/ErrByzantineColl occurred.
	Index uint32
	// contains filtered or unexported fields
}

func (*BadEncodingProof) HeaderHash

func (p *BadEncodingProof) HeaderHash() []byte

HeaderHash returns block hash.

func (*BadEncodingProof) Height

func (p *BadEncodingProof) Height() uint64

Height returns block height.

func (*BadEncodingProof) MarshalBinary

func (p *BadEncodingProof) MarshalBinary() ([]byte, error)

MarshalBinary converts BadEncodingProof to binary.

func (*BadEncodingProof) Type

func (p *BadEncodingProof) Type() ProofType

Type returns type of fraud proof.

func (*BadEncodingProof) UnmarshalBinary

func (p *BadEncodingProof) UnmarshalBinary(data []byte) error

UnmarshalBinary converts binary to BadEncodingProof.

func (*BadEncodingProof) Validate

func (p *BadEncodingProof) Validate(header *header.ExtendedHeader) error

Validate ensures that fraud proof is correct. Validate checks that provided Merkle Proofs correspond to the shares, rebuilds bad row or col from received shares, computes Merkle Root and compares it with block's Merkle Root.

type Broadcaster

type Broadcaster interface {
	// Broadcast takes a fraud `Proof` data structure that implements standard BinaryMarshal
	// interface and broadcasts it to all subscribed peers.
	Broadcast(context.Context, Proof) error
}

Broadcaster is a generic interface that sends a `Proof` to all nodes subscribed on the Broadcaster's topic.

type DummyService

type DummyService struct {
}

func (*DummyService) Broadcast

func (d *DummyService) Broadcast(context.Context, Proof) error

func (*DummyService) RegisterUnmarshaler

func (d *DummyService) RegisterUnmarshaler(ProofType, ProofUnmarshaler) error

func (*DummyService) Start

func (d *DummyService) Start(context.Context) error

func (*DummyService) Stop

func (d *DummyService) Stop(context.Context) error

func (*DummyService) Subscribe

func (d *DummyService) Subscribe(ProofType) (Subscription, error)

func (*DummyService) UnregisterUnmarshaler

func (d *DummyService) UnregisterUnmarshaler(ProofType) error

type Proof

type Proof interface {
	// Type returns the exact type of fraud proof.
	Type() ProofType
	// HeaderHash returns the block hash.
	HeaderHash() []byte
	// Height returns the block height corresponding to the Proof.
	Height() uint64
	// Validate check the validity of fraud proof.
	// Validate throws an error if some conditions don't pass and thus fraud proof is not valid.
	// NOTE: header.ExtendedHeader should pass basic validation otherwise it will panic if it's malformed.
	Validate(*header.ExtendedHeader) error

	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
}

Proof is a generic interface that will be used for all types of fraud proofs in the network.

func CreateBadEncodingProof

func CreateBadEncodingProof(
	hash []byte,
	height uint64,
	errByzantine *ipld.ErrByzantine,
) Proof

CreateBadEncodingProof creates a new Bad Encoding Fraud Proof that should be propagated through network. The fraud proof will contain shares that did not pass verification and their relevant Merkle proofs.

func UnmarshalBEFP

func UnmarshalBEFP(data []byte) (Proof, error)

UnmarshalBEFP converts given data to BadEncodingProof.

type ProofType

type ProofType int
const (
	BadEncoding ProofType = iota
)

func (ProofType) String added in v0.7.0

func (p ProofType) String() string

type ProofUnmarshaler

type ProofUnmarshaler func([]byte) (Proof, error)

ProofUnmarshaler aliases a function that parses data to `Proof`.

type Service

type Service interface {
	Subscriber
	Broadcaster
}

Service encompasses the behavior necessary to subscribe and broadcast Fraud Proofs within the network.

func NewService

func NewService(p *pubsub.PubSub, getter headerFetcher) Service

type Subscriber

type Subscriber interface {
	// Subscribe allows to subscribe on a Proof pub sub topic by its type.
	Subscribe(ProofType) (Subscription, error)
	// RegisterUnmarshaler registers unmarshaler for the given ProofType.
	// If there is no unmarshaler for `ProofType`, then `Subscribe` returns an error.
	RegisterUnmarshaler(ProofType, ProofUnmarshaler) error
	// UnregisterUnmarshaler removes unmarshaler for the given ProofType.
	// If there is no unmarshaler for `ProofType`, then it returns an error.
	UnregisterUnmarshaler(ProofType) error
}

Subscriber encompasses the behavior necessary to subscribe/unsubscribe from new FraudProof events from the network.

type Subscription

type Subscription interface {
	// Proof returns already verified valid proof.
	Proof(context.Context) (Proof, error)
	Cancel()
}

Subscription returns a valid proof if one is received on the topic.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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