UTXO Model vs. Account Model

UTXO Model vs. Account Model

Blockchains differ from each other in many factors like how is consensus ensured in them, what are their scalability limits, how interoperable are they with other blockchains and so on. One such factor where blockchains use different solutions is their account keeping model - basically how to keep track of the tokens and assets that a user owns. In this article, we'll first discuss two such models - the UTXO Model and the Account Model. We'll then compare these models in later sections. It's going to be an exciting journey, so let's get started!

UTXO Model

Any transaction in a blockchain contains a minimum of two things: an input and an output. The best way to understand UTXOs (Unspent Transaction Outputs) is through the analogy of cash :

  1. Let's say I want to transfer $10 to you via cash - I'll simply take out a $10 bill from my wallet and give it to you.
  2. The $10 bill being spent from my wallet is the input in the transaction - you getting the bill in your hand becomes the output of the transaction. As long as you keep this bill with you, it will remain as an unspent output from our transaction in your wallet.
  3. Come to think of it, all other bills in your wallet are unspent outputs from previous transactions that you would have done with people in the past. As soon as you use one of these bills to pay for something, it stops being an unspent output from a previous transaction - but rather becomes a spent input in a new transaction.
  4. The total value contained in your wallet is the total of all unspent outputs (i.e. bills from previous transactions) that you own. In fact, the total value contained in the whole world is the total of all bills present in each person's wallet. Yes I know we're not accounting for assets like real estate, gold, bonds, money deposited in banks, etc. but you get the idea!

And this is exactly how the UTXO model works in blockchains like Bitcoin. People's wallets contain multiple UTXOs and the total value contained inside a blockchain network is the sum of all these UTXOs. All of these UTXOs collectively form the UTXO Set. Each node that validates the blockchain contains a copy of this UTXO Set - hence each node knows which wallet address owns how many coins and hence can easily validate transactions. Let's understand how a transaction works in blockchains that use the UTXO model with the help of an example:

UTXO vs Account Model.png

Here, Daniel's wallet contains a UTXO worth 10 bitcoins (remember that a UTXO is simply the unspent output from a previous transaction that Daniel must have done with someone). He wants to send 8 bitcoins to his friend Kevin. To do this, first, a transaction is created. Then Daniel's UTXO is unlocked and marked as spent and removed from the UTXO set (this detail will come in handy later). The unlocked UTXO from Daniel becomes the input for the transaction. This transaction will actually have two outputs: one is a UTXO worth 8 bitcoins which is sent to Kevin's address, and another is a UTXO worth 1.999 bitcoins that is sent back to Daniel's address. Wait, why 1.999 bitcoins? Well, some part goes to the miners' fees. Here the miners' fee has been assumed to be 0.001 bitcoins. And that's it! Daniel now owns a UTXO worth 1.999 bitcoin and Kevin owns a UTXO worth 8 bitcoins. Both of them can use these unspent outputs as inputs in subsequent transactions. Hope you'll appreciate my feeble attempts at art in the picture above haha!

In the above example, we saw that a transaction can have multiple outputs. Well, as you might have guessed, a transaction can even have multiple inputs. If Daniel's wallet had initially contained two UTXOs worth 5 bitcoins each and he wanted to transfer 8 bitcoins to Kevin, then both of Daniel's UTXOs would've been unlocked (and removed from the UTXO set) and would've been used as two inputs in the transaction.

UTXO model is double-spend attack resistant since the UTXOs are marked as spent and removed from the UTXO set. Hence a user can't send the same coins to more than one entity.

We'll take a look at the advantages and disadvantages of the UTXO model when we compare it with the Account Model. But let's discuss the Account Model before that.

Account Model

Some blockchains are designed to do the accounting of tokens not by tracking each individual token itself, but by looking at the state of a user's account as a whole. So while we look at each unspent token in UTXOs, we don't do that in the Account model. Ethereum is an example of a blockchain that uses the Account Model. The account model is best understood by using the analogy of an actual bank account:

Let's say my account contains 10 ethers, and yours contains 15 ethers. The blockchain knows about our accounts and knows how many ethers are present in these accounts. Now if I want to transfer 3 ethers to you, I'll create and send a transaction to the blockchain network. The network will check if my account has at least 3 ethers to give out, and will reject the transaction if my account is low on funds. In this case, since my account has enough funds, the transaction is valid. The network will then deduct 3 ethers from my account and add 3 ethers to your account. Our respective accounts will now read 7 ethers and 18 ethers as balance. As you can see, this model works just like a bank account!

UTXO vs Account Model (1).png

Since there is no concept of tracking individual coins in the Account Model, hence a double-spend attack doesn't really exist in such blockchains. But a very similar exploit called Replay Attack does exist. Basically, if you sent a transaction to someone to send them some ethers, they can very well send the same transaction over and over again to the network and drain your wallet by charging you multiple times! To avoid this, Ethereum has a system of having a nonce for each account. This nonce value gets increased automatically after each transaction, and hence the same transaction can't be sent to the network over and over again. If the same transaction will be sent to the network, the network will detect that this transaction with the same nonce has already gone through once, and will reject all subsequent fraudulent transactions.

Comparisons Between UTXO and Account Model

Now that we understand both, UTXO and Account Model, we'll be able to discuss some pros and cons of both:

  1. In the UTXO model, the onus for calculating and accounting for the total assets of a user lies off-chain on the actual wallets which track all unspent transactions in all addresses owned by the user. This takes some pressure away from the main chain. In the Account Model however, the total accounting is done by the network itself.

  2. In the UTXO model, greater privacy is ensured because UTXOs are generally sent to newly-created addresses for users. Hence it becomes difficult to track ownership of coins since the owners of these newly created addresses are not easily known. However, in the Account Model, better fungibility is ensured. Say if you received 1 token each from 10 different addresses (hence making your total account worth 10 tokens), and if you now want to send 2 tokens to a friend, then there is no way of knowing that these 2 exact tokens originally came from which transaction and user. This prevents censorship in the network since all tokens are treated the same.

  3. The UTXO model is more scalable since it allows multiple transactions to happen in parallel. However, since the Account Model employs the use of a nonce value, it becomes impossible to have transactions happening parallelly.

  4. The Account Model is more compatible for running smart contracts, the UTXO model is kind of lacking in this department. Hence blockchains using the Account Model are more programmable.

  5. The Account Model is also more memory efficient since the network just needs to save the total account value of each user, not the individual unspent transactions owned by a user like in the UTXO Model.

Closing Remarks

We saw what the UTXO and Account models are and how they work. We also did a quick comparative study between them. As you must have gathered after reading all of that, each model has its own trade-offs and different models are required for different usecases.