Bitcoin Consensus
Bitcoin consensus = the set of rules every full node enforces to decide if a block / transaction is valid for inclusion in the chain. Distinct from mempool policy (which is a node-local default for what tx to accept and relay).
Block validation (high-level)
- Decoded block header is well-formed (80 bytes).
prev_blockexists and points to current best chain (or triggers reorg).- Proof-of-work:
SHA256d(header) ≤ targetwhere target is derived from the difficulty re-target window (every 2016 blocks). - Block timestamp > median of last 11 blocks (MTP) and ≤ network-adjusted time + 2 hours.
- Coinbase is the first tx, has 1 input with null prevout, scriptSig length in [2,100], and includes BIP34 height in scriptSig (active since block 227,931).
- Witness commitment in coinbase's
OP_RETURNmatches the merkle root ofwtxids (BIP141). - Merkle root of
txids matches header. - All transactions are individually consensus-valid (see below).
- Total fees + subsidy ≥ coinbase value.
Transaction validation
- Non-empty
vinandvout. - No negative or
> MAX_MONEY(21M × 1e8 sats) output amount. - No duplicate inputs (within the tx).
- Coinbase input present iff this is the coinbase tx.
- For each non-coinbase input: prevout exists in UTXO set and is unspent.
- Script execution succeeds for
scriptSig + scriptPubKeyand (post-segwit) the witness stack. - Sum(inputs) ≥ Sum(outputs).
- nLockTime / nSequence rules (BIP65, BIP112) — see proposals/.
Soft-fork activation
| Mechanism | First used | Note |
|---|---|---|
| BIP9 (versionbits) | CSV (BIP68/112/113), SegWit (initially) | bit signaled in version field; needs 95% of last 2016 |
| BIP8 (LOT=true/false) | proposed for Taproot, debated | BIP9 + lockinontimeout option |
| Speedy Trial (BIP9 short window) | Taproot deployment 2021 | 3-month signaling, 6-month grace |
nLockTime / nSequence semantics (key for layer-2)
nLockTime: tx valid only after specified block-height or unix-time.nSequenceper-input:0xFFFFFFFF→ final, disablesnLockTimefor that input.0xFFFFFFFE→ opt-in RBF disabled (BIP125).< 0xFFFFFFFE→ opts in to RBF.- BIP68 relative locktime when input's tx version ≥ 2:
- bit 31 = 0 → relative time enforced
- bit 22 = 0 → block-height units, =1 → 512s units
- low 16 bits = the lock value
Consensus vs Policy
| Layer | Examples | Where defined |
|---|---|---|
| Consensus | block size weight ≤ 4M WU, sigops ≤ 80k, nLockTime, output value rules | src/consensus/ in Core |
| Standardness | non-standard scripts rejected by mempool, dust threshold, MAX_STANDARD_TX_WEIGHT=400k, replaceability, package limits |
src/policy/ |
A tx that is non-standard but consensus-valid can be mined (via
direct submission to a miner like mempool.space accelerator) and is
valid in a block.
Recent additions
- Package relay (BIP331) — mempool now accepts dependent packages, enables CPFP for unconfirmed parents at any depth (within ancestor limits).
- TRUC v3 transactions (BIP431) — version=3, ≤1 unconfirmed ancestor, ≤ 10kvB, sibling-eviction, child can pay 0 fee. Pairs with ephemeral anchors (output value = 0, must be spent in same package).
See also
- transactions/SKILL.md — tx structure, sighash
- scripts/SKILL.md — Script language
- proposals/SKILL.md — covenants, unactivated forks
Reference
- Bitcoin Core source:
src/consensus/,src/validation.cpp - BIPs: 9, 8, 16, 30, 34, 65, 68, 112, 113, 141, 143, 144, 147, 341, 342, 431