<p>Any block, no matter how low its block hash is, contributes the same amount of work. This work depends on the current difficulty, as an average expected amount of work that should be performed to find this hash.<br />
<a href="https://bitcoin.stackexchange.com/a/29744/101498">See</a> <a href="https://bitcoin.stackexchange.com/a/939/101498">these</a> <a href="https://bitcoin.stackexchange.com/a/66874/101498">answers</a> which explain the code you linked. Also this <a href="https://bitcoin.stackexchange.com/a/53965/101498">answer</a> gives two examples of why the increased variance caused by making the work depend on the hash value isn't desirable.</p>

CC BY-SA 4.0
2022-06-21T11:51:49.633Z
Thank you for the links. This answers only why we're using the target instead of the block hash. It doesn't explain why division is used instead of difference like I showed in the question.
The Quantum Physicist
CC BY-SA 4.0
2022-06-21T09:48:04.557Z
2022-06-21T09:53:48.320Z
2022-06-21T09:53:48.320Z
Antoine Poinsot
<p>Bitcoin Core uses <a href="https://github.com/bitcoin/bitcoin/blob/1d39c9ca0672e7ad4c1f0959f9d58d2fcc7dc46b/src/chain.cpp#L125" rel="nofollow noreferrer">GetBlockProof()</a> function to determine the contribution of a block to the total difficulty of the current chain, aka, <code>nChainWork</code> in CBlockIndex. I'm having trouble understanding the logic in that implementation.</p>
<p>Let's ignore the math gymnastics done there to avoid overflowing off <code>uint256</code>. The only part we need is the beginning of the comment:</p>
<pre><code>// We need to compute 2**256 / (bnTarget+1)
</code></pre>
<p>And the question is simply, why?!</p>
<p>If I want to calculate the difficulty contribution of a block to the chain, my (possibly naive) logic would be: The lower the block hash value, the higher its contribution. While the equation mentioned in the comment achieves that, it doesn't do so linearly, but in a <code>f(x)=1/x</code> fashion. I don't get why. Again, my (possibly naive) implementation would simply be:</p>
<pre><code>~arith_uint256(0) - UintToArith256(block.GetBlockHash())
</code></pre>
<p>which basically means: The lower the hash of a block, the higher its contribution to the difficulty. And if using the block hash is bad for some reason (I'd appreciate explaining why if it's the case), a similar proportionality can be made with just the target:</p>
<pre><code>~arith_uint256(0) - bnTarget
</code></pre>
<p>Can someone please explain the reason for that division choice?</p>

<blockchain><block><difficulty><proof-of-work><difficulty-retargetting>
What's the logic behind the way block proofs (in GetBlockProof) is calculated?
The Quantum Physicist
# What's the logic behind the way block proofs (in GetBlockProof) is calculated?

(Asked by: username_0 on 2022-06-21)

Bitcoin Core uses [GetBlockProof()](https://github.com/bitcoin/bitcoin/blob/1d39c9ca0672e7ad4c1f0959f9d58d2fcc7dc46b/src/chain.cpp#L125) function to determine the contribution of a block to the total difficulty of the current chain, aka, `nChainWork` in CBlockIndex. I'm having trouble understanding the logic in that implementation.

Let's ignore the math gymnastics done there to avoid overflowing off `uint256`. The only part we need is the beginning of the comment:

```
// We need to compute 2**256 / (bnTarget+1)

```

And the question is simply, why?!

If I want to calculate the difficulty contribution of a block to the chain, my (possibly naive) logic would be: The lower the block hash value, the higher its contribution. While the equation mentioned in the comment achieves that, it doesn't do so linearly, but in a `f(x)=1/x` fashion. I don't get why. Again, my (possibly naive) implementation would simply be:

```
~arith_uint256(0) - UintToArith256(block.GetBlockHash())

```

which basically means: The lower the hash of a block, the higher its contribution to the difficulty. And if using the block hash is bad for some reason (I'd appreciate explaining why if it's the case), a similar proportionality can be made with just the target:

```
~arith_uint256(0) - bnTarget

```

Can someone please explain the reason for that division choice?

**Tags:** blockchain, block, difficulty, proof-of-work, difficulty-retargetting


---

## 1 answers

### Answer by username_1 on 2022-06-21. Score: 1

Any block, no matter how low its block hash is, contributes the same amount of work. This work depends on the current difficulty, as an average expected amount of work that should be performed to find this hash.  
[See](https://bitcoin.stackexchange.com/a/29744/101498) [these](https://bitcoin.stackexchange.com/a/939/101498) [answers](https://bitcoin.stackexchange.com/a/66874/101498) which explain the code you linked. Also this [answer](https://bitcoin.stackexchange.com/a/53965/101498) gives two examples of why the increased variance caused by making the work depend on the hash value isn't desirable.

> **Comments:**
> **username_0**: Thank you for the links. This answers only why we're using the target instead of the block hash. It doesn't explain why division is used instead of difference like I showed in the question.  

---

