Blockchain - Advanced Ethereum


Ethereum Blockchain has emerged as a very popular blockchain in the modern era. In this chapter, we will discuss some advanced Ethereum topics, like the Genesis Block, Block Difficulty, Gas and many more. Following this, the next chapters will discuss some important concepts of Ethereum Blockchain like Ethereum Wallets and the Role of Ethereum Miners.

Blocks and Blockchain in Ethereum

Blocks serve as the fundamental structural components of a blockchain. In Ethereum, each block is composed of several key elements, which include −

1. List of Transactions

The block contains a comprehensive list of all transactions that have taken place, as well as a list of the headers for any uncle blocks associated with it.

2. Headers of Ommers or Uncles

An uncle block refers to a block that is a descendant of a parent block but lacks any child blocks of its own. Ommers, or uncle blocks, are considered valid yet stale blocks that do not belong to the primary chain, although they enhance the overall security of the blockchain.

3. Block Header

Block headers represent the essential and intricate elements of an Ethereum block. Each header comprises several components, which are elaborated as follows −

  • Parent hash − This refers to the Keccak 256-bit hash of the header from the preceding block.
  • Ommers hash − This is the Keccak 256-bit hash representing the list of ommers (or uncle blocks) that are included in the current block.
  • Beneficiary − This field holds the 160-bit address of the entity designated to receive the mining reward upon the successful mining of the block.
  • State root − The state root field contains the Keccak 256-bit hash of the root node within the state trie.
  • Transactions root − This is the Keccak 256-bit hash of the root node of the transaction trie.
  • Receipts root − The receipts root is the Keccak 256-bit hash of the root node of the transaction receipt trie, which includes the receipts for all transactions within the block.
  • Logs bloom − The logs bloom is a bloom filter that aggregates the logger addresses and log topics from the log entries of each transaction receipt in the block's transaction list.
  • Difficulty − This indicates the difficulty level associated with the current block.
  • Number − This represents the cumulative count of all preceding blocks, with the genesis block designated as block zero.
  • Gas limit − This field indicates the maximum allowable gas consumption for the block.
  • Gas used − This field reflects the total gas expended by the transactions contained within the block.
  • Timestamp − The timestamp denotes the epoch Unix time at which the block was initialized.
  • Extra data − The extra data field is available for storing any arbitrary information pertinent to the block.
  • Mixhash − The mixhash field contains a 256-bit hash utilized to demonstrate that sufficient computational effort (Proof of Work, or PoW) has been exerted to create the block.
  • Nonce − The nonce is a 64-bit hash (a numerical value) that, in conjunction with the mixhash field, serves to validate that adequate computational effort (PoW) has been applied.
Block Header

The Genesis Block

The genesis block represents the initial block within a blockchain network. It differs somewhat from standard blocks in terms of its content and the method of its creation. This block includes 15 specific items like timestamp, nonce, hash and many more.

Block Validation

An Ethereum block is deemed valid if it meets the following criteria −

  • It aligns with the uncles and transactions, ensuring that all ommers are recognized as uncles and that the Proof of Work (PoW) for these uncles is legitimate.
  • The preceding block must exist and be valid.
  • The block's timestamp must be valid, meaning it should be later than the timestamp of the parent block and not exceed 15 minutes into the future.
  • If any of these conditions are not met, the block will be rejected.

Block Finalization

Block finalization is a critical process conducted by miners to authenticate the contents of a block and distribute rewards. This process encompasses four distinct steps, which are elaborated as follows −

Ommers Validation

In mining, the identification of ommers is essential. This involves validating the headers of stale blocks to ensure their legitimacy and confirming that the relationship between the uncle and the current block adheres to a maximum depth of six blocks.

Transaction Validation

In mining, the identification of transactions is crucial. This step entails verifying that the total gas utilized in the block corresponds to the final gas consumption after the last transaction, essentially reflecting the cumulative gas expended by the transactions within the block.

Reward Application

This step involves the distribution of rewards, which entails updating the beneficiary's account with the corresponding reward balance. In Ethereum, miners also receive compensation for stale blocks, amounting to 1/32 of the block reward.

State and nonce Validation

This final step requires the verification of the state and block nonce. In the context of mining, it is necessary to compute a valid state and block nonce.

Gas

Every operation executed on the Ethereum blockchain necessitates the payment of gas. This mechanism is crucial in preventing infinite loops from causing the entire blockchain to freeze, given the Turing-complete characteristics of the Ethereum Virtual Machine (EVM). A transaction fee, expressed in Ether, is deducted from the balance of the account initiating the transaction.

Miners require a fee to include transactions in their mining efforts. If this fee is set too low, the transaction may not be processed; conversely, a higher fee increases the likelihood of miners selecting the transaction for inclusion in a block. However, if a transaction with an adequate fee is included but involves excessively complex operations, it may trigger an out-of-gas exception if the allocated gas is insufficient. In such instances, the transaction will fail but will still be recorded in the block, and the originator will not receive a refund.

Transaction costs can be calculated using the following formula −

Total cost = gasUsed * gasPrice

Fee Schedule

Gas is incurred in three specific situations as a requirement for carrying out an operation −

  • When calculating an operation
  • During the creation of contracts or when making message calls
  • When there is an increase in memory usage