Lecture Note
University
Princeton UniversityCourse
Bitcoin and Cryptocurrency TechnologiesPages
5
Academic year
7
anon
Views
30
Bitcoin Scripts As we previously stated, each transaction output actually specifies a script in addition to a plain public key. What exactly do I mean by that, and why do we utilize scripts? This sectionwill describe the Bitcoin scripting language and explain why it is utilized rather than justissuing a public key. Okay, so to understand scripts, I think the easiest way by an example. And we'll take as an example the most common script in Bitcoin, which is to redeem a previous transaction bysigning with the correct public key. The output address would therefore appear as follows in that scenario. Indeed, the output address is a script. What happens to the script in this situation as there are four instructionsin it? Who oversees it? Who is able to use these coins is indicated by the script in what way?The input address is also a script, which is the trick. Hence, you simply concatenate thatpiece of script with the output address to create a single script that must executesuccessfully in order to claim a Bitcoin. So traditionally, these two scripts are called scriptSig and scriptPubKey, and that's because in the simplest case, the output script just specifies the public key, and the input scriptspecifies a signature with that public key. When a transaction is being validated, the two scripts get pasted together, they get run, and if the concatenated script can run without an errors, this is considered a valid transaction. So, where did this scripting language come from? It truly doesn't have a name. It was created especially for Bitcoin and is simply known as Script or the Bitcoin scripting language. You don't need to be familiar with Forth to graspBitcoin scripting, but Forth is a simple, classic stack-based programming language thatserved as its main source of inspiration. The key design properties here were to have something that was quite simple, quite compact, but yet had support for pretty sophisticated cryptography. So there are specialpurpose instructions to do compute hash functions, and to compute signatures and verifysignatures. And this is a stack-based language. And you may have never seen a stack-based language before in your life. But I'll explain in the next slide what that means and why that was chosen.So there are a lot of limits here that are important to keep in mind. In particular there are noloops in the Bitcoin scripting language. Every instruction is executed exactly once in a linearmanner. So if you look at a script, just based on the number of instructions in the script, youknow exactly how long it might take to run and how much memory it could use.
So this is not a turning complete language. It is unable to calculate functions with arbitrary power. And this is deliberate since the miners are required to execute these programs that are provided by arbitrary network users.Hence, you shouldn't grant them the authority to submit a script that might contain an infiniteloop or execute indefinitely. And since it's not a turning complete language, we don't have the halting problem. You can look at any Bitcoin script and be sure that it's going to terminate within a finite number ofsteps, which is just the number of instructions that are in that script. Okay, now the fun part.We're gonna look at a specific Bitcoin script, and exactly how it's executed. This is the same example as before, this is the most common script in Bitcoin. A script where the sender of coins simply specifies the public key of the recipient, and the recipient of the coins, to redeem them, has to specify a signature using that specified publickey. The recipient defined the signature and the public key used to produce it in the script's sig component or input script, therefore the first two instructions in this script are just datainstructions, as I previously stated. So executing data instructions is easy in a stack based language. If you see data, you just pushed it unto the stack. And that's the only interaction with memory that you have with a stack based programming language. There's no variables, there's only a stack, so the only thing you can do to write data to memory is to push it onto the stack. So after we've pushed those two values onto these stack, we're gonna start executing the second half of the script which was specified by the sender of the coins. So this is the scriptpubKey component of the script. And now we're gonna start to actually manipulate some of those values on the stack. So this duplicate instruction, OP_DUP, says, simply take the value that's on the top of the stack, pop it off, and then write two copies back to the stack. So we're just gonna duplicate that public key. The next instruction, HASH160, says, take the top value on the stack and compute a cryptographic hash of it. Understanding Bitcoin Scripting Language: Verification of Transactions and Signatures
Bitcoin is a digital currency that operates on a decentralized system that is powered by a network of computers. Transactions made on the Bitcoin network are verified by the networknodes and then added to the blockchain, which is a public ledger containing all thetransactions that have taken place on the network. In order to ensure the validity oftransactions and prevent fraud, Bitcoin uses a scripting language to verify transactions andsignatures. The Bitcoin scripting language is a simple, stack-based language that is used to create scripts that are executed by the Bitcoin Virtual Machine (VM). These scripts are included inthe inputs of Bitcoin transactions and are used to verify that the transaction is valid. Thescripts contain a set of instructions that are executed in order to determine whether thetransaction is valid or not. In this article, we will provide an overview of the Bitcoin scripting language, how it is used to verify transactions and signatures, and the various instructions that are available. Verification of Transactions On the Bitcoin network, when a transaction is made, it is broadcast to the network nodes, who subsequently confirm the transaction. By running the transaction's input script, thenodes confirm that the transaction is genuine. The script contains a set of instructions that are executed by the Bitcoin VM. The script must end with a TRUE or FALSE value, which determines whether the transaction is valid ornot. If the script returns a TRUE value, the transaction is considered valid and is added to theblockchain. If the script returns a FALSE value, the transaction is considered invalid and isnot added to the blockchain. The scripting language is used to create complex conditions that must be met before a transaction is considered valid. These conditions can include requirements such as thetransaction must be signed by a specific person or group of people, or that a certain amountof time must pass before the transaction can be considered valid. Verification of Signatures In order to verify that a transaction is valid, the script must also verify the signatures associated with the transaction. This is done using a set of instructions that are built into theBitcoin scripting language. The private key of the individual initiating the transaction is used to sign transactions. As a result, the transaction is associated with a special digital signature. The public key linked tothe transaction must then be compared to the signature by the script to ensure its validity.
The script verifies the signature using the CHECKSIG instruction, which checks the signature against the public key. If the signature is valid, the script returns a TRUE value,and the transaction is considered valid. If the signature is not valid, the script returns aFALSE value, and the transaction is considered invalid. Multi-Signature Verification In addition to single-signature verification, Bitcoin also supports multi-signature verification. Multi-signature verification allows transactions to be verified by multiple parties, making itmore secure and reducing the risk of fraud. Multi-signature verification is done using the CHECKMULTISIG instruction, which verifies that a certain number of signatures are valid before the transaction is considered valid. Thisallows transactions to be verified by multiple parties, such as a group of executives in acompany, before they are considered valid. The CHECKMULTISIG instruction can be customized to require a specific number of signatures, or a certain combination of signatures from a specific group of people. Thisallows for complex verification conditions to be created, making it more difficult for fraudulenttransactions to be accepted into the blockchain. Conclusion A potent tool for verifying transactions and signatures on the Bitcoin network is the scripting language. The stack-based language's simplicity makes it simple to use and comprehend.The language is also adaptable, enabling the creation of sophisticated verificationcircumstances like multi-signature verification. Proof-of-Burn: Burning Coins for a Purpose Bitcoin, the world's first decentralized cryptocurrency, introduced a new way of handling transactions through blockchain technology. The blockchain is a distributed public ledger, inwhich every transaction is recorded and validated by a network of computers known asnodes. But, what happens when we want to write data into the blockchain? Or create analternative cryptocurrency? Or implement a script that is not standard? These are some ofthe challenges that Bitcoin's scripting language has to deal with, and one of the solutions iscalled Proof-of-Burn. Proof-of-Burn is a script that can never be redeemed, meaning that the coins associated with it are destroyed forever. This can be achieved by using the OP_RETURN code, whichthrows an error if it's ever reached, and whatever values you put before it will get executed
eventually, causing the program to crash. The data after OP_RETURN is never going to belooked at, which allows users to specify arbitrary data in a script. One of the main use cases for Proof-of-Burn is to write arbitrary data into the blockchain. For example, if you want to write your name or timestamp some data, you can create a verylow-value Bitcoin transaction that is Proof-of-Burn. By destroying a small amount of currency,you can write whatever you want into the blockchain, which will be kept around forever. Another use case for Proof-of-Burn is to bootstrap an alternative to Bitcoin. This can be achieved by forcing people to destroy Bitcoin in order to gain coins in the new system. In thisscenario, Proof-of-Burn is used as a way of exchanging one currency for another. One issue with Proof-of-Burn is that the sender of coins has to specify the script exactly. This can be a problem for consumers who want to send coins to a simple address. To solvethis problem, Bitcoin uses a clever hack called Pay-to-Script-Hash (P2SH). Instead ofspecifying the entire script, the sender can specify just a hash of the script that is needed toredeem those coins. The recipient of those coins only needs to submit the appropriate script for the transaction to be verified. The fundamental script is relatively simple to fulfill. The value of the scriptwhose hash the sender gave only has to be specified by the recipient as a data value. Thetop data value from the stack will, however, go through a specific second level of validationwhere it will be reinterpreted as instructions and then run a second time as a script. The realsignature check will take place right here. Bitcoin nodes, by default, have a whitelist of scripts, and they refuse to accept scripts that they consider non-standard. This doesn't mean that those scripts can't be used at all, but itmakes them harder to use. Therefore, it is important to use scripts that are accepted by thenetwork. In conclusion, Proof-of-Burn is a script that can never be redeemed, which makes it useful for writing arbitrary data into the blockchain or creating an alternative to Bitcoin. However, itsusage requires that the sender of coins specify the script exactly, which can be a problem forconsumers. Pay-to-Script-Hash is a clever hack that solves this problem, allowing the senderto specify just a hash of the script that is needed to redeem those coins. However, it isimportant to use scripts that are accepted by the network.
Bitcoin Scripts: How Transactions Are Verified and Signed
Please or to post comments