Skip to content

Wrong Nonce converting and increment, Process finding Nonce will loop forever #14

@boris9a9

Description

@boris9a9

Dear sir,
I found a bug in these functions "nonceToInt()" and "intToNonce(uint32_t nonceInt)" of block_header.cpp
With the current code of these function, the process of finding result Nonce will loop forever.
They should be fixed like below:

uint32_t BlockHeader::nonceToInt()
{
uint32_t nonceInt = nonce[0] | (nonce[1] << 8) | (nonce[2] << 16) | (nonce[3] << 24);
return nonceInt;
}

void BlockHeader::intToNonce(uint32_t nonceInt)
{

nonce[0] = (nonceInt & 0x000000ff);
nonce[1] = (nonceInt & 0x0000ff00) >> 8;
nonce[2] = (nonceInt & 0x00ff0000) >> 16;
nonce[3] = (nonceInt & 0xff000000) >> 24;

}

Moreover, In your Genesis Gen Example:
$ cpp_miner genesisgen 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks" 50 1231006505 486604799 2083236893
block hash: 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
block header: 0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c
nonce: 0x1dac2b7c
block hash: 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
merkle root: 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b

The result nonce: 0x1dac2b7c in decimal = 497822588 => That's wrong
Instead, it should be 0x7c2bac1d in decimal = 2083236893

Please have a check!

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