L4 What is Mining

Bitcoin Mining

 

Mining 101

 

Bitcoin is what’s known as a Transaction Blockchain

Work for the blockchain is done by Miners, aka Mining Nodes

These Nodes represent the computation backbone for the decentralized network to exist

 

The Miners are paid to do this heavy computing in bitcoins by the network

via Block Rewards + Transaction fees

 

  • The technical definition for block rewards is Coinbase transactions

 

  • These special transactions are how bitcoin is created out of thin air

 

 

The Work

The actually heavy lifting for Bitcoin is the proof of work computation, this is the puzzle required to be solved each time a Miner wants to add a new block to the chain.

 

Proof of Work is a system in which only the longest block chain, the one with the most computational work is accepted as true.

 

 

The Supply

 

  • The system is designed for 21 million bitcoins ever in the system

 

  • The system Limits the total amount of coins and limits the rate they are produced.

 

  • Block rewards decrease over time until eventually hitting 0 satoshis.

 

++ 1 satoshi = 1/100th millionth of a bitcoin or .00000001 BTC ++

 

  • It’s possible to enforce these rules being that everything in the blockchain is public

 

 

 

 

  1. Mining Nodes
  2. Proof of Work Scheme
  3. Coinbase Transactions
  4. Block Rewards
  5. Block Contents
  6. FAQ

 

Mining Nodes

 

A Mining Node is a specific kind of software in the Bitcoin Peer to Peer Network responsible for verifying and added new blocks (of transactions) to the chain.

 

It’s called mining because in the first entry in a new block, the Miner (Mining Node) is allowed to include a special transaction that generates new bitcoin and assigns it to the Miner as a reward for computing the new block. (Conceptually Similar to Mining)

 

++ This first “reward” entry is what’s known as a Coinbase Transaction. ++

 

 

The Basics

Miners Take all the unrecorded transactions and record them in a new block along with a transaction for a reward to pay themselves

 

Each Transaction Block includes Data from the previous Block

 

++ That’s how you get a chain, spanning back from the 1st block at time=0 ++

 

This Includes solving a Proof of Work Computation

 

Now they Broadcasts the details of that block all the nodes in the peer to peer network

 

Once it’s verified everyone will start to implement it and append new blocks to it

If implemented they receive the block reward and transaction fees

 

 

The Process

A user wants to send some bitcoin, this is traditionally what your wallet software will do:

 

  1. It creates a transaction record about how you got the bitcoins

 

  1. Specifies the amount they want to spend and who it’s going to

 

  1. Species the transaction fee willing to be paid (if any)

 

  1. How much bitcoin is leftover in the account to be returned back to the sender (all the leftover bitcoin in the account has to be reassigned to you every time you make a transaction, if the total coins sending + the total coins leftover isn’t equal to the total in your account the transaction is instantly rejected)

 

  1. Then the Transaction gets broadcast to the entire Bitcoin world

 

 

 

 

Now there are these Special nodes-> called Miners

Their job is to make sure that everything in the transaction checks out in the global network

 

 

When they spot an incoming transaction they first look at the account history as to whether the person ever received the bitcoins in the past that they are now trying to send

 

(i.e. Does the person have enough money in their account to cover it)

 

  • They also weigh the transaction fee as to see if it’s worth their effort to include it in the block

 

  • Then they take a bunch of transactions that occurred around the same time and try and group them in one block

 

 

Proposing a block

 

Nodes work on incorporating the transaction record in the Bitcoin system

 

  1. First goal is to collate these transactions into a transaction block

 

  1. Take that block and get it added to the global ledger

 

  1. Hash transactions in pairs then take the digest of those

 

  1. Then hash those into a single digest value (i.e. 4->2->1)

 

  1. they then combine that digest with the previous hash of the last accepted block in the global record

 

  1. this final sequence of numbers is converted into a challenge for the proof of work protocol

 

  1. takes the challenge, and comes up with a proposed proof

 

  1. then concatenates the challenge with the proof and hashes it

 

  1. if the prefix of the resulting hash has a large enough portion of 0’s then it is eligible to be accepted as the next block in the chain

 

  1. the node then announces it to the other nodes once the proof has been completed

 

  1. then if it matches the other nodes will accept it and start to work on the next block

 

Time

The average time across the network is about 10mins for 1 node to come up with a valid proof for a new block.

 

  • A lot of nodes are working on it at the same time

 

  • It Can take a long time for one individual node to solve a puzzle

 

  • It is technically possible that a single mining node actually never solves a puzzle

 

  • As you increase the total nodes on the network, the proof of work for the next block starts getting solved faster and faster for the entire network

 

  • e. The more nodes that are working on the problem concurrently the higher probability of generating a solution.

 

 

Tie Breakers

What happens if two miners solve the puzzle it at the same time?

 

Peers break ties by sticking with the longest chain-> the one that has the highest aggregate difficulty (the most effort used to solve the proof of work) is the one that wins.

 

Ties are quickly resolved

 

 

Proof of Work Scheme

 

The Concept Involves Solving Cryptographically Difficult Puzzles to force each block to require a certain amount of work in order to be verified as true and added to the chain.

 

  • Prevents Spam, because you have to pay for each request in computational resources (CPU Cycles) it throttles the amounts of requests by users

 

  • Difficult to Falsify, as everyone is supposed to work off the chain that has the most work put into it (the longest chain)

 

  • The more work that went into a transaction the more trustworthy the transaction must be.

 

 

More specifically we mean the chain with the overall highest Difficulty Score [Dn], the chain with the most overall difficulty to compute.

 

A high [Dn] makes it resistant to attack as the total amount of computational power required has to outweigh the total amount of work already done, or out-compute the honest nodes mining blocks in the network.

 

Simplified Puzzle

The Node generates a Challenge String [C] and tries to come up with a corresponding Proof [P] associated with the [C]

 

To generate a solution, it takes [C] and concatenates the with the [P] and hashes it

The result/output of this function is Response String [R]

 

i.e. R = SHA256(SHA256(C, P))

If [R] has very specific properties it is accepted, otherwise it is rejected and they try again.

 

[R] has to start with a certain number of zeroes.

 

i.e. The first number (n) of bits has to be 0 -> 2n Steps to find the correct P string

 

 

This allows for a flexible system be it that probability wise, every additional 3 bits at the start required to be a 0 you are basically double the amount of computing effort to come up with a solution.

 

 

Coinbase Transactions

 

In a new transaction block, the miner can include in the first transaction record an assigned reward for completing it, completing all this work by using all this computational power to add a new block to the chain.2

 

This first “reward” entry is called a Coinbase transaction -> this is also the only way new coins get created in the bitcoin system.

 

The Miner who receives this reward is the one who succeeds in completing this block and having it added to the chain, they then also get the transaction fees included in the block.

 

 

Block Rewards

 

These are the incentives for people to play honestly.

Block rewards are what are awarded to Miners for each successful block.

 

This reward is designed to decreases over time.

So eventually the only incentive to create blocks will be the transaction fees-

 

These fees are set by the payer, so the hope is by then that the fees being submitted will be high enough for a mining node to accept their transaction in the next block.

 

 

Timeline

Every 210,000 Blocks that are generated the rewards get cut in half (i.e. 25->12.5)

It takes approximately 4 years to generate 210,000 Blocks

 

  • At launch in January 2009 the reward for each block was 50 bitcoins

 

  • 2013 is 25 bitcoins

 

  • 2017 is 12.5 bitcoins

 

Around the year ~2140 it’s expected that the entire supply (all bitcoins) will have been generated- and the total block rewards will hit 0 satoshis.

 

 

Calibration

The last way to limit the generation of new bitcoins is to calibrate the difficulty of solving them at a Global level

 

