types

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const BLSWithdrawalPrefixByte = byte(0)

BLSWithdrawalPrefixByte is the BLS withdrawal prefix

View Source
const MaxEffectiveBalanceInGwei uint64 = 32000000000

MaxEffectiveBalanceInGwei is the max effective balance

Variables

View Source
var (
	DomainProposer                    = [4]byte{0x00, 0x00, 0x00, 0x00}
	DomainAttester                    = [4]byte{0x01, 0x00, 0x00, 0x00}
	DomainRandao                      = [4]byte{0x02, 0x00, 0x00, 0x00}
	DomainDeposit                     = [4]byte{0x03, 0x00, 0x00, 0x00}
	DomainVoluntaryExit               = [4]byte{0x04, 0x00, 0x00, 0x00}
	DomainSelectionProof              = [4]byte{0x05, 0x00, 0x00, 0x00}
	DomainAggregateAndProof           = [4]byte{0x06, 0x00, 0x00, 0x00}
	DomainSyncCommittee               = [4]byte{0x07, 0x00, 0x00, 0x00}
	DomainSyncCommitteeSelectionProof = [4]byte{0x08, 0x00, 0x00, 0x00}
	DomainContributionAndProof        = [4]byte{0x09, 0x00, 0x00, 0x00}
	DomainApplicationBuilder          = [4]byte{0x00, 0x00, 0x00, 0x01}

	DomainError = [4]byte{0x99, 0x99, 0x99, 0x99}
)
View Source
var (
	PrimusTestnet = DomainType("primus_testnet")
	ShifuTestnet  = DomainType("shifu_testnet")
)
View Source
var GenesisForkVersion = spec.Version{0, 0, 0, 0}
View Source
var GenesisValidatorsRoot = spec.Root{}

Functions

func ComputeETHDomain

func ComputeETHDomain(domain spec.DomainType, fork spec.Version, genesisValidatorRoot spec.Root) (spec.Domain, error)

ComputeETHDomain returns computed domain

func ComputeETHSigningRoot

func ComputeETHSigningRoot(obj ssz.HashRoot, domain spec.Domain) (spec.Root, error)

func ComputeSigningRoot

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

func Decrypt

func Decrypt(sk *rsa.PrivateKey, cipherText []byte) ([]byte, error)

Decrypt with secret key (base64) and bytes, return the encrypted key string

func Encrypt

func Encrypt(pk *rsa.PublicKey, plainText []byte) ([]byte, error)

Encrypt with secret key (base64) the bytes, return the encrypted key string

func GenerateETHDepositData

func GenerateETHDepositData(
	validatorPK, withdrawalCredentials []byte,
	fork phase0.Version,
	domain phase0.DomainType) ([]byte, *phase0.DepositData, error)

GenerateETHDepositData returns un-signed deposit data and deposit data root for signature

func GenerateKey

func GenerateKey() ([]byte, []byte, error)

GenerateKey using rsa random generate keys

func GetPublicKeyPem

func GetPublicKeyPem(sk *rsa.PrivateKey) ([]byte, error)

GetPublicKeyPem get public key from private key and return []byte represent the public key

func InitBLS

func InitBLS()

InitBLS initializes BLS

func PemToPrivateKey

func PemToPrivateKey(skPem []byte) (*rsa.PrivateKey, error)

PemToPrivateKey return rsa private key from pem

func PemToPublicKey

func PemToPublicKey(pkPem []byte) (*rsa.PublicKey, error)

PemToPublicKey return rsa public key from pem

func PrivateKeyToPem

func PrivateKeyToPem(sk *rsa.PrivateKey) []byte

PrivateKeyToPem converts privateKey to pem encoded

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

Types

type BeaconNetwork

type BeaconNetwork string

BeaconNetwork represents the network.

const (
	// PraterNetwork represents the Prater test network.
	PraterNetwork BeaconNetwork = "prater"

	// MainNetwork represents the main network.
	MainNetwork BeaconNetwork = "mainnet"

	// BeaconTestNetwork is a simple test network with a custom genesis time
	BeaconTestNetwork BeaconNetwork = "now_test_network"
)

Available networks.

