Skip to content
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

Open
wants to merge 9 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,167 changes: 769 additions & 398 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ members = [
"anchor/http_metrics",
"anchor/qbft",
"anchor/network",
"anchor/common/version"
"anchor/common/version",
"anchor/common/ssv_types"
]
resolver = "2"

Expand All @@ -28,6 +29,7 @@ validator_metrics = { git = "https://github.com/agemanning/lighthouse", branch =
sensitive_url = { git = "https://github.com/agemanning/lighthouse", branch = "modularize-vc" }
slot_clock = { git = "https://github.com/agemanning/lighthouse", branch = "modularize-vc" }
unused_port = { git = "https://github.com/sigp/lighthouse", branch = "unstable" }
types = { git = "https://github.com/sigp/lighthouse", branch = "unstable" }
derive_more = { version = "1.0.0", features = ["full"] }
async-channel = "1.9"
axum = "0.7.7"
Expand Down
8 changes: 8 additions & 0 deletions anchor/common/ssv_types/Cargo.toml
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}
23 changes: 23 additions & 0 deletions anchor/common/ssv_types/src/committee.rs
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;
Copy link
Member

@AgeManning AgeManning Dec 1, 2024

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


/// 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,
}
6 changes: 6 additions & 0 deletions anchor/common/ssv_types/src/lib.rs
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;
14 changes: 14 additions & 0 deletions anchor/common/ssv_types/src/operator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// Unique identifier for an Operator
pub type OperatorID = u64;
Copy link
Member

Choose a reason for hiding this comment

The 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];
Copy link
Member

Choose a reason for hiding this comment

The 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,
}
51 changes: 51 additions & 0 deletions anchor/common/ssv_types/src/share.rs
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,
Copy link
Member

Choose a reason for hiding this comment

The 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,
}
2 changes: 1 addition & 1 deletion anchor/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ serde = { workspace = true }
tracing = { workspace = true }

[dev-dependencies]
async-channel = { workspace = true }
async-channel = { workspace = true }
Loading