bitcoindevkit / bitcoindevkit/bdk

Emitter silently replaces the caller’s genesis on a network mismatch

Open
#2,290 0 comments 0 reactions 1 assignee Claimed by @tvpeter View on GitHub
bug
Dominant language
Rust
Stars
1.1k
Forks
483
Avg merge
20d 3h
Merged PRs (30d)
3

Description

**Describe the bug**

When `Emitter` cannot find any caller-provided checkpoint on the RPC node, it silently replaces its checkpoint chain with the node's genesis and continues emitting blocks. This happens with an ordinary wrong-network configuration, such as mainnet checkpoints connected to a regtest node.

The emitted checkpoints no longer connect to the supplied chain, contrary to `BlockEvent::checkpoint`'s documented guarantee. `LocalChain::apply_update` rejects them, but the emitter has already switched its internal chain without reporting the mismatch.

This issue was found by AI.

**To Reproduce**

1. Run a regtest Bitcoin Core node with at least one mined block.
2. Create a `LocalChain` from mainnet genesis and pass its tip to `Emitter::new` with that node's RPC client, `start_height = 1`, and `NO_EXPECTED_MEMPOOL_TXS`.
3. Call `next_block()`. It returns a regtest block instead of reporting the network mismatch. Its checkpoint chain ends at regtest genesis, and `connected_to()` points to that genesis.
4. Apply the emitted checkpoint to the original `LocalChain`; it returns `CannotConnectError` at height 0.

Confirmed with an RPC stub returning `-5` for the caller's genesis and serving a chain rooted at a different genesis.

**Expected behavior**

An endpoint on a different network should not silently replace the caller's chain root or produce events that violate the documented connection guarantee.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.