1. What models are currently used by the chain?
Ethereum, EOS, Solana and other well-known chains all use the account model. It can even be said that more than 90% of the projects use the account model, and only some old projects use the UTXO model, such as BTC, DOGE, LTC. Of course, some newer projects also use this model, such as FUEL, which uses the OP solution in Layer2.
2. What is the account model?
Simply put, it is the bank account system, such as bank-to-bank transfers, Alipay and WeChat transfers, etc., all belong to the account model. Let me give you an example:
If A has 100 and B has 100
At this time, A transfers 50 yuan to B.
The manifestation in the system is
A -50,B +50
So their balance
A 50, B 150
This is a transfer.
Suppose again that A still has 100, and he wants to transfer 1 yuan to 100 new account holders.
At this time, A needs to transfer 1 yuan to 100 people at the same time
1st
A -1, 1st person +1
So their balance
A 99, 1st person 1
2nd Transaction
A -1, 2nd person +1
So their balance
A 98, 2nd person 1
3rd Transaction
A -1, 3rd person +1
So their balance
A 97, 3rd person 1
And so on
......
No. 100
A -1, 100th person +1
So their balance
A 0, 100th person 1
Theoretically, 100 transfers need to be made, and the next transfer must be completed before the previous one. Otherwise, the account balance cannot be guaranteed to be consistent, and there will be confusion as to whether there are multiple transfers or whether the balance is sufficient for transfer.
In theory, as the number of transactions increases, the time required for execution increases.
3. What is the UTXO model?
As mentioned earlier, many old mainstream brands use UTXO, and Bitcoin, the ancestor of this circle, 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 must have its unique features.
UTXO stands for Unspent Transaction Output, which means "unspent transaction output". Its model is a bit like the cash system in daily life. For example:
A has a wallet (real wallet) with 1 yuan, 10 yuan and 100 yuan notes in it.
A wants to give 1 yuan to B, C and D respectively.
A There are three ways
The first method: take out 1 yuan and give it to B.
The second method: give C 10 yuan and get 9 yuan in change.
The third option: give D a 100-yuan bill and get 99 yuan back.
All three methods can complete this transaction.
Back to the chain, imagine that each denomination of money here is actually a UTXO on the chain. The UTXO in use is not transferred, but constantly destroyed and rebuilt. For example:
A transfers money to C using the second method. 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. The 1 yuan will be given to C, and the 9 yuan will be returned to A.
The third method is the same. The 100 yuan is destroyed, and one UTXO with a face value of 1 yuan and one with a face value of 99 yuan are printed. The 1 yuan is given to D, and the 99 yuan is returned to A.
This is the difference between the UTXO and account model transfer methods. What's even more amazing is that the UTXO model can transfer in parallel. Because the balance exists through decentralized UTXOs, each denomination can actually be transferred to different people at the same time. The above three methods can be completed simultaneously in one transaction because there is no account consistency issue involved. Each UTXO is calculated independently.
When we compare the account model above, each transaction must rely on the completion of the previous transaction, and the performance gap can be imagined. This makes us understand why the central bank's digital currency uses the UTXO model, otherwise how can 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 customers who have opened accounts.
A UTXO with a face value of 100 can be split into 100 UTXOs with a face value of 1 yuan, and then distributed directly to 100 people in one transaction, which is completed instantly.
In short, think of the face value of UTXO as more flexible cash that is constantly destroyed and rebuilt on the chain.
If you want to know how much money is in this wallet address, you need to count the number of UTXOs with balances and sum them up.
4. Advantages and disadvantages of account model and UTXO
Advantages of account model:
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.
The cost of batch transactions is low. Imagine that a mining pool pays a handling fee to a miner. Because each Input and Out in UTXO requires a separate Witness script or Locking script, the transaction itself will be very large, and signature verification and transaction storage will consume valuable resources on the chain. The Account model can greatly reduce costs through contracts.
Account model disadvantages:
Account model transactions have no dependencies, so the replay problem needs to be solved. How does Ethereum solve this problem? 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 implementation of Lightning Network/Raiden Network, Plasma, etc., user evidence requires a more complex Proof mechanism, and the state migration from the sub-chain to the main chain requires a more complex protocol.
UTXO advantages:
The calculation is off-chain, and the transaction itself is both the result and the proof. The node only needs to verify, and no additional calculation is required for the transaction, and there is no additional state storage. The calculation of the output UTXO of the transaction itself is completed in the wallet, so the calculation burden of the transaction is completely borne by the wallet, which reduces the burden on the chain to a certain extent.
Except for Coinbase transactions, the input of a transaction is always linked to a UTXO. Transactions cannot be replayed, and the order and dependencies of transactions are easy to verify, and whether the transaction has been consumed is also easy to prove.
The UTXO model is stateless and easier to process concurrently.
For P2SH type transactions, there is better privacy. The inputs in the transaction are unrelated to each other, and technologies such as CoinJoin can be used to increase privacy.
UTXO Disadvantages:
It is impossible to implement some complex logics, and the programmability is poor. For complex logic or contracts that need to save state, it is difficult to implement, and the state space utilization rate is relatively low.
When the input is large, the witness script will also increase. The signature itself consumes more CPU and storage space.
5. What are the brief differences between the account model and UTXO?
Account Balance
Account model: You can easily and clearly see how much money is in the account.
UTXO model: Count the number of UTXOs under the address, and the result of summing them up is the balance.
When the number of transactions increases exponentially
Account model: It will become increasingly difficult.
UTXO model: naturally supports high concurrency.
From the perspective of smart contracts/developers
The account model conforms to the developer's logical habits and is relatively easy to write logic
UTXO script programming is relatively complex