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 10 commits into
base: unstable
Choose a base branch
from

Conversation

Zacholme7
Copy link
Member

@Zacholme7 Zacholme7 commented Nov 27, 2024

Issue Addressed

N/A

Proposed Changes

This PR starts a ssv_types crate within anchor/common. It contains core SSV types in accordance with the spec. It does not contain related methods as we still need to determine what is needed, but just having these types defined helps. Validator related types are imported via the types crate in lighthouse.

Additional Info

This is just an initial draft to get the ball rolling. It will change as we see fit. Also waiting on re-export of ValidatorIndex in lighthouse into unstable.

@Zacholme7 Zacholme7 changed the title Create a dedicated types module. Create a dedicated types crate. Nov 27, 2024
@Zacholme7 Zacholme7 changed the title Create a dedicated types crate. Create a dedicated ssv_types crate. Nov 27, 2024
@Zacholme7 Zacholme7 changed the base branch from stable to unstable November 27, 2024 14:09
Copy link
Member

@AgeManning AgeManning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I had a few comments

pub type OperatorID = u64;

/// 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.

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

#[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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants