Skip to content

Conversation

@sipa
Copy link
Member

@sipa sipa commented Apr 12, 2014

This completely removes the bignum-based base58 code, and replaces it with an implementation that directly operates on vectors of bytes / base58 numbers.

@ghost
Copy link

ghost commented Apr 12, 2014

👍

@laanwj
Copy link
Member

laanwj commented Apr 14, 2014

@gmaxwell we can be sure about that. DecodeBase58 is only called from two places in base58.h itself:

  • DecodeBase58(std::string) -> passed string.c_str() which is always zero-terminated
  • DecodeBase58Check(const char*) -> passes through its input which has always been a zero-terminated string

In general I too prefer APIs that explicitly pass the length of strings (or that use a string type with embedded length field like std::string), but it doesn't look like there is reason to change the API here.

@gmaxwell
Copy link
Contributor

:) Yea the "will" was meant to include all future callers. Communication is hard.

@laanwj
Copy link
Member

laanwj commented Apr 14, 2014

Right. It's especially useful to pass a length - or an begin* and end* pointer - if we want to be able to error out on NULs before the real end of the string (whose presence has triggered many browser bugs). It would also allow using std::string.data() and std::string.size() instead of c_str(), which is theoretically slighty more efficient.

Good to keep in mind, but let's not change the API and implementation at the same time, it would interfere with testing :)

The code looks straightforward and correct to me. It passes the tests and we have a fairly good testing suite in place for the Base58 functions.

@luke-jr
Copy link
Member

luke-jr commented Apr 14, 2014

Why reimplement DecodeBase58 and contribute to the current de-modularisation? Seems like a better idea to move libblkmaker's base58.c to its own library and add an encoder...

@gmaxwell
Copy link
Contributor

A library for 74 lines of trivial code? It's kind of an odd duck, in that I don't know what else I'd put in a library with it except 'generic bitcoin stuff'.

@laanwj
Copy link
Member

laanwj commented Apr 14, 2014

We definitely should move the Base58 stuff to a library when we library-ize Bitcoin Core. It's one of the useful functions for other projects. Removing the dependency on OpenSSL helps there, too.

However I certainly don't want to add a dependency on an external library for this (trivial) functionality.

@luke-jr
Copy link
Member

luke-jr commented Apr 14, 2014

@gmaxwell Everything needed to create a raw transaction spending to an address? :)

src/base58.cpp Outdated
Copy link
Member

Choose a reason for hiding this comment

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

I'd say 'leading zeroes'

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@sipa
Copy link
Member Author

sipa commented Apr 14, 2014

@laanwj: I agree that the interface is dangerous (and inconsistent too... mixing c++ style and c style strings/iteration). I'd like to replace that, but let's do that separately.

I've addresses your comments too.

@laanwj
Copy link
Member

laanwj commented Apr 16, 2014

ACK

@laanwj
Copy link
Member

laanwj commented Apr 19, 2014

Needs rebase after #4014 (should be easy as it only affected comments)

@sipa
Copy link
Member Author

sipa commented Apr 19, 2014

Rebased.

src/base58.cpp Outdated
Copy link
Member

Choose a reason for hiding this comment

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

std::vector<unsigned char> b256(strlen(psz) * 733 / 1000 + 1)

Would avoid a realloc.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think empty-constructed vector do any allocation. Still, it can be written in one line.

@theuni
Copy link
Member

theuni commented Apr 22, 2014

Sorry for the late review, I was pinged from one of my PRs so I figured I'd give it a quick look :)

@sipa
Copy link
Member Author

sipa commented Apr 22, 2014

Pushed an update to address @theuni's comments.

This removes the bignum/OpenSSL dependency.

The base58 transformation code is also moved to a separate .cpp file.
@gmaxwell
Copy link
Contributor

Thought I ACKed this already.

gmaxwell added a commit that referenced this pull request Apr 22, 2014
Remove dependency of base58 on OpenSSL
@gmaxwell gmaxwell merged commit e2bff7d into bitcoin:master Apr 22, 2014
@BitcoinPullTester
Copy link

Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/b58be132c994b6f9b25cb4a702186ef96104953f for binaries and test log.
This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/
Contact BlueMatt on freenode if something looks broken.

laanwj added a commit to laanwj/bitcoin that referenced this pull request May 9, 2014
After bitcoin#4076, bitcoin#3965 and bitcoin#4048 bignum.h is only used
for verifying scriptnum.
@laanwj laanwj mentioned this pull request May 9, 2014
@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.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants