Bitcoin Script is the stack-based language that defines spending conditions. It is intentionally limited — not Turing-complete — so validation stays predictable and safe for nodes.
Complete Step 1 // Required reading in the study plan above (locking/unlocking + P2PK + P2PKH), then continue here.
Step 2 — Core idea: lock, unlock, predicate
Wallets, multisig vaults, Lightning commitments, and covenant proposals all express rules in Script (or Tapscript). Misreading a scriptPubKey means misunderstanding who can spend coins.
Analogy: A locking script is a riddle on a locked box. The unlocking script (scriptSig/witness) is the answer. Nodes run both and check that the riddle evaluates to true.
When spending:
- Take the previous output’s
scriptPubKey(lock) - Provide
scriptSig/ witness (unlock) - Execute according to consensus rules
Loading diagram…
Script pushes and pops values on a stack. OP_DUP, OP_HASH160, OP_EQUALVERIFY, and OP_CHECKSIG appear often in P2PKH-style templates. You rarely write these by hand today — descriptors and Miniscript generate them — but reading them debugs explorers and policy bugs.
Opcodes like OP_CHECKLOCKTIMEVERIFY (CLTV) and OP_CHECKSEQUENCEVERIFY (CSV) add time constraints. Lightning depends on these. Miniscript helps compose policies safely.
Even if a script is consensus-valid, mempool policy may refuse to relay non-standard forms. Test both inclusion via miner on regtest and relay approximating mainnet policy.
Done when: You can explain lock vs unlock and why Script is a predicate, not a general language.
Step 3 — Climb the output-type ladder (lab)
Do not memorize every opcode first. Climb the historical ladder (Decoding Bitcoin modules in the study plan):
- P2PK — pay directly to a public key (simple, leaks the key early)
- P2PKH — pay to
HASH160(pubkey); classic1.../ wrapped patterns - P2SH — pay to a script hash; reveal the redeem script only at spend (BIP16)
- P2MS — bare multisig; usually wrapped in P2SH/P2WSH in practice
- SegWit / Taproot — witness programs (
P2WPKH,P2WSH,P2TR) — later lessons
# Conceptual P2WPKH witness stack (after the ladder)
<signature> <pubkey>Complete required P2PKH, then one further step (P2SH, P2MS, or stack project). Optionally:
bitcoin-cli -regtest decodescript <hex>Human policy (“2-of-3 keys, or Alice alone after 90 days”) becomes a composition of multisig and timelock branches. Taproot can hide unused branches until needed.
Common mistakes
- Hand-editing scripts without policy tests
- Confusing policy intent with exact opcode encoding
- Assuming non-standard scripts will relay on default mempool policy
Done when: Lab evidence (P2PKH + one further ladder step + lock/unlock paragraph) is complete.
Next lesson
SegWit & Bech32 — how witnesses changed fees, malleability, and address formats.