digitalbazaar / base58-spec

The Base58 Encoding Scheme
https://digitalbazaar.github.io/base58-spec/
2 stars 5 forks source link

Encoding & Decoding Algorithms #3

Open harrigan opened 4 years ago

harrigan commented 4 years ago

The algorithms in Sections 3 and 4 do not fully describe the encoding and decoding processes. They broadly follow the algorithms implemented in Bitcoin's source code [1], e.g. multiplying a byte value by 256 and adding it to a carry. However, the algorithms in the source code are based on two nested loops (e.g. the while loop on line 100 and the for loop on line 104) whereas the algorithms in the spec are based on a single loop.

I am working on a PR to fix this.

[1] https://github.com/bitcoin/bitcoin/blob/master/src/base58.cpp#L87

devbanana commented 3 years ago

Yeah I'd love to see a better description. I've been pouring over this all day trying to figure out what I was missing. In particular, this line makes no sense to me:

For each byte in the array of bytes and while 'carry' does not equal zero (0x0) after the first iteration:

Also there's no mention that carry should be initialized to the current byte's value.

msporny commented 3 years ago

The algorithms in Sections 3 and 4 do not fully describe the encoding and decoding processes.

That is my fault, the descriptions are horrible. I was hoping to be able to come back and fix them in time, but my current spec editing load is quite heavy.

I'd be thrilled if someone could do a better job and provide a PR. I'd be happy to merge it and re-publish a newer spec as a result.

Let me know when your PRs are ready @harrigan or @devbanana