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

Validate transparent inputs and outputs in V5 transactions #2302

Conversation

jvff
Copy link
Contributor

@jvff jvff commented Jun 15, 2021

Motivation

As part of NU5, there is a new transaction format and consensus rules (version 5). Zebra already had initial support for the new transaction, but the consensus rules aren't fully implemented. This includes another step in implementing the validation of those rules, by checking the transparent transfers in the V5 transaction.

This is the second PR that's part of #1981.

Specifications

The new transaction encoding and consensus rules are detailed in the specification.

Designs

Solution

The transparent validation code in transaction::Verifier::verify_v4_transaction method was moved to a new transaction::Verifier::verify_transparent_inputs_and_outputs method. This new method now returns a FuturesUnordered of futures that send validation requests to the script::Verifier and wait for their response.

The new method is now also called by transaction::Verifier::verify_v5_transaction. The verify_v5_transaction also calls the check::has_inputs_and_outputs helper.

Both V4 and V5 transaction verification rely on asynchronous checks, so a helper method was created to share the code that awaits for the checks to complete and that trace their completion.

Review

@teor2345

Reviewer Checklist

  • Code implements Specs and Designs
  • Tests for Expected Behaviour
  • Tests for Errors

Follow Up Work

There's still some work left for #1981 to be complete, which is validating the shielded parts of the transaction.

@jvff jvff requested a review from teor2345 June 15, 2021 02:27
@zfnd-bot zfnd-bot bot assigned jvff Jun 15, 2021
Copy link
Contributor

@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.

This looks good so far, but I think you'll find futures::stream::FuturesUnordered much easier to work with than CallAll.

zebra-consensus/src/transaction.rs Outdated Show resolved Hide resolved
zebra-consensus/src/transaction.rs Outdated Show resolved Hide resolved
@jvff jvff force-pushed the validate-sapling-and-transparent-v5-transactions branch from 168ff91 to 8d0194a Compare June 15, 2021 13:20
Copy link
Contributor

@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.

This is looking good, I just have to check the code movement now.

@jvff jvff changed the title Validate sapling shielded data and transparent inputs and outputs in V5 transactions Validate transparent inputs and outputs in V5 transactions Jun 15, 2021
@jvff jvff force-pushed the validate-sapling-and-transparent-v5-transactions branch from 20a8508 to ff76c70 Compare June 15, 2021 23:02
@jvff jvff marked this pull request as ready for review June 15, 2021 23:08
@jvff jvff force-pushed the validate-sapling-and-transparent-v5-transactions branch from ff76c70 to 0b60f21 Compare June 15, 2021 23:13
zebra-consensus/src/transaction.rs Outdated Show resolved Hide resolved
zebra-consensus/src/transaction/tests.rs Show resolved Hide resolved
zebra-consensus/src/transaction/tests.rs Outdated Show resolved Hide resolved
@jvff jvff requested a review from teor2345 June 15, 2021 23:14
@jvff jvff force-pushed the validate-sapling-and-transparent-v5-transactions branch from 0b60f21 to 09fcfc9 Compare June 16, 2021 03:35
Copy link
Contributor

@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.

I'd like to see some more doc comments in this PR, and the code that were added in the last PR.

A short, one-line comment is enough for most functions, types, and fields.

If the function is particularly complex, or has more than a few arguments, explain what each one does.

@jvff jvff force-pushed the validate-sapling-and-transparent-v5-transactions branch from 1e57053 to ad4cc1f Compare June 16, 2021 20:22
@dconnolly dconnolly added A-rust Area: Updates to Rust code A-consensus Area: Consensus rule updates NU-5 Network Upgrade: NU5 specific tasks labels Jun 17, 2021
teor2345
teor2345 previously approved these changes Jun 18, 2021
Copy link
Contributor

@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.

These all look good.

I'll leave it to @jvff to decide if he wants to fix any of the minor issues in this PR, or in the next one.

@jvff jvff force-pushed the validate-sapling-and-transparent-v5-transactions branch from 3111ec2 to 0b08aa0 Compare June 19, 2021 02:37
@jvff jvff requested a review from teor2345 June 21, 2021 12:39
@jvff jvff requested a review from dconnolly June 21, 2021 12:39
Copy link
Contributor

@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.

There's just one confusing function doc comment here, otherwise I'm good to merge.

Feel free to merge if @dconnolly approves and you've fixed the comment.

jvff and others added 17 commits June 22, 2021 02:11
Document methods to describe what they do and why.
Make it simpler to write the `FuturesUnordered` type with boxed futures.
This will also end up being used more when refactoring to return the
checks so that the `call` method can wait on them.
Refactors the verification of the transparent inputs and outputs into a
separate method.
Instead of pushing the verifications into a stream of unordered futures,
use the `ServiceExt::call_all` method to build an equivalent stream
after building a stream of requests.
Make it more consistent with the rest of the code, and make sure that
the `len()` method is available to use for tracing.

Co-authored-by: teor <teor@riseup.net>
Allow the code snipped to be reused by other transaction
version-specific check methods.
Use the script verifier to check the transparent inputs in a V5
transaction.
Check if a transaction has inputs and outputs, independently of the
transaction version.
Refactor to move the repeated code into the `call` method. Now the
validation methods return the set of asynchronous checks to wait for.
Creates a fake source UTXO, and then the input and output that represent
spending that UTXO. The initial UTXO can be configured to have a script
that either accepts or rejects any spend attempt.
Create a fake V4 transaction that includes a fake transparent transfer
of funds. The transfer uses a script to allow any UTXO to spend it.
Create a fake transparent transfer where the source UTXO has a script
that rejects spending. The script verifier should not accept this
transaction.
Create a mock V5 transaction that includes a transparent transfer of
funds. The transaction should be accepted by the verifier.
Create a fake transparent transfer where the source UTXO has a script
that rejects spending. The script verifier should not accept this
transaction.
Because this set of changes implement transparent validation.

Co-authored-by: teor <teor@riseup.net>
Simplify it so that it won't become updated when ZcashFoundation#1683 is fixed.

Co-authored-by: teor <teor@riseup.net>
Make it clearer, to avoid mixing up `Network` and `NetworkUpgrade`
types.

Co-authored-by: teor <teor@riseup.net>
@jvff jvff force-pushed the validate-sapling-and-transparent-v5-transactions branch from e162d90 to d0ea656 Compare June 22, 2021 02:11
@jvff jvff requested a review from teor2345 June 22, 2021 02:12
Copy link
Contributor

@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.

I've resolved all the fixed comments from all reviewers.

I also resolved the comments we said we might do later.

@teor2345 teor2345 merged commit 8ed50e5 into ZcashFoundation:main Jun 23, 2021
@jvff jvff deleted the validate-sapling-and-transparent-v5-transactions branch November 24, 2021 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-consensus Area: Consensus rule updates A-rust Area: Updates to Rust code NU-5 Network Upgrade: NU5 specific tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants