Definition
The script stack is the core data structure of Bitcoin Script, the Forth-like, stack-based language that decides whether a transaction may spend an output. Script has no loops and is intentionally simple: opcodes push data onto and pop data off a single last-in-first-out (LIFO) stack, processed strictly left to right.
How evaluation works
Spending an output combines two scripts: the unlocking script (legacy scriptSig, or the witness in SegWit) supplied by the spender, and the locking script (scriptPubKey) attached to the output by its creator. The unlocking script runs first, pushing items such as a signature and public key onto the stack. The locking script then runs, consuming those items with opcodes like OP_DUP, OP_HASH160, and OP_CHECKSIG. A transaction input is valid only if, after both scripts finish, the stack is left with a single non-zero (true) value on top.
Why a stack
A constrained, stack-based model keeps validation deterministic and bounded — every node reaches the same verdict, and there are no unbounded computations to exhaust resources. This predictability is what allows scripts to encode multisignature, hashlocks, and timelocks while remaining safe to run on every node in the network. Conditional opcodes let a single script offer multiple spending paths along the same stack.
Branching within the stack is handled by OP_IF / Script Conditional opcodes, and in SegWit the unlocking data arrives via the Witness Stack rather than scriptSig.
In Simple Terms
The script stack is the core data structure of Bitcoin Script, the Forth-like, stack-based language that decides whether a transaction may spend an output. Script…
