Commit Graph

16198 Commits

Author SHA1 Message Date
str4d a638e938bd
Merge pull request #5823 from str4d/add-orchard-wallet-tracing
Add trace-level logging to the Orchard wallet
2022-04-08 18:47:06 +01:00
Jack Grigg 70167dd2aa rpc: Document that enabling trace-level logging is unsafe 2022-04-08 15:48:02 +00:00
Jack Grigg a06406d087 wallet: Bump a trace log message to error in `Wallet::checkpoint`
If we hit this error, the node is going to end up with an assertion
failure, so there's no verbosity harm in logging here.
2022-04-08 15:43:44 +00:00
Kris Nuttycombe a4aba7cb91
Merge pull request #5830 from therealyingtong/orchard-z_listreceivedbyaddress
Support Orchard addresses in `z_listreceivedbyaddress`
2022-04-08 07:55:10 -06:00
Kris Nuttycombe c342e7d712
Merge pull request #5847 from nuttycom/bug/wallet_bestchain_init
Fix assertion in wallet initialization when wallet best block is ahead of the main chain.
2022-04-08 07:48:19 -06:00
Kris Nuttycombe f553ae3320 Apply suggestions from code review
Co-authored-by: str4d <thestr4d@gmail.com>
Co-authored-by: ying tong <yingtong@z.cash>
2022-04-07 23:05:05 -06:00
str4d 0c32c988fc
Merge pull request #5834 from nuttycom/bug/sendmany_privacy_policy_violations
Fix privacy policy violations when sending between unified addresses.
2022-04-08 04:00:31 +01:00
str4d 5f60f33daf
Merge pull request #5832 from therealyingtong/miner-latest-height
Use height of latest network upgrade in -mineraddress validation.
2022-04-08 03:01:20 +01:00
str4d 175dc4bc4a
Merge pull request #5841 from str4d/lint-cargo-patches
Add lints for Cargo patches
2022-04-08 02:01:02 +01:00
Kris Nuttycombe 773c2b515a Fix assertion in wallet initialization when wallet best block is ahead of the main chain.
In #5809, we attempted to fix the assumption that on startup, the
wallet's best chain was at the same position as the node's chain tip.
This did not account for a condition where the node's block index
might not contain the block corresponding to the wallet's best chain,
because the node had crashed before the block index containing that
block could be written to disk.

This commit adds handling so that the `ThreadNotifyWallets` thread
will not start until the wallet's best block has been restored
to the node's block index and we're able to obtain a pointer to
that state.
2022-04-07 17:23:13 -06:00
Kris Nuttycombe cb64997216 Never consider transactions that pay the default fee to be free. 2022-04-07 13:51:08 -06:00
Kris Nuttycombe 369fc78e0b Use DEFAULT_FEE consistently in wallet_unified_change test
This fixes a nondeterministic error where zero-fee transactions
may be excluded due to minimum-block-size rules.
2022-04-07 08:57:48 -06:00
Kris Nuttycombe 14f06f9f06 Return MAX_PRIORITY when transactions contain an Orchard bundle. 2022-04-07 08:47:47 -06:00
Kris Nuttycombe dada8b38bc Add 'AllowRevealedAmounts' in tests where it is now necessary. 2022-04-07 08:47:47 -06:00
Kris Nuttycombe 51defe9f96 Make all privacy policy checks after note selection.
This adds tests to wallet_z_sendmany that demonstrates conditions
where pool-crossing transfers were not being caught by the privacy
policy checks, which were validating only against the transfer
request rather than the actual transfer selected. This missed
cases where sending funds between unified addresses would reveal
amounts via the turnstile.

