Bitcoin Script Language Command Groups
Various people joined Bitcoin since it was introduced in 2009. Some of them are enthusiastic about its future as the technological solution, while others are fond of its security and privacy. However, all of them use Bitcoin as a payment system.
In the Bitcoin environment, assets are transferred with the help of transactions. The proposed approach is flexible enough to allow simultaneously managing multiple money units. A single transaction may consist of several inputs and outputs associated with different money units. Each unit is called a coin.
Due to its heavy mathematical security approach, Bitcoin uses a complex transaction structure. One of its indispensable part, besides addresses and assets values, is a small program designed to support transaction security. This program is written with a programming language called Script. Script is limited in its functionality. The reason for such decision is to prevent writing a malicious transactions code. Nevertheless, it is complex enough to support various structures and addressing methods.
Let’s get acquainted with command groups and data used in programs based on this language.
Script Data And Code
Of course, the program part of each Script line is complementary to processed data. In theory, it is possible to create a script line without any commands. However, it will not be executable. In the same way no data code can be combined. But it will not be able to unlock any of the outputs. Since only the unlocking output provides spendable assets, there is no sense in such approach.
Some data storage issues may be recollected but they are not used for the main goal of asset transferring. Thus, they are irrelevant. Another possibility to avoid data is to create outputs spendable for anyone. This case is closer to the main Bitcoin functionality but it is obviously the lack of reasoning.
Data units used in the script commonly refers to addresses. They are public key, hash of public key, signatures, and script hash. All of them are used to assure assets transfer to the correct destination.
Script Commands Groups
As a programming language, Script supports various functionality. Although it has no looping commands, there are many options to be implemented. Looping is important in cases when software is big and should perform the same operations many times. Bitcoin has no necessity in these options. Each payment is performed only once. Moreover, there is no need for assets transfer recalculation in any way since all transactions are referring to each other and blockchain is immutable.
Main command groups are:
- Constants. These are numbers placed in the script. They can be of two kinds: numbers from -1 to 16 or numbers placed in the next several bytes.
- Flow control. Commands used to manage the program execution. They include a conditional statement used for branching and checking the top element of the stack.
- Stack control. Here are commands used to process stack top items. The group includes addition, removal, copying, duplication, etc.
- Arithmetic. Commands for mathematical operations.
- Crypto. Since Bitcoin heavily depends on data protection, it requires hashing commands. Signature verification commands are also placed here.
There are several smaller groups. Some of them hold only one command. They are intended for string management, bitwise logic application, time lock management, assisting codes, and reserved words. We should also notice that some commands are blocked and removed from the opcodes pool because of security concerns.
The Script language could be applied not only in the Bitcoin environment if it was necessary. However, it will unlikely ever happen because it is very specialized. Though, from the programming point of view, we can’t deny this. In our next articles, we will examine some simple implementations of the Script code.