Risk Warning: Beware of illegal fundraising in the name of 'virtual currency' and 'blockchain'. — Five departments including the Banking and Insurance Regulatory Commission
Information
Discover
Search
Login
简中
繁中
English
日本語
한국어
ภาษาไทย
Tiếng Việt
BTC
ETH
HTX
SOL
BNB
View Market
Understand the UTXO model of Bitcoin in one article
Harbour
Odaily资深作者
@bcxiongdi
2022-12-29 02:00
This article is about 2379 words, reading the full article takes about 4 minutes
Account model VS UTXO model.

secondary title

Well-known chains such as Ethereum, EOS, and Solana all use the account model, and it can even be said that more than 90% of the projects use the account model, while only some old-fashioned projects use the UTXO model, such as BTC, DOGE , LTC, and of course some newer projects also use this model, such as FUEL using the OP scheme in Layer 2.

secondary title

2. What is an account model

To understand it simply, the bank account system, such as transfers between banks, Alipay, WeChat transfers, etc., all belong to the account model. Let me give a chestnut:

If A has 100 and B has 100

At this time, A transfers 50 yuan to B

A -50 ,B + 50 

The representation in the system is

A 50 , B 150 

so their balance

This is a transfer.

Suppose again, A still has 100, and he wants to transfer 1 yuan to 100 new accounts.

At this time, A needs to transfer 1 yuan to 100 people at the same time

1st transaction

A -1 , 1st person + 1

so their balance

A 99 , 1st person 1

2nd pen

A -1, 2nd person + 1

so their balance

A 98 , 2nd person 1

3rd pen

A -1, 3rd person + 1

so their balance

A 97 , 3rd person 1

......

and so on

100th person

A -1, the 100th person + 1

so their balance

A 0 , the 100th person 1

Theoretically, as the number of transactions increases, more time is required for execution.

secondary title

3. What is the UTXO model

As mentioned earlier, many old mainstream brands use UTXO, and the ancestor of this circle, Bitcoin, also uses the UTXO model. By the way, the legal digital currency DCEP issued by our country is also based on the UTXO model, so this model There must be something unique about it.

The full name of UTXO is Unspent Transaction Output, which means "unspent transaction output". Simply put, its model is a bit like the cash system in daily life. For example:

A has a wallet (a wallet in reality), which has a denomination of 1 yuan, a denomination of 10 yuan and a denomination of 100 yuan.

A wants to give B, C, and D 1 yuan each.

A There are three ways

The first method: take out 1 yuan of face value money to B

The second way: take out 10 yuan of face value to C, get back 9 yuan

The third way: take out 100 yuan of face value to D, get back 99 yuan

These three ways can complete the transaction.

Going back to the chain, imagine that every face value of money here is actually a UTXO on the chain. Specifically, the UTXO in the process of use is not transferred, but is constantly destroyed and rebuilt, for example:

A uses the second method to transfer money to C, the UTXO with a face value of 10 yuan will be destroyed, and the system will reprint a UTXO with a face value of 1 yuan and a UTXO with a face value of 9 yuan. a.

The same is true for the third method. When 100 yuan is destroyed, a UTXO with a face value of 1 yuan and a UTXO with a face value of 99 yuan is printed, and the 1 yuan is given to D, and the 99 yuan is returned to A.

This is the difference between UTXO and account model transfer methods. What's more, the UTXO model can be transferred in parallel. Because the balance exists through decentralized UTXO, each denomination can actually be transferred to different people at the same time. The above three methods It can be completed in one transaction at the same time, because there will be no account consistency issues involved, and each UTXO is calculated independently.

We are comparing the above account model, each transaction must rely on the completion of the previous transaction, the performance gap can be imagined. In this way, we can understand why the central bank's digital currency uses the UTXO model. Otherwise, how could Shenzhen send 10 million digital RMB to 50,000 wallets?

Let's go back to the example above:

A has 100, and he wants to transfer 1 yuan to 100 new accounts.

A UTXO with a face value of 100 can be split into 100 UTXOs with a face value of 1 yuan, and then directly distributed to 100 people in one transaction, which is completed instantly.

If you want to know how much money is in this wallet address, you need to count how many UTXO balances there are and sum them up.

secondary title

4. Advantages and disadvantages of account model and UTXO

Account model advantages:

The contract is stored in the Account in the form of code, and the Account has its own state. This model has better programmability, is easier for developers to understand, and has a wider range of scenarios.

Batch transactions are less expensive. Imagine that the mining pool pays the miners a fee. In UTXO, because each Input and Out requires a separate Witness script or Locking script, the transaction itself will be very large, and signature verification and transaction storage will consume precious resources on the chain. The Account model can greatly reduce costs through contracts.

Account Model Disadvantages:

There is no dependency between Account model transactions, and the replay problem needs to be solved. How does Ethereum solve it? We know that Ethereum uses a unique Nonce value method. There is a Nonce field in each transaction Tx. For each user, this Nonce cannot be repeated, thus avoiding replay attacks.

For the realization of Lightning Network/Raiden Network, Plasma, etc., users need a more complex Proof proof mechanism for proof, and a more complex protocol is required for the state migration from the sub-chain to the main chain.

UTXO advantages:

Computations are off-chain, and transactions themselves are both results and proofs. Nodes only need to do verification, no additional calculations are required for transactions, and no additional state storage is required. The calculation of the output UTXO of the transaction itself is completed in the wallet, so that the calculation burden of the transaction is completely borne by the wallet, which reduces the burden of the chain to a certain extent.

Except for Coinbase transactions, the Input of a transaction is always linked behind a UTXO. Transactions cannot be replayed, and the sequence and dependencies of transactions are easy to verify, and it is also easy to prove whether transactions are consumed.

The UTXO model is stateless and easier to process concurrently.

For P 2 SH type transactions, it has better privacy. The Input in the transaction is not related to each other, and technologies such as CoinJoin can be used to increase a certain degree of privacy.

Disadvantages of UTXO:

When there are more Inputs, the number of witness scripts will also increase. The signature itself consumes more CPU and storage space.

secondary title

  • 5. What are the brief differences between the account model and UTXO

Account Balance

Account model: You can see how much money is under the account in a simple and clear way.

  • UTXO model: Count the number of UTXOs under the address, and the result of summarizing them is the balance.

When the number of transactions increases exponentially

Account model: It will become more and more difficult.

  • UTXO model: naturally supports high concurrency.

From the perspective of smart contracts/developers

The account model conforms to the logic habits of developers, and it is relatively easy to write logic

BTC
basic knowledge
Welcome to Join Odaily Official Community