Author

Topic: PURE Java Miner (Read 3646 times)

newbie
Activity: 28
Merit: 0
April 30, 2013, 10:13:06 AM
#8
compagnio my university is trying to do something like this in ruby, java in your library that uses?
sr. member
Activity: 399
Merit: 250
April 30, 2013, 07:34:03 AM
#7
If you dig about on 'github' you will find miners for both Bitcoin & litecoin in Java.

The litecoin one is  *very* badly implemented, threads are setup incorrectly. Whoever wrote it had little knowledge of how java  'implements' objects. (it actually looks like it is from a c implementation.)

But the implementations are fairly clear.

hero member
Activity: 718
Merit: 545
April 29, 2013, 01:34:15 PM
#6
Thank you.. I think I get it now..
legendary
Activity: 1232
Merit: 1094
April 29, 2013, 01:00:35 PM
#5
So - because it's total POT luck if you get the correct HASH.. It doesn't matter what search space you try as long as you keep trying.. i see..

yeah

Quote
THEN - Why is the NONCE not reset to 0, whenever the MerkleRoot or the Timestamp changes ? Can it be ?

Yes, you can use any nonce you want.  It is incremented by 1 so as to make things easy.  Also, it allows pools to ask different people to do different ranges.

Quote
& Just for completeness, am I correct in assuming IF the nonce was of variable length, you would not need the extraNonce in the coinbase txn ?

Yes.  In fact, if they just went for a 64-bit fixed number, then it is unlikely that it would be an issue.
hero member
Activity: 718
Merit: 545
April 29, 2013, 12:44:35 PM
#4
Quote
It doesn't work that way.  If you test a hash and it fails, then that work is already lost.

It is like rolling 10 dice and hoping for all 6's.  If you do it a million times, and haven't succeeded, all that work is already gone.

Each time you update the nonce and fail, you are trying a whole new attempt.

So - because it's total POT luck if you get the correct HASH.. It doesn't matter what search space you try as long as you keep trying.. i see..

THEN - Why is the NONCE not reset to 0, whenever the MerkleRoot or the Timestamp changes ? Can it be ?

& Just for completeness, am I correct in assuming IF the nonce was of variable length, you would not need the extraNonce in the coinbase txn ?

Just want to make sure I fully understand what's going on..  Roll Eyes
legendary
Activity: 965
Merit: 1000
April 29, 2013, 08:51:46 AM
#3
I think Java is great, but Java in webpages is a bit dead these days? If it has to work on a webpage, I would use Javascript?
legendary
Activity: 1232
Merit: 1094
April 29, 2013, 08:27:22 AM
#2
Hello,

I am trying to write a pure JAVA miner, a nice webstart app or applet that can be embedded in webpages, and wanted to clarify my understanding of how things work..

1) If when I add a transaction to my current block, the Merkle Root (of all the transactions) in the Block Header changes, doesn't that mean that ALL the work i have done before is for nothing as I will have to start looking for the correct HASH again ? Wouldn't it be better to not add more transactions, and keep working on my current block, with the current Merkle Root ?

It doesn't work that way.  If you test a hash and it fails, then that work is already lost.

It is like rolling 10 dice and hoping for all 6's.  If you do it a million times, and haven't succeeded, all that work is already gone.

Each time you update the nonce and fail, you are trying a whole new attempt.

Quote
2) This may be answered by the answer to 1), but just in case - Since you get 25 btc for finding a block, much more than you make from the transaction fees, Why not just work soley on finding hashes of blocks with no transactions in it ? This way your Merkle root stays constant until you need to use the extraNonce in the coinbase txn ?  Would this not give you the greatest chance of finding a valid hash of a certain difficulty ?

That is anti-social.  However, it would work.  There is talk of putting in some ways to deal with it, if it became a problem.

Quote
3) In the Bitcoin Protocol Wiki it says -

'The SHA256 hash that identifies each block (and which must have a run of 0 bits) is calculated from the first 6 fields of this structure (version, prev_block, merkle_root, timestamp, bits, nonce, and standard SHA256 padding, making two 64-byte chunks in all) and not from the complete block. To calculate the hash, only two chunks need to be processed by the SHA256 algorithm. Since the nonce field is in the second chunk, the first chunk stays constant during mining and therefore only the second chunk needs to be processed..'

This I don't get.. Where do the 2 * 64 Byte Chunks come from ? When I Hash my Block Header I get a 32 byte hash.. ?

Sha-2 works on 512 bit "chunks".  When hashing a file, it is padded so that it is an integer multiple of 512.

So, since it is double sha-2

First call to the sha function

Sha2(header)
This is > 64 bytes, so extend to 2X64 bytes
Round 1: bytes 0 to 63 of the header
Round 2: 64 - 79 of the header (the nonce is here)

Sha2(output from round 1)
This is 32 bytes, so it is padded to 64 bytes
Round 1: bytes 0 to 63 of the padded output

The output of the 2nd call is the hash of the header.

Since the nonce is in the first round of the first sha2 call, you can compute it once and save the state.  Each time you change the nonce, it only changes the results from round 2 onwards.
hero member
Activity: 718
Merit: 545
April 29, 2013, 07:49:43 AM
#1
Hello,

I am trying to write a pure JAVA miner, a nice webstart app or applet that can be embedded in webpages, and wanted to clarify my understanding of how things work..

1) If when I add a transaction to my current block, the Merkle Root (of all the transactions) in the Block Header changes, doesn't that mean that ALL the work i have done before is for nothing as I will have to start looking for the correct HASH again ? Wouldn't it be better to not add more transactions, and keep working on my current block, with the current Merkle Root ?

2) This may be answered by the answer to 1), but just in case - Since you get 25 btc for finding a block, much more than you make from the transaction fees, Why not just work soley on finding hashes of blocks with no transactions in it ? This way your Merkle root stays constant until you need to use the extraNonce in the coinbase txn ?  Would this not give you the greatest chance of finding a valid hash of a certain difficulty ?

3) In the Bitcoin Protocol Wiki it says -

'The SHA256 hash that identifies each block (and which must have a run of 0 bits) is calculated from the first 6 fields of this structure (version, prev_block, merkle_root, timestamp, bits, nonce, and standard SHA256 padding, making two 64-byte chunks in all) and not from the complete block. To calculate the hash, only two chunks need to be processed by the SHA256 algorithm. Since the nonce field is in the second chunk, the first chunk stays constant during mining and therefore only the second chunk needs to be processed..'

This I don't get.. Where do the 2 * 64 Byte Chunks come from ? When I Hash my Block Header I get a 32 byte hash.. ?

..

I will be presenting my work as soon as it is more than nothing..  Grin

Thank You!

Jump to: