Skip to content

Simplify Base32 and Base64 conversions#11630

Merged
laanwj merged 2 commits intobitcoin:masterfrom
sipa:201711_simpleconvert
Mar 7, 2018
Merged

Simplify Base32 and Base64 conversions#11630
laanwj merged 2 commits intobitcoin:masterfrom
sipa:201711_simpleconvert

Conversation

@sipa
Copy link
Member

@sipa sipa commented Nov 7, 2017

Generalize ConvertBits a bit to also be usable for the existing Base32 and Base64 convertions (rather than just for Bech32).

@meshcollider
Copy link
Contributor

Impressive simplification, Concept ACK

@fanquake
Copy link
Member

fanquake commented Nov 8, 2017

All Travis failures seem to be the same issue in signmessages.py

    self.run_test()
  File "/home/travis/build/bitcoin/bitcoin/build/bitcoin-x86_64-unknown-linux-gnu/test/functional/signmessages.py", line 24, in run_test
    assert(self.nodes[0].verifymessage(address, signature, message))
  File "/home/travis/build/bitcoin/bitcoin/build/bitcoin-x86_64-unknown-linux-gnu/test/functional/test_framework/coverage.py", line 47, in __call__
    return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
  File "/home/travis/build/bitcoin/bitcoin/build/bitcoin-x86_64-unknown-linux-gnu/test/functional/test_framework/authproxy.py", line 138, in __call__
    raise JSONRPCException(response['error'])
test_framework.authproxy.JSONRPCException: Malformed base64 encoding (-5)
2017-11-07 23:50:01.876000 TestFramework (INFO): Stopping nodes
2017-11-07 23:50:01.877000 TestFramework.node0 (DEBUG): Stopping node

@sipa sipa force-pushed the 201711_simpleconvert branch from 927db41 to 8059735 Compare November 8, 2017 02:41
@sipa
Copy link
Member Author

sipa commented Nov 8, 2017

@fanquake Thanks, fixed.

Copy link
Contributor

@promag promag Nov 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not reserve? Doesn't pay off?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure but isn't (p - e) & 7 == 0 faster? Or does the compiler optimise this case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strength reduction will do that for you at -O1 and higher.

@sipa sipa force-pushed the 201711_simpleconvert branch from 8059735 to 16a01bf Compare November 23, 2017 01:59
@TheBlueMatt
Copy link
Contributor

utACK 16a01bf1a2a318effbbac4a22f1092fee1924dc8. Would be nice to add these folks to test_bitcoin_fuzzy.cpp!

@laanwj
Copy link
Member

laanwj commented Mar 1, 2018

utACK. Needs rebase in src/utilstrencodings.cpp.

@laanwj laanwj added this to the 0.17.0 milestone Mar 5, 2018
@sipa sipa force-pushed the 201711_simpleconvert branch from 16a01bf to eb59db5 Compare March 5, 2018 21:57
@sipa
Copy link
Member Author

sipa commented Mar 5, 2018

Rebased.

Copy link
Member

@laanwj laanwj Mar 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@laanwj I actually tried that, and it became a bit more complex than I wanted to do in this PR.

Copy link
Member

@laanwj laanwj Mar 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@laanwj
Copy link
Member

laanwj commented Mar 6, 2018

Needs rebase after #11372

@sipa sipa force-pushed the 201711_simpleconvert branch from eb59db5 to 110556f Compare March 7, 2018 04:30
@sipa
Copy link
Member Author

sipa commented Mar 7, 2018

Rebased.

@sipa sipa force-pushed the 201711_simpleconvert branch from 110556f to bc528e6 Compare March 7, 2018 14:57
@sipa
Copy link
Member Author

sipa commented Mar 7, 2018

Added reserves in several places.

@sipa sipa force-pushed the 201711_simpleconvert branch from bc528e6 to b3ea8cc Compare March 7, 2018 15:04
@laanwj
Copy link
Member

laanwj commented Mar 7, 2018

Added reserves in several places.

Thanks!

utACK b3ea8cc

@laanwj laanwj merged commit b3ea8cc into bitcoin:master Mar 7, 2018
laanwj added a commit that referenced this pull request Mar 7, 2018
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
zkbot added a commit to zcash/zcash that referenced this pull request Jun 11, 2018
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.
zkbot added a commit to zcash/zcash that referenced this pull request Jun 19, 2018
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.
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Apr 16, 2020
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
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Apr 16, 2020
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
ftrader pushed a commit to bitcoin-cash-node/bitcoin-cash-node that referenced this pull request Aug 17, 2020
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
ftrader pushed a commit to bitcoin-cash-node/bitcoin-cash-node that referenced this pull request Aug 17, 2020
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
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jan 8, 2021
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants