THAMER
Sovereign Bitcoin Wallet

WALLET AI BITCOIN

Your Bitcoin Wallet. Your Keys. Your Engine.

Self-hosted Bitcoin software built for developers, applications, and AI agents.

CREATE WALLET

Bitcoin Invalid Blocks Explained: Chainwork, Reorgs, and Rejection

permalink THAMER
#bitcoin-invalid-blocks#block-rejection#chainwork#reorganizations

Bitcoin's chain-selection rule is often shortened to "follow the longest chain." That phrase is imprecise. A validating node selects the valid chain with the greatest accumulated proof of work, subject to its consensus rules. An invalid block does not become acceptable merely because many blocks are mined on top of it.

Work is not a substitute for validity

Each valid block header contributes work derived from its difficulty target. Nodes can compare candidate branches by accumulated chainwork. However, the branch must also pass contextual block and transaction validation before its blocks can be connected to the active chainstate. A branch containing an invalid spend or excessive coinbase reward cannot win by accumulating more work.

Invalid headers versus invalid bodies

A header can fail proof-of-work or difficulty checks immediately. Another header may pass initial checks while the full block later fails due to a bad Merkle commitment, invalid script, double spend, or other consensus violation. Headers-only synchronization does not establish that the underlying blocks have been fully validated.

What happens in a reorganization?

When a competing valid branch has more cumulative work, the node may disconnect blocks from its active tip and connect blocks on the stronger valid branch. UTXO changes from disconnected blocks are undone, and the new branch's transactions update chainstate. Wallets and payment processors must handle confirmations decreasing or transactions returning to an unconfirmed state.

Example: competing branches

Suppose a node has validated branch A. Branch B extends an earlier ancestor and eventually has more work. If B's blocks all validate, the node can reorganize to B. If one B block spends an already-spent UTXO, the branch fails validation; additional descendants cannot repair that invalid ancestor.

Invalidity versus temporary uncertainty

A node may know about a promising header chain while still downloading its block data. This is not proof that the chain is invalid; it is not yet fully validated. Similarly, a block can be valid but temporarily unavailable from peers. Keep separate states for header-known, block-available, block-validated, and active-chain membership.

Implications for applications

A transaction with one confirmation is included in the current active chain, not guaranteed to remain there forever. More confirmations increase the work an attacker would generally need to replace that history, but do not create absolute finality. Applications should use risk-appropriate confirmation policies and explicitly handle reorg events.

Primary references

Bitcoin Developer Guide — Block Chain: https://developer.bitcoin.org/devguide/block_chain.html
Bitcoin Core validation source: https://github.com/bitcoin/bitcoin/blob/master/src/validation.cpp
Bitcoin Developer Reference — Block Headers: https://developer.bitcoin.org/reference/block_chain.html

Questions & Answers

Explore all questions →

Latest from the Lab

THAMER illustrated developer portrait and signature

ABOUT THE DEVELOPER

Independent Software Developer specializing in Bitcoin Script, Golang, and AI Agents.

Software engineering · Independent research · Open-source projects