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

Style: improve api clients comments #780

Merged
merged 12 commits into from
Oct 19, 2024
Merged

Conversation

samlaf
Copy link
Contributor

@samlaf samlaf commented Oct 2, 2024

Small improvements to comments/docs for api clients.
Had some fun in the plane while reading the code.
Added some TODOs in a few places which might be worth checking through, perhaps we can solve some of them right away @bxue-l2

@samlaf samlaf requested a review from bxue-l2 October 2, 2024 19:22
Comment on lines +30 to +31
// TODO: all of these should be private, to prevent users from using them directly,
// which breaks encapsulation and makes it hard for us to do refactors or changes
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this I personally think is a refactor worth doing... but it might break some client code... :\

Copy link
Contributor

Choose a reason for hiding this comment

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

agree this should be private. From my experience, it is difficult to understand data semantics in each stage or encoding and decoding.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't understand your comment, why are you mentioning data semantics here?
And are you saying I should change the fields to private right now? Are we not scared of breaking user code that might be using these?

Copy link
Contributor

Choose a reason for hiding this comment

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

just from the developers' view, it tool me a while to understand the intermediate phases. If someone else would use it, I doubted it would be correct

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: we decided to do all the breaking changes in a future PR.

api/clients/eigenda_client.go Outdated Show resolved Hide resolved
@samlaf samlaf requested a review from jianoaix October 16, 2024 21:25
// where the lower address has more significant bits. The integer must stay in the valid range to be interpreted
// as a field element on the bn254 curve. The valid range is
// 0 <= x < 21888242871839275222246405745257275088548364400416034343698204186575808495617
// containing slightly less than 254 bits and more than 253 bits. If any one of the 32 bytes chunk is outside the range,
// the whole request is deemed as invalid, and rejected.
// which is a 254 bit number (meaning the first 2 bits of each chunk must always be 00).
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't accurate though, 21888242871839275222246405745257275088548364400416034343698204186575808495617 is smaller than 2^254-1 (i.e. the original comment is accurate that it doesn't have 254 bits).

Also shall we not use chunk here since it's easy to confuse with the encoding chunks (which will become more user visible in the future)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Took me a while to figure this one out haha. Doesn't matter that it's < 2^254-1, what matters is that it's > 2^253-1, and so actually needs 254 bits.

The number is 254 bits according to https://hackmd.io/@jpw/bn254 (which also explains why its called bn254 and not bn253). Here's also a python script showing that it's a 254 bit number:

number = 21888242871839275222246405745257275088548364400416034343698204186575808495617
binary_representation = bin(number)

# Count the number of bits (excluding the '0b' prefix)
bit_count = len(binary_representation) - 2

print(f"The number is: {number}")
print(f"Binary representation: {binary_representation}")
print(f"Number of bits: {bit_count}")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's a better word that you would recommend instead of chunk? @bxue-l2 maybe you have an idea since you initially wrote this comment I believe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

EDIT: based on bowen's comment below, I think I understand what you guys are saying now. Still think my comment is more accurate and the original one weird/wrong (a number cannot have more than 253 bits and less than 254 bits, it has a fixed number of bits, and could happen to have 254 bits).
Updated the comment order to reflect you guys' confusion, hopefully this helps: 6b78c52

Copy link
Collaborator

@pschork pschork Oct 18, 2024

Choose a reason for hiding this comment

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

(meaning the first 2 bits of each chunk must always be 00)

Pedantically, this is not true. Disperser will happily encode & disperse a blob that does not prefix chunks with 00 as long as all 32 byte chunks are in range. The 00 chunk prefix is just the easiest way to achieve lossless chunk encode/decode at the expense of 1 byte per chunk.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pschork maybe wording is getting everyone confused? By "chunk" in here we are talking about 32byte field elements. If those are not prefixed by 00, then they are surely a number > the max allowed FE, and so therefore wouldn't be in range, right?

Copy link
Collaborator

@pschork pschork Oct 19, 2024

Choose a reason for hiding this comment

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

When encoding, if your encoding chunk size is 32 bytes and the current chunk is within range, you don't need to pad it, but if given chunk exceeds the range then you need to truncate the chunk and pad it with zero to fit within range. The problem is when you do this, you won't be able to decode the encoded blob because you wont know which chunks were or were not padded (aka lossy encoding). For lossless encoding you set the encoding chunk size to 31 bytes and reserve the first 1 byte with \x00 so that, when decoding, you can identify the start of a chunk.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

please avoid using chunk here, it'll quickly get overloaded and confusing.

I think we don't need to mention it's prefixed with 00 (it's not precise anyway), we just need to mention each 32 bytes should fall in that value range so it's a valid field element.

Copy link
Contributor Author

@samlaf samlaf Oct 19, 2024

Choose a reason for hiding this comment

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

795868e
I removed mentions of chunk, and also removed the 00 part because it was confusing. (@pschork I just realized you interpreted my 00 as \x00, aka a full byte, but my message was using 00 meaning 2 bits)

api/clients/eigenda_client.go Outdated Show resolved Hide resolved
api/clients/eigenda_client.go Outdated Show resolved Hide resolved
api/clients/config.go Show resolved Hide resolved
bxue-l2
bxue-l2 previously approved these changes Oct 17, 2024
api/proto/disperser/disperser.proto Outdated Show resolved Hide resolved
api/clients/codecs/blob_codec.go Outdated Show resolved Hide resolved
api/clients/config.go Show resolved Hide resolved
// The total amount of time that the client will spend waiting for EigenDA to confirm a blob
// Timeout used when making dispersals to the EigenDA Disperser
// TODO: we should change this param as its name is quite confusing
ResponseTimeout time.Duration
Copy link
Contributor

Choose a reason for hiding this comment

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

agree, how about DispersalTimeout?

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'm fine with doing that, but as I mentioned in the other comment #780 (comment), do we have a policy for these breaking changes? Or are we fine with just doing it now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: we decided to do all the breaking changes in a future PR.

api/clients/disperser_client.go Show resolved Hide resolved
api/clients/disperser_client.go Show resolved Hide resolved
Comment on lines +30 to +31
// TODO: all of these should be private, to prevent users from using them directly,
// which breaks encapsulation and makes it hard for us to do refactors or changes
Copy link
Contributor

Choose a reason for hiding this comment

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

agree this should be private. From my experience, it is difficult to understand data semantics in each stage or encoding and decoding.

api/clients/eigenda_client.go Outdated Show resolved Hide resolved
api/clients/eigenda_client.go Outdated Show resolved Hide resolved
api/clients/eigenda_client.go Outdated Show resolved Hide resolved
@samlaf samlaf dismissed bxue-l2’s stale review October 17, 2024 21:27

dismissing because there's a lot of good comments that I need to address before we merge this.

@@ -78,12 +78,12 @@ message AuthenticationData {

message DisperseBlobRequest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

api/clients/eigenda_client.go Outdated Show resolved Hide resolved
@samlaf samlaf force-pushed the style--improve-api-clients-comments branch from 795868e to 5b39fe6 Compare October 19, 2024 17:47
Copy link
Contributor

@bxue-l2 bxue-l2 left a comment

Choose a reason for hiding this comment

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

lg

@samlaf samlaf merged commit 78e4fc6 into master Oct 19, 2024
10 checks passed
@samlaf samlaf deleted the style--improve-api-clients-comments branch October 19, 2024 18:26
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