net_processing: fix BIP152 first integer interpretation #35550

pull brunoerg wants to merge 2 commits into bitcoin:master from brunoerg:2026-06-addrman-branch changing 2 files +21 −1
  1. brunoerg commented at 5:58 PM on June 17, 2026: contributor

    Fixes #35542

    According to the BIP152, the first integer in sendcmpct message shall be interpreted as a boolean (and MUST have a value of either 1 or 0). We currently correctly interpret it as boolean, however, we accept any value >=1 and treat it as true, deviating from the specification. This PR fixes it.

  2. net_processing: fix BIP152 first integer interpretation 2d0dce0af5
  3. DrahtBot commented at 5:59 PM on June 17, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35550.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK edilmedeiros, davidgumberg, w0xlt, Sjors, jonatack
    Concept ACK yancyribbens

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. in test/functional/p2p_compactblocks.py:275 in 2e6276bcb3
     270 | +        node = self.nodes[0]
     271 | +        bad_peer = node.add_p2p_connection(TestP2PConn())
     272 | +        msg = msg_sendcmpct(announce=2, version=2)
     273 | +        with node.assert_debug_log(['invalid sendcmpct announce field']):
     274 | +            bad_peer.send_without_ping(msg)
     275 | +            bad_peer.wait_for_disconnect()
    


    jonatack commented at 8:17 PM on June 17, 2026:

    nit, can probably use the helper

    @@ -271,8 +271,7 @@ class CompactBlocksTest(BitcoinTestFramework):
             bad_peer = node.add_p2p_connection(TestP2PConn())
             msg = msg_sendcmpct(announce=2, version=2)
             with node.assert_debug_log(['invalid sendcmpct announce field']):
    -            bad_peer.send_without_ping(msg)
    -            bad_peer.wait_for_disconnect()
    +            bad_peer.send_await_disconnect(msg)
    

    brunoerg commented at 10:50 PM on June 17, 2026:

    Done.

  5. in src/net_processing.cpp:3945 in 2e6276bcb3 outdated
    3941 |          vRecv >> sendcmpct_hb >> sendcmpct_version;
    3942 |  
    3943 | +        // BIP152: the first integer is interpreted as a boolean and MUST have a
    3944 | +        // value of either 1 or 0.
    3945 | +        if (sendcmpct_hb > 1) {
    3946 | +            Misbehaving(peer, "invalid sendcmpct announce field");
    


    jonatack commented at 8:22 PM on June 17, 2026:

    Musing, perhaps "byte" or "message" instead of "field" here but no strong opinion.


    brunoerg commented at 10:55 PM on June 17, 2026:

    I'm fine with "byte" or "field", no strong opinion on this. Will keep as is for now. Thanks.

  6. jonatack commented at 8:28 PM on June 17, 2026: member

    ACK 2e6276bcb3560bf07f6daa689a052200a4eb0a54, might be good to verify that other implementations would not be affected by this tightening. Sanity checked getpeerinfo and -netinfo output.

  7. test: announce field must be 0 or 1 in sendcmpct abc33ff043
  8. brunoerg force-pushed on Jun 17, 2026
  9. brunoerg commented at 10:51 PM on June 17, 2026: contributor

    Force-pushed addressing #35550 (review)

  10. yancyribbens commented at 11:29 PM on June 17, 2026: contributor

    Concept ACK

  11. edilmedeiros commented at 12:33 PM on June 18, 2026: contributor

    utACK abc33ff043f07226d1f1f88a1d1ddce8dccdd930

    might be good to verify that other implementations would not be affected by this tightening.

    This was found during the review of the draft implementation for btcd. Floresta doesn't implement bip152.

  12. DrahtBot requested review from jonatack on Jun 18, 2026
  13. davidgumberg commented at 11:34 PM on June 18, 2026: contributor

    crACK https://github.com/bitcoin/bitcoin/commit/abc33ff043f07226d1f1f88a1d1ddce8dccdd930 Seems reasonable to comply with BIP152 strictly, test looks good as well.

  14. w0xlt commented at 6:13 AM on June 19, 2026: contributor

    ACK abc33ff043f07226d1f1f88a1d1ddce8dccdd930

  15. fanquake commented at 7:24 AM on June 19, 2026: member
  16. Sjors commented at 12:18 PM on June 19, 2026: member

    ACK abc33ff043f07226d1f1f88a1d1ddce8dccdd930 @edilmedeiros wrote:

    This was found during the review of the draft implementation for btcd.

    Glad to see more adoption.

    The other independent implementations (not code forks) that implement BIP152 support (usually just the message encoding), as far as I'm aware, seem fine:

  17. 0xB10C commented at 12:54 PM on June 19, 2026: contributor

    Happy to run this for a few days on a node and see if anything that connects to me triggers the misbehavior.

    edit: Dashboard https://demo.peer.observer/monitoring/d/bcrn2q4/misbehavior-of-peers-for-23-35550

  18. jonatack commented at 8:47 PM on June 19, 2026: member

    re-ACK abc33ff043f07226d1f1f88a1d1ddce8dccdd930

    Sanity-checked that Knots' code is the same as current master.

    Thanks @Sjors and @0xB10C for looking at other impls and the network.


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: 2026-06-20 23:51 UTC

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