A story tells you the principle and operation mechanism of Bitcoin recommended: “Artificial Intelligence: The Age of Artificial Intelligence in the Capital of French Romance” “Flowers are not flowers, things are not things, AI is not a thing in the pool” “To Our Youth, a salute”

Pictures may be lost.

Over the weekend, I spent some time to read some information related to the principle of Bitcoin. Although I can not say that I fully understand every detail, I still understand the overall idea and the main principle of key parts. Write an article to share. The positioning of this article will be more popular, try to use the method of analogy to explain the basic principle of bitcoin. This article will not involve the details of algorithms and protocols, but I plan to write another article on the principles of Bitcoin from the perspective of programmers, which will explain some key data structures, algorithms and protocols in the bitcoin system from the perspective of technicians.

In this article, I will present a virtual village called “Bitvillage”. The whole article will gradually tell the motivation of bitcoin, what problems it solves, as well as the goals and design schemes of some key components in the way of story telling.

Let’s start with the motivation behind bitcoin.

In this world, there is a small village called Bute Village, with hundreds of families. The village is almost isolated from the rest of the world and leads a self-sufficient life. Since there is no large-scale trade, the villagers of Bute village have been living a barter life, that is to say, there is no unified currency among the villagers. Basically, the trade between the villagers is that Lao Zhang’s family gets a bag of flour for Lao Li’s sheep, and Aunt Wang gets a basket of wild fruits for aunt Liu’s two feet of cloth. The villagers have been living a simple life.

Finally one day, the villagers felt it was too inconvenient to keep bartering, so the whole village held a meeting to discuss how to solve the problem. Proposed in order to split and rare things, such as gold, as a universal equivalent, the corresponding relation of the other items and gold into a form, such as a gram of gold corresponds to a sheep, a gram of gold corresponds to a bag of flour, etc., the Lao zhang never carried a bag of flour panting to Lao li’s house for the sheep, he just pulled out from home a gram of gold, He could go to Lao Li’s house and bring back a sheep, and Lao Li could take this gram of gold in exchange for a bag of flour from anyone willing to part with it, and of course he could exchange it for anything of the same value as a gram of gold.

At this time bitt village entered the era of physical money.

Symbol money did not last long, after a period of time, the drawbacks of physical money also appeared. Because there are not many gold mines around Bute, mining and smelting gold takes too much time and effort. As gold is used, it is constantly worn out, lost or deliberately hoarded. The whole village sat together again and began to discuss. Then someone said, “You don’t have to really use gold. Just take a piece of paper and write” one gram of gold “on it. As long as the whole village agrees that the paper is equal to one gram of gold, the problem would be solved. Others agreed, but there were new questions: Real gold is the need to mining and smelting, gold mine is limited, mining and smelting also need to cost, so no one can create a lot of gold in a short period of time, but writing is different, as long as I have enough paper and pen enough, casually like how much to write how much, that will become a lot of paper who home, It might take 10,000 pieces of paper to buy a sheep (in effect, this would be economic inflation).

You think so. But then someone came up with a solution: Not everyone could write this paper. We only accepted the handwriting of the venerable village head, whose handwriting everyone knew. Old village head write some paper, at the same time according to each gold stock to give everyone equal amount of paper, for example, the old Zhangs have 200 grams of gold, the old village head will give The old Zhangs 200 pieces of paper written “one gram of gold”, at the same time take away the old Zhangs gold as collateral. In this way, the old village head took all the gold in the village to his home, and each family handed in an equivalent amount of gold paper with words on it. Then the villagers could trade the paper as gold, and everyone knew the old village head’s handwriting, which no one else could forge. In addition, if anyone’s paper is too badly worn, he can also take it to the old village chief to exchange for a new equivalent of the paper, and the old village chief promised that if anyone wants to exchange for real gold, as long as he brings back the paper, the old village chief will return the equivalent of the gold to that person. Since the amount of gold written on the old village head’s paper is the same as the amount of gold actually kept in the house, every valid piece of paper can be exchanged for real gold as long as the principle of destroying and writing new paper is strictly followed.

At this time, bitt village entered the era of symbol money (paper money). The old village chief assumed the role of government and bank.

After a few years, the old village head had to check a large number of old notes every day, write new notes, and carefully record all kinds of accounts. One after another, the old village head overworked unfortunately drive crane west.

The village of Bute held another general meeting to discuss what should be done. At this time the son of the old village head two dogs volunteered to take over his father’s pen, assume the responsibility of currency issuance. This young village head two dog son is very clever, he did for a few days, found that it does not really need to write so much paper. It’s perfectly fine: the villagers hand in their notes and destroy them, but Erdogi keeps track of how much each household turns in. Later if you want to pay, for example to Lao li Lao zhang will take 1 gram of gold in a sheep, just call the second dog son together, explain to Lao zhang’s name as a gram of gold Lao li, two dog son took out the books and see if there is a gram of gold, Lao zhang name if there is a will lose a gram, in Lao zhang’s name in the Lao li’s name plus a gram, thus complete the payment, At this time old Li heard two dogs on the phone to confirm the completion of the transfer, you can rest assured that Lao Zhang took the sheep away.

At this time bit village entered the era of central system virtual currency. Each villager does not need to pay in kind, and the payment process becomes a numerical change in the ledger maintained by Erdogzi.

Distributed virtual currency this new office of two dogs is smart, but this person is sometimes smart by mistake. One day two dog son stared at this account book, thought this whole village each household who has how much money is I say calculate, that I am not… . Then he was so hot that he secretly drew ten grams of gold from the old account to his own name.

This thought is perfect, but did not think that Old Zhang also has the habit of accounting, one day he was about to pay but was informed by two dogs account no money. Old Zhang checked his books, clearly there are ten grams ah, so took the books to find two dog theory, this check found that without old Zhang agreed to transfer.

The window is exposed! The village of Bute is boiling. Two dogs were impeached is inevitable, but through this matter, we found that the account concentrated in a person’s hand drawbacks:

This system completely depend on the book holder of personal credit, if the people don’t behave, tamper with the book at random, so the whole monetary system would collapse if the house was on fire, or theft of books, also will be a devastating blow for the whole system when people at a loss, in the village called the hearing otaku scientists took to the stage, Telling everyone that he had designed a virtual currency system called Bitcoin that did not rely on any central processor to solve these problems. Then he slowly explained his plan.

Let’s take a look at how Satoshi nakamoto designed this system.

Infrastructure construction account book open mechanism in The satoshi first explained, to the existing account book for the following transformation:

Instead of recording the balance of each villager household, only each transaction was recorded in the ledger. That is, to record the payer, payee and amount of each transaction. How much money each person currently holds can be calculated as long as the original state of the books is established and every transaction is recorded reliably and chronologically. The books have been changed from private to public, so that any villager who needs them can obtain the current complete books, which record all transactions from the time the books were created to the present day. As soon as he said that, the fryer went down. The first one is fine, but the second one is unacceptable, because the ledger records all the villagers’ transactions, so everyone’s privacy is exposed.

Satoshi was in no hurry, came up with a pair of strange things.

‘Don’t panic,’ says Satoshi Nakamoto. Under his scheme, no one trades with their real identity, but with a unique code name.

He showed off the magical objects in his hand and said they were called the seal of Secrecy and the seal scanner. He would then issue a seal of secrecy and a seal scanner to every household in the village. The functions of both are as follows:

The seal of secrecy can be stamped on the paper with a seal, each seal stamped with a hidden string of characters unique to the village, but invisible to the naked eye. You can’t make a seal by looking at it. A seal scanner can scan a sealed seal, read the hidden message, and display a string of characters on the LCD screen. With these two magic things, people can conduct transactions without revealing their true identity, and the hidden string of characters in the seal is the code name of the family. How to use secret seals and seal scanners for transactions will be detailed below.

Next, Satoshi Nakamoto will recruit virtual miners for the whole village. The recruitment requirements are as follows:

