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 unified addresses to the zcashd wallet. #5395

Conversation

nuttycom
Copy link
Contributor

@nuttycom nuttycom commented Nov 19, 2021

Fixes #5179

  • Add method for new account generation; i.e. generate a new Unified Spending Key for the next available account #
  • Persist the metadata & UFVK corresponding to the generated USK to the walletdb
  • When a new UFVK is generated, or when a UFVK is read from the walletdb, add its Sapling components to the keystore so that note detection can find the correct UFVK.
  • Add Unified Address generation for a particular account & set of receivers.
  • When a new UA is generated, add an association between its diversifier and the source account and set of receivers to the walletdb and keystore so that we can look up/regenerate the original UA.
  • Make it possible to look up the source UA from a receiver on which a payment was received.

@nuttycom nuttycom force-pushed the feature/wallet_orchard-unified_addrs branch 2 times, most recently from d77c489 to a47ae76 Compare November 25, 2021 02:02
@nuttycom nuttycom force-pushed the feature/wallet_orchard-unified_addrs branch 2 times, most recently from 12c8dcb to de6ac67 Compare December 3, 2021 20:26
@r3ld3v r3ld3v added the S-committed Status: Planned work in a sprint label Dec 7, 2021
@nuttycom nuttycom force-pushed the feature/wallet_orchard-unified_addrs branch 2 times, most recently from 316e02d to 66837af Compare December 9, 2021 01:13
@r3ld3v r3ld3v added this to the Core Sprint 2021-48 milestone Dec 13, 2021
@nuttycom nuttycom marked this pull request as ready for review December 13, 2021 22:13
@zcash zcash deleted a comment from mdr0id Dec 13, 2021
@nuttycom nuttycom force-pushed the feature/wallet_orchard-unified_addrs branch 2 times, most recently from 20e1614 to c6289cd Compare December 14, 2021 04:18
@nuttycom nuttycom force-pushed the feature/wallet_orchard-unified_addrs branch 2 times, most recently from 7e859f4 to bbe3d87 Compare December 14, 2021 22:44
@mdr0id mdr0id added the safe-to-build Used to send PR to prod CI environment label Dec 15, 2021
src/chainparams.h Outdated Show resolved Hide resolved
Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flushing review comments.

src/zcash/address/unified.h Outdated Show resolved Hide resolved
src/zcash/address/unified.h Outdated Show resolved Hide resolved
src/zcash/address/unified.h Outdated Show resolved Hide resolved
src/zcash/address/unified.cpp Outdated Show resolved Hide resolved
UnifiedAddress ua;

