Skip to content

Integer Overflow problem in stake reward calculation #3

@Truthsayer1

Description

@Truthsayer1

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

This is the simple fix (otherwise after 38.81million nCoinAge overflow and incorrect calculation occurs) :

in main.cpp (comment out old line and replace with nCoinAge at the end) 👍

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

to avoid the loss of accuracy and force floating point, simply add .0 to one of the numbers instead (nSubsidy is obviously still an integer):
int64_t nSubsidy = nCoinAge * COIN_YEAR_REWARD * 33.0 / (365 * 33 + 8);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions