Skip to main content

Script | Bitcoin Glossary | Mapping Bitcoin

Script

Protocol

Also known as: Bitcoin Script

Bitcoin's stack-based programming language used to define the conditions under which a transaction output can be spent. Script is intentionally limited (non-Turing-complete) to ensure predictable execution and security.

Overview

Script is Bitcoin's built-in programming language that defines the conditions for spending transaction outputs. Every bitcoin output contains a small program (the locking script or scriptPubKey) that specifies what evidence must be provided to spend it. The spender provides the evidence in the unlocking script (scriptSig) or witness data. When a node validates a transaction, it executes these scripts to determine if the spending conditions are satisfied.

Stack-Based Execution

Script uses a stack-based execution model, similar to the Forth programming language. Data and operations are processed using a last-in, first-out (LIFO) stack:

Example: P2PKH Script Execution

Unlocking Script:  <sig> <pubKey>
Locking Script:    OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG

Execution (read left to right, stack grows upward):

Step 1:    Step 2:    Step 3:     Step 4:       Step 5:
<sig>      <pubKey>   <pubKey>    <hash160>
           <sig>      <pubKey>    <pubKey>      OP_EQUALVERIFY
                      <sig>      <sig>         (compares top 2)
                                               <pubKey>
                                               <sig>

Push sig   Push key   OP_DUP     OP_HASH160    Step 6:

                                               OP_CHECKSIG
                                               → TRUE ✓

Why Non-Turing-Complete

Script is deliberately limited. It has no loops, no recursion, and a restricted set of opcodes. This is a feature, not a limitation:

  • Predictable execution — Every script terminates in bounded time and memory
  • No infinite loops — A malicious script cannot consume infinite node resources
  • Verifiable — The behavior of any script can be fully analyzed before execution
  • Security-focused — The attack surface is minimized by limiting capabilities

Common Script Types

Script TypeDescriptionAddress Prefix
P2PKPay to Public Key (original, rarely used)N/A
P2PKHPay to Public Key Hash1...
P2SHPay to Script Hash3...
P2WPKHPay to Witness Public Key Hashbc1q...
P2TRPay to Taprootbc1p...

Script Evolution

Bitcoin Script has evolved through several upgrades:

  • Original — Basic opcodes for signature checks and hash comparisons
  • P2SH (2012) — Enabled complex scripts hidden behind a hash
  • SegWit (2017) — Moved script execution to the witness, fixing transaction malleability
  • Taproot (2021) — Introduced Tapscript with new opcodes and Schnorr verification

Common Misconception

Bitcoin Script is sometimes dismissed as too limited for useful programmability. In reality, it supports a wide range of spending conditions including multisig, timelocks, hash locks, and combinations thereof. The Miniscript project demonstrates that complex, composable policies can be expressed within Script's constraints while maintaining safety guarantees.