Zero to One of Crypto Mining

Michael Xia
FPGA Mining
Published in
16 min readApr 6, 2018

here are the basics to help you get started

unfortunately this article is now very outdated. please check out https://fpga.guide/

I started looking into mining in May 2016 and found myself pouring over a wide variety of fragmented resources. Wiki pages from some new and old projects, bitcointalk.org forum posts from years ago (and the infamous 10000 BTC for pizza🍕post), how to articles from PCMag, linux mailing lists, etc.

Slowly things started to make sense. My hope is that this post can help the growing blockchain community understand Proof of Work (POW) mining, the ever changing economics, and lower the barrier to participation for beginners or non-engineers.

What is mining ⛏️?

We start with a transaction where I send my friend George a Bitcoin to participate in his SuperCoin ICO 🚀🔥. We’ll call it TxMikeToGeorge or TxMG.

TxMG gets sent to the network with a small Tx fee, it will float around the nodes in something called a MemPool. Each node has its own MemPool where unprocessed transactions hang out. Each node wants to write transactions from it’s MemPool to the blockchain. By processing a transaction and writing it into a block, a node can claim what is called “the block reward” which is a bit of BTC that’s created from thin air to incentivize miners. So who gets to write their transactions onto the chain and claim this block reward?

This is where mining comes in.

In order to write to the blockchain, you must have a valid hash or winning ticket. The winning ticket lets you write transactions from your MemPool to the block, claiming the transaction fees that everyone submitted (ie. from TxMG), and the block reward.

1x Winning Ticket = Block Reward + Tx Fees

there’s a winner somewhere…

Mining is the process of running a POW algorithm and looking for that winning ticket. Miners run the POW algorithm on loop and you usually go through a lot of duds.

An example Bitcoin SHA256 hash is:

514b63d6567afeaf7ca053742f754ec4b0c2b05287c6d00a62b13de775437798

For the power ball the winning ticket matches certain numbers. But for miners, the winning ticket is an output of the hashing algorithm, whose ending is within an acceptable “difficulty target”. For example, lets imagine the target is 8291, and the ending of our hash is 7798 from above.

18 14 … blah … 75 43 [77 98] is a winning ticket since 7798 < 8291
81 90 … blah … 41 22 [48 13] also a winning ticket since 4813 < 8291
47 11 … blah … 41 22 [90 11] dud because 9011 > 8291

The more computers you have, the faster you can guess lottery numbers, the sooner you find a winning ticket that falls within the accepted difficulty target, the more transactions you get to process, the more block rewards and transaction fees you get to earn as a miner.

But what happens if everyone starts to mine? We can’t just give a golden ticket out every few seconds, willy’s factory would run out of chocolate and we’d run out of BTC.

The concept of an adjusting difficulty is introduced to make it harder to find golden tickets if too many people are looking for one. The Bitcoin network adjusts the winning number range, making them smaller and smaller to optimize for a steady rate at which block rewards are given known as “block time”. Currently BTC has 1 block per 10 minutes, this 10 minute block time was simply picked by the developers, other coins have faster or slower block times. It’s as if Willy Wonka released a golden ticket every 10 minutes.

This means everyone is competing for the same block reward that comes every 10 minutes.

Contrary to popular belief, more miners does not mean more bitcoins created, in fact more miners means fewer bitcoins for each miner. Fewer miners does not mean slower transactions either, it stays at the same pace, one block of transactions every 10 minutes. (For example, this vice article makes a common mistake)

Hence there is an arms race to powerful hardware that mines faster. For slower miners who have little to no chances of finding a valid lottery ticket, they band together to Mining Pools and share the profits. We’ll go into detail for both hardware and pooling in the following sections.

The 4 Types of Mining Hardware

Hardware and Algorithms are heavily intertwined.

There are 4 main types of hardware for mining and a long list of algorithms that blockchains use for securing their protocol. Each algorithm has different properties that determine what kind of hardware can run them efficiently, and what it costs in terms of system resources.

The main hardware types are:

  1. ASIC: chips designed for mining, generally the fastest, high R&D and manufacturing cost.
  2. FPGA: reprogrammable chips, slower than ASICs but generally faster than GPUs.
  3. GPU: designed for graphics, but fast thanks to many cores and high memory bandwidth.
  4. CPU: flexible compute, but the slowest horse in the mining race.

An Example in BTC mining

To illustrate an example of ASICs and how they impact the ecosystem, see the below comparison for bitcoin mining (Feb 11, 2018).

AntMiner S9 ASIC Mining Bitcoin SHA256 costs $2500 USD. 14 x 10¹² hashes a second (14 TH/s). This is roughly $10.27 a day, which means 8.3 months later you recoup your investment. This is the most popular ASIC developed and manufactured by Bitmain.

NVIDIA Tesla S2070 GPU Mining Bitcoin SHA256 costs $500 USD. 750 x 10⁶ hashes a second (750 MH/s). This is roughly -$0.15 a day due to power costs of running the GPU being much greater than the value of any BTC you might happen to mine.

So why is the GPU not profitable when mining BTC? It’s a powerful device, and GPUs were very profitable many years ago, before ASICs entered the market.

Because everyone is competing for the same golden ticket or block reward that happens every 10 minutes, only the fastest hardware wins, and it becomes statistically meaningless to compete if you are magnitudes slower than the fastest competitor, which is in the case of ASICs vs GPUs.

ASICs effectively push out all other hardware (FPGA, GPU, CPU) from the race, slowly the only people mining BTC will be people who buy and run ASICs.

If I ran 1x Antminer ($2.5k) and 19000x NVIDIA Tesla S2070 GPU ($9.5M) were competing against me, I would get half the BTC block rewards, and the other half would be split between the GPU miners. You can see how very quickly the economics for GPU miners made no sense, and they either went elsewhere or invested in ASICs.

So where do the GPU miners go?

They started mining other coins like Monero, Ethereum, Zcash, etc. Because ASICs destroyed the profitability of GPU miners in BTC, they had to mine different a coin. But why doesn’t the ASIC miners target other coins as well?

ASICs are built to run a single algorithm very quickly on a silicon chip, it can only run that one algorithm. so an ASIC for bitcoin’s SHA256 algorithm cannot run Monero’s Cryptonight algorithm. Why doesn’t Bitmain create an ASIC for Cryptonight?

The Cryptonight POW isn’t as simple as the SHA256 POW.

It requires you generate a 2MB scratch pad of pseudo random data, run a series of hashing algorithms on different slices of the scratch pad, then compute a final hash that is our lottery ticket. 2MB of memory is a lot to fit onto a chip, and to manufacture at scale, meaning researching and creating ASICs for Cryptonight is far less meaningful economically than say for example SHA256.

Many POW algorithms have this property of requiring a lot of memory known as “Memory Hard” making them “ASIC Resistant”. Without ASICs on the market, the next fastest hardware (GPUs) are then used for mining.

Thanks to ASIC resistant algorithms, all the contestants for these other coins are running GPUs, meaning GPU miners compete on fair footing and get a reasonable rewards. But if an ASIC is created for any of these coins, that would change very quickly.

The takeaway?

Algorithms matter a lot as it will define who will mine your coin and what hardware they use to mine it. POW algorithms have an important role of securing your protocol, deciding who can participate in mining, and what kind of economics miners will see. Luckily most algorithms today have converged on GPUs, meaning if you invest in the hardware as a miner, you do have a good amount of optionality which we’ll go into detail below.

Algorithms and their many many many Coins.

POW algorithms are not a dime a dozen, these algorithms require cryptographic design and research, but there are an endless number of coins. As a result, multiple coins will start to use the same POW algorithm.

SHA256 is the POW algorithm for Bitcoin and Bitcoin Cash. And a few others that I didn’t even know about. Only ASICs mine these coins now.

Cryptonight is the POW algorithm for Monero, Sumokoin, Karbo, Aeon, Electroneum, etc. It’s ASIC resistant and very CPU friendly, so mostly GPUs or bot nets mine these.

Ethash is the POW for Ethereum, Ethereuem Classic, and their friends. Also ASIC resistant, so GPUs mine them.

Equihash is the POW for Zcash, BitcoinGold, and friends. Equihash is also ASIC Resistant.

Scrypt is the POW for Lightcoin. Originally intended to be ASIC resistant, but now you can buy ASICs for Scrypt.

X11 is the POW for Dash. ASICs also exist for mining X11 coins.

And that’s only a few of the coins that are out there, there are many many more.

What this means for miners though, is that you have some optionality. If you have a rig that mines one algorithm, ie X11 or Cryptonight, you can switch between any of the coins that use that POW.

  1. If the price drops for token X because the team is in a lawsuit, you can mine token Y which provides higher ROI.
  2. If the difficulty for mining token X increases because more miners want it, you can switch to token Y which has less competition.

This lets you hedge some of your risks as a miner. If you use GPUs that can run multiple algorithms, you have even more optionality. Sometimes even POW algorithms change (ie Monero’s anti-ASIC decision), but you can just update your miner program and continue mining.

Who is mining today?

