Commit Graph

300 Commits

Author SHA1 Message Date
Kris Nuttycombe fc0dd8e3eb Merge remote-tracking branch 'upstream/master' into autoshield-poc-daa 2021-10-25 13:24:03 -06:00
Kris Nuttycombe 120cc70a6d Fix type of default_address 2021-10-11 16:34:37 -06:00
Kris Nuttycombe cc58a21ad7 Feature-flag transparent functionality in zcash_client_sqlite
This fixes the wasm32-wasi build issues by excluding the
hdwallet dependencies which are not wasm32-wasi compatible.
2021-10-04 16:53:55 -06:00
Kris Nuttycombe da3c84ff31 Update hdwallet to depend upon secp256k1-v0.20 2021-10-01 12:52:19 -06:00
Kris Nuttycombe d43a893c72 Apply suggestions from code review & update changelog
Co-authored-by: str4d <jack@electriccoin.co>
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-10-01 12:03:06 -06:00
Kris Nuttycombe d49a20e6d2 Modify WalletTransparentOutput to wrap TxOut directly. 2021-10-01 11:42:04 -06:00
Kris Nuttycombe 6cf0749ac9 Merge remote-tracking branch 'upstream/master' into autoshield-poc-reorder 2021-10-01 11:03:41 -06:00
Kris Nuttycombe db89569b90 Address documentation & naming requests from code review. 2021-10-01 11:03:09 -06:00
Kris Nuttycombe 2053d7f57b Always take number of confirmations as a parameter. 2021-10-01 11:00:50 -06:00
Jack Grigg 65e1d32774 ff 0.11, group 0.11, etc. 2021-09-09 18:20:37 +01:00
Kris Nuttycombe b783c4d0e7 Merge remote-tracking branch 'upstream/master' into autoshield-poc-daa 2021-08-12 11:21:30 -06:00
Jack Grigg 0f15743200 Disable default benchmark harness for all workspace crates
This is necessary in order to provide criterion-specific arguments to
`cargo bench`, such as `--profile-time`.
2021-08-05 22:39:36 +01:00
Kris Nuttycombe 1a5aad723b Use generalized signature_hash for transaction builder. 2021-06-04 15:45:39 -06:00
Kris Nuttycombe 55d1090f70 Add v5 txid & signature hashing. 2021-06-04 15:45:39 -06:00
Jack Grigg 1222391dd7 Migrate to bitvec 0.22, ff 0.10, etc.
Requires patching three dependencies:

- bellman is pending a new release.
- nom is part of the funty breakage; we are blocking on a new release.
- orchard is in development.
2021-06-04 22:02:48 +01:00
Kris Nuttycombe 84e8952ec3 Move Sapling components to a bundle within TransactionData 2021-06-03 18:46:38 -06:00
Kris Nuttycombe 76999eb5c7 Make txid contents private & use txid for TzeOutPoint 2021-06-01 07:03:31 -06:00
Kris Nuttycombe 4efb21d1c7 Make amount addition and subtraction traits use checked operations. 2021-06-01 07:03:31 -06:00
Jack Grigg 5623e02a7c Migrate to ff 0.9 et al. 2021-05-19 18:29:37 +01:00
Kris Nuttycombe 8e3e7de50c Minor code cleanup. 2021-05-14 14:17:42 -06:00
Kevin Gorham bd65b01eb3
Remove drop accounts function. 2021-05-07 04:18:45 -04:00
Kevin Gorham 3828a814b5
Relax fk constraints. 2021-05-04 17:37:17 -04:00
Kevin Gorham 5a5100395a
Drop accounts table instead.
We need to recreate the table each time it is cleared to handle any migrations. This is mostly a stop-gap measure until the migrations and table creations are handled by the same code.
2021-04-30 23:06:28 -04:00
Kevin Gorham 08a5cfa80b
Add clear function for the accounts table. 2021-04-30 22:45:01 -04:00
Kevin Gorham 74434f370c
Fix: get rewind height when there are no unspent notes.
Previously, this function was not properly returning an optional.
2021-04-22 16:26:57 -04:00
Kevin Gorham 7fc2d9725c
Placeholder commit: just get things working.
Clean up later but for now don't allow nullable accountIds and also delete more data, during a rewind.
2021-04-20 10:13:47 -04:00
Kevin Gorham c1bc06964f Add get_all_nullifiers. 2021-04-16 14:27:18 -06:00
Kevin Gorham bb68744df1 Ensure that rewinds go far enough to properly restore incremental witness state. 2021-04-16 14:27:18 -06:00
Kris Nuttycombe 9b3025de4d Add ZIP-321 request based sends to zcash_client_backend. 2021-04-16 14:26:53 -06:00
Kevin Gorham 8e16d93f94 Update accounts table create statement.
This PR makes the opinionated change that T-addrs are required
to be supported when using the zcash_client_sqlite backend.
2021-04-16 14:26:53 -06:00
Kevin Gorham bdf56925e9 Insert into accounts table with taddrs. 2021-04-16 14:26:53 -06:00
Kris Nuttycombe 665c4c7aff Figure out the account ID for z->t spends. 2021-04-16 14:26:53 -06:00
Kris Nuttycombe 13cd7498b7 Store vout as part of store_decrypted_tx 2021-04-16 14:26:53 -06:00
Kris Nuttycombe 8828276361 Query for unspent utxos checks to ensure that spending tx is mined.
Also make it an error to try to send a memo to a transparent address.
2021-04-16 14:26:51 -06:00
Kris Nuttycombe a3bc1e3e63 Rename get_spendable -> get_unspent 2021-04-16 14:23:28 -06:00
Kris Nuttycombe 862e221a9b Put transparent dependencies behind a feature flag. 2021-04-16 14:23:26 -06:00
Francisco Gindre cff457ff15 PoC Auto-Shielding
Add retrieval of transparent UTXOs to WalletRead

