UTXO or Unspent transaction output (unspent transaction output) is one of the central concepts that allow the correct functioning of the blockchain technology that Satoshi Nakamoto developed for Bitcoin, the first cryptocurrency in the world.
Ddecades before it was created Bitcoin, the obsession with creating a purely digital money haunted many people's heads. But one of the main problems that everyone ran into head on was the famous double-spending.
It was Satoshi Nakamoto who, thanks to a set of techniques, solved this great problem, being able to create the first purely digital decentralized money. In this article we will explain what UTXOs are and the great role they play in creating transactions so that your bitcoins can travel safely within the protocol. blockchain.
UTXO, a concept to avoid double spending
As we have already explained in the article How do Bitcoin transactions work?, a transaction is composed of inputs and outputs. The set of inputs and outputs, together with coins to be sent and cryptographic signatures, result in a transaction hash, called HASH ID.
The entries are HASH ID of a transaction that received the purse and that have not been previously used, that is, they are UTXO, while the output is the destination address, for which UTXO will be created that can later be used in a transaction. The same address can have infinite UTXO. This is why UTXOs are defined as a set of transactions.
When a person needs to send a transaction, it has to feed on UTXO. That is, from transactions you have received that have not been spent. This means that a person can use one or more UTXOs for the same transaction. In fact, those UTXOs can be part of one or more addresses in your wallet. And we go further, even a transaction could be created with UTXO addresses from different wallets, as long as each one is signed with its corresponding clear private key.
This all leads to one place: a UTXO can only be used once. And this is fundamental within the operation of blockchain technology, since it is part of the set of tools that guarantees that some coins are not used more than once (the famous double spending).
Such is the reliability of using this mechanism to identify unspent coins that it is the way in which Bitcoin can be counted how many coins are in circulation. What is done is add all the coins that are in the UTXO, that is, in the transactions that have not been spent.
Next, we leave you a simple example so that you understand the flow:
Imagine that Maria wants to pay Pedro a total of € 100 in bitcoins for a job. María hopes to receive payment from some people who owe her bitcoins and from that money she will pay for Pedro's work.
When Maria receives these payments, she has had some "Inputs" of money, and from those inputs she will make an "Output" to pay Pedro. Maria was paid her debts, which were a payment of € 75 and another of € 50.
When she pays Pedro, Maria has to use both entrances, since neither of them has enough, and she will put Pedro as the exit.
After that, Pedro will have a UTXO entry (he has received the payment).
Where do the remaining coins go?
As you have seen, María had a total of €125 divided into two UTXOs, but she only needed to send €100. She has had to use the two UTXOs, putting Pedro's address as Output, but her purse will have done something else transparently to María. Her purse will have put an address for Maria as her output, to which she will have assigned the remaining €25. It is what is known as change direction.
By the way, there are some transactions that are converted into a UTXO but are not generated by a previous UTXO, you'll see what they consist of later.
With what has been described above you can understand how this model of "Tickets" y "Departures", can help us to establish relations of possession and granting of money. A relationships that in blockchain are marked by the use of cryptography and that provide us with absolute security that the money has reached its destination and that it is effectively under the control of the recipient.
UTXO and its importance in Bitcoin
in Bitcoin all transactions have this structure of inputs and outputs.
- In the "Inputs" of a Bitcoin transaction, we can see the origins of the balance that we are managing with our wallet or purse.
- While in the "Outputs", we can see where we send our money.
- In addition, we can see the remaining money that is returned. All this is visible and traceable by anyone, since the Bitcoin blockchain is public and transparent.
If you look closely, this model allows you to have total control over the way money is used and under what conditions it can be spent. First, In order to use a Bitcoin balance, it must be considered as a UTXO in your wallet.. That is, someone must make a payment (an output or UTXO) so that this payment becomes your input and thus you have available balance to spend.
This is a recursive process. That is, it is repeated from the moment the coin is generated as a result of a mined block. For example, a coinbase transaction is actually a UTXO created by the miner to send that balance to an address under their control. Thus, that output transaction becomes an input of money for the miner that he can later spend. The same process is repeated for the rest of Bitcoin users. With this we can see that UTXOs are an essential part of Bitcoin transactions and without them, their operation would be impossible.
Expanding the example of how a UTXO works on Bitcoin
We can see the operation of a UTXO in Bitcoin in the following way:
Daniel wants to pay for Luis's car, valued at 1 BTC, and a total of 1,5 BTC is available in his wallet. Daniel's balance is divided into two directions, A with 0,8 BTC and B with 0,7 BTC.
Thus, Daniel goes to Luis and makes the payment for 1 BTC. At this point, Daniel's wallet cannot send 1 BTC directly because the balance is split between two addresses. So takes both balances and converts them into the inputs of the payment transaction. Next, it takes Luis's address and assigns the sending of 1 BTC to it, additionally assigns a total of 0,4995 BTC to the exchange address, and the rest remains as the mining commission.
Once Daniel submits his transaction, it will be processed and confirmed by the network, beginning its path to irreversibility. And at this point, it will be easy to see where the transaction UTXOs are.
The first UTXOs that we can detect in the example are Daniel's balances. Those addresses with 0,8 BTC and 0,7 BTC balance are two UTXOs that are under their control and are the ones that allow them to make the payment to Luis. Since Daniel is in control of those balances, he can transform his UTXO into "Inputs" for a new payment as he effectively does in this example.
Immediately after the network confirms Daniel's transaction the situation changes. Now, Daniel no longer has under his control the balances that he had in principle, and in his place, your transaction has generated new UTXOs that overwrite the old ones. The new UTXOs in question are represented first, by Luis's address and the 1 BTC that he has received in it from Daniel. And second, because of the exchange address and the 0,4995 BTC that Daniel has received from the network, because it is what remains of the payment he made. As we have said, the rest to complete the 1,5 BTC that Daniel had in principle remain as a commission payment for the miner.
Bitcoin Scripts and its relationship with UTXOs
The entire operation of the UTXO in Bitcoin is guaranteed by the Bitcoin script, the programming language used to write all operations in Bitcoin. Each transaction has an associated script that allows us to:
- Validate that the balance used is really ours.
- Ensure that balances sent can only be spent by the person to whom we send them.
But how are these operations carried out? This is what we explain below:
Validating that the balance is ours
The first task to be able to use a balance in Bitcoin is to demonstrate that this balance is indeed ours. To do this, the first thing to take into account is that each UTXO that we transform into an input (balance that we are going to spend) is actually the exit from a previous transaction which gave us access to those BTC. That is, every balance in Bitcoin has a UTXO associated with it, and said UTXO has a blocking script associated with it.
This blocking script is a digital padlock that we must open in order to make use of the balance of said UTXO. Blocking scripts in Bitcoin are varied, but the most common is the P2PKH (Pay to Public Key Hash). Although there are also the P2SH (multisig), P2PK (the most primitive of all). This blocking script can be opened with the private key that results in the address indicated in the UTXO.
So in order to unlock this script, what we must do is take the Bitcoin address, together with our private key and generate the public key of said address. At the end we stamp our digital signature and with all that data verified, the balance of said address is unlocked so that we can use it. That is, the nodes will accept the transaction and put it in the mempool waiting for the miners
On the contrary, if we fail to do that procedure, we simply the transaction is rejected by the nodes and we will not be able to use the balance. This process is called an unlock script. Of course, this cryptographic process is automatic and transparent for users of a wallet, the entire process is carried out by the wallet itself, but now you know what happens inside it. In this scheme, this part of the operation is described in the scriptSig of each Bitcoin Script.
Creating the lock script
Demonstrating that we can spend our UTXOs, we move on to the transaction creation process, creating a block script for the new destination-bound UTXO. In this case, what the wallet does is create a script similar to the one that was created for us previously, which indicates that The only one who can spend this new UTXO is whoever has in their possession the private keys that control the addresses to which we have sent.
In this way, what is created is a validation string, where the bitcoins when passing from one address to another, are blocked to be used by the last person who takes possession of them.
As you can see, in Bitcoin everything has a well-defined reason, and that allows all its parts together to allow the proper functioning of the cryptocurrency. Being an open protocol, all nodes that want to be part of the protocol interpret the rules in the same way.
All transactions are reviewed by all nodes, with those accepted by the majority being validated and those accepted by the majority of the hash power (generated by the miners) being confirmed. These controls democratically guarantee compliance with the protocol.
Curiosities of the UTXO in Bitcoin
Now, in the previous example you have surely seen some curious things about UTXOs and their operation in Bitcoin, and we will give you an explanation in this section.
Transactions that do not come from a UTXO
As we indicated before, there are some special transactions, some that are not generated with UTXOs, since the coins appear "magically". This particular case occurs in the coinbase transactions, which are created by the miners at the time of mining a block and are used to obtain the block reward.
Why not make a fractional payment using the balances in BTC?
Reading the previous example, you have surely wondered why Daniel's Bitcoin wallet has not made an exact payment of 1 BTC using a single input? The answer for this is that UTXOs represent the balance within Bitcoin indivisibly. That is, we cannot transform that balance into smaller values, unless we spend the balance by creating a new transaction.
To make it easier, let's look at this example: if we want to pay 1 BTC with our wallet, but that amount is divided into 100 different UTXOs that have 0,01 BTC each, then our wallet will take the 100 addresses as inputs to our transaction and with it will make the payment. That is, the Bitcoin protocol marks those 100 UTXOs as "Spent". From there, it generates a new transaction with a new UTXO which is where we have sent the 1 BTC payment, and it leaves us without balance control in those addresses used.
Relationship with commissions in Bitcoin
Another utility of the UTXO has to do with the commissions or fee in Bitcoin. In the previous example we explained that every time we make a transaction, the commission of said operation is equal to the difference between the entries and the exits. Namely:
Total input - Total output = Commissions
This tells us that the construction of a transaction has from the outset a balance of commissions. The commission to the miners is not associated with any output, so the miners keep what is not associated. That is, the total input must always be greater than the associated total output.
The commission to the miners is not fixed, each one decides how much they want to pay depending on the rush they are in, but it is something that we see in all transactions within Bitcoin and its purpose is two things:
- Encourage the work of miners that when generating a block they not only receive the reward of the same, but also the commissions of all the transactions confirmed by said block.
- Prevent the network from being vulnerable to malicious attacks as DDoS, dusting attack, among others. This is because each transaction has a cost and making transactions in massive numbers has a high cost for the attacker.
UTXO on other blockchains and cryptocurrencies
The UTXO scheme is so good that the rest of the cryptocurrencies have decided to use it for their systems. Of course, each blockchain can adjust this concept differently. In this way, it can adapt to the additional functions that each blockchain protocol where they are executed may present. However, the basic operation is the same. Hence even privacy coins like Monero o Zcash, use this scheme adjusted to the particularities of your protocol.
Advanced Bitcoin Course
Advanced levelAt Bit2Me Academy we bring you this advanced free Bitcoin course so that you become the next Satoshi Nakamoto.