Bitcoin Forum
December 09, 2016, 02:05:15 AM *
News: Latest stable version of Bitcoin Core: 0.13.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: trying to figure out pool mining algorithm  (Read 1280 times)
sirblade
Newbie
*
Offline Offline

Activity: 6


View Profile
November 20, 2011, 11:24:58 PM
 #1

hi,
 
here is sample minerd solved and I'm trying to duplicate

Code:

JSON protocol response:
{
   "error": null,
   "result": {
      "target": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000",
      "midstate": "2eab9f8470f5bb52c6ff06b5624c2075433e76009595424828d33fce5b41afb7",
      "hash1": "000000000000000000000000000000000000000000000000000000
00000000000000008000000000000000000000000000000000000000000000000000010000",
      "data": "00000001251c6f225f41c2308bb114e6450b2670a49a9134cc6d2ce700000b4400
00000021863d2ba9531e8d51176c58a8b18aaaa2362eef6841bf72761b3786257f4a674ec84e1
51a0e119a0000000000000080000000000000000000000000000000000000000000000000000
0000000000000000000000000000080020000"
   },
   "id": "1"

[2011-11-19 18:47:24]  Proof: 000000006e778f00f9fe8d12b8ad2cce389
eb5b44c97261913eb7d13810261a2
Target: 00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
TrgVal? YES (hash < target)
[2011-11-19 18:47:24] thread 1: 9645836 hashes, 488.45 khash/sec
[2011-11-19 18:47:24] DBG: sending RPC call: {"method": "getwork", "params":
 [ "00000001251c6f225f41c2308bb114e6450b2670a49a9134cc6d2ce700000b440000
000021863d2ba9531e8d51176c58a8b18aaaa2362eef6841bf72761b3786257f4a674ec
84e151a0e119a0d2f93000000008000000000000000000000000000000000000000000
00000000000000000000000000000000000000080020000" ], "id":1}

how come this code:
Code:
import hashlib
header_hex = (
    "01000000" +
    "251c6f225f41c2308bb114e6450b2670a49a9134cc6d2ce700000b4400000000" +
    "21863d2ba9531e8d51176c58a8b18aaaa2362eef6841bf72761b3786257f4a67" +
    "4ec84e15".decode("hex")[::-1].encode("hex") +
    "1a0e119a".decode("hex")[::-1].encode("hex") +
    "0d2f9300".decode("hex")[::-1].encode("hex")
)

header_bin = header_hex.decode('hex')
hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
hash.encode('hex_codec')
print hash[::-1].encode('hex_codec')

prints 3691175a7d3e2fcfa79d89781fce5615db1c9f2ab2fc422784fd9de9dcf00fa2

instead of 000000006e778f00f9fe8d12b8ad2cce389eb5b44c97261913eb7d13810261a2

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

Posts: 1481249115

View Profile Personal Message (Offline)

Ignore
1481249115
Reply with quote  #2

1481249115
Report to moderator
1481249115
Hero Member
*
Offline Offline

Posts: 1481249115

View Profile Personal Message (Offline)

Ignore
1481249115
Reply with quote  #2

1481249115
Report to moderator
1481249115
Hero Member
*
Offline Offline

Posts: 1481249115

View Profile Personal Message (Offline)

Ignore
1481249115
Reply with quote  #2

1481249115
Report to moderator
sirblade
Newbie
*
Offline Offline

Activity: 6


View Profile
November 22, 2011, 12:22:39 AM
 #2

ok I found I had to do this to the hash from json to get it to be like the hash in blockexplorer

Code:
hash1="251c6f22".decode("hex")[::-1].encode("hex_codec")
hash2="5f41c230".decode("hex")[::-1].encode("hex_codec")
hash3="8bb114e6".decode("hex")[::-1].encode("hex_codec")
hash4="450b2670".decode("hex")[::-1].encode("hex_codec")
hash5="a49a9134".decode("hex")[::-1].encode("hex_codec")
hash6="cc6d2ce7".decode("hex")[::-1].encode("hex_codec")
hash7="00000b44".decode("hex")[::-1].encode("hex_codec")
hash8="00000000"

but it still doesn't give the correct proof of work. In puddinpop's program he only gives 4 bytes to Merkle root instead of 32, maybe is this why?
kano
Legendary
*
Offline Offline

Activity: 1932


Linux since 1997 RedHat 4


View Profile
November 24, 2011, 02:57:44 AM
 #3

Either a byte order or number order problem - the 4 byte hash codes are reversed for the previous and the merkl
i.e. you hash the prev 00000000 on the end (as would appear oyou are doing)
but all 20 4 byte numbers (they are all 4 bytes numbers) are also byte swapped
The first 4 hash bytes are 01 00 00 00 (which is the number '1' or 0x00000001)

Pool: https://kano.is BTC: 1KanoiBupPiZfkwqB7rfLXAzPnoTshAVmb
CKPool and CGMiner developer, IRC FreeNode #ckpool and #cgminer kanoi
Help keep Bitcoin secure by mining on pools with Stratum, the best protocol to mine Bitcoins with ASIC hardware
sirblade
Newbie
*
Offline Offline

Activity: 6


View Profile
November 24, 2011, 03:01:19 AM
 #4

Either a byte order or number order problem - the 4 byte hash codes are reversed for the previous and the merkl
i.e. you hash the prev 00000000 on the end (as would appear oyou are doing)
but all 20 4 byte numbers (they are all 4 bytes numbers) are also byte swapped
thank you thank you,

can you show python (or other) code that calculates the midstate and the new hash given the nonce from the example above? I don't understand concept too good, I understand examples better Sad
sirblade
Newbie
*
Offline Offline

Activity: 6


View Profile
November 25, 2011, 02:43:38 AM
 #5

even easier,

given:
Code:
Proof: 000000006e778f00f9fe8d12b8ad2cce389eb5b44c97261913eb7d13810261a2
sending RPC call: {"method": "getwork",
"params": [ "00000001251c6f225f41c2308bb114e6450b2670a49a9134cc6d2ce7
00000b440000000021863d2ba9531e8d51176c58a8b18aaaa2362eef6841bf72761b
3786257f4a674ec84e151a0e119a0d2f930000000080000000000000000000000000
0000000000000000000000000000000000000000000000000000000080020000" ], "id":1}

nonce above is 0d2f9300

shouldn't then
Code:
hash256(
 hash256(
00000280000000000000000000000000000000000
0000000000000000000000000000000000000000000000080000000
00932f0d9a110e1a154ec84e674a7f2586371b7672bf4168ef2e36a2a
a8ab1a8586c17518d1e53a92b3d862100000000440b0000e72c6dcc3
4919aa470260b45e614b18b30c2415f226f1c2501000000
     )
   )
== 000000006e778f00f9fe8d12b8ad2cce389eb5b44c97261913eb7d13810261a2
but it doesn't Sad

In other words what should I submit to hash twice function
sirblade
Newbie
*
Offline Offline

Activity: 6


View Profile
November 25, 2011, 03:17:57 AM
 #6

lol finally got it Smiley  Grin

Code:
import hashlib
work="00000001251c6f225f41c2308bb114e6450b2670a49a9134cc6d2ce700000b440000000021863d2ba9531e8d51176c58a8b18aaaa2362eef6841bf72761b3786257f4a674ec84e151a0e119a0d2f9300"
x=""
for i in range(0,len(work),8) :
 x+=(work[i:i+8]).decode('hex')[::-1].encode('hex')

print work
print
print x

x_bin=x.decode('hex')
hash=hashlib.sha256(hashlib.sha256(x_bin).digest()).digest()
print hash.encode('hex')
print hash[::-1].encode('hex')


result is 000000006e778f00f9fe8d12b8ad2cce389eb5b44c97261913eb7d13810261a2

also you have to leave off all the 0's at the end (the part that has 8002 in it)
kano
Legendary
*
Offline Offline

Activity: 1932


Linux since 1997 RedHat 4


View Profile
November 25, 2011, 04:47:23 AM
 #7

As I said ... 20 4 byte numbers

or ... 80 bytes

Pool: https://kano.is BTC: 1KanoiBupPiZfkwqB7rfLXAzPnoTshAVmb
CKPool and CGMiner developer, IRC FreeNode #ckpool and #cgminer kanoi
Help keep Bitcoin secure by mining on pools with Stratum, the best protocol to mine Bitcoins with ASIC hardware
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!