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

Refactor encoder (2 of N) #269

Merged
merged 27 commits into from
Feb 23, 2024
Merged

Conversation

mooselumph
Copy link
Collaborator

@mooselumph mooselumph commented Feb 22, 2024

Why are these changes needed?

Eliminates duplication in encoding types (removes core/encoding)

https://docs.google.com/document/d/1Z-XWWBxi_vCREpV1kbZj_PCb3ToM9_f0Ja3GMR0rNdU/edit

Checks

  • I've made sure the lint is passing in this PR.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, in that case, please comment that they are not relevant.
  • Testing Strategy
    • Unit tests
    • Integration tests
    • This PR is not tested :(

@mooselumph mooselumph changed the title Refactor encoder 3 Refactor encoder (2 of N) Feb 22, 2024
@mooselumph mooselumph marked this pull request as ready for review February 22, 2024 19:54
Copy link
Contributor

@jianoaix jianoaix left a comment

Choose a reason for hiding this comment

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

lg

// Encode takes in a blob and returns the commitments and encoded chunks. The encoding will satisfy the property that
// for any number M such that M*params.ChunkLength > BlobCommitments.Length, then any set of M chunks will be sufficient to
// reconstruct the blob.
EncodeAndProve(data []byte, params EncodingParams) (BlobCommitments, []*Frame, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think having an Encoder type (interface), and then Prover is a subtype of Encoder (is-a relationship, which is struct embedding in go)? The "XAndY()" method looks like it could be decomposed in general.

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer both Prover and RSEncoder at the same level and under a new object called "Framer". Regardless of the name, the reason behind is both proving and encoding are separate, and totally parallelizable. For the time being, I think it is fine for now

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds good to me as well. Then to be consistent, Decoder could also be a parallel concept and used under Framer?

Copy link
Contributor

Choose a reason for hiding this comment

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

RSEncoder and Decoder are at the same level. "Framer" choose to include RSEncoder and Prover. The way that the current PR handles it is right to me. rs and kzgrs are at the same lelvel.


// }

func roundUpDivide[T constraints.Integer](a, b T) T {
Copy link
Contributor

Choose a reason for hiding this comment

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

I saw multiple round-up division around the codebase, it can probably be moved to common and shared by all (sometime separately).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. I'll try to get to this.

@@ -156,6 +158,33 @@ func genRhsG1(samples []Sample, randomsFr []bls.Fr, m int, params rs.EncodingPar
return &rhsG1, nil
}

// TODO(mooselumph): Cleanup this function
Copy link
Contributor

Choose a reason for hiding this comment

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

can you explain here, I can do it


func encode(obj any) ([]byte, error) {
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it have to be gob, does binary work? I can make a note for improvement in the future

@@ -1,5 +1,5 @@
definitions:
core.BlobCommitments:
encoding.BlobCommitments:
properties:
commitment:
$ref: '#/definitions/core.Commitment'
Copy link
Contributor

Choose a reason for hiding this comment

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

not familiar with swagger, but should the ref 3 lines below be changed too?

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

Choose a reason for hiding this comment

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

It can be generated after fix the code:

BlobCommitment *core.BlobCommitments `json:"blob_commitment"`

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jianoaix, does anything need to be fixed here before this is merged?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good

Copy link
Contributor

Choose a reason for hiding this comment

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

The core.Commitment is obsolete but it's since a previous PR. So sounds fine to fix that separately to get this merged now to avoid conflicts (give its size).

@@ -117,9 +118,9 @@ func (c client) GetChunks(
return
}

chunks := make([]*core.Chunk, len(reply.GetChunks()))
chunks := make([]*encoding.Frame, len(reply.GetChunks()))
Copy link
Contributor

Choose a reason for hiding this comment

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

since there are so many places where chunks are assigned to frames. Does it make sense to use encoding.Chunk? My only concerns against it is that chunk usually means data only. However, the data here contain both data and proof

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It might be a future cleanup action to make the variable names consistent.

@@ -1,5 +1,5 @@
definitions:
core.BlobCommitments:
encoding.BlobCommitments:
properties:
commitment:
$ref: '#/definitions/core.Commitment'
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good

@mooselumph mooselumph merged commit 3ed5953 into Layr-Labs:master Feb 23, 2024
4 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.

3 participants