-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a dedicated ssv_types
crate.
#58
base: unstable
Are you sure you want to change the base?
Changes from all commits
834891b
0f0ef38
3676efe
c8bdf73
5b02a70
1712f7b
376cdaa
d53b83c
80b71c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "ssv_types" | ||
version = "0.1.0" | ||
edition = { workspace = true } | ||
authors = ["Sigma Prime <[email protected]>"] | ||
|
||
[dependencies] | ||
types = { workspace = true} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use crate::{Operator, OperatorID, OperatorPublicKey}; | ||
use types::Domain; | ||
|
||
/// Unique identifier for a committee. | ||
pub type CommitteeID = u64; | ||
|
||
/// Member of a SSV Committee. A `CommitteeMember` is just an operator that is part of the committee | ||
/// a validator has chosen to distribute its keyshares to. | ||
#[derive(Debug, Clone)] | ||
pub struct CommitteeMember { | ||
// Unique identifier for the operator | ||
pub operator_id: OperatorID, | ||
// Unique identifier for the committee this member is a part of | ||
pub committee_id: CommitteeID, | ||
// Base-64 encoded PEM RSA public key of the operator | ||
pub share_public_key: OperatorPublicKey, | ||
// Number of nodes that are faulty/malicious in the committee | ||
pub faulty: u64, | ||
// All of the operators that are a part of this committee | ||
pub members: Vec<Operator>, | ||
// Signature domain | ||
pub domain: Domain, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pub use committee::{CommitteeID, CommitteeMember}; | ||
pub use operator::{Operator, OperatorID, OperatorPublicKey}; | ||
pub use share::SSVShare; | ||
mod committee; | ||
mod operator; | ||
mod share; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/// Unique identifier for an Operator | ||
pub type OperatorID = u64; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For things that we will be using a lot, we should use the new type idiom: https://doc.rust-lang.org/rust-by-example/generics/new_types.html This enforces the type at compile time, so we can't get confused by accidentally putting another type that is a u64 in place of this. For the operator-id, I have already done this. See here - I used usize, (I didn't check the specs :p, if the specs say u64, then we should change it to that). |
||
|
||
/// Operator RSA public key | ||
pub type OperatorPublicKey = [u8; 459]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are using RSA, we probably should use a specific library and its associated public key type. Each library will have an RSAPublicKey struct. This object will have been verified when created or deserialized. If we use this type, then there is no chance that we are carrying around invalid/malicious bytes in other types. I think we want to deserialize any public key we get from the network instantly or reject the message, then we carry around only verified and valid keys throughout our types. i.e our types shouldn't really be bytes anywhere, unless we have to have them. |
||
|
||
/// Client responsible for maintaining the overall health of the network. | ||
#[derive(Debug, Clone)] | ||
pub struct Operator { | ||
// ID to uniquely identify this operator | ||
pub id: OperatorID, | ||
// Base-64 encoded PEM RSA public key | ||
pub public_key: OperatorPublicKey, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use crate::CommitteeID; | ||
use std::time::SystemTime; | ||
use types::{Address, Domain, Graffiti, PublicKey}; | ||
|
||
type ValidatorIndex = usize; | ||
|
||
/// Share of a key that a operator owns and accompanying metadata | ||
#[derive(Debug, Clone)] | ||
pub struct SSVShare { | ||
pub share: Share, | ||
pub metadata: Metadata, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You've been awesome with comments on all the fields, might as well be consistent here |
||
} | ||
|
||
/// One of N shares of a split validator key | ||
#[derive(Debug, Clone)] | ||
pub struct Share { | ||
/// Index of the validator | ||
pub validator_index: ValidatorIndex, | ||
/// Public key of the validator | ||
pub validator_pubkey: PublicKey, | ||
/// Public key for this portion of the share | ||
pub share_public_key: PublicKey, | ||
/// All committee members that contain a sibling share | ||
pub committee: Vec<ShareMember>, | ||
/// Identifies the context/purpose of signature | ||
pub domain_type: Domain, | ||
/// Eth1 fee address | ||
pub fee_recipient: Address, | ||
/// Graffiti | ||
pub graffiti: Graffiti, | ||
} | ||
|
||
/// A operator who holds a portion of the share | ||
#[derive(Debug, Clone)] | ||
pub struct ShareMember { | ||
/// Unique identifier for the operator | ||
pub operator: CommitteeID, | ||
/// The public key for this members share | ||
pub share_public_key: PublicKey, | ||
} | ||
|
||
/// General metadata | ||
#[derive(Debug, Clone)] | ||
pub struct Metadata { | ||
/// The owner of the validator | ||
pub owner: Address, | ||
/// Is the committee this share is a part of currently liquidated | ||
pub liquidated: bool, | ||
/// Track the last time the metadata was updated. | ||
pub last_updated: SystemTime, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here as operator id.
Its a bit cumbersome, but it does pay dividends in the future