Skip to content

mining: backport bitcoin/bitcoin#33745 (reset cached block checks in IPC submitSolution) #278

Closed

Description

@kiwidream

Summary

BlockTemplate::submitSolution (the IPC mining interface) replaces the template's coinbase and recomputes the merkle root. It does not reset the block's cached check flags.

CreateNewBlock already validated the template with TestBlockValidity, which leaves m_checked_witness_commitment = true. So when the solved block reaches ProcessNewBlock, ContextualCheckBlock skips the witness commitment and unexpected-witness checks for the coinbase the client supplied. The node can then accept a block as its tip that its peers reject.

This code is inherited unchanged from Bitcoin Core v30.2. Upstream fixed it in bitcoin/bitcoin#33745 ("mining: check witness commitment in submitBlock", merged to master on 2025-11-12). That fix is not in 1.x.x.

Affected code (1.x.x @ e374ba2)

  • submitSolution calls AddMerkleRootAndCoinbase and then ProcessNewBlock on the mutated template block:
    bool submitSolution(uint32_t version, uint32_t timestamp, uint32_t nonce, CTransactionRef coinbase) override
    {
    AddMerkleRootAndCoinbase(m_block_template->block, std::move(coinbase), version, timestamp, nonce);
    return chainman().ProcessNewBlock(std::make_shared<const CBlock>(m_block_template->block), /*force_processing=*/true, /*min_pow_checked=*/true, /*new_block=*/nullptr);
    }
  • AddMerkleRootAndCoinbase swaps the coinbase and recomputes the merkle root without resetting fChecked, m_checked_merkle_root or m_checked_witness_commitment:

    qbit/src/node/miner.cpp

    Lines 451 to 461 in e374ba2

    void AddMerkleRootAndCoinbase(CBlock& block, CTransactionRef coinbase, uint32_t version, uint32_t timestamp, uint32_t nonce)
    {
    if (block.vtx.size() == 0) {
    block.vtx.emplace_back(coinbase);
    } else {
    block.vtx[0] = coinbase;
    }
    block.nVersion = version;
    block.nTime = timestamp;
    block.nNonce = nonce;
    block.hashMerkleRoot = BlockMerkleRoot(block);
  • The template's TestBlockValidity call sets the witness-commitment flag:

    qbit/src/node/miner.cpp

    Lines 189 to 193 in e374ba2

    if (m_options.test_block_validity) {
    if (BlockValidationState state{TestBlockValidity(m_chainstate, *pblock, /*check_pow=*/false, /*check_merkle_root=*/false)}; !state.IsValid()) {
    throw std::runtime_error(strprintf("TestBlockValidity failed: %s", state.ToString()));
    }
    }
    →
    block.m_checked_witness_commitment = true;
  • CheckWitnessMalleation returns early when the flag is set:

    qbit/src/validation.cpp

    Lines 4390 to 4392 in e374ba2

    {
    if (expect_witness_commitment) {
    if (block.m_checked_witness_commitment) return true;

Impact

Only a local client of the IPC mining interface (qbit-node -ipcbind) can trigger this. ENABLE_IPC defaults to on for non-Windows builds. The RPC submission paths decode a fresh block, so they are not affected.

A client that submits a coinbase without the witness reserved value, or with a commitment that does not match the block's transactions, gets the block accepted as the local tip. Peers reject the block as mutated, so nothing is cached as invalid on other nodes. The miner, however, ends up on a block the network does not follow.

Fix

Backport bitcoin/bitcoin#33745:

  • Reset m_checked_witness_commitment, m_checked_merkle_root and fChecked at the end of AddMerkleRootAndCoinbase.
  • Bring over the test/functional/interface_ipc.py coverage: submitting a coinbase without its witness must be rejected, and resubmitting with the witness must succeed.
  • Bring over the doc updates in src/interfaces/mining.h and src/validation.h.

Activity

  1. added
    bug
    on Nov 3, 2026
  2. kiwidream commented on Nov 4, 2026

    @kiwidream
    MemberAuthor

    Fixed on 1.x.x by #289 (merged as 21fee6e). AddMerkleRootAndCoinbase now resets m_checked_witness_commitment, m_checked_merkle_root and fChecked. interface_ipc.py checks that a coinbase submitted without its witness is rejected and that resubmitting it with the witness succeeds. main gets the fix when 1.x.x is integrated. The AuxPoW-version abort found while reviewing the backport stays open as #291.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions