Diff_to_bits and bits_to_diff

Please help.

For bitcoin I found such code to convert difficulty to bits and vice versa.
_https://github.com/ckolivas/cgminer/blob/master/driver-cointerra.c#L26

How to adapt this code for litecoin?
Thanks.

@losh11 Can probably help.

1 Like

No answers?
Actually I found something but again for BTC and I don’t know python
_https://bitcoin.stackexchange.com/questions/74701/in-math-or-python-notation-how-to-convert-bits-to-difficulty

@ [losh11] How we can communicate please?

Hey @Petrs_Petrovs to me it looks like the code should be exactly the same.

1 Like

Why diff *= (double)2147483648.0; ? In cgminer code for scrypt:
diff = (double)65536; Also 0x8000000000000000ULL is max difficulty for BTC.
What’s that should be for LTC?
Also for btc diffone = 0x00000000FFFF
For LTC - 0x0000FFFF
////////////////////////
_https://github.com/ckolivas/cgminer/blob/master/driver-hashfast.c#L1842
from another drive(hashfast)r:
/
Set the number of leading zeroes to look for based on diff.
* Diff 1 = 32, Diff 2 = 33, Diff 4 = 34 etc. */
intdiff = (uint64_t)work->device_diff;
for (i = 31; intdiff; i++, intdiff >>= 1);

Again for btc 32,33,34,etc.
What it should be for LTC?
////////////////////////////////////////////////////////////////
Also truying to apply this code as is - no success

2020-09-24 14:46:06] Selecting pool 0 for work
[2020-09-24 14:46:06] Generated stratum merkle e24c2e8aaf286268c10ab2ab2c665c8e608d4540a1f6ddd5c4b3a1b19db0edd8
[2020-09-24 14:46:06] Generated stratum header 2000000082d707057d13915213d93665a76946b6f0d3015d535f440afb8a83eacc620f61e24c2e8e[43;1Haaf286268c10ab2ab2c665c8e608d4540a1f6ddd5c4b3a1b19db0edd85f6c86eb1a01b1980000 00000000008000000000000000000000000000000000000000e[44;1H000000000000000000
[2020-09-24 14:46:06] Work job_id L9DEwtsDy nonce2 39 ntime 5f6c86eb
[2020-09-24 14:46:06] Generated target 0000000000000000000000000000000000000000000000000080ff7f00000000
[2020-09-24 14:46:06] Generated stratum work
[2020-09-24 14:46:06] Pushing work from pool 0 to hash queue
[2020-09-24 14:46:06] USB: read1 buffering 64 extra bytes
[2020-09-24 14:46:06] : invalid nonce

That’s reson why I’m asking again how to adapt that code(from first exercice) for LTC?
Thanks.

Nobody can help?

OK from cgminer code:
/* truediffone == 0x00000000FFFF0000000000000000000000000000000000000000000000000000 for BTC

  • truediffone == 0x0000FFFF00000000000000000000000000000000000000000000000000000000 for LTC
  • Generate a 256 bit binary LE target by cutting up diff into 64 bit sized
  • portions or vice versa. */
    static const double truediffone = 26959535291011309493156476344723991336010898738574164086137773096960.0; // for BTC
    // static const double truediffone = 1766820104831717178943502833727831496196810259731196417549125097682370560.0; //for LTC
    static const double bits192 = 6277101735386680763835789423207666416102355444464034512896.0; //for BTC
    static const double bits128 = 340282366920938463463374607431768211456.0; //for BTC
    static const double bits64 = 18446744073709551616.0; // for BTC

/* Converts a little endian 256 bit value to a double */
static double le256todouble(const void *target)
{
uint64_t *data64;
double dcut64;

data64 = (uint64_t *)(target + 24);
dcut64 = le64toh(*data64) * bits192;

data64 = (uint64_t *)(target + 16);
dcut64 += le64toh(*data64) * bits128;

data64 = (uint64_t *)(target + 8);
dcut64 += le64toh(*data64) * bits64;

data64 = (uint64_t *)(target);
dcut64 += le64toh(*data64);

return dcut64;

}

static double diff_from_target(void *target)
{
double d64, dcut64;

d64 = truediffone; // for BTC
d64 *= (double)65536; //for scrypt LTC
dcut64 = le256todouble(target);
if (unlikely(!dcut64))
	dcut64 = 1;
return d64 / dcut64;

}

What should be bits192, bits128, bits64 for Litecoin?
Where that constants going from for BTC?

Also Satoshi decided to use 0x1d00ffff as a difficulty for the BTC genesis block, so the target was 0x00ffff0000000000000000000000000000000000000000000000000000

As I understood (maybe I’m wrong?) difficulty for LTC genesis is 0x1e0ffff0

Somebody?

Are it co big secret?

I also have the same question