Hot search keywords

Hot search keywords

Deep Dive : The C++ Code That Will Halve Bitcoin Block Rewards

With six days left until the Bitcoin halving, the event has become one of the most talked-about topics in the crypto industry. Experts have been racing to weigh in on the effects the halving will have on the market, with many arguing over whether or not the halving has already been “priced in.”

The total supply of Bitcoin is capped at 21 million coins, which means that once the final coin is mined no new Bitcoins will enter its supply. Each new Bitcoin is created by mining, a process in which powerful hardware competes to solve complex math problems. Once a block is created, the miner that created it receives a certain amount of Bitcoin as a reward. 

When Bitcoin was created, the block reward was initially set to 50 BTC per block, meaning that each miner that discovers a valid block would earn 50 BTC. While this reward system was revolutionary, the 10-minute block time would mean that the entire supply would be mined in less than 8 years.

To solve this problem, the Bitcoin network contains a rather interesting piece of code that decreases the block rewards given to miners over time. That way, the nodes supporting the networks would be incentivized to continue mining and secure the network. 

Instead of instituting a complex mechanism, the creator of Bitcoin equipped it with a single line of code that instructed the network to halve the rewards going to miners every 210,000 blocks:

Consensus.nSubsidyHalvingInterval = 210,000
nHeight = current block height ( Will be 630,000 at the time of halving)
COIN = 100,000,000 ( Number of Satoshis in 1 Bitcoin)
nSubsidy = The subsidy for mining 1 block

 

The function we see in the code above is called “GetBlockSubsidy.” The purpose of the function is to calculate the subsidy, or reward, for mining 1 block of bitcoin. The variable “halvings” calculates the number of halving events by dividing the current block height by a constant value of 210,000 (which is stored on the constant Consensus.nSubsidyHalvingInterval).

Simply put, Bitcoin mining rewards are set to adjust every 210,000 blocks or every four years. On the day of halving, the variable “nHeight,” which represents the current block height, will be greater than 6,30,000. Therefore, the value of the halvings will be 3 (6,30,000/2,10,000). Since it’s set to integer type of value, which has no support for decimals, the halvings value will remain 3 until 8,40,000 blocks are mined.

The number of the halving will be then checked to determine if it is greater than 64, as Bitcoin is programmed to undergo a maximum of 64 halvings. Since next week’s halving will be its third one, the code will be able to proceed.

In line 1245, we see the original subsidy that is calculated for mining a block. The unit of “nSubsidy” is COIN, which is a constant representing 100,000,000 units—equivalent to the number of satoshis in a single bitcoin. 

After line 1245 executes the value of “nSubsidy” is 50 Bitcoins. Then, a right shift operator used ‘>>’  in line 1247 divides the number by 2. When the right shift operator (>>) is accompanied by a number N on its right side, it divides the original number by 2^N. 

In this case, the value N is equal to the number of halvings—3. The nSubsidy will then be divided by (2^3) 8. Hence nSubsidy will equal to 50/8 = 6.25 Bitcoins.

The Bitcoin code shows that the original block mining reward was set at 50 BTC. Anyone that managed to find a valid block from 2009 to 2012 would have received 50 BTC as a reward. Once the first halving occured in 2012, the subsidy for miners was cut in half—between 2012 and 2016, miners that found a valid Bitcoin block received 25 BTC as a reward. 

The second halving, which occurred in 2016, slashed the 25 BTC reward in half, with miners receiving 12.5 BTC for each block mined until now. Next week’s event is set to reduce that amount even further—starting from next week, miners will receive 6.25 BTC per block until 2024. 

Many expect that the sudden decrease in Bitcoin production will push its price upwards, as the previous two halvings both marked the beginning of a bull rush. The halving makes it more costly to mine Bitcoin which results in a slower increase in the supply of Bitcoin. This has historically increased the demand for Bitcoin, resulting in massive bull rallies following the halvings. 

Graph showing the halvings impact on Bitcoin’s price.  (Source: Medium)

While the data shows Bitcoin had been appreciating in the weeks preceding the halving, the biggest impact on its price happened about a year after the halving. With six more days to go, we are yet to see whether the anticipation of a block reward reduction will push Bitcoin over the $9,000 mark or whether we’ll have to wait until 2021 before we see a significant rally. 

Please sign in first