Skip to content

Commit

Permalink
gcs: fix pseudo-code for filter construction, N is size of items, not…
Browse files Browse the repository at this point in the history
… block
  • Loading branch information
Roasbeef committed Jun 9, 2017
1 parent 578a4e3 commit bc5c6d6
Showing 1 changed file with 34 additions and 25 deletions.
59 changes: 34 additions & 25 deletions gcs_light_client.mediawiki
Expand Up @@ -527,31 +527,36 @@ Given a Bitcoin block, a full-node constructs a <code>Normal</code> compact
filter as follows:
<pre>
construct_normal_gcs_filter(block, fp) -> []byte:

let siphash_key = block.hash()[:16]

let P = 1 << fp
let N = len(block.transactions)
let F = N * P
items = []
let raw_items = []
for tx in block.transactions:
if tx.is_coinbase():
continue
continue
for input in tx.inputs:
input_bytes = input.hash || input.index
let item = siphash(siphash_key, input_bytes) % F
items.append(item)
// Inputs serialized as they are on the wire in transactions.
// Input index serialized in little-endian.
let input_bytes = input.hash || input.index
raw_items.append(input_bytes)
for output in tx.outputs:
output_bytes = extract_push_datas(output.script)
let item = siphash(siphash_key, output_bytes) % F
items.append(time)
let output_bytes = extract_push_datas(output.script)
raw_items.append(output_bytes)
let N = len(raw_items)
let F = N * P
items.sort()
let hashed_items = []
for raw_item in raw_items:
let hashed_item = siphash_key(siphash_key, raw_item) % F
hashed_items.append(hashed_item)
gcs_compress(items, fp)
hashed_items.sort()
gcs_compress(hashed_items, fp)
</pre>


Expand All @@ -562,30 +567,34 @@ construct_extended_gcs_filter(block, fp) -> []byte:
let siphash_key = block.hash()[:16]
let P = 1 << fp
let N = len(block.transactions)
let M = N * P
items = []
let raw_items = []
for tx in block.transactions:
txid = tx.hash()
items.append(txid)
let txid = tx.hash()
raw_items.append(txid)
if tx.is_coinbase():
continue
for input in tx.inputs:
for wit_elem in input.witness:
let item = siphash(siphash_key, wit_elem) % M
items.append(item)
raw_items.append(wit_elem)
sig_script_pushes = extract_push_datas(input.sig_script)
let sig_script_pushes = extract_push_datas(input.sig_script)
for push in sig_script_pushes:
let item = siphash(siphash_key, push) % M
items.append(item)
raw_items.append(push)
items.sort()
let N = len(raw_items)
let F = N * P
let hashed_items = []
for raw_item in raw_items:
let hashed_item = siphash_key(siphash_key, raw_item) % F
hashed_items.append(hashed_item)
hashed_items.sort()
gcs_compress(items, fp)
gcs_compress(hashed_items, fp)
</pre>

==== Filter Capability Querying ====
Expand Down

0 comments on commit bc5c6d6

Please sign in to comment.