What is Bitcoin Script?

Tiempo de lectura: 4 minutos

When we talk about Bitcoin Script we refer to a Bitcoin programming language. It handles transaction processing. From transactions as simple as micro payments to multi-user accounts. This language is read from left to right and bases its operation on a set of linear structures known as stack. The instructions of this language are executed in consecutive order one after the other.

It is important to note that this language is not Turing Complete so it cannot solve all types of problems. Its operation is limited to not allowing loops in the system. However, this limitation is not a disadvantage, since it is intentionally created. Thanks to this limitation, in case of any error in the system, it would not be repeated constantly.

Otherwise, very complicated operations could be created in a loop, slowing down the system and consuming the total Hash rate. This programming language is highly important, since it allows the writing of programs and the computer to execute our commands. OP_CODES are used for this purpose. These are used for functions such as mathematics, loops, function calls, etc….

In other words, Bitcoin Script is a set of instructions that record every transaction made. These instructions establish how users can make use of the network and gain access to Bitcoins.

Qué-es-Bitcoin-Script1

Why was Bitcoin Script created?

The goal of Bitcoin Script is to offer a set of flexible parameters that allow Bitcoin transactions in a simple way. For this very purpose Satoshi Nakamoto disabled certain functions when he developed Bitcoin, including multiplication. For this reason it is a simple script in terms of programming.

This language decides whether or not a transaction can be carried out on the network. In other words, it decides whether such a transaction is authorized to transfer funds. The Bitcoin Script brings the programmable nature of Bitcoin. Thanks to the Bitcoin Script we can make a transaction that will only take place if certain conditions are met. Properties like this are only found in cryptocurrencies. This makes them different from the current digital money and especially from paper money.

This program is an evolution that allows money to act independently and decentralized according to the programming implemented in it. But the Bitcoin Script not only allows transactions, it also avoids the creation of errors in the system and avoids the use of complex operations. This script converts transactions into easy-to-calculate operations and, as we have already mentioned, it does not allow infinite loops that slow down the network.

How does Bitcoin Script work?

Among the most widely used scripts on the network today is the P2PKH script.  Scripts are vital to carry out any type of Bitcoin operation. In this, each action is performed by a specific script that determines what should be done. In this operation nothing will happen that is not dictated by a Bitcoin Script.

A standard script would consist of a two-part structure, the ScriptPubKey and the ScriptSig. This type of script is the most common way to perform a BTC transaction.

The ScriptPubKey could be :

15higMjoCCNXSA95xZbJUdPvXNmkAduhCA

And the ScriptSig would be a set of numbers and letters similar to the following :

760402203f004eeed0cef2715643e2f25a27a28f3c578e94c7f0

f6a4df104e7d163f7f8f022100b8b248c1cfd8b55a0365107a9511d

759b7544d979dd152a955c867epect0ef79702

At first glance we only see the difficulty of a mixture of numbers and letters impossible to understand, but it is really the layer behind which hides a totally simple system.

In the scriptPubKey we see the actions to be performed in the transaction and in the ScriptSig we see the public key and signature that will help verify the authenticity of the transaction. This is how the Bitcoin Script ensures that the user sending the transaction has access to the funds and can move them.

All this involves the OP_CODES mentioned above. These are operation codes that represent a portion of a language instruction that specifies what operation will be performed.

In addition, OP_CODEs create advanced structures and schedule operations within the blockchain. Each OP_CODE has a different task. Some carry out input modification, others handle data verification and ensure that the data is correct and valid, and some duplicate items. Each OP_CODE performs an important role in the operation of the Bitcoin Script.

Execution of a Script

To execute a script the first step is to duplicate the public key of the owner of the funds involved in the transaction. This key then undergoes a hashing process where the SHA-256 hash is applied. The RIPEMD-160 hash is applied to the resulting combination.

Once this last hash has been applied, the result of the hashes is compared with the hash found in the public key of the scriptPubKey to verify that it is the same key and that it is verified as valid. Once it has been verified that the script matches, it proceeds to execute and passes to the CHECKSIG where the signature is verified through the public key.

Smart contract language

It is very common for users to believe that Bitcoin is incapable of creating smart contracts. Bitcoin Script is Bitcoin’s smart contract language so it can create smart contracts. It should be noted that Bitcoin’s smart contract capabilities are limited compared to Ethereum, however, the Bitcoin network has this capability.

We already know that Bitcoin Script does not share all the capabilities of a full Turing machine so it does not allow loops and thanks to this we can determine when a program will end and how it will end. In Bitcoin Script there is no possibility of creating scripts that run forever, just as it is impossible for the language to block programs or their executor.

These limitations lag Bitcoin’s smart contracts compared to Ethereum, however, they ensure greater security in the network.

Qué-es-Bitcoin-Script1

Bitcoin Script Features

The Bitcoin programming language has features that differentiate it from other languages. Below we will see some of them.

  • Small language. This language is considered small, since it contains only 256 instructions and each instruction is expressed in one byte.
  • It contains all the information. There is no state of the transaction before or after the script, since all the information is contained in it.
  • Limited functionality. Bitcoin Script is limited so it brings a higher level of security to the system.
  • It is simple as it requires minimal processing.
  • Adaptability. because of its simplicity it can be run on a wide range of devices.
  • Incomplete Turing language. Being incomplete, it does not allow loops. This ensures that the program stops repeating itself and with it the errors in the network.

Leave a comment
Your email address will not be published. Required fields are marked *