-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Fix broken test generators #1575
Conversation
cc: @ChihChengLiang |
I'd lean toward modifying the test case to test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I forgot the thumbs 👍👍👍
added the following test cases:
I also kept in ready for additional review @ChihChengLiang |
tests/generators/bls/main.py
Outdated
'message': encode_hex(msg), | ||
}, | ||
'output': hash_message_compressed(msg) | ||
} | ||
|
||
|
||
def case03_private_to_public_key(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not convinced that we should be explicitly checking this. While I exposed this functionality in py_ecc
, the BLS specs don't feature an implementation of this function. Maybe I should have made it a "private" method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this not an exceedingly common operation that we want to test? -- the determinism of moving from a secret integer to a pubkey?
I suppose I might be missing something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it is useful to test common functionality and that this functionality is probably common, but PrivToPub
is a function I made up. It does not exist in the BLS specifications. I opened an issue about this on the specs ~6 months ago, but they didn't feel like this if functionality that should be required as a part of the specs.
tests/generators/bls/main.py
Outdated
Output: | ||
- Message hash as a compressed G2 point | ||
""" | ||
z1, z2 = bls.utils.compress_G2(bls.utils.hash_to_G2(msg, domain)) | ||
z1, z2 = bls.point_compression.compress_G2(bls.hash_to_curve.hash_to_G2(msg, DST)) | ||
return [int_to_hex(z1, G2_COMPRESSED_Z_LEN), int_to_hex(z2, G2_COMPRESSED_Z_LEN)] | ||
|
||
|
||
def case01_message_hash_G2_uncompressed(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this (and hash_to_G2_compressed
) a meaningful test case? I imagine (and hope) that most BLS implementations won't expose the "raw" hash-to-curve functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel very strongly. These tests are really to ensure that you've integrated and configured your BLS library properly before getting lost in pyspec tests.
Curious to hear @benjaminion or @mratsim's opinion on this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the whole, I think that the reference tests should test only things used directly in the spec. Implementation-specific unit tests should take care of anything lower-level. So I'd vote for omitting the aggregate pubkeys tests, as well as the hash-to-G2 tests. The remaining BLS reference tests implicitly test these things in any case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should add a concrete rationale for the above, which is that it's undesirable to have to expose the inner workings of the BLS stuff just to satisfy the reference tests. If we can avoid doing that then it's easier to keep everything nicely encapsulated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree all around. Only the 5 specified BLS functions are now directly tested in this suite
Would love a last set of review @ChihChengLiang and/or @CarlBeek.
The latest commit is simply removing the non-api related tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My opinions are basically summarised by @benjaminion's comments above. Only test the high level API functionality that we use in the spec offered by a "standard" implementation of the specs.
…erator Co-Authored-By: Carl Beekhuizen <carl@ethereum.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In principal, I think this is good. In accordance with the ideology of only testing what is exposed to the api I think the following tests should be removed:
case01_message_hash_G2_uncompressed()
case02_message_hash_G2_compressed()
case03_private_to_public_key()
tests/generators/bls/main.py
Outdated
'message': encode_hex(msg), | ||
}, | ||
'output': hash_message_compressed(msg) | ||
} | ||
|
||
|
||
def case03_private_to_public_key(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it is useful to test common functionality and that this functionality is probably common, but PrivToPub
is a function I made up. It does not exist in the BLS specifications. I opened an issue about this on the specs ~6 months ago, but they didn't feel like this if functionality that should be required as a part of the specs.
tests/generators/bls/main.py
Outdated
Output: | ||
- Message hash as a compressed G2 point | ||
""" | ||
z1, z2 = bls.utils.compress_G2(bls.utils.hash_to_G2(msg, domain)) | ||
z1, z2 = bls.point_compression.compress_G2(bls.hash_to_curve.hash_to_G2(msg, DST)) | ||
return [int_to_hex(z1, G2_COMPRESSED_Z_LEN), int_to_hex(z2, G2_COMPRESSED_Z_LEN)] | ||
|
||
|
||
def case01_message_hash_G2_uncompressed(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My opinions are basically summarised by @benjaminion's comments above. Only test the high level API functionality that we use in the spec offered by a "standard" implementation of the specs.
Sorry, accidentally didn't push my local commit with the changes. Thanks for the review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicks, but LGTM. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My nitpicks
byte_value = byte_value.rjust(byte_length, b'\x00') | ||
return byte_value | ||
|
||
|
||
def hex_to_int(x: str) -> int: | ||
return int(x, 16) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line 44 DOMAINS
can now be safely removed
@@ -29,6 +30,13 @@ def int_to_hex(n: int, byte_length: int = None) -> str: | |||
return encode_hex(byte_value) | |||
|
|||
|
|||
def int_to_bytes(n: int, byte_length: int = None) -> bytes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is unused
Oops, an hour late, never mind 😂 |
Thanks! Fixed in |
Bytes
->ByteList
)