Bitcoin Forum
December 11, 2017, 02:55:05 AM *
News: Latest stable version of Bitcoin Core: 0.15.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: [Maybe Solved]More Wiki-fun, base58check encoding.  (Read 1160 times)
Richy_T
Legendary
*
Offline Offline

Activity: 1330


1RichyTrEwPYjZSeAYxeiFBNnKC9UjC5k


View Profile
November 27, 2013, 03:27:35 AM
 #1

So, wiki says

Quote
8 - Add the 4 checksum bytes from point 7 at the end of extended RIPEMD-160 hash from point 4. This is the 25-byte binary Bitcoin Address.

   00010966776006953D5567439E5E39F86A0D273BEED61967F6

9 - Convert the result from a byte string into a base58 string using Base58Check encoding. This is the most commonly used Bitcoin Address format

   16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM

So let's pop over to the base58check encoding page.

Quote
Take the version/application byte and payload bytes, and concatenate them together (bytewise).
Take the first four bytes of SHA256(SHA256(results of step 1))
Concatenate the results of step 1 and the results of step 2 together (bytewise).

So at this stage, we have 0000010966776006953D5567439E5E39F86A0D273BEED61967F6xxxxxxxx

where the xxxx is the four bytes of the sha of the sha.

Then

Quote
Treating the results of step 3 - a series of bytes - as a single big-endian bignumber, convert to base-58 using normal mathematical steps (bignumber division) and the base-58 alphabet described below. The result should be normalized to not have any leading base-58 zeroes (character '1').
The leading character '1', which has a value of zero in base58, is reserved for representing an entire leading zero byte, as when it is in a leading position, has no value as a base-58 symbol. There can be one or more leading '1's when necessary to represent one or more leading zero bytes. Count the number of leading zero bytes that were the result of step 3 (for old Bitcoin addresses, there will always be at least one for the version/application byte; for new addresses, there will never be any). Each leading zero byte shall be represented by its own character '1' in the final result.
Concatenate the 1's from step 5 with the results of step 4. This is the Base58Check result.

So there are two leading zero bytes. So this address would begin 11? But the address above begins 16. So this can't be right?

Then there's the bit on the page under "Encoding a Bitcoin address" that says "A Bitcoin address is the Base58Check encoding of the hash of the associated script." Script? The stuff on https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses doesn't mention anything about scripts.

Can anyone clarify this for me? I feel like I'm so close but it seems like there's a comprehension gap. These wiki pages really need some fleshing out but last time I attempted to create an account to modify a different page, there appeared to be no way to be able to.





1RichyTrEwPYjZSeAYxeiFBNnKC9UjC5k
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1512960905
Hero Member
*
Offline Offline

Posts: 1512960905

View Profile Personal Message (Offline)

Ignore
1512960905
Reply with quote  #2

1512960905
Report to moderator
1512960905
Hero Member
*
Offline Offline

Posts: 1512960905

View Profile Personal Message (Offline)

Ignore
1512960905
Reply with quote  #2

1512960905
Report to moderator
Richy_T
Legendary
*
Offline Offline

Activity: 1330


1RichyTrEwPYjZSeAYxeiFBNnKC9UjC5k


View Profile
November 27, 2013, 04:41:36 AM
 #2

Has anyone seen what is up here?

The Wiki says to follow steps... then to do the base58check encoding.

But the base58check encoding includes the steps that have already been done.

This might have been possible to spot if the wiki page had mentioned what they were actually doing, like prepending the version number but it just states that it's prepending a 0.

Grrr.

1RichyTrEwPYjZSeAYxeiFBNnKC9UjC5k
danneu
Jr. Member
*
Offline Offline

Activity: 32



View Profile
November 27, 2013, 08:16:28 AM
 #3

Here's my code. It's a function named `->address` that accepts `pubkey` data, concats together one sequence of `version+hash160+checksum` bytes, and base58 encodes it.

Code:
;; ByteArray -> String
(defn ->address [pubkey]
  (let [ver         (into-byte-array [0x00])
        hash160     (crypto/hash160 pubkey)  ;; (hash160 _) is (rmd160 (sha256 _))
        ver+hash160 (concat-bytes ver hash160)
        checksum    (crypto/calc-checksum ver+hash160)
        ver+hash160+checksum (concat-bytes ver+hash160 checksum)]
    (base58-encode ver+hash160+checksum)))

(->address "0450863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b23522cd470243453a299fa9e77237716103abc11a1df38855ed6f2ee187e9c582ba6")
;;=> "16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM"

The version-byte is actually determined by the network:

Code:
(def networks
  {:mainnet {:address/ver (byte 0x00)}
   :testnet3 {:address/ver (byte 0x6f)}})

Also, if you base58-encode a byte-array with leading 0-bytes, each 0-byte gets converted into a "1".

From bitcoin's test suite, "00000000000000000000" (hex) gets base58-encoded into "1111111111" (string).

In general, if the wiki doesn't help you, then check out any of the 50 partial bitcoin implementations and cross-examine them.
Richy_T
Legendary
*
Offline Offline

Activity: 1330


1RichyTrEwPYjZSeAYxeiFBNnKC9UjC5k


View Profile
November 27, 2013, 02:47:21 PM
 #4

I worked it out from bitaddress.org. Which was a little work as I'm not real up on OO Javascript but it was good enough. Now I have the data for the key, I just need to do the leading-zeros part.

1RichyTrEwPYjZSeAYxeiFBNnKC9UjC5k
FreedomDealer
Newbie
*
Offline Offline

Activity: 7


View Profile
November 27, 2013, 03:24:22 PM
 #5

The "Technical_background_of_Bitcoin_addresses" wiki page is executing the steps 1, 2 and 3 from the "Base58Check_encoding" wiki. It should contain only this 5 steps instead:

0 - same
1 - same
2 - same
3 - same
4 - Convert the result from a byte string into a base58 string using <Base58Check encoding> (for Main Network, use 0x00 as version byte). This is the most commonly used Bitcoin Address format.
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!