I received a mining job with target = f3220000.
My XMRig miner logged the following statement:
new job from ... diff 480045 algo rx/0 height 2027084
I want to find answers to the following questions:
How to get a decimal value of difficulty (
480045) by a hexadecimal value of a given target in hex (f3220000) ?How to get a hexadecimal value of target (
f3220000) by a decimal value of a given difficulty (480045)?
My research led to the following formula:
target = targetmax / diff when targetmax = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
I also found the something in the source of some pools here and here. They have a different logic and I can’t understand it anyway.
>>224is shifting out the bottom 224 bits from our division of the base diff to take only the top 32 bits. – jtgrassie Feb 05 '20 at 23:52((2^256-1) / 200000) >> 224is decimal21474, hex0x53e2. Swap endian and pad yields:e2530000. – Andrei Apr 07 '20 at 13:3653e20000and remove padding gets53e2, then0x100000001 / 0x53e2yields:200007. Its should be200000. What I'm doing wrong? – Andrei Apr 07 '20 at 13:410x100000001 / 200000 = 21474.836485is a float, and the reverse calc/truncation (with the shift), is using integers, thus you won't always get an exact match both ways. – jtgrassie Apr 08 '20 at 07:51200000? I think I mined onpool.supportxmr.com:3333and got this kind of work with difficulty of200000– Andrei Apr 08 '20 at 08:49200000. Then what target was sent to me? Or is it impossible? – Andrei Apr 08 '20 at 09:41200000then the pool sent a target of0x53e2(so in the stratum message formate2530000). As already mentioned, because there is rounding at play in the calculations above, you wont always get exact matches in both directions of the calculations - e.g. if the jobs target was 1 bigger (0x53e3), that would be difficulty 199998. – jtgrassie Apr 08 '20 at 17:18147640361901to target (hex)((2**256-1) // 147640361901) >> 224and got00000000. Why I have all zeros if using your formula ? – Andrei Apr 16 '20 at 01:42