Miners in groups, a group can be a separate door, also can be a few joint will not affect the normal use of money for a composition for miners miners to spend some time every day in the currency “dig” activities, but different to dig gold, virtual miners don’t need to take a tool to outdoor work, can finish the work in the home the miners have possibility to get paid, Miners can quit at any time, and new miners can join at any time. Soon, about a fifth of the villagers have joined the Bitcoin miners’ group, which is divided into seven groups.

Set up the initial books (creation block) below, cong announced, according to the two dogs hand books, the mortgage of all gold according to the balance of the books to return to each villager, and then thoroughly destroy the books.

Then, in the hearing took out a new book, on the first page of the books of record some trading records, in particular, the records of the drawee column is all “system”, and the payee are respectively corresponding to each seal characters implied, on behalf of the initial point, default distribution system for each household with a certain amount of COINS, but the quantity is very little, only a few pieces of, There are even some unlucky villagers who don’t get bitcoin.

Then Satoshi nakamoto said, since there is very little bitcoin on the market, we can first go back to the age of using gold as currency, because I am not the village head, I do not have the right to force everyone to recognize bitcoin, we can decide whether to accept bitcoin. But with the movement of bitcoin and miners’ activities, bitcoin will gradually increase.

So much for the setup of payments and transactions, and finally getting to the point, here’s how to make payments under such a system. Take Lao Zhang paying Lao Li 10 bitcoins as an example.

In order for the payer to sign the transaction order to pay for 10 bitcoins, Lao Zhang first asks Lao Li for an identity string, such as “ABCDEFG”, and Lao Zhang also has an identity string, such as “HIJKLMN”. Then Lao Zhang writes a list, saying “HILKLMN pays 10 bitcoins to ABCDEFG”. Then change a seal with his own secret seal and give the list to Lao Li. In addition, in order to facilitate the traceability of the source of the money, it is also necessary to indicate on which page the source of the money is recorded. For example, in this list, 10 bitcoins of Lao Zhang were presented by the system when the account book was established and recorded on the first page of the account book.

After Receiving the bill, Lao Li needs to confirm that the bill is indeed signed by the person “HIJKLMN” (Lao Zhang), which is not difficult. Since the bill must have a secret seal, Lao Li took out the seal scanner and scanned the seal. If the characters displayed on the LCD screen match those of the payer (HIJKLMN in this case), the bill was indeed signed by the payer. This is because, according to the secret seal mechanism, no one else can forge the seal, and anyone can scan the seal to confirm whether the payer and the issuer of the order are the same.

The payee checking the payer’s balance system has been problematic so far. Through the seal of secrecy, the payee can confirm that the payer has indeed signed the bill, but it cannot confirm by itself whether the payer has enough balance to pay. In the previous central virtual currency system, Erdogi was responsible for checking the payer’s balance and notifying the payee whether the transaction was valid. Now that Erdogi is open, who is responsible for the bookkeeping and verifying the validity of each transaction?

As mentioned earlier, the system designed by Satoshi Nakamoto is a distributed currency system that does not rely on any central figure, so there is not one or a few people in charge of this, but ultimately the miners’ organization mentioned earlier. Mr. Zhang, Mr. Li and everyone else in his village who uses Bitcoin rely on the work of the miners’ group to complete their transactions.

Miner’s Work Miner’s work is the heart of the whole system, and it is also the most complex place. The following is a step-by-step introduction to the miner’s work and purpose.

Miner’s Tools As the saying goes, to do a good job, you must first sharpen your tools. Bitcoin miners don’t need iron poutings, shovels and searchlights, but they do need a few things.

Initial ledger. Each group first made its own copy of the initial ledger, which was only one page long and recorded the first giveaway of the system

Empty accounting paper. Each group has a number of accounting paper, each page only has the structure of the accounting book, no content, the specific content of the writing rules will be described later. Here is what an empty accounting sheet looks like, and the meaning of the fields will be explained later

