concept bloom filter in category bitcoin

appears as: bloom filters, bloom filter, The bloom filter, bloom filter, bloom filters
Grokking Bitcoin

This is an excerpt from Manning's book Grokking Bitcoin.

Creating the bloom filter

To obfuscate what addresses belong together, John’s wallet creates a bloom filter to send to the full node (figure 6.16).

Figure 6.16. The client sends a bloom filter to the full node to obfuscate what addresses belong to the wallet.

The bloom filter is a sequence of bits, which, as mentioned in chapter 2, can have the value 0 or the value 1. John’s bloom filter happens to be 8 bits long. Figure 6.17 illustrates how it was created.

Figure 6.17. The lightweight wallet creates a bloom filter to send to the full node. Each address in the wallet is added to the bloom filter.

The wallet creates the sequence of bits (the bloom filter) and initializes them with zeroes all over. It then adds all John’s public key hashes (PKHs) to the bloom filter, starting with PKHa, the PKH for @a.

Why three hash functions?

The number of hash functions can be anything, as can the size of the bloom filter. This example uses three hash functions and 8 bits.

It runs PKHa through the first of the three hash functions. This hash function results in the value 2. This value is the index of a bit in the bloom filter. The bit at index 2 (the third from the left) is then set to 1. Then PKHa is run through the second hash function, which outputs 0, and the corresponding bit (the first from the left in the figure) is set to 1. Finally, the third hash function outputs 6, and the bit at index 6 (seventh from the left) is set to 1.