Bitcoin Forum
June 23, 2018, 01:01:27 PM *
News: Latest stable version of Bitcoin Core: 0.16.1  [Torrent]. (New!)
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Calculating Difficulty from Getwork "Target" Value  (Read 1282 times)
BinaryMage
Hero Member
*****
Offline Offline

Activity: 560
Merit: 500


Ad astra.


View Profile
April 02, 2013, 09:02:21 AM
 #1

According to the wiki, difficulty can be calculated by dividing the maximum target by the current target.

However, I'm unclear on how exactly the target value returned from a getwork call is encoded (and more importantly, how it should be de-encoded to calculate difficulty using this method).

Do I simply swap it to little-endian (and if so, how?), or is there a more complicated process?

Example code (Python) using the current target:

Code:
>> target = "00000000000000000000000000000000000000000000006e8102000000000000"
>> target = process(Target)
>> maxtarget = "00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
>> difficulty = int(maxtarget, 16) / int(target, 16)
>> print difficulty
6695826

Any advice would be appreciated.

-- BinaryMage -- | OTC | PGP
1529758887
Hero Member
*
Offline Offline

Posts: 1529758887

View Profile Personal Message (Offline)

Ignore
1529758887
Reply with quote  #2

1529758887
Report to moderator
1529758887
Hero Member
*
Offline Offline

Posts: 1529758887

View Profile Personal Message (Offline)

Ignore
1529758887
Reply with quote  #2

1529758887
Report to moderator
The World's Betting Exchange

Bet with play money. Win real Bitcoin. 5BTC Prize Fund for World Cup 2018.

Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1529758887
Hero Member
*
Offline Offline

Posts: 1529758887

View Profile Personal Message (Offline)

Ignore
1529758887
Reply with quote  #2

1529758887
Report to moderator
1529758887
Hero Member
*
Offline Offline

Posts: 1529758887

View Profile Personal Message (Offline)

Ignore
1529758887
Reply with quote  #2

1529758887
Report to moderator
1529758887
Hero Member
*
Offline Offline

Posts: 1529758887

View Profile Personal Message (Offline)

Ignore
1529758887
Reply with quote  #2

1529758887
Report to moderator
BinaryMage
Hero Member
*****
Offline Offline

Activity: 560
Merit: 500


Ad astra.


View Profile
April 02, 2013, 09:25:16 AM
 #2

Simply swapping to little-endian does the trick.

For reference:

Code:
>> target = "00000000000000000000000000000000000000000000006e8102000000000000"
>> target = target.decode('hex')
>> target = target[::-1]
>> target = target.encode('hex')
>> maxtarget = "00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
>> difficulty = int(maxtarget, 16) / int(target, 16)
>> print difficulty
6695928 # Slightly different because I'm using the non-truncated maximum target

-- BinaryMage -- | OTC | PGP
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!