Every 2,016 Blocks that are generated the networks estimates the amount of time it took to generate those blocks:

 

  • if the amount of time [T] is > than 2 weeks then the system simplifies the proof of work to make it easier

 

  • if [T] is < than 2 weeks (14 days) then the system calibrates it to make it harder so it takes longer

 

2 weeks to generate 2,016 blocks works out to approximately 10 mins / block

 

6 blocks per hour, 144 per day, etc.

 

 

Content of Blocks

 

What’s actually contained in a block?

There’s two different components, a Coinable Input and the Transaction Data:

 

 

Coinable Input

(The First Transaction in a Block) has exactly one input

 

null hash (32 Bytes)

base index (4 Bytes)

script size (Varies)

block height (4 Bytes)

coinbase script (Varies) – arbitrary data

 

 

Transaction Data

TXID’s are serialized byte format (raw format) created using SHA256(SHA256())

 

  • It contains the Version Number, the Transaction Inputs and Outputs and the number of Transaction Inputs and Outputs as well as a Lock Time or block number.1

 

  • Also, it includes the merkle root5 of a block containing the transaction.

 

Merkle root

Version Number

Inputs/Outputs

# of Inputs/Outputs

Lock Time or Block #

 

 

Uniqueness

Every node is technically solving completely different problems since each one is using their own unique Coinbase transaction.

 

This makes each challenge string unique and so they are all trying to compute the right proof with different inputs, so it completely randomizes the solution.

 

 

FAQs

 

WHAT ARE THE DIFFERENT KINDS OF NODES?

 

Bitcoin has 3 main types of nodes (User Software)

 

 

Basic Node

Regular User _> contain the most recent validated blocks in the chain

 

Full Node

Full Chain _> contain a complete record of the blockchain since inception

 

Mining Node

Workers _> contain a complete record, and work to create new blocks for the chain

 

 

WHAT IS PRE-MINING?

 

This is usually when the developers of a new cryptocurrency generate large amounts of coins/tokens before offering up the public mining protocol to the public

 

 

WHAT KIND OF MINING IS THERE?

 

CPU

Low Power _> using your Computer Processing Power to solve the puzzle

 

GPU

Medium Power _> this is where you use your Graphics card to solve the puzzle

 

FPGA

Strong Power _> this is specially designed hardware Pre-ASIIC to solve the puzzle

 

ASIIC

High Power _> this is specially designed hardware optimized to solve the puzzle6

 

 

WHAT ARE MINING POOLS?

 

Solo Mining

High Variance _> Generate blocks on your own, you collect all the rewards

 

Pooled Mining

Low Variance _> Combine your resources with other miners, you each receive rewards in proportion to the hashing power contributed to solve the block7

 

 

GAMING THE SYSTEM?

 

If one transaction is fraudulent, how likely is it to succeed?

 

 

Double Spending

 

One way someone can cheat the system is to send a duplicate transaction at the same time by assigning the bitcoins to someone else (So sending two transactions)

 

  • This is known as a Fork in the chain

 

  • Two versions of history, one real/one fake

 

Since each block has to both contain a solved proof of work puzzle, it puts a high computational load on trying to create a separate fake chain that is somehow longer than the real one.

 

This could mean having to solve several proofs of work puzzles in order for the attacker to outwork the real chain and try and prove their second fake transaction is not fake.

 

This also is protected against via the likely hood of solving these consecutive puzzles and outpacing all the honest nodes in the network.

 

 

Summary

As long as the Honest computing power (total computing power for all the honest nodes in the network) is greater than all the computing power than the person trying to game the system it makes it improbable. As each new verified block makes it harder and harder to do.

 

Rather than trying to beat the system, the person is much better off just using that computing power to behave honestly because of the benefits of all the fees and block rewards of just doing honest blocks

 

 

There is a strong economic incentive to play fair, as well as being extremely difficult to cheat the system.