Ethereum account

Ethereum account model

The BTC system is a transaction-based ledger. In this mode, there is no explicit record in the system of how much BTC a person has, and it can only be estimated through UTXO. The advantage of this model is that you may not know how much money you have, but in practice, it is awkward to use, which is different from the daily experience: when A transfers money to B, you need to explain the source of the currency. In practice, you only need to save money to explain the source, but you don't need to spend money. In addition, when the money in the account is spent, it must be spent all at once, and the excess money must be transferred to a change address where the money is saved.

The Ethereum system uses an account-based model, similar to a bank account in reality. The system explicitly records the amount of ether in each account. Whether the transfer is legal or not only needs to check whether there is enough ether in the transferer's account, and it is not necessary to transfer all the money every time. At the same time, it also naturally prevents double flower attacks.

replay attack 

A transfers money to B. After a period of time, B rebroadcasts A's transaction, which causes A's account to be debited twice. Assuming that A transfers money to B, a double spending attack is A's dishonesty, and a replay attack is B's dishonesty.

In order to prevent replay attacks, a counter is added to the account transaction to record how many transactions have been issued by the account in history, and the number of transfers is included in the content of the transaction when transferring money. 

If B replays the transaction at this time, then the current nonce of A is at least greater than or equal to 21, then obviously the next legal transaction is no longer satisfied than the current nonce+1! !
The full node in the system maintains the account balance and the number of transactions of the counter, thereby preventing local tampering with the balance or replay attacks.

External account and contract account

There are two types of accounts in the Ethereum system: external accounts and contract accounts.

External account: similar to the public-private key pair in the BTC system. There is an account balance balance and a counter nonce.

Contract account: not controlled by public-private key pair. (You cannot actively initiate transactions. Ethereum stipulates that all transactions can only be initiated by external accounts. A contract account can only initiate transactions or call other contract accounts after receiving calls from external accounts.) In addition to balance and nonce, it also has code( code), storage (related state - storage).

How to call a contract account?

When creating a contract account, an address will be returned, and you can call it if you know the address of the contract. During the call, the code remains unchanged but the state changes.

Why do Ethereum and replace it with an account-based model instead of following the BTC system?
Bitcoin supports every change of account, but Ethereum is designed to support smart contracts, and both parties to the contract need to be clear and less changed. Especially for contract accounts, it is necessary to maintain a stable state of the account.

References

1. Open class "Blockchain Technology and Application" by teacher Xiao Zhen from Peking University

2. Reference notes

Guess you like

Origin blog.csdn.net/LDDlove_java/article/details/127337912