Bitcoin Forum

Alternate cryptocurrencies => Altcoin Discussion => Topic started by: aaaxn on April 18, 2013, 07:12:54 AM



Title: [LTC] Checking if block hash is valid for given difficulty
Post by: aaaxn on April 18, 2013, 07:12:54 AM
Hi,

How litecoin checks if block hash matches difficulty?
I understand how it works for bitcoin. Bitcoin hashes have leading zeroes for example 000000002c05cc2e78923c34df87fd108b22221ac6076c18f3ade378a4d915e9  (http://blockexplorer.com/block/000000002c05cc2e78923c34df87fd108b22221ac6076c18f3ade378a4d915e9)is valid hash for difficulty 1. When difficulty icreases more leading zeroes are needed.

Litecoin hashes don't have leading zeroes and hash a4ef2ee56356014853936c6c5f50baeeaa74c0db90e973e2ae5bc9d0d840cdf1 (http://explorer.litecoin.net/block/a4ef2ee56356014853936c6c5f50baeeaa74c0db90e973e2ae5bc9d0d840cdf1) was accepted for difficulty 1.065.
Later on with difficulty 364.365 even greater hash d55ad6397da22574b63ae03d54dee8b58e0777cdc531252808371fc25bd296b3 (http://explorer.litecoin.net/block/d55ad6397da22574b63ae03d54dee8b58e0777cdc531252808371fc25bd296b3) was accepted.

So how do I check if block hash is valid for litecoin?


Title: Re: [LTC] Checking if block hash is valid for given difficulty
Post by: Remember remember the 5th of November on April 18, 2013, 08:37:37 AM
+1, I'd like to know how and why too.


Title: Re: [LTC] Checking if block hash is valid for given difficulty
Post by: Remember remember the 5th of November on April 18, 2013, 11:07:09 AM
I checked sources:
https://github.com/litecoin-project/litecoin/blob/master/src/main.cpp

I found function to check it. It is exacly same as in bitcoin so hashes should be similiar unless ... binary clients are from different source and LTC users are in BIG trouble or I am just missing something here.
Code:
bool CheckProofOfWork(uint256 hash, unsigned int nBits)
{
    CBigNum bnTarget;
    bnTarget.SetCompact(nBits);

    // Check range
    if (bnTarget <= 0 || bnTarget > bnProofOfWorkLimit)
        return error("CheckProofOfWork() : nBits below minimum work");

    // Check proof of work matches claimed amount
    if (hash > bnTarget.getuint256())
        return error("CheckProofOfWork() : hash doesn't match nBits");

    return true;
}
That sentence doesn't even make sense.


Title: Re: [LTC] Checking if block hash is valid for given difficulty
Post by: Balthazar on April 18, 2013, 11:27:39 AM
It's because TBX, FBX, BBQ, LTC and other similar clones actually don't use scrypt as blockhash function. Scrypt hash isn't used in blockchain directly, getpowhash() function generates this.