Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CID Specification does not define "base58btc" #45

Open
JDLH opened this issue Mar 21, 2021 · 3 comments
Open

CID Specification does not define "base58btc" #45

JDLH opened this issue Mar 21, 2021 · 3 comments

Comments

@JDLH
Copy link

JDLH commented Mar 21, 2021

The CID Specification refers to an encoding/decoding method "base58btc" but does not define what this method is.

I suspect the intended meaning is "Base58 encoding as used by Bitcoin". It might also mean "Base58Check encoding as defined by Bitcoin. Base58Check appears to have properties like: 1. well-defined way of handling leading zero bytes in the binary payload, and thus ability to represent any length of binary payload; 2. a notion of a one-byte "prefix" to which the binary payload is concatenated; 3. a 4-byte checksum which is concatenated to the prefix and payload. It is not clear to me whether or not the CID Specification's term "base58btc" is supposed to include these properties.

I am new to Multiformats and IPFS and Filecoin, so I have a very naive reading of the CID Specification. I did a little web searching, and could not find something which purported to be an authoritative spec for something named "base58btc". There are many pages which describe Base58 representation, and/or Bitcoin's Base58Check encoding, but none of these seemed to claim to be an authoritative specification. I may well have overlooked something.

The Base58 Encoding Scheme is an IETF internet draft by M Sporny. It describes the Base58 alphabet used by Bitcoin, and property 1. above. It does not include properties 2. or 3. This draft is labelled as a "draft", and as expiring in May 2021, so it may not be robust enough to refer to in the CID Specification.

Base58check encoding from the Bitcoin Cash Protocol website appears to have a pretty clear specification for the Base58Check encoding as defined by Bitcoin. I don't know how authoritative it is.

I saw a piece of source code which implemented Base58Check encoding, which quote extensively from Bitcoin source code defining Base58Check encoding. The Bitcoin content was attributed to Satoshi Nakamoto, and was very clear. I don't know where to find an authoritative copy of the Bitcoin source code module containing this quote. Maybe that source code is a good spec to refer to from the CID Specification.

In any case, as a naive software developer attempting to understand the CID Specification, it would be helpful to have a clear reference to what is specified by "base58btc".

@vmx
Copy link
Member

vmx commented Mar 23, 2021

I suspect the intended meaning is "Base58 encoding as used by Bitcoin".

Yes, that is the intended meaning. And the "The Base58 Encoding Scheme is an IETF internet draft by M Sporny" would be the one to implement.

I know, it doesn't make up for a proper specification, but the Multibase repository contains some test vectors, in case you want to check an implementation against base58btc encoding.

I've also opened an issue on the Multibase spec as I think this would be the right place to add the information about which specification a Multibase is based upon.

@rvagg
Copy link
Member

rvagg commented Mar 24, 2021

^ to reinforce @vmx' comment, the reason it's probably not clear is that we're all operating on a collection of assumed knowledge that shouldn't be assumed for the purpose of a spec! The string base58btc specifically comes from the multibase table, line 19: https://github.com/multiformats/multibase/blob/master/multibase.csv#L19

@sg495
Copy link

sg495 commented Oct 20, 2021

Just a note here that the third test vector in the base58 spec is wrong: it states that the base58-encoded value of 0x0000287fb4cd is 111233QC4, but it should be 11233QC4 instead. I implemented the spec myself, I checked it against the Python base58 library, and they both agree:

>>> import base58 # https://github.com/keis/base58
>>> base58.b58encode(bytes([0x00,0x00,0x28,0x7F,0xB4,0xCD]))
b'11233QC4'

This consolidates my impression that the base58 spec was a actually just a draft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants