Categories
Economics Technology

Difficulty Adjustment

Bitcoin protocol has a process called Difficulty Adjustment which is the way to change the level of difficulty in discovering new bitcoin blocks through mining. As I’ve written in previous article, each block on the bitcoin blockchain is produced or mined in around 10 minutes. The time it takes to mine new block is the result of the difficulty adjustment considering the time it took to mine previous blocks. If the new blocks are mined in less than 10 minutes, the difficulty is increased and if takes more than 10 minutes to mine a block, the difficulty is decreased.

This algorithm was hard-coded into the bitcoin source code from the beginning which constantly readjusts the difficulty of the mining process. This mining difficulty changes every 2,016 blocks or approximately 2 weeks. The next difficulty depends on how efficient miners were in the preceding cycle. This adjustment is also affected by the number of new miners that have joined Bitcoin network because it increases the hash rate or the amount of computing power deployed to mine BTC. So if there are more miners in the network, the difficulty of the problem is increased.

What is Bitcoin mining?

Mining is the process of validating the information in the block by searching for the cryptographic solution that matches certain criteria. When the correct solution is found, a reward in the form of the native currency, bitcoin (BTC) and fees for the work done is provided as block subsidy to the miner who found the solution first. Over time the block subsidy is reduced and this keeps on continuing until there are total of 21 million bitcoins in circulation. Once, the 21 million bitcoins are mined, miners are rewarded through the fees. While the block subsidy is the reward for mining, mining process is the process of maintaining the integrity of the blockchain.

During the earlier days, one could mine bitcoin from the laptop with ordinary CPUs. But it has been very sophisticated over several years. Miners today use complex machines with GPUs and ASICs (Application Specific Integrate Circuit) chip to speed up mining operations. For perspective, the difficulty level at the early 2015 would make ordinary CPUs so difficult to mine a block that it would take several hundred thousand years on average to mine a block. The ASICs  are capable of generating over 1 Quintillion random codes in a second which is an exponentially higher number of guesses than any regular laptop with CPU.

The bitcoin difficulty adjustment algorithm is programmed to make the bitcoin protocol stable by maintaining approximately 10 minutes duration for producing new blocks. All the miners in the network will work towards solving the problem but only single miner will be successful in finding the new block. Once the new block has been found, the miner then propose that block to be added to the blockchain. Whenever there’s an influx of miners, it ramps up the difficulty and if there is a drop in the number of miners finding the solution, the algorithm reduces the mining difficulty to make it easier for the remaining miners to discover new block.

The difficulty is actually altered by adding or reducing the zeros at the front of the target hash. This target hash is the specific hash that all the miners are trying to beat. The miner who generates a random code that has an equal or higher number of zeros at the front compared to the target hash, is selected as the winner and the block is created and added to the blockchain. This algorithm was set to prevent the creation of blocks at faster rate as miners could increase their machine and its specs to do so. One of the most important characteristics of Bitcoin protocol is its steady and predictable rate of inflation compared to other fiat currencies. The mining difficulty adjustment algorithm and its maximum amount of 21 million is what makes this protocol interesting and somewhat predictable which I’ve written in my previous article, Bitcoin Halving and Block subsidy.

The frequency of this difficulty adjustment is roughly around two weeks, which is determined by the number of blocks that is set to 2,016. This is the reason each 2,016 block interval is called the Difficulty Epoch in bitcoin. Bitcoin network determines whether the activities of miners for the last 2,016 blocks have reduced or increased the time to mine a new block. If it’s taking below 10 minutes, the mining difficulty will be increased and decreased if it’s taking above 10 minutes.

Difficulty Adjustment Algorithm

The actual calculation of the difficulty adjustment in an algorithm is made by comparing the standard time it should take to find 2,016 blocks of transactions to the time it took to find the last 2,016 blocks. The accepted block time is 10 minutes so the expected time for mining 2,016 blocks is 20,160 minutes. The network calculates the total time it takes to mine the previous 2,016 blocks. The ratio of the 20,160 minutes to the time it took to scale the previous difficulty epoch is then multiplied by the most recent difficulty level. This calculation gives a result that will determine the required percentage change in the mining difficulty that will bring the block time to the desired 10 minutes. This 10 minutes block time is the goal of the protocol. The mining difficulty cannot be altered above or below four times of the current difficulty level. The upper limit for each difficulty epoch is +300% increase and the lower limit is -75% decrease. This is vital so that the abrupt changes in difficult adjustment can be avoided.

The formula for the calculation of difficulty adjustment is:

Difficulty = Difficulty Target / Current Target

Difficulty Target is the highest possible target to be reached with a block hash. Current Target is the hexadecimal difficulty derived from 256-bit number in a block header. Difficulty is the approximate number of hashes required to mine a single block. The current difficulty, as of 7th October 2023 is 57.32 Trillion.

One of the interesting facts about bitcoin mining is, even if all the computing powers of the world or every energy and resources were used in bitcoin mining, the difficulty adjustment would readjust the difficulty and keep the block time around 10 minutes on average. This is why bitcoin protocol has the unique supply schedule and is predictable such that the last bitcoin/satoshi will be mined in around the year 2140.

Thank you for reading. See you on next one.

2 replies on “Difficulty Adjustment”

Just wish to say your article is as astounding. The clearness in your publish
is just cool and that i could think you’re a professional in this subject.

Well along with your permission let me to grab your RSS feed to stay updated with impending
post. Thanks a million and please carry on the rewarding work.

Leave a Reply

Your email address will not be published. Required fields are marked *