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

Compression/Decompression of G2 Points for BLS12_381 #909

Merged
merged 16 commits into from
Sep 9, 2024

Conversation

ColoCarletti
Copy link
Contributor

@ColoCarletti ColoCarletti commented Sep 9, 2024

Compression/Decompression of G2 Points for BLS12_381

This PR fixes a bug in the function responsible for decompressing points on the BLS12_381 curve, where the 3rd bit was not being properly accounted for.

It also adds functionality for compressing points on this curve.

Type of change

  • New feature
  • Bug fix

Checklist

  • Unit tests added

@ColoCarletti ColoCarletti requested a review from a team as a code owner September 9, 2024 12:58
@codecov-commenter
Copy link

codecov-commenter commented Sep 9, 2024

Codecov Report

Attention: Patch coverage is 96.11650% with 4 lines in your changes missing coverage. Please review.

Project coverage is 72.81%. Comparing base (94c2293) to head (98a32da).

Files with missing lines Patch % Lines
.../short_weierstrass/curves/bls12_381/compression.rs 96.11% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #909      +/-   ##
==========================================
+ Coverage   72.66%   72.81%   +0.15%     
==========================================
  Files         150      150              
  Lines       34057    34151      +94     
==========================================
+ Hits        24746    24866     +120     
+ Misses       9311     9285      -26     

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


// Set the 3rd bit based on y value.
let y_neg = -y;
if y.value()[0].representative() > y_neg.value()[0].representative()
Copy link
Contributor

Choose a reason for hiding this comment

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

This condition should be y.value()[0].representative() > y_neg.value()[0].representative() || (y.value()[0].representative() == y_neg.value()[0].representative() && y.value()[1].representative() > y_neg.value()[1].representative()).
Perhaps a more efficient strategy is
y_is_greater_or_equal = y.value()[0].representative() >= y_neg.value()[0].representative().
if y_is_greater_or_equal || (y_is_greater_or_equal && y.value()[1].representative() > y_neg.value()[1].representative()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@ColoCarletti ColoCarletti requested a review from a team September 9, 2024 15:58
Comment on lines +110 to +111
x_bytes[0] |= 1 << 7;
x_bytes[0] |= 1 << 6;
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
x_bytes[0] |= 1 << 7;
x_bytes[0] |= 1 << 6;
x_bytes[0] |= 0b11 << 6;

@@ -106,7 +102,48 @@ impl Compress for BLS12381Curve {
.ok_or(ByteConversionError::PointNotInSubgroup)
}

#[allow(unused)]
#[cfg(feature = "alloc")]
fn compress_g2_point(point: &Self::G2Point) -> alloc::vec::Vec<u8> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need a Vec here or is it constant size?

Copy link
Contributor

Choose a reason for hiding this comment

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

Traits get in the way, but we can try to solve this if we expose more things

@Oppen Oppen added this pull request to the merge queue Sep 9, 2024
Merged via the queue into main with commit 00869a7 Sep 9, 2024
7 checks passed
@Oppen Oppen deleted the fix_bls12_381_compression branch September 9, 2024 21:41
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.

4 participants