Address encoding cleanup #11372

pull sipa wants to merge 4 commits into bitcoin:master from sipa:201709_addr_cleanup changing 41 files +484 −574
  1. sipa commented at 1:16 am on September 20, 2017: member

    This PR contains some of the changes left as TODO in #11167 (and built on top of that PR). They are not intended for backporting.

    This removes the CBase58, CBitcoinSecret, CBitcoinExtKey, and CBitcoinExtPubKey classes, in favor of simple Encode/Decode functions. Furthermore, all Bitcoin-specific logic (addresses, WIF, BIP32) is moved to key_io.{h,cpp}, leaving base58.{h,cpp} as a pure utility that implements the base58 encoding/decoding logic.

  2. gmaxwell commented at 6:21 am on September 20, 2017: contributor
    Should this perhaps be merged only after the rest of the backport intended segwit stuff is done?
  3. sipa force-pushed on Sep 20, 2017
  4. sipa commented at 8:49 am on September 20, 2017: member
    Perhaps, yes. This is not urgent in any way.
  5. in src/test/bip32_tests.cpp:103 in 11ff1af237 outdated
    104-
    105-        CBitcoinExtKey b58keyDecodeCheck(derive.prv);
    106-        CExtKey checkKey = b58keyDecodeCheck.GetKey();
    107-        assert(checkKey == key); //ensure a base58 decoded key also matches
    108+        BOOST_CHECK(EncodeExtKey(key) == derive.prv);
    109+        BOOST_CHECK(DecodeExtKey(derive.prv) == key); //ensure a base58 decoded key also matches
    


    promag commented at 8:50 am on September 20, 2017:
    Nit, space after //. Same below.
  6. in src/base58.cpp:328 in 9efe89a663 outdated
    328+            std::equal(privkey_prefix.begin(), privkey_prefix.end(), data.begin())) {
    329+            bool compressed = data.size() == 33 + privkey_prefix.size();
    330+            key.Set(data.begin() + privkey_prefix.size(), data.begin() + privkey_prefix.size() + 32, compressed);
    331+        }
    332+    }
    333+    memory_cleanse(data.data(), data.size());
    


    promag commented at 9:26 am on September 20, 2017:
    Important: IMO DecodeBase58Checkshould cleanse databefore returning false.

    promag commented at 9:45 am on September 20, 2017:

    Extra: In that case this function could be:

     0    CKey key;
     1    std::vector<unsigned char> data;
     2    if (!DecodeBase58Check(str, data)) return key;
     3
     4    const auto& prefix = Params().Base58Prefix(CChainParams::SECRET_KEY);
     5    int size = data.size() - prefix.size();
     6    if (size == 32 || (size == 33 && data.back() == 1)) {
     7        if (std::equal(prefix.begin(), prefix.end(), data.begin())) {
     8            ...
     9        }
    10    }
    11
    12    memory_cleanse(data.data(), data.size());
    13    return key;
    

    promag commented at 9:47 am on September 20, 2017:
    Side note: Another option is to create a PR to use custom allocator for all containers that are memory_cleanse.
  7. promag commented at 9:56 am on September 20, 2017: member
    See collapsed comment.
  8. promag commented at 9:58 am on September 20, 2017: member
    In commit Split key_io (address/key encodings) off from base58 move tests {Decode,Encode}Destination tests from base58_tests.cpp to key_io_tests.cpp?
  9. MarcoFalke added this to the milestone 0.16.0 on Sep 20, 2017
  10. laanwj added the label Refactoring on Sep 20, 2017
  11. sipa commented at 11:59 pm on September 20, 2017: member
    @promag Added a commit that splits off the key_io tests from base58_tests.
  12. sipa force-pushed on Sep 23, 2017
  13. sipa force-pushed on Sep 23, 2017
  14. sipa force-pushed on Sep 24, 2017
  15. laanwj referenced this in commit aa624b61c9 on Sep 29, 2017
  16. promag commented at 9:02 am on September 29, 2017: member
    Needs rebase.
  17. sipa force-pushed on Nov 2, 2017
  18. sipa commented at 9:53 pm on November 2, 2017: member
    Rebased.
  19. laanwj commented at 4:50 pm on November 9, 2017: member
    Nice, I like how this gets rid of awkward conversion classes like CBitcoinSecret and replaces them with simple functions. utACK 68f0c52
  20. sipa force-pushed on Nov 21, 2017
  21. sipa commented at 10:44 am on November 21, 2017: member
    Rebased.
  22. MarcoFalke removed this from the milestone 0.16.0 on Nov 22, 2017
  23. MarcoFalke added this to the milestone 0.17.0 on Nov 22, 2017
  24. sipa force-pushed on Dec 12, 2017
  25. sipa commented at 7:21 pm on December 12, 2017: member
    Rebased.
  26. sipa force-pushed on Jan 5, 2018
  27. sipa commented at 11:43 am on January 5, 2018: member
    Rebased.
  28. sipa force-pushed on Feb 6, 2018
  29. sipa commented at 2:40 am on February 6, 2018: member
    Rebased.
  30. in src/test/key_tests.cpp:36 in e4eff7e875 outdated
    39-    BOOST_CHECK( bsecret2C.SetString(strSecret2C));
    40-    BOOST_CHECK(!baddress1.SetString(strAddressBad));
    41-
    42-    CKey key1  = bsecret1.GetKey();
    43+    CKey key1  = DecodeSecret(strSecret1);
    44     BOOST_CHECK(key1.IsCompressed() == false);
    


    MarcoFalke commented at 2:10 pm on February 8, 2018:
    This is initialized with false. I assume you’d also have to check for key1.IsValid()?

    sipa commented at 7:17 pm on February 8, 2018:
    Fixed.
  31. in src/test/key_tests.cpp:43 in e4eff7e875 outdated
    49+    CKey key1C = DecodeSecret(strSecret1C);
    50     BOOST_CHECK(key1C.IsCompressed() == true);
    51-    CKey key2C = bsecret2C.GetKey();
    52+    CKey key2C = DecodeSecret(strSecret2C);
    53     BOOST_CHECK(key2C.IsCompressed() == true);
    54+    CKey bad_address = DecodeSecret(strAddressBad);
    


    MarcoFalke commented at 2:10 pm on February 8, 2018:
    nit: bad_key

    sipa commented at 7:17 pm on February 8, 2018:
    Fixed.
  32. sipa force-pushed on Feb 8, 2018
  33. sipa commented at 7:17 pm on February 8, 2018: member
    Rebased and addressed @MarcoFalke’s comments.
  34. in src/base58.cpp:310 in c4c66e0bc0 outdated
    305+}
    306+
    307+std::string EncodeExtPubKey(const CExtPubKey& key)
    308+{
    309+    std::vector<unsigned char> data = Params().Base58Prefix(CChainParams::EXT_PUBLIC_KEY);
    310+    size_t size = data.size();
    


    MarcoFalke commented at 10:48 pm on February 8, 2018:
    naming: Should say prefix_size or size_prefix, current name has no meaning.
  35. MarcoFalke approved
  36. MarcoFalke commented at 7:34 pm on February 12, 2018: member
    utACK 5f8d5f7d0e7c97e2f24aeb2fa0c8f60e26e29ae2. Just one naming-nit
  37. sipa force-pushed on Feb 14, 2018
  38. sipa force-pushed on Feb 14, 2018
  39. MarcoFalke commented at 3:52 pm on February 18, 2018: member
    re-utACK 2333475531 (was rebased with no other code changes)
  40. Replace CBitcoinSecret with {Encode,Decode}Secret 32e69fa0df
  41. Stop using CBase58Data for ext keys ebfe217b15
  42. Split key_io (address/key encodings) off from base58 119b0f85e2
  43. Split off key_io_tests from base58_tests 92f1f8b319
  44. sipa force-pushed on Feb 20, 2018
  45. sipa commented at 3:02 am on February 20, 2018: member
    Rebased.
  46. MarcoFalke commented at 6:26 pm on February 22, 2018: member
    re-utACK 92f1f8b
  47. laanwj merged this on Mar 6, 2018
  48. laanwj closed this on Mar 6, 2018

  49. laanwj referenced this in commit b225010a80 on Mar 6, 2018
  50. zkbot referenced this in commit 1c2f24793b on Apr 24, 2018
  51. zkbot referenced this in commit d5b558ba5b on Apr 25, 2018
  52. zkbot referenced this in commit 962ba99b36 on Apr 25, 2018
  53. zkbot referenced this in commit f660c08991 on May 8, 2018
  54. zkbot referenced this in commit 1942f7a42b on May 11, 2018
  55. UdjinM6 referenced this in commit 5e311b6164 on Dec 25, 2020
  56. UdjinM6 referenced this in commit 70c82570b2 on Jan 8, 2021
  57. cryptolinux referenced this in commit a45c5d4adc on Feb 6, 2021
  58. ckti referenced this in commit 7c598f5657 on Mar 29, 2021
  59. furszy referenced this in commit 170beab56c on Jul 1, 2021
  60. random-zebra referenced this in commit b4751e10ce on Aug 11, 2021
  61. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-09-28 22:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me