-
Notifications
You must be signed in to change notification settings - Fork 107
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 ZIP-0244 TxId Digest support #2129
Conversation
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 looks really good!
I made a few suggestions, but overall the structure looks like what we'd want here. (And I'm glad it works.)
Let's also add some documentation comments:
- Add a short summary to the top of each module
- Explain the purpose of every new object
- Explain what each method does, and each method argument
Doc comments don't need to be long, 1-2 sentences is enough. Check out some of the other modules for examples.
And let's add some more tests:
- deserialization and serialization round-trip for
zcash_primitives::transaction::Transaction::read
using fake v5 transactions- this test helps us make sure our serialization works the same as
librustzcash
- for an example, see
zebra/zebra-chain/src/transaction/tests/vectors.rs
Lines 159 to 165 in 29893f2
/// Do a round-trip test on fake v5 transactions created from v4 transactions /// in the block test vectors. /// /// Covers Sapling only, Transparent only, and Sapling/Transparent v5 /// transactions. #[test] fn fake_v5_round_trip() {
- this test helps us make sure our serialization works the same as
- deserialization and serialization round-trip for
zcash_primitives::transaction::Transaction::read
using an empty v5 transaction- we might want to turn the empty transaction struct into a
lazy_static!
constant, then use it in both tests - for an example, see
zebra/zebra-chain/src/transaction/tests/vectors.rs
Lines 97 to 102 in 29893f2
/// An empty transaction v5, with no Orchard, Sapling, or Transparent data /// /// empty transaction are invalid, but Zebra only checks this rule in /// zebra_consensus::transaction::Verifier #[test] fn empty_v5_round_trip() {
- we might want to turn the empty transaction struct into a
zcash_primitives
might reject empty transactions - if that's the case, let's skip that test.
@teor2345 I believe I've made all the requested changes. The new tests share a lot of code with the older ones, though. Do you think it warrants some refactoring? I'm also considering moving the reserialization code (get branch ID from tx, convert to librustzcash enum, call librustzcash |
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 looks good so far, let's take it out of draft once you've done the refactoring.
Finished refactoring and took it out of draft. |
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.
Looks good, I just had one suggestion to future-proof the code.
Looking forward to the librustzcash
update for transaction IDs, so we can test this code properly.
Solved conflicts and updated test to not skip Orchard transactions now that we parse them. The only thing left is the test to pass. It's possibly a librustzcash issue which we decided to not investigate yet since their implementation is still under review. |
cbe6617
to
b7bda55
Compare
This is finally ready 🎉 I had to implement However I'm not sure if my approach is correct, since These changes are in a seprate commit (b7bda55) to make reviewing them easier |
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.
I made some specific suggestions about proptests and test vectors. But they are all optional.
I'd like @dconnolly or @jvff to do the final review here. Whoever is available after this PR is revised.
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.
Looks good! I did add some suggestions and nit-picks 😅
Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com> Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>
Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.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.
Another round of fixes, thanks for the great suggestions!
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.
Looks good! Just one optional suggestion.
Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.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.
Love it! I resolved a lot of conversations too
Motivation
ZIP-0244 specifies a new Transaction ID Digest which the hash of a "tree" of hashes from specific fields of the transaction, rather than the hash of the entire transaction itself.
Solution
This uses librustzcash to compute the digest. In order to call it, the transaction is re-serialized and deserialized with librustzcash.
While the implementation is done, it still has this pending issues:
The code in this pull request has:
Review
@teor2345 already reviewed the draft so I'm assuming they'll do the final review
Related Issues
Closes #2050
Follow Up Work
ZIP-0244 also specifies a new sighash and a new authorizing data digest, which need to be implemented too.