RoadmapsProjects
Sign in./start

Learn

RoadmapsProjects

Contribute

DiscoverIssues

Account

Sign in./start-building

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

Learn

RoadmapsProjectsStart Building

Contribute

DiscoverIssues

Account

Sign inDashboardSettings

Legal

PrivacyTerms

© 2026 Pull // all rights reserved

PrivacyTerms

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. Depth comes from required reading, interactive labs, reflection, and a hands-on check with evidence — the BOSS study pattern.

Research on Bitcoin Search

Required reading

  • 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 the Decoding Bitcoin output-type ladder through P2PKH (required), then either finish 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

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.

Why this matters

Wallets, multisig vaults, Lightning commitments, and covenants proposals all express rules in Script (or Tapscript). Misreading a scriptPubKey means misunderstanding who can spend coins.

Analogy

A locking script is a riddle printed on a locked box. The unlocking script (scriptSig/witness) is the answer. Nodes run both and check that the riddle evaluates to true without crashing the rules.

Locking and unlocking

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.

Output-type ladder

Do not memorize every opcode first. Climb the historical ladder (Decoding Bitcoin modules linked in the study plan):

further reading

  • docsScript opcodes reference
  • docsMiniscript

progress // sign in

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

./sign-in-to-track
prevTransactionsnextSegWit & Bech32

On this page

Press Shift + ? for keyboard shortcuts.

Press R to research on Bitcoin Search.

  • P2PK — pay directly to a public key (simple, leaks the key early)
  • P2PKH — pay to HASH160(pubkey); classic 1... / 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) — covered in later lessons
  • # Conceptual P2WPKH witness stack (after the ladder)
    <signature> <pubkey>

    Modern wallets mostly emit SegWit/Taproot, but reading P2PKH/P2SH is how you debug explorers, old UTXOs, and policy bugs.

    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.

    Timelocks and composeability

    Opcodes like OP_CHECKLOCKTIMEVERIFY (CLTV) and OP_CHECKSEQUENCEVERIFY (CSV) add time constraints. Lightning channel constructions depend on these. Miniscript helps compose policies safely instead of hand-writing fragile scripts.

    Common mistakes

    • Hand-editing scripts without policy tests
    • Confusing policy intent (“2-of-3 after 30 days”) with the exact opcode encoding
    • Assuming non-standard scripts will relay on default mempool policy

    Stack execution intuition

    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.

    Standardness

    Even if a script is consensus-valid, mempool policy may refuse to relay non-standard forms. Always test both:

    1. Inclusion via miner on regtest (generatetoaddress after submit)
    2. Relay behavior approximating mainnet policy

    From policy to Script

    Human policy: "2-of-3 keys, or Alice alone after 90 days."

    That becomes a composition of multisig and timelock branches. Miniscript exists so you do not invent unsafe encodings. Taproot can hide unused branches until needed.

    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 Mastering Bitcoin / Mastering Lightning chapters linked in Resources. Chapter references are intentional, not decorative.

    Hands-on habit

    Every protocol idea should be paired with one local experiment:

    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)

    That habit turns reading into builder instinct.

    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.

    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.

    Next steps

    Finish the Decoding Bitcoin ladder through P2SH (and the stack project if you can). Then learn SegWit: how witnesses changed fees, malleability, and address formats. Then move on to Taproot.