Key Features Of Bitcoin Language Called Script
The complexity of Bitcoin does not come only from privacy and security. Of course, there are several methods of data protection in use. Hashing of two types and elliptic curves protect data consistency. A strict block and transaction structure protect miners' efforts. Data exchange protocols applied to reach the connection between neighboring nodes were partially developed by the Bitcoin team. And also, we shouldn’t forget about the software itself which is the implementation of all rules and principles mentioned above.
However, in the Bitcoin environment there is a component which, due to its complexity, requires separate consideration. This is a programing language called Script. The reason to distinguish it from other components is that it is changeable. You can’t change network rules or a block structure without writing a new update and applying it to all Bitcoin participants. But you can write a rule for your transaction approvement with the help of the Script code.
Let’s find out more about this Bitcoin issue.
So, what is Script after all? It is the simplest programing language. It lacks several complex structures to be called Turing-complete. Script uses stack and it is an altered version of the Forth language.
This is an innate property of any programming language. To be more precise, this is the requirement programming languages may or may not satisfy. In general, it means that a language is capable of solving any finite task with strict and clear conditions. Different sources can give a different list of requirement. If a language possess all of them, it can be considered Turing-complete.
There is an important property that is absent in the Bitcoin programing language — a repetition commands set. You can place many identical commands one after another but can’t create a loop with several lines of the code. This restriction was made to prevent infinite loops in the code execution, as Bitcoin developers can be responsible for wallet software but they can’t manually control all transactions written by participants.
The stack-like nature of Script comes from Forth. This property is inherited and gets along with Bitcoin goals. A stack is a certain memory area accessed by programs. Each stack has two access modes called FILO and FIFO. These names stand for “first-in, last-out” and “first-in, first-out” and explain how elements placed in the stack are to be processed thereafter. Script accesses the stack in the FILO mode.
Every program unlocking funds is a combination of two parts. Both of them are written in Script and consist of two different object types:
- Data unit. This group includes public keys, hash data, and signature. When a Script processor meets this data in the code it simply puts it in the stack.
- Operation code. This group includes commands that explain what to do. The commands can perform some minor operations, such as comparison or duplication.
These two parts of a single code line are taken from the output of one transaction and the input of the next transaction. After they are written together, their content is taken and processed, one component by another. After the whole line is processed, there can be two outputs. If the result is satisfactory — the current transaction input is valid and funds are unlocked. If the result is false — the current transaction input is invalid and should be replaced.
In this article, we took a brief look at the Script programing language used in Bitcoin. Some core properties of this language were explained, yet there are many interesting details left. We will talk about them in our next articles.