From 1f561f323f54191e1323a8cd2df101df4f054b62 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 4 Apr 2019 18:27:46 +0100 Subject: [PATCH] init: Fix new HD seed generation for previously-encrypted wallets Closes #3607. --- src/init.cpp | 8 ++++++-- src/wallet/wallet.cpp | 8 +++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index f9da81e87..6910cf308 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1645,8 +1645,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) if (!pwalletMain->HaveHDSeed()) { - // generate a new HD seed - pwalletMain->GenerateNewSeed(); + // We can't set the new HD seed until the wallet is decrypted. + // https://github.com/zcash/zcash/issues/3607 + if (!pwalletMain->IsCrypted()) { + // generate a new HD seed + pwalletMain->GenerateNewSeed(); + } } if (fFirstRun) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 6dfa15025..97500911a 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -499,8 +499,14 @@ bool CWallet::Unlock(const SecureString& strWalletPassphrase) return false; if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey)) continue; // try another master key - if (CCryptoKeyStore::Unlock(vMasterKey)) + if (CCryptoKeyStore::Unlock(vMasterKey)) { + // Now that the wallet is decrypted, ensure we have an HD seed. + // https://github.com/zcash/zcash/issues/3607 + if (!this->HaveHDSeed()) { + this->GenerateNewSeed(); + } return true; + } } } return false;