A Simple Guide to Understanding Ledger Models, UTXOs and EUTXOs in Blockchain Technology

Otobong Peter
7 min readJul 6, 2021

--

Photo by Stanislaw Zarychta on Unsplash

Background

Basic finance begins with the knowledge of the mechanisms that enables us to classify transactions as either credits or debits. And the summation of the debit and credit columns provides a balance on the ledger.

In the world of cryptocurrencies, some blockchain protocols have stretched the concept even more to enable transactions to be tracked, recorded and retrieved in a distributed & decentralized system. All these mechanisms all seek of course to balance the accounts at the end of the day. So one can say the end is the same, but the means and the how differ. So what are accounting models, UTXOs and EUTXOs ?

Introduction

Blockchain networks can be complex with thousands of transactions transversing through blocks in the chain, creating volumes of data that needs to be carefully tracked and managed inorder to ensure that the underlying blockchain retains its integrity and reliability. Two major accounting ledgers often employed in the blockchain ecosystem are: UTXO-based ledgers (e.g Bitcoin) and Account/Balance ledgers (e.g Ethereum).

Bitcoin uses an Unspent Transaction Output (UTXO) model, whereas Ethereum deploys an Account/Balance one. Although a blockchain protocol like cardano stretched its infrastructure by combining both the account model and an Extended Unspent Transaction Output (EUTXO) model. According to IOHK, this combination was done because:

Cardano sought to combine Bitcoin’s UTXO model with Ethereum’s ability to handle smart contracts into an Extended UTXO (EUTXO) accounting model. The adoption of EUTXO facilitates the implementation of smart contracts into the Cardano chain.

Transaction Outputs

A transaction output includes an address (more like a lock) and a value. The signature that belongs to the address is the key to unlock the output. Once unlocked, its value can be used as input. Therefore, new transactions spend outputs of previous transactions, and produce new outputs which future transactions can consume. An Unspent transaction output (UTXO) can only be consumed once. Each output can be spent by exactly one input only.

Transaction Inputs

A transaction input is the output of a previous transaction. It includes a pointer and a cryptographic signature that acts as the unlocking key. The pointer points to a previous transaction output and the key unlocks this output. When an output is unlocked by an input, the blockchain marks the unlocked output as “spent”. New outputs created by a given transaction can then be pointed to by new inputs, and so the chain continues. These new outputs (which have not yet been unlocked, i.e., spent) are the UTXOs. Unspent outputs are simply that, outputs that have not yet been spent.

The Account/Balance Model

Every organisation or commercial entity requires a balance sheet to keep accurate record of its profit, loss, cash flow, etc. By maintaining a meticulous detail of all this data, they can, easily, visualize their financial status at any given point in time. The accounting ledger also offers another advantage: The ability to trace the provenance and ownership of funds.

The same also applies to blockchain protocols. Some blockchain networks also utilize an accounting model to determine who owns a token, coins (and how many of them), track where these go, which ones are used up, and which ones remain available to be spent. Ethereum basically runs on the conventional model of creating columns for spent on unspent amounts as a means to balance accounts and ultimately prevent double spending. The accounting model is very much the conventional way traditional financial institutions has always been where, if Sam has $100 dollars and sends $30 to James, $30 is subtracted from his account and added to James. Such that the balance becomes $70 for Sam and $30 for James.

.

The Unspent Transaction Output Model (UTXO)

n the unspent transaction output (UTXO) model, the movements of assets on the blockchain are recorded in directed acyclic graphs. Each time money is sent to an address it becomes recorded as an unspent transaction output (UTXO) on that particular addresses. This differs from the conventional idea that money sent into an address will automatically be summed by that address. What wallets do is to track all the UTXOs available to a particular address and sum this up to generate a balance for that particular address these will also serve as inputs for future transactions (i.e spending).

The Cardano Settlement Layer documentation on transactions sums it up quite nicely,

“Inputs and outputs carry information about money flow: inputs inform where the money came from, and outputs inform where the money [goes] to.”

This sounds unconventional compared to how conventional financial services operate as previously stated.

In the UTxO model, an input contains a transaction ID, which is a hash(BLAKE2b-256) of the transaction and an index of the outputs using the transaction. An output contains the amount of money being sent as well as an address where we want money to be sent to (which is just a BLAKE2b-256 hash of the addresses public key).

Imagine three persons Sam, James and Susan sending $30, $40 and $60 each to your account, these amount becomes an unspent transaction output tagged to your address. Your wallet then sums this to generate the information that you have a balance of $130, but literally in the blockchain network these are different UTXO sets that have been tracked to your address. Each time a transaction is to be made, the algorithm looks through our collections of UTXOs of $30, $40 and $60 (which sums into your balance). It then selects which UTXO to use for the transaction, say, maybe you want to make a purchase worth $70, to make this possible, the algorithm then utilizes two seperate UTXOs to fund this transaction. That can be done by maybe using your $30 and $40 Unspent Transaction Outputs. This is then sent as an input to another destination address and it becomes a new UTXO of $70 for that address.

Image Credit : Fernando Sanchez (IOHK)

Taking another example, let’s assume that your underlying total amount of cryptocurrency say ‘ADA’ in your wallet is actually composed of three separate UTxOs that add up to 7,000 ADA. You might have 1,000 ADA in one UTxO, 2,000 ADA in another UTxO, and 4,000 ADA in another.

The transaction will need to send 3,000 ADA to maybe your friend Sam from one of the UTxOs containing 4,000 ADA and it will also need to send 1,000 ADA back to your wallet as a “change address.” The process of figuring out which UTxOs to use in a transaction is called the Coin Selection Algorithm — originally created for Bitcoin. Alternatively, if you had 10 separate UTxOs all containing 1,000 ADA each, then you would only need to create a transaction with an input index that contained three UtxOs.

There are two primary benefits to the, stateless, UTxO model. The First is that privacy is increased when change addresses and new unspent outputs (i.e., the money you sent to someone else) are close to 1:1. Distributed apps will be unable to store user data in the same way a bank account, or accounting based model, like Ethereum, would, because every new transaction uses a new address. The second benefit is in terms of scalability. Transactions can be processed in a parallel fashion.

.

The Extended Unspent Transaction Model (EUTXO)

The cardano blockchain is a blend of both the conventional accounting model and an extended unspent transaction model, something called a ‘chimeric ledger’. The Unspent Transaction Model runs on the settlement layer while the account model runs on the computational layer.

An excerpt from an article by IOHK has this to say —

“The ‘basic’ UTXO model has a limited expressiveness of programmability. Ethereum’s Account/Balance accounting model addressed this specific problem with the development of an account-based ledger and associated contract accounts. But by doing so, the semantics of the contract code became far more complex, which had the unwanted effect of forcing contract authors to fully grasp the nuances of the semantics to avoid the introduction of potentially very costly vulnerabilities in the code.”

An ‘extended’ UTXO solution would require two pieces of additional functionality that the existing UTXO model could not provide:

  1. To be able to maintain the contract state.
  2. To be able to enforce that the same contract code is used along the entire sequence of transactions. Thus, ensuring continuity.

How does EUTXO extend the UTXO Model ?

The conventional UTXO model is such that addresses and their values acts like locks that must be unclocked using a particular signature(serving as keys) to spend it’s value. The extended UTXO model adds more feature to this lock by making it possible to set conditions for the locks (programmability). In other words, instead of just having public keys (hashes) for locks and corresponding signatures serving as “keys”, EUTXO enables arbitrary logic in the form of scripts. This arbitrary logic inspects the transaction and the data to decide whether the transaction is allowed to use an input or not. According to an IOHK article

“Cardano’s ledger model extends the UTXO model to support multi-assets and smart contracts without compromising the core advantages of a UTXO model.”

A research paper on the extended UTXO model by “Chakravarty, Chapman, MacKenzie, Melkonian, Peyton and Wadler” explains with more details the technicality behind how the EUTXO operates here.

Written by: Otobong Peter

Appreciation : To the African Blockchain Centre for Developers for making my journey in the Blockchain Space easier.

--

--

Otobong Peter
Otobong Peter

Written by Otobong Peter

Exploring the Web, WASM and Cloud technologies. (Tinkering with Python, Javascript and Rust)

No responses yet