Technical definition
Bitcoin Script is a non-Turing-complete, stack-based scripting language embedded in Bitcoin transactions. It operates by evaluating a sequence of opcodes (operations) against a stack of data elements. Scripts define spending conditions by pushing data (e.g., public keys, signatures) and executing opcodes (e.g., OP_CHECKSIG, OP_EQUAL) to verify cryptographic proofs. The language is intentionally limited in complexity to avoid vulnerabilities like infinite loops, making it deterministic and efficient. Scripts are evaluated in a linear, left-to-right manner, with the final stack state determining whether the transaction is valid.
An analogy
Imagine Bitcoin Script as a set of rules written on a piece of paper that must be followed to unlock a safe. The rules might say, 'Unlock the safe if two people sign this note with their keys.' The paper (script) is checked by a locksmith (the Bitcoin network), who verifies the signatures match the keys before allowing access. The locksmith doesn’t care about the complexity of the rules as long as they are clear and executable.
Why it matters
Bitcoin Script enables programmable money by defining how bitcoins can be spent, allowing for basic smart contracts, multi-signature wallets, and time-locked transactions. Without it, Bitcoin would be limited to simple transfers of ownership.
Where it came from
Bitcoin Script was introduced with Bitcoin’s genesis block in 2009 by Satoshi Nakamoto. It was designed to be intentionally limited to avoid security risks while still supporting essential functionality like digital signatures and basic conditions for spending.
Example in practice
A common use of Bitcoin Script is a 2-of-3 multi-signature transaction, where three parties each hold a key, and any two must sign to spend the funds. The script might look like: `OP_2 <PubKey1> <PubKey2> <PubKey3> OP_3 OP_CHECKMULTISIG`. This ensures that at least two signatures are required to unlock the bitcoins.
Common misconceptions
- Bitcoin Script is a full programming language → Correction: Bitcoin Script is intentionally limited and not Turing-complete, meaning it cannot perform loops or complex computations.
- Bitcoin Script is used for all Bitcoin transactions → Correction: Most Bitcoin transactions use a simplified script (Pay-to-PubKey-Hash, or P2PKH), which hides the underlying Script for efficiency and usability.
Risks & limitations
- Limited functionality: Bitcoin Script’s non-Turing-complete design restricts its ability to create complex smart contracts, limiting its use cases compared to platforms like Ethereum.
- Script malleability: Some scripts can be manipulated by third parties to alter transaction IDs before confirmation, though this is mitigated by SegWit and Taproot upgrades.
- Complexity risks: While Script is simple, poorly designed scripts can introduce security vulnerabilities, such as in early multi-signature implementations before P2SH.
- No built-in state: Bitcoin Script cannot maintain or reference external state, making it unsuitable for applications requiring persistent data (e.g., decentralized exchanges).