1 // Package filter implements BIP158 basic compact block filters: Golomb-coded
2 // sets (GCS) over the outputs of SipHash-2-4.
3 //
4 // A filter is built from an element set and the hash of the block it commits
5 // to. The first 16 bytes of the block hash, in the internal (little-endian)
6 // byte order used by the Bitcoin wire protocol, are used as the SipHash key.
7 // The basic filter type uses M = 784931 and P = 19, giving a false positive
8 // rate of about 1/784931 per queried element.
9 //
10 // The BIP158 basic element set consists of the previous output scripts spent
11 // by non-coinbase inputs, plus every output scriptPubKey in the block except
12 // OP_RETURN scripts. Empty ("nil") elements must be omitted and the element
13 // set is a set: exact duplicate scripts are included only once. Build does not
14 // enforce those rules; callers that supply the element set must. BuildFromScripts
15 // drops empty and duplicate scripts, but leaves OP_RETURN filtering to the
16 // caller.
17 //
18 // The serialization is a CompactSize element count followed by the bit-packed
19 // Golomb-Rice coded deltas of the sorted, hashed values, zero-padded to a byte
20 // boundary. A filter over the empty set is exactly the single byte 0x00.
21 package filter
22