Bitcoin Forum
May 21, 2019, 08:08:03 AM *
News: Latest Bitcoin Core release: 0.18.0 [Torrent] (New!)
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Which statement about the difficulty target is the correct one?  (Read 169 times)
sasageyo
Newbie
*
Offline Offline

Activity: 2
Merit: 2


View Profile
August 29, 2018, 09:05:31 PM
Merited by achow101 (2)
 #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
1558426083
Hero Member
*
Offline Offline

Posts: 1558426083

View Profile Personal Message (Offline)

Ignore
1558426083
Reply with quote  #2

1558426083
Report to moderator
1558426083
Hero Member
*
Offline Offline

Posts: 1558426083

View Profile Personal Message (Offline)

Ignore
1558426083
Reply with quote  #2

1558426083
Report to moderator
1558426083
Hero Member
*
Offline Offline

Posts: 1558426083

View Profile Personal Message (Offline)

Ignore
1558426083
Reply with quote  #2

1558426083
Report to moderator
START MINING BTC NOW WITH NEW GENERATION S17 ANTMINER! BTC/BCH/LTC/ZCASH/DASH/ETH/DCR MINING PLAN AVAILABLE Highly Reduced Electricity Fee $0.067/T/DAY!
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1558426083
Hero Member
*
Offline Offline

Posts: 1558426083

View Profile Personal Message (Offline)

Ignore
1558426083
Reply with quote  #2

1558426083
Report to moderator
1558426083
Hero Member
*
Offline Offline

Posts: 1558426083

View Profile Personal Message (Offline)

Ignore
1558426083
Reply with quote  #2

1558426083
Report to moderator
TheArchaeologist
Member
**
Offline Offline

Activity: 84
Merit: 84

Learn from the Past!


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.

odolvlobo
Legendary
*
Offline Offline

Activity: 2492
Merit: 1313



View Profile
August 30, 2018, 02:51:08 AM
Merited by Foxpup (3), TheArchaeologist (2), ETFbitcoin (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;
}


Buy bitcoins with cash from somebody near you: LocalBitcoins
Buy stuff on Amazon at a discount with bitcoins or convert Amazon points to bitcoins: Purse.io
Join an anti-signature campaign: Click ignore on the members of signature campaigns.
TheArchaeologist
Member
**
Offline Offline

Activity: 84
Merit: 84

Learn from the Past!


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
mocacinno
Legendary
*
Online Online

Activity: 1582
Merit: 1584


https://unblur.ninja =>lightning network testsite


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)

TheArchaeologist
Member
**
Offline Offline

Activity: 84
Merit: 84

Learn from the Past!


View Profile WWW
August 30, 2018, 07:50:48 AM
Last edit: August 30, 2018, 09:43:00 AM by TheArchaeologist
Merited by 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.
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
Hero Member
*****
Offline Offline

Activity: 896
Merit: 1014



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
*
Online Online

Activity: 1582
Merit: 1584


https://unblur.ninja =>lightning network testsite


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)...

TheArchaeologist
Member
**
Offline Offline

Activity: 84
Merit: 84

Learn from the Past!


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

Activity: 896
Merit: 1014



View Profile WWW
August 30, 2018, 10:11:03 AM
Merited by achow101 (2)
 #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:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!