Skip to content

Instantly share code, notes, and snippets.

@gavinandresen
gavinandresen / sigop_sighash_count.md
Last active January 28, 2021 09:13
sigop/sighash counting

The consensus protocol limits on blocks are:

1 million or fewer bytes canonically-serialized size. 20,000 or fewer "sigops"

Unfortunately, Satoshi implemented those as quick fixes with zero code review and little testing (Bitcoin was not a Big Deal back then, it was the right decision at the time), and the way sigop counting is done is... well, just wrong.

Here's how Satoshi did it, as pseudo-code (see GetLegacySigOpCount in main.cpp for actual code):

For all the transactions in a block:

@markblundeberg
markblundeberg / golomb_part2.md
Created April 22, 2019 23:48
Progressive knockout block filters

Progressive knockout block filters

In my last gist, I described how the BIP158 block filters are technically not quite optimal, though in an inconsequential way since the false positive rate has been made so low.

In this document I'm going to describe how it's possible to significantly beat the bandwidth requirements of BIP158 while also achieving a lower overall false positive rate. The idea is to prepare multiple independent filters per block, each of which which has a higher false positive rate. Practically this can give roughly a factor of two improvement over BIP158, but at the cost of additional complexity.

The problem

The BIP158 false positive rate was chosen with a particular size of wallet in mind -- somewhere around 1000 items (addresses) to watch in each block. There is a trade off between the overall size of the filter (which must be do