Magic Internet Math

Satoshi Ep10: Script and Opcodes


Listen Later

This podcast episode delves into Satoshi Nakamoto's writings on Bitcoin script and opcodes, exploring how Bitcoin's scripting language enables sophisticated financial contracts.

Key Topics:

  • Bitcoin Script
  • Stack-Based Programming Language
  • Opcodes
  • Transaction Conditions
  • Standard Script Types
  • Summary:

    Bitcoin is not merely a ledger of balances, but a programmable money system where every transaction includes scripts defining spending conditions. The design supports a variety of transaction types, including escrow transactions, bonded contracts, third-party arbitration, and multi-party signatures. Satoshi chose a controlled supply to create digital gold, ensuring no central bank could inflate the currency.

    Bitcoin Script is a stack-based programming language used to define these transaction conditions. It's deliberately simple, lacking loops and persistent state to ensure predictability and prevent infinite loops that could halt the network. This simplicity is a key feature. Scripts are not Turing-complete by design, always terminating with predictable resource usage. Each transaction output contains a locking script, while each input provides an unlocking script. Satoshi described the script as a predicate, an equation that evaluates to true or false.

    The stack-based execution model of Script involves pushing data onto the stack, with operators popping items off, processing them, and pushing results back. When script execution completes, the transaction is valid if the top stack item is true (non-zero). Opcodes are single operations in Script, identified by a byte value, that perform specific actions such as pushing data, manipulating the stack, performing arithmetic, checking signatures, or evaluating conditions. Bitcoin has over 100 opcodes, though many are disabled for security reasons. The most commonly used opcodes handle stack manipulation, cryptographic operations, and conditional logic. Satoshi aimed to design Bitcoin to support every possible transaction, but each addition required special support code and data fields, regardless of usage.

    While Script is flexible, most transactions use a few standard patterns. Non-standard scripts are valid but may not be relayed by default nodes. The classic Bitcoin address format hides complexity until spending time. Standard script types like P2PKH, P2SH, and multisig cover most use cases while maintaining compatibility. Satoshi disabled risky opcodes early on, prioritizing security over features, with the option to re-enable them later if deemed safe.

    In summary, Bitcoin script is a stack-based language that defines spending conditions for each transaction output. It is intentionally not Turing complete, ensuring scripts always terminate with predictable resource usage. Opcodes perform operations like hashing, signature verification, and conditional logic on stack data. Standard patterns cover most use cases while maintaining compatibility, and Satoshi prioritized security by disabling risky opcodes early on.

    ...more
    View all episodesView all episodes
    Download on the App Store

    Magic Internet MathBy Brian HIrschfield and Rob Hamilton