Two types of record-keeping models are popular in today’s blockchain networks. The first method is called the UTXO (Unspent Transaction Output) Model and the second one is the Account/Balance Model. The UTXO model is employed by Bitcoin, and Ethereum uses the Account/Balance Model. In this article, we will lay out a basic understanding of how these two models work, how they differ, and briefly touch on pros and cons of the two.
In Bitcoin, each transaction spends output from prior transactions and generates new outputs that can be spent by transactions in the future. All of the unspent transactions are kept in each fully-synchronized node, and therefore this model is named “UTXO”. A user’s wallet keeps track of a list of unspent transactions associated with all addresses owned by the user, and the balance of the wallet is calculated as the sum of those unspent transactions.
Let’s take a look at a simplified example of how the UTXO model works in Bitcoin transactions:
1. Alice gains 12.5 bitcoins through mining. Alice’s wallet is associated with one UTXO record of 12.5 bitcoins.
2. Alice wants to give Bob 1 bitcoin. Alice’s wallet first unlocks her UTXO of 12.5 bitcoins and uses this whole 12.5 bitcoins as input to the transaction. This transaction sends 1 bitcoin to Bob’s address and the reminder of 11.5 bitcoins is sent back to Alice in the form of a new UTXO to a newly-created address (owned by Alice).
3. Say there was another UTXO of 2 bitcoins associated with Bob prior to step 2, Bob’s wallet now shows that his balance is 3 bitcoins. Bob’s wallet now keeps track of two UTXOs: one from before and another from the transaction in step 2. Each UTXO needs to be unlocked if Bob wishes to spend them.
The Account/Balance Model, on the other hand, keeps track of the balance of each account as a global state. The balance of an account is checked to make sure it is larger than or equal to the spending transaction amount.
Here is a simplified example of how this model works in Ethereum:
1. Alice gains 5 ethers through mining. It is recorded in the system that Alice has 5 ethers.
2. Alice wants to give Bob 1 ether, so the system will first deduct 1 ether from Alice’s account, so Alice now has 4 ethers.
3. The system then increases Bob’s account by 1 ether. The system knows that Bob has 2 ethers to begin with, therefore Bob’s balance is increased to 3 ethers.
One analogy for the transactions in the UTXO model is paper bills (banknotes). Each account keeps track of how much money it has by adding up the amount of bills (UTXOs) in the purse (associated with this address/wallet). When we want to spend money, we use one or more bills (existing UTXOs), enough to cover the cost and maybe receive some change back (new UTXO). Each bill can only be spent once since, once spent, the UTXO is removed from the pool.
On the other hand, the record-keeping for Ethereum is just like that in a bank. An analogy is using an ATM/debit card. The bank tracks how much money each debit card has, and when we need to spend money, the bank checks its record to make sure we have enough balance before approving the transaction.
Both models achieve the same goal of keeping track of account balances in a consensus system.
The benefits of the UTXO Model are:
- Scalability — Since it is possible to process multiple UTXOs at the same time, it enables parallel transactions and encourages scalability innovation.
- Privacy — Even Bitcoin is not a completely anonymous system, but UTXO provides a higher level of privacy, as long as the users use new addresses for each transaction. If there is a need for enhanced privacy, more complex schemes, such as ring signatures, can be considered.
The benefits of the Account/Balance Model are:
- Simplicity — Ethereum opted for a more intuitive model for the benefit of developers of complex smart contracts, especially those that require state information or involve multiple parties. An example is a smart contract that keeps track of states to perform different tasks based on them. UTXO’s stateless model would force transactions to include state information, and this unnecessarily complicates the design of the contracts.
- Efficiency — In addition to simplicity, the Account/Balance Model is more efficient, as each transaction only needs to validate that the sending account has enough balance to pay for the transaction.
One drawback for the Account/Balance Model is the exposure to double spending attacks. An incrementing nonce can be implemented to counteract this type of attack. In Ethereum, every account has a public viewable nonce and every time a transaction is made, the nonce is increased by one. This can prevent the same transaction being submitted more than once. (Note, this nonce is different from the Ethereum proof of work nonce, which is a random value.)
Like most things in computer architecture, both models have trade-offs. Some blockchains, notably Hyperledger, adopt UTXO because they can benefit from the innovation derived from the Bitcoin blockchain. We will look into more technologies that are built on top of these two record-keeping models.