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
Sapling keys in keystore, wallet #3273
Conversation
☔ The latest upstream changes (presumably #3275) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the two binaries that were added.
@@ -313,4 +346,3 @@ TEST(wallet_zkeys_tests, write_cryptedzkey_direct_to_db) { | |||
|
|||
ECC_Stop(); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave this in.
src/wallet/wallet.cpp
Outdated
@@ -3881,4 +3906,3 @@ void CWallet::GetUnspentFilteredNotes( | |||
} | |||
} | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave this in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. New methods and tests are independent of existing Sprout keystore. Verified that WriteSaplingZKey
is never invoked, so database is not touched.
7343289
to
891760c
Compare
@zkbot try |
⌛ Trying commit 891760c with merge 5c98b97a8ae64fac706126c34888b83fe7a99054... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking pretty good overall!
// Add addr -> SaplingIncomingViewing to SaplingIncomingViewingKeyMap | ||
auto ivk = fvk.in_viewing_key(); | ||
auto addr = sk.default_address(); | ||
mapSaplingIncomingViewingKeys[addr] = ivk; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reminder to self: when we implement ZIP 32, we need to set the address -> ivk
mapping inside AddSaplingFullViewingKey()
, not here (which we can't do in this PR because we can't get the default address from fvk
).
src/keystore.cpp
Outdated
bool CBasicKeyStore::RemoveViewingKey(const libzcash::SproutViewingKey &vk) | ||
{ | ||
LOCK(cs_SpendingKeyStore); | ||
mapViewingKeys.erase(vk.address()); | ||
return true; | ||
} | ||
|
||
bool CBasicKeyStore::RemoveSaplingFullViewingKey(const libzcash::SaplingFullViewingKey &fvk) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we need this, but I'm not going to block the PR on removing it.
src/keystore.h
Outdated
@@ -70,6 +91,13 @@ typedef std::map<libzcash::SproutPaymentAddress, libzcash::SproutSpendingKey> Sp | |||
typedef std::map<libzcash::SproutPaymentAddress, libzcash::SproutViewingKey> ViewingKeyMap; | |||
typedef std::map<libzcash::SproutPaymentAddress, ZCNoteDecryption> NoteDecryptorMap; | |||
|
|||
// Full viewing key has equivalent functionality to a transparent address | |||
// When encrypting wallet, encrypt SaplingSpendingKeyMap, while leaving SaplingFullViewingKeyMap unencrypted | |||
typedef std::map<libzcash::SaplingFullViewingKey, libzcash::SaplingSpendingKey> SaplingSpendingKeyMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reminder to self: when we implement ZIP 32, we'll add another map here from fvk -> ExtendedSpendingKey
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added comment
src/wallet/wallet.cpp
Outdated
// Generate a new Sapling spending key and return its public payment address | ||
SaplingPaymentAddress CWallet::GenerateNewSaplingZKey() | ||
{ | ||
AssertLockHeld(cs_wallet); // mapZKeyMetadata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: mapSaplingZKeyMetadata
in comment.
src/wallet/wallet.cpp
Outdated
|
||
// Check for collision, even though it is unlikely to ever occur | ||
if (CCryptoKeyStore::HaveSaplingSpendingKey(fvk)) | ||
throw std::runtime_error("CWallet::GenerateNewSaplingZKey(): Collision detected"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add brackets and fix indentation.
src/wallet/walletdb.h
Outdated
@@ -141,7 +141,7 @@ class CWalletDB : public CDB | |||
|
|||
bool WriteViewingKey(const libzcash::SproutViewingKey &vk); | |||
bool EraseViewingKey(const libzcash::SproutViewingKey &vk); | |||
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove whitespace.
@@ -1,3 +1,4 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove whitespace.
{ | ||
AssertLockHeld(cs_wallet); // mapSaplingZKeyMetadata | ||
|
||
if (!CCryptoKeyStore::AddSaplingSpendingKey(sk)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this call will fail, because this PR doesn't update CCryptoKeyStore
with the new methods. Please add a test that calls GenerateNewSaplingZKey()
and/or AddSaplingZKey()
to ensure the pathway is exercised.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the ongoing try
passes, I will downgrade this to non-blocking in the interest of unblocking downstream PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated CCryptoKeyStore
to add sapling spending keys, and added a test calling GenerateNewSaplingZKey()
and AddSaplingZKey()
, going to run a try again
💔 Test failed - pr-try |
@zkbot try |
Sapling keys in keystore, wallet - Add/Have/Get SaplingSpendingKey - Add/Remove/Have/Get SaplingFullViewingKey - Have/Get SaplingIncomingViewingKey - SaplingSpendingKeyMap, SaplingFullViewingKeyMap, SaplingIncomingViewingKeyMap - GenerateNewSaplingZKey() Not included: note decryptors, crypted keystore
💔 Test failed - pr-try |
5fa6689
to
a33eff6
Compare
@zkbot try |
⌛ Trying commit 2173767 with merge 2b21793ac510d049ffb5e6540c2c2ce5040bd3a4... |
☀️ Test successful - pr-try |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ut(ACK+cov)
auto fvk = sk.full_viewing_key(); | ||
auto addr = sk.default_address(); | ||
|
||
// Check for collision, even though it is unlikely to ever occur |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically it is also possible for a collision to occur on ivk, even though fvk does not collide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ut(ACK+cov)
//! Sapling | ||
virtual bool AddCryptedSaplingSpendingKey(const libzcash::SaplingFullViewingKey &fvk, | ||
const std::vector<unsigned char> &vchCryptedSecret); | ||
bool AddSaplingSpendingKey(const libzcash::SaplingSpendingKey &sk); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Todo in subsequent PR: implement crypter overrides of HaveSaplingSpendingKey()
etc.
CKeyingMaterial vchSecret(ss.begin(), ss.end()); | ||
auto address = sk.default_address(); | ||
auto fvk = sk.full_viewing_key(); | ||
if (!EncryptSecret(vMasterKey, vchSecret, address.GetHash(), vchCryptedSecret)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use fvk.GetHash()
here (as that is what is stored in the mapping with the ciphertext). Non-blocking, as we can fix this in the subsequent PR that fleshes out the crypter for Sapling.
Nice work! @zkbot r+ |
📌 Commit 2173767 has been approved by |
Sapling keys in keystore, wallet - Add/Have/Get SaplingSpendingKey - Add/Remove/Have/Get SaplingFullViewingKey - Have/Get SaplingIncomingViewingKey - SaplingSpendingKeyMap, SaplingFullViewingKeyMap, SaplingIncomingViewingKeyMap - GenerateNewSaplingZKey() Not included: note decryptors, crypted keystore
Add/Have/Get SaplingSpendingKey
Add/Remove/Have/Get SaplingFullViewingKey
Have/Get SaplingIncomingViewingKey
SaplingSpendingKeyMap, SaplingFullViewingKeyMap, SaplingIncomingViewingKeyMap
GenerateNewSaplingZKey()
Not included: note decryptors, crypted keystore