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?
Can’t locate the Bitcoin supply formula in the code
4 replies 488 views
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
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
How about https://unchained.com/blog/bitcoin-source-code-21-million/
Thanks all,
was clear after reading validation.cpp
Related topics
- Bitcoin Core displaying coins (UTXOs) in a new tab 13
- Are you in favor of BIP-110? Let's get a Bitcoin poll going. 0
- Erlay seems to have some issues here’s a better proposal for a bitcoin protocol without invites 3
- Ways to earn some sats by contributing to bitcoin core development 5
- Exploring the Potential and Challenges of a Kardashev-Scale Bitcoin Network 3
- What can I do to fix this Bitcoin Core error? 8