POW Algorithms are a foundational component in the protocol that shapes what devices will mine a coin and support the protocol, all driven by economic forces.

For example, Bitcoin’s mining difficulty increases by 15% every two weeks, meaning miner revenues are dropping constantly. This is because ASIC manufacturers profit from selling ASIC miners so they’re incentivized to sell as many as possible, and to reduce their margins if people stop buying. Selling ASICs in turn increases the overall networks difficulty, since if you buy an ASIC you’re probably running it 24/7 to get your investment back. Miners with a lot of capital can rent out an entire warehouse, outfit it, fill it to the brim with ASICs,

These big miners have a lot of power and influence on the protocols (which is outside the scope of this post but very very interesting). As a result, many protocols have moved towards GPUs and ASIC Resistant Algorithms to avoid those issues. But when the GPU coins became valuable and the returns looked attractive, people started building multi GPU machines purely meant for mining, buying up large number of GPUs, combining them with crappy CPUs and a little bit of RAM, driving up the prices of GPUS consumers and other miners.

For example, I bought my first set of AMD Vega 64 GPUs for $650 USD each. Now they’re going for as much as $1200 USD each.

That’s if you’re lucky and it’s in stock, most of the time online stores will be out of stock and you’re best chances are to get connected directly to a distributor (or a friend of a friend of a brother of a distributor), and buy in bulk. Even then the prices are not great, and can vary a lot from person to person since every middleman takes a cut, and it requires volume to get a deal.

6000 rmb = 950 USD, batches of 100+
vega56 was originally in the 500–600 range

For miners, supply is the biggest bottleneck, distributors are hard to come by, and they want to find reliable bigger miners to ensure consistent larger orders.

Since revenue scales linearly larger miners with capital can scale up quickly as long as they can handle the risk in price volatility and can continue operating the rigs.

How long does it take to recoup my investment?

Ah the question you’re waiting for! Unfortunately there is no easy money here. ROI on mining depends on a number of things some of which change very quickly:

  1. your hardware mining rate (how fast it earns token X)
  2. the difficulty of mining (how many other people are you competing with)
  3. what you paid for your miner (ASICs, or a GPU rig which needs RAM, Motherboard, and Power supplies)
  4. how much you can sell token X for (the market price)
  5. minus the small operational costs, like power, rent, etc

Other people could swoop in and drive up the difficulty, for example Monero’s difficulty has increased 3x since I started mining it. Suddenly I’m only making 1/3 of what I used to make.

Market price might drop too, in the last few months Monero’s price has oscillated between 200 and 380. Luckily it oscillated, who knows one day it might just go down and never get up.

Power costs are also a common misconception. It seems like popular belief that mining is not profitable since it costs you more in electricity to mine the same value in tokens. This might have been true at one point in time but it’s definitely not the case anymore if you use the right hardware.

Of course you could always use your MacBook to mine BTC, at which point yes you are losing money steadily, with an astronomically small chance of winning a small chunk of BTC (like a real lottery).

The many Miner Programs

There are many different miner programs. Why? Because this space is very new and heavily fragmented. The majority of miner programs are written by talented individuals who just love their work, it has yet to be consolidated into a single miner program, or a best operating system, or a company that offers an optimized program as a service.

Some of them are open source, such as xmr-stak, so it’s free for you to use and modify. Usually the developers who open source their miner programs suggest a small donation of maybe 1% from the community who uses their software, as a way of saying thank you and funding further development.

Other miners are proprietary, such as the most popular Ethereum miner claymore. By offering a 3–4% speed boost over all the other miner programs, it makes sense for profit driven miners to use claymore, which charges a 1% fee, which given how much ETH is mined is quite a lot...

Here is a non-exhaustive list of miner programs in case you want to get started.

Ethash miners: Pheonix Miner, Ethminer, Claymore ETH

Cryptonight miners: Cast XMR, XMRig, Claymore XMR, XMR-Stak

Equihash miners: ZM, Optiminer

Multi currency miner: ccminer, excavator

If I missed a good miner please leave a comment, happy to add it. Thanks!

There are lots of sketchy characters in this space so be careful… some people release miner apps that report faulty hash rates, and take a cut of your rewards as a fee. see this forum discussion on Bminer for example.

Each program implements a different algorithm, or a set of algorithms, the claymore miner implements Ethash, XMR-Stak implements Cryptonight. Even within a single miner program there are subtle differences, ccminer supports many different algorithms, but only on NVIDIA GPUs running Cuda, while XMR-Stak supports both AMD GPUs that run OpenGL, NVIDIAs, and even CPUs.

Some of these programs only run on Windows and have an installer package, others you have to download, compile, and build for yourself to run. Some of them require the latest drivers, others require specific drivers that are compatible with your current linux kernel.

It’s a mess.

Mining Pools and Profit Sharing

So now you finally bought a few GPUs, setup the small rig, banged your head against linux kernels and drivers for a few days before giving up and installing windows and going back to your double click installers, picked up claymore from github like everyone else, and decided to start mining ETH your favorite crypto.

A few days go by, nothing.
No big deal you think, just bad luck.
A few weeks go by, then a few months, and still nothing.

What’s wrong?

Well you bought 4 Vega 64 GPUs, and are getting a good 160.0 MH/s. Turns out, you are competing with a lot of other miners, and that the Ethereum network has about 241.522 TH/s.

This means that you have a 0.0000662% chance of winning each block. Given ETH has a block time of 10 seconds, statistically you will find a winning ticket and claim a block reward after 208.76832 days.

That’s not good, you have bills to pay and more hardware to buy. Turns out, other miners have the same problem you do, so they’ve banded together to increase the chance of finding a block. If you and your new online buddies work together, you can find a block every 10 minutes!

But how do we split the profit?

Everyone has different hardware, some people are running a warehouse of GPUs, and others like yourself have a hobby rig, how can we be fair to everyone if a small 4 card rig won’t find a winner for 200 days, but a large operation can find a winner every few minutes? Pools solve this problem by introducing shares and pool difficulty

The ETH has a difficulty of X, pools purposefully send out jobs with a easier pool difficulty Y so that even if miners don’t find a winning ticket, they still submit a valid hash which is recorded so the pool knows who is doing work. This continues until someone happens to submit a winning ticket.

Then the pool claims a block reward, it looks at who submitted shares and splits the reward proportionally. Your 4 GPU rig submitted 100 shares and the big miner submitted 9900 shares. In that case, you would just take 1% of the earnings, and the big pool wold take 99%.

Often pools will take a 1–5% fee on all blocks found for operating costs. Pools have servers to pay for, engineering time put into building and maintaining the software, and often they come under DDoS attacks or other hacks. This small fee is for their troubles, and for turning your 208 day wait to a steady smaller revenue sharing stream.

Beware though, some pools do some funny business in the back since it’s very hard for miners to find out. The recommended approach is to simply run your miner for 24 hours with pool A monitoring the hash rates, then repeat with a separate pool and seeing if there’s a significant difference.

Tools of the Trade

whattomine.com

Compare profitability for different coins across different types of hardware. Easily my favorite mining resource. You can adjust the parameters to reflect your own mining setup, and get a quick estimate of how profitable your mining operation will be. Check it out here.

nicehash.com

Nicehash takes out a lot of the complexities of mining, such as picking the right coin, monitoring market conditions, etc. Nicehash is an all-in-one miner that looks at the most profitable coins on the market, mines with your hardware, then liquidates them into BTC which is stable (relatively speaking) and easy to sell. Check it out here.

bitcointalk.org

bitcointalk is a forum where people in the crypto space share ideas, announce launches, etc. A lot of great information here, it usually takes a bit of searching to find but definitely high quality.

For example, Sumokoin announced their launch here. If you were in early, you would have seen it pop from nothing to $10 USD a SUMO in a few months. shouldacouldawoulda

ethOS

Probably the simplest plug and play mining OS. It’s a linux distro that has the drivers of most GPUs pre installed and runs on a bootable USB drive. You can plug it into your rig, download a miner program, and start mining. Check it out here

gpushack.com

Buy prebuilt bundles for your first mining rig. It’s a great way to get started, their bundles support anywhere between small 4 card rigs to big 13 card ones. The bundles will include RAM, CPU, MOBO, and ethOS on a USB stick, all verified to work together and support your GPUs. All you need to do is buy the GPUs and PSUs. Check it out here

NowInStock.com

Now this one is amazing. It’s a website that will monitor online stores, and emails you when certain GPUs are in stock! You’ll probably receive an email every few hours, but most of the time the site will already be out of stock again by the time the page loads.

So really you have to get lucky. Check it out here

OverdriveNTool for AMD GPUs

One important thing I did not cover here was tweaking your rig. The voltage, fan speeds, clock speeds, memory speeds, are all very important for a steady profitable miner. Unfortunately there aren’t magical correct numbers, trial and error is your best bet. Most AMD GPUs do not need to be on full power to mine at the most efficient rate, and the same is true for clock speeds. If you lower the clock speed, and undervolt the card, you could potentially save a lot of power and be able to maintain the card temperature with slower quieter fans. Check it out here

And if there’s any good tools I haven’t added here, happy to add them!

--

--