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

Further test new transaction consensus rules #2246

Conversation

jvff
Copy link
Contributor

@jvff jvff commented Jun 3, 2021

Motivation

Some recent PRs (#2229 and #2236) added some new V5 transaction consensus rules. However, they weren't thoroughly tested.

Solution

This PR adds three new test vectors:

  • Test check::has_inputs_and_outputs with a transaction that has Orchard actions
  • Test check::coinbase_tx_no_prevout_joinsplit_spend with:
    • a transaction that has Orchard shielded data with enableSpendsOrchard flag set
    • a transaction that has Orchard shielded data with enableSpendsOrchard flag not set

For the implementation of these tests, a helper function was implemented (insert_dummy_orchard_shielded_data) that changes a V5 transaction to include a dummy instance of orchard::ShieldedData. A mutable reference to the shielded data is returned in case the test wants to customize the data.

The PR also includes an at_least_one! helper macro, that is usable for tests.

The code in this pull request has:

  • Documentation Comments
  • Unit Tests and Property Tests

Open questions

  • Should the PR include some extra tests for the V4 rules applied to V5 transactions?
  • Should there be tests for V4 transactions?
  • What would be useful to have as a proptest? (Should some of these test vectors become proptests?)

Review

Anyone can review this low priority PR.

Related Issues

Part of #1980

Follow Up Work

@zfnd-bot zfnd-bot bot assigned jvff Jun 3, 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.

Should the PR include some extra tests for the V4 rules applied to V5 transactions?
Should there be tests for V4 transactions?
What would be useful to have as a proptest? (Should some of these test vectors become proptests?)

This seems like enough tests for now - I'd rather focus on fixes to the network stack, and implementing more NU5 consensus rules.

jvff and others added 6 commits June 4, 2021 14:39
Similar to the `vec!` macro, but doesn't allow creating an empty list.
Create a dummy transaction with no inputs and no outputs, and add a
dummy Orchard action to it. The `check::has_inputs_and_outputs`
should succeed, because the consensus rule considers having Orchard
actions as having inputs and/or outputs.
Move the code to create a fake Orchard shielded data instance to a
helper function in `zebra_chain::transaction::arbitrary`, so that other
tests can also use it.
A V5 coinbase transaction that has Orchard shielded data MUST NOT have
the enable spends flag set.
A coinbase transaction with Orchard shielded data and without the enable
spends flag set should be valid.
@jvff jvff force-pushed the further-test-new-transaction-consensus-rules branch from 6e87237 to 665c84e Compare June 4, 2021 17:12
Copy link
Contributor Author

@jvff jvff left a comment

Choose a reason for hiding this comment

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

Updated.

@jvff jvff marked this pull request as ready for review June 4, 2021 17:18
@teor2345 teor2345 linked an issue Jun 6, 2021 that may be closed by this pull request
14 tasks
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, I'll just add a comment about the security implications of the at_least_one macro, then merge.

zebra-chain/src/serialization/constraint.rs Outdated Show resolved Hide resolved
@teor2345 teor2345 enabled auto-merge (squash) June 7, 2021 00:04
@teor2345 teor2345 merged commit 2e03188 into ZcashFoundation:main Jun 7, 2021
@jvff jvff deleted the further-test-new-transaction-consensus-rules branch June 10, 2021 13:23
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.

Implement transaction::check for Transaction Version 5 and Orchard
2 participants