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

Update Transaction definition. #105

Merged
merged 16 commits into from
Dec 5, 2019
Merged

Update Transaction definition. #105

merged 16 commits into from
Dec 5, 2019

Conversation

hdevalence
Copy link
Contributor

@hdevalence hdevalence commented Nov 18, 2019

Progress towards #13.

This creates a Transaction enum over all transaction versions, with the goal of making (structurally) invalid Zcash transactions unrepresentable. Of course, it's still possible to make one which is semantically invalid, with e.g., invalid proofs, or contextually invalid, e.g., double-spending a note, but it should not be possible to construct a Transaction which does not have a valid encoding (e.g., a version 1 transaction with Sapling proofs in it, or some other structurally invalid combination. In addition to being a better design, this is also important for us, as we want to be able to construct transaction hashes by an infallible From impl.

To do this, the Transaction struct has one enum variant for each transaction encoding version, and the data is modeled (at times slightly differently from the description in the spec) so that each variant has only the appropriate fields.

Previously this comment said it closes #13; it doesn't, and there is a bunch of work left to do, but that work could be split out into separate, further tickets:

  1. Many of the types in the structures that make up a Transaction need to be refined to assign them semantic meaning. The complete list can be found by running rg 'XXX refine' -A 2 in zebra/zebra-chain/src. Fleshing out many of these types will require further work – for instance, the Zcash-flavored Ed25519 pubkey in the JoinSplit data requires Zcash-flavored Ed25519 #109. (This item is now Finish refining all primitive types brought in by Transaction data. #123).

  2. The actual transaction encoding and decoding is not implemented, although there is a stub module in which it will live (transaction/serialization.rs). Implementing ZcashSerialize and ZcashDeserialize is a further chunk of work, but because all of the unrefined types are in place, it can be done independently of (1) by, e.g., parsing something as a [u8; 32] instead of some refined PublicKey type. (This item is now Implement transaction serialization. #124).

  3. The as-yet-unimplemented encoding and decoding is not tested. In addition to the transaction test vectors, we could define a proptest strategy to generate random transaction data to check that the encodings round-trip. (This item is now Implement transaction serialization. #124).

@dconnolly
Copy link
Contributor

The build job is having a hard time
image

dconnolly and others added 8 commits November 27, 2019 13:22
This could alternately use bytes::Bytes to save some allocations
but I don't think this is important to get perfectly now.  In the future, we
will want to have all of the script handling code in the zebra-script crate,
but we will need to have a container type for an encoded script in zebra-chain,
because otherwise zebra-chain would depend on zebra-script and not the other
way around.
These are only *transparent* inputs and outputs, so by putting Transparent in
the name (instead of Transaction) it's more clear that a transaction's inputs
or outputs can also be shielded.
This attempts to map the versioning and field presence rules into an ADT, so
that structurally invalid transactions (e.g., a BCTV14 proof in a Sapling
transaction) are unrepresentable.
Co-Authored-By: Daira Hopwood <daira@jacaranda.org>
This has a lot of duplication and should really use generics to abstract over
Sprout-on-BCTV14 or Sprout-on-Groth16.
This also adds a trait to abstract over them.
@hdevalence hdevalence marked this pull request as ready for review November 28, 2019 00:43
@hdevalence
Copy link
Contributor Author

Rewrote the description above.

@hdevalence hdevalence mentioned this pull request Dec 5, 2019
Copy link
Contributor

@dconnolly dconnolly left a comment

Choose a reason for hiding this comment

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

LGTM!

@dconnolly dconnolly merged commit c013895 into main Dec 5, 2019
@dconnolly dconnolly deleted the tx branch December 5, 2019 20:57
@dconnolly dconnolly mentioned this pull request Mar 5, 2021
53 tasks
skyl added a commit to skyl/zebra that referenced this pull request Sep 25, 2024
Co-authored-by: Skylar Saveland <skylar.saveland@gmail.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.

Update Transaction type and message to support the Zcash changes from Bitcoin
3 participants