Bitcoin Compact Block Filters Explained: BIP157, BIP158, and GCS
A Bitcoin compact block filter is a small probabilistic representation of selected data in a block. A lightweight wallet can test whether a block might contain scripts relevant to it before deciding to download the full block. This is a discovery mechanism, not a substitute for validating Bitcoin consensus rules.
What does BIP158 specify?
BIP158 defines a basic filter construction using Golomb-coded sets (GCS). The basic filter represents certain output scripts and scripts associated with spent prevouts, with specified exclusions and construction rules. It does not simply list addresses, transaction IDs, or every field of every transaction.
A client maps its query elements into the same hashed domain and checks for possible membership. A match is a reason to inspect the block, not proof that a wallet received money. Because the representation is probabilistic, false positives are possible. A correctly constructed filter should not omit an element that the specification requires it to include; however, a dishonest server can supply an incorrect or incomplete filter.
What does BIP157 specify?
BIP157 specifies peer-to-peer messages for requesting and serving compact filters, filter headers, and checkpoints. It lets clients synchronize filter data while relying on the Bitcoin block-header chain for proof-of-work context.
A filter header commits to the current filter hash and the preceding filter header, forming a linked sequence. This detects inconsistencies against a previously trusted checkpoint or agreed sequence; it does not independently establish that a filter accurately represents its block.
What are the privacy tradeoffs?
A wallet that obtains filters for many blocks and checks them locally need not reveal each watched script to a server. Yet network peers can still observe IP addresses, timing, block requests, and other metadata. Fetching matching blocks can reveal interests, particularly if requests are sparse or predictable.
What are the security limits?
A malicious filter source may omit relevant scripts, leading a wallet to miss transactions unless it compares sources or verifies the corresponding blocks independently. Filter-header commitments alone do not make an incorrect filter correct. Wallets should distinguish transaction discovery, block inclusion, and full consensus validation.
Primary references
BIP157 — Client Side Block Filtering: https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki
BIP158 — Compact Block Filters for Light Clients: https://github.com/bitcoin/bips/blob/master/bip-0158.mediawiki
Bitcoin Developer Guide — Block Chain: https://developer.bitcoin.org/devguide/block_chain.html
