How to Check Bitcoin Address Balance Using Bloom Filter Algorithm

20.03.2025
How to Check Bitcoin Address Balance Using Bloom Filter Algorithm

To create a Python script that checks the balance of Bitcoin addresses using the Bloom filter algorithm, we need to follow a few steps. First, we will create a Bloom filter to store the addresses, and then we will check the balance of each address using the Blockchain.com API.

Step 1: Installing the required libraries

To work, we will need libraries pybloom_livefor implementing the Bloom filter and requestsfor API requests.

bashpip install pybloom_live requests

Step 2: Create a script

Below is an example script that creates a Bloom filter and checks the balance of Bitcoin addresses:

pythonimport requests
from pybloom_live import BloomFilter

# Параметры для Bloom filter
size = 1000000  # Размер фильтра
error_rate = 0.001  # Вероятность ложного срабатывания

# Создание Bloom filter
bf = BloomFilter(size, error_rate)

# Список Bitcoin адресов
addresses = [
    '12VeK1eRgPHRUikNLXq3Nuz99gS2S46QMD',
    # Добавьте больше адресов сюда
]

# Добавление адресов в Bloom filter
for address in addresses:
    bf.add(address)

# Функция для проверки баланса адреса
def check_balance(address):
    url = f'https://blockchain.info/rawaddr/{address}'
    try:
        response = requests.get(url)
        data = response.json()
        balance = data['final_balance'] / 1e8  # Переводим в BTC
        print(f'Адрес: {address}, Баланс: {balance} BTC')
    except Exception as e:
        print(f'Ошибка при запросе баланса для {address}: {e}')

# Проверка баланса для каждого адреса в Bloom filter
for address in bf:
    if address in addresses:  # Проверяем, чтобы адрес был в исходном списке
        check_balance(address)

# Если вы хотите проверить баланс для новых адресов, не добавленных в Bloom filter
new_address = '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'
if new_address not in bf:
    bf.add(new_address)
    check_balance(new_address)

Notes

  1. Bloom Filter : Used to quickly determine if an element is present in a set. However, it can produce false positives, so it is important to double-check the results.
  2. Blockchain.com API : Used to get Bitcoin address balances. Please note that there are limits on the number of requests per minute.
  3. Adding addresses : In the script you need to manually add Bitcoin addresses to the list addresses.

This script allows you to quickly filter addresses that have already been verified and then check their balance. However, to fully use the Bloom filter in real applications, you need to carefully adjust its size and error probability depending on your specific requirements.


How to Use Bloom Filter to Check Bitcoin Address Balance

To check the balance of Bitcoin addresses using Bloom filter, you can follow these steps:

Step 1: Implementing Bloom Filter

First we need to implement or use a ready-made implementation of Bloom filter. We can use a library pybloom_livefor Python.

pythonfrom pybloom_live import BloomFilter

# Параметры для Bloom filter
size = 1000000  # Размер фильтра
error_rate = 0.001  # Вероятность ложного срабатывания

# Создание Bloom filter
bf = BloomFilter(size, error_rate)

Step 2: Adding Addresses to Bloom Filter

Add Bitcoin addresses to the Bloom filter. This will allow you to quickly check if the address is in the set.

python# Список Bitcoin адресов
addresses = [
    '12VeK1eRgPHRUikNLXq3Nuz99gS2S46QMD',
    # Добавьте больше адресов сюда
]

# Добавление адресов в Bloom filter
for address in addresses:
    bf.add(address)

Step 3: Checking the balance of addresses

Use the Blockchain.com API to check the balance of each address. If the address is in the Bloom filter, check its balance.

pythonimport requests

# Функция для проверки баланса адреса
def check_balance(address):
    url = f'https://blockchain.info/rawaddr/{address}'
    try:
        response = requests.get(url)
        data = response.json()
        balance = data['final_balance'] / 1e8  # Переводим в BTC
        print(f'Адрес: {address}, Баланс: {balance} BTC')
    except Exception as e:
        print(f'Ошибка при запросе баланса для {address}: {e}')

# Проверка баланса для каждого адреса в Bloom filter
for address in addresses:
    if address in bf:
        check_balance(address)

Notes

  1. Bloom Filter : Used to quickly determine if an element is present in a set. However, it can produce false positives, so it is important to double-check the results.
  2. Blockchain.com API : Used to get Bitcoin address balances. Please note that there are limits on the number of requests per minute.
  3. Adding addresses : In the script you need to manually add Bitcoin addresses to the list addresses.

This approach allows you to quickly filter addresses that have already been verified and then check their balance. However, to fully use the Bloom filter in real applications, you need to carefully tune its size and error probability depending on specific requirements.

Full script

pythonfrom pybloom_live import BloomFilter
import requests

# Параметры для Bloom filter
size = 1000000  # Размер фильтра
error_rate = 0.001  # Вероятность ложного срабатывания

# Создание Bloom filter
bf = BloomFilter(size, error_rate)

# Список Bitcoin адресов
addresses = [
    '12VeK1eRgPHRUikNLXq3Nuz99gS2S46QMD',
    # Добавьте больше адресов сюда
]

# Добавление адресов в Bloom filter
for address in addresses:
    bf.add(address)

# Функция для проверки баланса адреса
def check_balance(address):
    url = f'https://blockchain.info/rawaddr/{address}'
    try:
        response = requests.get(url)
        data = response.json()
        balance = data['final_balance'] / 1e8  # Переводим в BTC
        print(f'Адрес: {address}, Баланс: {balance} BTC')
    except Exception as e:
        print(f'Ошибка при запросе баланса для {address}: {e}')

# Проверка баланса для каждого адреса в Bloom filter
for address in addresses:
    if address in bf:
        check_balance(address)

This script allows you to quickly filter addresses and check their balance, using Bloom filter to optimize the process.

What Bloom filter parameters should be taken into account when working with Bitcoin addresses

When working with Bitcoin addresses and using Bloom filter, the following key parameters must be taken into account:

1. Bit array size (m)

  • Description : This is the number of bits allocated to store information about the presence of elements.
  • Impact : The larger the value m, the lower the probability of false positives, but more memory will be required.
  • The formula for calculation is: m=−n⋅ln⁡(p)(ln⁡(2))2m = -\frac{n \cdot \ln(p)}{(\ln(2))^2}m=−(ln(2))2n⋅ln(p), where nnn is the expected number of elements and ppp is the desired probability of false positives 8 .

2. Number of hash functions (k)

  • Description : The number of hash functions used to calculate indices into the bitmap.
  • Impact : Increasing kreduces the number of false positives, but slows down the checking process.
  • The formula for calculation : k=mn⋅ln⁡(2)k = \frac{m}{n} \cdot \ln(2)k=nm⋅ln(2), where mmm is the size of the bit array, and nnn is the number of elements 2 .

3. Probability of false positives (p)

  • Description : The probability that the filter will report the presence of an element that is not actually present.
  • Impact : Decreasing prequires increasing mand k, which may impact performance and memory consumption 8 .

4. Number of elements (n)

  • Description : The expected number of Bitcoin addresses that will be stored in the filter.
  • Impact : Affects the size of the bit array and the number of hash functions required to achieve the desired accuracy of 5 8 .

5. Hash functions

  • Description : Used to calculate indices in a bit array.
  • Impact : The choice of hash functions affects the performance and uniformity of the distribution of elements in the 8 filter .

When working with Bitcoin addresses, it is important to find a balance between memory, speed, and filter accuracy to ensure effective filtering and minimize false positives.

What errors can occur when using Bloom filter to check the balance of Bitcoin addresses

When using Bloom filter to check Bitcoin address balances, the following errors may occur:

1. False positives (false positives)

  • Description : A Bloom filter may report that an address is present in a set even if it is not. This is due to hash function collisions, where different inputs produce the same hash 3 .
  • Consequences : Misidentification of addresses as having a balance when in fact they do not.

2. Insufficient memory

  • Description : If the bitmap size is too small for the number of addresses stored, this may result in an increased probability of false positives 6 .
  • Consequences : Reduced filter accuracy, which may lead to incorrect results.

3. Incorrect choice of hash functions

  • Description : If hash functions do not distribute elements uniformly across the bitmap, this can increase the likelihood of collisions 2 .
  • Consequences : Increased number of false positives.

4. Incorrect parameter settings

  • Description : Incorrect choice of the number of hash functions ( k) or the size of the bit array ( m) can lead to suboptimal performance of the filter 4 .
  • Consequences : Reduced filter performance or accuracy.

5. Scalability issues

  • Description : When working with a large number of addresses, the Bloom filter can require significant memory resources, which can be problematic on devices with limited resources 4 .
  • Consequences : Reduced system performance due to memory consumption.

6. Incorrect API error handling

  • Description : If an API error (such as 500 or 503) occurs when requesting a balance, this may result in incorrect results or the program freezing 1 .
  • Consequences : Program execution may be interrupted or incorrect data may be received.

To minimize these errors, it is important to carefully configure the Bloom filter parameters and implement correct error handling when making API requests.

What collisions can occur when using Bloom filter for Bitcoin addresses

When using Bloom filter for Bitcoin addresses the following collisions may occur:

1. False positives (false positives)

  • Description : Bloom filter can report that a Bitcoin address is present in the set even if it is not. This happens due to hash function collisions, when different addresses give the same hash 4 .
  • Consequences : Misidentification of addresses as having a balance when in fact they do not.

2. Hash function collisions

  • Description : Two different Bitcoin addresses can have the same hash, which results in the same indices in the 4 Bloom filter bitmap .
  • Consequences : Increased likelihood of false positives, which may lead to incorrect results when checking balance.

3. Insufficient bit array size

  • Description : If the bitmap size is too small for the number of addresses stored, this may result in an increased chance of collisions 6 .
  • Consequences : Reduced filter accuracy, which may lead to incorrect results.

4. Incorrect choice of hash functions

  • Description : If hash functions do not distribute elements evenly across the bitmap, this can increase the likelihood of collisions 4 .
  • Consequences : Increased number of false positives.

To reduce the likelihood of collisions, you can use the following strategies:

  • Increasing the size of the bit array .
  • Increasing the number of hash functions .
  • Selecting quality hash functions .
  • Using specialized algorithms such as Counting Bloom Filter 2 .

What strategies can be used to reduce collisions in Bloom filter

To reduce collisions in Bloom filter, the following strategies can be used:

1. Increasing the size of the bit array

  • Description : Increasing the bitmap size ( m) reduces the chance of collisions because the number of bits available for storing hash codes increases.
  • Consequences : Requires more memory, but reduces the likelihood of false positives 2 .

2. Increasing the number of hash functions

  • Description : Using more hash functions ( k) increases the number of bits that are marked when an element is added, reducing the likelihood of false positives.
  • Consequences : Increases the number of memory accesses, but improves the accuracy of the 3 filter .

3. Selecting quality hash functions

  • Description : Using hash functions that evenly distribute elements across a bitmap reduces the likelihood of collisions.
  • Effect : Improves filter accuracy and reduces false positives 5 .

4. Using specialized algorithms

  • Description : Using algorithms such as the Counting Bloom Filter, it is possible to track the number of times each element is encountered, which helps reduce the percentage of false positives.
  • Effect : Improves filter accuracy and allows more accurate checking of the presence of elements 1 .

5. Preliminary check

  • Description : Use Bloom filter as a pre-filter to exclude elements that are definitely not in a set, and then confirm the results with more accurate methods.
  • Impact : Reduces the number of queries to the main database and speeds up the verification process 4 .

These strategies allow you to optimize the Bloom filter and minimize the number of collisions, which is especially important when working with large data sets.

Citations:

  1. https://gitverse.ru/blog/articles/data/255-chto-takoe-filtr-bluma-i-kak-on-rabotaet-na-praktike
  2. https://habr.com/ru/companies/otus/articles/541378/
  3. https://habr.com/ru/articles/491132/
  4. https://ru.hexlet.io/blog/posts/filtr-bluma-zachem-nuzhen-i-kak-rabotaet
  5. https://dzen.ru/a/XZR3S9W7wwCsGo3R
  6. https://evmservice.ru/blog/filtr-bluma/
  7. https://docs.unity3d.com/ru/530/Manual/script-BloomOptimized.html
  8. https://neerc.ifmo.ru/wiki/index.php?title=%D0%A4%D0%B8%D0%BB%D1%8C%D1%82%D1%80_%D0%91%D0%BB%D1%83%D0%BC%D0%B0

  1. https://gitverse.ru/blog/articles/data/255-chto-takoe-filtr-bluma-i-kak-on-rabotaet-na-praktike
  2. https://habr.com/ru/companies/otus/articles/541378/
  3. https://habr.com/ru/articles/788772/
  4. https://ru.hexlet.io/blog/posts/filtr-bluma-zachem-nuzhen-i-kak-rabotaet
  5. https://www.gate.io/ru/learn/articles/what-is—bloom-filter-in-blockchain/809
  6. https://neerc.ifmo.ru/wiki/index.php?title=%D0%A4%D0%B8%D0%BB%D1%8C%D1%82%D1%80_%D0%91%D0%BB%D1%83%D0%BC%D0%B0
  7. https://datafinder.ru/files/downloads/01/algoritmy_i_struktury_dlja_massivnyh_naborov_dannyh_2023_medzhedovich.pdf
  8. https://evmservice.ru/blog/filtr-bluma/

  1. https://github.com/Blockchair/Blockchair.Support/blob/master/API_DOCUMENTATION_RU.md
  2. https://habr.com/ru/companies/otus/articles/541378/
  3. https://ru.hexlet.io/blog/posts/filtr-bluma-zachem-nuzhen-i-kak-rabotaet
  4. https://habr.com/ru/articles/491132/
  5. https://www.gate.io/ru/learn/articles/what-is—bloom-filter-in-blockchain/809
  6. https://neerc.ifmo.ru/wiki/index.php?title=%D0%A4%D0%B8%D0%BB%D1%8C%D1%82%D1%80_%D0%91%D0%BB%D1%83%D0%BC%D0%B0
  7. https://pikabu.ru/story/istoricheskaya_spravka_kasaemo_vzlomov_bitkoin_koshelkov_9596225
  8. https://datafinder.ru/files/downloads/01/algoritmy_i_struktury_dlja_massivnyh_naborov_dannyh_2023_medzhedovich.pdf

  1. https://nuancesprog.ru/p/21154/
  2. https://habr.com/ru/companies/otus/articles/541378/
  3. https://ibmm.ru/news/chto-novogo-v-bitcoin-core-0-21-0/
  4. https://www.gate.io/ru/learn/articles/what-is—bloom-filter-in-blockchain/809
  5. https://habr.com/ru/companies/otus/articles/843714/
  6. https://forklog.com/exclusive/bitkoin-koshelki-sravnili-po-48-kriteriyam-najdite-svoj
  7. https://github.com/brichard19/BitCrack/issues/313
  8. https://neerc.ifmo.ru/wiki/index.php?title=%D0%A4%D0%B8%D0%BB%D1%8C%D1%82%D1%80_%D0%91%D0%BB%D1%83%D0%BC%D0%B0

  1. https://crypto.oni.su/54-python-perebor-mnemonicheskih-fraz-dlja-btcethtrx.html
  2. https://habr.com/ru/companies/otus/articles/541378/
  3. https://www.gate.io/ru/learn/articles/what-is—bloom-filter-in-blockchain/809
  4. https://github.com/brichard19/BitCrack/issues/313
  5. https://www.bitget.com/ru/glossary/bloom-filter
  6. https://forklog.com/exclusive/bitkoin-koshelki-sravnili-po-48-kriteriyam-najdite-svoj
  7. https://neerc.ifmo.ru/wiki/index.php?title=%D0%A4%D0%B8%D0%BB%D1%8C%D1%82%D1%80_%D0%91%D0%BB%D1%83%D0%BC%D0%B0
  8. https://dzen.ru/a/YBkKO40wyxeAFLPO

  1. https://cryptodeep.ru/check-bitcoin-address-balance/
  2. https://rutube.ru/video/4559c67d6deb70128512cbf232bb8d4e/
  3. https://habr.com/ru/articles/525638/
  4. https://www.youtube.com/watch?v=LrVLVyaeMRA
  5. https://bitnovosti.io/2025/01/18/python-bitcoin-crypto/
  6. https://www.linux.org.ru/forum/development/14449143
  7. https://habr.com/ru/articles/674812/
  8. https://github.com/OxideDevX/btcbruter_script

Source code

Telegram: https://t.me/cryptodeeptech

Video: https://youtu.be/i9KYih_ffr8

Video tutorial: https://dzen.ru/video/watch/6784be61b09e46422395c236

Source: https://cryptodeeptech.ru/discrete-logarithm


Useful information for enthusiasts:


Discrete Logarithm mathematical methods and tools for recovering cryptocurrency wallets Bitcoin