1 of 29

1

Bitcoin Mining

Blockchain Technologies

Lecture # 04

2 of 29

The task of Bitcoin miners

  • To be a Bitcoin miner, you have to join the Bitcoin network and connect to other nodes.
  • Once you’re connected, there are six tasks to perform
  • Listen for transactions. First, you listen for transactions on the network and validate them by checking that signatures are correct and that the outputs being spent haven’t been spent before.

2

3 of 29

  • Maintain block chain and listen for new blocks. You must maintain the block chain. You start by asking other nodes to give you all of the historical blocks that are already part of the block chain before you joined the network. You then listen for new blocks that are being broadcast to the network. You must validate each block that you receive — by validating each transaction in the block and checking that the block contains a valid nonce.

3

4 of 29

  • Assemble a candidate block. Once you have an up‐to‐date copy of the block chain, you can begin building your own blocks. To do this, you group transactions that you heard about into a new block that extends the latest block you know about. You must make sure that each transaction included in your block is valid.

4

5 of 29

  • Find a nonce that makes your block valid. This step requires the most work and it’s where all the real difficulty happens for miners
  • Hope your block is accepted. Even if you find a block, there’s no guarantee that your block will become part of the consensus chain. There’s bit of luck here; you have to hope that other miners accept your block and start mining on top of it, instead of some competitor’s block

5

6 of 29

  • Profit. If all other miners do accept your block, then you profit! At the time of this writing in early 2015, the block reward is 25 bitcoins which is currently worth over $6,000

6

7 of 29

Finding a valid block

  • Let’s return to the question of finding a nonce that makes your block valid
  • The first thing that you do as a miner is to compile a set of valid transactions that you have from your pending transaction pool into a Merkle tree
  • You then create a block with a header that points to the previous block.

7

8 of 29

  • In the block header, there’s a 32 bit nonce field, and you keep trying different nonces looking for one that causes the block’s hash to be under the target — roughly, to begin with the required number of zeros.
  • A miner may begin with a nonce of 0 and successively increment it by one in search of a nonce that makes the block valid.

8

9 of 29

9

10 of 29

Mining Hardware

  • The core of the difficult computation miners are working on is the SHA‐256 hash function
  • The first generation of mining was all done on general purpose computers — that is general purpose central processing units (CPUs).
  • Miners simply searched over nonces in a linear fashion, computed SHA 256 in software and checked if the result was a valid block

10

11 of 29

  • The second generation began when people started to get frustrated with how slow their CPUs were and instead used their graphics card, or graphics processing unit (GPU)
  • Almost every modern PC has a GPU built‐in to support high performance graphics.
  • They’re designed to have high throughput and also high parallelism, both of which are very useful for Bitcoin mining.

11

12 of 29

  • Bitcoin mining can be parallelized easily because you can try computing multiple hashes at the same time with different nonces.
  • In 2010, a language called OpenCL was released.
  • OpenCL is a general purpose language to do things other than graphics on a GPU.
  • It's a high level‐language and over time people have used it to run many types of computation more quickly on graphics cards.
  • This paved the way for Bitcoin mining on GPUs.

12

13 of 29

  • Most graphics cards can also be overclocked, meaning you can run them faster than they're actually designed for if you want to take on the risk that they might overheat or malfunction

13

14 of 29

Disadvantages of GPU mining

  • GPUs can also draw a fairly large amount of power, so a lot of electricity is used relative to a computer.
  • Another disadvantage initially was that you had to either build your own board or buy expensive boards to house multiple graphics cards.

14

15 of 29

FPGA mining

  • Around 2011 some miners started switching from GPUs to FPGAs, or Field Programmable Gate Arrays, after the first implementation of Bitcoin mining came out in Verilog, a hardware design language that’s used to program FPGAs.
  • The general rationale behind FPGAs is to try to get close as possible to the performance of custom hardware while also allowing the owner of the card to customize it or reconfigure it “in the field.”

15

16 of 29

  • By contrast, custom hardware chips are designed in a factory and do the same thing forever.
  • FPGAs offer better performance than graphics cards, particularly on “bit fiddling” operations which are trivial to specify on an FPGA.
  • Cooling is also easier with FPGAs and, unlike GPUs, you can theoretically use nearly all of the transistors on the card for mining.
  • Like with GPUs, you can pack many FPGAs together and drive them from one central unit, which is exactly what people began to do

16

17 of 29

ASIC mining

  • Mining today is dominated by Bitcoin ASICs, or application‐specific integrated circuits.
  • These are chips that were designed, built, and optimized for the sole purpose of mining Bitcoins.
  • There are a few big vendors that sell these to consumers with a good deal of variety: you can choose between slightly bigger and more expensive models, more compact models, as well as models with varying performance and energy consumption claims.

17

18 of 29

Energy consumption and ecology

  • We saw how large professional mining data centers have taken over the business of Bitcoin mining, and how this parallels the movement to pit mining in gold mining.
  • You may be aware that pit mines have been a major source of concern over the years due to the damage they cause to the environment.
  • Bitcoin is not quite at that level yet, but it is starting to use a significant amount of energy which has become a topic of discussion.

18

19 of 29

  • Energy is never destroyed; it's converted from one form into another.
  • In the case of computation the energy is mostly transformed from electricity, which is useful, high‐grade energy, into heat which is dissipated into the environment.

19

20 of 29

Embodied energy

  • First, Bitcoin mining equipment needs to be manufactured.
  • This requires physical mining of raw materials as well as turning these raw materials into a Bitcoin mining ASIC, both of which require energy.
  • This is the embodied energy.
  • As soon as you receive a Bitcoin mining ASIC in the mail, you've already consumed a lot of energy — including the shipping energy, of course — before you've even powered it on!

20

21 of 29

Electricity

  • When your ASIC is powered on and mining, it consumes electricity.
  • This is the step that we know has to consume energy due to Landauer's principle.
  • As mining rigs get more efficient, the electrical energy cost will go down.
  • But because of Landauer’s principle, we know that it will never disappear; electrical energy consumption will be a fact of life for Bitcoin miners forever

21

22 of 29

Cooling

  • A third important component of mining that consumes energy is cooling off your equipment to make sure that it doesn't malfunction.
  • If you’re operating at a small scale in a very cold climate your cooling cost might be trivial, but even in cold climates once you get enough ASICs in a small space you're going to have to pay extra to cool off your equipment from all of the waste heat that it is generating.
  • Generally, the energy used to cool off mining equipment will also be in the form of electricity

22

23 of 29

Mining pools

  • If we look at the distribution of how many blocks you're likely to find in the first year, the variance is pretty high and the expected number is quite low.
  • Because you find blocks at a fixed, low rate which is independent of the time since the last block you found, your expected number of blocks is very well approximated by a Poisson distribution

23

24 of 29

  • If you expect to find about 1 block per 14 months (a Poisson distribution with λ=6/7 blocks/year), there's a greater than 40% chance that you won't find any blocks within the first year.
  • For an individual miner, this could be devastating.
  • You spent thousands of dollars on the miner, paid lots in electricity to run it, and received nothing in return.

24

25 of 29

  • Historically, when small business people faced a lot of risk, they formed mutual insurance companies to lower that risk.
  • Farmers, for example, would get together and agree that if any individual farmer’s barn burned down the others would share their profits with that farmer.
  • Could we have a mutual insurance model that works for small Bitcoin miners?

25

26 of 29

  • A mining pool is exactly that — mutual insurance for Bitcoin miners.
  • A group of miners will form a pool and all attempt to mine a block with a designated coinbase recipient.
  • That recipient is called the pool manager.
  • So, no matter who actually finds the block, the pool manager will receive the rewards.
  • The pool manager will take that revenue and distribute it to all the participants in the pool based on how much work each participant actually performed.
  • Of course, the pool manager will also probably take some kind of cut for their service of managing the pool.

26

27 of 29

Mining shares

  • Miners can prove probabilistically how much work they're doing by outputting shares, or near‐valid blocks.
  • Say the target is a number beginning with 67 zeros.
  • A block’s hash must be lower than the target for the block to be valid.
  • In the process of searching for such a block, miners will find some blocks with hashes beginning with a lot of zeros, but not quite 67. Miners can show these nearly valid blocks to prove that they are indeed working.
  • A share might require say 40 or 50 zeros, depending on the type of miners the pool is geared for.

27

28 of 29

  • In the pay per share model, the pool manager pays a flat fee for every share above a certain difficulty for the block that the pool is working on.
  • In this model, miners can send their shares to the pool manager right away and get paid without waiting for the pool to find a block

28

29 of 29

  • In the proportional model, instead of paying a flat fee per share, the amount of payment depends on whether or not the pool actually found a valid block.
  • Every time a valid block is found the rewards from that block are distributed to the members proportional to how much work they actually did.

29