Author

Topic: Is the wiki incorrect about length of addresses. (Read 2314 times)

legendary
Activity: 1246
Merit: 1077
0000000000000000000000000000000000000000
1111111111111111111114oLvT2

27 characters

0000000000000000000000000000000000000001
11111111111111111111BZbvjr
26 characters

This fact always surprises people. Wink

Another related surprise is that version-zero addresses are on average longer than version-one addresses, due to Satoshi's inefficient encoding of the zero byte. The only exceptions are those addresses with multiple leading zeroes.
legendary
Activity: 1386
Merit: 1053
Please do not PM me loan requests!
0000000000000000000000000000000000000000
1111111111111111111114oLvT2

27 characters

0000000000000000000000000000000000000001
11111111111111111111BZbvjr
26 characters

This fact always surprises people. Wink
I thought I remember a 26 character address! I assumed I just miscounted the first one. Color me surprised Grin
I guess I'll update the wiki accordingly. Welp you already did. Tongue
administrator
Activity: 5222
Merit: 13032
0000000000000000000000000000000000000000
1111111111111111111114oLvT2

27 characters

0000000000000000000000000000000000000001
11111111111111111111BZbvjr
26 characters

This fact always surprises people. Wink
legendary
Activity: 1386
Merit: 1053
Please do not PM me loan requests!
0000000000000000000000000000000000000000
1111111111111111111114oLvT2

27 characters

FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1QLbz7JHiBTspS962RLKV8GndWFwi5j6Qr

34 characters
member
Activity: 96
Merit: 10
esotericnonsense
Here is the exact address hash (with fake checksum) where addresses would change into 35 bytes of base58. Remember in Base58 that 2=1 and 1=0, so we want to find the network byte + 20 + 4 where addresses of that network byte start to have 35 character long addresses:


>>> dice2key.changebase('21111111111111111111111111111111111', 58, 16)
'90248722fa0bf5a28a9dfee80227dc40a4d518272400000000'

>>> dice2key.changebase('90248722fa0bf5a28a9dfee80227dc40a4d518272400000000', 16, 58)
'21111111111111111111111111111111111'

>>> len('21111111111111111111111111111111111')
35
>>>


That is a network byte of 90 (144 decimal). From the start of 35 byte addresses being 0x90 + 0x2487.... 9351/65536 = 85.7% of addresses using network byte 90 will be 35 digit. All network bytes above 0x90 will be 35 digit addresses starting with 2.

This agrees with: https://en.bitcoin.it/wiki/List_of_address_prefixes

Yes. A 35 character address has a number representation >= 58**34.
>>> hex(58**34)
'0x90248722fa0bf5a28a9dfee80227dc40a4d518272400000000'

For fun:
Base58(58**34 - 1) = 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'

(But yes, neither of these are valid due to checksum).
legendary
Activity: 1512
Merit: 1036
Here is the exact address hash (with fake checksum) where addresses would change into 35 bytes of base58. Remember in Base58 that 2=1 and 1=0, so we want to find the network byte + 20 + 4 where addresses of that network byte start to have 35 character long addresses:


>>> dice2key.changebase('21111111111111111111111111111111111', 58, 16)
'90248722fa0bf5a28a9dfee80227dc40a4d518272400000000'

>>> dice2key.changebase('90248722fa0bf5a28a9dfee80227dc40a4d518272400000000', 16, 58)
'21111111111111111111111111111111111'

>>> len('21111111111111111111111111111111111')
35
>>>


That is a network byte of 90 (144 decimal). From the start of 35 byte addresses being 0x90 + 0x2487.... 9351/65536 = 85.7% of addresses using network byte 90 will be 35 digit. All network bytes above 0x90 will be 35 digit addresses starting with 2.

This agrees with: https://en.bitcoin.it/wiki/List_of_address_prefixes
legendary
Activity: 3472
Merit: 4801
Where were you?! :-)

Right here.  Take a look at my posting history.  I've been around this forum quite a bit for the past 2 years.
donator
Activity: 1218
Merit: 1079
Gerald Davis
Quote
Assume a 20 byte hash value of 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

For a P2PkH address it would be 1QLbz7JHiBTspS962RLKV8GndWFwi5j6Qr and yes it is 34 digits.


You are right any version below a certain value will be 34 or less digits.  I was thinking full bytes but as you point out it is the bits that matter.  Even P2SH (0x05) only needs 4 bits.

So 34 *log2(58) = 199 bits.  As long as the value to be encoded is less than or equal to the max 199 bit number it won't require 35 bytes.  So with a 160 bit hash and 32 bit checksum that leaves 7 bits for version.  The largest 7 bit uint is 127 (0x7f).  

