Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merkle root not reversed? #35

Open
invpe opened this issue Apr 21, 2024 · 1 comment
Open

Merkle root not reversed? #35

invpe opened this issue Apr 21, 2024 · 1 comment

Comments

@invpe
Copy link

invpe commented Apr 21, 2024

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?

@matteocrippa
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants