Zebra/zebra-consensus/src
Janito Vaqueiro Ferreira Filho 8ed50e578d
Validate transparent inputs and outputs in V5 transactions (#2302)
* Add missing documentation

Document methods to describe what they do and why.

* Create an `AsyncChecks` type alias

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.

* Create `verify_transparent_inputs_and_outputs`

Refactors the verification of the transparent inputs and outputs into a
separate method.

* Refactor transparent checks to use `call_all`

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.

* Replace `CallAll` with `FuturesUnordered`

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>

* Refactor to move wait for checks into a new method

Allow the code snipped to be reused by other transaction
version-specific check methods.

* Verify transparent inputs in V5 transactions

Use the script verifier to check the transparent inputs in a V5
transaction.

* Check `has_inputs_and_outputs` for all versions

Check if a transaction has inputs and outputs, independently of the
transaction version.

* Wait for checks in `call` method

Refactor to move the repeated code into the `call` method. Now the
validation methods return the set of asynchronous checks to wait for.

* Add helper function to mock transparent transfers

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.

* Test if transparent V4 transaction is accepted

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.

* Test transaction V4 rejection based on script

Create a fake transparent transfer where the source UTXO has a script
that rejects spending. The script verifier should not accept this
transaction.

* Test if transparent V5 transaction is accepted

Create a mock V5 transaction that includes a transparent transfer of
funds. The transaction should be accepted by the verifier.

* Test transaction V5 rejection based on script

Create a fake transparent transfer where the source UTXO has a script
that rejects spending. The script verifier should not accept this
transaction.

* Update `Request::upgrade` getter documentation

Simplify it so that it won't become updated when #1683 is fixed.

Co-authored-by: teor <teor@riseup.net>
2021-06-23 11:54:00 +10:00
..
block Move network_upgrade check into zebra-chain (#2354) 2021-06-22 12:06:52 +10:00
chain Standardise clippy lints and require docs (#2238) 2021-06-04 08:48:40 +10:00
checkpoint Add and use a function for mandatory checkpoint (#2314) 2021-06-18 10:05:28 +10:00
parameters Replace smart quotes with ascii quotes 2021-03-15 03:18:10 -04:00
primitives Rename shielded_data to sapling_shielded_data as needed (#2072) 2021-04-27 10:37:53 -03:00
transaction Validate transparent inputs and outputs in V5 transactions (#2302) 2021-06-23 11:54:00 +10:00
block.rs Validate nConsensusBranchId (#2100) 2021-05-10 01:31:45 +00:00
chain.rs Document required request timeouts due to data dependencies (#2337) 2021-06-18 14:43:05 -03:00
checkpoint.rs Clippy: remove needless borrows 2021-06-07 18:33:58 -04:00
config.rs Make sure the mandatory checkpoint includes Canopy activation (#2235) 2021-06-03 10:24:08 +10:00
error.rs Reject V5 transactions before NU5 activation (#2285) 2021-06-15 10:15:59 +10:00
lib.rs Standardise clippy lints and require docs (#2238) 2021-06-04 08:48:40 +10:00
parameters.rs move genesis parameters to zebra-chain (#1151) 2020-10-12 14:08:23 -07:00
primitives.rs Ed25519 async batch verification for JoinSplit signatures (#1952) 2021-03-31 09:08:19 +10:00
script.rs Make the state usage clearer in script::Verifier (#1733) 2021-02-16 05:53:12 +10:00
transaction.rs Validate transparent inputs and outputs in V5 transactions (#2302) 2021-06-23 11:54:00 +10:00