What is a state machine? Why Ethereum is called a state machine?
A state machine refers to something that makes a transaction from one state to another based on the input.
When nodes make transactions, the current state transitions into some final state. At any point in time, this final state represents the current state of Ethereum.
What is a Merkle tree? What is the importance of the Merkle tree in blockchain? How Ethereum implements a Merkle tree?
A Merkle tree, in the most general sense, is a way of hashing a large number of “chunks” of data together which relies on splitting the chunks into many buckets, where each bucket contains only a few chunks. Then taking the hash of each bucket and repeating the same process, continuing to do so until the total number of hashes remaining becomes only one: the root hash (Merkle Root).
A binary Merkle tree looks like below:
The Merkle Root is important because it summarizes every transaction in the block and is located on the block header. If there is any malicious change in the transactions stored in the block, the Merkle root changes. This makes it easier to verify whether or not a transaction has occurred within a block.
The Ethereum blockchain uses a modified version of the basic Merkle tree which is actually called the Merkle Patricia tree, Patricia tree, or Patricia Trie.
Each Ethereum block header has three Merkle trees.
- Receipts (essentially, pieces of data showing the effect of each transaction)
The first one is the root of transactions on the block, the second is the root showing the state of the Ethereum network, and the third is the receipt root.
Ethereum’s global state consists of a mapping between account addresses and the account states. This mapping is stored in the Merkle Patricia tree. In this data structure, data is stored in the form of a key-value pair. The state in Ethereum is different, and as explained by Vitalik Buterin, it is a key-value map. The keys are the addresses of an account, and the values are nonces, account balances, and code and storage.
How does the gas parameter save the system from attackers?
Let us consider a situation where an attacker wants to halt the Ethereum network by running a smart contract which consists of an infinite loop. Without the gas parameter, every node will execute the infinite loop which will eventually crash the network.
With the gas parameter included, if an attacker runs such a smart contract, he will also have to attach the equivalent amount of gas i.e Ether. So, it will only lead to the attacker’s loss as he will eventually run out of gas and the execution will stop at that instant. This is how the gas parameter saves the Ethereum network from attackers.
Gas is the Ether, the cryptocurrency of the network.
Where does the contract code is executed?
A smart contract is executed when a mining node includes the transaction in a block it generates. The associated gas acts as a fuel to run the smart contract. If the gas price is sufficient enough to run the contract, state transitions as directed by smart contract and the related transaction is included in the block and is then broadcasted in the network. If the gas is not sufficient, it throws an error. The smart contract codes are then run by every other node when they include the block in their local Ethereum Network.
What is DAO and how it functions?
A decentralized autonomous organization is an organization represented by rules encoded in a transparent smart contract and it is controlled by shareholders or board of directors.
For certain actions to enforce, be it transfer of fund or modification in the base code, there should be the consent of at least 2/3rd of the members. Methods for allocating a DAO’s funds could range from bounties, salaries, internal currency to reward work.
What GHOST protocol? What problems does it solve in Ethereum?
The GHOST (Greedy Heaviest-Observed Sub-Tree) protocol picks the path that has had the most computation done upon it.
GHOST solves the issue of network security loss by including in the calculation of which chain is the “longest by not only including the parent and further ancestors of a block but also the stale blocks (called uncle blocks).
Name 4 components of the account state?
nonce: For an externally owned account, this number represents the number of transactions sent from the account’s address. For a contract account, the nonce is the number of contracts created by the account.
balance: The number of Wei owned by this address.
storageRoot: A hash of the root node of a Merkle Patricia tree. This tree encodes the hash of the storage contents of this account and is empty by default.
codeHash: The hash of the EVM code of this account. For contract accounts, this is the code that gets hashed and stored as the codeHash. For externally owned accounts, the codeHash field is the hash of the empty string.
How the signing and verification of a transaction take place in Ethereum?
The private key along with the transaction data is used to sign a transaction. ECDSA signatures in a transaction consist of three parameters r, s, and v. Ethereum clients provide a global method that returns an address given these three parameters. If the returned address is the same as the signer’s address, then the signature is valid.
What is the importance of difficulty?
The “difficulty” of a block is used to enforce consistency in the time it takes to validate blocks. If a certain block is validated more quickly than the previous block, the Ethereum protocol increases that block’s difficulty. If a block validation takes more time than the previous block, the Ethereum protocol decreases that block’s difficulty.
What is intrinsic gas value?
Intrinsic gas value gives an estimated cost of the gas fees. So, the transaction’s gas limit must be equal to or greater than the intrinsic gas. Intrinsic gas consists of –
- a predefined cost of 21,000 gas for executing the transaction
- a gas fee for data sent with the transaction (4 gas for every byte of data or code that equals zero, and 68 gas for every non-zero byte of data or code)
- if the transaction is contract-creating, an additional 32,000 gas
What is the importance of account nonce in Ethereum?
An account nonce is a transaction counter in each account. It is used to prevents replay attacks i.e. taking a transaction on one blockchain, and maliciously or fraudulently repeating it.
What is the state channel?
State channels are used for scaling the Ethereum blockchain and reducing costs for micropayments by moving on-chain components to off-chain. This can avoid delays and fees associated with micropayments. This is similar to the Lightning network in Bitcoin. Participants in a state channel pass cryptographically signed messages without publishing them to the main chain until they both decide to close the channel.
What is Whisper Protocol?
Whisper is a peer-to-peer communication protocol for Dapps built upon the Ethereum network. It provides a privacy-focused, encrypted messaging system for Dapps. Properties of Whisper protocol –