UTXO vs. the Account Model
In the world of cryptocurrencies, consensus algorithms are necessary to maintain security and validate the state of the blockchain. The transaction model is used to demonstrate ownership of the tokens.
What is UTXO?
The model states that the output of a transaction directed to the user is what the user will use as input to create a new output transaction. Therefore, they represent a chain of ownership. Through digital signatures in transactions, the system guarantees the transfer of funds from the sender(s) to the receiver(s).
This model stands on three essential rules:
In every transaction, the sum of its inputs is greater than or equal to the sum of its outputs.
Each input must be valid and unused.
A transaction must contain the signature of the owner of the input.
Example: You could say that each UTXO is like a bill or a coin. For example, imagine you have $100 in cash. There are different combinations of bills or coins to reach this amount:
Two $50 bills
Twenty banknotes of $5
Two bills of $10 and four of $20
Ten bills of $10
In each of the scenarios, no matter the combination, in the end, you always have $100. The behavior of the UTXO is the same. When you open your wallet and see your balance, this is the result of adding several UTXOs.
But how does the UTXO return work?
Continuing with the cash example, a UTXO is also not divisible. Imagine that we want to buy some pants and they cost us $20, but we only have a $50 bill. We have left the only option to hand over the 50 bills and receive a $30 return.
A UTXO works similarly. As they are not divisible, if we have to send 2 BTC, but we only have one UTXO worth 3 BTC, we have to send it in full and receive the return. The difference is that the receiver does not receive the 3 BTC, but the protocol itself takes care of the operation. The receiver will receive the 2 BTC, and the rest returns to your address as a new UTXO. But what if I had 3 UTXOs of 1 and wanted to send 2? It would be the same as with cash. You would use 2 UTXOs to reach the required amount.
Why are UTXOs essential?
The importance of UTXOs is that nodes use them to verify whether a transaction is valid or not since all the inputs of a transaction must be in the UTXOs database to be accurate. Why? Because if an input is not in it, it means that the transaction is trying to double-spend (that is, it is trying to use the same bitcoins twice) or trying to use bitcoins that do not exist.
Here we come to 2 ideas: The first, the total number of UTXOs in a Blockchain, represents the total number of tokens/coins in the system. Second, the chains that use this model do not create accounts with balances—the chain stores individual transactions. Therefore, users must use wallets to check their balance since they search the blockchain for all transactions related to the user's addresses. Once found, it goes on to add the incoming and subtracting the outgoing to determine the balance.
Advantages of the UTXO model
This model allows parallel processing of transactions since each transaction contains unique UTXOs independent of the others. Therefore, the processing of one does not affect the others.
The model allows a higher degree of privacy than the account-based model, as a user uses a different address for each transaction.
Disadvantages of the UTXO model
Despite the advantages, it also has some significant disadvantages, especially when we want to develop a complete Turing platform like Ethereum. The UTXO model limits developers in the number of states produced by each output. Furthermore, it is not compatible with the development of Smart Contracts since the model starts from the idea that output can only be owned by one person and can only be used by that person once at any given time.
This proposal, contrary to the previous one, represents the currencies as balances of an account. These can be controlled with a private key or by a smart contract.
If we take Ethereum as an example, we can see two types of accounts: those controlled by users through a private key and those governed by smart contracts. This distinction is not trivial since the Ethereum project opted for this model over that of UTXO.
How does the Account Model work?
You could say that they work the same as a bank account. Each user has an account with its corresponding balance. The account will allow you to make both total and partial deposits and withdrawals.
Example: Let's say you have an account with 5 ETH and you want to send someone 2.5 ETH. You must carry out a transaction that transfers that exact amount, after which you will see in your account that you have 2.5 ETH. Unlike the UTXO model, you don't have to send the 5 ETH and receive the difference.
Why are Accounts important?
This design provides greater flexibility to the blockchain since transactions can have different effects when they execute since they depend on the state when they occur, allowing the introduction of some logic that will vary the result, thus opening up the possibility of having a Turing Complete platform.
At the same time, from the user's point of view, its use may become more understandable than that of the UTXO model since it resembles a bank account that users are already used to using, facilitating its adoption to the general public.
Advantages of the Account Model
More flexible transactions
Transactions depend on the current state and can have different effects on themselves, allowing the existence of oracles and other logic mechanisms to influence the state resulting from a transaction.
Save storage space
Each transaction in this model only has a reference and a signature when producing a specific output, contrary to the UTXO design.
Disadvantages of the Account Model
As the outcome of the transactions depends on the existing state, you have to be very careful when executing transactions in parallel. Generally, transactions that affect the same account must be executed in order and sequentially. This model encourages users to reuse the same address, which reduces privacy since someone can connect the same account to a single owner.
This model is vulnerable to a possible double-spend attack. Specific platforms have included a nonce that increments each time a transaction executes to prevent the same transaction from running more than once.
As we have seen, both models have their advantages and disadvantages. The UTXO model stands out for facilitating the verification of token ownership in a blockchain. In contrast, the account-based model allows creating a more complex platform, enabling creating smart contracts and applications.
It is not necessary to imagine both models as something static but in constant evolution and improvement. Both mechanisms are subject to development iterations to better adapt to the evolution of their respective platforms.
However, we cannot rule out hybrid proposals that use parts of both models, for example, using UTXO for balances and the account model to enable the development of smart contracts.