Author

Topic: Which statement about the difficulty target is the correct one? (Read 282 times)

member
Activity: 392
Merit: 44
fo' sho'  less means equal blockheader claimed already.
legendary
Activity: 1624
Merit: 2509
End conclusion: We agree #1 is the correct one. We even both delivered examples as proof Smiley

Note: An example can NEVER proof a theory. It can only disprove one.

The real prove is this:


bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params)
{
~snip~
    // Check proof of work matches claimed amount
    if (UintToArith256(hash) > bnTarget)
        return false;

    return true;
}


The statement is:
Hash > Target  THEN  Not valid

If we negate that statement (to match the statement 'valid'):
Hash <= Target THEN Valid

And this matches #1 from OP.
sr. member
Activity: 310
Merit: 727
---------> 1231006505

I still think #1 is correct, the function will return true if the hash is lower than or equal to the target Wink


We came to the same conclusion Smiley I mixed up by claiming #2 was right while delivering proof #1 was right (just as you did). I edited my post to match the right number.

End conclusion: We agree #1 is the correct one. We even both delivered examples as proof Smiley
legendary
Activity: 3612
Merit: 5297
https://merel.mobi => buy facemasks with BTC/LTC
If the hash is bigger than the target, return false.. So if the hash is smaller than OR EQUAL TO the target, true is returned... #1 is correct (if i'm not mistaking)

Let's break this down to a simple example:
Code:
Target = 10

Scenario A: Check value 9
Scenario B: Check value 10
Scenario C: Check value 11

Code
return = true;

#Scenario A:
if (9 > 10 )
        return false;
#Scenario A:  returns ->true

#Scenario B:
if (10 > 10 )
        return false;
#Scenario B:  returns -> true

#Scenario C:
if (11 > 10)
        return false;
#Scenario B:  returns  -> false  

Conclusion: EQAUL TO (as in scenario B) returns true, meaning it is accepted. In other words: #2 is the correct one.

I'm on my employer's laptop, which only has php installed, so i wrote this analogy with the code:
Code:
$target 10;
$hash $target 2;
$end $target 2;

while (
$hash $end)
{
        echo 
"testing hash $hash vs target $target => ";
        if (
$hash $target)
        {
                echo 
"POW does not match claimed ammount\n";
        }
        else
        {
                echo 
"OK!\n";
        }
        
$hash++;
}
?>


response:
Code:
testing hash 8 vs target 10 => OK!
testing hash 9 vs target 10 => OK!
testing hash 10 vs target 10 => OK!
testing hash 11 vs target 10 => POW does not match claimed ammount

Since the OP was:
1) The SHA-256 hash of a block's header must be lower than or equal to the current target for the block to be accepted by the network. As mentioned in https://en.bitcoin.it/wiki/Target

or,

2) The hash of the block has to be less than the target. As mentioned by Andreas Antonopoulos here: https://youtu.be/h429LCTRmQw?t=1m28s

I still think #1 is correct, the function will return true if the hash is lower than or equal to the target Wink

EDIT: after re-reading your reply and noticing your conclusion was the same as mine: the hash has to be lower than or equal to, i just realised one of us is just misinterpreting the OP...
We both conclude that hashes lower than or equal to the target are fine... It's just that my interpretation of sollution one is exactly correct, while my interpretation of sollution 2 says that only hashes lower than the target are true (which is not correct if i'm not mistaking)...
legendary
Activity: 1624
Merit: 2509
From my past experience in mining sha-256 ...hash need to be greater to be accepted and if it is lower you try again and every re targeting period the difficulty increase.

You obviously don't have any experience at all.
The hash needs to be LOWER or EQUAL TO the target. This has been discussed in this thread and should be clear if you have completely read it.

The difficulty also does NOT increase each 2016 blocks. This depends on time it took to mine these blocks.
Overall, the difficulty rises. But there also were shorter streaks where the difficulty and hashrate was dropping over multiple periods.
newbie
Activity: 7
Merit: 0
Hi,

