message

package
v0.2.1-rc.6 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2022 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const EntryNotFoundError = "EntryNotFoundError"

EntryNotFoundError is the error message for when an entry is not found

Variables

View Source
var (
	// QBFTSigType is the type for QBFT signatures
	QBFTSigType = []byte{1, 0, 0, 0}
	// PostConsensusSigType is the type for post consensus signatures
	PostConsensusSigType = []byte{2, 0, 0, 0}
)
View Source
var ErrDuplicateMsgSigner = errors.New("can't aggregate 2 signed messages with mutual signers")

ErrDuplicateMsgSigner is thrown when trying to sign multiple times with the same signer

View Source
var (
	// PrimusTestnet is the domain type for the testnet
	PrimusTestnet = DomainType("primus_testnet")
)

Functions

func ComputeSigningRoot

func ComputeSigningRoot(data Root, domain SignatureDomain, forkVersion string) ([]byte, error)

ComputeSigningRoot computes the signing root

func ReconstructSignatures

func ReconstructSignatures(signatures map[OperatorID][]byte) (*bls.Sign, error)

ReconstructSignatures receives a map of user indexes and serialized bls.Sign. It then reconstructs the original threshold signature using lagrange interpolation

func VerifyReconstructedSignature

func VerifyReconstructedSignature(sig *bls.Sign, validatorPubKey, root []byte) error

VerifyReconstructedSignature verifies the reconstructed signature

Types

type CommitData

type CommitData struct {
	Data []byte
}

CommitData is the structure used for commit messages

func (*CommitData) Decode

func (d *CommitData) Decode(data []byte) error

Decode returns error if decoding failed

func (*CommitData) Encode

func (d *CommitData) Encode() ([]byte, error)

Encode returns a msg encoded bytes or error

type ConsensusMessage

type ConsensusMessage struct {
	MsgType    ConsensusMessageType
	Height     Height     // QBFT instance Height
	Round      Round      // QBFT round for which the msg is for
	Identifier Identifier // instance Identifier this msg belongs to
	Data       []byte
}

ConsensusMessage is the structure used for consensus messages

func (*ConsensusMessage) Decode

func (msg *ConsensusMessage) Decode(data []byte) error

Decode returns error if decoding failed

func (*ConsensusMessage) DeepCopy

func (msg *ConsensusMessage) DeepCopy() *ConsensusMessage

DeepCopy returns a new instance of ConsensusMessage, deep copied

func (*ConsensusMessage) Encode

func (msg *ConsensusMessage) Encode() ([]byte, error)

Encode returns a msg encoded bytes or error

func (*ConsensusMessage) GetCommitData

func (msg *ConsensusMessage) GetCommitData() (*CommitData, error)

GetCommitData returns commit specific data

func (*ConsensusMessage) GetPrepareData

func (msg *ConsensusMessage) GetPrepareData() (*PrepareData, error)

GetPrepareData returns prepare specific data

func (*ConsensusMessage) GetProposalData

func (msg *ConsensusMessage) GetProposalData() (*ProposalData, error)

GetProposalData returns proposal specific data

func (*ConsensusMessage) GetRoot

func (msg *ConsensusMessage) GetRoot(forkVersion string) ([]byte, error)

GetRoot returns the root used for signing and verification

func (*ConsensusMessage) GetRoundChangeData

func (msg *ConsensusMessage) GetRoundChangeData() (*RoundChangeData, error)

GetRoundChangeData returns round change specific data

func (*ConsensusMessage) Higher

func (msg *ConsensusMessage) Higher(other *ConsensusMessage) bool

Higher checks if the message is higher than the other

func (*ConsensusMessage) Sign

func (msg *ConsensusMessage) Sign(sk *bls.SecretKey, forkVersion string) (*bls.Sign, error)

Sign takes a secret key and signs the Message

type ConsensusMessageType

type ConsensusMessageType int

ConsensusMessageType is the type of consensus messages

const (
	// ProposalMsgType is the type used for proposal messages
	ProposalMsgType ConsensusMessageType = iota
	// PrepareMsgType is the type used for prepare messages
	PrepareMsgType
	// CommitMsgType is the type used for commit messages
	CommitMsgType
	// RoundChangeMsgType is the type used for change round messages
	RoundChangeMsgType
	// DecidedMsgType is the type used for decided messages
	DecidedMsgType
)

func (ConsensusMessageType) String

func (cmt ConsensusMessageType) String() string

String is the string representation of ConsensusMessageType

type DomainType

type DomainType []byte

DomainType is a unique identifier for signatures, 2 identical pieces of data signed with different domains will result in different sigs

type Encoder

type Encoder interface {
	// Encode encodes the message
	Encode() ([]byte, error)
	// Decode decodes the message
	Decode(data []byte) error
}

Encoder encodes or decodes the message

type Height

type Height int64

Height is the height of the QBFT instance

type Identifier

type Identifier []byte

Identifier is used to identify and route messages to the right validator and DutyRunner

func NewIdentifier

func NewIdentifier(pk []byte, role RoleType) Identifier

NewIdentifier creates a new Identifier. expect pk hex sting as byte[]

func (Identifier) GetRoleType

func (msgID Identifier) GetRoleType() RoleType

GetRoleType extracts the role type from the id

func (Identifier) GetValidatorPK

func (msgID Identifier) GetValidatorPK() ValidatorPK

GetValidatorPK extracts the validator public key from the id

func (Identifier) String

func (msgID Identifier) String() string

String returns the string representation of the id

type KeyVal

type KeyVal struct {
	Key string
	Val interface{}
}

KeyVal is a struct of key value pair

type MsgSignature

type MsgSignature interface {
	Root
	GetSignature() Signature
	GetSigners() []OperatorID
	// MatchedSigners returns true if the provided signer ids are equal to GetSignerIds() without order significance
	MatchedSigners(ids []OperatorID) bool
	// Aggregate will aggregate the signed message if possible (unique signers, same digest, valid)
	Aggregate(signedMsg ...MsgSignature) error // value should depend on implementation
}

MsgSignature includes all functions relevant for a signed message (QBFT message, post consensus msg, etc)

type MsgType

type MsgType uint32

MsgType is the type of the message

const (
	// SSVConsensusMsgType are all QBFT consensus related messages
	SSVConsensusMsgType MsgType = iota
	// SSVSyncMsgType are all QBFT sync messages
	SSVSyncMsgType
	// SSVPostConsensusMsgType are all partial signatures sent after consensus
	SSVPostConsensusMsgType
	// SSVDecidedMsgType out of consensus process. holds agg commit messages
	SSVDecidedMsgType
)

func (MsgType) String

func (mt MsgType) String() string

type Operator

type Operator struct {
	OperatorID OperatorID
	PubKey     []byte
}

Operator represents an SSV operator node

func (*Operator) GetID

func (n *Operator) GetID() OperatorID

GetID returns the node's ID

func (*Operator) GetPublicKey

func (n *Operator) GetPublicKey() []byte

GetPublicKey returns the public key with which the node is identified with

type OperatorID

type OperatorID uint64

OperatorID is a unique ID for the node, used to create shares and verify msgs

func AppendSigners

func AppendSigners(signers []OperatorID, appended ...OperatorID) []OperatorID

AppendSigners is a utility that helps to ensure distinct values TODO: sorting?

type OrderedMap

type OrderedMap []KeyVal

OrderedMap Define an ordered map

func (OrderedMap) MarshalJSON

func (omap OrderedMap) MarshalJSON() ([]byte, error)

MarshalJSON Implement the json.Marshaler interface

type PostConsensusMessage

type PostConsensusMessage struct {
	Height          Height
	DutySignature   []byte // The beacon chain partial Signature for a duty
	DutySigningRoot []byte // the root signed in DutySignature
	Signers         []OperatorID
}

PostConsensusMessage is the structure used for post consensus messages

func (*PostConsensusMessage) Decode

func (pcsm *PostConsensusMessage) Decode(data []byte) error

Decode returns error if decoding failed

func (*PostConsensusMessage) Encode

func (pcsm *PostConsensusMessage) Encode() ([]byte, error)

Encode returns a msg encoded bytes or error

func (*PostConsensusMessage) GetRoot

func (pcsm *PostConsensusMessage) GetRoot(forkVersion string) ([]byte, error)

GetRoot returns the root of the message

type PrepareData

type PrepareData struct {
	Data []byte
}

PrepareData is the structure used for prepare messages

func (*PrepareData) Decode

func (d *PrepareData) Decode(data []byte) error

Decode returns error if decoding failed

func (*PrepareData) Encode

func (d *PrepareData) Encode() ([]byte, error)

Encode returns a msg encoded bytes or error

type ProposalData

type ProposalData struct {
	Data                     []byte
	RoundChangeJustification []*SignedMessage
	PrepareJustification     []*SignedMessage
}

ProposalData is the structure used for propose messages

func (*ProposalData) Decode

func (d *ProposalData) Decode(data []byte) error

Decode returns error if decoding failed

func (*ProposalData) Encode

func (d *ProposalData) Encode() ([]byte, error)

Encode returns a msg encoded bytes or error

type RoleType

type RoleType int

RoleType type of the validator role for a specific duty

const (
	RoleTypeUnknown RoleType = iota
	RoleTypeAttester
	RoleTypeAggregator
	RoleTypeProposer
)

List of roles

func RoleTypeFromString

func RoleTypeFromString(rt string) RoleType

RoleTypeFromString returns RoleType from string

func (RoleType) String

func (r RoleType) String() string

String returns name of the role

