How to extract RSZ values ​​(R, S, Z) from Bitcoin transaction RawTx and uses the “Bloom filter” algorithm to speed up the work

20.03.2025

How to extract RSZ values ​​(R, S, Z) from Bitcoin transaction RawTx and uses the "Bloom filter" algorithm to speed up the work

Creating a Python script that extracts RSZ values ​​(R, S, Z) from a Bitcoin RawTx transaction and uses the Bloom filter algorithm to speed up the work requires several steps. However, it is worth noting that the Bloom filter is usually used to quickly determine the presence of an element in a set, rather than to extract specific values ​​from transactions. However, we can use the Bloom filter to pre-filter transactions and then extract the RSZ values.

Below is an example script that extracts RSZ values ​​without using Bloom filter, as this is a more direct approach to the task at hand. Using Bloom filter would require additional logic to filter transactions, which may not be practical in this context.

Step 1: Installing the required libraries

To work with Bitcoin transactions and ECDSA signatures you will need the library ecdsaand secp256k1. However, for simplicity, we will use secp256k1from the repository iceland2k14/rsz, which already contains the necessary functions for extracting R, S, Z values.

Install the required libraries:

bashpip install ecdsa
git clone https://github.com/iceland2k14/rsz.git

Step 2: Extract RSZ values

Using the script getz_input.pyfrom the repository rsz, you can extract the R, S, Z values ​​from RawTx. However, to demonstrate how this can be done manually, here is a sample code:

python

import hashlib
from ecdsa.curves import SECP256k1
from ecdsa.keys import SigningKey

def get_z_value(tx_hash, message):
# Для упрощения примера, предполагаем, что tx_hash — это хэш сообщения
return int.from_bytes(hashlib.sha256(message.encode()).digest(), 'big')

def get_r_s_values(signature, z_value):
# Для упрощения, предполагаем, что signature — это подпись в формате (r, s)
# В реальности, подпись должна быть извлечена из RawTx
r = signature[0]
s = signature[1]
return r, s

def main():
# Пример использования
tx_hash = "d76641afb4d0cc648a2f74db09f86ea264498341c49434a933ba8eef9352ab6f"
message = "Пример сообщения"
z_value = get_z_value(tx_hash, message)

# Для демонстрации, используем фиктивную подпись
signature = (1234567890, 9876543210) # (r, s)
r_value, s_value = get_r_s_values(signature, z_value)

print(f"R: {r_value}, S: {s_value}, Z: {z_value}")

if __name__ == "__main__":
main()

Bloom filter application

If you want to use Bloom filter to filter transactions before extracting RSZ values, you will need to implement additional logic to add transactions to the filter and check if the transaction is in the filter. This can be useful if you have a large set of transactions and want to quickly determine if a transaction is in the set.

Example of using Bloom filter (simplified):

python

from pybloom_live import BloomFilter

def add_transactions_to_bloom_filter(transactions):
bf = BloomFilter(100000, 1e-6) # Настройки для Bloom filter
for tx in transactions:
bf.add(tx)
return bf

def check_transaction_in_bloom_filter(bf, tx):
return tx in bf

# Пример использования
transactions = ["tx1", "tx2", "tx3"]
bf = add_transactions_to_bloom_filter(transactions)
print(check_transaction_in_bloom_filter(bf, "tx1")) # True

This approach can be useful for quickly determining whether a transaction is in a set, but it is not necessary for extracting RSZ values.


Using a Bloom filter to speed up Bitcoin transactions is commonly used in SPV (Simple Payment Verification) clients, which do not download the entire blockchain but instead query full nodes for only those transactions that are associated with specific addresses. A Bloom filter allows a transaction to be checked quickly and with minimal space, although with some chance of false positives.

How Bloom Filter Works in Bitcoin

  1. Creating a filter : The client creates a Bloom filter by adding hashes of addresses that are of interest to it.
  2. Query full nodes : The client sends a Bloom filter to full nodes, which check if there are transactions in the blockchain that match the filter.
  3. Receiving transactions : Full nodes send transactions to the client that potentially match the filter. Since the filter is probabilistic, there may be false positives.

Benefits of using Bloom filter

  • Traffic savings : The client receives only the transactions he needs, which reduces traffic.
  • Privacy protection : The client does not reveal all of its addresses to full nodes, only hashes, which increases privacy.

Bloom filter implementation in Python

To demonstrate how Bloom filter can be used in Python, a simplified example is given below:

pythonfrom pybloom_live import BloomFilter

# Создание Bloom filter
bf = BloomFilter(100000, 1e-6)

# Добавление адресов в фильтр
addresses = ["addr1", "addr2", "addr3"]
for addr in addresses:
    bf.add(addr)

# Проверка наличия адреса в фильтре
def check_address_in_bloom_filter(bf, addr):
    return addr in bf

# Пример использования
print(check_address_in_bloom_filter(bf, "addr1"))  # True
print(check_address_in_bloom_filter(bf, "addr4"))  # False

Speeding up work with transactions

Bloom filter speeds up transactions by allowing clients to quickly and efficiently filter transactions without downloading the entire blockchain. However, Bloom filter is not used directly to extract RSZ values ​​(R, S, Z) from transactions, as it is intended for filtering, not for extracting specific data.



What are the benefits of using Bloom filter for Bitcoin SPV clients?

Using Bloom filter for Bitcoin SPV clients provides several important benefits:

  1. Bandwidth savings : Bloom filter allows SPV clients to request from full nodes only those transactions that are potentially related to their addresses, which reduces the amount of data transferred and saves bandwidth 2 .
  2. Privacy protection : When using a bloom filter, clients do not reveal all of their addresses to full nodes. Instead, they send a filter that prevents nodes from determining which addresses the client is interested in, thereby increasing privacy 4 .
  3. Data processing efficiency : Bloom filter allows you to quickly check the presence of an element in a set, which makes it an effective tool for filtering transactions in Bitcoin 8 .
  4. Resource savings : SPV clients do not require storing the entire blockchain, which significantly reduces memory and computational requirements. Bloom filter helps with this by allowing clients to work without downloading the entire blockchain 5 .
  5. Speed ​​of Operation : By quickly determining whether there are transactions that match a filter, SPV clients can operate faster than if they had to download and check all transactions manually 6 .


Conclusion

To extract RSZ values ​​from Bitcoin RawTx transactions, you can use the scripts in the repository rsz. Using Bloom filter can be useful for pre-filtering transactions, but it is not a necessary step to extract RSZ values. Bloom filter is a powerful tool for optimizing Bitcoin transaction processing, especially in SPV clients. It allows for fast and efficient transaction filtering, which reduces traffic and increases privacy. However, Bloom filter is not used to extract specific data such as RSZ values.

Citations:

  1. https://habr.com/ru/articles/674736/
  2. https://cryptodeep.ru/blockchain-google-drive/
  3. https://pikabu.ru/story/samaya_pervaya_sereznaya_uyazvimost_v_blockchain_i_kak_poluchit_publichnyiy_klyuch_bitcoin_ecdsa_znachenie_rsz_iz_fayla_rawtx_9243201
  4. https://dzen.ru/a/Yw0GaeDPYHqEjJg-
  5. https://github.com/iceland2k14/rsz/blob/main/README.md
  6. https://habr.com/ru/articles/694122/
  7. https://pikabu.ru/tag/Free%20bitcoin,%D0%9A%D1%80%D0%B5%D0%B4%D0%B8%D1%82/best?page=2
  8. https://github.com/iceland2k14/rsz/blob/main/getz_input.py

  1. https://qna.habr.com/q/364658
  2. https://www.gate.io/ru/learn/articles/what-is—bloom-filter-in-blockchain/809
  3. https://www.youtube.com/watch?v=Vg5yuqH9xd0
  4. https://nuancesprog.ru/p/21154/
  5. https://kurs.expert/ru/encyclopedia/lightning_network.html
  6. https://ru.hexlet.io/blog/posts/filtr-bluma-zachem-nuzhen-i-kak-rabotaet
  7. https://habr.com/ru/companies/otus/articles/541378/
  8. https://dzen.ru/a/YBkKO40wyxeAFLPO

Citations:

  1. https://www.gate.io/ru/learn/articles/what-is—bloom-filter-in-blockchain/809
  2. https://academy.binance.com/ru/glossary/bloom-filter
  3. https://habr.com/ru/articles/788772/
  4. https://bits.media/shest-prichin-zapustit-polnyy-uzel-bitkoina/
  5. https://ru.bitdegree.org/crypto/obuchenie/kripto-terminy/chto-takoe-filtr-bluma
  6. https://ru.hexlet.io/blog/posts/filtr-bluma-zachem-nuzhen-i-kak-rabotaet
  7. https://www.bitget.com/ru/glossary/bloom-filter
  8. https://habr.com/ru/companies/otus/articles/541378/

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:


How to extract RSZ values ​​(R, S, Z) from Bitcoin transaction RawTx and uses the "Bloom filter" algorithm to speed up the work