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

feat(frost-core): simplify trait bounds, don't use the allocator in some places #810

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

StackOverflowExcept1on
Copy link
Contributor

@StackOverflowExcept1on StackOverflowExcept1on commented Dec 12, 2024

Resolves #807
@conradoplg We discussed this earlier. This will also allow to encrypt Serialization for the 2nd round of DKG (without allocation). I haven't added + Default yet as that would break the API, but I think even this implementation will be enough.

@mpguerra mpguerra requested a review from conradoplg December 12, 2024 14:21
Copy link
Contributor

@conradoplg conradoplg left a comment

Choose a reason for hiding this comment

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

This looks good, but since it's a breaking change (in the SemVer sense, any Ciphersuite implementor will need to implement the additional traits) it will have to wait until we're ready to release 3.0.0.

I think the Copy bounds are not needed?

@@ -37,7 +37,7 @@ pub trait Field: Copy + Clone {
+ Sub<Output = Self::Scalar>;

/// A unique byte array buf of fixed length N.
type Serialization: AsRef<[u8]> + Debug + TryFrom<Vec<u8>>;
type Serialization: Copy + AsRef<[u8]> + AsMut<[u8]> + for<'a> TryFrom<&'a [u8]> + Debug;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
type Serialization: Copy + AsRef<[u8]> + AsMut<[u8]> + for<'a> TryFrom<&'a [u8]> + Debug;
type Serialization: AsRef<[u8]> + AsMut<[u8]> + for<'a> TryFrom<&'a [u8]> + Debug;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also need Copy for my DKG implementation with encryption. Maybe we could reduce it to Clone instead of Copy (to also be compatible with types like Vec<u8>)?

@@ -102,7 +102,7 @@ pub trait Group: Copy + Clone + PartialEq {
/// A unique byte array buf of fixed length N.
///
/// Little-endian!
type Serialization: AsRef<[u8]> + Debug + TryFrom<Vec<u8>>;
type Serialization: Copy + AsRef<[u8]> + AsMut<[u8]> + for<'a> TryFrom<&'a [u8]> + Debug;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
type Serialization: Copy + AsRef<[u8]> + AsMut<[u8]> + for<'a> TryFrom<&'a [u8]> + Debug;
type Serialization: AsRef<[u8]> + AsMut<[u8]> + for<'a> TryFrom<&'a [u8]> + Debug;

Comment on lines +165 to +169
type SignatureSerialization: Copy
+ AsRef<[u8]>
+ AsMut<[u8]>
+ for<'a> TryFrom<&'a [u8]>
+ Debug;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
type SignatureSerialization: Copy
+ AsRef<[u8]>
+ AsMut<[u8]>
+ for<'a> TryFrom<&'a [u8]>
+ Debug;
type SignatureSerialization: AsRef<[u8]>
+ AsMut<[u8]>
+ for<'a> TryFrom<&'a [u8]>
+ Debug;

@conradoplg conradoplg added the S-blocked Status: Blocked on other tasks label Dec 27, 2024
Copy link

codecov bot commented Dec 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.45%. Comparing base (5f4ac6e) to head (5a65678).
Report is 79 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #810      +/-   ##
==========================================
+ Coverage   82.18%   82.45%   +0.26%     
==========================================
  Files          31       41      +10     
  Lines        3188     4331    +1143     
==========================================
+ Hits         2620     3571     +951     
- Misses        568      760     +192     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@StackOverflowExcept1on
Copy link
Contributor Author

StackOverflowExcept1on commented Dec 27, 2024

This looks good, but since it's a breaking change

@conradoplg I disagree, since implementations of Ciphersuite are more likely to just use [u8; N]. The Copy bound is not used, but it's kind of an additional restriction (to have the user use [u8; N] for now, rather than wrapper type with + Default). You can certainly follow with SemVer, but I think only 1 out of 100 cases will break something. We can release it as minor version 2.1.0.

@StackOverflowExcept1on
Copy link
Contributor Author

@conradoplg After some reseach about SemVer, I was only able to find 1 place where my PR breaks it: https://github.com/penumbra-zone/penumbra/blob/0e3d7966e3ff34bf74d7721a97848567f345e364/crates/crypto/decaf377-frost/src/traits.rs#L87. type SignatureSerialization = Vec<u8> and type Serialization = Vec<u8> are likely to cause an error, since both do not implement Copy. I found this through GitHub Search: https://github.com/search?q=%2F(%3F-i)impl+Ciphersuite+for%2F+NOT+is%3Afork&type=code. Should we be so worried and block it because of one breakdown?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-blocked Status: Blocked on other tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Copy + Clone trait-bound can be simplified
2 participants