CS120 Study Guide

Unit 7: Transactions and Scripting

7a. List the elements of a valid transaction 

  • Why does the Bitcoin network include transaction fees and how are they added to a Bitcoin transaction?

Transaction fees play a very important role on the Bitcoin network. They provide incentives to ensure that the network is used well and maintained. They serve as incentives to miners, encouraging them to continue the work of creating blocks, and transition fees offer a disincentive against abuse of the system by imposing a small cost on every transaction, discouraging spam.
 
How transaction fees are calculated is different than you might suspect. Rather than being based upon the value of a transaction, fees are calculated based on the size in kilobytes (and thus complexity) of a transaction. This protects the functioning of the network as it makes it expensive to send a large amount of big and complex transactions, which take up valuable resources on the network.
 
How fees are included in transactions has also been a point of confusion. Fees are not directly stated. Rather, they are inferred from the difference between inputs and outputs. Fees = Sum(Inputs) – Sum(Outputs)
 
To review, see What's in a Transaction?.
 

7b. Describe and understand the structure of unspent transaction outputs, or UTXOs 

  • Describe the Bitcoin scripting language used when locking and unlocking(spending) an Unspent Transaction Output, or UTXO.

The bitcoin transaction script language, called Script, is a Forth-like reverse-polish notation stack-based execution language. Unspent Transaction Outputs, or UTXOs, are locked using this script. When a transaction is broadcast to the network, it is validated by executing the unlocking Script in each input alongside the corresponding locking script. If this process satisfies the spending condition, the transaction is considered valid.
 
To understand this process, you'll need to be familiar with stack-based execution of a program. This process uses push and pop functions that add and remove items from the stack whose data structure is also called a Last-In-First-Out, or "LIFO" queue. This image can help you visualize how the transaction validation process works through a script.


Via this process, transaction inputs and outputs go through a locking and unlocking process. It is also important to note that the bitcoin transaction script language is stateless, as all the information needed to execute a script is contained within the script.
 
To review, see Scripts and Script Language.
 

7c. Describe the Bitcoin transaction timeline 

What is the Bitcoin mempool, and when would a transaction be in the mempool?
 
The mempool can be thought of as the transaction waiting room. It lists all broadcast and valid transactions that have yet to be "confirmed" or included in the blockchain. What is a bit confusing is that we often reference "the" mempool, it would be more accurate to say "a" mempool as each node maintains its own mempool.
 
A transaction is created by wallet software, signed using a private key controlled by the wallet, broadcast to peers on the network, validated by peers receiving the transaction, then sits in the mempool waiting to be included in a block. Once a miner has found a block that includes that transaction, we say that the transaction has one confirmation. Each time a block is added to the chain on top of that block that includes that transaction, we say that the transaction has another confirmation. Once the transaction has six confirmations, we consider it final.
 
To review, see Transactions and Multisig.
 

7d. Work with Bitcoin scripts

  • What are OP codes, and what are their roles in Bitcoin transactions?

Op codes are operators that push or pop one or more parameters from the stack, act on them, and perhaps push a result onto the stack.
 
To review, see Scripts and Script Language and Transactions and Multisig.
 

Unit 7 Vocabulary

This vocabulary list includes terms you will need to know to successfully complete the final exam.

  • Op codes
  • stack-based
  • transaction fees