{"id":279,"date":"2023-10-07T08:20:20","date_gmt":"2023-10-06T23:20:20","guid":{"rendered":"https:\/\/www.sumitbilashjoshi.com\/?p=279"},"modified":"2023-10-07T08:26:30","modified_gmt":"2023-10-06T23:26:30","slug":"difficulty-adjustment","status":"publish","type":"post","link":"https:\/\/www.sumitbilashjoshi.com\/?p=279","title":{"rendered":"Difficulty Adjustment"},"content":{"rendered":"\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">Bitcoin<\/mark> protocol has a process called <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">Difficulty Adjustment<\/mark> which is the way to change the level of difficulty in discovering new bitcoin blocks through mining. As I\u2019ve written in previous article, each block on the bitcoin blockchain is produced or mined in around <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">10 minutes<\/mark>. 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 <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">less than 10 minutes<\/mark>, the difficulty is increased and if takes <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">more than 10 minutes<\/mark> to mine a block, the difficulty is decreased. <\/p>\n\n\n\n<!--more-->\n\n\n\n<p>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 <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">2,016<\/mark> 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.<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">What is Bitcoin mining?<\/mark><\/p>\n\n\n\n<p>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 <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">21 million<\/mark> 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.<\/p>\n\n\n\n<p>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 <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">GPUs<\/mark> and <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">ASICs<\/mark> (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\u00a0 are capable of generating over <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">1 Quintillion<\/mark> random codes in a second which is an exponentially higher number of guesses than any regular laptop with CPU.<\/p>\n\n\n\n<p>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\u2019s 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.<\/p>\n\n\n\n<p>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\u2019ve written in my previous article, <a href=\"https:\/\/www.sumitbilashjoshi.com\/?p=246\" target=\"_blank\" rel=\"noopener\" title=\"\">Bitcoin Halving and Block subsidy.<\/a><\/p>\n\n\n\n<p>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 <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">Difficulty Epoch<\/mark> 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\u2019s taking below 10 minutes, the mining difficulty will be increased and decreased if it\u2019s taking above 10 minutes.<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">Difficulty Adjustment Algorithm<\/mark><\/p>\n\n\n\n<p>The actual calculation of the difficulty adjustment in an algorithm is made by comparing the standard time it should take to find <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">2,016<\/mark> 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 <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">2,016 blocks<\/mark> is <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">20,160 minutes<\/mark>. 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 <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">+300%<\/mark> increase and the lower limit is <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">-75%<\/mark> decrease. This is vital so that the abrupt changes in difficult adjustment can be avoided.<\/p>\n\n\n\n<p>The formula for the calculation of difficulty adjustment is:<\/p>\n\n\n\n<p><code>Difficulty = Difficulty Target \/ Current Target<\/code><\/p>\n\n\n\n<p>Difficulty Target is the highest possible target to be reached with a block hash. Current Target is the hexadecimal difficulty derived from <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">256-bit<\/mark> number in a block header. Difficulty is the approximate number of hashes required to mine a single block. The current difficulty, as of <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">7th October 2023<\/mark> is <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">57.32 Trillion<\/mark>.<\/p>\n\n\n\n<p>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 <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">2140<\/mark>.<\/p>\n\n\n\n<p>Thank you for reading. See you on next one.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u2019ve 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":282,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_themeisle_gutenberg_block_has_review":false,"footnotes":""},"categories":[5,17],"tags":[8,10,18],"class_list":["post-279","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-economics","category-technology","tag-bitcoin","tag-economics","tag-technology"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.sumitbilashjoshi.com\/index.php?rest_route=\/wp\/v2\/posts\/279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sumitbilashjoshi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sumitbilashjoshi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sumitbilashjoshi.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sumitbilashjoshi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=279"}],"version-history":[{"count":1,"href":"https:\/\/www.sumitbilashjoshi.com\/index.php?rest_route=\/wp\/v2\/posts\/279\/revisions"}],"predecessor-version":[{"id":280,"href":"https:\/\/www.sumitbilashjoshi.com\/index.php?rest_route=\/wp\/v2\/posts\/279\/revisions\/280"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sumitbilashjoshi.com\/index.php?rest_route=\/wp\/v2\/media\/282"}],"wp:attachment":[{"href":"https:\/\/www.sumitbilashjoshi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sumitbilashjoshi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sumitbilashjoshi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}