This is quite possibly the most brilliantly useless bitcoin mining rig ever created.

Mersenne from Something Awul turned us on to this hilariously useless but kinda neat project.

So apparently some guy developed a hilariously roundabout method for mining Bitcoins on a NES.

 

nes-bitcoin-miner
Of course, like most things Bitcoin, this is only technically true:

*Communication with the Bitcoin network

This part is pretty simple. I’m using bitcoind to do the network communication. This is pretty standard for bitcoin mining, the mining software focuses on doing the hashing and lets bitcoind do the p2p network stuff. There’s a few standard protocols for those two pieces to communicate with varying levels of efficiency, but I’m using the most basic ‘getwork’ protocol because, heh, this isn’t going to be the bottleneck in this operation.

For the portions of computing that do not happen on the NES, I’ve got a raspberry pi housed in a Makerbot Replicator2 3D printed case. I believe I am now fully 2013 Hack Project compliant.

Raspian’s repos were serving some crusty version of arm bitcoind, so I compiled my own from the latest source. This is not hard, except that my rpi has 256MB of RAM and g++ just gives up when its all filled up. I’m sure there’s a more elegant cross-compilation environment available, but adding a 2GB swap and letting it crank all night worked for me.

*Data in

There are a couple pieces involved in getting data into the NES, many of which I’m just pasting together from other people’s code. They deserve the credit for their respective projects.

First, I’m using a python implementation of the mining protocol by jgarzik (https://github.com/jgarzik/pyminer) to do the jsonrpc communication out to bitcoind and basic structure.

Next, I’m using a NES that I modified with a USB CopyNES (http://www.retrousb.com/product_inf…&products_id=36). Inserting this board inbetween the NES’s mainboard and processor adds a USB port to an NES that affords for lots of development capability, including the ability to write to RAM carts. The RAM cart I’m using is a PowerPak Lite, also from retrousb.com (http://www.retrousb.com/product_info.php?products_id=35)

For the USB serial communications to the NES I’ve gutted and hacked up mstrand’s script (https://github.com/mstrand/copynes)

So the rpi getworks a chunk of data, wraps it up into a ROM (detailed below), and sends it to the console using via USB CopyNES.

*Doing the hashing

SHA256 hashing uses many 32-bit operations, and the 6502 in the NES is an 8-bit CPU. Initially I thought this would be a significant challenge, but with some modifications, I got an open implementation of SHA256 to compile to a 6502 target using the cc65 compiler (cc65.org)

The rpi getworks a chunk of data, compiles it into a ROM that includes the SHA256 algo and current target data, and sends it to the console via USB CopyNES.

Each ROM computes and tests a single hash.

*Data Out

After the NES computes and tests the hash against the target value, the NES knows if this iteration was a success. But we need to pass successes back out to the bitcoin network.

If the generated hash is less than the target value, the background color of the screen will be green, otherwise it will be red. A Playstation Eye camera pointed at the screen takes a picture and, using OpenCV, checks for the predominant color in the image.

If there’s more green than red in the picture that the webcam snaps then it gets reported out to the bitcoin network as a success. If not, then we start the process over again with a freshly grabbed chunk of getwork data.

(emphasis mine)

So to recap: This guy is using a Raspberry Pi to pull transaction data from the network, packs it into a ROM containing a built-in SHA256 implementation and a single hash, and copies it via USB into a flashcart. The NES then computes and displays the result, and depending on the background color the webcam pointed at the screen reports this result back to the network as either a success or failure.

Again, all of this is for a single hash.

It’s even better once you actually see the thing running in that video he posted. If you count the time between screen refreshes, that setup is chugging along at approximately five hashes a minute, or 0.083 hash/sec.

At the current difficulty level, the average time per block would be 10,987,004,979 years, or more than twice the age of the earth. Truly the next generation of mining rigs!