Bitcoin developer has selected Forth programming language to write code. The code consists of the sender’s public key, signature, operations. Every transaction has a minimum of two codes, the first code is called ScriptSig, and the second one is called ScriptPubKey.
- ScriptSig: It contains the public key and signature of the sender.
- ScriptPubKey: It contains operations code, sender bitcoin address, and other data.
The Forth is stack-based, procedural, without type checking, and it uses reverse polish notation. It is not Turing complete Programming Language as it does not support looping (No halting problem). The selection of this language may be because of security reasons as it supports minimal functionalities that were sufficient to perform the necessary operations in the bitcoin ecosystem.
Understand the script with an Example
Step 1: Combine these two scripts together that looks as follows:
Step 2: Push the operands such as signature and public key of Alice into the stack.
Step 3: OP_DUP duplicates top operator inside the stack.
Step 4: Pop the top operator and generate 160-bit hash and again push into stack.
Step 5: Push the operand into stack.
Step 6: Pop top two operand and perform the operation.
Step 7: Check the signature of Alice.
The above example just illustrated how the Forth language works and how the bitcoin ecosystem executes the script to perform validation of transactions. There are many opcodes that are supported by bitcoin architecture.
Summary
This note shows how to write a script and how the system processes a script to perform the transaction validation and execution.
References:
- NPTEL lecture series on Blockchains Architecture, Design and Use Cases by Prof. Sandip Chakraborty, IIT Kharagpur.
170 total views, 1 views today