Bitcoin: Under the Hood
Bitcoin Script: The Logic Behind Every Transaction · 1/2

A tiny, stack-based language with no loops

Every Bitcoin transaction output is locked by a small program written in Bitcoin Script, and every input that spends it must supply data that makes that program evaluate successfully. Script is a stack-based language: operations push and pop values on a stack, and there's no concept of variables, functions, or control flow beyond simple conditionals. The most common pattern, Pay-to-Pubkey-Hash (P2PKH), locks funds to the hash of a public key. To spend it, you provide your signature and your actual public key, the script hashes the public key and checks it matches, then verifies the signature proves you control the corresponding private key.

This is deliberately primitive compared to a general programming language. There's no way to write a loop that runs an unpredictable number of times, no way to make network calls, and no way to access outside data. Every script is guaranteed to finish executing in a small, predictable number of steps.