Feedback
Sign in./start

Site navigation

Theme

Learn

  • Roadmaps

Build

  • Projects
  • Developer Tools

Contribute

  • Open Source Projects
  • Issues
  • Reviews
  • First Contribution
  • BountiesSoon
  • Feedback

Prove

  • Builders

Ecosystem

  • Partners
  • Get Funded↗
  • HackathonsSoon
Sign in./start-building

Become an Open Source Builder. Learn. Build. Contribute. Prove.

Feedback welcome — open a GitHub issue.

Learn

RoadmapsStart Building

Build

ProjectsDeveloper Tools

Contribute

Open Source ProjectsIssuesReviewsFirst ContributionSupportFeedback

Prove

Builders Directory

Account

Sign in

Legal

PrivacyTermsCredits

© 2026 Pull // code MIT · curriculum CC BY-SA 4.0

PrivacyTermsCredits

lesson // bitcoin

Bitcoin Script

Learn script puzzles, locking conditions, and standard output types.

intermediate7 days

Public lesson — sign in to track progress on this roadmap.

./sign-in

On this page

Learning objectives

  • Explain locking vs unlocking scripts
  • Walk the standard output ladder (P2PK → P2PKH → P2SH → P2MS → SegWit/Taproot)
  • Reason about Script as a predicate, not a general programming language

study // plan

Lessons are primers. Start with Step 1 (required reading) when present, then follow the numbered steps in the article. Depth comes from primary sources, labs, reflection, and evidence.

Research on Bitcoin Search
Bitcoin scriptP2PKHP2SHMiniscript

Step 1 // Required reading

Complete these before the numbered steps in the lesson body. Links are listed here once — not repeated below.

  • bookMastering Bitcoin

    Ch. 7: Authorization and Authentication

Interactive lab // Decoding Bitcoin

Open these Bitcoin Dev Project modules and tools before (or alongside) the graded lab. Capture evidence from the interactive path — do not only skim Pull.

  • Decoding Bitcoin: Locking & unlocking

    Start here - scriptPubKey vs scriptSig/witness mental model.

  • Decoding Bitcoin: P2PK

    Ladder step 1 - pay to public key (and why wallets moved on).

  • Decoding Bitcoin: P2PKH

    Ladder step 2 - hash the key; complete at least one P2PKH exercise.

  • Decoding Bitcoin: P2SH

    Ladder step 3 - hide redeem scripts until spend (BIP16).

  • Decoding Bitcoin: P2MS

    Ladder step 4 - bare multisig vs P2SH-wrapped policy.

  • Decoding Bitcoin: Build a Bitcoin stack

    Capstone mini-project - stack execution before descriptors/Miniscript.

Reflection prompts

  1. Explain Bitcoin Script to a teammate without jargon - what problem does it solve?
  2. What would break in production if you misunderstood Bitcoin Script?
  3. Walk P2PK → P2PKH → P2SH in one paragraph: what problem did each step solve?

Lab // Script ladder + stack exercise

Complete Steps 2–3. Finish the Decoding Bitcoin output-type ladder through P2PKH (required), then either one P2SH/P2MS exercise or the stack project. Optionally verify a matching template on regtest with decodescript / descriptors.

evidence required

  • ·Link or screenshot from a completed Decoding Bitcoin P2PKH exercise
  • ·Evidence from one further ladder step (P2SH, P2MS, or stack project)
  • ·One-paragraph comparison of locking vs unlocking for the template you studied
  • ·Optional: decodescript / descriptor output from regtest matching that template
  1. 01

    Worked mental model

    Re-read the diagrams in this lesson once out loud in plain language. If you cannot explain the flow to a friend without jargon, pause and revisit the Mastering Bitcoin / Mastering Lightning chapters linked in Resources. Chapter references are intentional, not decorative.

  2. 02

    Hands-on habit

    Every protocol idea should be paired with one local experiment. That habit turns reading into builder instinct.

    1. Reproduce the happy path on regtest (or Polar for Lightning)
    2. Break it on purpose (wrong fee, expired invoice, offline peer)
    3. Write down what error you saw and which layer produced it (wallet, node, mempool, peer)
  3. 03

    Glossary check

    Pick three terms from this lesson and define them in one sentence each without opening notes. Weak definitions mean the lesson is not finished yet.

  4. 04

    Resource order

    Use Resources in order: narrative book chapter first, then BIP/BOLT for precision, then implementation docs for commands. Jumping straight to RPC flags without the mental model creates brittle knowledge.

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:

  1. Take the previous output’s scriptPubKey (lock)
  2. Provide scriptSig / witness (unlock)
  3. Execute according to consensus rules

Loading diagram…

Spends succeed only when the unlocking data satisfies the lock.

Script is a predicate

Think “does this satisfy the condition?”, not “run an app on-chain.” Loops and unbounded complexity are restricted for a reason.

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):

  1. P2PK — pay directly to a public key (simple, leaks the key early)
  2. P2PKH — pay to HASH160(pubkey); classic 1... / wrapped patterns
  3. P2SH — pay to a script hash; reveal the redeem script only at spend (BIP16)
  4. P2MS — bare multisig; usually wrapped in P2SH/P2WSH in practice
  5. 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.

further reading

  • docsScript opcodes reference
  • docsMiniscript

review // club

Review club

Practice on real Bitcoin OSS changes tied to this chapter. Read the diff, use the checklist, and optionally paste your review comment URL in your lab notes.

  • rust-bitcoin serialization PRs

    Review a rust-bitcoin PR touching transaction or script encoding and check test coverage.

    pr review
    consensus encodingtests
    40 min·intermediateopen on GitHub
review checklist
  1. Does the change solve the stated problem?
  2. Are edge cases and rollout behavior covered?
  3. Are tests or test vectors included?
  4. Is the diff minimal and clearly explained?

More repos and GFIs on /discover and /issues.

progress // sign in

Reading is public. Sign in to mark lessons complete, sync across devices, and unlock your roadmap.

./sign-in-to-track

discussion

Discussion

prevTransactionsnextSegWit & Bech32

On this page

Press Shift + ? for keyboard shortcuts.

Press R to research on Bitcoin Search.

No questions yet — be the first to ask.