![](https://coding-bootcamps.com/wp-content/uploads/2024/01/72-1.jpg)
Note
If you are new to the blockchain technology, taking our Introduction to Blockchain Technology self-paced course is highly recommended. Also, for a comprehensive coverage of blockchain development in Ethereum or mastering Solidity programming, taking our below self paced courses is highly recommended:
Recap
In our previous article (How address and wallet work in Ethereum), we discussed how Ethereum address and wallet work.
In this article, we learn about mining in Ethereum.
Understanding mining in Ethereum
In this article, we will explain how mining works in Ethereum, and briefly discuss Ethereum’s plan for the PoS consensus mechanism.
The mining process in Ethereum is largely the same as the one we discussed in Bitcoin. For each block of transactions to be added to the Ethereum blockchain and the world state to be updated, consensus must be reached among all network nodes that the new blocks proposed by the miners, including the nonce found with the PoW, must be verified by all nodes.
However, there are quite a few notable differences between Ethereum mining and Bitcoin mining. Most of them are driven by the protocol and architecture difference in the blockchain. As we discussed earlier, Ethereum maintains both the transaction list and the world state on the blockchain. We will discuss those differences in detail here.
One-to-One Live Blockchain Classes
Coding Bootcamps school offers One-to-One Live Blockchain Classes for Beginners.
Mining and consensus protocol
Bitcoin uses a general-purpose cryptographic hash function SHA-256 as the PoW algorithm. With advances in specialized mining equipment such as ASIC, miners have been building large mining pools to compete with each other for the rewards of the bitcoin. It puts small miners at a disadvantage and leads to more mining centralization.
To avoid such concerns, Ethereum uses a memory-hard hash function called Ethash, a modified version of the Dagger-Hashimoto algorithm, as the PoW algorithm and targets GPUs as the primary mining equipment.
As with other PoW algorithms, Ethash involves finding a nonce that makes the resulting hash value fall under a protocol defined target. The design idea for a new hash algorithm is twofold. First, it is that it is hard enough for miners to mine but it is trivial for the validators to verify. Also, the hash results are uniformly distributed for easy control at the time of finding a new block. In Ethereum, new blocks are created every 12 seconds, instead of the 10 minutes of the Bitcoin network. The difficulty is dynamically adjusted to ensure the much fast block creation speed.
Overall, the Ethash algorithm in Ethereum involves two stages. The first stage is to generate a dataset of a Directed Acyclic Graph, referenced as DAG. This is usually calculated for each epoch—or every 30,000 blocks. The second stage is to repeatedly hash the dataset, the proposed header, and a random nonce using Keccak-256, until the resulting hash value meets the difficulty target. DAG generation is composed of the following three steps:
- A seed is created from the blockchain by hashing the headers of each block together with the current epoch using Keccak-256.
- Once the seed is found, a 16 MB pseudorandom cache is generated from the seed using Keccak-256.
- A DAG is generated using the Fowler–Noll–Vo (FNV) hash function. It consists of many chunks of 64-byte elements; each of them depends on a part of the cache.
Each Ethereum client may implement DAG differently. It is typically generated in advance and cached for performance improvement. Geth implements automatic DAG generation and maintains two DAGS at a time for smooth epoch transitions.
Ethereum transaction and block structure
Due to blockchain architecture and mining difference in Ethereum implementations, Ethereum defines quite different transaction and block structures in the Ethereum protocol. Ethereum DApps need to follow Ethereum protocol rules to format and submit transactions to the network. Invalid transactions will be rejected by the network.
The following are the essential data structures in Ethereum, taken from Ethereum’s GitHub code:
Ethereum block structure:
An Ethereum block structure looks similar to the screenshot:
Block header structure:
The following screenshot shows the Ethereum block header structure:
Instead of a Merkle hash root in Bitcoin, Ethereum uses a modified Merkle Patricia Trie notation for the root hash in the block header. More specifically, stateRoot in the preceding structure is the Merkle Patricia Trie of account state, transactionRoot is the Merkle Patricia Trie of all transactions in the block, and receiptsRoot is the Merkle Patricia Trie of all transaction receipts.
Another difference in Ethereum is, when creating new blocks, Ethereum adds the new block to the heaviest branch of the block tree, instead of to the longest chain as we saw in Bitcoin. The header attribute, difficulty, is used by the miner to determine which branch is heavier.
Transaction structure in Ethereum:
Let’s have a look at the following table:
The preceding table shows the general data structure of Ethereum transactions. The following table shows the data structure of transaction receipts:
A transaction receipt is generated once the blockchain accepts the submitted transaction. The preceding shows the data structure of transaction receipts.
Transaction validation and block verification
Ethereum maintains all accounts in the underlying world state, which makes the state transition much easier. When the transaction is submitted to the Ethereum blockchain, miners will perform an intrinsic validity check on the transaction. It will be validated according to the consensus rules and heuristic limits of the local node, such as price and size. If the transaction size is over 32KB, it will be rejected for preventing DoS attacks. The transaction needs to be well-formed with Recursive Length Prefix (RLP) encoding. They will be checked to ensure that the transaction is properly signed by the sender and has the proper nonce ordering and to make sure the sender should have enough funds to cover the total transition costs; in other words, the amounts being transferred plus the gas cost for the smart contract execution.
Miners add transactions to the transaction pool once they pass the intrinsic validity check. Every 12 seconds, miners take transactions out of the transaction pool and start to propose the new block. They determine ommer or uncle blocks, and the total gas used in the block. They will create the block structure as defined earlier and start mining. Once the nonce is found to meet the ethash target, the new block with newfound nonce is broadcasted to the network for all network nodes to verify and add to their local copy of blockchain.
Next Article
In our next article (List of Tools and Technologies in Ethereum Ecosystem), we review tools and technologies that are used in the Ethereum ecosystem.
This article is written in collaboration with Brian Wu who is a leading author of “Learn Ethereum: Build your own decentralized applications with Ethereum and smart contracts” book. He has written 7 books on blockchain development.
Resources
Free Webinars on Blockchain
Here is the list of our free webinars that are highly recommended:
- Hyperledger Fabric for system admin versus developers
- How to harness blockchain for environmental and corporate sustainability
- Review of Initial Coin Offering, Security Token Offering and asset tokenization use cases and best practices
- Hyperledger Fabric Deployment on Cloud
- Hyperledger Fabric for entrepreneurship- 21 blockchain business use cases
Free Courses
Here is the list of our 10 free self-paced courses that are highly recommended:
- IT Career Roadmap Explained
- Web Design with Bootstrap
- User Experience Best Practices
- Intro to Search Engine Optimization
- Web Design with WordPress
- Introduction to Drupal CMS
- Intro to Joomla CMS
- Intro to Cybersecurity
- Introduction to Cloud Technology
- Recorded Live Webinars and Classes
Self-Paced Blockchain Courses
If you like to learn more about Hyperledger Fabric, Hyperledger Sawtooth, Ethereum or Corda, taking the following self-paced classes is highly recommended:
- Intro to Blockchain Technology
- Blockchain Management in Hyperledger for System Admins
- Hyperledger Fabric for Developers
- Intro to Blockchain Cybersecurity
- Learn Solidity Programming by Examples
- Introduction to Ethereum Blockchain Development
- Learn Blockchain Dev with Corda R3
- Intro to Hyperledger Sawtooth for System Admins
Live Blockchain Courses
If you want to master Hyperledger Fabric, Ethereum or Corda, taking the following live classes is highly recommended:
- Live and self-paced blockchain development with Ethereum
- Live and self-paced blockchain development with Hyperledger Fabric
- Live and self-paced blockchain development with Corda
- Immersive Blockchain Bootcamp with live and self-paced courses
- Live crash course for learning Ethereum with Solidity
- Live crash course for building DApps with Hyperledger Fabric
- Live crash course for building DApps with Corda
- Live full-stack blockchain development in Hyperledger and Ethereum
Articles and Tutorials on Blockchain Technology
If you like to learn more about blockchain technology and how it works, reading the following articles is highly recommended:
- History and Evolution of Blockchain Technology from Bitcoin
- Overview of Blockchain evolution and phases from Ethereum to Hyperledger
- Comprehensive overview and analysis of blockchain use cases in many industries
- Blockchain Crowdfunding Security Token or Initial Coin Offerings
- A beginner Guide to Blockchain Technology
- How Decentralized Peer-To-Peer Network Works
- How blocks are added to the blockchain
- How Public and Private Keys of Cryptography Work
- What Is A Cryptographic Hash Function
- How Digital Signature Works In Blockchain
- The role and types of consensus mechanism in blockchain
- How Proof-of-Work Consensus Works in Blockchain
- How Proof of Stake Consensus works in Blockchain
Articles and Tutorials on Ethereum and Solidity
If you like to learn more about blockchain development in Ethereum with Solidity, reading the following articles and tutorials is highly recommended:
- Review of Architecture and Components of Ethereum
- Comprehensive Blockchain Ethereum Developer Guide from Beginner to Advance Level
- How to Write Ethereum Smart Contracts with Solidity in 1 hour
- Review of Architecture and Components of Ethereum
- How Ethereum Manages Accounts
- How Ethereum Manages Transactions
- How Smart Contracts Work in Ethereum
- How Ether and Gas Work in Ethereum
- How Ethereum Virtual Machine works
- How address and wallet work in Ethereum
- How mining works in Ethereum
- List of Tools and Technologies in Ethereum Ecosystem
- Review of challenges in distributed systems
- Review of Cap Theorem in Distributed Systems
- Horizontal Scaling versus Vertical Scaling in Distributed Systems
- How to Scale up Ethereum Blockchain Applications
- Review of scaling solutions for Ethereum
- How to Manage Ethereum State Channel with Raiden
- How Plasma Chains Work in Ethereum
- How Sharding and Gasper work in Ethereum
- How Proof-of-Stack Consensus Works in Ethereum
- A roadmap for Implementing Ethereum 2.0
- How to work with Decentralized Data and Content Storage in Ethereum
- How Decentralized Messaging with Whisper Works in Ethereum
- Review of Infura for Ethereum Development
- Review of Infura Ethereum API
- How to Use Remix with Infura for Ethereum Development
- How Ethereum Client API Works
- How Ethereum IPFS Storage Works
- How to Install and Start Ethereum IPFS Storage
- How to Run Ethereum IPFS Storage
- How to Work with Ethereum Swarm Storage
- How to Install Ethereum Swarm Storage
- How to Handle Ethereum Messages with Whisper
- Review of Popular Ethereum Smart Contract Libraries
- Review of Private and Permissioned blockchain
- How to Set up a Local Private Ethereum Blockchain
- How to Run Geth on a Local Private Ethereum Blockchain
- How to Build a Local Private Ethereum Blockchain with Mining
- How to Run Geth on a Local Private Ethereum Blockchain with Mining
- How to Create an Account on a Local Private Ethereum Blockchain
- How to Use Ethereum Optional Flags with New Chains
- Review of Ethereum Options for Development and Testing
- Review of Ethereum Developer Chain Options
- Review of Ethereum API and Console Options
- Review of Ethereum Networking Options
- Review of Ethereum Transaction Pool Options
Articles and Tutorials on Hyperledger Family
If you like to learn more about blockchain development with Hyperledger, reading the following articles and tutorials is highly recommended:
- Introduction to Hyperledger Architecture, Projects, Tools and Libraries
- Complete Review of Hyperledger Fabric Architecture and Components
- Hyperledger Fabric for System Administers versus Developers
- How to use Prometheus and Grafana to monitor Hyperledger Fabric
- Blockchain Developer Guide- How to Install Hyperledger Fabric on AWS
- Blockchain Developer Guide- How to Install and work with Hyperledger Sawtooth
- Blockchain Developer Guide- How to Install Hyperledger Burrow on AWS
- Blockchain Developer Guide- How to Install Hyperledger Iroha on AWS
- Blockchain Developer Guide- How to Install Hyperledger Indy and Indy CLI on AWS
- Blockchain Developer Guide- How to Install Hyperledger Seth and Docker on AWS
- Blockchain Developer Guide- How to Configure Hyperledger Sawtooth Validator and REST API on AWS
- Blockchain Developer Guide- How to Build Transaction Processor as a Service and Python Egg for Hyperledger Sawtooth
- Blockchain Developer Guide- How to Deploy Ethereum Smart Contracts with Hyperledger Burrow
- Blockchain Developer Guide- How to Create Cryptocurrency Using Hyperledger Iroha CLI
- Blockchain Developer Guide- How to Explore Hyperledger Indy Command Line Interface
- Blockchain Developer Guide- Comprehensive Blockchain Hyperledger Developer Guide from Beginner to Advance Level
- Introduction to Hyperledger Sawtooth Blockchain Development
Articles and Tutorials on R3 Corda
If you like to learn more about blockchain development on Corda , reading the following articles and tutorials is highly recommended:
Articles and Tutorials on Other Blockchain Platforms
If you like to learn more about blockchain development in other platforms, reading the following articles and tutorials is highly recommended: