Bitcoin Forum
December 13, 2017, 05:35:46 AM *
News: Latest stable version of Bitcoin Core: 0.15.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: The Definition of the BitCoin Limit (Techies and Old Timers Come Hither)  (Read 387 times)
archaeopteryx
Newbie
*
Offline Offline

Activity: 16


View Profile
March 20, 2013, 09:24:41 AM
 #1

So while I relax in the Newbie pool I'm trying to understand some of the more technical aspects of BitCoin. Over and over again we hear and read that there is a limit of 21 million coins that can ever be minted, but I'm interested in what that actually means in terms of BitCoin source code. Is this limit due to the fact that there is a variable defined with a certain bit-length limiting how high of numbers can be expressed? Or is it due to the algorithm for mining rewards where every 210k blocks the reward is halved? Something like:

50*210,000 + 25*210,000 + 12.5*210,000 + . . . ~= 21,000,000 BTC?

I've been digging through the forum and wiki and even making small forays into the source code to try to understand this, but I don't have a lot of programming or crypto knowledge. Any explanations from knowledgeable individuals would be appreciated.

Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
Foxpup
Legendary
*
Online Online

Activity: 2044



View Profile
March 20, 2013, 10:30:11 AM
 #2

Or is it due to the algorithm for mining rewards where every 210k blocks the reward is halved? Something like:

50*210,000 + 25*210,000 + 12.5*210,000 + . . . ~= 21,000,000 BTC?
This exactly. The limit is actually slightly less than BTC21,000,000 (BTC20,999,999.9769 to be exact) as the block reward is rounded down to eight decimal places (eg, on the tenth halving the reward will decrease from BTC0.09765625 to BTC0.04882812, not BTC0.048828125 as you might expect). The code for this is in the function GetBlockValue() in main.cpp:
Code:
int64 static GetBlockValue(int nHeight, int64 nFees)
{
    int64 nSubsidy = 50 * COIN;

    // Subsidy is cut in half every 210000 blocks, which will occur approximately every 4 years
    nSubsidy >>= (nHeight / 210000);

    return nSubsidy + nFees;
}

For more details, see en.bitcoin.it/wiki/Controlled_supply.

Will pretend to do unverifiable things (while actually eating an enchilada-style burrito) for bitcoins: 1K6d1EviQKX3SVKjPYmJGyWBb1avbmCFM4
archaeopteryx
Newbie
*
Offline Offline

Activity: 16


View Profile
March 20, 2013, 11:36:00 AM
 #3

Ahhhh, it's all starting to make sense. So, dissecting this code:

Code:
int64 static GetBlockValue(int nHeight, int64 nFees)
{
    int64 nSubsidy = 50 * COIN;

    // Subsidy is cut in half every 210000 blocks, which will occur approximately every 4 years
    nSubsidy >>= (nHeight / 210000);

    return nSubsidy + nFees;
}

I'm guessing that nHeight is the current block number, and then nFees is all the transaction fees that are associated with the block. So then we have

Code:
int64 nSubsidy = 50 * COIN;

as the definition of the reward for any given block. "COIN" must be the elusive definition of the Bitcoin that I've been trying to find.  Then,

Code:
nSubsidy >>= (nHeight/210000);

this is bit-shifting the block reward by integer values of the current block divided by the halving block number. So this bit shift value was initially zero until we reached block #210,000 at which point nHeight/210000 = 1. So really what we have for nSubsidy is a 64-bit integer with an initial value of:

00000000 00000000 00000000 00000001 00101010 00000101 11110010 00000000 (dec: 5,000,000,000 = 50 BTC)

and which is then shifted an extra bit every time the block count reaches another multiple of 210,0000. Then the block reward added to the  transaction fees are returned by the function.

Thanks, Foxpup, this has cleared a lot of things up for me.

EDIT: I just did a case-sensitive word search through about 90% of the Bitcoin source code in order to find this:

Code:
static const int64 COIN = 100000000;

Exactly what I was expecting, but good to see it and know that it is in "util.h". I've learned things today. And, oh look, my four hours in the Newbie pool are up. No one can say I wasted them. Smiley
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!