type Root

type Root interface {
	// GetRoot returns the root used for signing and verification
	GetRoot(forkVersion string) ([]byte, error)
}

Root holds an interface to access the root for signing/verification

type Round

type Round uint64

Round is the QBFT round of the message

type RoundChangeData

type RoundChangeData struct {
	PreparedValue            []byte
	Round                    Round
	NextProposalData         []byte
	RoundChangeJustification []*SignedMessage
}

RoundChangeData represents the data that is sent upon change round

func (*RoundChangeData) Decode

func (r *RoundChangeData) Decode(data []byte) error

Decode returns error if decoding failed

func (*RoundChangeData) Encode

func (r *RoundChangeData) Encode() ([]byte, error)

Encode returns a msg encoded bytes or error

func (*RoundChangeData) GetNextProposalData

func (r *RoundChangeData) GetNextProposalData() []byte

GetNextProposalData returns NOT nil byte array if the signer is the next round's proposal.

func (*RoundChangeData) GetPreparedRound

func (r *RoundChangeData) GetPreparedRound() Round

GetPreparedRound return prepared round

func (*RoundChangeData) GetPreparedValue

func (r *RoundChangeData) GetPreparedValue() []byte

GetPreparedValue return prepared value

func (*RoundChangeData) GetRoundChangeJustification

func (r *RoundChangeData) GetRoundChangeJustification() []*SignedMessage

GetRoundChangeJustification returns signed prepare messages for the last prepared state

type SSVMessage

type SSVMessage struct {
	MsgType MsgType
	ID      Identifier
	Data    []byte
}

SSVMessage is the main message passed within the SSV network, it can contain different types of messages (QBTF, Sync, etc.)

func (*SSVMessage) Decode

func (msg *SSVMessage) Decode(data []byte) error

Decode implements Encoder

func (*SSVMessage) Encode

func (msg *SSVMessage) Encode() ([]byte, error)

Encode implements Encoder

func (*SSVMessage) GetData

func (msg *SSVMessage) GetData() []byte

GetData returns message Data as byte slice

func (*SSVMessage) GetIdentifier

func (msg *SSVMessage) GetIdentifier() Identifier

GetIdentifier returns a unique msg Identifier that is used to identify to which validator should the message be sent for processing

func (*SSVMessage) GetType

func (msg *SSVMessage) GetType() MsgType

GetType returns the msg type

func (*SSVMessage) MarshalJSON

func (msg *SSVMessage) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler all the top level values will be encoded to hex

func (*SSVMessage) UnmarshalJSON

func (msg *SSVMessage) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

type Signature

type Signature []byte

Signature represents signature bytes

func (Signature) Aggregate

func (s Signature) Aggregate(other Signature) (Signature, error)

Aggregate aggregates other signatures

func (Signature) Verify

func (s Signature) Verify(data Root, domain DomainType, sigType SignatureType, pkByts []byte, forkVersion string) error

Verify verifies the signature for the given public key

func (Signature) VerifyByOperators

func (s Signature) VerifyByOperators(data MsgSignature, domain DomainType, sigType SignatureType, operators []*Operator, forkVersion string) error

VerifyByOperators verifies signature by the provided operators

func (Signature) VerifyMultiPubKey

func (s Signature) VerifyMultiPubKey(data Root, domain DomainType, sigType SignatureType, pks [][]byte, forkVersion string) error

VerifyMultiPubKey verifies the signature for multiple public keys

type SignatureDomain

type SignatureDomain []byte

SignatureDomain represents signature domain bytes

func ComputeSignatureDomain

func ComputeSignatureDomain(domain DomainType, sigType SignatureType) SignatureDomain

ComputeSignatureDomain computes the signature domain according to domain+signature types

type SignatureType

type SignatureType []byte

SignatureType is the type of the signature

type SignedMessage

type SignedMessage struct {
	Signature Signature
	Signers   []OperatorID
	Message   *ConsensusMessage // message for which this signature is for
}

SignedMessage contains a message and the corresponding signature + signers list

func (*SignedMessage) Aggregate

func (signedMsg *SignedMessage) Aggregate(sigs ...MsgSignature) error

Aggregate will aggregate the signed message if possible (unique signers, same digest, valid)

func (*SignedMessage) Decode

func (signedMsg *SignedMessage) Decode(data []byte) error

Decode returns error if decoding failed

func (*SignedMessage) DeepCopy

func (signedMsg *SignedMessage) DeepCopy() *SignedMessage

DeepCopy returns a new instance of SignedMessage, deep copied

func (*SignedMessage) Encode

func (signedMsg *SignedMessage) Encode() ([]byte, error)

Encode returns a msg encoded bytes or error

func (*SignedMessage) GetRoot

func (signedMsg *SignedMessage) GetRoot(forkVersion string) ([]byte, error)

