The UTXO model

Do repost and rate:

The previous covered the surface level of various prerequisites for understanding the transactions models. It also introduced you to the account model which is used in Ethereum and many other blockchains. In brief, think about the account model as an account in a bank. You can add money to it, which will increase your bank balance and when you withdraw/transfer money, it will decrease your account balance.

Before heading over to the UTXO, remember that in a transaction, there are input (or a set of inputs) and corresponding outputs. The sum total of input value is always equal to sum total of output value. LAW of conservation is maintained here. You cannot create money out of thin air unless you are the Venezuela’s or Zimbabwe’s government or a coinbase(not the exchange) transaction*.

We will start off with some daily scenarios where you are dealing with UTXO type transactions. Take a cash register as an example. Consider you bought some grocery for $25. You give a $50 bill to the cashier who will give you $25 back. You don’t tear the $50 bill in half and give one-half to the cashier, right? That would be a dumb thing to do and will probably annoy the cashier. The $50 bill is atomic on its own. You can swap it for two $20 bill and one $10 bill but if you tore the $50 bill in half, you cannot swap either half for a value of $25.

Take another example, you have to pay $6 to me and $10 to my friend. Consider you have two $10 bills. You will give one to me and I will give you $4 back and the other $10 bill to the friend. You can do it at once right? Pay me with your left hand and pay my friend with your right hand. Both the $10 bills belong to you and you can spend them independently. So, you can do multiple transaction at once if you have two separate bills and more if you have more cash and more hands.

What happens if you have a single $20 bill? You will give the $20 to our mutual friend. He will keep the $10 you owe to him and then he will give you $10 back. You will then give the $10 to me and I will give you your $4 back (not sure about that though).

In UTXO, there are transactions that are spent and unspent. Consider you owe me 2 Bitcoin and you have 5 bitcoins in a single unspent transaction (we will get back to this). You will create a new transaction.

  1. You will take the unspent 5 bitcoins transaction as input.
  2. You will create two outputs. One output will have 2 Bitcoin sent to my address and the other transaction is 3 bitcoins sent back to yourself.
  3. Input = 5 bitcoins and Output is 5 bitcoins (2 to me and 3 to your own address). So, the transaction is valid.

We are considering that there is no transaction fees.

The great thing is you can combine several UTXOs (just like combining a $10 bill and a $5 bill to make a total of $15) and take them as input to your transaction. And there can be multiple outputs. Also, you are free to split the coins as much as you like. You can create a transaction where you take 1 BTC UTXO as an input and create 10 outputs of 0.1. The only condition is that Input = Output(). The only case where it is not true is for a COINBASE (again not the Exchange!) transaction.

The outputs of transactions are then called the Unspent Transaction Outputs (UTXOs). I can take the 2 bitcoins output of your transaction (that you have sent to my address) as an input and then send them to anyone else. The input (i.e., your 5 bitcoins) were also an output of a transaction where you were sent that 5 Bitcoins. Since, you have spent that output, it is marked as spent. And you have created 2 new unspent transaction outputs.

Hopefully, you see the pattern here. You create a transaction out of some previous UTXO that contains your address as the redeemer. That UTXO is the input. (Your dollar bills are the UTXO you hold in real life). Now, we will cover the surface level technicality of how transactions are created and verified.

First, we will consider the output. How will you create an output so that it can be only retrieved by a certain receiver?

In simplest way, you can essentially enter the public key of the receiver in the output along with the amount of coin you have sent to them (Pay to Public Key). But the public key is usually very large. Instead you can enter the hash of the public key of the receiver along with the amount (Pay to Public Key Hash) or you can also add the hash of a script (helps in Multi-sig etc) but we will not delve into that.

Now, the input. How will you redeem a UTXO that contains your address as the redeemer?

When you want to spend an unspent transaction output, you take that as an input (by using its hash).

there are various outputs in transaction (just like we created 2 outputs from a single output). How are you going to tell everyone which UTXO you are going to use? Well, you can use the output that was addressed to you using something called indexes. Basically, inside the transaction, the first output is index 0, second is index 1 and so on.

how will someone check that the hash of the public key stored in the UTXO is yours (If Pay to Public Key hash is used)? Well, you will add your public key as an input.

how will someone check that you are in fact the owner of the corresponding private key? Well, you will provide a digital signature that will prove to everyone that you are the owner of the private key.

Validators are the one who will verify the transactions. They will keep record of all the new UTXOs being created and those that have been spent. One thing to note here is that, to redeem the coins you are only required to have access to the output part (i.e. the UTXO). So, when you are spending the 5 BTC, you only care about the hash of the transaction, the index of your output within the transaction and the corresponding amount. You do not care about the other output indexes or the inputs in that transaction.

As you have (hopefully) now understood, the UTXO are the outputs of the transaction that have not been spent yet. There can be any number of UTXO addressed towards your address and you are free to combine and spend them as per your requirement. And the advantage here is that it is inherently parallelizable.

  • So, if you have 2 unspent transactions addressed toward you of, say, 2 bitcoins each.
  • You can spend them by combining them together and spend the 4 bitcoins.
  • You can also send 2 BTC to me using one UTXO and 2 BTC to my other account using the other UTXO. Both of these transactions can be done simultaneously and independently as the two UTXO do not depend on each other. They are like two different cash registers!

UTXO also requires less bandwidth to work on and they require less storage space. The validators only need to keep record of all the UTXOs. So, there is no need to update the account balance in main account LEDGER with every transaction.

The issue with the UTXO model is that deploying smart contracts is inherently difficult. There is no single account under which all of your assets are listed as your wealth is spread all over the blockchain in the form of UTXOs.

Extended UTXO as we will see allows us to deploy smart contracts while still maintaining the UTXO property.

* Coinbase transaction: When a miner adds a block in the blockchain, they get some reward for doing the work. Bitcoin blockchain rewards miner with 6.25 BTC per block as of now. The rewards are given to the miner in a transaction called “Coinbase transaction”. There is no input to the transaction. Corresponding output is the amount of coins (depending on block reward at the time) along with the address of the receiver. The Coinbase transactions essentially create coins out of thin air! And only these transactions are allowed to do so. The miner can then spend them using his/her key as they do with any other transaction.

** Transaction fees: There is a transaction fees associated with every transaction in most crypto-currencies (Nano being one of the exceptions). Consider Bitcoin for example. As the block rewards halves, the transaction fees will be the primary source of the income for the miners. So, initially the Output Bitcoin = Input Bitcoin. But now the conditions have slightly changed. So, Output Bitcoins <= Input Bitcoins. The difference between the output bitcoins and the input bitcoins is the transaction fees. So, if you have input UTXOs totalling to, say, 12.6 BTC and the total output is 12.4 BTC. Then the 0.2 BTC is the transaction fees. The miner who will add the block containing your transaction will receive the transaction fees.

Next up will be EUTXO model. Until then, Peace!

Regulation and Society adoption

Ждем новостей

Нет новых страниц

Следующая новость