-
Notifications
You must be signed in to change notification settings - Fork 67
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
Add "rust proof format" Deserialization #175
Conversation
5056015
to
61bb52a
Compare
fc7a2bb
to
3633d99
Compare
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[:] | ||
} |
There was a problem hiding this comment.
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.
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) | |
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* 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>
* 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>
No description provided.