mirror of
https://github.com/urbit/shrub.git
synced 2024-12-19 16:51:42 +03:00
2.6 KiB
2.6 KiB
BIP158 - Neutrino Filters
GCS Decoding
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)
Parse GCS BlockFilter
=b158 -build-file %/lib/bip158/hoon
=filter1 0xfd.9721.d01c.f654.63f9.9af6
=filter2 0x9.027a.cea6.1b6c.c3fb.33f5.d52f.7d08.8a6b.2f75.d234.e89c.a800
(parse-filter:b158 filter1)
(parse-filter:b158 filter2)
Yields: [n=0x9 gcs-set=[wid=192 dat=...]] [n=0x2197 gcs-set=[wid=9 dat=...]]
Siphash Testing
https://github.com/bitcoin/bips/blob/master/bip-0158/testnet-19.json blockhash: 000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943
filter
is the block filter. First byte isN
, rest is the filter in Golomb-Ricegr
is the GCS part of the filterk
is the last 16 bytes of the blockhash, and we flip the endianness so0x43
is in frontf
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
From https://blog.trezor.io/bip158-compact-block-filters-9b813b07a878
Just Hashing
=b158 -build-file %/lib/bip158/hoon
=block-filter 0x9.027a.cea6.1b6c.c3fb.33f5.d52f.7d08.8a6b.2f75.d234.e89c.a800
=n n:(parse-filter:b158 block-filter)
=gcs-set gcs-set:(parse-filter:b158 block-filter)
=in1 [25 0x76.a914.3ebc.40e4.11ed.3c76.f867.1150.7ab9.5230.0890.3972.88ac]
=in2 [25 0x76.a914.5033.3046.115e.aa0a.c9e0.2165.65f9.4507.0e44.5739.88ac]
=out1 [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 ~[in1 in2 out1] k (mul n m:params:b158))
Yields for the hashed set: ~[176.536 2.341.508 3.078.625]
Yes/No Match
(match:b158 block-filter k ~[in1 in2 out1])
(match:b158 block-filter k ~[out1])
Yields %y.
and %.n
, respectively.
Return All Matches
`(list [@ @ux])`(all-match:b158 block-filter k ~[in1 in2 out1])
`(list [@ @ux])`(all-match:b158 block-filter k ~[out1])
Yields ~[ [25 0x76.a914.5033.3046.115e.aa0a.c9e0.2165.65f9.4507.0e44.5739.88ac] [25 0x76.a914.3ebc.40e4.11ed.3c76.f867.1150.7ab9.5230.0890.3972.88ac] ] and ~