What The Heck is UTXO

Rajarshi Maitra
BitHyve
Published in
10 min readApr 25, 2020

--

                      ---------Kernel-----------
* Details of the Blockchain structure
* Details of the Transaction structure
* UTXO
* UTXO vs Account-Balanace Model

Many words and idioms surrounding Bitcoin doesn’t always make obvious sense. Some words mean something else than what they might suggest at first glance. Some don’t create any impression on the reader’s mind when they first hear about it, precisely because they never existed before in the English dictionary. They are purely constructed from the design terminologies of the Bitcoin system. Sometimes rather technical word sticks around in common lingo due to lack of better alternatives.

One such word is “UTXO”, which is almost as commonly used in the Bitcoin world as “money” is used in the real world. Yet nobody knows what to think about, when they first hear it. UTXO doesn’t have any previous precedence in the English language. It means “Unspent Transaction Output”, which is a mouthful technical term and came pretty much straight out of the Bitcoin codebase. Yet, its probably the most important concept someone wanna wrap their head around if they plan to use Bitcoin effectively.

So in this article, we will dissect this term piece by piece, and hopefully, by the end, the reader will have a graspable mental model to think about UTXOs, and be an efficient Bitcoin user.

In order to imagine UTXOs, we need to look at the gears of the Bitcoin machine, starting from the biggest structure of the system, the Blockchain.

The Blockchain

The Bitcoin machine is constructed out of mathematical structures. When I say structure, think about abstract mathematical objects, which have semantical meanings. A structure can contain raw data or more smaller structures within itself. Depending upon the semantics of these structures (suggested by its name) the data within them are interpreted by the protocol.

Schematic of The Blockchain

Let us start with the most glorified data structure of this decade, A Blockchain. As the name suggests, its a chain of Blocks. Its the largest of all the structures in the protocol and as of writing sized about 310 GB for Bitcoin, which is a long list of Blocks (blocks are also structures).

Each block contains two types of structures, a Header, and a Transaction List. The header contains all metadata regarding a particular block, and among them is the previous block hash that points to an earlier block (aka parent block). In this way, each block points to its parent, which points to its parent, so on and so forth, all the way back to the first block ever created (aka the genesis block). This pointing back into the past creates this chain-like structure of the blocks, and thus appropriately named as a Blockchain. A blockchain is nothing more than a linked list.

Block #10

The above figure shows the data contained in the 10th block of the Bitcoin blockchain. The summary section specifies the Header data, and the section below specifies the list of transactions. This block was mined on 9th Jan 2009 (see the time stamp field) probably by Satoshi himself. In the transaction list there is only a single transaction of 50 BTC going to an address. This is the coinbase transaction, the first transaction in every block where miners get their block reward. There was nobody else in the network to transact with back then, so the only transaction in the list was the coinbase transaction where the block creator claimed 50BTC for solving the Proof of Work.

Now that we got the basic idea of blocks, let’s go one step deeper and look inside a transaction.

The Transaction

The Transaction Structure

Peeling down a single transaction, we can find many different structures, which all have their separate semantic meanings.

First is a Structure called Transaction Version, which is a version number specifying the type of this particular transaction to the network. By reading the version number, a node can determine the set of rules to be used to verify this particular transaction.

The last structure is Lock Time, which specifies whether a transaction can be included in the blockchain right away or after some specified time.

In between them comes a list of Inputs and Outputs. These two are the most important field for our discussion here.

A transaction Output consists of a cryptographic lock and a value. The details of the lock will be described in a separate blog post (this is where the smart contract comes in). For now, you can simply imagine that the outputs are somehow locked and the input provides a key to unlock them. The value is simply the amount in satoshis (sats) that is locked inside the output.

Every Transaction input consists of a pointer and an unlocking key. The pointer points back to a previous transaction output. And the key is used to unlock the previous output it points to. Every time an output is successfully unlocked by an input, it is marked inside the blockchain database as “spent”. Thus you can think of a transaction as an abstract “action” that defines unlocking some previous outputs, and creating new outputs.

These new outputs can again be referred by a new transaction input. A UTXO or “Unspent Transaction Output” is simply all those outputs, which are yet to be unlocked by an input.

Once an output is unlocked, imagine they are removed from circulating supply and new outputs take their place. Thus the sum of the value of unlocked outputs will be always equal to the sum of values of newly created outputs (ignoring transaction fees for now) and the total circulating supply of bitcoins remains constant.

The below figure shows the transaction “action” schematic. A transaction consumes some past UTXOs and spits out new UTXOs.

Transaction Action Schematic

A UTXO is nothing more than locked up bitcoins. You can think of UTXOs as a box that contains the coins and they can hold any amounts. Once you have some bitcoins, in the Blockchain all you have is a bunch of UTXOs. For all practical purposes, you can think of your UTXOs as your box full of sats.

The blockchain is a canonical list of all the transactions that were ever recorded by the network. By tracing through them, we can construct what is known as a transaction history graph. Every output can be traced in this way all the back to the instant where it was first created by a coinbase transaction.

The figure below demonstrates the schematic of the Bitcoin transaction history graph.

Transaction graph history

For example, in TX4 above, the input0 points back to output0 of TX2. The Outputs at the last transactions namely TX6 and TX3, the one with 10K and 20K values are the UTXOs. Because they have not yet been referred to by a transaction input. Once an input points at them and provides the correct key to open them, they are spent and are not considered UTXO anymore. They will be replaced by new UTXOs that will be created by that future transaction.

One small detail to notice here is, for example, in TX1 the input0 points to an output that had value 40K, but it creates a new output that has value 30K. The missing 10K is the transaction fee. This is the fee paid to the miners for the inclusion of the particular transaction in a new block. Higher the transaction fee, higher is the probability of miners picking it up for inclusion in the next block.

The UTXO Set

The collection of all the UTXOs at any moment is called the UTXO set and is being constantly maintained by every Bitcoin node. Technically they are known as the chainstate and are stored in the chainstate data directory of a node. The chainstate updates every time a new block is accepted in the blockchain. That block contains the list of latest transactions, which defines which of the previous UTXOs are spent and which new UTXOs are created. Every Bitcoin node in the network will always have the exact same copy the UTXO set in their local storage.

Size of the UTXO Set

As of writing, the size of this UTXO set is 4.1GB. And yes, if you own some bitcoin, your UTXOs are also present inside my Bitcoin full node. But don’t worry, I cannot open them.

As we have already mentioned, UTXOs are bitcoins, and they are represented in different ways by different wallets for user information. When you query a wallet for your bitcoin balance, the wallet in the backend gathers up all the UTXOs that you own, and show you the sum of the value of these UTXOs. That sum is your final wallet balance. These calculations happen in the background and are abstracted away from users.

The UTXO Model

Real World payment with UTXOs

In the real-world, the UTXOs are almost similar to physical cash/coins. When one tries to spend cash in a shop, he gives up the entire note, takes the goods, and takes back the remaining change. If one has a cash note of 10 bucks and wants to buy good priced 5 bucks, he doesn’t divide the note in half for the payment. Rather he gives up the full note, and takes a new 5 bucks note as a change along with the goods.

UTXOs work in similar fashion. In a transaction, UTXOs are always consumed in full, even if the required payment is of the partial value of the original UTXO. For example, referring to the figure above, suppose Alice wants to pay Bob for some goods/services which cost 6 BTC. But Alice only has a single UTXO of 10 BTC. She will create a transaction that will consume up this whole UTXO of 10 BTC and create two new UTXOs, one for Bob with 6 BTC and one for herself with 4 BTC value. The UTXO Alice pays to herself is known as the change UTXO, and her wallet software automatically tracks this UTXO to give her the final balance of 4 BTC. Every time a payment is made for a smaller value than the available UTXOs, the wallet automatically creates the change UTXO for the user.

Every UTXO is associated with a bitcoin address, and there are many types of addresses (P2PKH, P2SH, Bech32, etc). Different addresses provide different functionality for these UTXOs. For example, if one creates a multisignature UTXO, i.e. a UTXO that needs keys from 2 or more people to be spent, it is associated with an address that starts with a 3… and looks like below:

3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy

If you have a bitcoin wallet with some balance, you can always try looking up for your individual UTXOs.

UTXO vs Account-Balance Model

It should feel a little bizarre to think about this obscured concept of UTXO in a digital payment system. UTXO feels inherently similar to physical cash, whereas, in digital payment platforms, we deal with accounts. The account model is simply, where users have one or multiple accounts, the amounts can be anything, and there is no concept of change back. Credit is added to the balance, and debit is subtracted away.

Even though these two models achieve similar goals, i.e. pay money to people, they both have some advantages and disadvantages.

UTXO models are better for scalability and privacy. The transaction logic is simplified as each UTXO can only be consumed once and as a whole. Because the logic is simpler, transaction verifications can be made parallel. Different schemes of privacy-enhancing techniques can be developed using the UTXO model, like coin-join, etc. In exchange for these benefits, the tradeoffs are in usability. UTXO model is inherently unintuitive thus most of the wallets had to abstract away the UTXOs and simulate normal account like UI for users. UTXOs are limited in terms of more exotic smart contracts that executes based on the user’s total account balance.

Because of these reasons, Ethereum rejected the UTXO model and they went for a simple and more flexible account-balance model.

But in the end, they both have their tradeoffs.

Conclusion

It’s entirely possible that all the above details regarding UTXO has made you more confused than before. That’s alright, we all had our weird moments with Bitcoin. To gist it up, abstract the entire concept as follows and you should be alright.

  • UTXOs are locked up box full of coins.
  • The lock can be opened by providing the right key.
  • When you spend some bitcoin, you create a transaction (or the wallet does it for you) that consumes some old UTXOs and creates a bunch of new UTXOs.
  • UTXOs are always consumed as a whole, and change UTXO is created automatically by your wallet to get back the balance.
  • Every UTXO is associated with an address. Different types of address denotes different types of UTXOs.
  • You should always be aware of your keys to open up the lock in your UTXO. Not Your Keys, Not Your Coins.

So next time you use a wallet, see if you can figure out your individual UTXOs. Hint: Figure out the transaction ID, and look it up on a block explorer.

Happy Bitcoining.

Off to the moon!!

--

--

Rajarshi Maitra
BitHyve

Independent Bitcoin and Lightning Network observere learner and educator.