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

[1/N] Chunk encoding optimization: Support encoding format with gnark #617

Merged
merged 5 commits into from
Jun 25, 2024

Conversation

jianoaix
Copy link
Contributor

@jianoaix jianoaix commented Jun 24, 2024

Why are these changes needed?

There are inefficiency in chunk encoding, which causes more than data to transmit over network and store to db than necessary.

This PR adds the encoding with gnark. The followup PR will integrate it (compatibly).

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 :(

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.

lgtm

@@ -22,6 +23,41 @@ func (c *Frame) Deserialize(data []byte) (*Frame, error) {
return c, err
}

func (c *Frame) SerializeGnark() ([]byte, error) {
coded := make([]byte, 0, 32*(1+len(c.Coeffs)))
Copy link
Contributor

Choose a reason for hiding this comment

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

can replace 32 with constants.go inside encoding/*

Copy link
Contributor

Choose a reason for hiding this comment

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

for point size you can use SizeOfG1AffineUncompressed, see https://pkg.go.dev/github.com/consensys/gnark-crypto/ecc/bn254#G1Affine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -22,6 +23,41 @@ func (c *Frame) Deserialize(data []byte) (*Frame, error) {
return c, err
}

func (c *Frame) SerializeGnark() ([]byte, error) {
coded := make([]byte, 0, bn254.SizeOfG1AffineCompressed+BYTES_PER_SYMBOL*len(c.Coeffs))
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to consider to use SizeOfG1AffineUncompressed? Marshal uses uncompressed format. https://github.com/consensys/gnark-crypto/blob/v0.6.1/ecc/bn254/marshal.go#L607

In current EigenDA, we use uncompressed format with 64 bytes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could settle on a 32 bytes point for this new encoding format

@jianoaix jianoaix merged commit eb422ff into Layr-Labs:master Jun 25, 2024
6 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.

2 participants