Encoding generator (hash function). Satoshi nakamoto also distributed a number of code generators to each group of miners, a magical thing that fed a page of ledger paper into the machine, which automatically printed 256 numbers of zeros and ones in the “bill number” section of the ledger paper. Best of all, the numbering generator does the following:

Generated number is only related to the content of the paper to fill in the books of the filled out and man, fonts, time and other factors are not content the same books paper generated number is always the same, but if the content even if only one character at a time, instead number will be unrecognisable code generator in printing code also need to put all fill in the books of the paper trade in, Machine scans transaction list and fill in the list of consistency, especially the secret seal, seal and inconsistent, if it is found that confidentiality will refuse to print coding put a sheet of books have been printed in machines will determine if number is effective to print, and determine whether the number and the content is consistent, this number cannot be forged trade single inbox. Each group of miners will need to hang a box at the door to collect transactions. Bulletin board. Each group of miners also needs a bulletin board to publicize some information.

With the tools above, the miners’ organization is ready to go!

In order to collect the transaction slips, The originator of each transaction must not only send the slips to the payees, but also deliver several copies of the identical slips to the inbox of each group of miners.

Members of the miners’ group regularly go to their inboxes to collect a list of transactions and pull it out.

At this point, the team takes out an empty sheet of ledger paper and writes these transactions in the “Transaction list” column. At the same time, they find the last page of the current ledger and copy the number of the last page into the “previous bill number” column. Note that there is also a “lucky number”. You can fill in any number, such as 12345. Then, the account paper into the number generator, print a good number, an account book even completed.

If you think the miner’s job is so simple, it is very wrong, Satoshi nakamoto has a abnormal rule: only the first 10 numbers of the number are 0, this page of accounting paper is effective.

According to the previous description of the number generator, to change the number, you can only change the contents of the account paper, and the “transaction list” and “last account paper number” cannot be changed randomly, so you can only change the lucky number. To generate valid ledger paper, the miners in the team copied and copied ledger paper, each with a different lucky number, into the encoder over and over again. If the resulting number did not match the rules, the paper was discarded, and the process was repeated until it produced a valid series of numbers.

We know that if each numbered number was random, it would take an average of 1,000 different lucky numbers to get a valid number.

So why are these miners working so hard at this seemingly pointless task? Remember we said miners get paid, that’s what motivates them. Nakamoto stipulated that the first transaction on each sheet of ledger paper was “50 bitcoins paid by the system to this group”. In other words, if you generate a meaningful sheet of ledger paper and it is accepted by all mining groups, that means the transaction is accepted and your mining group gets 50 bitcoins.

That’s why miners are called miners, and that’s why the number of Bitcoins has been said to increase as a result of trade and activity by miners. For example, here is a mining process. The group’s public Bitcoin account is “UVWXYZ.”

When the lucky number tries “533,” the system generates a valid ledger page.

When a mining group is lucky enough to produce a meaningful account book, it must immediately ask the other groups to confirm its work in order to receive a reward. As mentioned earlier, there were currently seven mining groups in the village, so this group had to make six copies of valid accounting books and gallop to the other six groups for confirmation.

Cong cong provisions, when a group received other groups sent books paper, must immediately stop the hands of the mining work to confirm the books.

Three pieces of information need to be confirmed:

Before the number of zhang book effective zhang book one page zhang book trades list effectively to see the first above all, this affirms simpler. As long as the sent ledger paper into the code generator for verification, if the verification passes, the number is valid.

In the second part, it is required to compare the number of the “previous page of account paper” on the account page with the number of the last page of the valid account book kept by this team. If the number is the same, it is confirmed; if the number is different, it is required to follow the existing account book forward until the page with this number is found. If it does not find a page corresponding to the specified “previous page number”, the team will discard the page. No confirmation.

Note that the above mechanism ensures that if each group has the same sheet of paper, they can bind the same book in the same order. Because the number of later sheets of paper always depends on the number of previous sheets, the mechanism of the code generator ensures that the relative order of all legal ledger sheets is the same for each group (there may be branches, but no rings, more on that later).

Finally, how to confirm that the transaction list is valid, which is to make sure that the payer of each current transaction has enough balance to pay the money. Since the transaction information contains how the money came from, it also contains the bill number from which the transaction was recorded. For example, HIJKLMN would give ABCDEFG10 bitcoins and note that the 10 bitcoins came from a previous transaction paid by OPQRST to HIJKLMN. The confirmation would first confirm whether the previous transaction existed and also check that HIJKLMN had not paid the 10 bitcoins to others before. After all this is confirmed, the deal is confirmed.

The first transaction was awarded to the 50 teams that generated the page of ledger, which everyone acknowledged by default. The following transactions can be traced to confirm whether HIJKLMN actually currently has 10 bitcoins paid to ABCDEFG.

If all the above verification is completed and passed, the group will recognize the validity of the above accounting paper, and then merge the accounting paper into the group’s main accounting book, abandon the ongoing work, and the subsequent mining work will be based on this updated main accounting book.

Books of the confirmed feedback for mining group, after the paper books out, if have received books from other groups behind the paper, the “previous page books paper number” to send out before their own books of paper, then say their success in your work by other team approved, because there has been a group based on their books paper go on with my work. At this point, you can roughly say you’ve got 50 bitcoins.

In addition, any a group when effective books of the new generation of paper or paper confirmed that the other team’s books, will be recognized by the group’s latest deal wrote on the bulletin board, so the payee, as long as find deals being groups approved by basic can think the money has reached your account, he can back the money at the time of payment of the source points to the deal.

So that’s the whole bitcoin payment system. Let’s take a look at why the system works and the risks it may face.

Although the basic operation rules of Bitcoin are explained above, the villagers still have many questions. So Satoshi held a question-and-answer session to answer frequently asked questions. Sum up the problem that villager cares most centrally below.

Q: What if I receive two legitimate pages at the same time? Note that the mining teams are working in parallel, so it is entirely possible for one team to receive two different pages based on the last page of the current team’s main book, and both are perfectly legal.

On this question, Satoshi nakamoto said that the group should not organize the books in a linear way, but should organize the books in a tree shape. At any time, the longest branch should be used as the main book, but the other branches should be kept. For example, A group receives two account pages A and B at the same time, both of which are legal after accounting. In this case, the group should organize the two pages in the form of bifurcation, as shown in the figure below:

Black indicates the current account trunk. At this point, you can choose any page as the current main branch, for example, select A:

If there is A new ledger page based on A, the trunk continues:

If this trunk goes on like this, it means that everyone is basically doing A, and B will be forgotten. But it’s also possible that suddenly B becomes longer:

Then we need to take branch B as the current trunk and work from there.

Locally, while the backbone of each group’s ledger may differ at one point in time, the general direction is the same, and those small branches that are occasionally out of sync are quickly lost to history.

About this question, Satoshi nakamoto said that as long as most people in the mining organization are honest, the system will be reliable. He gave specific answers from several aspects.

First, based on the secret seal mechanism, no one can forge another person’s identity to make payment, because the code generator will check the secret seal of all transactions when printing the code, and the seal and the payer will not be able to print.

And honest miners will not admit to illegal transactions (such as one in which the payer has an insufficient balance).

So there is only one possible attack, which is to set up another transaction order from another branch after the recipient has confirmed the payment, cancel the previous payment and pay the same money to another person again (the so-called double-spending problem). Here’s another example to illustrate the problem.

Suppose an attacker owns 10 Bitcoins and is prepared to pay both victims, A and B, to be recognized.

In the first step, the attacker prepares to buy 10 bitcoins of gold from Victim A. He signs A transaction order to victim A and transfers 10 bitcoins to victim A.

In the second step, the transaction is confirmed in the latest books and announced by the mining groups. Victim A sees the announcement, confirms that the bitcoins have arrived, and gives the attacker 10 bitcoins worth of gold.

In the third step, the attacker finds the ledger and makes a branch from the previous page of the ledger containing the transaction, generating more billing pages than the previous branch. As the branch created by the attacker becomes the main branch, and the branch where victim A received the money becomes the side branch, the mining organization no longer recognizes the transfer and victim A’s 10 Bitcoins are cancelled.

In the fourth step, the attacker can sign the transaction again, paying victim B the same amount of money. Victim B confirms that the money has arrived and pays the attacker the gold equivalent.

At this point, the attacker spent the 10 bitcoins twice, buying gold from each of the two victims. The attacker could also do the same and cancel the transfer with victim B and pay the same money to someone else…

About this attack, Satoshi nakamoto gave the solution is to suggest that the payee should not immediately confirm the completion of the transaction in the announcement of hanging out, but should look at a period of time, waiting for each mining group to hang out six confirmed books, and the previous books have not been cancelled, to confirm that the money has arrived in the account.

Satoshi explained, before setting abnormal numbering rules, it is to defend this point. As mentioned earlier, generating valid book pages is not that simple, it takes a lot of human effort to try different lucky numbers over and over again, and the process is purely hit-or-miss. If one ledger page contains confirmation that you have received money, and six more continue after that, it is very difficult for an attacker to overtake the current main branch from another branch after being six pages behind, unless the attacker has a lot of manpower, more than all the other honest miners combined.

Also, if the attackers have so much manpower, it’s better to be a good citizen and get more out of mining than to put so much effort into such an attack. This prevents an attack from forming on a slave.

‘Bitcoin will continue to increase, won’t it lead to serious inflation,’ Mr. Nakamoto said. I forgot to mention that the operation manual I gave to the miners’ organization stated that at the beginning we agreed to reward the team with 50 bitcoins for each page of the ledger generated. Later, the reward would be halved for each additional 21,000 pages of the ledger, for example, 25 Bitcoins for each page generated after 210,000 pages. After 420,000 pages, 12.5 bonuses per page generated, and so on, after 6,930,000 pages, there are no bonuses for new pages generated. At this point, the total number of bitcoins is about 21,000,000. That’s the total number of bitcoins, so it’s not going to grow indefinitely.

If there’s no reward, there’s no one to work as a miner, there’s no one to confirm the deal, and the miner’s income will change from mining to collecting fees. For example, when you transfer money, you can specify that 1% of the transaction is paid as a fee to the team that generates the book page. Each team will select the transaction with the highest fee to confirm first.

Will bitcoin be created faster if there are more miners? No. In the hearing to explain, is free to join and exit miners, though, the number of miners, each miners will also get a code generator, but I have joined the regulatory mechanism in the code generator, the current working code generator, the more the lower the efficiency of each machine, ensure that the books of the new page generation rate unchanged.

Everyone’s name is anonymous, but if you leak someone’s name, and the books are open, wouldn’t all of their accounts be accounted for which they are. For example, if you want to trade with someone, you must get his code number to fill out the transaction form. Because you have to put that person’s code name in the payee column. However, Satoshi nakamoto said that unlimited seal of secrecy can be provided, suggesting that each transaction with a different seal of secrecy, so that the audit books can not trace all the accounts of the same person.

End of q&A.

Note This article explains the operation mechanism of Bitcoin in a popular way. A few caveats:

I’ve made a lot of simplifications to make it easier to understand, so some of the mechanical details may not be exactly the same as the actual Bitcoin. But the general idea and the key principles are the same. Since many things in the computer world (public-key systems, network transport) don’t have particularly good real-world equivalents, the story inevitably has some hard and perverse details. This paper describes the technical principle and operation mechanism of the Bitcoin network itself. When Bitcoin is traded in a trading market like Mtgox, the market acts as an intermediary agent and does not comply with the above mechanism. Refer to Bitcoin: A peer-to-peer Electronic Cash Systemhttps:// Bitcoii. it

| | copyright statement: this article for the blogger Du Jin YangYuan articles, reprint please indicate the source.

Author: ultraman superman Dujinyang

Source: CSDN

Original text: dujinyang.blog.csdn.net/

Copyright notice: This article is an original article by du Jinyang. Please attach a link to it.