test: BIP324: add checks for v1 prefix matching / wrong network magic detection #28588

pull theStack wants to merge 1 commits into bitcoin:master from theStack:202310-test-add_v1_prefix_detection_wrong_network_magic_check changing 1 files +27 −1
  1. theStack commented at 3:04 pm on October 4, 2023: contributor
    This PR adds missing test coverage for the detection of incoming v1 connections and wrong network magic on BIP324-enabled (i.e. running with -v2transport=1) nodes. Both checks are using prefix sizes of 16 bytes (previously only 12 bytes were used for the v1 prefix matching, which was fixed by PR #28577).
  2. DrahtBot commented at 3:04 pm on October 4, 2023: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK Sjors, MarcoFalke
    Stale ACK sipa

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  3. DrahtBot added the label Tests on Oct 4, 2023
  4. fanquake requested review from sipa on Oct 4, 2023
  5. sipa commented at 3:23 pm on October 4, 2023: member

    utACK c8581d449efcd0c7e45a0a2476a6dc356efd45dc

    Happy to rebase #28577 on this if it goes in first.

  6. DrahtBot removed review request from sipa on Oct 4, 2023
  7. fanquake requested review from vasild on Oct 4, 2023
  8. test: BIP324: add checks for v1 prefix matching / wrong network magic detection e1308967e1
  9. theStack force-pushed on Oct 4, 2023
  10. theStack commented at 10:07 pm on October 4, 2023: contributor

    Rebased on master, now that #28577 is merged. Diff:

     0diff --git a/test/functional/p2p_v2_transport.py b/test/functional/p2p_v2_transport.py
     1index 47828867b..dd564fed8 100755                                                                                                        
     2--- a/test/functional/p2p_v2_transport.py
     3+++ b/test/functional/p2p_v2_transport.py
     4@@ -130,9 +130,8 @@ class V2TransportTest(BitcoinTestFramework):                                                                         
     5         assert_equal(self.nodes[4].getblockcount(), 11)            
     6                                                                    
     7         # Check v1 prefix detection                                                                                                     
     8-        # TODO: this should have the same prefix size as the one used for wrong network magic detection (see below)
     9-        V1_PREFIX = MAGIC_BYTES["regtest"] + b"version\x00"
    10-        assert_equal(len(V1_PREFIX), 12)
    11+        V1_PREFIX = MAGIC_BYTES["regtest"] + b"version\x00\x00\x00\x00\x00"
    12+        assert_equal(len(V1_PREFIX), 16)
    13         with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:                                                   
    14             num_peers = len(self.nodes[0].getpeerinfo())                                                                                
    15             s.connect(("127.0.0.1", p2p_port(0)))                                                                                       
    16@@ -143,11 +142,11 @@ class V2TransportTest(BitcoinTestFramework):                                                                       
    17             self.wait_until(lambda: self.nodes[0].getpeerinfo()[-1]["transport_protocol_type"] == "v1")                                 
    18                                                                                                                                         
    19         # Check wrong network prefix detection (hits if the next 12 bytes correspond to a v1 version message)                           
    20-        wrong_network_magic_prefix = MAGIC_BYTES["signet"] + V1_PREFIX[4:] + b"\x00\x00\x00\00"
    21+        wrong_network_magic_prefix = MAGIC_BYTES["signet"] + V1_PREFIX[4:]
    22         with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    23             s.connect(("127.0.0.1", p2p_port(0)))
    24             with self.nodes[0].assert_debug_log("V2 transport error: V1 peer with wrong MessageStart"):
    25-                s.sendall(wrong_network_magic_prefix)
    26+                s.sendall(wrong_network_magic_prefix + b"somepayload")
    

    (note that some more data has to be sent after the 12-bytes v1 message type string, to trigger calling the ProcessReceivedKeyBytes method which contains the detection of the wrong network magic prefix)

  11. Sjors commented at 7:29 am on October 5, 2023: member
    utACK e1308967e1a7e0ab275ab4c6f2f94c4ca0ee517b
  12. DrahtBot requested review from sipa on Oct 5, 2023
  13. maflcko commented at 10:50 am on October 5, 2023: member
    lgtm ACK e1308967e1a7e0ab275ab4c6f2f94c4ca0ee517b
  14. fanquake merged this on Oct 5, 2023
  15. fanquake closed this on Oct 5, 2023

  16. theStack deleted the branch on Oct 5, 2023
  17. Frank-GER referenced this in commit 92cf68a6d8 on Oct 13, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-06-29 16:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me