Simplify Base32 and Base64 conversions#11630
Conversation
|
Impressive simplification, Concept ACK |
|
All Travis failures seem to be the same issue in signmessages.py |
927db41 to
8059735
Compare
|
@fanquake Thanks, fixed. |
src/utilstrencodings.cpp
Outdated
There was a problem hiding this comment.
Any reason to not reserve? Doesn't pay off?
src/utilstrencodings.cpp
Outdated
There was a problem hiding this comment.
Not sure but isn't (p - e) & 7 == 0 faster? Or does the compiler optimise this case?
There was a problem hiding this comment.
Strength reduction will do that for you at -O1 and higher.
8059735 to
16a01bf
Compare
|
utACK 16a01bf1a2a318effbbac4a22f1092fee1924dc8. Would be nice to add these folks to test_bitcoin_fuzzy.cpp! |
|
utACK. Needs rebase in src/utilstrencodings.cpp. |
16a01bf to
eb59db5
Compare
|
Rebased. |
src/utilstrencodings.cpp
Outdated
There was a problem hiding this comment.
It seems a bit of a pity to allocate and fill an intermediate vector here, which is just the contents of the string mapped through decode64_table. Could we maybe wrap the iterator to weave this into ConvertBits?
(to be clear, this could be done later, no need to do so in this PR, but as the rest of the changes is so elegant it just jumped out)
There was a problem hiding this comment.
@laanwj I actually tried that, and it became a bit more complex than I wanted to do in this PR.
There was a problem hiding this comment.
Yes it seems quite annoying to do so in C++, iterators are tricky enough to make this seemingly trivial thing non-trivial :/
So as we keep it like this, we should heed @promag's suggestion and reserve, I think.
|
Needs rebase after #11372 |
eb59db5 to
110556f
Compare
|
Rebased. |
110556f to
bc528e6
Compare
|
Added reserves in several places. |
bc528e6 to
b3ea8cc
Compare
Thanks! utACK b3ea8cc |
b3ea8cc Simplify Base32 and Base64 conversions (Pieter Wuille) 3296a3b Generalize ConvertBits (Pieter Wuille) Pull request description: Generalize `ConvertBits` a bit to also be usable for the existing Base32 and Base64 convertions (rather than just for Bech32). Tree-SHA512: 3858247f9b14ca4766c08ea040a09b1d6d70caaccc75c2436a54102d6d526f499ec07f5bdfcbbe16cbde5aae521cd16e9aa693e688a97e6c5e74b8e58ee55a13
Sapling address encodings This PR enables Sapling keys and addresses to be passed in anywhere Sprout keys and addresses are used. Doing so will cause crashes until those places are updated with Sapling support. Includes code cherry-picked from the following upstream PRs: - bitcoin/bitcoin#11167 - bitcoin/bitcoin#11630 Closes #3058.
Sapling address encodings This PR enables Sapling keys and addresses to be passed in anywhere Sprout keys and addresses are used. Doing so will cause crashes until those places are updated with Sapling support. Includes code cherry-picked from the following upstream PRs: - bitcoin/bitcoin#11167 - Only the `ConvertBits()` function. - bitcoin/bitcoin#11630 Closes #3058.
Summary: The behavior of ConvertBits() has been simplified in D572 from it's original form, and would return `false` when there is any remaining bit and padding is disabled. This diff relaxes this requirement to be in par with the original behavior (see https://github.com/bitcoin/bitcoin/pull/11167/files#diff-b5877ad42a7dbee9a99cbf0596977fd9). The call will now returns `true` if the remaining bits are all zeros. This is a prerequisite for backporting [[bitcoin/bitcoin#11630 | PR11630]]. The cash address decoding is updated to now check the output of `ConvertBits()` Test Plan: ninja check check-functional Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Subscribers: deadalnix Differential Revision: https://reviews.bitcoinabc.org/D5734
Summary: ``` Generalize ConvertBits a bit to also be usable for the existing Base32 and Base64 convertions (rather than just for Bech32). ``` Backport of core [[bitcoin/bitcoin#11630 | PR11630]]. Depends on D5734. The key_io.cpp changes are not ported because they are segwit related, however some cashaddrenc.cpp and util_tests.cpp changes were required. Test Plan: ninja all check check-functional Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D5735
Summary: The behavior of ConvertBits() has been simplified in D572 from it's original form, and would return `false` when there is any remaining bit and padding is disabled. This diff relaxes this requirement to be in par with the original behavior (see https://github.com/bitcoin/bitcoin/pull/11167/files#diff-b5877ad42a7dbee9a99cbf0596977fd9). The call will now returns `true` if the remaining bits are all zeros. This is a prerequisite for backporting [[bitcoin/bitcoin#11630 | PR11630]]. The cash address decoding is updated to now check the output of `ConvertBits()` Test Plan: ninja check check-functional Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Subscribers: deadalnix Differential Revision: https://reviews.bitcoinabc.org/D5734
Summary: ``` Generalize ConvertBits a bit to also be usable for the existing Base32 and Base64 convertions (rather than just for Bech32). ``` Backport of core [[bitcoin/bitcoin#11630 | PR11630]]. Depends on D5734. The key_io.cpp changes are not ported because they are segwit related, however some cashaddrenc.cpp and util_tests.cpp changes were required. Test Plan: ninja all check check-functional Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D5735
b3ea8cc Simplify Base32 and Base64 conversions (Pieter Wuille) 3296a3b Generalize ConvertBits (Pieter Wuille) Pull request description: Generalize `ConvertBits` a bit to also be usable for the existing Base32 and Base64 convertions (rather than just for Bech32). Tree-SHA512: 3858247f9b14ca4766c08ea040a09b1d6d70caaccc75c2436a54102d6d526f499ec07f5bdfcbbe16cbde5aae521cd16e9aa693e688a97e6c5e74b8e58ee55a13
Generalize
ConvertBitsa bit to also be usable for the existing Base32 and Base64 convertions (rather than just for Bech32).