Ethereum Mining and Ethash

Source: Internet
Author: User
Tags json
Introduction to Mining

The term mining is derived from the analogy between cryptocurrency and gold. Gold or precious metals are rare, and electronic tokens are also the only way to increase the total is to dig mine. So is Ethereum, and the only way to release it is to dig mine. But unlike other examples, mining is also a way to protect the network by creating, validating, distributing, and propagating chunks in the blockchain.

Dig aether = Protect Network = Verify the calculation of what is mining.

Ethereum, like all blockchain technologies, uses an excitation-driven safety model. Consensus is based on selecting blocks with the highest total difficulty. Miners create chunks, others detect effectiveness. Blocks are only valid if they contain a certain amount of difficulty, as well as other eligibility criteria. Please note that the Ethereum Serenity Milestone may be superseded (refer to the proof of interest model).

The Ethereum blockchain is similar in many ways to the Bitcoin blockchain, but it is also somewhat different. In the blockchain architecture, the main difference between Ethereum and bitcoin is that, unlike Bitcoin, the Ethereum block contains not only the trading list but also the recent state (the root hash code of the Merkle Patricia structure is more accurate in the state) besides, the other two values, the number of chunks and the difficulty, are also stored in chunks.

The work proof algorithm used is called Ethash (an improved version of the Dagger-hashimoto algorithm), including finding the random number input of the algorithm to make the result less than a specific difficulty threshold. The significance of the proof-of-work algorithm is that to find such a random number, there is no better strategy than enumerating the possibilities, and the validation of the solution is trivial and inexpensive. Since the output is evenly distributed (the result of the application of the hash table function), we can guarantee that, on average, the time required to find such a random number depends on the difficulty threshold. This makes it possible to control the time to find new chunks only by manipulating the difficulty.

As described in the agreement, the difficulty is dynamically adjusted in such a way that the entire network generates a chunk every 15 seconds. We say that the network uses 15 seconds of chunk time to produce a blockchain. This "heartbeat" basically emphasizes system state synchronization, ensuring that a fork is not maintained (allowing double spend) or rewritten by a malicious molecule, unless the attacker has more than half of the network's mining capacity (known as the 51% attack).

Any node that participates in the network may be miners, and the expected mining benefits are proportional to their (relative) digging capacity, such as the number of random numbers per second that are standardized by the network's total dispersion.

The Ethash workload proves to be hard to solve, which makes it resistant to Asics. The memory difficulty is realized by the work proof algorithm, and it needs to choose the subset of fixed resources which depend on the random number and the chunk title. This resource (billions of-byte-size data) is called a dag. Each 3,000-block Dag is completely different, and the 125-hour window called the epoch (about 5.2 days) takes a little time to generate. Since the DAG is determined only by the block height, it can be generated beforehand, and if not generated beforehand, the client needs to wait until the process most later produces the block. If the client does not pre-build and cache the DAG in advance, the network may experience a large chunk delay at each epoch transition. Note It is not necessary to generate a DAG to verify proof of effort, which can be verified in low CPU and small memory state.

In special cases, when a node is created from scratch, mining is only started when the DAG is created for the existing epoch. Mining Incentives

The successful work of the winning block proves that the miner obtains the static block award for the "winning" block, which contains the gas cost of 5.0 (5) of the spent in the Ethereum block-a certain amount of ethereum, depending on the current gas price uncles block bonus, in the form of an additional 1/32 per uncles block

The gas that is executed by the winning miners in the block that is consumed by all exchanges is paid by the sender of each transaction. The gas costs incurred have been attributed to the miner's account as part of the consensus agreement. As time changes, this makes the data chunk award smaller.

Uncles blocks are stable chunks, for example, and parent chunks that contain previous chunks (up to 6 chunks). Effective uncles blocks are rewarded with the impact of medium and network lag on mining incentives, thus increasing security (this is called the Ghost Protocol). The uncles block receives 7/8 of the Data Block Award (=4.375 ether) by the uncles block contained in the block that the miners formed by the successful workload. A maximum of 2 uncles blocks per chunk are allowed. Reddit on the uncles block ELI5 explain the uncles block of the sub-forum

The success of mining depends on the difficulty of the block set. Block difficulty dynamically adjusts each chunk to specify the network hash capability to create 12-second chunk time. The opportunity to find chunks is therefore generated by the hash rate associated with the difficulty. Ethash DAG