Co-authored-by: Kris Nuttycombe <kris@electriccoin.co>
Co-authored-by: Kevin Gorham <anothergmale@gmail.com>
2021-04-16 14:22:16 -06:00
Kris Nuttycombe fae1a1517a Simplify try_sapling_output_recovery. 2021-04-12 18:40:17 -06:00
Kris Nuttycombe 324fc36521 Use ShieldedOutput trait for note encryption/decryption.
This change modifies note encryption and decryption functions
to treat a shielded output as a single value instead of handling
the parts of an output as independent arguments.
2021-04-12 12:59:06 -06:00
Kris Nuttycombe cfdbafe2e3 Add myself to crate contributors. 2021-04-08 10:13:04 -06:00
Kris Nuttycombe e77839232d Generalize note encryption and decryption.
This commit introduces a `Domain` trait which defines the types
and operations that are shared between Sapling and Orchard note
encryption and decryption processes.
2021-04-08 08:19:10 -06:00
Kris Nuttycombe 5baccdf052 Move note_encryption into the sapling module. 2021-04-08 08:19:10 -06:00
Jack Grigg 636845d0f9 Renames to use lower-case abbreviations (matching Rust convention)
As of our MSRV bump to 1.51.0, we get lints for this.
2021-03-27 19:01:03 +13:00
Kris Nuttycombe 4086df772c Move sapling-specific primitives into the sapling module. 2021-03-27 16:18:21 +13:00
Kris Nuttycombe 88d58aac0a Move relevant utils into sapling module. 2021-03-27 16:18:21 +13:00
Kris Nuttycombe 16948d9d78 Move zcash_primitives::prover to sapling module 2021-03-27 16:18:21 +13:00
Jack Grigg 38f7a0330c Fix various clippy lints
The remainder will be fixed after the refactor PRs are merged.
2021-03-27 08:50:40 +13:00
Jack Grigg 9d9c0579f8 Use new name for broken_intra_doc_links lint
We also add the lint to crates in the workspace that didn't have it.

