types

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: GPL-3.0 Imports: 20 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 (
	// PrimusTestnet is the domain for primus testnet
	PrimusTestnet = DomainType("primus_testnet")
	// ShifuTestnet is the domain for shifu testnet
	ShifuTestnet = DomainType("shifu")
)
View Source
var DomainDeposit = [4]byte{0x03, 0x00, 0x00, 0x00}

Functions

func ComputeETHDomain

func ComputeETHDomain(domain phase0.DomainType, fork phase0.Version) (phase0.Domain, error)

ComputeETHDomain returns computed domain

func ComputeETHSigningRoot

func ComputeETHSigningRoot(root phase0.Root, domain phase0.Domain) (phase0.Root, error)

func ComputeSigningRoot

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

func Decrypt added in v0.2.2

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

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

func Encrypt added in v0.2.2

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 added in v0.2.2

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

GenerateKey using rsa random generate keys

func GetPublicKeyPem added in v0.2.2

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 added in v0.2.2

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

PemToPrivateKey return rsa private key from pem

func PemToPublicKey added in v0.2.2

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

PemToPublicKey return rsa public key from pem

func PrivateKeyToPem added in v0.2.2

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 AggregatorCalls

type AggregatorCalls interface {
	// SignSlotWithSelectionProof signs slot for aggregator selection proof
	SignSlotWithSelectionProof(slot spec.Slot, pk []byte) (Signature, []byte, error)
	// SignAggregateAndProof returns a signed aggregate and proof msg
	SignAggregateAndProof(msg *spec.AggregateAndProof, duty *Duty, pk []byte) (*spec.SignedAggregateAndProof, []byte, error)
}

type AttesterCalls

type AttesterCalls interface {
	// SignAttestation signs the given attestation
	SignAttestation(data *spec.AttestationData, duty *Duty, pk []byte) (*spec.Attestation, []byte, error)
	// IsAttestationSlashable returns error if attestation is slashable
	IsAttestationSlashable(data *spec.AttestationData) error
}

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"

	// NowTestNetwork is a simple test network with genesis time always equal to now, meaning now is slot 0
	NowTestNetwork BeaconNetwork = "now_test_network"
)

Available networks.

func NetworkFromString

func NetworkFromString(n string) BeaconNetwork

NetworkFromString returns network from the given string value

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) 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
)

List of roles

func (BeaconRole) String

func (r BeaconRole) String() string

String returns name of the role

type ConsensusData

type ConsensusData struct {
	Duty                   *Duty
	AttestationData        *phase0.AttestationData
	BlockData              *altair.BeaconBlock
	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)

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

func GetDefaultDomain added in v0.2.2

func GetDefaultDomain() DomainType

GetDefaultDomain returns the global domain

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
}

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 EncryptionCalls

type EncryptionCalls interface {
	// Decrypt given a rsa pubkey and a PKCS1v15 cipher text byte array, returns the decrypted data
	Decrypt(pk *rsa.PublicKey, cipher []byte) ([]byte, error)
	// Encrypt given a rsa pubkey and data returns an PKCS1v15 encrypted cipher
	Encrypt(pk *rsa.PublicKey, data []byte) ([]byte, error)
}

EncryptionCalls captures all RSA share encryption calls

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 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
	// SSVDecidedMsgType are all QBFT decided messages
	SSVDecidedMsgType
	// 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 ProposerCalls

type ProposerCalls interface {
	// SignRandaoReveal signs randao
	SignRandaoReveal(epoch spec.Epoch, pk []byte) (Signature, []byte, error)
	// IsBeaconBlockSlashable returns true if the given block is slashable
	IsBeaconBlockSlashable(block *altair.BeaconBlock) error
	// SignBeaconBlock signs the given beacon block
	SignBeaconBlock(block *altair.BeaconBlock, duty *Duty, pk []byte) (*altair.SignedBeaconBlock, []byte, error)
}

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 {
	EncryptionCalls
	SignRoot(data Root, sigType SignatureType, pk []byte) (Signature, error)
}

SSVSigner used for all SSV specific signing

type Share

type Share struct {
	OperatorID            OperatorID
	ValidatorPubKey       ValidatorPK
	SharePubKey           []byte
	Committee             []*Operator
	Quorum, PartialQuorum uint64
	DomainType            DomainType
	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 SyncCommitteeCalls

type SyncCommitteeCalls interface {
	// SignSyncCommitteeBlockRoot returns a signed sync committee msg
	SignSyncCommitteeBlockRoot(slot spec.Slot, root spec.Root, validatorIndex spec.ValidatorIndex, pk []byte) (*altair.SyncCommitteeMessage, []byte, error)
}

type SyncCommitteeContributionCalls

type SyncCommitteeContributionCalls interface {
	// SignContributionProof signs contribution proof
	SignContributionProof(slot spec.Slot, index uint64, pk []byte) (Signature, []byte, error)
	// SignContribution signs a SyncCommitteeContribution
	SignContribution(contribution *altair.ContributionAndProof, pk []byte) (*altair.SignedContributionAndProof, []byte, error)
}

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