if (saplingKey.has_value()) {
if (saplingKey.has_value() && receiverTypes.count(ReceiverType::Sapling) > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the PR that connects this logic to the z_getaddressforaccount RPC method, the latter's help text needs to document that "unsupported" receiver types for this account (e.g. if the account was generated before some future shielded protocol was added to zcashd) will be ignored, i.e. the returned UA will contain the largest subset of the specified receiver types that it can support. (This behaviour might change in future, if e.g. we decide to automatically add future shielded pools to existing accounts, but doing so is compatible with this documentation.)

@nuttycom nuttycom force-pushed the feature/wallet_orchard-unified_addrs branch from 6cd46ad to aaf48b0 Compare December 15, 2021 20:31
@nuttycom nuttycom force-pushed the feature/wallet_orchard-unified_addrs branch from aaf48b0 to 7adc6ef Compare December 15, 2021 20:59
Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flushing comments.

src/rust/include/librustzcash.h Outdated Show resolved Hide resolved
src/zcash/Address.cpp Show resolved Hide resolved
@r3ld3v r3ld3v added S-committed Status: Planned work in a sprint and removed S-committed Status: Planned work in a sprint labels Dec 20, 2021
src/keystore.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ordering of items for the ID is blocking. Otherwise utACK.

Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to my comments, I notice that zcash-gtest failed on three of seven CI workers, which seems statistically significant (but the error logs have been garbage-collected from Tekton).

src/zcash/address/zip32.h Show resolved Hide resolved
src/zcash/address/unified.cpp Outdated Show resolved Hide resolved
src/zcash/address/unified.cpp Show resolved Hide resolved
src/zcash/address/unified.cpp Show resolved Hide resolved
src/zcash/address/bip44.h Show resolved Hide resolved
src/wallet/wallet.cpp Outdated Show resolved Hide resolved
src/wallet/wallet.cpp Outdated Show resolved Hide resolved
src/wallet/wallet.cpp Outdated Show resolved Hide resolved
src/wallet/wallet.cpp Show resolved Hide resolved
src/wallet/wallet.cpp Show resolved Hide resolved
@nuttycom nuttycom force-pushed the feature/wallet_orchard-unified_addrs branch 4 times, most recently from f9e1894 to c532257 Compare January 4, 2022 00:36
@nuttycom nuttycom added safe-to-build Used to send PR to prod CI environment and removed safe-to-build Used to send PR to prod CI environment labels Jan 4, 2022
Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK c532257bbdee1c2d8780457a0dd526d2b8b59683 modulo the return value issue below (which is technically fine as-is because it will always return true AFAICT).

src/wallet/wallet.cpp Outdated Show resolved Hide resolved
src/wallet/wallet.cpp Outdated Show resolved Hide resolved
src/wallet/wallet.h Outdated Show resolved Hide resolved
src/zcash/address/zip32.h Show resolved Hide resolved
@nuttycom nuttycom force-pushed the feature/wallet_orchard-unified_addrs branch from 93a0c19 to dda30ba Compare January 4, 2022 20:09
nuttycom and others added 4 commits January 4, 2022 16:29
ZcashdUnifiedFullViewingKey::FindAddress was previously not checking
that the transparent child index did not overflow in unified address
generation. GenerateUnifiedAddress has been modified to search from
the last known diversifier index if no diversifier is specified, and
boundary conditions for transparent addresses are now correctly handled.
Co-authored-by: str4d <jack@electriccoin.co>
@nuttycom nuttycom force-pushed the feature/wallet_orchard-unified_addrs branch from dda30ba to eb53abb Compare January 4, 2022 23:30
Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-utACK eb53abb

@str4d str4d merged commit 1d7a29e into zcash:feature/wallet_unified_addresses Jan 5, 2022
@nuttycom nuttycom deleted the feature/wallet_orchard-unified_addrs branch January 5, 2022 02:37

diversifier_index_t j;
// If the wallet is missing metadata at this UFVK id, it is probably
// corrupt and the node should shut down.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does a std::out_of_range exception here actually shut the node down in all calling contexts?

We normally minimize the use of exceptions because of the difficulty of answering questions like that (and because we've had past cases in which an exception was caught and the node proceeded with inconsistent state).

}

// If the wallet is missing metadata at this UFVK id, it is probably
// corrupt and the node should shut down.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does a std::out_of_range exception here actually shut the node down in all calling contexts?

@@ -281,37 +280,48 @@ CPubKey CWallet::GenerateNewKey()
BIP44CoinType(),
ZCASH_LEGACY_ACCOUNT).value();

std::optional<std::pair<CExtKey, HDKeyPath>> extKey = std::nullopt;
std::optional<std::pair<CKey, HDKeyPath>> extKey = std::nullopt;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable is still called extKey even though it no longer is. (I'm assuming that ext stood for extended rather than external.)

Comment on lines +719 to +721
* Returns `true` if this is a new entry or if the operation would not
* alter the existing set of receiver types at this index, `false`
* otherwise.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it useful to return true in those two cases?

}

/**
* Search the for the maximum diversifier that has already been used to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Search the for the maximum diversifier that has already been used to
* Search for the the maximum diversifier that has already been used to

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-committed Status: Planned work in a sprint safe-to-build Used to send PR to prod CI environment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants