Bitcoin’s UTXO Set Explained

Bitcoin's UTXO Set Explained 

Last Updated: 20th December 2018

In order to understand how the Bitcoin UTXO set works, the manner in which Bitcoin transactions are constructed must first be understood.

At a basic level, Bitcoin transactions use outputs from previous transactions as inputs in the construction of a new transaction. To illustrate, consider that Alice wants to send Bob 1 bitcoin, however, she knows that a transaction fee of 0.25 bitcoins is required. Such a transaction could have the following inputs:

  • Input 1 – 0.25 BTC
  • Input 2 – 0.25 BTC
  • Input 3 – 0.25 BTC
  • Input 4 – 0.25 BTC
  • Input 5 – 0.25 BTC

Taking into account the transaction fee of 0.25 BTC, the output of the transaction, i.e. the number of bitcoins Bob would actually receive, would be:

  • Output 1 – 0.25 BTC
  • Output 2 – 0.25 BTC
  • Output 3 – 0.25 BTC
  • Output 4 – 0.25 BTC

Bob would therefore receive 1 bitcoin at the end of the transaction. The output of a transaction can either be classified  as an unspent transaction output (UTXO), or spent transaction output. For transactions such as Alice's to be valid, it must only use unspent transaction outputs as inputs.

Outputs are also discrete integer values denominated in satoshis that cannot be divided down any further. Satoshis are currently the lowest unit of account on the Bitcoin network, with 1 bitcoin equalling 0.00000001 satoshis.

UTXO Set

The function of the UTXO set is to act as a global database that shows all the spendable outputs that are available to be used in the construction of a bitcoin transaction. When a new transaction is constructed, it uses an unspent output from the UTXO set, resulting in the set shrinking. Conversely, when a new unspent output is created, the UTXO set will grow.

Bitcoin full nodes are required to track all the unspent outputs in existence on the Bitcoin network in order to ensure:

  • A user is not attempting to spend bitcoins that have already been spent, i.e. a double-spend

A user’s bitcoin balance is the sum of all the individual outputs that can be spent by their private key. Therefore, when a user initiates a transaction, the outputs from the user’s UTXO set is used. All the unspent outputs must entirely be consumed when a transaction is being conducted, with change being sent back if the total value of the outputs is larger than the value of the transaction.

For example, if a user has a UTXO worth 10 bitcoins, but only requires 2 bitcoins for their transaction, then the entire 10 bitcoins is sent with two outputs being produced:

  • Output 1 – 2 BTC payment to the recipient
  • Output 2 – 8 BTC payment back to the user’s wallet as change

A transaction consumes previously recorded unspent transaction outputs and creates new transaction outputs that be used in for a future transaction. This allows bitcoins to move from one owner to another, with each transfer consuming and creating UTXOs in a chain of transactions.

However, a special type of transaction known as a coinbase transaction, does not adhere to the input and output chain. A coinbase transaction is the first transaction a miner places in a block constructed by them; it is a transaction that rewarding the miner in bitcoins for successfully creating a block to be relayed to the network. This transaction type have no inputs, and thus, does not consume a UTXO.

Parts of a Transaction Output

scriptPubKey is a locking script placed on the output of a Bitcoin transaction that requires certain conditions to be met in order for a recipient to spend his/her bitcoins. Conversely, scriptSig is the unlocking script that satisfies the conditions placed on the output by the scriptPubKey, and thus, is what allows the bitcoins to be spent.

Using the previous example, in order for Bob to spend the bitcoins received from Alice, each output will contain a locking script, scriptPubKey, which must first be satisfied by the unlocking script, scriptSig.

To illustrate, when Alice decides to initiate her transaction with Bob, the outputs that Bob receives contain an amount of bitcoins that can be spent only when the conditions laid out by the attached scriptPubKey are satisfied. When Bob decides to spend these outputs, he will create an input that includes an unlocking script, scriptSig, that must satisfy the conditions that Alice placed on the previous outputs before he can spend them.

Unspendable Outputs & Bitcoin Dust

Unspendable Outputs 

The Bitcoin UTXO set contains spendable outputs, however, prior to version 0.9 of the Bitcoin Core client, there are instances where the Bitcoin UTXO set contained unspendable outputs.

Unspendable outputs arose from developers using the Bitcoin transaction scripting language, Script, to create applications such as: smart contracts and digital record keeping applications. These applications created outputs that could not be spent, but were regardless still included the UTXO set. The net result of this was an ever increasing UTXO set which made it more expensive to run a Bitcoin full node; remembering that Bitcoin full nodes are required to track all outputs in the UTXO set.

However, in version 0.9 of the Bitcoin core client, a RETURN operator was implemented whereby the operator creates unspendable outputs which are not stored in the UTXO set. Although, even though RETURN outputs are no longer stored in the UTXO set, they are still recorded on the blockchain which still requires disc space.

Bitcoin Dust

The Bitcoin Core reference implementation defines dust as an output where the fee to required to move it is greater than 1/3 its value. Put more simply, dust is low-value bitcoins wherein the transaction fee incurred in moving them is greater than the value of the bitcoins themselves.

Dust can be problematic because it is inherently uneconomical to transact with. However, by combining separate, low-value outputs, into a single more valuable, output, such a transaction becomes more viable. Some wallet providers provide the option for users to carry out this function.

Conclusion

To conclude, the Bitcoin UTXO set contains all the spendable outputs on the Bitcoin network. All outputs are discrete integer values denominated in satoshis. Bitcoin full nodes are tasked with tracking all spendable outputs on the network in order to ensure no bitcoins are being double spent.

Unspendable outputs arise as a result of applications created using Script. Even though unspendable outputs are no longer stored in the UTXO set, they are still stored on the Bitcoin blockchain.

Low-value outputs, known as Bitcoin dust, are bitcoins that cost more to transact with than they are actually worth.