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 split array serialization functions for Transaction::V5 #2017

Merged
merged 5 commits into from
Apr 15, 2021

Conversation

teor2345
Copy link
Contributor

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:

  • zcash_deserialize_external_count
  • zcash_serialize_external_count

Also refactor out deserialization for raw byte arrays with external lengths:

  • zcash_deserialize_bytes_external_count
  • zcash_serialize_bytes_external_count

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

  • uses the new functions in filter deserialization
  • re-uses existing unit tests and property tests (the new code is called by existing tested code)
  • has documentation comments

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

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.
@teor2345 teor2345 added A-rust Area: Updates to Rust code C-enhancement Category: This is an improvement NU-5 Network Upgrade: NU5 specific tasks P-Medium labels Apr 15, 2021
@teor2345 teor2345 added this to the 2021 Sprint 7 milestone Apr 15, 2021
@teor2345 teor2345 requested a review from oxarbitrage April 15, 2021 10:56
@teor2345 teor2345 self-assigned this Apr 15, 2021
teor2345 added a commit to oxarbitrage/zebra that referenced this pull request Apr 15, 2021
//
// 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>(
Copy link
Contributor

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_counts, it seems to just invoke zcash_serialize on each item in the vec where supported. Maybe zcash_serialize_vec ?

Copy link
Contributor Author

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>(
Copy link
Contributor

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?

Copy link
Contributor Author

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)

teor2345 added a commit that referenced this pull request Apr 15, 2021
…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>
Copy link
Contributor Author

@teor2345 teor2345 left a 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.

@teor2345 teor2345 merged commit 0def12f into ZcashFoundation:main Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rust Area: Updates to Rust code C-enhancement Category: This is an improvement NU-5 Network Upgrade: NU5 specific tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants