CodeChain’s UTXO Model

Kwang Yul Seo
CodeChain
Published in
3 min readMay 1, 2018

Two bookkeeping models are popular in today’s blockchain technology. The first model is called the UTXO(Unspent Transaction Output) model and the second one is the Account/Balance model. The UTXO model has been firstly employed by Bitcoin and used by many other cryptocurrencies derived from Bitcoin. Ethereum and other smart contract platforms are using the Account/Balance model.

CodeChain is a programmable multi-asset blockchain platform which is inspired by Color Coins project. In this article, we will explain how CodeChain’s UTXO model works and how it differs from Bitcoin’s UTXO model.

In the UTXO model, each transaction spends output from prior transactions and generates new outputs that can be spent by future transactions. The benefits of the UTXO model are:

  1. Scalability: It is possible to process multiple UTXOs at the same time. Because CodeChain aims to provide a scalable blockchain solution to multi-asset applications such as games, the scalability benefit of the UTXO model becomes very important.
  2. Privacy: UTXO provides a higher level of privacy if a user uses new addresses for each transaction.

A user’s balance in UTXO model is not stored as a single number; rather, it must be computed as the total sum of the UTXOs that the user owns.

In the UTXO model, a transaction must satisfy two rules:

  1. It must contain a valid signature for the owner of each UTXO it consumes.
  2. The total sum of the UTXOx consumed must be equal or greater than the total sum of the UTXOs it produces. This rule prevents accidental inflation.

So far so good, but there is one serious problem with Bitcoin’s implementation. A transaction input in Bitcoin only contains the transaction hash and index of the output. It means that we cannot tell how much a transaction is spending without having to have all the input transactions.

Here is an example showing why it is a serious problem:

Let’s say I want to create a $10 offline signing device. I will put 32 kB of RAM and a small screen and a tiny embedded chip that is just powerful enough for ECDSA signing. It will sign transactions for me after asking me to physically confirm with a button press. But the device has so little RAM, it can’t support arbitrary transactions. So, I’ll just make sure my online computer software never produces transactions bigger than 10 kB, and just do multiple transactions if necessary.

In Bitcoin, this isn’t possible. Without access to the blockchain, the device does not know whether it is signing 1 BTC input, or 1000 BTC input without supplying all supporting transaction along with the one to be signed.

Our team recognized this problem from day 1 and solved it simply by adding input value to transactions. Now we can tell how much a transaction is spending without having to have input transactions. When a CodeChain offline wallet user signs a transaction input that is worth 12.33 coins, the signature becomes only valid if that’s how much it’s actually worth. This small change greatly simplified offline tx signing.

Here is CodeChain’s AssetOutPoint struct which corresponds to Bitcoin’s COutPoint class. You can see it has amount field.

In conclusion, a small change in transaction format can greatly simplify offline tx signing. CodeChain learned this lesson from Bitcoin. It would be great that Bitcoin also had this support which only takes a few lines of code, but unfortunately this would mean a hard-fork.

Check out the source code at our github repo. If you would like to chat with the CodeChain developers community, join our gitter channel.

--

--