Commit Graph

2714 Commits

Author SHA1 Message Date
teor ccf93cf5c6
Update state RFC for incremental trees, value pools, and RocksDB (#2456)
* Update state RFC for double-spends and other recent designs

* Update the value pool column family name

* Mark incremental note commitment trees as tentative

* Change history tree type

* Apply suggestions from code review
2021-07-12 10:33:02 -03:00
Alfredo Garcia f7026d728f
move `Utxo` type to zebra-chain (#2481) 2021-07-12 12:49:33 +10:00
teor 6d24ee1d21
Restore the previous non-finalized chain if a block is invalid (#2478)
Previously, we would implicitly drop the full non-finalized chain,
and reset the state to the finalized tip.
2021-07-09 11:22:15 -03:00
teor ada525e1ff
Stop ignoring sapling binding signature errors (#2472) 2021-07-09 09:52:05 -03:00
teor f745333ff2
Use the block verifier and non-finalized state in the cached state tests (#2463)
* Use the block verifier and non-finalized state in the cached state tests

This substantially increases test coverage.

Previously, the cached state tests were configured with
`checkpoint_sync = true`, which only uses the checkpoint
verifier and the finalized state.

* Log the source of blocks in commit_finalized_direct

This lets us check that we're actually testing the non-finalized state
and block verifier in the cached state tests.

It also improves diagnostics for state errors.

* Fail cached state tests if they're using incorrect heights or configs

This makes sure that the cached state tests actually test the transition
from checkpoint to block verification, and the non-finalized state.
2021-07-09 09:47:09 -03:00
teor 14d5abdb03
Add methods for getting block nullifiers (#2465)
* Add methods for getting block nullifiers

These methods will be used in a future PR to check for double-spends.

* Add doc links

Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>

Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>
2021-07-09 02:54:57 +00:00
teor d4cc867132
Combine near-duplicate Utxo creation functions (#2467)
* Combine near-duplicate Utxo creation functions

* rustfmt
2021-07-09 12:40:39 +10:00
teor 64be7fddb7
Add a TypeNameToDebug formatter to zebra_chain (#2466)
* Add a TypeNameToDebug formatter to zebra_chain

This formatter makes it much easier to diagnose proptest errors.
It will be used in a future PR.

Implement Arbitrary and DerefMut for all the formatters.

Also make the formatter type bounds consistent,
to produce better compiler errors.

* Clarify how TypeNameToDebug actually works

Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>

Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>
2021-07-09 12:40:19 +10:00
Janito Vaqueiro Ferreira Filho 23fe2c2e94
Update panics by `todo!` and `unimplemented!` macros (#2471)
* Add panic message to `unimplemented!`

So that it is clear why the panic happened upon initial inspection. Also
include a reference to the mempool epic, so that it's easier to find the
issue that tracks the implementation of the missing code.

* Add panic message that references a tracking issue

Make it easy to find the relevant issue if the panic occurs.

* Remove incomplete and currently unnecessary code

The current implementation works, the commented out code was just a
previous improvement idea, which is now tracked by issue #2473.
2021-07-09 01:49:55 +00:00
Conrado Gouvea 40e350c342
Always compute sighash with librustzcash (#2469)
* Always use librustzcash for sighash and remove old sighash code

Also added ZIP-143 test vectors

* Remove librustzcash_sighash test that is no longer needed
2021-07-09 09:55:08 +10:00
Alfredo Garcia d1ab8a8946
Value pools design (#2430)
* add a draft for value pools design

* add some `ValueBalance` operators

* add `value_balance` methods to modules

* fix some minors

* finalize the last part of the implementation design

* replace wrong AllowNegative with correct NegativeAllowed

* add design PR to header

* update scope

* remove details from transaction `value_balance()`

* update definitions

* change method name

* return Result in operators

* fix the TODOs

* implement `UpdateWith<PreparedBlock>` for `ValueBalance`

* add details to `ValueBalance` serialization

* add a panic to block value balance

* fix `remaining_transaction_value()`

* add the block value balance into `FinalizedState`

* populate the `Chain` with the finalized tip value balance

* remove redundant text from definition

* add docs to `Chain` field

* trigger the `remaining_transaction_value()` check

* fix mistake

* add some tests, remove some not needed sections

* add a summary of the implementation

* do some minor fixes to consensus rules text

* clarify some names

* fix `UpdateWith`

* move the remaining transaction value consensus rule

* fix serialization bug

* fix typo

* Add a missing test

* typo

Co-authored-by: Conrado Gouvea <conradoplg@gmail.com>

Co-authored-by: teor <teor@riseup.net>
Co-authored-by: Conrado Gouvea <conradoplg@gmail.com>
2021-07-09 09:53:14 +10:00
teor 0be7470601
Modify UTXO and state designs for transparent coinbase output checks (#2413)
* Modify UTXO and state designs for transparent coinbase output checks

* Add missing word

* Clarify unspent transparent transaction outputs

And add a definition for OutPoint

* Fix coinbase flag derivation

* Rename SpendPools to SpendRestriction

* Replace coinbase_height with Coinbase.height

And clarify a height to spend_height

* Make block height italic to match spec formatting

* Provide a value for MIN_TRANSPARENT_COINBASE_MATURITY

* Add new v1-4 transaction ID consensus rule

* Make the design match the existing Utxo code

This minimises the changes we'll need to make.

* Add a justification for parallel coinbase verification

* Change to Response::SpendableUtxo

To avoid confusion.

* Update the state RFC to match the current design

* Move a change to another PR to avoid conflicts

* Fix spacing

* Clarify the future returned by `PendingUtxos::queue(u)`

* Add missing PendingUtxos::queue arguments
2021-07-09 07:11:43 +10:00
Conrado Gouvea ba9fab1241
Fix missing blake2b_simd::Hash -> SigHash replacement (#2470) 2021-07-08 17:09:55 -03:00
Conrado Gouvea 1c919fbabb
Fix bug in sighash for coinbase transactions (#2459) 2021-07-08 16:05:40 -03:00
Alfredo Garcia 01ea87a039
Verify orchard spend auth (#2442) 2021-07-08 09:36:36 -03:00
teor 2aaf1d245f
Revert "ZIP-221: Validate chain history commitments in the non-finalized state (#2301)" (#2464)
This reverts commit 91b1fcb37b.
2021-07-08 09:25:49 -03:00
teor f817df638b
clippy: remove needless borrows (#2457) 2021-07-07 11:38:57 -03:00
teor c8305fba1f
Stop using the wrong name for the coverage action (#2453)
Previously the action was called "CI", which could be confusing.
2021-07-07 11:36:54 -03:00
Janito Vaqueiro Ferreira Filho 20eeddcaab
Parse `MSG_WTX` inventory type (part of ZIP-239) (#2446)
* Rename constant to `MIN_INVENTORY_HASH_SIZE`

Because the size is not constant anymore, since the `MSG_WTX` inventory
type is larger.

* Add `InventoryHash::smallest_types_strategy`

A method for a proptest strategy that generates the `InventoryHash`
variants that have the smallest serialized size.

* Update proptest to use only smallest inventories

In order to properly test the maximum allocation.

* Add intra-doc links in some method documentation

Make it easier to navigate from the documentation of the proptest
strategies to the variants they generate.

* Parse `MSG_WTX` inventory type

Avoid returning an error if a received `GetData` or `Inv` message
contains a `MSG_WTX` inventory type. This prevents Zebra from
disconnecting from peers that announce V5 transactions.

* Fix inventory hash size proptest

The serialized size now depends on what type of `InventoryHash` is being
tested.

* Implement serialization of `InventoryHash::Wtx`

For now it just copies the stored bytes, in order to allow the tests to
run correctly.

* Test if `MSG_WTX` inventory is parsed correctly

Create some mock input bytes representing a serialized `MSG_WTX`
inventory item, and check that it can be deserialized successfully.

* Generate arbitrary `InventoryHash::Wtx` for tests

Create a strategy that only generates `InventoryHash::Wtx` instances,
and also update the `Arbitrary` implementation for `InventoryHash` to
also generate `Wtx` variants.

* Test `InventoryHash` serialization roundtrip

Given an arbitrary `InventoryHash`, check that it does not change after
being serialized and deserialized.

Currently, `InventoryHash::Wtx` can't be serialized, so this test will
is expected to panic for now, but it will fail once the serialization
code is implemented, and then the `should_panic` should be removed.

* Test deserialize `InventoryHash` from random bytes

Create an random input vector of bytes, and try to deserialize an
`InventoryHash` from it. This should either succeed or fail in an
expected way.

* Remove redundant attribute

The attribute is redundant because the `arbitrary` module already has
that attribute.

* Implement `Message::inv_strategy()`

A method to return a proptest strategy that creates `Message::Inv`
instances.

* Implement `Message::get_data_strategy()`

A method that returns a proptest strategy that creates
`Message::GetData` instances.

* Test encode/decode roundtrip of some `Message`s

Create a `Message` instance, encode it and then decode it using a
`Codec` instance and check that the result is the same as the initial
`Message`.

For now, this only tests `Message::Inv` and `Message::GetData`, because
these are the variants that are related to the scope of the current set
of changes to support parsing the `MSG_WTX` inventory type.

Even so, the test relies on being able to serialize an
`InventoryHash::Wtx`, which is currently not implemented. Therefore the
test was marked as `should_panic` until the serialization code is
implemented.
2021-07-07 11:06:11 +10:00
Conrado Gouvea 91b1fcb37b
ZIP-221: Validate chain history commitments in the non-finalized state (#2301)
* sketch of implementation

* refined implementation; still incomplete

* update librustzcash, change zcash_history to work with it

* simplified code per review; renamed MMR to HistoryTree

* expand HistoryTree implementation

* handle and propagate errors

* simplify check.rs tracing

* add suggested TODO

* add HistoryTree::prune

* fix bug in pruning

* fix compilation of tests; still need to make them pass

* Apply suggestions from code review

Co-authored-by: teor <teor@riseup.net>

* Apply suggestions from code review

Co-authored-by: teor <teor@riseup.net>

* improvements from code review

* improve check.rs comments and variable names

* fix HistoryTree which should use BTreeMap and not HashMap; fix non_finalized_state prop tests

* fix finalized_state proptest

* fix non_finalized_state tests by setting the correct commitments

* renamed mmr.rs to history_tree.rs

* Add HistoryTree struct

* expand non_finalized_state protest

* fix typo

* Add HistoryTree struct

* Update zebra-chain/src/primitives/zcash_history.rs

Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>

* fix formatting

* Apply suggestions from code review

Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>

* history_tree.rs: fixes from code review

* fixes to work with updated HistoryTree

* Improvements from code review

* Add Debug implementations to allow comparing Chains with proptest_assert_eq

Co-authored-by: teor <teor@riseup.net>
Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>
2021-07-07 10:29:08 +10:00
Conrado Gouvea fdfa3cbdc6
Add ZIP-244 signature hash support (#2165)
* ZIP-244 sighash implementation using librustzcash

* ZIP-244: fix sighash test; add roundtrip test; update vectors

* Improvements from review; renamed sighash::Hash to SigHash
2021-07-07 08:27:10 +10:00
Conrado Gouvea d430e951c2
Add HistoryTree struct (#2396)
* Add HistoryTree struct

* Update zebra-chain/src/primitives/zcash_history.rs

Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>

* fix formatting

* Apply suggestions from code review

Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>

* history_tree.rs: fixes from code review

Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>
2021-07-07 08:22:00 +10:00
Conrado Gouvea dd645e7e0c
Add ZIP-0244 TxId Digest support (#2129)
* Add ZIP-0244 TxId Digest support

* Apply suggestions from code review

Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>
Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>
2021-07-06 09:58:22 -03:00
dependabot[bot] 6a6c8ee999
build(deps): bump displaydoc from 0.2.1 to 0.2.2 (#2439)
Bumps [displaydoc](https://github.com/yaahc/displaydoc) from 0.2.1 to 0.2.2.
- [Release notes](https://github.com/yaahc/displaydoc/releases)
- [Changelog](https://github.com/yaahc/displaydoc/blob/master/CHANGELOG.md)
- [Commits](https://github.com/yaahc/displaydoc/compare/v0.2.1...v0.2.2)

---
updated-dependencies:
- dependency-name: displaydoc
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-02 13:20:47 -04:00
Janito Vaqueiro Ferreira Filho f5bc5279ca
Validate V5 transactions with Sapling shielded data (#2437)
* Make `verify_sapling_shielded_data` more generic

Prepare to support V5 transactions which have a shared anchor.

* Verify Sapling shielded data in V5 transactions

Call the `verify_sapling_shielded_data` method and add the respective
asynchronous checks to the set of V5 checks.

* Fix expect message in V4 transaction test

It was using the same message as the previous test, even though the test
searches with different criteria.

* Test V5 transaction with Sapling spends

Create a fake V5 transaction that has Sapling spends and check that the
verifier accepts the transaction.

* Ignore rejected V5 transaction test for now

Because now it needs the `sighash` implementation for V5 to be ready.

* Reference V5 `sighash` PR in comment

So that it is easier to check if it's possible to remove the
`should_panic` or not.

Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>

* Remove `sapling shielded pool` TODO

V5 transactions now have Sapling shielded pool properly validated.

* Link to some extra issues in TODO comment

Some other issues are also necessary for full V5 validation.

* Add a TODO in the main code to fix the tests

Some tests are blocked due to missing features required for full V5
validation. Once those features are implemented, they should be updated
to remove the `#[should_panic]` attribute so that they actually run and
check the code correctly.

Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
2021-07-02 13:48:53 -03:00
Pili Guerra d30b95d0fa
CHANGELOG for Zebra 1.0.0-alpha.12 (#2414)
* Draft CHANGELOG for Zebra 1.0.0-alpha.12

* Add suggestions from review

* Update CHANGELOG.md

Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>

* Update CHANGELOG.md

* Final updates before merging and tagging release

Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>
Co-authored-by: teor <teor@riseup.net>
2021-07-02 11:01:19 +01:00
Janito Vaqueiro Ferreira Filho ac1a1c76c6
Refactor asynchronous checks in `transaction::Verifier` (#2432)
* Refactor `AsyncChecks` into a proper type

Add some helper methods to it so that checks can be added by
daisy-chaining calls. Also move the code to wait for the checks to
finish into the new type.

* Refactor inclusion of individual Sapling checks

Use `oneshot` instead of `ready_and` so that the method becomes
synchronous.

* Make V4 and V5 verification methods synchronous

There is no longer a need to wait for any internal service to be ready,
since now that's always done as part of an asynchronous check included
in the returned set of checks.
2021-07-02 03:01:26 -04:00
Deirdre Connolly 06eddf7fb3
Add notes about note commitment trees storage (#2259)
* Add notes about note commitment trees storage

* Updates

* Update book/src/dev/rfcs/drafts/0005-treestate.md

Co-authored-by: teor <teor@riseup.net>

* Update book/src/dev/rfcs/drafts/0005-treestate.md

Co-authored-by: teor <teor@riseup.net>

* Update book/src/dev/rfcs/drafts/0005-treestate.md

Co-authored-by: teor <teor@riseup.net>

* Update book/src/dev/rfcs/drafts/0005-treestate.md

Co-authored-by: teor <teor@riseup.net>

* Update book/src/dev/rfcs/drafts/0005-treestate.md

Co-authored-by: teor <teor@riseup.net>

* Update book/src/dev/rfcs/drafts/0005-treestate.md

Co-authored-by: teor <teor@riseup.net>

* Update book/src/dev/rfcs/drafts/0005-treestate.md

Co-authored-by: teor <teor@riseup.net>

* Update book/src/dev/rfcs/drafts/0005-treestate.md

Co-authored-by: teor <teor@riseup.net>

* Update book/src/dev/rfcs/drafts/0005-treestate.md

Co-authored-by: teor <teor@riseup.net>

* Update book/src/dev/rfcs/drafts/0005-treestate.md

Co-authored-by: teor <teor@riseup.net>

Co-authored-by: teor <teor@riseup.net>
2021-07-02 02:52:19 -04:00
Deirdre Connolly ff299781c1
Merge pull request #2318 from ZcashFoundation/redpallas-verifier
RedPallas async verifier service
2021-07-02 02:50:23 -04:00
teor 14137bfc8e Stop allowing JoinSplit<Halo2> 2021-07-01 23:56:30 -04:00
dependabot[bot] 11d8389371
build(deps): bump vergen from 5.1.11 to 5.1.12 (#2431)
Bumps [vergen](https://github.com/rustyhorde/vergen) from 5.1.11 to 5.1.12.
- [Release notes](https://github.com/rustyhorde/vergen/releases)
- [Commits](https://github.com/rustyhorde/vergen/compare/5.1.11...5.1.12)

---
updated-dependencies:
- dependency-name: vergen
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-02 09:24:20 +10:00
teor 936168b40d
Fix failing legacy chain tests (#2427)
* Skip invalid legacy chain check test cases

Add proptest seeds for the failing test.
And improve some unclear documentation.

* Fix the legacy chain test blocks order

Also fix unclear documentation that might have led to this bug.
2021-07-02 09:21:22 +10:00
Alfredo Garcia e4ab01dde0
ZIP-211: Validate Disabling Addition of New Value to the Sprout Value Pool (#2399)
* add disabled sprout pool check

* change method name

* change error name

* fix typo

* make the success test case in other tx than the coinbase

* use new `height` method instead of deriving `PartialOrd` in `NetworkUpgrade`

* move check of network upgrade into function, rename, docs

* increase test coverage

* fix comment
2021-07-02 09:03:34 +10:00
Pili Guerra 515dc4bf5c
Update versions for Zebra v1.0.0 alpha.12 release (#2415)
* Update versions for zebra v1.0.0-alpha.12 release

* Update Cargo.lock

* Update release checklist with latest version changes to help keep track for future releases

* Remove reference to the fact that tower-fallback was not updated
2021-07-01 08:59:32 +01:00
Janito Vaqueiro Ferreira Filho 76fca5f32f
Refactor validation of Sapling shielded data in `transaction::Verifier` (#2419)
* Refactor to create `verify_sapling_shielded_data`

Move the code to verify Sapling shielded data into a new helper method
that returns `AsyncChecks`.

* Test verifying a Sapling transaction with spends

Use the test vectors to find a transaction that has Sapling spends and
test if it the verifier considers it valid.

* Create a helper method to list test transactions

Transforms the block test vectors into a list of transactions and block
heights for each transaction.

* Use new helper function in V4 Sapling spend test

Also use the block height for that transaction as specified in the test
vector.

* Test V4 tx. with Sapling outputs but no spends

Find a transaction V4 vector that has Sapling outputs but no spends, and
check that the verifier accepts it.
2021-07-01 12:17:37 +10:00
Janito Vaqueiro Ferreira Filho f33923f12f
Create a shared Tokio runtime for tests (#2397)
* Add a `zebra_test::RUNTIME` shared runtime

Create a lazily instantiated Tokio runtime that can be shared by tests.

* Split tests that require a shared runtime

Split two tests that were previously in one because of the need to share
a single Tokio runtime. With the `zebra_test::RUNTIME`, they can now
share the runtime without having to be a single test.
2021-07-01 10:30:31 +10:00
dependabot[bot] 3dbb4098e5
build(deps): bump vergen from 5.1.9 to 5.1.11 (#2422)
Bumps [vergen](https://github.com/rustyhorde/vergen) from 5.1.9 to 5.1.11.
- [Release notes](https://github.com/rustyhorde/vergen/releases)
- [Commits](https://github.com/rustyhorde/vergen/compare/5.1.9...5.1.11)

---
updated-dependencies:
- dependency-name: vergen
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-01 10:14:31 +10:00
Deirdre Connolly ffdaf073aa Add link to specific implementation of computing the non-adjacent form from curve25519-dalek 2021-06-30 16:26:08 -04:00
Deirdre Connolly 681ccdb974 Remove unneeded scalar accumulator set to zero for redpallas batch verify 2021-06-30 16:26:08 -04:00
Deirdre Connolly 7c75a887b7 Add a test that explicitly checks for a bad RedPallas binding signature in batch verification
Along with the explicit test for bad SpendAuth's in the batch.
2021-06-30 16:26:08 -04:00
Deirdre Connolly 08d84cc0a7 Rustdoc for redpallas types 2021-06-30 16:26:08 -04:00
Deirdre Connolly 22015c127d Add doc to redpallas batch types 2021-06-30 16:26:08 -04:00
Deirdre Connolly 8d8813d427 assert that all redpallas signatures verify when we benchmark them 2021-06-30 16:26:08 -04:00
Deirdre Connolly 25cf199265 Make sure all RedPallas benchmarks sign and verify the same message 2021-06-30 16:26:08 -04:00
Deirdre Connolly edf0946208 Docs for the items in redpallas::bench 2021-06-30 16:26:08 -04:00
Deirdre Connolly 20343c5f75 Remove redundant allow(non_snake_case)
Co-authored-by: teor <teor@riseup.net>
2021-06-30 16:26:08 -04:00
Deirdre Connolly 53067d7370 Update comment to doc comment
Co-authored-by: teor <teor@riseup.net>
2021-06-30 16:26:08 -04:00
Deirdre Connolly 2734357671 Remove empty doc comment line
Co-authored-by: teor <teor@riseup.net>
2021-06-30 16:26:08 -04:00
Deirdre Connolly d5687720c2 Batch match and multiscalar multiplication for redpallas
Resolves #2098
2021-06-30 16:26:08 -04:00
dependabot[bot] b59121b09e build(deps): bump indexmap from 1.6.2 to 1.7.0
Bumps [indexmap](https://github.com/bluss/indexmap) from 1.6.2 to 1.7.0.
- [Release notes](https://github.com/bluss/indexmap/releases)
- [Commits](https://github.com/bluss/indexmap/compare/1.6.2...1.7.0)

---
updated-dependencies:
- dependency-name: indexmap
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-30 13:36:35 -04:00