Documentation ¶
Index ¶
- Constants
- Variables
- func ComputeETHDomain(domain spec.DomainType, fork spec.Version, genesisValidatorRoot spec.Root) (spec.Domain, error)
- func ComputeETHSigningRoot(obj ssz.HashRoot, domain spec.Domain) (spec.Root, error)
- func ComputeSigningRoot(data Root, domain SignatureDomain) ([]byte, error)
- func Decrypt(sk *rsa.PrivateKey, cipherText []byte) ([]byte, error)
- func Encrypt(pk *rsa.PublicKey, plainText []byte) ([]byte, error)
- func GenerateETHDepositData(validatorPK, withdrawalCredentials []byte, fork phase0.Version, ...) ([]byte, *phase0.DepositData, error)
- func GenerateKey() ([]byte, []byte, error)
- func GetPublicKeyPem(sk *rsa.PrivateKey) ([]byte, error)
- func InitBLS()
- func PemToPrivateKey(skPem []byte) (*rsa.PrivateKey, error)
- func PemToPublicKey(pkPem []byte) (*rsa.PublicKey, error)
- func PrivateKeyToPem(sk *rsa.PrivateKey) []byte
- func ReconstructSignatures(signatures map[OperatorID][]byte) (*bls.Sign, error)
- func VerifyReconstructedSignature(sig *bls.Sign, validatorPubKey, root []byte) error
- type BeaconNetwork
- func (n BeaconNetwork) EpochStartTime(epoch spec.Epoch) time.Time
- func (n BeaconNetwork) EstimatedCurrentEpoch() spec.Epoch
- func (n BeaconNetwork) EstimatedCurrentSlot() spec.Slot
- func (n BeaconNetwork) EstimatedEpochAtSlot(slot spec.Slot) spec.Epoch
- func (n BeaconNetwork) EstimatedSlotAtTime(time int64) spec.Slot
- func (n BeaconNetwork) EstimatedTimeAtSlot(slot spec.Slot) int64
- func (n BeaconNetwork) FirstSlotAtEpoch(epoch spec.Epoch) spec.Slot
- func (n BeaconNetwork) ForkVersion() [4]byte
- func (n BeaconNetwork) MinGenesisTime() uint64
- func (n BeaconNetwork) SlotDurationSec() time.Duration
- func (n BeaconNetwork) SlotsPerEpoch() uint64
- type BeaconRole
- type BeaconSigner
- type ConsensusData
- type ContributionsMap
- type DKGSigner
- type DomainType
- type Duty
- type Encoder
- type KeyManager
- type MessageID
- type MessageSignature
- type MsgType
- type Operator
- type OperatorID
- type OperatorList
- type Root
- type SSVMessage
- type SSVSigner
- type SSZBytes
- type SSZTransactions
- type SSZUint64
- type Share
- type Signature
- func (s Signature) Aggregate(other Signature) (Signature, error)
- func (s Signature) ECRecover(data Root, domain DomainType, sigType SignatureType, address common.Address) error
- func (s Signature) Verify(data Root, domain DomainType, sigType SignatureType, pkByts []byte) error
- func (s Signature) VerifyByOperators(data MessageSignature, domain DomainType, sigType SignatureType, ...) error
- func (s Signature) VerifyMultiPubKey(data Root, domain DomainType, sigType SignatureType, pks [][]byte) error
- type SignatureDomain
- type SignatureType
- type ThreadSafeF
- type Validate
- type ValidatorPK
Constants ¶
const BLSWithdrawalPrefixByte = byte(0)
BLSWithdrawalPrefixByte is the BLS withdrawal prefix
const MaxEffectiveBalanceInGwei uint64 = 32000000000
MaxEffectiveBalanceInGwei is the max effective balance
Variables ¶
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} )
var ( PrimusTestnet = DomainType("primus_testnet") ShifuTestnet = DomainType("shifu_testnet") )
var GenesisForkVersion = spec.Version{0, 0, 0, 0}
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 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 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 ¶
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 PemToPrivateKey ¶
func PemToPrivateKey(skPem []byte) (*rsa.PrivateKey, error)
PemToPrivateKey return rsa private key from pem
func PemToPublicKey ¶
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
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
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 ¶
type ContributionsMap map[phase0.BLSSignature]*altair.SyncCommitteeContribution
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 KeyManager ¶
type KeyManager interface { BeaconSigner SSVSigner AddShare(shareKey *bls.SecretKey) error 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 NewMsgID ¶
func NewMsgID(pk []byte, role BeaconRole) MessageID
func (MessageID) GetRoleType ¶
func (msg MessageID) GetRoleType() BeaconRole
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 Operator ¶
type Operator struct { OperatorID OperatorID PubKey []byte }
Operator represents an SSV operator node
func (*Operator) GetPublicKey ¶
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 SSVMessage ¶
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) HashTreeRoot ¶
func (SSZBytes) HashTreeRootWith ¶
func (b SSZBytes) HashTreeRootWith(hh ssz.HashWalker) error
type SSZTransactions ¶
type SSZTransactions []bellatrix.Transaction
SSZTransactions --
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) HashTreeRootWith ¶
func (s SSZUint64) HashTreeRootWith(hh ssz.HashWalker) error
type Share ¶
type Share struct {
Share holds all info about the QBFT/ SSV Committee for msg signing and verification
func (*Share) HasPartialQuorum ¶
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 ¶
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) 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