kernel: don't reuse cached CheckBlock results across params #36353

pull FlashWayne wants to merge 1 commits into bitcoin:master from FlashWayne:fix-kernel-block-check-cache changing 2 files +50 −2
  1. FlashWayne commented at 10:36 PM on September 26, 2026: none

    CheckBlock returns true right away when block.fChecked is set (validation.cpp:3930). The signet solution is only checked inside CheckBlock. PoW is checked again for new headers in AcceptBlockHeader, the signet solution isn't.

    In the kernel API a btck_Block wraps a shared CBlock, and btck_block_copy only adds a reference. Once a block passes btck_block_check or btck_chainstate_manager_process_block under one set of consensus params, the flag stays set on the shared object, and every later check on it passes, whatever params or flags are passed:

    • a regtest block fails btck_block_check with mainnet params and ALL flags. After it has been checked once with regtest params, the same call with mainnet params returns 1.
    • a signet block that satisfies an OP_TRUE challenge but not an OP_RETURN one: processing it on a chainstate manager with the OP_TRUE challenge first, then on a second one with the OP_RETURN challenge, connects it on both. The second chain then can't read its own tip back with btck_block_read, because ReadBlock does check the signet solution.

    bitcoind isn't affected, since it only has one chainstate manager and one set of params. btck_block_check and the custom signet chain params are new in 32.0, and their header docs don't say a block may only be used with one set of params.

    This runs both entry points on a copy of the block without the cached flags. The copy is built from the header plus the transaction list, so it only copies the transaction pointers. It also means btck_block_check no longer writes to the caller's block without cs_main (the comment at validation.cpp:4422).

    Two cases are added to test_kernel.cpp that match the examples above. On master they give 4 failures, with the fix test_kernel passes.

  2. kernel: don't reuse cached CheckBlock results across params
    CheckBlock returns early when block.fChecked is set, and the signet
    solution is only checked inside CheckBlock. A btck_Block wraps a shared
    CBlock (btck_block_copy only adds a reference), so once a block passed
    btck_block_check or btck_chainstate_manager_process_block under one set
    of consensus params, every later check on the same object passes,
    whatever params or flags are used. For example, a regtest block checked
    first with regtest params then passes btck_block_check with mainnet
    params, and a signet block accepted by a chainstate manager with an
    OP_TRUE challenge is also connected by a second one with an OP_RETURN
    challenge.
    
    Run both entry points on a copy of the block without the cached
    fChecked/merkle/witness flags. The copy only shares the transaction
    pointers. This also avoids writing to the caller's block from
    btck_block_check without cs_main.
    9d735dae13
  3. DrahtBot added the label Validation on Sep 26, 2026
  4. DrahtBot commented at 10:36 PM on September 26, 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/36353.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

Contributors

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-09-28 10:51 UTC

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