-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: P15 ETH Accounts & P21 Proof of Stake (POS) & P23 The DAO Incident #48
Open
raftale
wants to merge
4
commits into
YoubetDao:main
Choose a base branch
from
raftale:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# P15 - Accounts | ||
|
||
## Account-Based Ledger | ||
Comparing Bitcoin and Ethereum: | ||
- Bitcoin uses a **transaction-based ledger**, where account balances are inferred through `UTXO`. | ||
- Ethereum uses an **account-based ledger**, similar to a banking system, where accounts directly store `balance` states. | ||
|
||
Differences in transfer mechanisms: | ||
- Bitcoin: When transferring from account B to C, the source of coins must be specified, and every `UTXO` must be entirely spent at once, so any remaining coins should be transferred back to another self-owned account. | ||
- Ethereum: The source of coins during a transfer is the `balance` state of the account, as the account includes the `balance` state, so it does not need to be entirely spent at once. | ||
|
||
```txt | ||
Transaction-based Ledger Account-Based Ledger | ||
┌────────────────────────────────────────┐ ┌───────────────────────────────────┐ | ||
│ ┌──────────────────┐ │ │ │ | ||
│ │ │ │ │ │ | ||
│┌─────▼───────┐ ┌┼─────────────┐│ │┌─────────────┐ ┌─────────────┐ │ | ||
││A───►B(10BTC)│ │B─┬──►C(3BTC) ││ ││A───►B(10ETH)│ │B───►C(3ETH) │ │ | ||
││ │ │ │ ││ ││ │ │ │ │ | ||
││ │ │ └──►B'(7BTC)││ ││ │ │ │ │ | ||
│└─────────────┘ └──────────────┘│ │└─────────────┘ └─────────────┘ │ | ||
└────────────────────────────────────────┘ └───────────────────────────────────┘ | ||
``` | ||
**Advantages** of the account-based model: No need to consider the source of coins, inherently preventing double-spending attacks. | ||
|
||
## Replay Attack | ||
Although the **account-based ledger** avoids double-spending attack, there is still a risk of **replay attack**. | ||
|
||
**Replay Attack**: After transferring from account B to C, C maliciously broadcasts B's transaction later, resulting in B being debited twice. | ||
|
||
**How to prevent Replay Attack?** | ||
|
||
1. Add a `nonce` state to the account as a transaction counter, recording the number of transactions posted by the account, the `nonce` becomes part of the transaction and is signed during transfers. | ||
2. Transactions with a `nonce` less than or equal to the account's current `nonce` are rejected. | ||
|
||
```txt | ||
┌─────────────────┐ | ||
│ B -> C(10ETH) │ | ||
│ │ | ||
│ nonce = 21 │ | ||
│ │ | ||
│ signed by A │ | ||
└─────────────────┘ | ||
``` | ||
|
||
## Smart Contract Accounts | ||
|
||
Two types of accounts exist in the Ethereum system: | ||
1. Externally Owned Accounts: Controlled by user's public-private key pairs, these accounts have a `balance` and a `nonce`. | ||
2. **Smart Contract Accounts**: In addition to `balance` and `nonce`, these accounts include `code` and `storage`. | ||
- When a contract is created, it returns an address that can be used to make calls to the contract. During these calls, the `code`remains unchanged. | ||
- Contract Accounts can't initiate a transaction on their own, all transactions must be initiated by external accounts. | ||
- Contract Accounts also have a `nonce`, which records the number of times the contract has been invoked. | ||
- A contract can call another contract. | ||
|
||
## Why Ethereum use Account-Based Ledger? | ||
Ethereum is designed to support smart contracts, which require stable account addresses for execution. | ||
|
||
Therefore, the account-based ledger is more suitable than the transaction-based ledger. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ | |
# ETH | ||
|
||
- [Difficulty Adjustment](ETH/difficulty-adjustment.md) | ||
- [Accounts](ETH/Accounts.md) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you sure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for sure. The arrow from B to A indicates the source of the coin, which is feature of the UTXO model but unnecessary for the account-based model.