Closes zcash/librustzcash#279.
2021-03-27 08:27:17 +13:00
Jack Grigg afa0b29e62 Bump MSRV to 1.51.0
This is the MSRV for the orchard crate, which we will be depending on
soon.
2021-03-27 08:21:45 +13:00
Jack Grigg 4ff0a81a7f zcash_client_sqlite 0.3.0 2021-03-26 19:01:04 +13:00
Jack Grigg acc650cc17 zcash_client_backend 0.5.0 2021-03-26 18:54:42 +13:00
Jack Grigg 813525f0b5 zcash_proofs 0.5.0 2021-03-26 18:53:42 +13:00
Jack Grigg 725699c76b zcash_primitives 0.5.0 2021-03-26 18:51:35 +13:00
str4d 78f6432be6
zcash_client_sqlite: Minor tweaks to documentation 2021-03-26 18:47:59 +13:00
Kris Nuttycombe 88fbd9f423 Add docstrings for zcash_client_sqlite. 2021-03-25 22:22:45 -06:00
Jack Grigg c3c7bd1d9c bech32 0.8 2021-03-26 13:31:20 +13:00
Jack Grigg 0166cb6487 cargo fmt 2021-03-26 13:10:46 +13:00
Jack Grigg cb631a58ba zcash_client_sqlite: Add no-change fixes to changelog 2021-03-26 10:12:10 +13:00
Jack Grigg 55e73d7910 Fix clippy lints 2021-03-26 10:07:20 +13:00
Kris Nuttycombe 42f15a575e
Merge pull request #359 from str4d/356-create_spend_to_address-assumption
zcash_client_backend: Use correct output index for t-addr recipients
2021-03-25 07:58:53 -06:00
Kris Nuttycombe 309d83af57 Retrieve nullifiers for all unconfirmed notes.
Previously we were retrieving nullifiers for notes that were not
marked spent, but not checking against whether the spending
transaction had been included in a block.
2021-03-24 16:18:54 -06:00
Jack Grigg cb6a993840 zcash_client_backend: Use correct output index for t-addr recipients
`create_spend_to_address` was originally written only for sending to
Sapling addresses. It was later amended to support sending to
transparent addresses, but the assumption about there being a Sapling
output was not removed. This was not an issue for most transactions
because there would be change, but in the case of a z->t transaction
with no change, `create_spend_to_address` would reliably panic.

This commit fixes the bug by setting the output index for transparent
recipients to 0. The `output_index` field of `SentTransaction` is also
documented to correctly reflect its dependency on the type of
`recipient_address`.
2021-03-24 19:01:35 +13:00
Jack Grigg 7c8b29e693 zcash_client_sqlite: Add test that exposes the no-change bug 2021-03-24 18:46:55 +13:00
Kris Nuttycombe 334442c505 Address comments from review. 2021-03-17 09:21:10 -06:00
Jack Grigg 8a84203685 Remove Default impl from MemoBytes
Memo fields have two ways to encode an empty memo:

- 0xF6 followed by all-zeroes, encoding "there is no memo".
- All-zeroes, encoding the empty UTF-8 string.

In almost all cases you want the former, but users thinking about byte
slices may expect MemoBytes::default() to result in the latter. To
ensure clarity, we now require calling either MemoBytes::default() or
MemoBytes::from_bytes(&[]) to be explicit.

No such confusion exists for the Memo enum, because the two types are
visibly separated as different enum cases, and Memo::Empty makes sense
as the default.
2021-03-17 21:16:01 +13:00
Jack Grigg c7a3ef0e88 Split memo-handling into MemoBytes struct and Memo enum
The MemoBytes struct is a minimal wrapper around the memo bytes, and only
imposes the existence of null-padding for shorter memos. The only error
case is attempting to construct a memo that is too long. MemoBytes is
guaranteed to be round-trip encodable (modulo null padding).

The Memo enum implements the additional memo rules defined in ZIP 302,
interpreting the contents of a memo (for example, parsing it as text).
2021-03-17 21:05:50 +13:00
Jack Grigg 48f7ef84a4 Move Memo into zcash_primitives::memo 2021-03-17 19:58:40 +13:00
Kris Nuttycombe 5a9b29a75a Address comments from code review. 2021-03-11 13:01:22 -07:00
Kris Nuttycombe 0e022f2283 Allow block scanning using either IVKs or FVKs. 2021-03-09 21:00:40 -07:00
Kris Nuttycombe 16289750e8 Remove WalletWrite::transactionally 2021-03-09 20:59:57 -07:00
Kris Nuttycombe a74cc8b231 Remove sqlite-specific data organization from data access api. 2021-03-09 20:59:57 -07:00
Kris Nuttycombe b5bbbb6f5a Factor out nullifier update from database actions in scan_cached_blocks 2021-03-09 20:59:57 -07:00
Jack Grigg 463e252af4 Fix more intra-doc links 2021-03-04 23:01:42 +00:00
Jack Grigg 464b533937 Bump MSRV to 1.47.0
We'll be needing it shortly for ff et al.
2021-03-04 17:32:57 +00:00
Jack Grigg 5242718b8f bs58 0.4 2021-03-04 17:03:14 +00:00
Jack Grigg 1f6f45bbe7 Add details of unreleased changes to changelogs 2021-02-22 16:59:07 +00:00
str4d 9f14c757e6
Merge pull request #340 from str4d/changelogs
Add changelogs to the crates
2021-02-14 02:34:20 +13:00
Jack Grigg bd3e18984c Changelogs: s/project/library 2021-02-04 15:16:32 +00:00
Jack Grigg b5c7d7f1e7 Add changelogs to the crates
The changelogs are accurate for the 0.4.0 release tag, but don't yet
include changes before or after that tag.
2021-02-04 15:13:22 +00:00
Kris Nuttycombe 98530184c0 Fix clippy complaints. 2021-02-03 14:27:31 -07:00
Kris Nuttycombe df09877b11 Use an enum to distinguish between sent and received notes in sqlite backend. 2021-01-20 10:51:27 -07:00
Kris Nuttycombe 7f43b05e21 Update protobuf dependency version. 2021-01-19 13:01:51 -07:00
Kris Nuttycombe 779a5670e0 Improve data access api method documentation. 2021-01-19 12:45:55 -07:00
Kris Nuttycombe 8fe6f0fdfd Remove default get_balance method.
Recommended by @str4d
2021-01-19 08:25:10 -07:00
Kris Nuttycombe 8e8ed2bb4f Rename get_verified_balance -> get_balance_at 2021-01-15 12:00:14 -07:00
Kris Nuttycombe c70a9ed81f Apply suggestions from code review
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
Co-authored-by: str4d <thestr4d@gmail.com>
2021-01-15 11:57:58 -07:00
Kris Nuttycombe f59124ce19 Pass account ID with IVK. 2021-01-15 10:18:43 -07:00
Kris Nuttycombe 8a7d051138 Rustfmt 2021-01-13 18:06:42 -07:00
Kris Nuttycombe a3f9fa788d Update data_api doctests for error handling changes. 2021-01-13 15:43:39 -07:00
Kris Nuttycombe 5a21580f13 Correct the hierarchy of errors. 2021-01-13 15:20:11 -07:00
Kris Nuttycombe 6c6b05fa9b Trivial rename. 2021-01-12 21:32:46 -07:00
Kris Nuttycombe ce06db197a Rustfmt. 2021-01-12 21:10:34 -07:00
Kris Nuttycombe eef2d5944b Use a slice literal instead of a vec in put_received_note 2021-01-12 21:06:57 -07:00
Kris Nuttycombe fcb2f7a433 Use collect instead of collecting a vec manually. 2021-01-12 21:04:42 -07:00
Kris Nuttycombe 011eda364f Add get_spendable_notes method to WalletRead 2021-01-12 20:42:04 -07:00
Kris Nuttycombe 48f226f8b5 Move decoding errors to sqlite crate.
Also move dependency on params out of wallet read/write methods.
The result is cleaner because these parameters are only required
for backend-specific encoding and decoding operations.
2021-01-12 20:07:02 -07:00
Kris Nuttycombe ca4567b275 More data api documentation. 2021-01-12 13:55:22 -07:00
Kris Nuttycombe 34bc655f64 Add MockBlockSource and MockWalletDB
These can readily be made into an in-memory wallet implementation.
2021-01-12 12:55:24 -07:00
Kris Nuttycombe 7d92150965 Fix test compilation with WalletWrite changes. 2021-01-11 18:13:40 -07:00
Kris Nuttycombe aad2e174c1 Consistently use nullifier and AccountId newtypes. 2021-01-08 21:49:38 -07:00
Kris Nuttycombe 56adbbb545 Make `WalletWrite` depend upon `WalletRead`. 2021-01-08 12:49:10 -07:00
Kris Nuttycombe e96578195a Not sure how this happened. 2020-12-03 10:10:37 -07:00
Kris Nuttycombe 4e608216c1 Do not create nested transaction in rewind_to_height
Fixes #321
2020-12-02 14:36:56 -07:00
Kris Nuttycombe d77784eba8 Do not update `is_change` in received_notes with null values.
Fixes #322
2020-12-02 13:16:02 -07:00
Kris Nuttycombe 7ac08631b9 Fix doctest imports. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe cf2dae8af0 Add hrp_sapling_extended_spending_key to Parameters trait. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 1fd74d0a71 Improve naming for wallet/block database connections. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 897a70dd9e Simplify block source & clean up chain validation. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 8a215d67fe Improve wallet "database" trait names. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe b2cc240454 Do not require wallet database for chain scan. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe e6de7c07f0 Use <module_name>.rs instead of <module_name>/mod.rs 2020-12-02 09:46:17 -07:00
Kris Nuttycombe f742895118 Fix test/doctest errors. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 2e2f34b033 Use named_params macro for query_and_then_named (less error-prone) 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 25b5fc965f Fix broken empty_database_has_no_balance test 2020-12-02 09:46:17 -07:00
Kris Nuttycombe c60b9d3ece Remove database initialization calls from common API. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 903ef58ec6 Fix transactionality in rewind_to_height 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 4c2cda48e6 Clean up transactional API.
This API is still somewhat unsafe in that it doesn't inhibit nested
transactions, but it's better than it was.
2020-12-02 09:46:17 -07:00
Kris Nuttycombe cd2729bbd0 Move 'create_spend_to_address' to wallet backend.
This required changing a bit about the relationship between
database errors and wallet errors, and opens up the possibility
of now simplifying the error situation a bit.
2020-12-02 09:46:17 -07:00
Kris Nuttycombe e144015558 Reuse sent note insertion for wallet/transact. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 68737dd1dd Remove duplicate method. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 8de05f3429 Move transact.rs to wallet module. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 8967745c22 Push chain & wallet functionality down to child modules. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 22ef05239c Split init module into chain and wallet-related parts. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe a181203179 Move related functions into the same modules. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe eab2951c99 Move decrypt_and_store_transaction to zcash_client_backend 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 0165ae7003 Minor renamings. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 746c4c9a00 Move scan_cached_blocks out of sqlite crate. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe d16c124ffe Abstract over data access in scan_cached_blocks. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 06c1772692 Move traversal of cached blocks to CacheOps 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 604294dd9f Factor out nullifier retrieval into data api. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe ffd503134d Factor out witness retrieval from scan. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 499dcd2e6c Add the remainder of sqlite/query.rs functions to the data API. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 56e6091876 Factor out `get_commitment_tree` from scan. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe d16c74725e Extract get_extended_full_viewing_keys function.
This required a bit of generalization of the data_api error types.
2020-12-02 09:46:17 -07:00
Kris Nuttycombe 3eec6f8faa Add get_balance, get_verified_balance to data api. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 70de11dd32 Add address retrieval. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe b72251ee28 Add accounts table initialization. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 724fbac33a Add database initialization implementation. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe f3f3512068 Move get_target_and_anchor_heights to data_api. 2020-12-02 09:46:17 -07:00
Kris Nuttycombe 9874abfd6c Implement chain validation & fix doctests. 2020-12-02 09:46:17 -07:00
Jack Grigg 936b399599 Fix remaining tests after default fee change 2020-11-24 01:50:47 +00:00
str4d 7176ff077c
Apply suggestions from code review
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2020-10-24 12:05:15 +01:00
Jack Grigg 450d68f073 Merge branch 'master' into zcash_client_sqlite-0.2.1 2020-10-24 00:44:37 +01:00
Jack Grigg 74bf85641c zcash_client_sqlite 0.2.1 2020-10-24 00:42:24 +01:00
Jack Grigg 524cc2e979 zcash_client_sqlite: Read rcm correctly from data DB after Canopy
ZIP 212 alters the note plaintext to store a seed from which rcm is
derived, rather than storing rcm directly. In the mobile SDKs we only
need rcm, so for post-ZIP 212 notes, we derive rcm from the seed and
store rcm in the data DB.