func NetworkFromString

func NetworkFromString(n string) BeaconNetwork

NetworkFromString returns network from the given string value

func (BeaconNetwork) EpochStartTime

func (n BeaconNetwork) EpochStartTime(epoch spec.Epoch) time.Time

func (BeaconNetwork) EstimatedCurrentEpoch

func (n BeaconNetwork) EstimatedCurrentEpoch() spec.Epoch

EstimatedCurrentEpoch estimates the current epoch https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/beacon-chain.md#compute_start_slot_at_epoch

func (BeaconNetwork) EstimatedCurrentSlot

func (n BeaconNetwork) EstimatedCurrentSlot() spec.Slot

EstimatedCurrentSlot returns the estimation of the current slot

func (BeaconNetwork) EstimatedEpochAtSlot

func (n BeaconNetwork) EstimatedEpochAtSlot(slot spec.Slot) spec.Epoch

EstimatedEpochAtSlot estimates epoch at the given slot

func (BeaconNetwork) EstimatedSlotAtTime

func (n BeaconNetwork) EstimatedSlotAtTime(time int64) spec.Slot

EstimatedSlotAtTime estimates slot at the given time

func (BeaconNetwork) EstimatedTimeAtSlot

func (n BeaconNetwork) EstimatedTimeAtSlot(slot spec.Slot) int64

func (BeaconNetwork) FirstSlotAtEpoch

func (n BeaconNetwork) FirstSlotAtEpoch(epoch spec.Epoch) spec.Slot

func (BeaconNetwork) ForkVersion

func (n BeaconNetwork) ForkVersion() [4]byte

ForkVersion returns the fork version of the network.

func (BeaconNetwork) MinGenesisTime

func (n BeaconNetwork) MinGenesisTime() uint64

MinGenesisTime returns min genesis time value

func (BeaconNetwork) SlotDurationSec

func (n BeaconNetwork) SlotDurationSec() time.Duration

SlotDurationSec returns slot duration

func (BeaconNetwork) SlotsPerEpoch

func (n BeaconNetwork) SlotsPerEpoch() uint64

SlotsPerEpoch returns number of slots per one epoch

type BeaconRole

type BeaconRole int

BeaconRole type of the validator role for a specific duty

const (
	BNRoleAttester BeaconRole = iota
	BNRoleAggregator
	BNRoleProposer
	BNRoleSyncCommittee
	BNRoleSyncCommitteeContribution

	BNRoleValidatorRegistration
)

List of roles

func (BeaconRole) String

func (r BeaconRole) String() string

String returns name of the role

type BeaconSigner

type BeaconSigner interface {
	// SignBeaconObject returns signature and root.
	SignBeaconObject(obj ssz.HashRoot, domain spec.Domain, pk []byte, domainType spec.DomainType) (Signature, []byte, error)
	// IsAttestationSlashable returns error if attestation is slashable
	IsAttestationSlashable(pk []byte, data *spec.AttestationData) error
	// IsBeaconBlockSlashable returns error if the given block is slashable
	IsBeaconBlockSlashable(pk []byte, block *bellatrix.BeaconBlock) error
}

type ConsensusData

type ConsensusData struct {
	Duty                   *Duty
	AttestationData        *phase0.AttestationData
	BlockData              *bellatrix.BeaconBlock
	BlindedBlockData       *bellatrix2.BlindedBeaconBlock
	AggregateAndProof      *phase0.AggregateAndProof
	SyncCommitteeBlockRoot phase0.Root
	// SyncCommitteeContribution map holds as key the selection proof for the contribution
	SyncCommitteeContribution ContributionsMap
}

ConsensusData holds all relevant duty and data Decided on by consensus

func (*ConsensusData) Decode

func (cid *ConsensusData) Decode(data []byte) error

func (*ConsensusData) Encode

func (cid *ConsensusData) Encode() ([]byte, error)

func (*ConsensusData) Validate

func (cid *ConsensusData) Validate() error

type ContributionsMap

func (*ContributionsMap) MarshalJSON

func (cm *ContributionsMap) MarshalJSON() ([]byte, error)

func (*ContributionsMap) UnmarshalJSON

