shrub/BIP158.md
2021-05-26 18:30:15 -07:00

1.7 KiB

BIP158 - Neutrino Filters

GCS Decodijng

Below should yield 769.941 as the delta, with 3 bits of padding at the end.

=b158 -build-file %/lib/bip158/hoon
=filter 0x19d.fca8
=gr 0x9d.fca8
(de:gol:b158 [(mul 8 (met 3 gr)) `@ub`gr] 19)

Siphash Testing

https://github.com/bitcoin/bips/blob/master/bip-0158/testnet-19.json blockhash: 000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943

  • filter is the block filter. First byte is N, rest is the filter in Golomb-Rice
  • gr is the GCS part of the filter
  • k is the last 16 bytes of the blockhash, and we flip the endianness so 0x43 is in front
  • f is N*M

Genesis block on testnet, N=1

=b158 -build-file %/lib/bip158/hoon
=filter 0x19d.fca8
=gr 0x9d.fca8
=n 0x1
=f (mul n 784.931)
=k [16 0x4349.7fd7.f826.9571.08f4.a30f.d9ce.c3ae]
=item [67 0x41.0467.8afd.b0fe.5548.2719.67f1.a671.30b7.105c.d6a8.28e0.3909.a679.62e0.ea1f.61de.b649.f6bc.3f4c.ef38.c4f3.5504.e51e.c112.de5c.384d.f7ba.0b8d.578a.4c70.2b6b.f11d.5fac]

(rsh [0 64] (mul f (swp 3 dat:(siphash:b158 k item))))

Last should return 769.741, same as delta in GCS above.

Hash Set of Script Pubkeys

=b158 -build-file %/lib/bip158/hoon
=block-filter 0x9.027a.cea6.1b6c.c3fb.33f5.d52f.7d08.8a6b.2f75.d234.e89c.a800
=n (get-n:b158 block-filter)

=set1 [25 0x76.a914.3ebc.40e4.11ed.3c76.f867.1150.7ab9.5230.0890.3972.88ac]
=set2 [25 0x76.a914.5033.3046.115e.aa0a.c9e0.2165.65f9.4507.0e44.5739.88ac]
= not-in-set [21 0x14.7e69.a44c.1a94.2139.c8ab.4127.8325.5e1e.46d0.f0da]
=k [16 0x1373.188d.e55c.f77d.e254.1cf1.cc75.f7ca]
(set-construct:hsh:b158 ~[set1 set2 not-in-set] k (mul n m:params:b158))

https://blog.trezor.io/bip158-compact-block-filters-9b813b07a878

0xfd.9721.d01c.f654.63f9.9af6