Bitcoin Forum
April 28, 2024, 09:54:17 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: I left this one Final Bit to understanding Bitcoin Mining Programming, Help  (Read 493 times)
Toddler (OP)
Newbie
*
Offline Offline

Activity: 10
Merit: 0


View Profile
April 14, 2013, 06:41:28 PM
 #1

Hi,

I am very close to figuring this whole Bitcoin mining help and I just need one last push in the right direction.

I am able to retrieve all these data:

midstate= "8147d1c8a775b41fe2fc710128f760ee61eed0022fd13fe4e0b0197dfe87cee1";
data = "000000029af1f43c342ad525e3c4fd9368a76fbe32a2bfc1d5503b6c0000007600000000e5a720f 8ec330f06fab42bb92f24d5d4211002bb202beb163fbeed28123f8e235166d77c1a022fbe000000 0000000080000000000000000000000000000000000000000000000000000000000000000000000 0000000000080020000";
hash1 = "0000000000000000000000000000000000000000000000000000000000000000000000800000000 0000000000000000000000000000000000000000000010000";
target = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000";

And I also manage to calculate out the correct nonce for it which in this case is: 635141297.

Now my question is, how do I send this "635141297" to the pool ?
How do I hash it so that it is in the form that the pool can accept ?
The network tries to produce one block per 10 minutes. It does this by automatically adjusting how difficult it is to produce blocks.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714298057
Hero Member
*
Offline Offline

Posts: 1714298057

View Profile Personal Message (Offline)

Ignore
1714298057
Reply with quote  #2

1714298057
Report to moderator
1714298057
Hero Member
*
Offline Offline

Posts: 1714298057

View Profile Personal Message (Offline)

Ignore
1714298057
Reply with quote  #2

1714298057
Report to moderator
1714298057
Hero Member
*
Offline Offline

Posts: 1714298057

View Profile Personal Message (Offline)

Ignore
1714298057
Reply with quote  #2

1714298057
Report to moderator
shibaji
Full Member
***
Offline Offline

Activity: 308
Merit: 102



View Profile
April 14, 2013, 06:45:00 PM
 #2

Good job! :-)
Toddler (OP)
Newbie
*
Offline Offline

Activity: 10
Merit: 0


View Profile
April 14, 2013, 07:20:14 PM
 #3

Thanks for the encouragement shibaji.

Is this the Hash I should sent ?
ea74ac6a11610a7471d84291759c11db1e57bfe53cc88e7a935729f000000000


To Recap, I have built a program that successful Retrieve:
midstate= "8147d1c8a775b41fe2fc710128f760ee61eed0022fd13fe4e0b0197dfe87cee1";

data = "000000029af1f43c342ad525e3c4fd9368a76fbe32a2bfc1d5503b6c0000007600000000e5a720f 8ec330f06fab42bb92f24d5d4211002bb202beb163fbeed28123f8e235166d77c1a022fbe000000 0000000080000000000000000000000000000000000000000000000000000000000000000000000 0000000000080020000";

hash1 = "0000000000000000000000000000000000000000000000000000000000000000000000800000000 0000000000000000000000000000000000000000000010000";

target = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000";

I also successful Calculated that the nonce for this instance is: 635141297.

The Question now is, is my resulting calculated Hash to be send to getwork correct ?
This:
ea74ac6a11610a7471d84291759c11db1e57bfe53cc88e7a935729f000000000

Please someone help me, this is my final hurdle to finally understanding the algorithm once and for all.
Toddler (OP)
Newbie
*
Offline Offline

Activity: 10
Merit: 0


View Profile
April 14, 2013, 07:52:01 PM
 #4

I tried formatting the result as:

{"method":"getwork","params":["ea74ac6a11610a7471d84291759c11db1e57bfe53cc88e7a935729f000000000"],"id":1}


But something is wrong...the params shouldn't be this short...what did I left out ?

I am so close, please help me understand this.
deepceleron
Legendary
*
Offline Offline

Activity: 1512
Merit: 1028



View Profile WWW
April 14, 2013, 08:43:45 PM
 #5

You can look at the references:

https://bitcointalk.org/index.php?topic=120960.0 - has examples of getwork submissions

Here's an old post, follow for more info:
scanhash_c in https://github.com/jgarzik/cpuminer/blob/master/sha256_generic.c shows midstate and hash1 being used.

Basically, there are 3 chunks that the sha256_transform function in that file is called for per "nonce" value. [Here is the header definition from https://en.bitcoin.it/wiki/Block_hashing_algorithm:]

FieldPurposeUpdated when...Size (Bytes)
VersionBlock version numberYou upgrade the software and it specifies a new version4
Previous hashHash of the previous blockA new block comes in32
Merkle root256-bit hash based on all of the transactionsA transaction is accepted32
TimestampCurrent timestampEvery few seconds4
"Bits"Current target in compact formatThe difficulty is adjusted4
Nonce32-bit number (starts at 0)A hash is tried (increments)4


You are getting a block header, changing the nonce, and returning the hash of it you found which is below the target.

Note that special transforms have to be done before hashing (and then back before submitting results). Endian-ness of data needs to be flipped in 4 byte increments before hashing.

Header contents from your data (hashes are reversed):
Code:
000000029af1f43c342ad525e3c4fd9368a76fbe32a2bfc1d5503b6c00000076
00000000e5a720f8ec330f06fab42bb92f24d5d4211002bb202beb163fbeed28
123f8e235166d77c1a022fbe0000000000000080000000000000000000000000
0000000000000000000000000000000000000000000000000000000080020000

Version: 00000002
00000002 9af1f43c342ad525e3c4fd9368a76fbe32a2bfc1d5503b6c00000076

Previous hash: 0000000000000076d5503b6c32a2bfc168a76fbee3c4fd93342ad5259af1f43c
(block 230829)
00000002 9af1f43c342ad525e3c4fd9368a76fbe32a2bfc1d5503b6c00000076
00000000
e5a720f8ec330f06fab42bb92f24d5d4211002bb202beb163fbeed28

Merkle root: 123f8e23fbeed2802beb16311002bb2f24d5d42ab42bb92c330f06fe5a720f8e
00000000 e5a720f8ec330f06fab42bb92f24d5d4211002bb202beb163fbeed28
123f8e23
5166d77c1a022fbe0000000000000080000000000000000000000000

Timestamp: 51 66 d7 7c (1365694332 unix epoch time)
123f8e23 5166d77c 1a022fbe0000000000000080000000000000000000000000

bits (Compact target): 1a 02 2f be
123f8e235166d77c 1a022fbe 0000000000000080000000000000000000000000

nonce: the value your miner will be changing
123f8e235166d77c1a022fbe 00000000 00000080000000000000000000000000


the data1 midstate should be ignored and calculated by your miner, newer mining protocols remove this.
turtle83
Sr. Member
****
Offline Offline

Activity: 322
Merit: 250


Supersonic


View Profile WWW
April 14, 2013, 09:05:56 PM
 #6


Looking thru https://github.com/bitcoin/bitcoin/blob/master/contrib/pyminer/pyminer.py#L147

it seems this is what you should send :-

{"method":"getwork","params":["000000029af1f43c342ad525e3c4fd9368a76fbe32a2bfc1d5503b6c0000007600000000e5a720f 8ec330f06fab42bb92f24d5d4211002bb202beb163fbeed28123f8e235166d77c1a022fbe25db7c b100000080000000000000000000000000000000000000000000000000000000000000000000000 0000000000080020000"],"id":1}

#Convert your integer to binary first
nonce_bin = bufreverse(nonce_bin) #reverse it
nonce = nonce_bin.encode('hex') #Get the hex
solution = original_data[:152] + nonce + original_data[160:256] #Mash it with original.


Toddler (OP)
Newbie
*
Offline Offline

Activity: 10
Merit: 0


View Profile
April 15, 2013, 03:10:46 AM
 #7

Wow....Endian...why....WHY DO YOU DO THIS DO ME Mr. Endian! ;p

Anyway, is my lash hash incredibly wrong ?
ea74ac6a11610a7471d84291759c11db1e57bfe53cc88e7a935729f000000000

I don't see what I have generated in any of the suggested send data, this sequence of data is not even embed in anyway Sad

Am I that far off ?
Is my Nonce calculation even correct ?
Toddler (OP)
Newbie
*
Offline Offline

Activity: 10
Merit: 0


View Profile
April 15, 2013, 05:13:49 AM
 #8

From what I learn from Luke-Jr in the IRC, the result seems to be:

000000029af1f43c342ad525e3c4fd9368a76fbe32a2bfc1d5503b6c0000007600000000e5a720f 8ec330f06fab42bb92f24d5d4211002bb202beb163fbeed28123f8e235166d77c1a022fbe635141 2970000080000000000000000000000000000000000000000000000000000000000000000000000 0000000000080020000

Is this right ?

Basically, it's the first 152 Characters from Data + Solved Nonce + The rest of the Source Data [Minus the Space taken up by the Nonce].
deepceleron
Legendary
*
Offline Offline

Activity: 1512
Merit: 1028



View Profile WWW
April 15, 2013, 06:06:02 AM
 #9

You can check out the python miner as a reference, which does all it's hashing in software. https://github.com/jgarzik/pyminer

Technically, if it didn't take you about 30000000000000000 hashes to find a valid nonce, its not really a block hash..
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!