Did you know that mining a bitcoin is not always the same complicated? A mobile phone (one of the cheapest) could mine bitcoins quickly in 2009, but today it requires huge industrial warehouses full of thousands of specialized devices in this task, generating millions of millions of operations per second to mine the same amount of bitcoins. Find out why this is due to knowing one of the most important aspects of mining, the “difficulty”.

Bitcoin has a dynamic mining complexity / difficulty. what does it mean exactly? In essence it means that the difficulty of mining a block in Bitcoin is not always the same. Sometimes it goes up, sometimes it goes down (although in the long term it currently tends to rise).

In the next chapter of Bit2Me Academy you will delve into one of the most important aspects of cryptocurrencies like Bitcoin. Entering the guts is not always easy but, as always, we will explain this concept in a simple way.

The term "difficulty" is used as a unit of measure in the process cryptocurrency mining, Referring to like difficult is to find the hash of the block.

As we have already explained in the article dedicated to how cryptocurrencies are mined, the hash must meet the characteristics sought in that  blockchain. Each block within the network is generated at a rate determined by the blockchain protocol. And this rhythm must remain, to the extent, constantly.

Here comes one of the most important questions: Why is the complexity of mining variable?

Well, let's take Bitcoin as an example. In Bitcoin it has been stipulated in your code that one block should be mined every 10 minutes on average. To mine a block, the nuncio that within the mining operation with a hash that meets the desired pattern. A person who has a lot of computing power (for example thousands of ASIC, or discovering a new mechanism to do the operation more quickly) you will be able to find the nonce very quickly, breaking the average of the 10 minutes you are looking for. That's where Bitcoin added one of its most important components: the resetting mining difficulty.

Without this readjustment, that miner would mine all the blocks in a short time, breaking the bitcoin emission curve pre-established in the economic model that underlies the Bitcoin protocol. That is, in a short time all the bitcoins would be mined. To avoid this, the readjustment of mining comes into action, increasing the complexity of the desired mathematical problem, and stabilizing the time of each block again to 10 minutes (on average).

How often is the difficulty of mining in Bitcoin reset?

The mining difficulty setting depends on the programming and operating protocols of each blockchain and cryptocurrency. As we have already explained, the mining difficulty in Bitcoin should allow miners to solve and generate a new block approximately every 10 minutes. And when this condition is not met, the degree of difficulty is adjusted.

This readjustment occurs automatically every 2.016 blocks (approximately every two weeks). That is, in each of the nodes From the bitcoin network there is already a piece of code in its source code that has been prepared for this. Therefore, every time 2.016 mined blocks are reached, all nodes will recalculate resulting in a new level of proof of work (PoW) difficulty.

How is Bitcoin mining difficulty determined?

First of all, it is important to note that the mining difficulty is totally independent of the number of transactions or the value of the transactions. However, it does correlate with the hash power of the network, and therefore, with the objective and the mining time.

The formula for calculating the difficulty is as follows:

difficulty = difficulty_1_target / current_target

Where the target is a 256 bit number. difficulty_1_target it may be different for various ways of measuring difficulty. Traditionally, it represents a hash where the initial 32 bits are zero and the remainder is one (this is known as “group difficulty"Or"piff"). The Bitcoin protocol represents targets as a custom floating point type with limited precision. As a result, Bitcoin clients often approximate the difficulty based on this, which is known as “bdiff".

In turn, the Bitcoin network verifies the real time it took to mine the last 2.016 blocks in the chain and compares it to 20.160 minutes. This value is due to the fact that since each block had to be mined in a time of 10 minutes, the estimated time to mine the 2.016 blocks is 20.160 minutes. Then, using these data, the relationship between the real time interval and the estimated time interval is calculated. Making the adjustments corresponding to the difficulty according to the results obtained, whether it is required to increase or decrease it.

What does the difficulty translate to?

The difficulty in the blockchain plays a very important role. First, it regulates the manufacturing and activation of the cryptocurrency at a constant and predetermined rate. Secondly, it allows to maintain the production time of cryptocurrency blocks uniformly avoiding security problems and avoiding possible fraud. Thus, when the value of a cryptocurrency increases, miners are attracted to join the network, thereby increasing its hash power and the difficulty adjusts and increases. Therefore, the rate of coin issuance remains constant.

In addition to this, as there is a long time between each block, the miners provide greater security to the network, being able to verify that all the blocks meet the requirements.

Therefore, this feature is important as it ensures that blocks are generated at the predetermined speed by protocol and network security, remaining resilient even as more miners join the network and increase the hash power of the same.

How is the difficulty of mining in Bitcoin visually represented?

Oddly enough, the difficulty of mining can be represented visually. Also, depending on the blockchain it can be seen differently. However, let's take Bitcoin to show how it is represented. First of all, let's look at the image we leave below (or open the link), where the data of the block # 607557.

Look at the data bits y difficulty. The first of these is a shortened representation in hexadecimal of the maximum number that can be reached in the hash of the block. The second value is a decimal representation of the difficulty in reaching that goal.

Now if we take the bit value (1715dbd2) and transform it into a complete hexadecimal number we obtain the following:

bits = 0x00000000000000000015dbd20000000000000000000000000000000000000000

Now let's transform this value into decimal:

bits = 2093644940525638357414324633411056914147713045789409280

As you can see bits, it represents a very large decimal number and this is the maximum target number to be reached for the block hash. However, How do we verify that the hash of the block respects that?. Very simple, let's take the hash of the block and transform it from hexadecimal to decimal.

Block hash = 000000000000000000144758ca662636f4aa4089caaa776ea18cf53cbc8f5781

Transforming this result to a decimal base gives us the following number:

Block hash = 1942313447480713367840564387969267204147459722176321409

As you can see, the block hash number is less than the target that bits tells us. This means that the block is valid for the difficulty programmed by the Bitcoin protocol at that specific time.

As a curious fact we can mention that the value of the hash and the target are expressed in hexadecimal numbers. That is, in a set of numbers and letters, but that in the end is a number. While the difficulty is expressed in whole numbers, with which we are most familiar.

What is a high difficulty?

The maximum difficulty of the Bitcoin network can be expressed as: maximum_target / 1. And the number 1 is used since when Bitcoin was launched on the market the difficulty of the network was at that level. This value cannot be 0, as it would give an infinite result. Thus, the calculation of maximum_target / 1 will result in an enormously large number, approximately 2 ^ 224.

Is the difficulty just for the PoW consensus protocol?

The difficulty of mining in a cryptocurrency is applicable to different consensus protocols as PoW, PoS, DPoS is PoA. But It is the blockchains that use the Proof of Work (PoW) system, which use this data as an important point for their security and operation. In a PoW blockchain network, miners are asked to perform a cryptographic test whose difficulty increases as the power of the network increases.

This means that finding the right solution requires millions of hash operations per second to be performed across the entire network. The proof-of-work algorithm involves hashing the block header and generating a random number. For this, the cryptographic algorithm is generally used SHA-256, until you find a solution that fits a certain pattern.

This whole process causes more powerful computing equipment to be created, such as FPGA, CPU, But by the full GPU acceleration tech o ASIC to generate enough solutions and to verify transactions. Thus, the difficulty of the network is adjusted to ensure that the speed of block generation.

This whole process is not repeated in other protocols because their operation is different and they focus their ability to provide security in other less demanding mechanisms in energy and computational resources.

Is the difficulty of mining variable and adapting to the competition in Bitcoin?

Yes, the difficulty of mining in Bitcoin is variable and adapts to the competition that participates in the network. This mining difficulty is provided by an algorithm. This algorithm ensures that the difficulty has the ideal value, so that miners can produce a new block approximately every 10 minutes.

If we observe this in an extreme scenario, where the price of Bitcoin falls to extremely low values, mining would not be profitable at all. So many miners would abandon the network. But since the difficulty is adjustable according to the hash power of the network at a given moment, it would decrease and adjust automatically. Thus opening the doors to smaller miners, who could, at least for a time, extract bitcoins again as at the beginning: from a desktop or laptop computer.

How much do you know, cryptonuta?

Can the difficulty be easily manipulated by the miners?

FALSE!

Although there are ways to manipulate the difficulty of a blockchain, these attacks are not easy at all, especially in very large and decentralized networks. Hence the importance of decentralizing networks to maintain their security against all circumstances.

Why does mining difficulty sometimes increase and others decrease?

Mining difficulty works as a dynamic parameter that is constantly adjusted according to network conditions. Remember that the mining objective is to discover and generate a new block according to the programming of the network. So, the difficulty is adjusted by the same system. All this taking into account the hash power that the network has at a given moment.

Let's take the following example, if the Bitcoin network is generating new blocks in less time than the established 10 minutes, the same network will adjust the difficulty to a greater degree. That is, as the blocks are generated faster than desired, the mining difficulty will increase. On the contrary, if the network is generating new blocks in a time greater than 10 minutes, the difficulty of mining will be reduced, since the blocks would be generating more slowly.

Another very influential aspect in the degree of difficulty of the Bitcoin network is the cost of electricity and the value of Bitcoin in the market. This in relation to the fiduciary currency used to cover network operating expenses. Thus, the price of one kilowatt per hour in bitcoins is a very important aspect of the difficulty.

But when the price of a bitcoin is high, mining becomes profitable; on the contrary, if the price of Bitcoin is low, some miners will leave the network because their profits do not cover their operating expenses. Therefore, when mining is profitable, the greater the number of miners connected to the network and, therefore, greater hash power and a greater degree of difficulty. On the other hand, when mining is not profitable, the hash power decreases and with it, the difficulty.

How to know the current difficulty of a blockchain?

This is another point that is related to the technical part and protocols of the blockchain. For example, to find out the current difficulty of the Bitcoin network, you can visit a block explorer, for example Bit2Me Explorer, that shows you the difficulty of Bitcoin and its testing network Bitcoin Testnet, just by exploring the last generated block, you can see the last blocks here!, and see the details of the block you want.

Likewise, if you have a Bitcoin client, you can know the difficulty by entering the command OP_GETDIFFICULTY in the client of Bitcoin Core.