Making all privacy policy checks after note selection guards against
this error.
2022-04-07 08:47:47 -06:00
therealyingtong 63c83ad5df Fix >= bound when iterating over network upgrades. 2022-04-07 20:03:46 +08:00
therealyingtong 1ab4da3f2c Use height of latest network upgrade in -mineraddress validation.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2022-04-07 18:49:44 +08:00
str4d a86220ee62
Merge pull request #5835 from nuttycom/dep/update_secp256k1
Update to orchard-0.1.0-beta.3, incrementalmerkletree 0.3.0-beta.2, secp256k1-0.21
2022-04-07 03:21:11 +01:00
Jack Grigg b2b178bd21 lint: Add check that every Cargo patch has a matching replacement
We canonicalize git URLs when linting Cargo patches, because Cargo
treats `path/to/repo` and `path/to/repo.git` identically (and similarly
it strips a trailing slash), so we allow `.cargo/config.offline` and
`Cargo.toml` to mismatch in this way to minimise lints.
2022-04-07 02:14:52 +00:00
Kris Nuttycombe 63d13a437f Update to orchard-0.1.0-beta.3, incrementalmerkletree 0.3.0-beta.2, secp256k1-0.21 2022-04-06 17:48:49 -06:00
Kris Nuttycombe cc892fd48d
Merge pull request #5824 from nuttycom/bug/change_reveals_amounts
Fix condition where change outputs could violate z_sendmany privacy policy.
2022-04-06 14:57:08 -06:00
Kris Nuttycombe 834162a25e
Merge pull request #5833 from therealyingtong/fix-orchard-z_listunspent
Correctly derive UAs for unknown Orchard receivers.
2022-04-06 14:54:25 -06:00
therealyingtong 896ae6315b Correctly derive UAs for unknown Orchard receivers.
The previous code assumed that we would only see wallet addresses
that we had explicitly generated, and crashed if we detected a note
sent to a different Orchard receiver within a known account.

Fixes zcash/zcash#5827.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2022-04-06 23:42:51 +08:00
therealyingtong da5575a02d IsNoteSaplingChange: Inline internal recipient check.
This fixes the usage of IsNoteSaplingChange in z_listreceivedbyaddress.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2022-04-06 23:28:55 +08:00
therealyingtong 37c5bca411 Introduce push_orchard_result in z_listreceivedbyaddress. 2022-04-06 20:39:15 +08:00
therealyingtong 8a7283ca83 Introduce CWallet::HaveOrchardSpendingKeyForAddress. 2022-04-06 20:34:38 +08:00
Kris Nuttycombe e6d498e9c9 Check privacy strategy when setting allowed change types. 2022-04-05 20:47:37 -06:00
Kris Nuttycombe a48aa0195c Add logging to the miner to provide more detail on tx selection. 2022-04-05 20:47:37 -06:00
Kris Nuttycombe 1d2f1d6689 Add a test demonstrating that change may cross the pool boundary without permission. 2022-04-05 18:16:57 -06:00
Jack Grigg 484edf2cdb wallet: Remove duplicate nullifier insertion into Orchard wallet
We have the same insertion a few lines earlier.
2022-04-05 18:22:36 +00:00
Jack Grigg b3b5429956 wallet: Add assertions during Orchard wallet bundle appends
`Wallet::append_bundle_commitments` should never be called twice on the
same bundle, as that breaks sequentiality requirements (which we already
check for), so it is safe to assert that the inserted values do not
overwrite any existing data.
2022-04-05 18:19:20 +00:00
Jack Grigg 838f1cccec Add trace-level logging to the Orchard wallet
This can be enabled with `zcash-cli setlogfilter trace` (or a more
specific filter to target just the Orchard wallet trace lines).
2022-04-05 18:18:49 +00:00
str4d 9e80e4aff6
Merge pull request #5819 from ebfull/fix-rescans
Fix logic for deciding whether to perform Orchard updates during rescan
2022-04-05 14:53:17 +01:00
Kris Nuttycombe 53a302cf3f
Merge pull request #5789 from nuttycom/bug/wallet_init_post_nu5
Fix a bug in initialization of the Orchard wallet after NU5 activation.
2022-04-04 20:06:34 -06:00
Kris Nuttycombe 98c848fd20
Merge pull request #5809 from str4d/5805-fix-thread-notify-wallets-init
wallet: Initialise ThreadNotifyWallets with wallets best block
2022-04-04 20:04:53 -06:00
Sean Bowe 979d0b5ee3
Fix logic for deciding whether to perform Orchard updates during rescan
In `ScanForWalletTransactions` we skip forward from `pindexStart` to a block
near our wallet birthday. But we use this as the basis for deciding the value
of `performOrchardWalletUpdates` later, which is wrong because our wallet
birthday might be beyond the NU5 activation height. The result is that we
won't actually perform the required scanning (mainly witnessing and so forth)
needed to spend notes in our wallet.
2022-04-04 16:06:11 -06:00
Kris Nuttycombe 8e4dd1e964 Only check nWitnessCacheSize on rewind if we've ever witnessed a Sprout or Sapling note.
This allows "rollback" for empty Sapling wallets injected into nonempty
chain state that is then rolled back.
2022-04-04 15:31:19 -06:00
ebfull fbddebc63f
Merge pull request #5804 from str4d/consensus-check-coinbase-shielded-spends
Apply HaveShieldedRequirements to coinbase transactions
2022-04-04 14:28:52 -06:00
Kris Nuttycombe afb503503d Omit check of Orchard commitment root after rewind past first checkpoint.
If we no longer have any checkpoints in the Orchard wallet, we must
skip the check against the prior note commitment tree root because
we know that the Orchard wallet's state may be for a chain that is
being reorg'ed away. This is safe because we know that we will have
removed all information from the wallet that we need to perform spends
from that state, and we also know that when we start rolling forward
along the new chain that we will overwrite the initial state of the
Orchard note commitment tree.
2022-04-04 13:05:46 -06:00
Kris Nuttycombe 5b7370c55e Update test to verify rewind behavior. 2022-04-04 13:05:42 -06:00
Kris Nuttycombe 344aef435d Improve error output from OrchardWallet::get_spend_info 2022-04-04 13:05:42 -06:00
Kris Nuttycombe 6fbcba641d Fix a bug in initialization of the Orchard wallet after NU5 activation.
When initializing a new Orchard wallet after NU5 activation, it is
not valid to start from the empty note commitment tree; instead,
the note commitment tree needs to be initialized from the state of
the global Orchard Merkle frontier.