Just a heads up (which I didn't realize until now) testnet uses version 196 (0xc4) for P2SH addresses.
full member
Activity: 238
Merit: 100
- snip -
1 byte version
- snip -

I think this is where you've made the mistake if I'm correct.

With bitcoin addresses the version is currently represented with either a single "1" or "3".  This makes it more of a 2 bit version than a 1 byte version.  Unless significantly larger version numbers are used in the future, there really isn't much chance that the full byte will be used any time soon.  Therefore, you'll never see the extra 35th digit that would be needed to represent for example a version byte of 0x3C.
You are correct. Had an issue with a chain 5 months ago, had to go through a lot of documentation to figure out what's going on.Where were you?! :-)
legendary
Activity: 3472
Merit: 4801
If you're still uncertain, prove it to yourself.

Assume a 20 byte hash value of 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Then calculate the bitcoin address.

That should give you the largest possible bitcoin address (and therefore the maximum possible characters), right?
legendary
Activity: 1246
Merit: 1077
In byte form it is simply a sequence of bytes.  For addresses it is 25 bytes long.  It may begin with a 0x00 byte but it may not.   Because Satoshi likes to make things difficulty a preprocessing step is done where ALL leading 0x00 bytes are replaced with a "1".   Note this doesn't make the addresses shorter unless there are at least 2 or more leading zero bytes.  For addresses this would require the version to be zero (P2KhH) AND the leading byte(s) of the hash are also zero.  

A version byte of zero doesn't result in a smaller address than any other version UNLESS the hash also starts with a zero.  The version byte refers to Bitcoin address versions (although altcoins lazily co-opted them).  There are versions other than zero in use right now, P2SH addresses use 0x05.

Note that replacing an entire byte with one character "1" effectively encodes 8 bits worth of information in a single base-58 character. It then remains to encode the remaining 24 bytes in 33 base-58 characters, which by your formula is possible. Hence version-0 addresses fit in 34 characters.

Version-5 addresses (P2SH) also fit in 34 characters because the version byte is small enough to ensure that the base-58 conversion does not overflow to the 35th character. This can be demonstrated by noting that log58(6×28×24) is merely 33.2, and the value being logged is strictly higher than all version-5 addresses.
donator
Activity: 1218
Merit: 1079
Gerald Davis
On edit: deleted prior post.  I realized I misunderstood azeteki's post when I saw Danny's.

Yeah that makes sense now.  Well I made my db fields 35 bytes so I guess I am "version 60+" compliant.

Quote
With bitcoin addresses the version is currently represented with either a single "1" or "3".

Just to be clear those are the resulting leading Base58 digits.  P2PkH is 0x00 and P2SH is 0x05 on main-net and 0x6f and 0xc4 on testnet.

legendary
Activity: 3472
Merit: 4801
- snip -
1 byte version
- snip -

I think this is where you've made the mistake if I'm correct.

With bitcoin addresses the version is currently represented with either a single "1" or "3".  This makes it more of a 2 bit version than a 1 byte version.  Unless significantly larger version numbers are used in the future, there really isn't much chance that the full byte will be used any time soon.  Therefore, you'll never see the extra 35th digit that would be needed to represent for example a version byte of 0x3C.
member
Activity: 96
Merit: 10
esotericnonsense
The version byte is in the low end of the range.

Mainnet addresses are prefixed 0x00, for example.

See https://en.bitcoin.it/wiki/List_of_address_prefixes.
The longest addresses are indeed 35 characters. But they are not 'Bitcoin' addresses, because we don't use those prefixes.
legendary
Activity: 1246
Merit: 1077
Quote
A Bitcoin address, or simply address, is an identifier of 27-34 alphanumeric characters, beginning with the number 1 or 3, that represents a possible destination for a Bitcoin payment. Addresses can be generated at no cost by any user of Bitcoin. For example, using Bitcoin-Qt, one can click "New Address" and be assigned an address. It is also possible to get a Bitcoin address using an account at an exchange or online wallet service.

An example of a Bitcoin address is 3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy.
https://en.bitcoin.it/wiki/Address


Decoded an address consists of
20 byte payload/hash
4 byte checksum
1 byte version
--------------------
total: 25 bytes

34 symbols * Log2(58)/8 bytes  per symbol = 24.896 bytes

So 35 digits?

I think all currently-used versions have a maximum of 34 characters, because of leading zeroes, but some alt-coin versions can go up to 35.
donator
Activity: 1218
Merit: 1079
Gerald Davis
Quote
A Bitcoin address, or simply address, is an identifier of 27-34 alphanumeric characters, beginning with the number 1 or 3, that represents a possible destination for a Bitcoin payment. Addresses can be generated at no cost by any user of Bitcoin. For example, using Bitcoin-Qt, one can click "New Address" and be assigned an address. It is also possible to get a Bitcoin address using an account at an exchange or online wallet service.

An example of a Bitcoin address is 3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy.
https://en.bitcoin.it/wiki/Address


Decoded an address consists of
20 byte payload/hash
4 byte checksum
1 byte version
--------------------
total: 25 bytes

34 symbols * Log2(58)/8 bytes  per symbol = 24.896 bytes

So 35 digits?
Jump to: