- How to get a decimal value of difficulty (480045) by a hexadecimal value of a given target in hex (f3220000) ?
f3220000 and remove padding gets
0x100000001 / 0x22f3 yields:
- How to get a hexadecimal value of target (f3220000) by a decimal value of a given difficulty (480045)?
((2^256-1) / 480045) >> 224 is decimal
0x22f3. Swap endian and pad yields:
The reason for both the division in #1 and shift in #2 is because we are exploiting the fact that we are working with only a 32 bit difficulty target. Thus, we are only concerning ourselves with the most significant 32 bits of a 256 bit number.
It's worth noting that this calculation is just legacy hangover of how the pools and miners were doing this when forked, which nobody felt strongly enough to improve upon. The current miner implementations foresaw this 32 bit limitation and do have code to handle larger targets [ref], though most pools do not, as can be seen by the pools you cite. In retrospect, it would probably be more sensible if the pools and miners calculated/checked difficulty more akin to how Monero does (i.e. if hash multiplied by difficulty doesn't overflow, it's good), as whilst this would mean passing around a slightly larger target in the stratum job message, it's more future-proof.