func (cm *ContributionsMap) UnmarshalJSON(input []byte) error

type DKGSigner

type DKGSigner interface {
	SSVSigner
	// SignDKGOutput signs output according to the SIP https://docs.google.com/document/d/1TRVUHjFyxINWW2H9FYLNL2pQoLy6gmvaI62KL_4cREQ/edit
	SignDKGOutput(output Root, address common.Address) (Signature, error)
	// SignETHDepositRoot signs an ethereum deposit root
	SignETHDepositRoot(root []byte, address common.Address) (Signature, error)
}

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 Duty

type Duty struct {
	// Type is the duty type (attest, propose)
	Type BeaconRole
	// PubKey is the public key of the validator that should attest.
	PubKey spec.BLSPubKey
	// Slot is the slot in which the validator should attest.
	Slot spec.Slot
	// ValidatorIndex is the index of the validator that should attest.
	ValidatorIndex spec.ValidatorIndex
	// CommitteeIndex is the index of the committee in which the attesting validator has been placed.
	CommitteeIndex spec.CommitteeIndex
	// CommitteeLength is the length of the committee in which the attesting validator has been placed.
	CommitteeLength uint64
	// CommitteesAtSlot is the number of committees in the slot.
	CommitteesAtSlot uint64
	// ValidatorCommitteeIndex is the index of the validator in the list of validators in the committee.
	ValidatorCommitteeIndex uint64
	// ValidatorSyncCommitteeIndices is the index of the validator in the list of validators in the committee.
	ValidatorSyncCommitteeIndices []spec.CommitteeIndex
}

Duty represent data regarding the duty type with the duty data

type Encoder

type Encoder interface {
	// Encode returns the encoded struct in bytes or error
	Encode() ([]byte, error)
	// Decode returns error if decoding failed
	Decode(data []byte) error
}

type KeyManager

type KeyManager interface {
	BeaconSigner
	SSVSigner
	// AddShare saves a share key
	AddShare(shareKey *bls.SecretKey) error
	// RemoveShare removes a share key
	RemoveShare(pubKey string) error
}

KeyManager is an interface responsible for all key manager functions

type MessageID

type MessageID [52]byte

MessageID is used to identify and route messages to the right validator and Runner

func MessageIDFromBytes

func MessageIDFromBytes(mid []byte) MessageID

func NewMsgID

func NewMsgID(pk []byte, role BeaconRole) MessageID

func (MessageID) GetPubKey

func (msg MessageID) GetPubKey() []byte

func (MessageID) GetRoleType

func (msg MessageID) GetRoleType() BeaconRole

func (MessageID) String

func (msgID MessageID) String() string

type MessageSignature

type MessageSignature 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 MessageSignature) error
}

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

type MsgType

type MsgType uint64
const (
	// SSVConsensusMsgType are all QBFT consensus related messages
	SSVConsensusMsgType MsgType = iota
	// SSVPartialSignatureMsgType are all partial signatures msgs over beacon chain specific signatures
	SSVPartialSignatureMsgType
	// DKGMsgType represent all DKG related messages
	DKGMsgType
)

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

type OperatorList

type OperatorList []OperatorID

func (OperatorList) ToUint32List

func (operators OperatorList) ToUint32List() []uint32

type Root

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

type SSVMessage

