The script is the power of bitcoin, it allows the sender to decide who can redeem a transaction, how, and when
A series of commands are provided by the protocol, together with some of the commands of a generic programming language make this manipulation possible
which commands are available?
Let’s talk a bit more about the programming language, and what it means for a language to be like Forth or more generally stack-based
Ehm.. ok, can you give an example?
Let’s start with the most basic operation:
1 + 1, in a standard programming language this operation is generally done like this
var x = 1 + 1
The result of the operation will be contained in the variable x, but with a stack-based programming language the operation would look like this
1 1 +
Fist we put the number we want to operate with on the stack, then we put the operation, so we get 1 1 on the stack, and then we do the + operation between them, the result will be then pushed on the stack
This programming language has an important property: it is NOT Turing complete, which means It can’t loop infinitely, granting that the hardware of the miner won’t get stuck on an infinite script
This is important, it keeps the solidity of Bitcoin and doesn’t create a vulnerability where the system is most vulnerable.
Where is the script placed in the transaction?
The script is split into two parts, the first is the output of the transaction, that defines who, how, and when the receiver can redeem the transaction, the second part is in the input of another transaction, the purpose of this part is to provide the information defined by the sender to redeem the transaction
What’s the order of execution of input and output?
Since the input provides the information, and the output verifies the information, the input is executed first, putting all the info on the stack, the information is then verified by the input, and based on the result, the transaction can be valid or not
A complete example will be in the next article, where we’ll talk about Pay to public key hash (aka P2PKH)