So you’re interested in getting your hands on some cash?
In a cash-only world, you have two options: either exchange for money with another individual or organization, or be the government and print cash for yourself.
In the world of bitcoin, your options for obtaining money are similar. You can either (1) exchange for some bitcoin from another individual or organization (like a cryptocurrency exchange), or (2) you can create bitcoin by becoming a miner and participating in the transaction validation process.
Transactions: Inputs (senders) and Outputs (receivers)
In the cash world, money is physical and is moved from one party, the input, to another party, the output. Once you spend cash, you cannot spend it again because you no longer have it. However, in the world of bitcoin, money is a software and must be moved around differently to ensure no one can spend a coin more than once. This idea is called the “double spend” problem.
As an aspiring computer scientist, I was curious to know what this spending process looked like, so I did some exploration on how cryptocurrency transactions actually occur.
(1) Coinbase Transactions
Besides being the name of your favorite bitcoin exchange, a coinbase is actually part of the bitcoin creation process. When a group of transactions, or “block”, is validated on the blockchain, the bitcoin network literally creates new coins (like the U.S. Treasury printing new dollars). Because this new coin has no history of a previous owner, the transaction of these coins has no inputs. The output is the miner who did the work in validating the block and is rewarded by the network through the receipt of its new coins.
The process of creating a new coin and giving it to the miner is called a “coinbase” transaction. This occurs every 10 minutes in the bitcoin blockchain as blocks are locked, become uneditable, and a new block begins building a list of transactions.
Our other option for obtaining money is to exchange it with another party that already owns bitcoin. All bitcoin received is bitcoin spent by someone else, unless it was created through the mining process. In other words, all bitcoin inputs were once outputs.
A UTXO is an Unspent Transaction Output. Bitcoin uses the UTXO transaction system to track bitcoin wallet balances. A UTXO is exactly as its name implies — bitcoin (the output) that has not yet been spent. This unspent bitcoin sits in a database called a UTXO set. Each miner holds a separate but uniform copy of this database and uses it to validate transactions. When a bitcoin is moved, it changes from an output from a previous transaction, and becomes an input for a new transaction. A miner will check to make sure this input is in the UTXO set. If it is not, that means the bitcoin either does not exist, or has already become an input for a different transaction, and thus cannot be spent again.
This UTXO “change” from an input to an output is not as simple as it sounds. When a UTXO is spent, it is considered gone forever. The data can be viewed on the blockchain, but it cannot be used for anything else. If spent UTXOs cannot be used for anything, then how can they become future inputs for new transactions?
To understand this, let’s go back to the world of regular money. You have a check for one hundred dollars and want to keep fifty dollars for yourself and give fifty dollars to a friend. You cannot simply rip the check in half, give your friend one side and keep the other. Instead, you have to go to the bank and essentially turn your one check into two new checks — one check of fifty dollars addressed to your friend, and another check of fifty dollars addressed to yourself that is probably just left in your account or cashed. The original check for one hundred dollars is then destroyed.
A Technical Dive into UTXOs
The bitcoin you once received that is now becoming the input for a new transaction (“the $100 check”) is called a vin. The bitcoin you want to spend, or the output to the transaction (“the two new $50 checks”) are called vouts. When you spend less than your full bitcoin holdings, a transaction is created that points your leftover change back to yourself, known as the “change address”. Once a vin is turned into a vout, it is destroyed and can no longer be used again. The newly created vouts become future vins and then are destroyed.
Bitcoin uses cryptographic public and private keys to identify senders and receivers of the currency. Anyone can safely see public keys, but private keys should be kept secret by their owners. One popular analogy compares public and private key cryptography to a high-tech mailbox with two doors, one to put mail in, and one to take mail out. The mailbox has two passwords. Password One is used to put mail in the mailbox. You give everyone this password because you want everyone to send you mail. Password Two is used to take mail out of the mailbox. This password you keep secret so only you can access the contents of your mailbox. In this analogy, Password One is a cryptographic public key and Password Two is a cryptographic private key.
Bitcoin is a software, and like many softwares, it runs on code called scripts. An example of a bitcoin script used to spend bitcoin is called “pay-to-pubkey script” and looks like this:
Exploring this script lets us see where public/private key cryptography and vins/vouts come together. This script will return either true or false. True means the UTXO is allowed to be spent, false means it is not.
The script will first check your vin. Each vin has a private key. This private key is like the signature on the back of a check. In order to spend cash from a check, the bank makes sure that the person trying to spend that cash is in fact the correct recipient of the check, or the person who signed the back. In order for a vin to become a vout, the script checks to make sure the vin is being inputted by the person who received the UTXO. If the private key is correct, OP_CHECKSIG will return true. The script then takes a public key (pubKey), or address of the party you are sending bitcoin to. If the script returns true, vouts are created and sent to this public key, creating new UTXOs.
UTXOs are how a the bitcoin blockchain tracks your “balance”. For each transaction you send a portion of your holdings to another party, with the remaining bitcoin sent back to yourself as a new transaction (change address). When you’re ready to send bitcoin to the next person, you reference this change address to prove that you’ve got enough funds to authorize the transaction. A computer, not a person, confirms this as part of the mining process (incentivized by receiving bitcoin for their work).
Although Bitcoin often gets a lot of heat for being a bubble or scam, it is important to step back and realize that some of the world’s best developers are working on the bitcoin blockchain, creating software models like UTXOs. Whether Bitcoin succeeds or not, these systems can be used in other blockchain platforms that inevitably will have the impact of reducing manual processes. An example of UTXOs being used outside of financial transactions is in Corda, a blockchain built by R3 - a financial organization consortium. Corda uses UTXOs to track and process contractual agreements between companies.
When we hear discussions about Bitcoin on the news, we don’t hear technical details described. However, learning more about the novel pieces such as UTXOs that work together to form the Bitcoin network will help you understand the nascent currency and the transformative technology that is blockchain.