<p>First of all, &quot;difficulty&quot; as a concept does not exist in the protocol. It's a unit intended only for human consumption.</p>
<p>Internally, the value that corresponds with it is the <em>target</em>. The target is a 256-bit number, computed for every block, and a block is valid if its hash (interpreted as 256-bit number as well) is less than or equal to the target.</p>
<p>The difficulty is simply defined as the (floating-point, approximate) value of <em>MAX_TARGET / target</em>. MAX_TARGET us <em>(2<sup>16</sup>-1)2<sup>208</sup></em>, the maximum possible target (so the lowest difficulty Bitcoin will permit for any block).</p>
<p>To compare chains, a new metric is introduced: <em>work</em>. Work is the expected number of hashing attempts are necessary to construct valid proof-of-work for that block. It is simply <em>2<sup>256</sup></em> divided by the number of potential hash values that meet the target, namely <em>target + 1</em>. So, the work of a block is defined as <em>2<sup>256</sup> / (target + 1)</em>.</p>
<p>The work of a chain is simply the sum of the work values of the blocks in it. This makes sense: we want to make sure that an attacker needs to do as much work as the honest miners needed to produce a valid chain.</p>
<p>At block 678033, with approximate difficulty 23137439666472.1, we have:</p>
<ul>
<li>Target is <em>1165190949371886336955396954992052935118810155482873856</em> (or <em>0xc2a480000000000000000000000000000000000000000</em> in hex).</li>
<li>Work is <em>99376063039054378510219</em></li>
<li>Cumulative work (sum of all work in the entire chain) is approximately <em>8.565487⋅10<sup>27</sup></em>.</li>
</ul>
<p>So - perhaps remarkably - this is (approximately) equivalent to just summing the difficulty values of all blocks. No logarithms involved.</p>
<p>For completeness, Bitcoin Core's current rules for picking the best chain:</p>
<ul>
<li>First exclude all chains with invalid blocks</li>
<li>Then pick the tips of all those chains, and leave only the ones with the highest cumulative work (which may be more than one if there is a fork).</li>
<li>Among those, pick the one for which the full block (not just the header) was received first.</li>
</ul>

CC BY-SA 4.0
2021-04-06T16:37:55.047Z
2021-04-06T16:54:55.843Z
2021-04-06T16:54:55.843Z
Pieter Wuille
<p>Chain 1 has blocks with targets diff1, diff2, diff3, diff4</p>
<p>Chain 2 has blocks with targets DIFF1 DIFF2 DIFF3</p>
<p>What's the formula to derive the (relative) cumulative proof of works from these chains to find out which one is stronger?</p>
<p>My guess is we take their logarithms and add them up?</p>

<difficulty><proof-of-work>
How is "cumulative PoW" calculated to decide between competing chains?
MCCCS
# How is "cumulative PoW" calculated to decide between competing chains?

(Asked by: username_0 on 2021-04-06)

Chain 1 has blocks with targets diff1, diff2, diff3, diff4

Chain 2 has blocks with targets DIFF1 DIFF2 DIFF3

What's the formula to derive the (relative) cumulative proof of works from these chains to find out which one is stronger?

My guess is we take their logarithms and add them up?

**Tags:** difficulty, proof-of-work


---

## 1 answers

### Answer by username_1 on 2021-04-06. Score: 3 | Accepted answer

First of all, "difficulty" as a concept does not exist in the protocol. It's a unit intended only for human consumption.

Internally, the value that corresponds with it is the *target*. The target is a 256-bit number, computed for every block, and a block is valid if its hash (interpreted as 256-bit number as well) is less than or equal to the target.

The difficulty is simply defined as the (floating-point, approximate) value of *MAX\_TARGET / target*. MAX\_TARGET us *(216-1)2208*, the maximum possible target (so the lowest difficulty Bitcoin will permit for any block).

To compare chains, a new metric is introduced: *work*. Work is the expected number of hashing attempts are necessary to construct valid proof-of-work for that block. It is simply *2256* divided by the number of potential hash values that meet the target, namely *target + 1*. So, the work of a block is defined as *2256 / (target + 1)*.

The work of a chain is simply the sum of the work values of the blocks in it. This makes sense: we want to make sure that an attacker needs to do as much work as the honest miners needed to produce a valid chain.

At block 678033, with approximate difficulty 23137439666472.1, we have:

* Target is *1165190949371886336955396954992052935118810155482873856* (or *0xc2a480000000000000000000000000000000000000000* in hex).
* Work is *99376063039054378510219*
* Cumulative work (sum of all work in the entire chain) is approximately *8.565487⋅1027*.

So - perhaps remarkably - this is (approximately) equivalent to just summing the difficulty values of all blocks. No logarithms involved.

For completeness, Bitcoin Core's current rules for picking the best chain:

* First exclude all chains with invalid blocks
* Then pick the tips of all those chains, and leave only the ones with the highest cumulative work (which may be more than one if there is a fork).
* Among those, pick the one for which the full block (not just the header) was received first.


---

