Bitcoin Forum
May 12, 2024, 08:52:25 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Which statement about the difficulty target is the correct one?  (Read 273 times)
sasageyo (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 4


View Profile
August 29, 2018, 09:05:31 PM
Merited by achow101 (2), ABCbits (1)
 #1

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
1715547145
Hero Member
*
Offline Offline

Posts: 1715547145

View Profile Personal Message (Offline)

Ignore
1715547145
Reply with quote  #2

1715547145
Report to moderator
You can see the statistics of your reports to moderators on the "Report to moderator" pages.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715547145
Hero Member
*
Offline Offline

Posts: 1715547145

View Profile Personal Message (Offline)

Ignore
1715547145
Reply with quote  #2

1715547145
Report to moderator
1715547145
Hero Member
*
Offline Offline

Posts: 1715547145

View Profile Personal Message (Offline)

Ignore
1715547145
Reply with quote  #2

1715547145
Report to moderator
1715547145
Hero Member
*
Offline Offline

Posts: 1715547145

View Profile Personal Message (Offline)

Ignore
1715547145
Reply with quote  #2

1715547145
Report to moderator
TheArchaeologist
Sr. Member
****
Offline Offline

Activity: 310
Merit: 727


---------> 1231006505


View Profile WWW
August 29, 2018, 09:23:46 PM
Last edit: August 30, 2018, 09:46:03 AM by TheArchaeologist
 #2

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.


Sooner or later you're going to realize, just as I did, that there's a difference between knowing the path and walking the path
odolvlobo
Legendary
*
Offline Offline

Activity: 4312
Merit: 3214



View Profile
August 30, 2018, 02:51:08 AM
Merited by Foxpup (3), TheArchaeologist (2), ABCbits (1)
 #3

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;
}


Join an anti-signature campaign: Click ignore on the members of signature campaigns.
PGP Fingerprint: 6B6BC26599EC24EF7E29A405EAF050539D0B2925 Signing address: 13GAVJo8YaAuenj6keiEykwxWUZ7jMoSLt
TheArchaeologist
Sr. Member
****
Offline Offline

Activity: 310
Merit: 727


---------> 1231006505


View Profile WWW
August 30, 2018, 06:38:59 AM
Last edit: August 30, 2018, 09:42:30 AM by TheArchaeologist
 #4


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

Sooner or later you're going to realize, just as I did, that there's a difference between knowing the path and walking the path
mocacinno
Legendary
*
Offline Offline

Activity: 3388
Merit: 4922


https://merel.mobi => buy facemasks with BTC/LTC


View Profile WWW
August 30, 2018, 06:43:52 AM
 #5


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)

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
TheArchaeologist
Sr. Member
****
Offline Offline

Activity: 310
Merit: 727


---------> 1231006505


View Profile WWW
August 30, 2018, 07:50:48 AM
Last edit: August 30, 2018, 09:43:00 AM by TheArchaeologist
Merited by ABCbits (4), achow101 (3)
 #6

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.

Sooner or later you're going to realize, just as I did, that there's a difference between knowing the path and walking the path
waxload
Newbie
*
Offline Offline

Activity: 7
Merit: 0


View Profile
August 30, 2018, 08:34:43 AM
 #7

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.

bob123
Legendary
*
Offline Offline

Activity: 1624
Merit: 2481



View Profile WWW
August 30, 2018, 09:03:37 AM
 #8

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.

mocacinno
Legendary
*
Offline Offline

Activity: 3388
Merit: 4922


https://merel.mobi => buy facemasks with BTC/LTC


View Profile WWW
August 30, 2018, 09:40:20 AM
 #9

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:
<?php
$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)...

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
TheArchaeologist
Sr. Member
****
Offline Offline

Activity: 310
Merit: 727


---------> 1231006505


View Profile WWW
August 30, 2018, 09:50:32 AM
 #10


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

Sooner or later you're going to realize, just as I did, that there's a difference between knowing the path and walking the path
bob123
Legendary
*
Offline Offline

Activity: 1624
Merit: 2481



View Profile WWW
August 30, 2018, 10:11:03 AM
Merited by achow101 (2), ABCbits (1)
 #11

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.

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!