Bitcoin Script is a simple, stack-based programming language used in Bitcoin transactions to define how outputs can be spent. It functions as a locking and unlocking mechanism for transaction outputs, ensuring that the person attempting to spend the bitcoins has the right to do so.
The script consists of two parts: the locking script (or scriptPubKey) which is attached to an output and specifies the conditions under which the output can be spent, and the unlocking script (or scriptSig) which is attached to an input and provides the data required to satisfy those conditions. When a node receives a spending transaction, it combines these scripts and runs them from left to right using a data structure called a stack. If the result is valid, the transaction is authorized.
Understanding Bitcoin Input Output Transaction Model: What is UTXO?
Scripts are not Turing complete, meaning they do not support loops or other constructs that could potentially consume excessive computational resources. This limitation ensures security and efficiency across the network. While P2PKH (Pay-to-Public-Key-Hash) is the most commonly used script type, more complex scripts can enable functionalities like multisig addresses, where multiple signatures are required to authorize a transaction.
Bitcoin Script is intentionally designed to be non-Turing complete for several important reasons: