Skip to content

Commit

Permalink
Merge pull request #121 from ethereum/fix-z1-check
Browse files Browse the repository at this point in the history
Fix the x1 point check
  • Loading branch information
hwwhww authored Apr 7, 2021
2 parents 8ddea32 + a8c5595 commit 033b4ea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions py_ecc/bls/point_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ def decompress_G2(p: G2Compressed) -> G2Uncompressed:
# Else, not point at infinity
# 3 MSBs should be 100 or 101
x1 = z1 % POW_2_381
# Ensure that x1 is less than the field modulus.
if x1 >= q:
raise ValueError("x1 value should be less than field modulus. Got %d", x1)

# Ensure that z2 is less than the field modulus.
if z2 >= q:
Expand Down
1 change: 1 addition & 0 deletions tests/bls/test_point_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def test_G2_compress_and_decompress_flags(pt, on_curve, is_infinity):
((compressed_g2[0] & ~(1<<383), compressed_g2[1]), "c_flag should be 1"), # set c_flag1 to 0
((compressed_g2[0] | (1<<382), compressed_g2[1]), "b_flag should be 0"), # set b_flag1 to 1
((compressed_z2[0] & ~(1<<382), compressed_z2[1]), "b_flag should be 1"), # set b_flag1 to 0
((q | (1<<383), compressed_z2[1]), "x1 value should be less than field modulus."), # x1 == q
((compressed_z2[0] | (1<<381), compressed_z2[1]), "a point at infinity should have a_flag == 0"), # set a_flag1 to 1
((compressed_g2[0], compressed_z2[1] | (1<<383)), "z2 point value should be less than field modulus."), # set c_flag2 to 1
((compressed_g2[0], compressed_z2[1] | (1<<382)), "z2 point value should be less than field modulus."), # set b_flag2 to 1
Expand Down

0 comments on commit 033b4ea

Please sign in to comment.