How Does Halving Work: The Code Behind the Hype

Published at: May 7, 2020

How does Bitcoin’s block halving work on an engineering level? We explain with help from Andreas Antonopoulos.

In a recent video, Antonopoulos explained the Bitcoin Core code that controls the halving of the Bitcoin (BTC) block reward in detail.

Bitcoin halving code. Source: Bitcoin Core Software.

Line by line explanation

Every time a Bitcoin block is evaluated or a new block is mined, the function GetBlockSubsidy gets called. Its purpose is to calculate the appropriate size of the block reward. Line 1240 evaluates the halving cycle and divides the current block height by 210,000; the interval between the halving. At the time of this writing, the block height is 629369, if we divide it by 210,000, we get 2.99. Since the variable that stores this value is an integer type, the decimals get discarded. Using this information, the code “knows” that we have had two halvings. This is why the next halving will happen at block 630000.

Satoshi stands corrected

Lines 1242 and 1243 correct a mistake that Satoshi made in the original code. This error originally kept on halving the block reward past 64 halvings; the total number of halvings embedded in the Bitcoin protocol.

Line 1245 multiplies the original block reward of 50 by a constant COIN, which is equal to 100,000,000 Satoshis. Ironically, there are no Bitcoins in the Bitcoin code, only Satoshis.

Line 1247 calculates the appropriate block reward for the current block height. It uses a bitwise operation which is more efficient than regular math operations. The block reward  that was calculated in Line 1245 is then adjusted according to the present block reward. Currently, this would look like this:

50 * 100,000.000 / 22= 1,250,000,000 Satoshis or 12.5 Bitcoins.

Finally, Line 1248 returns the appropriate block reward when called by another function or procedure in the Bitcoin code.

When the halving finally arrives in about 4 days, or 631 blocks, we can all take a sigh of relief and appreciate the beauty of Bitcoin’s code.

Tags
Related Posts
Motions Fly High as Craig Wright Set to Face Kleiman Estate in Court
The crypto news headlines at the start of May with regard to Kleiman v. Wright were mostly variations on the theme of Craig Wright’s Satoshi case going to trial. The two parties appear well entrenched in their positions, and lawyers for both sides have said they expect the trial to begin as scheduled on July 6, 2020, in Florida. Does this mean there will be no settlement? “This is not like an ordinary commercial dispute where the parties can agree they’ve got a 50-50 chance of winning on an ambiguous contract provision, so they just split the difference,” Jason Gottlieb, …
Bitcoin / May 15, 2020
Crypto Investment Advisory Firm Ranks Halving Scenarios
On May 4, CoinShares Research put out its ranking of the likelihood of various halving scenarios as well as their potential impact on the industry. Bitcoin (BTC) halving has captivated the imagination of the crypto industry and there is no lack of outlandish predictions forecasting anything from the death spiral that will destroy the Bitcoin network, to the one predicting its parabolic rise. Earlier today, this subject was also discussed in another episode of Cointelegraph Talks. In the latest post, CoinShare’s head of research, Christopher Bendiksen, analyzed five of the most popular scenarios and concluded by proposing his own. Source: …
Bitcoin / May 5, 2020
Charles Hoskinson: Blockstream Founder Adam Back 'Checks All The Boxes' as Satoshi
In a recent Cointelgraph interview, Ethereum co-founder and Cardano founder Charles Hoskinon said that he believes that Adam Back “checks all the boxes” as a Satoshi Nakamoto candidate. The puzzle of Satoshi’s true identity never seems to get old. Although Hoskinson admits that he does not have any hard evidence connecting the Blockstream’s founder to the pseudonymous Bitcoin creator, he did make a mental profile of Satoshi — Back seemingly has a perfect fit. Hoskinson believes that Satoshi was somebody, who lived either in Western Europe of the coastal United States, was comfortable with British English, and had a background …
Bitcoin / May 26, 2020
Bitcoin On-Chain Data Suggests Miners Expect Halving to Pump BTC Price
As the coronavirus pandemic continues to unfold and new signs of lockdowns beginning to be slowly lifted in Europe, all eyes in the crypto community are back on the Bitcoin (BTC) halving. The event is only 10 days away, and Bitcoin’s price seems to be acting accordingly, having surged an incredible 23% to a monthly high above $9,400 earlier this week. A widely celebrated event in the cryptocurrency industry, the halving is part of the Bitcoin monetary policy, in which every four years, the Bitcoin mining reward is cut in half. This means that on May 11, 6.25 BTC will …
Bitcoin / May 1, 2020
Three reasons why PlanB’s stock-to-flow model is not reliable
In the last couple of years, the stock-to-flow model proposed by PlanB has become very famous. A quantitative study published on the site planbtc.com shows the model and the prediction that Bitcoin (BTC) could reach the capitalization of $100 trillion. Obviously, the crypto industry, including myself, was fascinated by the logic of the model and even more so by the idea that it could reach and exceed $100,000 as early as 2021. In fact, the stock-to-flow model assumes that there is a relationship between the amount of a precious metal that is mined each year (flow) and the amount already …
Bitcoin / Jan. 2, 2022