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

bls: Use int_to_bytes8 to serialize domain #681

Closed
wants to merge 1 commit into from
Closed

bls: Use int_to_bytes8 to serialize domain #681

wants to merge 1 commit into from

Conversation

wemeetagain
Copy link
Contributor

@wemeetagain wemeetagain commented Feb 24, 2019

The function bytes8 does not exist in the spec. Using int_to_bytes8
has a clearer meaning: serialize into 8 bytes as little endian.

The function `bytes8` does not exist in the spec. Using `int_to_bytes8`
has a clearer meaning.
@hwwhww
Copy link
Contributor

hwwhww commented Feb 25, 2019

  1. IMO we would avoid BLS spec referencing to core specs.
  2. int_to_bytes8 is little endian converting, while x_re and x_im are still in big-endian. IMO BLS spec is part of cryptography black box (Little vs big endian #556 (comment)). Also, related to Cross-blockchain BLS12-381 standardisation #605.

What do you think about explicitly:

    x_re = int.from_bytes(hash(message_hash + domain.to_bytes(8, 'big') + b'\x01'), 'big')
    x_im = int.from_bytes(hash(message_hash + domain.to_bytes(8, 'big') + b'\x02'), 'big')

@wemeetagain
Copy link
Contributor Author

wemeetagain commented Feb 25, 2019

If we clarify as you mentioned, that gets at the heart of the issue, that the endian-ness is currently unspecified/unclear.

Perhaps an even cleaner solution would be to pass in domain as a bytes8 rather than as a uint64, and have the bls spec not need to worry about domain integer serialization at all.

eg:

def hash_to_G2(message_hash: Bytes32, domain: Bytes8) -> [uint384]:
    x_re = int.from_bytes(hash(message_hash + domain + b'\x01'), 'big')
    x_im = int.from_bytes(hash(message_hash + domain + b'\x02'), 'big')

@hwwhww
Copy link
Contributor

hwwhww commented Feb 26, 2019

Hey @wemeetagain, I like your second proposal more. :)

However, it will change the interface, and #605 may change it again later. Therefore, it may not worth it to change the interface recently before #605 due to the overhead of updating test vectors.

@wemeetagain
Copy link
Contributor Author

Oky, I'll close this PR. When the #605 change rolls around, we can give the appropriate input.

@wemeetagain wemeetagain deleted the clarify-bls-domain-serialization branch February 26, 2019 16:18
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.

2 participants