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 V5 transparent and sapling to transaction::check, add missing coinbase PrevOut check #2070

Merged
merged 10 commits into from
Apr 28, 2021

Conversation

oxarbitrage
Copy link
Contributor

@oxarbitrage oxarbitrage commented Apr 26, 2021

Motivation

We need some tests in the consensus side for the new sapling data in V5 transactions.

Solution

Add a test that converts the transactions from all test blocks we have(real past blocks from testnet and mainnet) into V5 transactions and validate them.

Also this PR moves the utility functions needed for the transaction conversion so they can be used by zebra-chain and zebra-consensus crates.

Update the "check" functions for transaction v5, and simplify.

Add the missing "no transparent inputs with prevouts" coinbase check.

Simplify a bunch of the transaction checks, so the consensus rules are easier to review.

The code in this pull request has:

  • Documentation Comments
  • Unit Tests

Review

Related Issues

Implement Transparent and Sapling validation for transaction v5 #1981 - "check" part
Hard-coded sapling-only transaction v5 test vectors #2047

Follow Up Work

Implement Transparent and Sapling validation for transaction v5 #1981 - transaction verifier part

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 push a quick commit that tweaks the dependencies and removes some duplicate code.

We only need itertools when the `proptest-impl` feature is enabled.
@teor2345 teor2345 changed the title Validate sapling data of V5 transactions Validate transparent and sapling data of V5 transactions Apr 27, 2021
@teor2345
Copy link
Contributor

I pushed a fix that makes the itertools dependency optional, and enables it when proptest-impl is enabled.

@teor2345 teor2345 changed the title Validate transparent and sapling data of V5 transactions Validate transparent and sapling in V5 transactions, add missing coinbase PrevOut check Apr 27, 2021
…inputs

This is a bugfix on V4 transaction validation. The PrevOut consensus
rule was not explicitly stated in the Zcash spec until April 2021.
(But it was implied by Bitcoin, and partially implemented by Zebra.)

Also do the shielded sapling input check for V5 transactions.
Also make the variable names match the spec.
Move counts or iterators into `Transaction` methods, so we can remove
duplicate code, and make the consensus rule logic clearer.
@teor2345 teor2345 changed the title Validate transparent and sapling in V5 transactions, add missing coinbase PrevOut check Validate transparent and sapling counts in V5 transactions, add missing coinbase PrevOut check Apr 27, 2021
@teor2345 teor2345 changed the title Validate transparent and sapling counts in V5 transactions, add missing coinbase PrevOut check Add V5 transparent and sapling to transaction::check, add missing coinbase PrevOut check Apr 27, 2021
@teor2345
Copy link
Contributor

I added PRs in your repository with spec updates and refactors:

Here's what was missing from the PR:

  • quote the latest consensus rules for each check, and
  • add Orchard TODOs.

While I was changing that code, I also:

  • implemented the missing "no PrevOuts" coinbase check, added a few days ago in zcash/zips@10710d9, and
  • refactored the code to make the checks simpler.

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.

teor2345 and others added 4 commits April 27, 2021 12:47
- Quote from the spec
- Explain why the function is redunant for v5
- Rename the function so it's clear that it is sapling-specific
Update sapling_balances_match for Transaction v5
Simplify transaction checks, add missing coinbase PrevOut check
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.

Looks good, now we just need to do the rest of #1981.

But this PR is a good size to merge.

@teor2345 teor2345 merged commit 75d29ac into ZcashFoundation:main Apr 28, 2021
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.

2 participants