Open In App

What is Unspent Transaction Output (UTXO)?

Last Updated : 11 May, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Blockchain is a digital, decentralized, distributed ledger. Blockchain utilizes a P2P (Peer to Peer) network, where participants present on the network are called nodes. The ledger stores data about transactions. It is a chain of blocks, where its most significant feature is that blocks are cryptographically linked together.

Blockchain

Cryptographically Linked Together

  • Each block in the blockchain except the first block (known as the genesis block) contains a field called a previous hash. It is the hash of the previous block in the chain. This makes blockchain very secure.
  • If an attacker attempts to change the data of a block, the hash of the block will change, as stated earlier, the next block will be holding the hash of the current block, if the hash changes the chain will get destroyed. Or, the attacker has to mine all the blocks again from that point. This is a possibility in a 51% attack.

Cryptographically Linked Together

What is a Block?

A block in blockchain stores transactions. In the case of bitcoin, blocks are added to the blockchain every 10 minutes, this might vary as a time to mine a new block depending on the complexity of the target hash, and it might take more time to mine one block, compared to the other.

  • When the block successfully gets mined by the miner, it gets added to the blockchain.
  • When the block gets added to the chain, the status of all the transactions inside the block changes from unconfirmed to confirmed.
  • In the case of bitcoin, the number of transactions that can be stored inside a block isn’t fixed, but the maximum size of the block is set to roughly 1 MB, the block size can slightly vary from 1 MB.
  • Empty blocks are valid, which means an empty block can be mined and added to the chain.

Transaction

Peeling down a single transaction reveals several different structures in a transaction that have different semantic meanings. The following are the different structures present in the transaction:

  1. Transaction version number: It is a version number specifying the type of transaction to the network. Through the transaction number, a node can determine the set of rules to be used to verify this particular transaction.
  2. Output: Transaction output consists of a cryptographic lock and time.
  3. Input: Transaction input consists of a pointer and an unlocking key. The pointer points to the previous transaction output. The unlocking key is used to unlock the previous output the input points to. Every time output is unlocked by an input, it is marked in the blockchain database as spent.
  4. Lock Time: It specifies whether a transaction can be included in the blockchain right away or after some specified time.

UTXO is all those outputs that are yet to be unlocked by an input.

Once an output is unlocked, they are removed from the circulating supply. The new outputs take their place. Thus, the sum of the unlocked outputs will always be equal to the sum of values of the newly created outputs.

Transaction structure

What is a UTXO?

In bitcoin, the transaction lives until it has been executed till the time another transaction is done out of that UTXO. UTXO stands for Unspent Transaction Output.

  • It is the amount of digital currency someone has left remaining after executing a transaction.
  • When a transaction is completed, the unspent output is deposited back into the database as input which can be used later for another transaction.

How is a UTXO created?

UTXOs are created through the consumption of existing UTXOs. Every Bitcoin transaction is composed of inputs and outputs. Inputs consume an existing UTXO, while outputs create a new UTXO.

UTXO Model

The UTXO model does not incorporate wallets at the protocol level. It is based on individual transactions that are grouped in blocks. The UTXO model is a design common to many cryptocurrencies, most notably Bitcoin.

  • Cryptocurrencies that use the UTXO model do not use accounts or balances. Instead, UTXOs are transferred between users much like physical cash.
  • Each transaction in the UTXO model can transition the system to a new state, but transitioning to a new state with each transaction is infeasible.
  • The network participants must stay in sync with the current state.

To understand how transactions work, let’s have a look at an example:

1. Suppose the following bitcoins are received from the transactions. Each one of these transactions is a UTXO.

Bitcoins from the transactions

2. Now I want to buy a car that costs 0.5 BTC.

3. In order to transfer 0.5 BTC, there is a need to choose one or multiple transactions as input.

4. This is why, a transaction in bitcoin is different from banks, in the case of banks, one would have entered an amount of 0.5 BTC, pressed transfer and it would have gone to the seller, but this is not the case in bitcoin, here there is a need to choose one or more UTXOs as the input.

5. In the case of cryptocurrency, there is no such thing as an amount lying in your account.

6. Let’s choose 0.7 BTC from Sarah as input to purchase a car.

7. In the case of UTXO, the input amount can’t be left unspent, one can’t say that do nothing with the remaining 0.2 BTC.

8. The remaining 0.2 BTC, has to be used in one of the following 3 ways-

  • Send the remaining amount back to your account, as we did in the above image.
  • Use the remaining amount as the transaction fee. Remember, that there should be some transaction fee otherwise no miner will add your transaction to block, and it will remain unconfirmed.
  • Send the remaining amount to someone else.

9. Now that 0.5 BTC has been sent to the seller but no fee has been added, the transaction didn’t get confirmed, and after 72 hours, 0.7 BTC will be refunded back.

10. So in order to send money to the seller, let’s put those 0.2 BTC as fees for this transaction.

11. In order to provide a transaction fee, nothing needs to be mentioned, if you don’t send the remaining amount to anyone, it is assumed a transaction fee.

12. Now that the transaction fee has been added, a miner included this transaction in the block and subsequently got 0.2 BTC as the transaction fee.

13. Let’s have a look at our original UTXOs again.

UTXO

14. The UTXO from Sarah is no longer there, the UTXO only lived till another transaction was not done from it, but now it has been used in another transaction, i.e. to purchase the car.

15. Transaction is stored inside a block, also it is one of four factors that changes the hash of a block. This means if a miner chooses a different transaction keeping the other 4 factors the same, the hash will be different. 

16. The factors that determine the hash of a block

  • Timestamp
  • Block Number: It is the serial number of the current block in the chain.
  • Data: The transactions stored on the block.
  • Nonce

17. If any one of these four factors changes even by 1 bit, the hash changes completely, this is due to the avalanche effect.

UTXO Set

The total UTXOs present in a blockchain represents a set and is being constantly maintained by every bitcoin node.

  • Each transaction consumes elements from this set and creates new ones that get added to the set.
  • Thus, the set represents all of the coins in a particular cryptocurrency system.
  • UTXO set is updated every time a new block is accepted in the blockchain.
  • Every Bitcoin node in the network will have the exact copy of the UTXO set in their local storage.
  • The complete UTXO set can be summed to calculate the total supply of a cryptocurrency at a given point in time.
  • In the case of a valid blockchain transaction, only unspent outputs can be used to fund further transactions.
  • The condition that only unspent outputs may be used in further transactions is necessary to prevent double-spending and fraud.

Importance of UTXO Model

  • Language Agnostic Smart Contracts: The UTXO based smart contracts are independent of language and allow UTXOs to develop unique consensus mechanisms.
  • Support for Decentralized Exchanges and Atomic Swap: The UTXO model could support atomic swaps, hence enabling peer-to-peer crypto trades without the involvement of a third party. The atomic swap feature of UTXOs offers a better facility for direct cryptocurrency trades between user wallets.
  • Scalability Benefits: Facility or parallel transaction processing reduces computation load on the blockchain networks.
  • Privacy and Security: With new addresses used for every UTXO transaction, it is impossible to track the transactions.
  • Prevents Double Spending: A UTXO can only be used once, this is fundamental within the operation of the blockchain technology that guarantees that the currencies are not used more than once.
  • More Flexibility: It provides more flexibility than fiat currency.
  • Simple parallelization: It allows for the simpler parallelization of transactions in the smart contracts.

UTXO vs Accounting Model

Below are some of the differences between the UTXO model and the Accounting model:

S.No. UTXO Model Accounting Model
1.  The transaction requires more storage space. The transaction requires less storage space.
2. The state is saved in transactions. The state is saved on the nodes.
3. The transactions are computationally simpler. The transactions utilize complex calculations.
4.  Bulk transactions are less efficient. Bulk transactions are more efficient.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads