Ch.10: Something on Transaction Unlocking & Locking Script
There are different types of bitcoin transactions. The bitcoin address and script (unlocking & locking) will vary according to each transaction type. The various types of bitcoin transaction are as follow:
Recall that:
Bitcoin transaction consumes existing UTXO (at the input) by unlocking it with current owner’s signature (or together with public key/script), and generates new UTXO (at the output) by locking it to the new owner’s public key/public key hash/script hash.
The ‘unlocking’ & ‘locking’ are actually performed by programming language called ‘script’. A script is a stack-based program consist of data and opcode (operation code). The data are meant to be ‘push’ into the stack and ‘pop’ out of the stack. Please do not confuse this data with bitcoin transaction data. This data in script are basically public key, public key hash, script hash and signature. On the other hand, opcode ‘pop’ data out of stack, do something to the data, and ‘push’ the result back into the stack. If the result is ‘1’, then the script is valid.
There are two types of script in bitcoin transaction:
· Unlocking script (located at the input) also known as ‘scriptSig’
· Locking script (located at the output) also known as ‘scriptPubKey’
Unlocking & locking script help to validate a new transaction by checking on its signature/public key/script. If we refer to the diagram below, to validate a new transaction Tx15, we need to prove that the Red Man actually owns the output (UTXO) from previous transaction Tx1. This can be proven if Tx15’s unlocking script can ‘unlock’ Tx1’s output (UTXO). In the context of programming, we will run Tx15’s unlocking script & Tx1’s locking script together. If the result in the stack is 1, then the script is valid, Tx15’s signature/public key/script is valid and transaction TX15 is valid.
In the next few articles, we’ll look at the unlocking & locking script for different types of transactions, and see how the script helps to validate the transaction.
Remember
· unlocking script (scriptSig) is located at the input; locking script (scriptPubKey) is located at the output.