However, when selecting notes to spend, `create_to_address` was using the
transaction's target height to determine if Canopy is active, and parsing
the rcm value as the seed if so. This effectively applied a seed->rcm
derivation to all selected notes' rcms once Canopy activated on the
chain. As a result, the note commitments were incorrect, and thus the
anchors derived from the witness paths were also incorrect. This caused
two kinds of observed failures:

- If more than one note was selected, the builder would fail with
  "anchor mismatch", as the note commitments would be effectively
  randomised, causing the derived anchors to also randomise.
- If a single note was selected, the transaction would be built using
  the randomised anchor, and then rejected when sent to the network.

The fix is to "pretend" in `create_to_address` that all notes are
pre-ZIP 212 notes. This works fine because we never need to serialize
back to the note plaintext while spending a note.
2020-10-24 00:23:05 +01:00
Kris Nuttycombe b1c3f9d3f0
ZIP 321 Reference Implementation (#294)
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2020-10-15 14:03:40 +01:00
str4d e0587e752b
Merge pull request #290 from str4d/273-remove-decryption-epk-subgroup-check
Take epk as a jubjub::ExtendedPoint for note decryption
2020-09-22 03:05:35 +12:00
Kris Nuttycombe cfb6850d7c Rustfmt 2020-09-18 10:52:58 -06:00
Kris Nuttycombe 80e1d35ea6 Apply additional suggestions from code review. 2020-09-18 10:40:30 -06:00
Kris Nuttycombe 90d8980162
Apply suggestions from code review
Co-authored-by: str4d <thestr4d@gmail.com>
2020-09-18 10:39:37 -06:00