In addition, this change necessitates a change to how rewinds work,
such that in a rollback scenario with a newly initialized wallet
that does not have sufficient checkpoints to fully satisfy a requested
rewind, the rewind is allowed to proceed so long as it does not
invalidate any persisted witness data.
2022-04-04 13:05:42 -06:00
Kris Nuttycombe 4afc6a37c9 Refactor ChainTip to take a struct of Merkle trees instead of a pair.
This makes addition of the Orchard Merkle frontier easier in the future.
2022-04-04 12:04:34 -06:00
Kris Nuttycombe d9de6b64fc Adds a test demonstrating an Orchard wallet initialization bug.
If a new Orchard wallet is created after the first Orchard spend
post NU5 activation, it causes an assertion failure because the root
of the wallet's empty note commitment tree does not match the global
note commitment tree root.
2022-04-04 12:04:32 -06:00
Jack Grigg 098a70ed89 wallet: Rename `CWallet::GetBestBlock` to `GetPersistedBestBlock`
This more accurately reflects its meaning, as it corresponds to the most
recently persisted best chain (i.e. the chain tip that the wallet will
return to on restart), rather than the chain tip to which the in-memory
wallet state has been synced.
2022-04-04 17:43:17 +00:00
Jack Grigg bb072f06c9 AcceptToMemoryPool: Re-add missing code comment
The comment on `view.SetBackend(dummy)` was removed when we backported
upstream locking PRs in zcash/zcash#5017. The upstream commit in
question removed a locking scope but did not remove the reference to
that scope in the comment. Our backport removed the outdated comment,
but should have modified it instead, because otherwise the existence of
`view.SetBackend(dummy)` is very confusing (as it disconnects the cache
from `pcoinsTip`, on the assumption that everything we need from it has
been cached via calls to `CCoinsViewCache::HaveCoins` and
`CCoinsViewCache::HaveShieldedRequirements`).
2022-04-04 16:57:55 +00:00
Jack Grigg c99e7752e4 mempool: Remove duplicated anchor and nullifier assertions
Now that we call `Consensus::CheckTxShieldedInputs` on all transactions
in `CTxMemPool::check`, we don't need to separately check the nullifiers
and anchors directly. That change also fixed a bug where we weren't
previously making the same assertions about Orchard Actions.
2022-04-04 16:57:55 +00:00
Jack Grigg f1cda64602 Apply `HaveShieldedRequirements` to coinbase transactions
Both transparent and shielded inputs have contextual checks that need to
be enforced in the consensus rules. For shielded inputs, these are that
the anchors in transactions correspond to real commitment tree states
(to ensure that the spent notes existed), and that their nullifiers are
not being double-spent.

When Sprout was first added to the codebase, we added input checks in
the same places that transparent inputs were checked; namely anywhere
`CCoinsViewCache::HaveInputs` is called. These all happened to be gated
on `!tx.IsCoinBase()`, which was fine because we did not allow Sprout
JoinSplits in coinbase transactions (enforced with a non-contextual
check).

When we added Sapling we also allowed coinbase outputs to Sapling
addresses (shielded coinbase). We updated `HaveShieldedRequirements` to
check Sapling anchors and nullifiers, but didn't change the consensus
code to call it on coinbase. This was fine because Sapling Spends and
Outputs are separate, and we did not allow Sapling Spends in coinbase
transactions (meaning that there were no anchors or nullifiers to
enforce the input rules on).

Orchard falls into an interesting middle-ground:
- We allowed coinbase outputs to Orchard addresses, to enable Sapling
  shielded coinbase users to migrate to Orchard.
- Orchard uses Actions, which are a hybrid of Sprout JoinSplits and
  Sapling Spends/Outputs. That is, an Orchard Action comprises a single
  spend and a single output.

To maintain the "no shielded spends in coinbase" rule, we added an
`enableSpends` flag to the Orchard circuit. We force it to be set to
`false` for coinbase, ensuring that all Orchard spends in a coinbase use
dummy (zero-valued) notes. However, this is insufficient: the coinbase
transaction will still contain an Orchard anchor and nullifiers, and
these need to be correctly constrained.

In particular, not constraining the Orchard nullifiers in a coinbase
transaction enables a Faerie Gold attack. We explicitly require that
Orchard nullifiers are unique, so that there is a unique input to the
nullifier derivation. Without the coinbase check, the following attack
is possible:
- An adversary creates an Orchard Action sending some amount of ZEC to a
  victim address, with a dummy spent note. The entire transaction can be
  fully-shielded by placing the real spent note in a separate Action.
- The adversary uses the exact same dummy note in a coinbase
  transaction, creating the exact same output note (same victim address
  and amount).
- The victim now has two notes with the same ZEC amount, but can only
  spend one of them because they have the same nullifier.

This commit fixes the consensus bug by calling `HaveShieldedRequirements`
outside of `!tx.IsCoinBase()` gates. To simplify its usage, there is now
a `Consensus::CheckTxShieldedInputs` function that handles the logging
and validation state updates. We also move shielded input checks from
`ContextualCheckInputs` to `ContextualCheckShieldedInputs`; these now
mirror each other in that they check contextual rules on transparent and
shielded inputs respectively, followed by checking signatures.
2022-04-04 16:57:55 +00:00
ebfull a4cc6ad3d0
Merge pull request #5788 from daira/orchard-nullifier-check
Orchard nullifier and anchor consistency checks
2022-04-04 08:20:17 -06:00
Steven c8e0503c69
Merge pull request #5797 from nuttycom/feature/z_listunspent_account
Add account ID to z_listunspent results.
2022-04-04 07:17:53 -07:00