matteocrippa / matteocrippa/leafminer

Merkle root not reversed?

Open
#35 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
158
Forks
26
PR merge metrics
No merged PRs in 30d

Description

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.

``` $prevBlockHash = SwapOrder('00000000000008a3a41b85b8b29ad444def299fee21793cd8b9e567eab02cd81');
$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

``` std::string merkle_root;
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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Bitcoin block hashing algorithm linked in the issue, then inspect src/model/job.cpp at line 30 and trace calculateMerkleRoot. Compare its merkle-root byte handling with the reverseBytesAndFlip treatment of block.previous_block. Done means the byte order is verified against the referenced algorithm and the issue's question is resolved in the relevant code or documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
blockchain, embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.