Bitcoin Script
Also called: Script, Bitcoin scripting language, scriptPubKey, scriptSig, locking script.
Bitcoin Script is the simple stack-based language that sets the conditions for spending each output, such as which signatures or timelocks are required.
Bitcoin Script is the small programming language that decides who can spend a coin. Every output carries a locking script (scriptPubKey). To spend it, the spender supplies data in an unlocking script (scriptSig) or witness, and every node runs the two together. The spend is valid only if the script finishes without error and leaves a true value on the stack.
How Script works
Script is stack-based and read left to right. Each opcode is one byte that either pushes data onto the stack or acts on it. A classic P2PKH output is:
OP_DUP OP_HASH160 <20-byte public key hash> OP_EQUALVERIFY OP_CHECKSIG
The spender provides a signature and public key; the script checks that the key hashes to the right value and that the signature is valid.
Script deliberately has no loops, so every script finishes and its cost is predictable. Limits keep validation cheap: stack items of at most 520 bytes, at most 1,000 items on the stacks, and (outside Tapscript) scripts of at most 10,000 bytes with at most 201 non-push opcodes.
How Script has evolved
- BIP 16 (P2SH) lets an output commit to a script hash, with the script revealed when spending.
- BIP 65 and BIP 112 turned spare NOP opcodes into timelocks.
- BIP 141 (SegWit) moved scripts and signatures into the witness and added script versions.
- BIP 342 (Tapscript) added Schnorr signature checks and OP_SUCCESS upgrade hooks.
Raw Script is easy to get wrong, so wallets increasingly use Miniscript (BIP 379) and output descriptors. Every opcode is listed in the opcode reference.