Bitcoin Forum
May 28, 2024, 09:06:37 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 [2]  All
  Print  
Author Topic: Bug in Bitcoin Discovered by PMC Community - Altcoins Affected As Well  (Read 2628 times)
maardein
Sr. Member
****
Offline Offline

Activity: 420
Merit: 250


View Profile
March 01, 2014, 10:28:27 PM
 #21

Yes, bitcoin may have a lot of time left to fix this.

Don't forget though that pretty much all coins are bitcoin clones, and there are many different block times. Probably there will be quite some coins who reach 64 times block halving way before bitcoin does.

BTC: 1788UegKXGXXicfPcbZ1bmSUJ99ZWRCF7p
LTC: LZ2rCcoxK4X8wRRynqdxoimd4d3TDNk7Lk
PMP: PApSSdorQds5tQysymwDXPAN3viJLFTUs8
DeathAndTaxes
Donator
Legendary
*
Offline Offline

Activity: 1218
Merit: 1079


Gerald Davis


View Profile
March 01, 2014, 10:29:51 PM
 #22

Title should be changed to PMC community "discovers" bug already known (with potential fix) in 2012.

Looks like you can see the code here:

https://github.com/bitcoin/bitcoin/blob/v0.7.1/src/main.cpp

Quote
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;
}
As I've pointed out before, this is shoddy code.  Once nHeight is about 13.23 million (admittedly some way off) this code has undefined right-shift behaviour.  It needs a conditional such as

  if (nHeight / 210k >= 63)
    nSubsidy = 0;
  else
    nSubsidy >>= (nHeight / 210k);

Why code is written with nFees, nHeight and nSubsidy as signed integers, given they can only ever be non-negative, is also weak and a source of bugs IMO.
alexeft
Legendary
*
Offline Offline

Activity: 854
Merit: 1000


View Profile
March 01, 2014, 10:36:07 PM
 #23

Better to fix it today than waiting 200 years and having the whole United Federation of Planets update every client on every planet and every spaceship


 Cheesy Cheesy Cheesy

If we reach that point we won't need new coins because the block will have a pretty big value from fees!

Ok people, let's speculate what the price will be at that point!

I say $1.000.000.000.000.000 per gracchi!

Corrected it for you! no thanks necessary!

 Wink

Pangia
Sr. Member
****
Offline Offline

Activity: 406
Merit: 250


View Profile
March 01, 2014, 11:05:58 PM
 #24

Dogecoin NOT impacted by this.

https://github.com/dogecoin/dogecoin/blob/f1677f31296daaa00e074bd9a6be14c4425b4a96/src/main.cpp#L1089


 
 
           ▄████▄
         ▄████████▄
       ▄████████████▄
     ▄████████████████▄
    ████████████████████      ▄█▄                 ▄███▄                 ▄███▄                 ▄████████████████▀   ▄██████████

  ▄▄▄▀█████▀▄▄▄▄▀█████▀▄▄▄     ▀██▄             ▄██▀ ▀██▄             ▄██▀ ▀██▄             ▄██▀                   ██
▄█████▄▀▀▀▄██████▄▀▀▀▄█████▄     ▀██▄         ▄██▀     ▀██▄         ▄██▀     ▀██▄         ▄██▀        ▄█▄          ▀██████████████▄
████████████████████████████       ▀██▄     ▄██▀         ▀██▄     ▄██▀         ▀██▄     ▄██▀          ▀█▀                        ██
 ▀████████████████████████▀          ▀██▄ ▄██▀             ▀██▄ ▄██▀     ▄█▄     ▀██▄ ▄██▀                                       ██
   ▀████████████████████▀              ▀███▀                 ▀███▀       ▀█▀       ▀███▀      ▄███████████████████████████████████▀
     ▀████████████████▀
       ▀████████████▀
         ▀████████▀
           ▀████▀
║║


║║
.
.

║║
██
║║
.
.

║║
██
║║
.
║║


║║
Skybuck
Full Member
***
Offline Offline

Activity: 384
Merit: 110


View Profile
March 01, 2014, 11:57:13 PM
 #25

Title should be changed to PMC community "discovers" bug already known (with potential fix) in 2012.

Looks like you can see the code here:

https://github.com/bitcoin/bitcoin/blob/v0.7.1/src/main.cpp

Quote
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;
}
As I've pointed out before, this is shoddy code.  Once nHeight is about 13.23 million (admittedly some way off) this code has undefined right-shift behaviour.  It needs a conditional such as

  if (nHeight / 210k >= 63)
    nSubsidy = 0;
  else
    nSubsidy >>= (nHeight / 210k);

Why code is written with nFees, nHeight and nSubsidy as signed integers, given they can only ever be non-negative, is also weak and a source of bugs IMO.

This is like driving at a wall with a ferrari and then hitting the breaks at the very last moment Wink
notbatman
Legendary
*
Offline Offline

Activity: 2212
Merit: 1038



View Profile
March 02, 2014, 01:05:34 AM
 #26

Quote
Better to fix it today than waiting 200 years and having the whole United Federation of Planets update every client on every planet and every spaceship

"To the moon!"

http://www.virginiaedition.com/media/spaceelevators.pdf
Skybuck
Full Member
***
Offline Offline

Activity: 384
Merit: 110


View Profile
July 03, 2015, 04:54:15 AM
 #27

Assumption is the mother of all fok ups.

My earlier posting was pretty good except for the following part:

"
So what we need to calculate now is the number of times this 21m number can be halved.

Which is log10(21m) / log10(2) = 24.323885992102934376117624838116

So that's roughly:
24.32 * 210k blocks = 5108016.0583416162189847012160044 blocks.

5.1m blocks will be mined and then the rewards should go to zero.
"

This is wrong.

It's not the supply that's being halved... it's the reward that's being halved:

50 * COIN

COIN is defined as 1 0000 0000  (without the space)

So the function starts with 50 0000 0000

It is then right shifted by:

BlockNumber / 210000

So the question is then at what block number will the reward go to zero or near zero ?

The answer is:

Step 1. Figure out how many times 50 0000 0000 can be shifted right. It turns out this is 33.

(Note... this is over the safety range of 0..31 for shift values... so any 32 bit software version of bitcoin might be unsafe).

Step 2. Calculate which block turns into zero reward or problem:

33 * 210000 = 6930000

Another little bit of interesting tid bit is:

5.000.000.000 is already over the 32 bit safety limit.

Another little bit of interesting information is, this table below is wrong...

https://en.bitcoin.it/wiki/Controlled_supply#Projected_Bitcoins_Long_Term

The reward will not be 1 but 0.

At least according to windows calculator !

It's very funny to see how hard it is to get it right... but I am trying to get it right this time ! =D

(I am also glad I can login again ! password reset working =D)

The correct shift value to still get an reward is 32...

Anyway block 6930000 should probably be the first block to have a reward of zero. Thus shift value 33 is reward = 0.

When will reward go to zero 4*210k so 4x33 = 132 years from genesis or so... maybe sooner or later... correct calculation would be taking the 10 minutes... too lazy now to do that... maybe later.

However point is: for 32 bit software it would already go undefined sooner... at 32:  32x4 = 128 years from genesis.

So let's step:

Step 3. Multiple by halving time (expressed in dividing block number by 210.000 which more or less equals 4 years):

ShiftValue * 210.000 = X

So see above.

Bit vague posting maybe... but I am not too sharp anymore... heat, sleep lol but it's pretty good anyway.

But strange maybe... but true: 210.000 and 4 years related to each other.

I will leave it at that for now... just to correct my posting a little bit.
Pages: « 1 [2]  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!