Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: ggbtctalk000 on September 06, 2017, 06:44:07 AM



Title: bitcoin address calculation deep dive, does not add up
Post by: ggbtctalk000 on September 06, 2017, 06:44:07 AM
Looking through mastering bitcoin book's chapters, I get the following formula for bitcoin address generation:
BitcoinAddress=base58encode( 2 bytes version + 20 bytes output from RIPEMD160(SHA256(pubkey)) + 4 bytes checksum)
= base58encode(26 bytes)=base58encode(104 bits) however this is generating base58 digit size of
104bits / ((log(58)/log(2)) = 104bits/5.8579...=17.75 base58 digits.


Why 104bits / (log(58)/log(2))?
Suppose 256-bits address and how many hexes are there if represented by hex? 256 / ((log 16) / log(2)) = 256/4 = 64 hex digits.

But when I check several bitcoin wallet address the base58encoded address they are showing is 34 base58 digits. Definitely not adding up or I am missing something here.


Title: Re: bitcoin address calculation deep dive, does not add up
Post by: Foxpup on September 06, 2017, 07:58:51 AM
base58encode(26 bytes)=base58encode(104 bits)
I think you'll find 26 bytes is actually 208 bits. ;)


Title: Re: bitcoin address calculation deep dive, does not add up
Post by: DannyHamilton on September 06, 2017, 08:54:34 AM
BitcoinAddress=base58encode( 2 bytes version + 20 bytes output from RIPEMD160(SHA256(pubkey)) + 4 bytes checksum)

Are you sure about that?  I thought:

BitcoinAddress=base58encode( 1 bytes version + 20 bytes output from RIPEMD160(SHA256(pubkey)) + 4 bytes checksum)

1 + 20 + 4 = 25 bytes

Since 1 byte = 8 bits...

25 * 8 = 200 bits
base58encode(25 bytes) = base58encode(200 bits)

200 bits / [ log(58) / log(2) ] = 200 bits / 5.85798... = 34.14 base58 digits


Title: Re: bitcoin address calculation deep dive, does not add up
Post by: ggbtctalk000 on September 06, 2017, 03:02:50 PM
THANKS for both of you guys :) !! now it adds up! why do i always mess up between nibbles and bytes!!  ;D