Ethash uses a dag (directed acyclic graph) for the work Proof algorithm, which is generated for each epoch, for example, every 3,000 chunks (125 hours, about 5.2 days). Dags take a long time to build. If the client only builds it as needed, each epoch transition waits a long time before the first chunk of the new epoch is found. However, the DAG depends only on the number of blocks, so it can be pre-calculated to avoid a long wait time for each epoch transition. Geth and Ethminer perform automated dag generation, maintaining 2 dags at a time to smooth the epoch transition. When mining is being manipulated from the console, automatic dag generation is turned on and off. If Geth is started with the-mine option, it will also be turned on by default. Note The client shares the DAG resource, and if you run multiple instances of any client, make sure that the automatic DAG build is opened only in one instance.

To generate a DAG for any epoch:

Geth Makedag <block number> <outputdir>

Instance Geth makedag 360000 ~/.ethash. Note that Ethash uses ~/.ethash (mac/linux) or ~/appdata/ethash (Windows) for dags so that it can be shared between different client implementations and multiple running instances. algorithm

Our algorithm, Ethash (formerly known as Dagger-hashimoto), is based on a large, instantaneous, arbitrarily generated data set that forms a DAG (Dagger-part), attempting to resolve it with a specific constraint, partially determined by the chunk header hash.

It is designed to hash fast verification times in an environment with only a slow CPU, but provides a lot of acceleration for mining when a large amount of high-bandwidth memory is provided. Large memory requirements mean that large miners get relatively little extra-linear benefits. High bandwidth requirements mean that the acceleration from the heap in many overspeed processing units, sharing the same memory, gives little benefit in each individual unit (translator Note: Reduce the role of the miner by blocking the use of the dedicated chip to share memory).

The benefits of no node validation are thus hampering the centrality, which is important in mining.

The communication between the external mining application and the Ethereum work rules and the reporting daemon occurs through the JSON-RPC API. Provides two RPC functions, Eth_getwork and Eth_submitwork.

These are officially recorded under the miners entry in the JSON-RPC API Wikipedia article.

In order to dig, you need a fully synchronized Ethereum client and at least one Ethereum account to mine. This account is used to send mining rewards, often referred to as currency bases or garthage. See the "Create an Account" section of this description to learn how to create an account.

Warning: Before you start digging, make sure that the blockchain is fully synchronized with the main chain, otherwise you will not be able to mine on the main chain.


Design target resistance mining machine (ASIC resistance). The advantages of using specially optimized chips should be as small as possible, so small that even mining with ordinary CPUs can generate revenue. The light client can be verified. The light client should be able to verify the authenticity of each block. The goal is to run a C-implemented verification algorithm on a normal desktop computer, with a validation time of less than 0.01 seconds, less than 0.1 seconds with Python or JavaScript, and no more than 1MB of memory. Mining Algorithm

The mining algorithm of the etheric currency (ether) is called Ethash, aka Dashimoto (Dagger-hashimoto), which is a variant of Hashimoto algorithm combined with Dagger. It is characterized by the efficiency of mining is basically independent of the CPU, but is positively correlated with memory size and memory bandwidth. The requirement for memory size and bandwidth means that miners ' chips, which are deployed on a large scale through shared memory, do not have linear or ultra-linear (super-linear) growth in mining efficiency.

Let's take a look at the basic flow of Dashimoto: for each block, a seed is calculated first. The seed calculation relies only on the information of the current block, such as block number and block headers. Uses a seed to produce a pseudo-random data set of 32MB, called the cache. The light client needs to save the cache. The cache is regenerated into a 1GB-sized dataset called the DAG. Each element in the dataset relies on only a few elements of the cache, in other words, a cache can be used to quickly calculate the element in the specified position in the DAG. The full mining-able client needs to save the DAG. Mining can be summarized as the process of randomly selecting elements from a dag and then hashing them. The same is true of the validation process, except that the element is not selected from the DAG, but rather the element of the specified location is computed based on the cache, and then the hash result of this element collection is less than a certain value. Because the cache is small and the DAG element at the specified location is easy to calculate, the verification process requires only the normal CPU and normal memory to complete. The cache and DAG are updated once for each cycle, and the length of a cycle is 1000 blocks. This means that the 1000 blocks produce the same cache as the DAG, so the main job of mining is to read the data from the DAG instead of updating the cache and DAG. The size of the DAG grows linearly over time, starting from 1GB, which increases annually about 7gb– so that to December 2015 is approximately 8GB, to December 2016 about 15GB.

Note: The figures in the above steps have been adjusted with the development of the progress, the exact value please refer to the source code. Mining Software

We expect to have at least two mining methods on-line: Using the Mist Client (the official client implementation, based on the Go language) for CPU mining. GPU mining is done through the combination of the Ethereum daemon (ETH daemon) and the Sgminer. The data communication before the daemon and Sgminer can be done through the JSON-RPC API. There are currently two APIs associated with mining: Eth_getwork and Eth_submitwork.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.