Xiaolu takes you to explore the principle of blockchain

Xiaolu takes you to explore the principle of blockchain
It takes about 7 minutes to read this article

Write in front

Before, I often heard people say that things like mining, Bitcoin, and blockchain sounded so tall. Later, I learned about relevant knowledge on the Internet, but most of them are reprinted on the Internet, and none of them can explain it clearly. Unconsciously, I came into contact with some easy-to-understand points, so today I will integrate it to let everyone thoroughly understand what is a blockchain, what is mining, and what is Bitcoin.

From beginning to end, it’s been three hours of manual typing by Xiaolu. Because I have been preparing for an interview recently, there is less and less time for writing, but I still like to take time to share it with readers. If you understand today’s content, don’t forget to forward To your friends, I believe they will appreciate you for bringing him such a clear and easy-to-understand article.

What is Bitcoin?

Bitcoin is actually a virtual electronic currency, which is based on cryptography.

virtual? Electronic money? Cryptography? I'm still a little ignorant. Okay, let's be more specific. Bitcoin is different from all currencies. It is not issued by a specific currency institution, but is generated based on a specific algorithm. We will talk about this next.

The concept of Bitcoin was proposed on November 1, 2008 by a person who claimed to be Satoshi Nakamoto, and his identity is still unknown. It mentioned in the "White Paper" that this is a decentralized electronic accounting system.

What is decentralization? Each of us now has a bank card and Alipay. Our money is kept by the bank and Alipay. Because of our trust in the country, the bank is equivalent to the center. Each of our deposit and expenditure records are given by the bank or Alipay. We recorded.

So what about the decentralization of the electronic accounting system proposed by Satoshi Nakamoto, that is, each of us does not need bank and Alipay records, but to disclose our own consumption records and let others record it for us, which is equivalent to publicizing us The ledger, our balance and consumption will be known by others.

If there are four people A, B, C, and D, and A pays 10 bitcoins to B, then C and D will record that A paid 10 bitcoins to B. Then B pays C 20 bitcoins, then A and D will record their own bills, and B pays C 20 BTC. The same C paid 5 BTC to D, and A and B will also record this transaction.

What is blockchain?

Then we pack the recorded bills into a package called "block". Each block records about 4000 pieces of data (about 1 trillion). We connect this block to the previous block to form a chain called "blockchain".

Xiaolu takes you to explore the principle of blockchain

Then you may encounter several problems. The first problem is that everyone keeps accounts. If A pays 10 BTC to B, then B pays 20 BTC to C, and the person who keeps the account has a network delay. It is recorded that A paid B first, and another person recorded B first paid to C. Then whose bill shall we take?

The second question, why keep accounts? If Zhang San pays Li Si, then why should Xiao Lu keep his account? Not only wasted my precious time, but also wasted my computer resources.

The third question is, if Xiaolu keeps him account, I secretly forged a piece of data behind my back, also called forged records, how can I prevent this from happening?

Time is limited here, and only solutions to the first two problems are shared.

Each of us will have a commission fee for accounting in the accounting system. I will keep the account for you. The person who pays will give a small part of the commission to the person who keeps the account. Then again, the bank deposits and withdraws There are fees for money, but the fees for our electronic accounting system are very low. And whoever finally packs up the ledger to form a block, there will be a packing fee, and there is such a good thing, then you can pack it for him to make money.

The fee for you is Bitcoin, so how much Bitcoin is given to you? This is what Satoshi Nakamoto designed to make a package every 10 minutes and halve the package fee every four years. That is to say, when the system was first operating, the packaging cost was 50 bitcoins, and every four years, it would be reduced by half, which is 25, 12.5...

Then let's calculate how many bitcoins are generated in total. Each hour has 6 ten minutes, 24 hours a day, 365 days a year. The first four years is 50, and it is reduced by half every four years. Mathematical calculation: 50 x 6 x 24 x 365 x 4 x(1 + 1/2 + (1/2)² + ...), we can calculate that there are 21 million Bitcoins in the world.

Here comes the problem. Packing has both a handling fee and a packing fee. Everyone wants to do this, so everyone is rushing to do it. Whoever prevails?

What is mining?

Since we want to do it all, let's design a math problem. Whoever does it first can pack it and earn Bitcoin. If you say that I am very good at math, I won the first prize in the Olympic competition, etc., sorry, even the famous statistician Gauss can't solve it manually. This math problem cannot be calculated by the human brain at all, so how difficult is this math problem?

All of them are hash algorithms. Those who have studied data structure know that the forward calculation of the hash algorithm is very easy, and the reverse calculation is extremely difficult. It is unimaginably difficult and can only be calculated by the calculation of the CPU.

This math problem is the SHA256 algorithm used. You have heard of MD5 encryption, and I must be familiar with SHA256. Generate a 256-bit binary from a string. Regardless of the size, there will be 256 bits, giving you a 20 G video, and it will also generate a 256 bit binary. The so-called problem is what is the string corresponding to this 256-bit binary?

Xiaolu takes you to explore the principle of blockchain

We call the process of solving this math problem "mining".

So how is this string generated? The information of this string is composed of the information of the previous block header + the information of the current bill + the time of the bill and other information. The previous ones are fixed, but the last one needs to add a random number, which is a difficult point in design.

For this string, perform two hash (SHA256) operations, HASH = sha256(sha256(string)), and the result is a 256-bit binary number. We require the first n bits to be zero. The requirement to join the first few is 6 zeros. If you figure out it is 6 zeros, then you are right. If you are right, you can pack it, and insert the hash value you calculated into the previous block as the head of the new block, and then you get the reward you want.

Xiaolu takes you to explore the principle of blockchain

A small partner will ask, how do you find the first few of the regulations to be 0? Then we have to change a number, that is, the random number in the string, because the other content is fixed, if we want to find the hash value through HASH, we can only try one by one, adding 1 Look at whether the hash value meets the conditions, if not, then sequentially 2, 3, 4, 5... until someone tries it out, pack this block, and use the obtained string as this block The head of the file is connected to the previous block.

Xiaolu takes you to explore the principle of blockchain

The random number corresponding to each person is different, so if you want to mine, one depends on your luck and the other depends on the speed of your CPU calculation per second. Some people are lucky. Although their computing power is not enough, they try the first number. Some people are unlucky and their CPU computing power is no good. On average, if you look at the computing power of the CPU, you will be more hopeful. So many people are desperately buying mining machines for 24-hour mining.

Write behind

In order to give readers a better reading experience, Xiaolu closed the advertisements below. I tried to read several of my own articles. The advertisements do affect reading a bit.

I have always paid great attention to the user experience and the quality of the article, so Xiaolu decided to focus on the reader experience in the end. The chicken drumsticks are not needed. Xiaolu is more comfortable eating steamed buns. If you really think an article is very helpful to you, just give a few cents to support it.

If you think the article is really easy to understand, you can forward it to people around you, and learn to share it. That is our ultimate goal and let us influence more people around us together.

Guess you like

Origin blog.51cto.com/15064450/2602380