From 854b826d8e5f955c41855a1c8b16f42724ceb925 Mon Sep 17 00:00:00 2001 From: lateminer Date: Tue, 2 Jan 2018 12:44:22 +0300 Subject: [PATCH] [Wallet] use constant for bip32 hardened key limit https://github.com/bitcoin/bitcoin/commit/c022e5b15dd0b26bb6ef77a382279987c2efa93f --- src/wallet/wallet.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 255fe8610..f9d6ee671 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -41,6 +41,8 @@ unsigned int nTxConfirmTarget = DEFAULT_TX_CONFIRM_TARGET; bool bSpendZeroConfChange = DEFAULT_SPEND_ZEROCONF_CHANGE; bool fSendFreeTransactions = DEFAULT_SEND_FREE_TRANSACTIONS; +const uint32_t BIP32_HARDENED_KEY_LIMIT = 0x80000000; + static int64_t GetStakeCombineThreshold() { return 500 * COIN; } static int64_t GetStakeSplitThreshold() { return 2 * GetStakeCombineThreshold(); } @@ -115,16 +117,19 @@ CPubKey CWallet::GenerateNewKey() masterKey.SetMaster(key.begin(), key.size()); // derive m/0' - // use hardened derivation (child keys > 0x80000000 are hardened after bip32) - masterKey.Derive(accountKey, 0 | 0x80000000); + // use hardened derivation (child keys >= 0x80000000 are hardened after bip32) + masterKey.Derive(accountKey, BIP32_HARDENED_KEY_LIMIT); // derive m/0'/0' - accountKey.Derive(externalChainChildKey, 0 | 0x80000000); + accountKey.Derive(externalChainChildKey, BIP32_HARDENED_KEY_LIMIT); // derive child key at next index, skip keys already known to the wallet do { - externalChainChildKey.Derive(childKey, hdChain.nExternalChainCounter | 0x80000000); + // always derive hardened keys + // childIndex | BIP32_HARDENED_KEY_LIMIT = derive childIndex in hardened child-index-range + // example: 1 | BIP32_HARDENED_KEY_LIMIT == 0x80000001 == 2147483649 + externalChainChildKey.Derive(childKey, hdChain.nExternalChainCounter | BIP32_HARDENED_KEY_LIMIT); // increment childkey index hdChain.nExternalChainCounter++; } while(HaveKey(childKey.key.GetPubKey().GetID()));