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 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
++ 1 satoshi = 1/100th millionth of a bitcoin or .00000001 BTC ++
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:
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)
Proposing a block
Nodes work on incorporating the transaction record in the Bitcoin system
Time
The average time across the network is about 10mins for 1 node to come up with a valid proof for a new block.
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.
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
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:
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())
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)
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.