test: Add reorg<->mempool invariants related to CVE-2025-62861 #36841

pull instagibbs wants to merge 5 commits into bitcoin:master from instagibbs:2026-11-reorg-invariants changing 4 files +108 −18
  1. instagibbs commented at 7:08 PM on November 11, 2026: member

    Adds a functional test for regression coverage, then a couple targeted invariance Assum()s. Finally, fuzz harness changes to give more coverage of reorg behavior.

    Future work could include harness with a real chain and chain tip, and package_eval improvements to catch ephemeral dust policy regressions more directly.

  2. DrahtBot added the label Tests on Nov 11, 2026
  3. DrahtBot commented at 7:08 PM on November 11, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    Concept ACK darosior, ismaelsadeeq
    Stale ACK mercie-ux, janb84

    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. fanquake added this to the milestone 33.0 on Nov 11, 2026
  5. darosior commented at 10:07 PM on November 11, 2026: member

    Concept ACK

  6. mercie-ux commented at 8:47 AM on November 12, 2026: contributor

    Tested ACK f19656b94bb4822d38e842f7b1929f4ca148a445

    Verified that with sibling eviction re-enabled during reorg, the new test fails while test_truc_reorg still passes.

  7. DrahtBot requested review from darosior on Nov 12, 2026
  8. ismaelsadeeq commented at 7:53 AM on November 13, 2026: member

    Concept ACK

  9. javierpmateos commented at 5:34 PM on November 13, 2026: none

    Tested f19656b

    Built with -DABORT_ON_FAILED_ASSUME. mempool_truc.py passes, including the new test_truc_reorg_no_sibling_eviction test.

    I ran 1,200 iterations with my two-node randomized reorg test (4 seeds, 3 configurations). This covered BIP68, double-spends, TRUC, coinbase spends, reorgs up to 20 blocks, and the invalid-block case where cleanup runs at a lower intermediate tip. About 10k transactions were in the disconnected blocks. Neither Assume() failed.

    I also checked that the checks actually fire. Making the mempool size check fail caused an abort right away. Removing TX_MISSING_INPUTS or TX_PREMATURE_SPEND from the allowed rejection cases also caused aborts (the latter with the coinbase variants). Reverted everything after each check.

    I didn't run or review the fuzzing changes, and haven't covered all the rejection cases yet (cluster limits, non-standard, witness).

    Scripts: https://gist.github.com/javierpmateos/358865d350735dd76bcf821b1fe1cac4 (mempool_reorg_twonode_random.py)

  10. bitcoin blocked a user on Nov 14, 2026
  11. in src/validation.cpp:343 in f19656b94b outdated
     342 | -                AcceptToMemoryPool(*this, *it, GetTime(),
     343 | -                    /*bypass_limits=*/true, /*test_accept=*/false).m_result_type !=
     344 | -                        MempoolAcceptResult::ResultType::VALID) {
     345 | +            bool accepted{false};
     346 | +            if (fAddToMempool && !(*it)->IsCoinBase()) {
     347 | +                const auto size_before{m_mempool->size()};
    


    janb84 commented at 2:29 PM on December 2, 2026:

    NIT: maybe add an additional assume. the size Assume (L348) rests on "doesn't conflict with the mempool", but that premise isn't checked itself. If a conflict did occur and the replacement was rejected, the size is unchanged and the reason can be one IsExpectedReorgRejection accepts. So a broken invariant would go unnoticed. Asserting the premise before AcceptToMemoryPool closes that, and also catches txn-already-in-mempool / txn-same-nonwitness-data-in-mempool earlier:

                    // A transaction from a disconnected block doesn't conflict with the mempool: the
                    // mempool was consistent with the old chain, in which this transaction spent its inputs.
                    Assume(std::ranges::none_of((*it)->vin, [&](const CTxIn& txin) EXCLUSIVE_LOCKS_REQUIRED(m_mempool->cs) {
                        return m_mempool->GetConflictTx(txin.prevout) != nullptr;
                    }));
                    const auto size_before{m_mempool->size()};
    

    instagibbs commented at 3:28 PM on December 2, 2026:

    taken

  12. janb84 commented at 2:33 PM on December 2, 2026: contributor

    ACK 217050c22ec8e8ce73bdb5469ac9cb426808acaf

    Fuzzing is not my forte so only ack-ed the non-fuzzing commits (I did use it for testing).

    Reverted the #33504 m_bypass_limits guard around SingleTRUCChecks:

    • with only the new test_truc_reorg_no_sibling_eviction running, the size Assume fires; - without the Assumes, CTxMemPool::check asserts on the stranded grandchild's missing prevout, so the test catches the regression on its own.
    • the existing test_truc_reorg trips Assume(accepted || IsExpectedReorgRejection(...)) on a TRUC-violation.

    Took a close look at all the IsExpectedReorgRejection cases, given its importance and that it is (hand) composed. Looks good.

  13. DrahtBot requested review from janb84 on Dec 2, 2026
  14. instagibbs force-pushed on Dec 2, 2026
  15. DrahtBot added the label CI failed on Dec 2, 2026
  16. DrahtBot commented at 4:59 PM on December 2, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task lint: https://github.com/bitcoin/bitcoin/actions/runs/46914940118/job/143580223994</sub> <sub>LLM reason (✨ experimental): lint_fail: The assert_falsy lint check rejects assert(false) in src/validation.cpp:319, requiring AssertUnreachable() instead.</sub>

    <details><summary>Hints</summary>

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • Intermittent network issues can occur; re-run CI for now, and report the issue if they keep happening.

    • A functional or integration test failure may be intermittent or unrelated to this pull request. If no dedicated issue thread exists, create a new one to track it.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  17. test: reorg doesn't sibling-evict a TRUC child with a descendant
    Catches a revert of the CVE-2025-62861 fix (#33504): the evicted child's descendant is left spending a missing output.
    251dfda410
  18. validation: Assume reorg re-add never removes mempool transactions 831fc1d7be
  19. validation: Assume reorg re-add rejections don't depend on mempool policy 0dcb0fd81f
  20. fuzz: tx_pool: re-add the mined block through MaybeUpdateMempoolForReorg
    Runs the real reorg path, so its Assumes catch a re-add that evicts or rejects on policy.
    ef437991ac
  21. fuzz: tx_pool: add rejected transactions to the reorged block
    Gives the reorg block topologies the mempool won't build, catching e.g. CVE-2025-62861 (TRUC sibling eviction on reorg).
    df3c0db177
  22. instagibbs force-pushed on Dec 2, 2026
  23. instagibbs commented at 7:01 PM on December 2, 2026: member

    Appeased the assert_falsy linter on rebase

  24. DrahtBot removed the label CI failed on Dec 2, 2026

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-12-04 00:51 UTC

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