<p>Variable <code>nsubsidy</code> is of type <code>CAmount</code> which is an <code>int64</code>.</p>
<p>As the comments say in the code you quoted, a 64-bit integer value can have no more than 64 bitwise right-shift operations meaningfully performed. So this is the limit applied.</p>
<p>It just happens that the initial subsidy <code>50 * COIN</code> is a much smaller value that falls to zero only around 32 bitwise right shifts.</p>
<p>So the limit is based on the data type not the initial value. Regardless of the initial value, we know that the result must be zero after a 64-bit variable is right shifted 64 times.</p>
<p>A bitwise rightshift is a pretty cheap operation in CPU cycles so there's probably not much to be gained by optimising further here.</p>

CC BY-SA 4.0
2023-07-30T15:22:32.083Z
See also BIP42 for background (while it's written in a humorous way - check the publication date - it does describe an actual big that existed before this check was introduced). Note that Bitcoin was always intended to have a 21M BTC limit; this BIP did not actually make the supply finite.
Pieter Wuille
CC BY-SA 4.0
2023-07-30T15:39:53.067Z
[LOL](https://github.com/bitcoin/bips/blob/master/bip-0042.mediawiki)
RedGrittyBrick
CC BY-SA 4.0
2023-07-30T16:55:11.557Z
Ok so would bitcoin work just fine after 2140 if the code was like this? if (halvings > 33) return 0;
Efe
CC BY-SA 4.0
2023-07-30T17:02:33.427Z
@Efe Yes, that would behave exactly the same way.
Pieter Wuille
CC BY-SA 4.0
2023-07-30T15:17:04.440Z
2023-07-30T15:17:04.440Z
RedGrittyBrick
<p>If there are 32 halvings, why is the if block in the GetBlockSubsidy function checking if there are equal or more than 64 halvings?</p>
<p><a href="https://i.sstatic.net/X8Umt.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/X8Umt.jpg" alt="enter image description here" /></a></p>

<reward-schedule>
If there are 32 halvings, why is the if block in the GetBlockSubsidy function checking if there are 64 or more halvings already done?
Efe
# If there are 32 halvings, why is the if block in the GetBlockSubsidy function checking if there are 64 or more halvings already done?

(Asked by: username_0 on 2023-07-30)

If there are 32 halvings, why is the if block in the GetBlockSubsidy function checking if there are equal or more than 64 halvings?

[![enter image description here](https://i.sstatic.net/X8Umt.jpg)](https://i.sstatic.net/X8Umt.jpg)

**Tags:** reward-schedule


---

## 1 answers

### Answer by username_1 on 2023-07-30. Score: 3 | Accepted answer

Variable `nsubsidy` is of type `CAmount` which is an `int64`.

As the comments say in the code you quoted, a 64-bit integer value can have no more than 64 bitwise right-shift operations meaningfully performed. So this is the limit applied.

It just happens that the initial subsidy `50 * COIN` is a much smaller value that falls to zero only around 32 bitwise right shifts.

So the limit is based on the data type not the initial value. Regardless of the initial value, we know that the result must be zero after a 64-bit variable is right shifted 64 times.

A bitwise rightshift is a pretty cheap operation in CPU cycles so there's probably not much to be gained by optimising further here.

> **Comments:**
> **username_2**: See also BIP42 for background (while it's written in a humorous way - check the publication date - it does describe an actual big that existed before this check was introduced). Note that Bitcoin was always intended to have a 21M BTC limit; this BIP did not actually make the supply finite.  
> **username_1**: [LOL](https://github.com/bitcoin/bips/blob/master/bip-0042.mediawiki)  
> **username_0**: Ok so would bitcoin work just fine after 2140 if the code was like this? if (halvings > 33) return 0;  
> **username_2**: @username_0 Yes, that would behave exactly the same way.  

---

