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

IF: Change bls_public_key & bls_signature serialization #2338

Merged
merged 13 commits into from
Mar 28, 2024

Conversation

heifner
Copy link
Member

@heifner heifner commented Mar 26, 2024

Change bls_public_key and bls_signature serialization to be:

  • Non-Montgomery form and little-endian encoding for the field elements.
  • Affine form for the group element (the z component is 1 and not included in the serialization).
  • Binary serialization encodes x component first followed by y component.

Add bls_aggregate_signature which is mutable version of bls_signature. bls_signature is now immutable.

Serialize as variable sized array and instead of a fixed sized array to make it easier to use in external tools that use ABI since our ABI does not handle fixed sized arrays.

Resolves #2334

@heifner heifner linked an issue Mar 26, 2024 that may be closed by this pull request
@heifner heifner added the OCI Work exclusive to OCI team label Mar 26, 2024
@heifner heifner marked this pull request as ready for review March 26, 2024 21:30
@heifner heifner changed the title IF: Change bls_public_key serialization IF: Change bls_public_key & bls_signature serialization Mar 26, 2024
Base automatically changed from ship_finality_info_support to hotstuff_integration March 27, 2024 13:29
libraries/libfc/src/crypto/bls_public_key.cpp Outdated Show resolved Hide resolved
libraries/libfc/src/crypto/bls_public_key.cpp Outdated Show resolved Hide resolved
libraries/libfc/include/fc/crypto/bls_public_key.hpp Outdated Show resolved Hide resolved
libraries/libfc/include/fc/crypto/bls_signature.hpp Outdated Show resolved Hide resolved
libraries/libfc/include/fc/crypto/bls_signature.hpp Outdated Show resolved Hide resolved
libraries/libfc/include/fc/crypto/bls_signature.hpp Outdated Show resolved Hide resolved
@ericpassmore
Copy link
Contributor

Note:start
group: IF
category: INTERNALS
summary: Update internal storage format of BLS keys to optimize usage. No change to external representation of keys.
Note:end

Copy link
Member

@linh2931 linh2931 left a comment

Choose a reason for hiding this comment

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

Don't forget to change fixed array to vector for clients.

libraries/chain/hotstuff/hotstuff.cpp Show resolved Hide resolved
libraries/chain/block_state.cpp Show resolved Hide resolved
friend T& operator<<(T& ds, const bls_public_key& sig) {
// Serialization as variable length array when it is stored as a fixed length array. This makes for easier deserialization by external tools
fc::raw::pack(ds, fc::unsigned_int(static_cast<uint32_t>(sig._affine_non_montgomery_le.size()*sizeof(uint8_t))));
ds.write(reinterpret_cast<const char*>(sig._affine_non_montgomery_le.data()), sig._affine_non_montgomery_le.size()*sizeof(uint8_t));
Copy link
Contributor

Choose a reason for hiding this comment

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

why not?

Suggested change
ds.write(reinterpret_cast<const char*>(sig._affine_non_montgomery_le.data()), sig._affine_non_montgomery_le.size()*sizeof(uint8_t));
ds.write(reinterpret_cast<const char*>(sig._affine_non_montgomery_le.data()), sizeof(sig._affine_non_montgomery_le));

@heifner heifner requested a review from greg7mdp March 28, 2024 17:04
@heifner heifner merged commit 30fd771 into hotstuff_integration Mar 28, 2024
34 checks passed
@heifner heifner deleted the GH-2334-bls-serialization branch March 28, 2024 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCI Work exclusive to OCI team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IF: Ensure all serialization of g1/g2 uses serialization form
5 participants