Author

Topic: Finding total number of BTC wallets starting from selected prefix (Read 486 times)

full member
Activity: 706
Merit: 111
I have a question.
Is there any ready script e.g. in PHP or JavaScript which I could check the number of all BTC addresses starting with the prefix indicated? Suppose I would like to know the number of all addresses starting with "1Bitcoin". I mean the total number resulting from ECDSA rules (so regardless of balance).

The number of all BTC addresses starting with a prefix indicated is:

2^160 / (difficulty of that vanity address).

Then you need a software to compute the difficulty.

example:

prefix 1A  --> difficulty = 22 -->  number of all BTC addresses starting with 1A =  2^160  /  22

= 66431892605950132645622037850740137257087842862


Here some details:

https://bitcoin.stackexchange.com/questions/48586/best-way-to-calculate-difficulty-of-generating-specific-vanity-address

Quote
Difficulty is basically number_of_all_possible_addresses / number_of_addresses_with_vanity_prefix rate.


Here a old software:

https://github.com/fordhurley/vanitycalc





Of this number 66431892605950132645622037850740137257087842862 how many of those keys are compressed?
sr. member
Activity: 443
Merit: 350
...
First symbol of the addreess is always "1" (5.85798 bits of information). However as the first 8 bits are always predefined, so the remaining 2.142 bits influence on the 2nd symbol of the address: 8/5.85798 = 1.3656 symbols are used to store 8 predefined bits of '00' prefix.
...
Easy example: let's take 160bit number consists of all 0s (so it is 40 hex '0'). We add '00' prefix, and add checksum '94a00911' to the end. After that we convert the received number to Base58 and receive the valid bitcoin address: 1111111111111111111114oLvT2.
You have to handle the initial '1's separately. In the base58check encoding scheme, initial groups of 8 0-bits are encoded as '1's, and base-58 encoding starts after those groups. The encoding for 0 is 21 '1's (8-bit prefix of 0 plus 160-bit value of 0), followed by the base-58 encoding of the checksum -- 1111111111111111111114oLvT2

I am not sure if I understood you correctly. However the initial "1" is not used in the calcualtion actually. I deducted it because wrote the "total bits" length as 200bits, but this number included the first 8 bits of "00" byte. So, actual information to be coded is 160bit hash plus 32 bit checksum (192bit).

The issue is that not only the first 1 must be handled differently, but all of the initial 1's. The problem can be clearly demonstrated with this sequence: "111111111111111111111". According to your formula, the number of possble addresses that start with "111111111111111111111" is 5827.3132 - 20 = 587.3132 = 7.88x1012, but the correct answer is 1: 1111111111111111111114oLvT2.

It seems like you are right. Later I will check this. I calcualted all the possibilities based on the total length of the address. However "00" bytes decrease the length of the address.

Is it really just only one address starting with 20 "1"? ) Actually 21 "1" with prefix and plus 6 check sum symbols.
legendary
Activity: 4466
Merit: 3391
...
First symbol of the addreess is always "1" (5.85798 bits of information). However as the first 8 bits are always predefined, so the remaining 2.142 bits influence on the 2nd symbol of the address: 8/5.85798 = 1.3656 symbols are used to store 8 predefined bits of '00' prefix.
...
Easy example: let's take 160bit number consists of all 0s (so it is 40 hex '0'). We add '00' prefix, and add checksum '94a00911' to the end. After that we convert the received number to Base58 and receive the valid bitcoin address: 1111111111111111111114oLvT2.
You have to handle the initial '1's separately. In the base58check encoding scheme, initial groups of 8 0-bits are encoded as '1's, and base-58 encoding starts after those groups. The encoding for 0 is 21 '1's (8-bit prefix of 0 plus 160-bit value of 0), followed by the base-58 encoding of the checksum -- 1111111111111111111114oLvT2

I am not sure if I understood you correctly. However the initial "1" is not used in the calcualtion actually. I deducted it because wrote the "total bits" length as 200bits, but this number included the first 8 bits of "00" byte. So, actual information to be coded is 160bit hash plus 32 bit checksum (192bit).

The issue is that not only the first 1 must be handled differently, but all of the initial 1's. The problem can be clearly demonstrated with this sequence: "111111111111111111111". According to your formula, the number of possble addresses that start with "111111111111111111111" is 5827.3132 - 20 = 587.3132 = 7.88x1012, but the correct answer is 1: 1111111111111111111114oLvT2.
legendary
Activity: 1932
Merit: 2077
I have only computed the difficulty with 3 different programs:

vanitygen 1A --> difficulty 22

supervanitygen 1A --> difficulty 23

VanitySearch 1A --> difficulty 23


with difficulty 23
63543549449169692095812384031142739985040545346 = 58^26.540959790286436

with difficulty 22
66431892605950132645622037850740137257087842862 = 58^26.55190730573127

your formula = 58^(160/(math.log2(58) - 1) = 58^26.313164746195223  gives a different result.


The difficulty in your case would be = 2^160 / 58^26.31316 = about 58, pretty different from 22-23 (it couldn't be some "roundings")


Now the question is: the difficulty computation is wrong or this formula?


If the number of the addresses depends only from the length of the prefix,

why:

vanitygen 1A => 22
vanitygen 1Q => 66
vanitygen 1R => 1354


More details here:

https://bitcoin.stackexchange.com/questions/48586/best-way-to-calculate-difficulty-of-generating-specific-vanity-address
sr. member
Activity: 443
Merit: 350
...
First symbol of the addreess is always "1" (5.85798 bits of information). However as the first 8 bits are always predefined, so the remaining 2.142 bits influence on the 2nd symbol of the address: 8/5.85798 = 1.3656 symbols are used to store 8 predefined bits of '00' prefix.
...
Easy example: let's take 160bit number consists of all 0s (so it is 40 hex '0'). We add '00' prefix, and add checksum '94a00911' to the end. After that we convert the received number to Base58 and receive the valid bitcoin address: 1111111111111111111114oLvT2.
You have to handle the initial '1's separately. In the base58check encoding scheme, initial groups of 8 0-bits are encoded as '1's, and base-58 encoding starts after those groups. The encoding for 0 is 21 '1's (8-bit prefix of 0 plus 160-bit value of 0), followed by the base-58 encoding of the checksum -- 1111111111111111111114oLvT2

I am not sure if I understood you correctly. However the initial "1" is not used in the calcualtion actually. I deducted it because wrote the "total bits" length as 200bits, but this number included the first 8 bits of "00" byte. So, actual information to be coded is 160bit hash plus 32 bit checksum (192bit).

I made a simple formula depending only on the quantity of the defined symbols. I think it is easy to use. The full formula without roundings is:

58^((200/(Log2(58)/Log2(2))-32/(Log2(58)/Log2(2))-8/(Log2(58)/Log2(2)) - x) = 58^((160/(Log2(58)/Log2(2)) - x), where x is the number of predefined symbols in address.

Check the result of this formula with your calculations, and I beleive that we have the same results. I use the power of 58, and use the power of 2

But of course we can easily transform the formula from the power of 58 to the power of 2. As 58 = 2^(Ln58/Ln2), so:

58^((160/(Log2(58)/Log2(2)) - x) = 2(ln58/ln2)*(160/(ln58/ln2) - x) = 2(160 - x * (ln58/ln2))
sr. member
Activity: 443
Merit: 350
Now the total number of addresses where you predefine such symbols could be calculated in the following way:

58 ^ (34.1414 - 6.8282 - x) = 58 ^ (27.3132 - x), where x is the number of your predefined symbols (excluding 1st "1").

zielar, probably this formula will be easier for you if you do not wish to decode Base58 address to bits and calculate in bits. But the results should be the same as in odolvlobo's formula.
No, this formula is not correct.
-snip-

Can you tell which step of my logic is not correct? T obe honest I can not rely just on your calcualtions where you took "difficulty" number which is not proved (i guess there are some roundings are applied, as these difficulties are used for vanity search and based on birthday paradox). I wrote the formula where only one dependency - quantity of predefined symbols. I guess this is the right thing to have.

Now the total number of addresses where you predefine such symbols could be calculated in the following way:

58 ^ (34.1414 - 6.8282 - x) = 58 ^ (27.3132 - x), where x is the number of your predefined symbols (excluding 1st "1").

zielar, probably this formula will be easier for you if you do not wish to decode Base58 address to bits and calculate in bits. But the results should be the same as in odolvlobo's formula.
-snip-
prefix 1ABC -> difficulty 77178 --> all addresses starting with 1ABC = 2^160 / 77178 =
18936764846600105188054689584030203162247435  = 58^24.54157808

At least my formula gives the same result as odolvlobo's calculations. For example, for 3 digits odolvlobo wrote the result as 2^142.43.  Under my formula I have the same result: 58^(27.3132-3) = 58^24.3132 = 2^142.426263.
You are saying that for 3 digits the result is 58^24.54157808 which is 2^143.764, the bigger number (approx. 2.5 times bigger).

Why my formula gives the same result as odolvlobo's, but your calculation is different?
legendary
Activity: 1932
Merit: 2077
Now the total number of addresses where you predefine such symbols could be calculated in the following way:

58 ^ (34.1414 - 6.8282 - x) = 58 ^ (27.3132 - x), where x is the number of your predefined symbols (excluding 1st "1").

zielar, probably this formula will be easier for you if you do not wish to decode Base58 address to bits and calculate in bits. But the results should be the same as in odolvlobo's formula.

No, this formula is not correct.


For example, prefix 1A:

with your formula:

58 ^ (27.3132 - x) = 58^26.3132 =
25201911388171680000000000000000000000000000000


but

prefix 1A -> difficulty 22 --> all addresses starting with 1A = 2^160 / 22 = 66431892605950132645622037850740137257087842862 = 58^26.5519073

prefix 1AB -> difficulty 1330 --> all addresses starting with 1AB = 2^160 / 1330 =
1098873411526994675341116415576152646357844017  = 58^25.541699366

prefix 1ABC -> difficulty 77178 --> all addresses starting with 1ABC = 2^160 / 77178 =
18936764846600105188054689584030203162247435  = 58^24.54157808
legendary
Activity: 4466
Merit: 3391
...
First symbol of the addreess is always "1" (5.85798 bits of information). However as the first 8 bits are always predefined, so the remaining 2.142 bits influence on the 2nd symbol of the address: 8/5.85798 = 1.3656 symbols are used to store 8 predefined bits of '00' prefix.
...
Easy example: let's take 160bit number consists of all 0s (so it is 40 hex '0'). We add '00' prefix, and add checksum '94a00911' to the end. After that we convert the received number to Base58 and receive the valid bitcoin address: 1111111111111111111114oLvT2.

You have to handle the initial '1's separately. In the base58check encoding scheme, initial groups of 8 0-bits are encoded as '1's, and base-58 encoding starts after those groups. The encoding for 0 is 21 '1's (8-bit prefix of 0 plus 160-bit value of 0), followed by the base-58 encoding of the checksum -- 1111111111111111111114oLvT2
sr. member
Activity: 443
Merit: 350
Agree with odolvlobo and with calculations in bit.

Bitcoin address is Base58 from HEX address, where HEX address is '00' byte + 160bit encrypted key + 4 bytes checksum.
- prefix '00' byte is always '00' and it is 1 byte, or 8 bit length
- 160bit encrypted key is ripemd160 from sha256 of public key - so it has 160bit length
- check sum is 4 bytes, or 32 bit length.

So, HEX address is 2 + 40 + 8 = 50 hex symbols, or 8 + 160 + 32 = 200 bit length, where first 8 bits always the same, and last 32 bits are just the checksum.

For bit number every symbol has 2 possibilities (1 or 0). But the address is in Base58 formmat, so every symbol of that number could have 58 different options.

Each Base58 address symbol contains Log2(58)/Log2(2) = 5.85798 bits of information.

First symbol of the addreess is always "1" (5.85798 bits of information). However as the first 8 bits are always predefined, so the remaining 2.142 bits influence on the 2nd symbol of the address: 8/5.85798 = 1.3656 symbols are used to store 8 predefined bits of '00' prefix. The last 32 / 5.85798 = 5.4626, actually 5 are also could not be random, and represent the checksum. The residual 0.4626 bits influence the 6th symbol from the last. Total defined number of symbols is 1.3656 + 5.4626 = 6.8282.

Usually legacy bitcoin addresses are 33-34 symbols long, however the maximum possible length is 200 bit / 5.85798 = 34.1414, so 35 symbols (because the 35th symbol will be used to code the remaining 0.1414 bits of information).

Now the total number of addresses where you predefine such symbols could be calculated in the following way:

58 ^ (34.1414 - 6.8282 - x) = 58 ^ (27.3132 - x), where x is the number of your predefined symbols (excluding 1st "1").

zielar, probably this formula will be easier for you if you do not wish to decode Base58 address to bits and calculate in bits. But the results should be the same as in odolvlobo's formula.

P.S. Also very important to add that this total number of possible addresses is calculated just based on the probability of all possible combinations, however no ECDSA rules are used. ECDSA is used only to convert private key (256 bit number) to public key (point on ECDSA curve). The public key later is hashed by SHA256 and RIPEMD160 resulting the 160bit number. We assume that any 160bit number is a valid bitcoin address, but you can not know the private key to that number due to ECDSA security.

Easy example: let's take 160bit number consists of all 0s (so it is 40 hex '0'). We add '00' prefix, and add checksum '94a00911' to the end. After that we convert the received number to Base58 and receive the valid bitcoin address: 1111111111111111111114oLvT2. This address is valid, and we know that zero 160bit hash number was used to create it, but how could find the private key? You need the private key resulting to the public key which RIPEMD160/SHA256 hash is 0. Nobody knows if such private key exist, but continues to send bitcoins to this address  Wink
legendary
Activity: 1932
Merit: 2077
I have a question.
Is there any ready script e.g. in PHP or JavaScript which I could check the number of all BTC addresses starting with the prefix indicated? Suppose I would like to know the number of all addresses starting with "1Bitcoin". I mean the total number resulting from ECDSA rules (so regardless of balance).

The number of all BTC addresses starting with a prefix indicated is:

2^160 / (difficulty of that vanity address).

Then you need a software to compute the difficulty.

example:

prefix 1A  --> difficulty = 22 -->  number of all BTC addresses starting with 1A =  2^160  /  22

= 66431892605950132645622037850740137257087842862


Here some details:

https://bitcoin.stackexchange.com/questions/48586/best-way-to-calculate-difficulty-of-generating-specific-vanity-address

Quote
Difficulty is basically number_of_all_possible_addresses / number_of_addresses_with_vanity_prefix rate.


Here a old software:

https://github.com/fordhurley/vanitycalc
legendary
Activity: 4466
Merit: 3391
A Bitcoin address is a base-58 encoding of a prefix byte followed by a 160 bit-hash followed by a checksum. To determine the number of possible addresses, follow these steps:

1. Decode the address prefix ("1Bitcoin" in your example) and determine the number of bits in the decoded data, N.
2. Subtract 8 from N to get the number of bits in the decoded portion of the 160-bit hash, P.
3. Subtract P from 160 to get the number of remaining bits in the hash, R.
4. The number of possible addresses is 2R. Note that this assumes that every 160-bit value is part of a legitimate address. That is likely, but it is not guaranteed.

In theory, I think it is possible to determine the number of decoded bits in #1, but I don't think it is as easy as it looks. I think you can calculate the number of bits by counting the number of characters following the initial 1's and multiplying that by 5.85 (ln 58 / ln 2) and then adding 8 times the number of initial 1's.

For example, 1BTC decodes to 25.57 bits of data (3 x 5.85 + 8 ).
1. N = 25.57
2. P = 17.57
3. R = 142.43
4. The number of possible addresses is 2142.43
full member
Activity: 281
Merit: 114
if you don't care about it being used or not then just generate an address via whatever algo you are talking about and check whether its checksum validates. the only requirement for a bitcoin address is that the checksum validate. you don't need the blockchain to do this.

also afaik abe isn't maintained anymore. you may want to look at electrumx for something similar.

Thanks for the answer.
I see that you understand what I mean ...
However, I would like to remind you an important point:
1. I need a solution that will give me the number of possibilities with the prefix, not verification of the correctness of a single address
2. The question concerns knowledge about an existing solution that I once saw somewhere ... I am not a programmer or a person with above-average mathematical knowledge to create something new.
legendary
Activity: 3682
Merit: 1580
if you don't care about it being used or not then just generate an address via whatever algo you are talking about and check whether its checksum validates. the only requirement for a bitcoin address is that the checksum validate. you don't need the blockchain to do this.

also afaik abe isn't maintained anymore. you may want to look at electrumx for something similar.
full member
Activity: 281
Merit: 114
As I mentioned. I am interested in determining the number of possible occurrences of addresses with a selected prefix on the basis of syntax features resulting from a specific algorithm, and not the occurrence of used addresses.

P.S. a year ago I gave up on creating a local blockchain with the help of abe (for other reasons)
On the best optimized configuration (MariaDB + CGI + 24GB RAM etc.) after four months after four months of uninterrupted operation - I was able to barely reach 400,000, and the view of synchronization of the next ones allowed me to cheat with the fact that despite being 30 years old - I think that i will die before sync finish.😁
hero member
Activity: 1220
Merit: 612
OGRaccoon
What you could do is download the chain and setup bitcoin ABE locally then scrape with a custom script for the address prefixes.
I have yet to see something like this to scrape  for specific addresses from the chain.

Another thing you could do is setup ABE and scrape the data to a MySQL data base I did this in the past took a few weeks to actually populate the data here is a guide below how to setup Bitcoin ABE  and setup the database.


Code:
    SETUP

  :Required:

Ubuntu, MySQL Python, MySQL Client, MySQL Server, Python, Python2, Blockchain,

Downloading the bitcoin blockchain two options. 

1. Download & Install bitcoin core wallet and sync with network


################################################################################

Install Python MySQL


$ sudo apt-get install python-mysqldb

    Install MySQL Client & Server

$ sudo apt-get install mysql-client mysql-server

To configure the MySQL instance with InnoDB engine support. 
If you installed with Debian/Ubuntu then InnoDB is enabled by default. 
To check for InnoDB support, issue "SHOW ENGINES" and look in the output
for "InnoDB" with "YES" next to it.  If "skip-innodb" appears in the server
configuration (my.cnf or my.ini) then remove it and restart the server.

################################################################################

SETUP MYSQL

Log into MySQL as root (i.e: mysql -u root) and give commands.
Don't forget to change the PASSWORD

    create database abe;
    CREATE USER 'abe'@'localhost' IDENTIFIED BY 'YOUR_PASSWORD_HERE';
    grant all on abe.* to abe;

The above will

1.  Create a database called abe
2.  Create a user called abe for localhost with the password you enter above
3.  Will grant all permisions to abe for abe user


################################################################################

DOWNLOAD AND INSTALL BITCOIN-ABE

This will allow you to check getrecievedbyaddress calls quickly without being rate limited by online API checkers.

$ git clone https://github.com/bitcoin-abe/bitcoin-abe.git
cd bitcoin-abe
python setup.py install

once installed open file abe.conf
(Included is a copy of the file with section uncommented all you need to do is edit the password and DB info if you changed it)
If You use the original config file from abe you will need to follow steps below and uncomment and modify lines.

################################################################################

abe.conf GUIDE

uncomment lines 33 & 34 and update line 34 with your password / user and db info for MySQL

# MySQL example; see also README-MYSQL.txt:
dbtype MySQLdb
connect-args {"user":"abe","db":"abe","passwd":"YOUR_PASSWORD_HERE"}

Uncomment lines 57 & 58

# Specify port and/or host to serve HTTP instead of FastCGI:
port 2750
host localhost

This will open port 2750 on localhost to allow the wallet checker to connect to the API

Next scroll down to the section where datadir is listed, you must specifiy the path to the blockchain directory this path should contain the bitcoin.conf & blocks & chainstate folders.

Uncomment Lines 136 / 137 / 139 / 140
**Do not uncomment line 138 "loader"**  as we are not caling via RPC rather via the API and http request to gettecievedbyaddress + addy

datadir += [{
        "dirname": "/path/to/blockchain",
#        "loader": "rpc",    # See the comments for default-loader below.
        "chain": "Bitcoin"
      }]

################################################################################

START THE IMPORT

You can now start to load the data to abe from the blockchain run the following command from the bitcoin-abe-master dir

$ python -m Abe.abe --config abe.conf --commit-bytes 100000 --no-serve --datadir /path/to/blockchain

You should see output like:

block_tx 1 1
    block_tx 2 2
block_tx 3 3
    block_tx 4 4
block_tx 5 5
    block_tx 6 6
block_tx 7 7
    block_tx 8 8

( THIS PROCESS WILL TAKE A VERY LONG TIME POSSIBLY 2-6 DAYS DEPENDING ON YOUR SYSTEM SPEC )

You can stop the process at any time and re-start the load will continue from the last block loaded after checking the chain.
The data that is loaded can also be used to search while data in importing but only up to the latest block number processed.

Next step can be done now if you want to scan small search space or wait for full import of data before continuing.


################################################################################

CHECK MYSQL

Go back to MySQL and log in and type

mysql> use abe;

mysql> show tables;

Output will show.

+-----------------+
| Tables_in_abe   |
+-----------------+
| abe_lock        |
| block           |
| block_next      |
| block_seq       |
| block_tx        |
| block_txin      |
| chain           |
| chain_candidate |
| chain_seq       |
| chain_summary   |
| configvar       |
| datadir         |
| datadir_seq     |
| multisig_pubkey |
| orphan_block    |
| pubkey          |
| pubkey_seq      |
| tx              |
| tx_seq          |
| txin            |
| txin_detail     |
| txin_seq        |
| txout           |
| txout_approx    |
| txout_detail    |
| txout_seq       |
| unlinked_tx     |
| unlinked_txin   |
+-----------------+



################################################################################


LAUNCH BITCOIN ABE (LOCALHOST)

If you have this working you can now launch ABE from the bitcoin-abe-master dir to view the api in localhost.

$ python -m Abe.abe --config abe.conf

Open browser and navagate to: localhost:2750 

You should now see the ABE block explorer running.


################################################################################

full member
Activity: 281
Merit: 114
Thanks for the answer. This is what I know ... but I mean the number of ALL addresses starting with the given phrase (including those on which there was no transaction).
legendary
Activity: 1638
Merit: 1329
Stultorum infinitus est numerus
Millions, if not even more.

You might need to check for addresses with balance of 0.00000x or addresses that received BTC in the past. To do that, you, of course, need to download the whole blockchain and then use a scraper. There are various scrapers available on GitHub but you'll most likely need to configure it yourself to look for addresses that received BTC/has an active balance and starts with 1Bitcoin.
full member
Activity: 281
Merit: 114
I have a question.
Is there any ready script e.g. in PHP or JavaScript which I could check the number of all BTC addresses starting with the prefix indicated? Suppose I would like to know the number of all addresses starting with "1Bitcoin". I mean the total number resulting from ECDSA rules (so regardless of balance). Alternatively, I am interested in quantitative division into compressed and uncompressed.
Somewhere I saw something like that but I don't remember how it worked, but I remember that it was even possible to generate a list of such addresses (provided that it was quite complex). It needs to obviously scale the tune in a random hit on the selected prefix. I will be grateful for guiding me.
Regards
Jump to: