A gentle introduction to Bitcoin mining

I suppose you have all heard of Bitcoin (BTC), the P2P digital currency. There are basically two ways to get bitcoins: the first one is to exchange money (dollars, euros etc.) for bitcoins, and the second one is to mine. At the time I'm writing this, a bitcoin is worth about $140, and when you mine, you earn (until 2017) 25 BTC for each block you find (at the current rate this equals to $3.5K). In the Bitcoin system, a new block is generated every 10 minutes on average, so if you were the only miner in the world you would earn (at the current rate) about $250K per day. Of course, you are far from being the only miner out there, and finding a new block has recently become very difficult.

Bitcoin mining is the process of finding a nonce for a block such that SHA-256(SHA-256(block, nonce)) <= target. 'nonce' is a 32-bit variable that is regularly incremented; of course at this point much more than 4G hashes are necessary to find a block, so each time nonce overflows the block is modified by incrementing the 'extraNonce' field (which in turn changes the Merkle root of the transaction tree). One property of hashing algorithm (like SHA-256) is that it is infeasible to compute the input that when hashed gives a given hash. On a side note, some algorithms make it reasonably easy to compute an input that gives the same hash as a target hash - with attacks such as collision attack or length extension attack; incidentally, protecting from length-extension attacks is suspected to be the reason behind the double hashing scheme of Bitcoin.

Now that we know more about the mining process, how come it became so difficult? Well the difficulty increases (that is, the target decreases) in order to keep the number of blocks generated at about one every 10 minutes. As more miners joined the game, the difficulty increased; CPUs were soon useless as miners turned to GPUs, which further increased the difficulty, at which point people started using FPGAs to mine. At this point, only Application-Specific Integrated Circuits (ASICs) are now competitive enough in terms of hashes per watt to earn more money than spent on electricity :mrgreen: They say Get rich or die mining, and just so you know we are just past 50% of the Bitcoin supply, so I guess it's more than time to design your own ASIC!

Please read the next post if you'd like to know how to do that :-)