Saturday, November 30, 2013

Bitcoin mining

For fun, I just put together a Bitcoin mining machine! The machine does brute-force calculations to try to solve the mathematical problem of what input (random string), in combination with the current Bitcoin block header (that contains a list of transactions) will produce the desired output, a series of numbers that starts with a bunch of zeroes. As an example, here is a script that will calculate the hash of Bitcoin Block number 125552:

import hashlib
header_hex = ("01000000" +
"81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +
"e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +
"c7f5d74d" +
"f2b9441a" +
"42a14695")
header_bin = header_hex.decode('hex')
hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
hash.encode('hex_codec')
testblock=hash[::-1].encode('hex_codec')
print "The hash of block 125552: ", testblock;


I got this from here https://en.bitcoin.it/wiki/Block_hashing_algorithm . You can test this script for yourself by pasting and executing it here: http://www.compileonline.com/execute_python_online.php Note that the first few digits of the resulting hash are zeroes, which is the criteria for mining a new block. This block was mined by trying numbers in the place of the '42a14695' until one of them worked. Note that the number 2504433986 is 9546A142 in hexadecimal, which becomes 42a14695 when re-arranged between little and big endian. So we can speculate that perhaps the miner had to try more than 2 billion combinations before finding the one that worked! All the current Bitcoin miners in the network are brute-force trying numbers, hoping to get lucky and collect the 25 Bitcoin reward. By performing this work, miners verify that the transactions are valid and secure the network as a whole since other miners scrutinize the block header looking for any mistakes that would invalidate it and prevent it from being widely accepted.
The mining setup that I built uses an ASICMiner Erupter Blade. I mounted the Blade in an old broken lab power supply that had a working fan in it already. The power supply is a 12V 10A LED power supply. I read some reports of the wires overheating so I went overkill and put some super beefy wires (AWG 8) between the power supply and the Blade. It took a lot of tinkering to set up. Eventually I settled on using 32 bit bfgminer since it has built in stratum proxy capability. I ran it with "bfgminer --http-port 8330" where I configured the Blade through a browser at 192.168.1.254:8000/Main as follows:

UPDATE: I created a .bat file, and put a shortcut to it in my startup folder. Now, everytime I start up my computer, it automatically starts mining. I had to set the properties of the shortcut to run as administrator in order for it to work. The bat file contains:
"cd Desktop/bfgminer-3.7.0-win32
bfgminer --http-port 8330 -o stratum.btcguild.com:3333 -u username -p 123"

Currently, the device mines approximately 293 micro-BTC/hr, but this is likely to decrease in the near future with faster mining machines. Update: down to 99 micro-BTC/hr :(

Update: I stopped mining because electricity costs became greater than the mining reward!

Comments/questions welcome! And of course donations :) 1EXhFqvXkwcXRfhUxmbaUSZgLhGCsWsUcu

1 comment:

  1. Did you think about using the most recommended Bitcoin exchange company: YoBit.

    ReplyDelete