Bitcoin Forum
March 28, 2024, 11:39:16 AM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to generate hashes/getwork from .NET?  (Read 3100 times)
SondreB (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
March 01, 2011, 05:08:22 PM
 #1

Hi all! I've built a simple client that works against the JSON-RPC HTTP endpoint, it works OK. Built it using the HttpClient of Microsoft.Net.Http.dll and extensions in the http://wcf.codeplex.com/ release.

Now the question is, what do I do with the results I get from getwork? Is there are good description on the basics of just building a miner? I'm building this on .NET (C#).

Thanks in advance for any help, I did some searching on the forum but couldn't easily find what I was looking for.
1711625956
Hero Member
*
Offline Offline

Posts: 1711625956

View Profile Personal Message (Offline)

Ignore
1711625956
Reply with quote  #2

1711625956
Report to moderator
1711625956
Hero Member
*
Offline Offline

Posts: 1711625956

View Profile Personal Message (Offline)

Ignore
1711625956
Reply with quote  #2

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

Posts: 1711625956

View Profile Personal Message (Offline)

Ignore
1711625956
Reply with quote  #2

1711625956
Report to moderator
1711625956
Hero Member
*
Offline Offline

Posts: 1711625956

View Profile Personal Message (Offline)

Ignore
1711625956
Reply with quote  #2

1711625956
Report to moderator
1711625956
Hero Member
*
Offline Offline

Posts: 1711625956

View Profile Personal Message (Offline)

Ignore
1711625956
Reply with quote  #2

1711625956
Report to moderator
BitterTea
Sr. Member
****
Offline Offline

Activity: 294
Merit: 250



View Profile
March 01, 2011, 05:25:52 PM
 #2

I was going to try to explain it, but I'd probably get it wrong.

https://en.bitcoin.it/wiki/Block_hashing_algorithm
0x6763
Guest

March 01, 2011, 05:54:45 PM
 #3

If anyone would like to explain the info that the getwork rpc command gives you, here's a page where you can post it: https://en.bitcoin.it/w/index.php?title=Getwork
The explanation of getwork https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list#Full_list (which is just copied from the bitcoin source code) is not very explanatory at all.

I see the block header in the first 80 bytes of the "data", and I see the "target", but I have no idea what the "midstate", last 48 bytes of "data", and "hash1" are for.  The block hashing algorithm is simple, but the info that getwork returns needs more explanation someplace.
SondreB (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
March 01, 2011, 10:02:43 PM
 #4

Neither of those links explains to me the basics of how to build an miner app, which is what I'm trying to do... Any more links?
0x6763
Guest

March 01, 2011, 10:55:12 PM
 #5

You have the json-rpc part done.  The block hashing algorithm explains how to generate a block.  The missing piece is what does all of the information returned from the getwork command mean?  Most of that info is still a mystery to me, which is why I created a link to a wiki page so maybe someone else will explain it there for us.

Otherwise building a miner just means you write a program that calls the getwork command on a bitcoind server and then uses that information as the starting point for generating a block according to the block hashing algorithm linked to above.

I do not believe there are any good explanations of how to build a miner anywhere, yet.  I'm writing a bitcoin client, myself, rather than a miner, so I don't know what some of the getwork information means.

You might have to spend some time digging through the code of some other miners that call the getwork command.  There's a list of 4 different miners down in the "How do I get started?" section of slush's pool page: http://mining.bitcoin.cz/
blap
Newbie
*
Offline Offline

Activity: 51
Merit: 0


View Profile
June 03, 2011, 06:30:03 PM
 #6

if anyone knows how to build a miner, please explain. I think the best is to put a pseudo-code in the wiki after all coments...
kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1024



View Profile
June 03, 2011, 06:43:47 PM
 #7

Just ignore the midstate until you understand the internals of SHA256.

calculate: hash = SHA256(SHA256(data))

If that meets the difficulty, you win!

If not, increment the portion of the data that starts 640 bits in (bytes 76 to 79), and try again.

If the incremented portion overflows, get new work.

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
twmz
Hero Member
*****
Offline Offline

Activity: 737
Merit: 500



View Profile
June 03, 2011, 10:11:08 PM
 #8

You could read this cpu miner C code to learn the algorithm.  It's pretty easy to read:

https://github.com/jgarzik/cpuminer

The algorithm you are looking for is mostly in miner_thread of https://github.com/jgarzik/cpuminer/blob/master/cpu-miner.c and in scanhash_c of https://github.com/jgarzik/cpuminer/blob/master/sha256_generic.c


Was I helpful?  1TwmzX1wBxNF2qtAJRhdKmi2WyLZ5VHRs
WoT, GPG

Bitrated user: ewal.
just_someguy
Full Member
***
Offline Offline

Activity: 125
Merit: 100


View Profile
June 03, 2011, 10:12:54 PM
 #9

Hi all! I've built a simple client that works against the JSON-RPC HTTP endpoint, it works OK. Built it using the HttpClient of Microsoft.Net.Http.dll and extensions in the http://wcf.codeplex.com/ release.

Now the question is, what do I do with the results I get from getwork? Is there are good description on the basics of just building a miner? I'm building this on .NET (C#).

Thanks in advance for any help, I did some searching on the forum but couldn't easily find what I was looking for.

It would probably be best not to try to build one in C# if you want to be mining for profit.
You will be competing with miners running against bare metal gpus.

Second, you would need to port the whole protocol to c# first if you want to actually mine directly from the network.
This is a huge undertaking. Bitcoinj is still working on it and thats being done by people who understand the protocol.

If you really want to see how the mining works you can look at this piece of code from bitcoinj:
http://code.google.com/p/bitcoinj/source/browse/trunk/src/com/google/bitcoin/core/Block.java#203
That part is easy.... its everything going on around it that you have to implement first that will make you pull your hair out.
Raistlan
Newbie
*
Offline Offline

Activity: 10
Merit: 0


View Profile
June 06, 2011, 07:47:11 AM
 #10

Thanks, just_someguy.

It looks like midstate is the optimization I was curious about myself: Since SHA-256 works on 64 Byte chunks at a time, and the first 64 Bytes of the data is constant for a header, it doesn't need to be recalculated when you just increment the nonce, since the nonce is in the second 64 Byte chunk.

The other, smaller optimization I see is that, since the nonce is the 4th byte of the second 64 Byte chunk, as long as the first 3 bytes of that chunk are held constant, the sha256_transform iterations up to when W[3] is referenced will be constant, so those values could be cached for all the nonce values tried on an otherwise constant header.
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!