diff options
| author | Bitflash <btf01@proton.me> | 2026-08-01 21:48:03 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-01 21:48:03 -0300 |
| commit | d54a07170808b921c79e25c2a0a8f6b9c447d4ea (patch) | |
| tree | be83d3b40c1e466b1ecab1e3f5375b6a9b23c755 /src/selftest.cpp | |
| parent | 5a5478669c487963e99491112abc065c59973966 (diff) | |
wallet: reserve index 0 before deriving it, and name the address the phrase does not cover (#104)
Follow-up to #102. Reserves derivation index 0 before deriving it, so a failure between installing the seed and writing the default key cannot leave the pool free to hand that index out as an ordinary key. Renames the address that stops being the default to 'Your Address (created before the recovery phrase)', which was otherwise left under the same name as the new one. Also documents why the key-pool clear precedes the seed write, correcting a review comment of mine that asked for the reverse.
Diffstat (limited to 'src/selftest.cpp')
| -rw-r--r-- | src/selftest.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/selftest.cpp b/src/selftest.cpp index bc9fa5a..88e9863 100644 --- a/src/selftest.cpp +++ b/src/selftest.cpp | |||
| @@ -334,6 +334,10 @@ static int RunWalletHDSelfTest() | |||
| 334 | nFail += Check(nRandomPoolSize == KEYPOOL_SIZE, | 334 | nFail += Check(nRandomPoolSize == KEYPOOL_SIZE, |
| 335 | "a wallet can start with a random key pool") ? 0 : 1; | 335 | "a wallet can start with a random key pool") ? 0 : 1; |
| 336 | 336 | ||
| 337 | // The address the wallet was showing before any of this. It has to | ||
| 338 | // survive under a name that says it is not covered by the phrase. | ||
| 339 | std::string strPreSeedAddr = PubKeyToAddress(keyUser.GetPubKey()); | ||
| 340 | |||
| 337 | nFail += Check(SetHDSeedFromMnemonic(strPhraseA, strError), | 341 | nFail += Check(SetHDSeedFromMnemonic(strPhraseA, strError), |
| 338 | "a valid phrase installs a seed") ? 0 : 1; | 342 | "a valid phrase installs a seed") ? 0 : 1; |
| 339 | nFail += Check(HaveHDSeed(), "the wallet reports having a seed") ? 0 : 1; | 343 | nFail += Check(HaveHDSeed(), "the wallet reports having a seed") ? 0 : 1; |
| @@ -356,6 +360,14 @@ static int RunWalletHDSelfTest() | |||
| 356 | nFail += Check(WalletHasPrivateKey(vchDefaultKey), | 360 | nFail += Check(WalletHasPrivateKey(vchDefaultKey), |
| 357 | "the derived default key is stored in wallet.dat") ? 0 : 1; | 361 | "the derived default key is stored in wallet.dat") ? 0 : 1; |
| 358 | 362 | ||
| 363 | std::string strNewAddr = PubKeyToAddress(vchDefaultKey); | ||
| 364 | nFail += Check(strPreSeedAddr != strNewAddr, | ||
| 365 | "the visible address stops being the pre-seed one") ? 0 : 1; | ||
| 366 | nFail += Check(mapAddressBook.count(strPreSeedAddr) > 0 && | ||
| 367 | mapAddressBook[strPreSeedAddr] != | ||
| 368 | mapAddressBook[strNewAddr], | ||
| 369 | "the pre-seed address is kept, named apart from the new one") ? 0 : 1; | ||
| 370 | |||
| 359 | std::vector<unsigned char> vchBefore = vchHDMaster; | 371 | std::vector<unsigned char> vchBefore = vchHDMaster; |
| 360 | nFail += Check(!SetHDSeedFromMnemonic("not a mnemonic at all", strError), | 372 | nFail += Check(!SetHDSeedFromMnemonic("not a mnemonic at all", strError), |
| 361 | "an invalid phrase is refused") ? 0 : 1; | 373 | "an invalid phrase is refused") ? 0 : 1; |