warp

package
v1.9.10-rc.2 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: BSD-3-Clause Imports: 18 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidBitSet      = errors.New("bitset is invalid")
	ErrInsufficientWeight = errors.New("signature weight is insufficient")
	ErrInvalidSignature   = errors.New("signature is invalid")
	ErrParseSignature     = errors.New("failed to parse signature")
)
View Source
var (
	ErrUnknownValidator = errors.New("unknown validator")
	ErrWeightOverflow   = errors.New("weight overflowed")
)
View Source
var AnycastID = ids.ID{
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
}

AnycastID is a special DestinationChainID that is used to indicate that the message is intended to be able to be received by any chain.

View Source
var SignerTests = []func(t *testing.T, s Signer, sk *bls.SecretKey, chainID ids.ID){
	TestSignerWrongChainID,
	TestSignerVerifies,
}

SignerTests is a list of all signer tests

Functions

func AggregatePublicKeys

func AggregatePublicKeys(vdrs []*Validator) (*bls.PublicKey, error)

AggregatePublicKeys returns the public key of the provided validators.

Invariant: All of the public keys in [vdrs] are valid.

func SumWeight

func SumWeight(vdrs []*Validator) (uint64, error)

SumWeight returns the total weight of the provided validators.

func TestSignerVerifies

func TestSignerVerifies(t *testing.T, s Signer, sk *bls.SecretKey, chainID ids.ID)

Test that a signature generated with the signer verifies correctly

func TestSignerWrongChainID

func TestSignerWrongChainID(t *testing.T, s Signer, _ *bls.SecretKey, _ ids.ID)

Test that using a random SourceChainID results in an error

func VerifyWeight

func VerifyWeight(
	sigWeight uint64,
	totalWeight uint64,
	quorumNum uint64,
	quorumDen uint64,
) error

VerifyWeight returns [nil] if [sigWeight] is at least [quorumNum]/[quorumDen] of [totalWeight]. If [sigWeight >= totalWeight * quorumNum / quorumDen] then return [nil]

Types

type BitSetSignature

type BitSetSignature struct {
	// Signers is a big-endian byte slice encoding which validators signed this
	// message.
	Signers   []byte                 `serialize:"true"`
	Signature [bls.SignatureLen]byte `serialize:"true"`
}

func (*BitSetSignature) Verify

func (s *BitSetSignature) Verify(
	ctx context.Context,
	msg *UnsignedMessage,
	pChainState validators.State,
	pChainHeight uint64,
	quorumNum uint64,
	quorumDen uint64,
) error

type Message

type Message struct {
	UnsignedMessage `serialize:"true"`
	Signature       Signature `serialize:"true"`
	// contains filtered or unexported fields
}

Message defines the standard format for a Warp message.

func NewMessage

func NewMessage(
	unsignedMsg *UnsignedMessage,
	signature Signature,
) (*Message, error)

NewMessage creates a new *Message and initializes it.

func ParseMessage

func ParseMessage(b []byte) (*Message, error)

ParseMessage converts a slice of bytes into an initialized *Message.

func (*Message) Bytes

func (m *Message) Bytes() []byte

Bytes returns the binary representation of this message. It assumes that the message is initialized from either New, Parse, or an explicit call to Initialize.

func (*Message) Initialize

func (m *Message) Initialize() error

Initialize recalculates the result of Bytes(). It does not call Initialize() on the UnsignedMessage.

type Signature

type Signature interface {
	// Verify that this signature was signed by at least [quorumNum]/[quorumDen]
	// of the validators of [msg.SourceChainID] at [pChainHeight].
	//
	// Invariant: [msg] is correctly initialized.
	Verify(
		ctx context.Context,
		msg *UnsignedMessage,
		pChainState validators.State,
		pChainHeight uint64,
		quorumNum uint64,
		quorumDen uint64,
	) error
}

type Signer

type Signer interface {
	// Returns this node's BLS signature over an unsigned message. If the caller
	// does not have the authority to sign the message, an error will be
	// returned.
	//
	// Assumes the unsigned message is correctly initialized.
	Sign(msg *UnsignedMessage) ([]byte, error)
}

func NewSigner

func NewSigner(sk *bls.SecretKey, chainID ids.ID) Signer

type UnsignedMessage

type UnsignedMessage struct {
	SourceChainID      ids.ID `serialize:"true"`
	DestinationChainID ids.ID `serialize:"true"`
	Payload            []byte `serialize:"true"`
	// contains filtered or unexported fields
}

UnsignedMessage defines the standard format for an unsigned Warp message.

func NewUnsignedMessage

func NewUnsignedMessage(
	sourceChainID ids.ID,
	destinationChainID ids.ID,
	payload []byte,
) (*UnsignedMessage, error)

NewUnsignedMessage creates a new *UnsignedMessage and initializes it.

func ParseUnsignedMessage

func ParseUnsignedMessage(b []byte) (*UnsignedMessage, error)

ParseUnsignedMessage converts a slice of bytes into an initialized *UnsignedMessage.

func (*UnsignedMessage) Bytes

func (m *UnsignedMessage) Bytes() []byte

Bytes returns the binary representation of this message. It assumes that the message is initialized from either New, Parse, or an explicit call to Initialize.

func (*UnsignedMessage) Initialize

func (m *UnsignedMessage) Initialize() error

Initialize recalculates the result of Bytes().

type Validator

type Validator struct {
	PublicKey      *bls.PublicKey
	PublicKeyBytes []byte
	Weight         uint64
	NodeIDs        []ids.NodeID
}

func FilterValidators

func FilterValidators(
	indices set.Bits,
	vdrs []*Validator,
) ([]*Validator, error)

FilterValidators returns the validators in [vdrs] whose bit is set to 1 in [indices].

Returns an error if [indices] references an unknown validator.

func GetCanonicalValidatorSet

func GetCanonicalValidatorSet(
	ctx context.Context,
	pChainState validators.State,
	pChainHeight uint64,
	subnetID ids.ID,
) ([]*Validator, uint64, error)

GetCanonicalValidatorSet returns the validator set of [subnetID] at [pChcainHeight] in a canonical ordering. Also returns the total weight on [subnetID].

func (*Validator) Less

func (v *Validator) Less(o *Validator) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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