@@ -31,6 +31,11 @@ class MutatedBlocksTest(BitcoinTestFramework):
31
31
def set_test_params (self ):
32
32
self .setup_clean_chain = True
33
33
self .num_nodes = 1
34
+ self .extra_args = [
35
+ [
36
+ "-testactivationheight=segwit@1" , # causes unconnected headers/blocks to not have segwit considered deployed
37
+ ],
38
+ ]
34
39
35
40
def run_test (self ):
36
41
self .wallet = MiniWallet (self .nodes [0 ])
@@ -74,7 +79,7 @@ def self_transfer_requested():
74
79
75
80
# Attempt to clear the honest relayer's download request by sending the
76
81
# mutated block (as the attacker).
77
- with self .nodes [0 ].assert_debug_log (expected_msgs = ["bad-txnmrklroot, hashMerkleRoot mismatch" ]):
82
+ with self .nodes [0 ].assert_debug_log (expected_msgs = ["Block mutated: bad-txnmrklroot, hashMerkleRoot mismatch" ]):
78
83
attacker .send_message (msg_block (mutated_block ))
79
84
# Attacker should get disconnected for sending a mutated block
80
85
attacker .wait_for_disconnect (timeout = 5 )
@@ -92,5 +97,20 @@ def self_transfer_requested():
92
97
honest_relayer .send_and_ping (block_txn )
93
98
assert_equal (self .nodes [0 ].getbestblockhash (), block .hash )
94
99
100
+ # Check that unexpected-witness mutation check doesn't trigger on a header that doesn't connect to anything
101
+ assert_equal (len (self .nodes [0 ].getpeerinfo ()), 1 )
102
+ attacker = self .nodes [0 ].add_p2p_connection (P2PInterface ())
103
+ block_missing_prev = copy .deepcopy (block )
104
+ block_missing_prev .hashPrevBlock = 123
105
+ block_missing_prev .solve ()
106
+
107
+ # Attacker gets a DoS score of 10, not immediately disconnected, so we do it 10 times to get to 100
108
+ for _ in range (10 ):
109
+ assert_equal (len (self .nodes [0 ].getpeerinfo ()), 2 )
110
+ with self .nodes [0 ].assert_debug_log (expected_msgs = ["AcceptBlock FAILED (prev-blk-not-found)" ]):
111
+ attacker .send_message (msg_block (block_missing_prev ))
112
+ attacker .wait_for_disconnect (timeout = 5 )
113
+
114
+
95
115
if __name__ == '__main__' :
96
116
MutatedBlocksTest ().main ()
0 commit comments