Can’t locate the Bitcoin supply formula in the code

4 replies 488 views
tony.satMember
Posts: 12 · Reputation: 203
#1Dec 17, 2024, 04:35 PM
Hey everyone, I came across this formula on Twitter and figured out how it controls Bitcoin's supply. I tried to dig through some source code, but I can't find the number 210000 mentioned anywhere. Also, where's the hex value for that number? (33450). Could anyone help me out and point me to where this formula is actually coded?
2 Reply Quote Share
just_gangMember
Posts: 44 · Reputation: 245
#2Dec 17, 2024, 07:23 PM
The total supply limit (which btw is only 20,999,999.9769 BTC) is not explicit, but implicit [1] from its block subsidy formula as encoded in https://github.com/bitcoin/bitcoin/blob/master/src/validation.cpp#L1811-L1822 :     CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)     {         int halvings = nHeight / consensusParams.nSubsidyHalvingInterval;         // Force block reward to zero when right shift is undefined.         if (halvings >= 64)             return 0;         CAmount nSubsidy = 50 * COIN;         // Subsidy is cut in half every 210,000 blocks which will occur approximately every 4 years.         nSubsidy >>= halvings;         return nSubsidy;     } It does have the number 210000 in a comment, albeit with a comma added for legibility... [1] https://bitcoin.stackexchange.com/questions/38994/will-there-be-21-million-bitcoins-eventually/38998#38998
3 Reply Quote Share
colddiamondHero Member
Posts: 623 · Reputation: 2467
#3Dec 17, 2024, 09:06 PM
Side note, this is one of those questions that comes up on a somewhat regular basis. I'm surprised it's not discussed more since it is somewhat important. I have even seen the tinfoil hat wearing nutjobs that don't understand programming argue that since they can't see a line that says maxcoins = 21000000 that we all must be wrong and there is going to be an infinite amount of BTC. Someone (not me) should probably put together a better (read more dumbed down) explainable way of showing this then what is in the slackexchnage link. -Dave
4 Reply Quote Share
just_gangMember
Posts: 44 · Reputation: 245
#4Dec 17, 2024, 09:53 PM
How about https://unchained.com/blog/bitcoin-source-code-21-million/
6 Reply Quote Share
tony.satMember
Posts: 12 · Reputation: 203
#5Dec 18, 2024, 01:56 AM
Thanks all, was clear after reading validation.cpp
2 Reply Quote Share

Related topics