Skip to content

Commit

Permalink
test: add further BIP37 size limit checks to p2p_filter.py
Browse files Browse the repository at this point in the history
also unified method of detecting misbehaviour
(using assert_debug_log instead of checking peer's banscore)
  • Loading branch information
theStack committed Apr 20, 2020
1 parent fc00e65 commit c743718
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 13 additions & 5 deletions test/functional/p2p_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from test_framework.messages import (
CInv,
MAX_BLOOM_FILTER_SIZE,
MAX_BLOOM_HASH_FUNCS,
MSG_BLOCK,
MSG_FILTERED_BLOCK,
msg_filteradd,
Expand All @@ -16,6 +18,7 @@
msg_getdata,
)
from test_framework.mininode import P2PInterface
from test_framework.script import MAX_SCRIPT_ELEMENT_SIZE
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal

Expand Down Expand Up @@ -67,7 +70,13 @@ def run_test(self):

self.log.info('Check that too large filter is rejected')
with self.nodes[0].assert_debug_log(['Misbehaving']):
filter_node.send_and_ping(msg_filterload(data=b'\xaa', nHashFuncs=51, nTweak=0, nFlags=1))
filter_node.send_and_ping(msg_filterload(data=b'\xaa', nHashFuncs=MAX_BLOOM_HASH_FUNCS+1))
with self.nodes[0].assert_debug_log(['Misbehaving']):
filter_node.send_and_ping(msg_filterload(data=b'\xbb'*(MAX_BLOOM_FILTER_SIZE+1)))

self.log.info('Check that too large data element to add to the filter is rejected')
with self.nodes[0].assert_debug_log(['Misbehaving']):
filter_node.send_and_ping(msg_filteradd(data=b'\xcc'*(MAX_SCRIPT_ELEMENT_SIZE+1)))

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

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

self.log.info("Check that division-by-zero remote crash bug [CVE-2013-5700] is fixed")
filter_node.send_and_ping(msg_filterload(data=b'', nHashFuncs=1))
Expand Down
2 changes: 2 additions & 0 deletions test/functional/test_framework/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

MAX_LOCATOR_SZ = 101
MAX_BLOCK_BASE_SIZE = 1000000
MAX_BLOOM_FILTER_SIZE = 36000
MAX_BLOOM_HASH_FUNCS = 50

COIN = 100000000 # 1 btc in satoshis
MAX_MONEY = 21000000 * COIN
Expand Down

0 comments on commit c743718

Please sign in to comment.