EmberCoin / Ember

Official Ember Blockchain
http://embercoin.io/
MIT License
25 stars 31 forks source link

Stake Rewards Overflow #15

Closed EmberCoin closed 7 years ago

EmberCoin commented 7 years ago

At around 38 million in coin calculation value, a subsidy value gets overflowed to very low payouts. Credit for finding this bug goes to @Truthsayer

Truthsayer1 commented 7 years ago

Oh did I put it in the wrong ember one?? I put this somewhere else before

An alternative to:

// int64_t nSubsidy = nCoinAge COIN_YEAR_REWARD 33 / (365 * 33 + 8);

int64_t nSubsidy = COIN_YEAR_REWARD * 33 / (365 * 33 + 8) * nCoinAge;

which loses accuracy (just slightly less Ember reward in the decimal points etc after millions are staked so nothing to worry about)

or

simply add .0 to one of the numbers to make it more accurate (this makes all values exactly the same for both the original and new version of the code except after 38.81million nCoinAge - nSubsidy is still accurate after that with this code so fixes the bug):

int64_t nSubsidy = nCoinAge * COIN_YEAR_REWARD * 33.0 / (365 * 33 + 8);

So this last solution has the advantage of making both wallet versions exactly the same up to the bug level of nCoinAge..... (it simply forces floating point operations but still returns the same integer nSubsidy amount)

EmberCoin commented 7 years ago

This is now fixed in https://github.com/EmberCoin/Ember/releases/tag/v1.1.4

We have decided to use CBigNum which are based on OpenSSL bignum primitives in order to guarantee correctness. Thanks.