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

Updated blst to latest c-kzg hash #237

Merged
merged 12 commits into from
Oct 12, 2023

Conversation

ProgrammingBen
Copy link
Contributor

@ProgrammingBen ProgrammingBen commented Sep 24, 2023

In this PR updated:

  1. Patches;
  2. Trusted setup;
  3. Vector tests;
  4. Unit tests;
  5. Parallelization;
  6. Code base.

From 5703f6f3536b7692616bc289ac3f3867ab8db9d8 to b2e41491ad1859f1792964a2432a419b64dc6fb2

@sauliusgrigaitis
Copy link
Member

So I reviewed a bit more and it seems upstream c-kzg-4844 implementation is quite different. They changed various things, including adding additional checks etc. Tests likely don't cover it. So all the details need to be ported. The best is probably to compare side-by-side our implementation and c-kzg-4844 and port/fix any incompatibilities.

Comment on lines 19 to 24
fn u64_to_bytes(x: u64) -> [u8; 32] {
let mut bytes = [0u8; 32];
bytes[0..8].copy_from_slice(&x.to_le_bytes());
bytes[24..32].copy_from_slice(&x.to_be_bytes());
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 change will affect other backends that expect from_bytes to be LE format. I'm not sure if this is relevant to mcl or zkcrypto, haven't checked, but it does affect arkworks.

Probably same thing is also in other modified tests, have we decided that all from_bytes should expect BE format?

Copy link
Contributor

@lynxcs lynxcs Oct 5, 2023

Choose a reason for hiding this comment

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

To clarify - I'm fine with changing arkworks implementation to convert from BE to LE, just think that from_bytes should be consistent across all backends.

EDIT: Alternatively we can add from_bytes_le & from_bytes_be to traits & then this issue will be avoided

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think that's a good idea to rename TFr::from_bytes to TFr::from_be_bytes, although I don't really see a point in implementing TFr::from_le_bytes - all eip4844 functions expect that bytes will be in BE (see "constants" section "KZG_ENDIANNESS").

Copy link
Contributor

@lynxcs lynxcs Oct 6, 2023

Choose a reason for hiding this comment

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

Ah right, my mistake, I heard about that switch to BE and thought it applied to all elements though looks like G1/G2 was already BE & only field element was recently changed to BE. I checked arkworks deserialization implementation it seems that G1/G2 already assumed BE format, so all good on that front.

In our case arkworks library Fr serialization assumed input to be LE & that's why that specific test started failing.

Overall I think simplest solution is just to make other teams aware that they should check their Fr from/to bytes/u64 implementations 😄
Or if we decide to change the traits then probably only Fr should have those _le/_be variants.

Anyways, thank you for detailed explanation!

EDIT: saw you changed your comment in the time it took for me to write the original comment xddd. I guess I would agree with from_le_bytes not being really relevant.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, deleted the original comment, as it is a bit irrelevant - TFr is not a direct API of eip4844, so technically trait could be implemented as you wish.

I believe we should write additional tests for general traits, so all of them work the same.

@ProgrammingBen ProgrammingBen changed the base branch from main to integration October 12, 2023 14:10
@sauliusgrigaitis sauliusgrigaitis merged commit 4aa475e into grandinetech:integration Oct 12, 2023
6 of 20 checks passed
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.

4 participants