type SSVMessage struct {
	MsgType MsgType
	MsgID   MessageID
	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 returns error if decoding failed

func (*SSVMessage) Encode

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

Encode returns a msg encoded bytes or error

func (*SSVMessage) GetData

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

GetData returns message Data as byte slice

func (*SSVMessage) GetID

func (msg *SSVMessage) GetID() MessageID

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

func (*SSVMessage) GetType

func (msg *SSVMessage) GetType() MsgType

type SSVSigner

type SSVSigner interface {
	SignRoot(data Root, sigType SignatureType, pk []byte) (Signature, error)
}

SSVSigner used for all SSV specific signing

type SSZBytes

type SSZBytes []byte

SSZBytes --

func (SSZBytes) GetTree

func (b SSZBytes) GetTree() (*ssz.Node, error)

func (SSZBytes) HashTreeRoot

func (b SSZBytes) HashTreeRoot() ([32]byte, error)

func (SSZBytes) HashTreeRootWith

func (b SSZBytes) HashTreeRootWith(hh ssz.HashWalker) error

type SSZTransactions

type SSZTransactions []bellatrix.Transaction

SSZTransactions --

func (SSZTransactions) GetTree

func (b SSZTransactions) GetTree() (*ssz.Node, error)

func (SSZTransactions) HashTreeRoot

func (b SSZTransactions) HashTreeRoot() ([32]byte, error)

HashTreeRoot --

func (SSZTransactions) HashTreeRootWith

func (b SSZTransactions) HashTreeRootWith(hh ssz.HashWalker) error

type SSZUint64

type SSZUint64 uint64

func (SSZUint64) GetTree

func (s SSZUint64) GetTree() (*ssz.Node, error)

func (SSZUint64) HashTreeRoot

func (s SSZUint64) HashTreeRoot() ([32]byte, error)

HashTreeRoot --

func (SSZUint64) HashTreeRootWith

func (s SSZUint64) HashTreeRootWith(hh ssz.HashWalker) error

type Share

type Share struct {
	OperatorID            OperatorID
	ValidatorPubKey       ValidatorPK
	SharePubKey           []byte
	Committee             []*Operator
	Quorum, PartialQuorum uint64
	DomainType            DomainType
	FeeRecipientAddress   bellatrix.ExecutionAddress
	Graffiti              []byte
}

Share holds all info about the QBFT/ SSV Committee for msg signing and verification

func (*Share) Decode

func (share *Share) Decode(data []byte) error

func (*Share) Encode

func (share *Share) Encode() ([]byte, error)

func (*Share) HasPartialQuorum

func (share *Share) HasPartialQuorum(cnt int) bool

HasPartialQuorum returns true if at least f+1 items present (cnt is the number of items). It assumes nothing about those items, not their type or structure. https://github.com/ConsenSys/qbft-formal-spec-and-verification/blob/main/dafny/spec/L1/node_auxiliary_functions.dfy#L244

func (*Share) HasQuorum

func (share *Share) HasQuorum(cnt int) bool

HasQuorum returns true if at least 2f+1 items are present (cnt is the number of items). It assumes nothing about those items, not their type or structure https://github.com/ConsenSys/qbft-formal-spec-and-verification/blob/main/dafny/spec/L1/node_auxiliary_functions.dfy#L259

type Signature

type Signature []byte

func (Signature) Aggregate

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

func (Signature) ECRecover

func (s Signature) ECRecover(data Root, domain DomainType, sigType SignatureType, address common.Address) error

func (Signature) Verify

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

func (Signature) VerifyByOperators

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

VerifyByOperators verifies signature by the provided operators

func (Signature) VerifyMultiPubKey

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

type SignatureDomain

type SignatureDomain []byte

func ComputeSignatureDomain

func ComputeSignatureDomain(domain DomainType, sigType SignatureType) SignatureDomain

type SignatureType

type SignatureType [4]byte
var (
	QBFTSignatureType    SignatureType = [4]byte{1, 0, 0, 0}
	PartialSignatureType SignatureType = [4]byte{2, 0, 0, 0}
	DKGSignatureType     SignatureType = [4]byte{3, 0, 0, 0}
)

func (SignatureType) Equal

func (sigType SignatureType) Equal(other SignatureType) bool

type ThreadSafeF

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

ThreadSafeF makes function execution thread safe

func NewThreadSafeF

func NewThreadSafeF() *ThreadSafeF

NewThreadSafeF returns a new instance of NewThreadSafeF

func (*ThreadSafeF) Run

func (safeF *ThreadSafeF) Run(f func() interface{}) interface{}

Run runs the provided function

type Validate

type Validate interface {
	// Validate returns error if msg validation doesn't pass.
	// Msg validation checks the msg, it's variables for validity.
	Validate() error
}

type ValidatorPK

type ValidatorPK []byte

ValidatorPK is an eth2 validator public key

func (ValidatorPK) MessageIDBelongs

func (vid ValidatorPK) MessageIDBelongs(msgID MessageID) 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