The Bitcoin system of trust is based on computation (Bitcoin Mining). Transactions are bundled into blocks, which require an enormous amount of computation to “prove” (or “confirm”), but only a small amount of computation to verify as “proven”, in a process called mining.
Mining creates new bitcoins in each block, almost like a central bank printing new money. The amount of bitcoins to be created is fixed and diminishes with time (cuts in half every 4 years). Mining creates trust by ensuring that transactions are confirmed only when enough computational power was devoted to the block that contains them. More blocks mean more computation, which means more trust.
Mining algorithm
Mining consists of the following steps, which are performed in a continuous loop:
- Bundling transactions that were broadcast on the peer-to-peer network into a block. Each miner can arbitrarily decide which transactions to include in their block.
- Verifying that all transactions in the block are valid.
- Selecting the most recent block on the longest path in the blockchain and inserting a hash of its header into the new block.
- Trying to solve the Proof of Work (PoW) problem for the new block and simultaneously watching for new blocks coming from other nodes.
If a solution is found to the Proof of Work problem, the new block is added to the local blockchain and broadcast to the peer-to-peer network.
Proof of Work
Miners search for acceptable blocks using the following procedure, performed in a loop:
- Increment (add 1 to) an arbitrary number in the block header called a nonce.
- Take the hash of the resulting block header.
- Check if the hash of the block header, when expressed as a number, is less than a predetermined target value.
If the hash of the block header is not less than the target value, the block will be rejected by the network. Finding a block that has a sufficiently small hash value is the PoW problem. Mining performance, therefore, is measured in hashes/sec. Currently the performance of miners is measured in GH/s (billions of hashes per second) or TH/s (trillions of hashes per second).
H/ s = Hashes per second | 1,000 H/ s = 1 KH/ s |
KH/ s = Kilo Hashes per second | 1,000 KH/ s = 1 MH/ s |
MH/ s = Mega Hashes per second | 1,000 MH/ s = 1 GH/ s |
GH/ s = Giga Hashes per second | 1,000 GH/ s = 1 TH/ s |
TH/ s = TeraHashes per second | 1,000 TH/ s = 1 PH/ s |
PH/ s = PetaHashes per second | 1,000 PH/ s = 1 EH/ s |
Bitcoin Mining Difficulty
Bitcoin nodes that mine, actively regulate the rate of creation of new blocks.
As more miners join, the rate of block creation will go up. As the rate of block creation goes up, the mining difficulty rises to compensate, which pushes the rate of block creation back down.
The creation of new blocks must take an average of 10 minutes(Ten minutes was specifically chosen by Satoshi Nakamoto as a trade off between fast confirmation time and the amount of work wasted due to chain splits and orphan blocks. Read more about this here). The regulation is done by periodically adjusting the hash target value for blocks.
Every 2,016 blocks (which ideally spans every 2 weeks, with each block taking 10 minutes to confirm) Bitcoin nodes calculate a new difficulty accordingly, based on the time it took to mine the last 2,016 blocks. In December 2018, Bitcoin’s mining difficulty saw its second largest drop in history, with a 15% adjustment.
Bitcoin Mining Reward
Solving the Proof of Work problem requires a lot of computing power and that power costs money. To encourage participants to invest their resources in mining, Bitcoin provides a reward in each successfully mined block (plus the transaction fees of the transactions contained in the new block).
When a block is discovered, the discoverer will award themselves a certain number of bitcoins, which is agreed-upon by everyone in the network. Currently this bounty is 12.5 bitcoins. Based on Bitcoin’s algorithm, this bounty halves every 210,000 blocks (i.e. approximately every 4 years).
Eventually, the reward will be removed entirely when the limit of 21 million bitcoins is reached asymptotically, by the year 2140. After that, transaction processing will be rewarded solely by transaction fees.
As mentioned in the first bullet, the miner is awarded in addition the fees paid by Bitcoin users sending transactions.
Solo Mining
Solo mining is when you use your computer (or specialized mining hardware) to search for blocks. In this case, you are getting paid only when you personally find a block, receiving the full amount of the reward, plus any transaction fees. This type of mining was efficient only when the mining difficulty was low enough to expect to find new blocks relatively often.
Today (February 2018), the hashrate of the Bitcoin network is over 20,000,000 TH/s (!!). In order to mine one block per day, your bitcoin mining rig should perform with the speed of: 20,000,000 TH / 24 Hours / 6 Blocks per Hour = 833,327.2 TH/s ≈ 833 PH/s. In this case, you are getting paid only when you personally find a block, receiving the full amount of it, plus any transaction fees.
Pool Mining
Mining pools collect all of the hashing from miners and basically run them off of one account. When a block is found, the mining pool’s wallet is the one that gets the payment, and then the payments are split and distributed into each miner’s site account based on their personal contribution towards finding the block. For example, if a miner contributed half of the pool’s shares into finding the new block, they would get half of the block reward.
Mining pools
Most pools work using the following algorithm:
- The pool server prepares a block with the coinbase transaction pointing to the pool’s address.
- Miners in the pool contact the pool server and make a getwork request to get the block to work on.
- Each miner tries to solve the Proof of Work problem for the block, by incrementing the nonce and hashing the block header.
- Whenever a miner finds a hash value that is below the easier target, it submits the solution to the server for a share.
- The mining server verifies submitted shares and tracks how many each miner has.
- When a miner finds a solution to the Proof of Work problem, the server pays out the reward in proportion to the number of shares each miner earned since the last payout.
- Miners periodically contact the pool server for updates on what to work on, in case a new block was discovered.
Pool Mining – Rewards
Mining pools use different distribution schemes, the most popular of which are:
- PPS (Pay Per Share): Each miner gets paid a guaranteed amount for every share they submit. Pools that use this method often employ custom pool difficulties as well, rather than allowing for variable difficulties. This makes the calculations a lot easier and ensures every miner is fairly treated.
- PPLNS (Pay Per Last Number of Shares): Each miner gets paid based on the last x number of shares after a block is found. For example, if it is set to pay at 5,000 shares and a miner has contributed 2,500 of the last 5,000, this miner would get half of the block’s payment.
- Proportional: Each miner gets paid based on the proportion of shares since the last block. This is a lot like PPLNS, but instead of only counting n shares, it counts every share between each block and then calculates the payments based on each person’s proportional amount
Bitcoin Mining Hardware
- CPU mining: Initially, Satoshi’s Bitcoin client software did mining on a user’s PC (i.e. CPU mining), but now CPUs have been eclipsed by more efficient mining hardware.
- GPU mining: GPUs (i.e. Graphics Processing Units on Graphics cards) are designed for doing lots of mathematical calculations in parallel and are orders of magnitude faster than CPUs
- FPGA (Field Programmable Gate Arrays): An intermediate step between a fast processor and a dedicated ASIC, FPGAs were used until ASICs emerged and dominated Bitcoin mining
- ASIC mining: ASICs (Application-Specific Integrated Circuits) are custom built for a particular application and are thus orders of magnitude faster than GPUs, which are general-purpose. In Bitcoin, these chips are customized to only perform SHA-256 hashing.
Today, ASIC mining is the only economically efficient Bitcoin mining technique. If you want to calculate your earning from mining you can use our Bitcoin mining calculator.