Skip to content

Use Bytes48 for commitments/proofs#86

Merged
xrchz merged 22 commits intoethereum:mainfrom
jtraglia:use-bytes48
Jan 26, 2023
Merged

Use Bytes48 for commitments/proofs#86
xrchz merged 22 commits intoethereum:mainfrom
jtraglia:use-bytes48

Conversation

@jtraglia
Copy link
Copy Markdown
Member

@jtraglia jtraglia commented Jan 25, 2023

This PR implements the changes defined here:

Notable:

  • KZGProof/KZGCommitment are considered trusted types. Bytes48 is untrusted.
    • Technically they are the same value though, it's just a typedef.
  • [deviation] Used z_bytes instead of z for consistency, this will be renamed later anyway.
  • Renamed all of the static constants to be ALL_UPPER_CASE.
  • Removed bytes_to_g1 function (bytes_from_g1 is still required).
  • There's a duplicate check in validate_kzg_g1. Not sure which is better.

Comment thread bindings/rust/src/lib.rs Outdated
Ok(Self { bytes: new_bytes })
}

pub fn to_proof(self) -> Result<KZGProof, Error> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are we using these helper functions? If not, maybe we can remove them? If yes, i think they should do the validate_kzg_G1 logic since we consider KZGProof and KZGCommitment to be trusted types.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good call. They weren't actually being used. Removed.

@asn-d6
Copy link
Copy Markdown
Contributor

asn-d6 commented Jan 26, 2023

LGTM!

@jtraglia jtraglia marked this pull request as ready for review January 26, 2023 13:32
Comment thread src/c_kzg_4844.c Outdated
static C_KZG_RET validate_kzg_g1(g1_t *out, const Bytes48 *b) {
/* Fast check without needing to uncompress */
if (memcmp(G1_POINT_AT_INFINITY.bytes, b->bytes, sizeof(b)) == 0)
return C_KZG_OK;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't we still need to fill out in this case?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good catch!

Copy link
Copy Markdown
Member Author

@jtraglia jtraglia Jan 26, 2023

Choose a reason for hiding this comment

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

Yes, thank you. I'm just going to remove that check, since there's an infinity check below.

Comment thread src/c_kzg_4844.h
typedef struct { uint8_t bytes[48]; } Bytes48;
typedef struct { uint8_t bytes[BYTES_PER_BLOB]; } Blob;

typedef Bytes48 KZGCommitment;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I probably missed it, but are these used for something?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

They are used as inputs/outputs in internal functions as in the spec. They signify a KZG proof or commitment which has been deserialized and normalized.

@xrchz
Copy link
Copy Markdown
Contributor

xrchz commented Jan 26, 2023

Does this address #84 too?

@asn-d6
Copy link
Copy Markdown
Contributor

asn-d6 commented Jan 26, 2023

Does this address #84 too?

It does yes. Altho we might want to leave that ticket open to figure out how to add a small subgroup unittest.

@xrchz xrchz merged commit 03b90ef into ethereum:main Jan 26, 2023
@jtraglia jtraglia deleted the use-bytes48 branch January 26, 2023 15:00
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.

3 participants