-
Notifications
You must be signed in to change notification settings - Fork 120
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 split array serialization functions for Transaction::V5 #2017
Add split array serialization functions for Transaction::V5 #2017
Conversation
In Transaction::V5, Zcash splits some types into multiple arrays, with a single prefix count before the first array. Add utility functions for serializing and deserializing the subsequent arrays, with a paramater for the original array's length.
And fix the test module structure so it is consistent with the rest of zebra-chain.
// | ||
// we specifically want to serialize `Vec`s here, rather than generic slices | ||
#[allow(clippy::ptr_arg)] | ||
pub fn zcash_serialize_external_count<W: io::Write, T: ZcashSerialize>( |
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.
On its surface, this implementation seems agnostic to anything about external_count
s, it seems to just invoke zcash_serialize
on each item in the vec where supported. Maybe zcash_serialize_vec
?
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 function is specifically for arrays that don't store a count before the data.
Almost all arrays in Zcash have a count before the data, except for a 4 split arrays in Transaction::V5, and some of the filter network messages.
// | ||
// we specifically want to serialize `Vec`s here, rather than generic slices | ||
#[allow(clippy::ptr_arg)] | ||
pub fn zcash_serialize_bytes_external_count<W: io::Write>( |
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.
Related to the above comment, this seems generic enough to be zcash_serialize_vec_bytes
or something agnostic of external_count
?
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 isn't generic, it is designed for a very specific and rare use case.
#2017 (comment)
…nullifier utility functions (#1996) * add sapling shielded data to transaction V5 * implement nullifiers * test v5 in shielded_data_roundtrip * Explicitly design serialization for Transaction V5 Implement serialization for V4 and V5 spends and outputs, to make sure that the design works. * Test serialization for v5 spends and outputs Also add a few missing v4 tests. * Delete a disabled proptest * Make v5 transactions a top-level heading And add a missing serialized type. * Fix a comment typo * v5 transaction RFC: split array serialization Based on #2017 * RFC: explicitly describe serialized field order And link to the spec * RFC: add the shared anchor serialization rule test Co-authored-by: teor <teor@riseup.net>
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.
We've got an open PR that depends on this PR, and we want to open 2 more, so we're just going to merge it.
Motivation
Transaction::V5
splits some data into multiple arrays, with a single count before the first array.But Zebra expects every array to have a compactsize prefix when serializing and deserializing.
Solution
Refactor out serialization functions for typed arrays with external lengths:
Also refactor out deserialization for raw byte arrays with external lengths:
(
Transaction::V5
doesn't use raw byte arrays.)Use some of the new functions in zebra-network.
Move some tests into a consistent module structure.
The code in this pull request:
Review
@oxarbitrage can review before he uses these functions to implement #1829.
Related Issues
#1996 redesign transaction serialization
#1829 parse sapling data in transaction v5
Follow Up Work
Use these functions to handle
V5
transactions