Transaction based state-machine
state of the blockchain changes after executing transactions.
stores states in state root
Accounts
20-byte hex addresses whose state is stored on the blockchain
Two types of accounts:
- EOA: externally owned account
- Contract Accounts
Each Accounts Has Four Parts:
- Nonce: for EOA, number of transactions sent from the address. For Contracts, number of contracts creations.
- Balance: amount of ether owned by the account.
- storageRoot: Merkle-Patricia tree that stores data related to the account. Stored in the top-level state root tree.
- codeHash: For EOA, hash of empty string. For contracts, hash of the init code.
Transactions
Piece of data signed by an external actor.
Two types of txs:
- Transaction which result in message calls
Message Calls: Done by contract account, when executing
CALL
opcode. - Contract creation
Fields in a tx:
- nonce
- gasLimit
- gasPrice
- to
- value
- v, r, s: signature identifying sender
- init: in case of contract creating tx, returns code of the contract without constructor
- data: in case of message call tx, data being passed in call
Blocks
aggregate transactions and include in the blockchain
Contains:
- parentHash
- ommerHash
- beneficiary
- stateRoot
- transactionsRoot
- receiptsRoot
- timestamp
- number
- difficulty
- gasLimit
- gasUsed
- extraData
- mixHash
- nonce
GHOST
GHOST
protocol is used by ethereum to prevent mining centralization and enhance protocol security.
Longest chain isn’t just the chain with more blocks as ancestor, but it also includes other stale(uncle) blocks in the calculation.
Uncle blocks are child of the ancestor of the block and not directly related to the block.
RLP
It is the data encoding used by the protocol to store data in tries. There are several rules for encoding mentioned below.
Data structure in Ethereum | Episode 1: Recursive Length Prefix (RLP) Encoding/Decoding.
HP Encoding
This encoding is used for trie paths.
Data structure in Ethereum | Episode 1+: Compact (Hex-prefix) encoding.
Ethereum: Tutorials - LayerX Research
Patricia tree