We're all accustomed to the way our banks make the accounting with our money. Traditional accounting documents the flow of funds between different accounts. UTXO, by contrast, focuses on the flow of funds from transaction to transaction.
Every transaction has inputs (amount coming from where other people are spending the money) and outputs (where this money is going in a new transaction). The body of a transaction can contain other data as well. The Unspent Transaction Output (UTXO) paradigm is an essential part of Cryptocurrency and many others. This post tries to serve as a quick intro to UTXO.
The consumer uses a digital signature to validate the inputs' possession, which ultimately must correspond to outputs. The consumed UTXOs are now called "spent."
UTXO accounting style is a convenient mechanism for redistributing the cash flow from several contributors to the desired payees. The "bucket" where all this cash is temporarily stored/bundled is called a Transaction. In the interim, the transaction results become new UTXOs - to be included later on in a new transaction. When anyone sends some amount of a coin (bitcoin, Cardano ADA), one or more locked unspent (UTXO) outputs are activated to function as the same coin input.
If you have read the previous post in this blog, you'll see that this mechanism shares many Smart Contracts characteristics. However, as we're used to the traditional accounting method, UTXO is not an intuitive way of moving funds.
Underneath every transaction, there is a ledger to record all of them along with their internal details. The Ledger record that contains the transaction information is called a UTXO: Unspent Transaction Outputs.
This record is a map with keys and values. The Keys are the transaction IDs and one or more output indexes (a transaction can have many outputs), while the values are pairs of ADA amounts and wallet addresses.
Processing a transaction involves updating the UTXO on the ledger that makes the funds spent (recorded inside the transaction) available to be consumed by the owners of the addresses listed in the outputs.
The validation of a transaction is not an easy task. The validation implies calculating the total amount of ADA in the outputs and inputs of the transaction. The treasury is the destination for the ADA spent besides adding them as UTXO entries. All the deposits and fees are paid inside the treasury. There are output entries with no matching inputs: These are the rewards that the network pays to delegators, collected from rewards addresses. Every transaction also includes much more info: hashes, scripts, witnesses, and certificates.
Validation also implies more calculations to ensure that no ADA is created from thin air. These calculations take into account the ADA in the transaction and the other accounts in the ledger. This process is called Generalized Accounting Property (GAP).
UTXO also implements protection against double-spending: Network users can't spend outputs more than once. This protection, along with the GAP, disables bad or dishonest behavior between the network participants. It also ensures that the total amount of ADA in existence does not change.
The UTXO Set
There is a global network database that keeps track of all the spendable outputs. When a new transaction is being constructed, it uses the spendable Outputs exposed by the UTXO Set. The Outputs selected are removed from the UTXO set resulting in its shrinkage. On the other side, when new unspent output is created, the UTXO Set grows accordingly.
Security and simplicity. A UTXO is "consumed" thoroughly after spending, so the system avoids double-spending.
Every user can use a new address for every transaction that she makes. This characteristic provides users privacy, making it very difficult to associate a set of coins with a specific user.
When a new transaction is committed, and the UTXO is spent inside it, the UTXO is destroyed, and more UTXO are crated. The UTXO is updated accordingly. Nodes can verify transactions in parallel independently.
UTXO is not an intuitive model. We're used to thinking about accounts when we're dealing with money.
Traditional mechanisms are easier to manage: Multiple account numbers make UI/UX difficult for wallet designers.
The UTXO model requires multiple signatures from multiple parties when dealing with Smart Contracts and, at the same time, access outside blockchain data with Oracles. Some Smart Contract platforms use a hybrid model: UTXO keeping track of balances and Accounts for Smart Contracts.
The majority of working blockchains use the UTXO model (except Ethereum, which uses the traditional Account Model). The UTXO is not an easy concept; at least the first time you are confronted with it. But once you're accustomed, it is a logical and handy choice for the development of blockchains. In the UTXO way of thinking, your money (coins) is exactly the UTXO that can be unlocked with your private keys. Verification is the main objective behind the UTXO model, but this comes at a cost: It is computationally more complex, introduces usability challenges, and puts some difficulty to Smart Contracts.