leafminer icon indicating copy to clipboard operation
leafminer copied to clipboard

Merkle root not reversed?

Open invpe opened this issue 10 months ago • 1 comments

When looking at the bictcoin wiki: https://en.bitcoin.it/wiki/Block_hashing_algorithm It is clearly mentioned that merkle root hash should be reversed.

  $rootHash = SwapOrder('2b12fcf1b09288fcaff797d71e950e71ae42b91e8bdb2304758dfcffc2b620e3');

When looking at the leaf code, it isn't done :
https://github.com/matteocrippa/leafminer/blob/main/src/model/job.cpp#L30

    calculateMerkleRoot(coinbase_hash, notification.merkle_branch, merkle_root);

The Previous hash is correctly reversed.

  block.version = strtoul(version, nullptr, 16);
    hexStringToByteArray(prevhash, block.previous_block);
    reverseBytesAndFlip(block.previous_block, 32);

Why is that?

invpe avatar Apr 21 '24 17:04 invpe

I recall I was reversing it, I had an unit test to verify the calculated merkle on top of a few examples. I think it's reversed in another func, I will check when back home

matteocrippa avatar Apr 21 '24 21:04 matteocrippa