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

Fix broken test generators #1575

Merged
merged 6 commits into from
Jan 23, 2020
Merged

Fix broken test generators #1575

merged 6 commits into from
Jan 23, 2020

Conversation

djrtwo
Copy link
Contributor

@djrtwo djrtwo commented Jan 16, 2020

  • Fix BLS test generator by utilizing new py_ecc functions, types, etc. Strip down test cases to only test the 5 BLS functions in the spec
  • Fix ssz_generic test generator with a simple import fix (Bytes -> ByteList)

@djrtwo
Copy link
Contributor Author

djrtwo commented Jan 16, 2020

cc: @ChihChengLiang

@ChihChengLiang
Copy link
Contributor

I'd lean toward modifying the test case to test AggregateVerify and FastAggregateVerify. In short-run, client teams need to update their tests. But the tests should reflect on the specified functions.

Copy link
Contributor

@ChihChengLiang ChihChengLiang left a 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 👍👍👍

@benjaminion benjaminion mentioned this pull request Jan 21, 2020
6 tasks
@djrtwo
Copy link
Contributor Author

djrtwo commented Jan 21, 2020

added the following test cases:

  • case05_verify_message handling valid and invalid cases of bls.Verify
  • case08_fast_aggregate_verify handling valid and invalid cases of bls.FastAggregateVerify
  • case09_aggregate_verify handling valid and invalid cases of bls.AggregateVerify

I also kept in case07_aggregate_pubkeys as it is an independent feature that might very well be used by a validator/tooling in some cases.

ready for additional review @ChihChengLiang

'message': encode_hex(msg),
},
'output': hash_message_compressed(msg)
}


def case03_private_to_public_key():
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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 Show resolved Hide resolved
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():
Copy link
Contributor

@CarlBeek CarlBeek Jan 22, 2020

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.

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

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

@djrtwo djrtwo changed the base branch from master to v010x January 23, 2020 01:15
Copy link
Contributor

@CarlBeek CarlBeek left a 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()

'message': encode_hex(msg),
},
'output': hash_message_compressed(msg)
}


def case03_private_to_public_key():
Copy link
Contributor

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.

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():
Copy link
Contributor

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.

@djrtwo
Copy link
Contributor Author

djrtwo commented Jan 23, 2020

Sorry, accidentally didn't push my local commit with the changes. Thanks for the review

Copy link
Contributor

@CarlBeek CarlBeek left a comment

Choose a reason for hiding this comment

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

Nitpicks, but LGTM. 👍

tests/generators/bls/main.py Outdated Show resolved Hide resolved
tests/generators/bls/main.py Outdated Show resolved Hide resolved
tests/generators/bls/main.py Outdated Show resolved Hide resolved
tests/generators/bls/main.py Outdated Show resolved Hide resolved
tests/generators/bls/main.py Outdated Show resolved Hide resolved
tests/generators/bls/main.py Outdated Show resolved Hide resolved
@djrtwo djrtwo merged commit ec00f6d into v010x Jan 23, 2020
@djrtwo djrtwo deleted the broken-gens branch January 23, 2020 17:36
Copy link
Contributor

@ChihChengLiang ChihChengLiang left a 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)

Copy link
Contributor

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:
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is unused

@ChihChengLiang
Copy link
Contributor

Oops, an hour late, never mind 😂

@djrtwo
Copy link
Contributor Author

djrtwo commented Jan 23, 2020

Thanks! Fixed in v010x

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.

None yet

5 participants