Like all programming languages, Bitcoin Script now has a number of properties and characteristics that make it unique. Among them we can mention the following:
- The command processing is of the batch or batch type. This means that the instructions are stacked on top of each other.
- The reading order is of type LIFO (Last In – Last Out). This means that the last command to enter the stack is the first to exit.
- This language is not full turing, which means that it has limited functionality.
- The Bitcoin script codes are called OP_CODES or operation codes. Actually as it is designed by Bitcoin Script, only 256 OP_CODES can exist in this system. These codes help us, among other things, in the creation of operations for memory manipulation, mathematics, loops and function calls.
- In language it takes very little strength to carry out its instructions.
In addition to these elements, there are two other elements that are important in Bitcoin Script. These elements are scriptSig and scriptPubKey. The first, scriptSig, is the unlock script, which requires a public key and digital signature. Nbsp; The second, the PubKey script, is the blocking script, which contains a public key hash, also known as a Bitcoin address.
But let’s look at each of these parts in practice using a simple example that we’ll explain step by step.
Example of a Bitcoin script
An example of Bitcoin Script would be the following statement, which is called scriptPubKey:
OP_DUP OP_HASH160 f6b137461f8bd00a52357670fd2b175b259937d7 OP_EQUALVERIFY OP_CHECKSIG
In addition, these codes are accompanied by the following sig script or signature script.
At first glance, the sentence is difficult to read. But if we study the same thing, we will be able to understand the same thing. Let’s take a look at the scriptSig first. These rooms contain two important pieces of data, the user’s public key and their digital signature. This data is the first to be entered into the Bitcoin Script execution stack. First, the signature and second, the public key.
Then the script starts to run. The first operation is the operation code. OP_DUP. This code indicates that the top of the command stack should be doubled. That is, the public key is duplicated. his duplicate in third place. The second function code is OP_HASH160. This code commands the duplicate public key to be converted using the functions SHA-256 and RIPEMD-160.
This means that it will take the public key and it will apply a SHA-256 hash. We apply a hash to the result of this operation RIPEMD-160. Your end result is finally put on the stack. Nbsp; Next, the script shows us another hash RIPEMD-160that is simply copied onto the stack to make room for the next operation.
The next operation in the script is OP_EQUALVERIFY. This will take the two hashes RIPEMD-160 (the one that comes from the scriptSig public key and the one that comes from the Bitcoin script) and verify á do it now. If the operation is true, it continues execution of the script and otherwise the transaction; marked as invalid. nbsp;
The code remains to complete the process OP_CHECKSIG, which asks us to check the digital signature of the scriptSig. If the signature is also checked correctly, the entire process is considered to be genuine and the result is reproduced in the blockchain.
As you can see, it is a very linear and easy to understand process. Scripts can contain a variety of statements, of course, but some of them are standard. For example, this script we examined is called P2PKH (Pay to Pub Key Hash). This is currently the most common way to create transactions between two people in Bitcoin.
That said, every time we make a transaction in Bitcoin, our wallets write a similar programming. In summary, these scripts are interpreted by the nodes. This happens when the nodes receive a valid block from the miners. In fact, this little example comes from a real transaction that you can review here.