Actually it seems that the wiki have some errors : and a lot.

Definitely the second answer is correct ! From my past experience in mining sha-256 ...hash need to be greater to be accepted and if it is lower you try again and every re targeting period the difficulty increase.

sr. member
Activity: 310
Merit: 727
---------> 1231006505
If the hash is bigger than the target, return false.. So if the hash is smaller than OR EQUAL TO the target, true is returned... #1 is correct (if i'm not mistaking)

Let's break this down to a simple example:
Code:
Target = 10

Scenario A: Check value 9
Scenario B: Check value 10
Scenario C: Check value 11

Code:
return = true;

#Scenario A:
if (9 > 10 )
        return false;
#Scenario A:  returns ->true

#Scenario B:
if (10 > 10 )
        return false;
#Scenario B:  returns -> true

#Scenario C:
if (11 > 10)
        return false;
#Scenario C:  returns  -> false  

Conclusion: EQAUL TO (as in scenario B) returns true, meaning it is accepted. In other words: #1 is the correct one.
legendary
Activity: 3612
Merit: 5297
https://merel.mobi => buy facemasks with BTC/LTC

bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params)
{
    bool fNegative;
    bool fOverflow;
    arith_uint256 bnTarget;

    bnTarget.SetCompact(nBits, &fNegative, &fOverflow);

    // Check range
    if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit))
        return false;

    // Check proof of work matches claimed amount
    if (UintToArith256(hash) > bnTarget)
        return false;


    return true;
}


Code doesn't lie Smiley So I agree it should be #2 then. Another case where the (official) documentation doesn't project the reality then!

Anyhow, learned something again Smiley

If the hash is bigger than the target, return false.. So if the hash is smaller than OR EQUAL TO the target, true is returned... #1 is correct (if i'm not mistaking)
sr. member
Activity: 310
Merit: 727
---------> 1231006505

bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params)
{
    bool fNegative;
    bool fOverflow;
    arith_uint256 bnTarget;

    bnTarget.SetCompact(nBits, &fNegative, &fOverflow);

    // Check range
    if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit))
        return false;

    // Check proof of work matches claimed amount
    if (UintToArith256(hash) > bnTarget)
        return false;


    return true;
}


Code doesn't lie Smiley So I agree it should be #1 then. Another case where the (official) documentation doesn't project the reality then!

Anyhow, learned something again Smiley
legendary
Activity: 4522
Merit: 3426
1) The SHA-256 hash of a block's header must be lower than or equal to the current target for the block to be accepted by the network. As mentioned in https://en.bitcoin.it/wiki/Target

or,

2) The hash of the block has to be less than the target. As mentioned by Andreas Antonopoulos here: https://youtu.be/h429LCTRmQw?t=1m28s

It looks to me like the answer is #1.


bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params)
{
    bool fNegative;
    bool fOverflow;
    arith_uint256 bnTarget;

    bnTarget.SetCompact(nBits, &fNegative, &fOverflow);

    // Check range
    if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit))
        return false;

    // Check proof of work matches claimed amount
    if (UintToArith256(hash) > bnTarget)
        return false;


    return true;
}

sr. member
Activity: 310
Merit: 727
---------> 1231006505
The second one is correct. Each block header must hash to a value below the target threshold.

For more in-depth documentation you can check the developers guide on proof of work here:
https://bitcoin.org/en/developer-guide#proof-of-work

Update: see below for proof my linked documentation does not match the reality. #1 is correct.

newbie
Activity: 2
Merit: 4
1) The SHA-256 hash of a block's header must be lower than or equal to the current target for the block to be accepted by the network. As mentioned in https://en.bitcoin.it/wiki/Target

or,

2) The hash of the block has to be less than the target. As mentioned by Andreas Antonopoulos here: https://youtu.be/h429LCTRmQw?t=1m28s
Jump to: