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

Add "rust proof format" Deserialization #175

Conversation

jwasinger
Copy link
Collaborator

No description provided.

@jwasinger jwasinger force-pushed the serialize-rust-proof-format-deserialize branch from 5056015 to 61bb52a Compare January 14, 2022 06:39
@jwasinger jwasinger requested a review from gballet January 14, 2022 06:40
@jwasinger jwasinger marked this pull request as ready for review January 14, 2022 06:40
@jwasinger jwasinger force-pushed the serialize-rust-proof-format-deserialize branch from fc7a2bb to 3633d99 Compare January 14, 2022 06:47
Comment on lines +150 to +158
poaStems = make([][]byte, numPoaStems)
for i := 0; i < int(numPoaStems); i++ {
var poaStem [31]byte
if err := binary.Read(reader, binary.LittleEndian, &poaStem); err != nil {
return nil, err
}

poaStems[i] = poaStem[:]
}
Copy link
Member

Choose a reason for hiding this comment

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

This allocate a buffer and copies the data into it, when you already have direct access to the source data.

Suggested change
poaStems = make([][]byte, numPoaStems)
for i := 0; i < int(numPoaStems); i++ {
var poaStem [31]byte
if err := binary.Read(reader, binary.LittleEndian, &poaStem); err != nil {
return nil, err
}
poaStems[i] = poaStem[:]
}
// verify that there is enough data to read
if numPoaStems * 31 + 4 <= len(proofSerialized) {
return nil, errors.New("truncated proof")
}
poaStems = make([][]byte, numPoaStems)
for i := 0; i < int(numPoaStems); i++ {
poaStems[i] = poaStem[4+31*i:4+31*i+31]
reader.Seek(31, io.SeekStart)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay. If we go with this option, then the caller must make sure that the source data is not used after they call DeserializeProof(sourceData). It has potential to create some annoying bugs down the line.

But I'm fine to make it this way if you think the reduction in allocations is worth it here.

Copy link
Member

Choose a reason for hiding this comment

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

It's only a problem if the buffer is reused to deserialize another proof afterwards, it's unlikely to happen but I guess you are right. I made a note of this in issue #176 and we will revisit it when the go-ethereum part of the code is more stable, and we know that this won't happen.

proof_ipa.go Show resolved Hide resolved
proof_test.go Outdated Show resolved Hide resolved
jwasinger and others added 2 commits January 16, 2022 18:47
Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
Copy link
Member

@gballet gballet left a comment

Choose a reason for hiding this comment

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

LGTM

@gballet gballet merged commit 612b312 into ethereum:serialize-rust-proof-format Jan 17, 2022
gballet added a commit that referenced this pull request Jan 17, 2022
* rust-verkle-style proof serialization

* coverage: remove an error check that can not be tested independently from another error check

* Add "rust proof format" Deserialization (#175)

* proof deserialization

* appease the almighty linter

* Update proof_test.go

Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>

* fix linter issues

Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>

* improve deserialization error coverage

Co-authored-by: jwasinger <j-wasinger@hotmail.com>
gballet added a commit that referenced this pull request Jan 18, 2022
* change proof to the format of rust-verkle

* merge the depth and presence status into a single byte (#168)

* when encountering another stem in GetCommitmentsAlongPath, return it (#169)

* when encountering another stem in GetCommitmentsAlongPath, return it

* add a unit test for coverage

* goimport

* rust-verkle-style proof serialization (#173)

* rust-verkle-style proof serialization

* coverage: remove an error check that can not be tested independently from another error check

* Add "rust proof format" Deserialization (#175)

* proof deserialization

* appease the almighty linter

* Update proof_test.go

Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>

* fix linter issues

Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>

* improve deserialization error coverage

Co-authored-by: jwasinger <j-wasinger@hotmail.com>

Co-authored-by: jwasinger <j-wasinger@hotmail.com>
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