Lec 5 - BCT
Lec 5 - BCT
Scripts
Mechanics of Blockchain:
Scripts
● A script is a program or sequence of
instructions that is interpreted or carried
out by another program rather than by
the computer processor
● Bitcoin script is based on stack-based
programming. The stack-based scripting
language embedded in Bitcoin
transactions.
● Bitcoin scripts are compact, simple,
Scripts
● When bitcoins are sent to a recipient, Script commands
in an unlocking script (scriptSig) validate the available
bitcoins (UTXOs), while Script commands in a locking
script (scriptPubKey) set the conditions for spending
them.
Input Script
Output Script
Bitcoin Scripts
Bitcoin Scripts
● There are 2 components of Bitcoin Script
(separated by whitespace): Data & Instruction
● Data: Digital Signature, Public Key of sender,
Public key of receiver, etc. Data is always pushed
to stack!
● Operation: A keyword recognizable by Bitcoin
client software, has a prefix of “OP_”. Operation
always executes a specific function!
● Arithmetic Operations
● If/Then Conditions
● Logic/Data Handling
● Cryptographic Functions
○ Computation of Hashes
○ Signature Verification
○ Multi-signature Verification
Bitcoin Script opcodes
opcode Description
OP_CHECKSIG Takes public key and signature and validates the signature of the hash of
the transaction.
OP_IF If top stack value is not False, the statements are executed. The top
stack value is removed.
OP_HASH160 The input is hashed twice: first with SHA-256 and then with RIPEMD-160.