Skip to content

Commit 2f01ebe

Browse files
knstachow101
andcommitted
Merge bitcoin#26341: test: add BIP158 false-positive element check in rpc_scanblocks.py
fa54d30 test: check for false-positives in rpc_scanblocks.py (Sebastian Falbesoner) 3bca6cd test: add compact block filter (BIP158) helper routines (Sebastian Falbesoner) 25ee74d test: add SipHash implementation for generic data in Python (Sebastian Falbesoner) Pull request description: This PR adds a fixed false-positive element check to the functional test rpc_scanblocks.py by using a pre-calculated scriptPubKey that collides with the regtest genesis block's coinbase output. Note that determining a BIP158 false-positive at runtime would also be possible, but take too long (we'd need to create and check ~800k output scripts on average, which took at least 2 minutes on average on my machine). The introduced check is related to issue bitcoin#26322 and more concretely inspired by PR bitcoin#26325 which introduces an "accurate" mode that filters out these false-positives. The introduced cryptography routines (siphash for generic data) and helpers (BIP158 ranged hash calculation, relevant scriptPubKey per block determination) could potentially also be useful for more tests in the future that involve compact block filters. ACKs for top commit: achow101: ACK fa54d30 Tree-SHA512: c6af50864146028228d197fb022ba2ff24d1ef48dc7d171bccfb21e62dd50ac80db5fae0c53f5d205edabd48b3493c7aa2040f628a223e68df086ec2243e5a93 Co-authored-by: Andrew Chow <github@achow101.com>
1 parent 7c854c2 commit 2f01ebe

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

test/functional/rpc_scanblocks.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the scanblocks RPC call."""
6+
from test_framework.blockfilter import (
7+
bip158_basic_element_hash,
8+
bip158_relevant_scriptpubkeys,
9+
)
610
from test_framework.messages import COIN
711
from test_framework.test_framework import BitcoinTestFramework
812
from test_framework.util import (
@@ -70,6 +74,28 @@ def run_test(self):
7074
assert(blockhash in node.scanblocks(
7175
"start", [{"desc": f"pkh({parent_key}/*)", "range": [0, 100]}], height)['relevant_blocks'])
7276

77+
# check that false-positives are included in the result now; note that
78+
# finding a false-positive at runtime would take too long, hence we simply
79+
# use a pre-calculated one that collides with the regtest genesis block's
80+
# coinbase output and verify that their BIP158 ranged hashes match
81+
genesis_blockhash = node.getblockhash(0)
82+
genesis_spks = bip158_relevant_scriptpubkeys(node, genesis_blockhash)
83+
assert_equal(len(genesis_spks), 1)
84+
genesis_coinbase_spk = list(genesis_spks)[0]
85+
false_positive_spk = bytes.fromhex("1400000000000000000000000000000000000ad23b")
86+
87+
genesis_coinbase_hash = bip158_basic_element_hash(genesis_coinbase_spk, 1, genesis_blockhash)
88+
false_positive_hash = bip158_basic_element_hash(false_positive_spk, 1, genesis_blockhash)
89+
assert_equal(genesis_coinbase_hash, false_positive_hash)
90+
91+
assert(genesis_blockhash in node.scanblocks(
92+
"start", [{"desc": f"raw({genesis_coinbase_spk.hex()})"}], 0, 0)['relevant_blocks'])
93+
assert(genesis_blockhash in node.scanblocks(
94+
"start", [{"desc": f"raw({false_positive_spk.hex()})"}], 0, 0)['relevant_blocks'])
95+
96+
# TODO: after an "accurate" mode for scanblocks is implemented (e.g. PR #26325)
97+
# check here that it filters out the false-positive
98+
7399
# test node with disabled blockfilterindex
74100
assert_raises_rpc_error(-1, "Index is not enabled for filtertype basic",
75101
self.nodes[1].scanblocks, "start", [f"addr({addr_1})"])

0 commit comments

Comments
 (0)