Skip to content

Commit c743718

Browse files
committed
test: add further BIP37 size limit checks to p2p_filter.py
also unified method of detecting misbehaviour (using assert_debug_log instead of checking peer's banscore)
1 parent fc00e65 commit c743718

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

test/functional/p2p_filter.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
from test_framework.messages import (
1010
CInv,
11+
MAX_BLOOM_FILTER_SIZE,
12+
MAX_BLOOM_HASH_FUNCS,
1113
MSG_BLOCK,
1214
MSG_FILTERED_BLOCK,
1315
msg_filteradd,
@@ -16,6 +18,7 @@
1618
msg_getdata,
1719
)
1820
from test_framework.mininode import P2PInterface
21+
from test_framework.script import MAX_SCRIPT_ELEMENT_SIZE
1922
from test_framework.test_framework import BitcoinTestFramework
2023
from test_framework.util import assert_equal
2124

@@ -67,7 +70,13 @@ def run_test(self):
6770

6871
self.log.info('Check that too large filter is rejected')
6972
with self.nodes[0].assert_debug_log(['Misbehaving']):
70-
filter_node.send_and_ping(msg_filterload(data=b'\xaa', nHashFuncs=51, nTweak=0, nFlags=1))
73+
filter_node.send_and_ping(msg_filterload(data=b'\xaa', nHashFuncs=MAX_BLOOM_HASH_FUNCS+1))
74+
with self.nodes[0].assert_debug_log(['Misbehaving']):
75+
filter_node.send_and_ping(msg_filterload(data=b'\xbb'*(MAX_BLOOM_FILTER_SIZE+1)))
76+
77+
self.log.info('Check that too large data element to add to the filter is rejected')
78+
with self.nodes[0].assert_debug_log(['Misbehaving']):
79+
filter_node.send_and_ping(msg_filteradd(data=b'\xcc'*(MAX_SCRIPT_ELEMENT_SIZE+1)))
7180

7281
self.log.info('Add filtered P2P connection to the node')
7382
filter_node.send_and_ping(filter_node.watch_filter_init)
@@ -116,10 +125,9 @@ def run_test(self):
116125
assert not filter_node.merkleblock_received
117126
assert not filter_node.tx_received
118127

119-
self.log.info('Check that sending "filteradd" if no filter is set is treated as misbehavior (+100)')
120-
assert_equal(self.nodes[0].getpeerinfo()[0]['banscore'], 0)
121-
filter_node.send_and_ping(msg_filteradd(data=b'letsmisbehave'))
122-
assert_equal(self.nodes[0].getpeerinfo()[0]['banscore'], 100)
128+
self.log.info('Check that sending "filteradd" if no filter is set is treated as misbehavior')
129+
with self.nodes[0].assert_debug_log(['Misbehaving']):
130+
filter_node.send_and_ping(msg_filteradd(data=b'letsmisbehave'))
123131

124132
self.log.info("Check that division-by-zero remote crash bug [CVE-2013-5700] is fixed")
125133
filter_node.send_and_ping(msg_filterload(data=b'', nHashFuncs=1))

test/functional/test_framework/messages.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
MAX_LOCATOR_SZ = 101
3939
MAX_BLOCK_BASE_SIZE = 1000000
40+
MAX_BLOOM_FILTER_SIZE = 36000
41+
MAX_BLOOM_HASH_FUNCS = 50
4042

4143
COIN = 100000000 # 1 btc in satoshis
4244
MAX_MONEY = 21000000 * COIN

0 commit comments

Comments
 (0)