GetRoot returns the root used for signing and verification

func (*SignedMessage) GetSignature

func (signedMsg *SignedMessage) GetSignature() Signature

GetSignature returns the message signature

func (*SignedMessage) GetSigners

func (signedMsg *SignedMessage) GetSigners() []OperatorID

GetSigners returns the message signers

func (*SignedMessage) HasMoreSigners

func (signedMsg *SignedMessage) HasMoreSigners(other *SignedMessage) bool

HasMoreSigners checks if the message has more signers than the other

func (*SignedMessage) MatchedSigners

func (signedMsg *SignedMessage) MatchedSigners(ids []OperatorID) bool

MatchedSigners returns true if the provided signer ids are equal to GetSignerIds() without order significance

func (*SignedMessage) MutualSigners

func (signedMsg *SignedMessage) MutualSigners(sig MsgSignature) bool

MutualSigners returns true if signatures have at least 1 mutual signer

type SignedPostConsensusMessage

type SignedPostConsensusMessage struct {
	Message   *PostConsensusMessage
	Signature Signature
	Signers   []OperatorID
}

SignedPostConsensusMessage is the structure used for signed post consensus messages

func (*SignedPostConsensusMessage) Aggregate

func (spcsm *SignedPostConsensusMessage) Aggregate(signedMsg ...MsgSignature) error

Aggregate aggregates signatures

func (*SignedPostConsensusMessage) Decode

func (spcsm *SignedPostConsensusMessage) Decode(data []byte) error

Decode returns error if decoding failed

func (*SignedPostConsensusMessage) Encode

func (spcsm *SignedPostConsensusMessage) Encode() ([]byte, error)

Encode returns a msg encoded bytes or error

func (*SignedPostConsensusMessage) GetRoot

func (spcsm *SignedPostConsensusMessage) GetRoot(forkVersion string) ([]byte, error)

GetRoot returns the signature root

func (*SignedPostConsensusMessage) GetSignature

func (spcsm *SignedPostConsensusMessage) GetSignature() Signature

GetSignature returns the message signature

func (*SignedPostConsensusMessage) GetSigners

func (spcsm *SignedPostConsensusMessage) GetSigners() []OperatorID

GetSigners returns the message signers

func (*SignedPostConsensusMessage) MatchedSigners

func (spcsm *SignedPostConsensusMessage) MatchedSigners(ids []OperatorID) bool

MatchedSigners returns true if the provided signer ids are equal to GetSignerIds() without order significance

type StatusCode

type StatusCode uint32

StatusCode is the response status code

const (
	// StatusUnknown represents an unknown state
	StatusUnknown StatusCode = iota
	// StatusSuccess means the request went successfully
	StatusSuccess
	// StatusNotFound means the desired objects were not found
	StatusNotFound
	// StatusError means that the node experienced some general error
	StatusError
	// StatusBadRequest means the request was bad
	StatusBadRequest
	// StatusInternalError means that the node experienced an internal error
	StatusInternalError
	// StatusBackoff means we exceeded rate limits for the protocol
	StatusBackoff
)

func (*StatusCode) String

func (sc *StatusCode) String() string

type SyncMessage

type SyncMessage struct {
	// Protocol is the protocol of the message
	// TODO: remove after v0
	Protocol SyncMsgType
	// Params holds request parameters
	Params *SyncParams
	// Data holds the results
	Data []*SignedMessage
	// Status is the status code of the operation
	Status StatusCode
}

SyncMessage is the message being passed in sync operations

func (*SyncMessage) Decode

func (sm *SyncMessage) Decode(data []byte) error

Decode decodes the message

func (*SyncMessage) Encode

func (sm *SyncMessage) Encode() ([]byte, error)

Encode encodes the message

func (*SyncMessage) UpdateResults

func (sm *SyncMessage) UpdateResults(err error, results ...*SignedMessage)

UpdateResults updates the given sync message with results or potential error

type SyncMsgType

type SyncMsgType int32

SyncMsgType represent the type of sync messages TODO: remove after v0

const (
	// LastDecidedType is the last decided message type
	LastDecidedType SyncMsgType = iota
	// LastChangeRoundType is the last change round message type
	LastChangeRoundType
	// DecidedHistoryType is the decided history message type
	DecidedHistoryType
)

type SyncParams

type SyncParams struct {
	// Height of the message, it can hold up to 2 items to specify a range or a single item for specific height
	Height []Height
	// Identifier of the message
	Identifier Identifier
}

SyncParams holds parameters for sync operations

type ValidatorPK

type ValidatorPK []byte

ValidatorPK is an eth2 validator public key

func (ValidatorPK) MessageIDBelongs

func (vid ValidatorPK) MessageIDBelongs(msgID Identifier) bool

MessageIDBelongs returns true if message ID belongs to validator

Jump to

Keyboard shortcuts

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