What is Bitcoin mining?
Bitcoin has been here and friends of mine have been talking about bitcoin for a while. I have also read some of the articles talking about bitcoin, the hashing and the trustful features. But to be honest, these concepts still remain a mist for me. So I decided to really figure out them in the way that I think and try to explain it as clear as possible. This post is just one part of the whole bitcoin stuff. As a beginning, I want to focus on the concept of mining bitcoin.
It is all about verifying transaction
As a type of currency, bitcoin must solve the following requirements including how to mint the coin and how to validate the transaction (in other words, how to keep track on all of the transaction) since bitcoin is electronic yet decentralized currency (not centralized comparing to the traditional currency printed by the government or central bank) eventually.
So how bitcoin manage to do that? Well, bitcoin manage to solve these problems by utilizing the concept called blockchain.
What? What is block chain again?
It might sounds a bit creepy again by importing this blockchain stuff. If you have some Computer science background, think of it as the single linked list. Or else, think of it as a long lego chain comprised with lego block. Each lego block is equivalent to the block in block chain. It contains identification of the previous block which is the solved puzzle and the transactions that reside in this block.
With this structure, everyone can append a block to the current chain and the transaction info can be seen by any one which is the soul of the internet right? (I mean everyone has the equal right to access the resource)
But wait a sec, how to append a new block?
In order to append a new block, one has to solve the puzzle given by the previous block which is a hashed value generally (remember when we talk about hash algorithms before? here is one of the usage).
A public block chain is holding a puzzle which is a hashed value. Miners have to solve the puzzles provided by the block chain in order to validate their list of transactions and therefore append their block(node) to the block chain (By saying solving the puzzle here, I’m using general expression, more detail could be found here). The first one who solved the puzzle will have access to append itself to the blockchain which mean the ledger in the local block can be public to the global block chain so that everyone can see it. At the mean time, this miner will get 12.5 bitcoin as reward. And this is how bitcoin get distributed. Yet the process of solving the puzzle is the process of validation.
Different kinds of algorithms for the puzzle
Speaking of the puzzle, I said it is a hashed value but there are some different algorithms used to get validated(define who is the winner). Hash value is known for not revertible unless by brute force searching. Getting the exactly original message is not easy.
prove of work(pos)
it is a method to ensure the new block is hard to create. Basically the requirements to get the puzzle solved is to let the hashed value < target. Here is a simple implementation provided by Siraj
#Simple Proof-of-Work exampleimport sys
import time
import hashlib
from struct import unpack, packtimestamp = str(time.time())
message = "this is a random message"
payload = (timestamp + message).encode('utf-8')nonce = 0
guess = 999999999999
throttle = 100000000
target = 2**64/ throttlepayloadHash = hashlib.sha512(payload).digest()start = time.time()
while guess > target:
nonce+1
guess, = unpack('>Q', hashlib.sha512(hashlib.sha512(pack('>Q', nonce) + payloadHash).digest()).digest()[0:8])[0:8]
end = time.time()
print "%s:%s:%s:%s:%s:%s:%s" % (timestamp, message, nonce, guess, payload, target, end-start)
prove of stack
prove of burn
In summary
In a nutshell, the whole process from decrypt the digest to get bitcoin reward is the so called bitcoin mining. It is greatly related to the block chain. However, this is just the very shallow glance on bitcoin. Keep updating, peace!
Remaining questions
- If I am a miner, how do I know which algorithms to use to solve the puzzle?
- How does the initial block chain get generated?
- How does the local block chain get generated?
Reference
https://github.com/llSourcell/blockchain_consensus/blob/master/blockchain_consensus.ipynb
https://www.huffingtonpost.com/ameer-rosic-/what-is-bitcoin-mining-a-_b_13764842.html
https://blockgeeks.com/guides/what-is-blockchain-technology/
https://www.bitcoinmining.com
Related Techniques
- single linked list
- hash algorithms
I will be publishing some topics that I’m interested in in my own blog. If you want, please stay tune to my blog and hopefully comment here or there to tell me some improvement for the blogs that I wrote.
And since I’m Chinese, I wrote some of the post in Chinese too. I will continue writing blogs in english in the future cause I think ideas worth spreading globally!