Transactions & Network

Script

Script is Bitcoin's stack-based programming language used to define the conditions under which bitcoin can be spent. Every transaction output contains a locking script, and every input contains an unlocking script that satisfies those conditions.

How It Works

Bitcoin Script is intentionally limited — it is not Turing-complete, meaning it cannot create infinite loops or arbitrary programs. This is a feature, not a bug. The language supports a specific set of operations (opcodes) designed for transaction validation: checking digital signatures, verifying hash preimages, enforcing timelocks, and combining these conditions with boolean logic. This deliberate simplicity makes the system more secure and predictable.

Every transaction output contains a "locking script" (scriptPubKey) that defines what conditions must be met to spend the bitcoin. The most common type is Pay-to-Public-Key-Hash (P2PKH): "prove you have the private key corresponding to this public key hash." When spending, the input provides an "unlocking script" (scriptSig) containing the signature and public key. Nodes evaluate both scripts together, and if the result is true, the spend is valid.

Modern Bitcoin uses more sophisticated script types. P2SH (Pay-to-Script-Hash) allows complex scripts to be represented as a simple hash. P2WSH and P2TR (Taproot) further improve efficiency and privacy. Taproot is particularly elegant — it uses Schnorr signatures and MAST (Merkelized Abstract Syntax Trees) to make complex spending conditions look identical to simple single-sig transactions on-chain, dramatically improving privacy for multisig and timelock users.

Key Points

  • Stack-based language defining conditions for spending bitcoin
  • Intentionally not Turing-complete — simplicity is a security feature
  • Locking scripts set spending conditions; unlocking scripts satisfy them
  • Standard types: P2PKH, P2SH, P2WPKH, P2WSH, P2TR (Taproot)
  • Taproot makes complex scripts indistinguishable from simple transactions on-chain