Principle and operation mechanism of bitcoin


Source: http://blog.codinglabs.org   

Barter bit Village

        In this world, there is a small village called bit village, There are hundreds of families in the village. The village was almost isolated and lived a self-sufficiency life. Because there is no large-scale trade, the bit village lived a barter life. That is to say, the villagers did not use a unified currency and the basic trade is Lao Zhang exchange a bag of flour with a sheep of Lao Li. Miss Wang exchange a basket of fruit with two feet of cloth of Aunt Liu. The villagers have been lived so simple life.

      

Physical currency


       Finally one day, the villagers feel barter too inconvenient, and then the village staff have a meeting to discuss how to solve the problem. Somebody propose use easily be divided and rare things, such as gold, as a general equivalent, then corresponding relationship between other items and gold, such as corresponding to one gram of gold a sheep, one gram of gold corresponding a bag of flour and so on. At this time, Mr Zhang never carrying a bag of flour to Mr Li’s home for sheep, he need only pulled out a gram of gold from home,and can hold back a sheep from Mr Li’s home. and Mr Li took the grams of gold from anyone in exchange for a bag of flour, of course, he can also be in exchange one gram gold for any equivalent items. At this time, the village entered the physical currency era.

Sign currency


       The good times don't last long, over a period of time, the disadvantages of physical currency also appeared. Because of the gold mine near the bit village is not too much, mining and smelting gold is consuming too much time and laborious. And the gold will loss by using, loss or someone deliberately hoarding. The village people sit together once again to discuss countermeasures. One person say that, in fact we do not have to use really gold, casually looking for a piece of paper, write "one gram of gold", as long as the village people would agree with this piece of paper is equal to one gram of gold, the problem is solved. Other people have been recognized, but a new problem occurs: Real gold need of mining and smelting, the gold mine is limited and mining and smelting consumes cost, so no one can easily manufacturing large amounts of gold in short time, but writing is different, as long as I have enough paper and pen, I can write the number as many as I want, then it becomes compete who has more paper, it will cause ten thousand pieces of paper to change a sheep (in fact, this is the economics of inflation).    
   
        Everyone recognized the problem. But then one person put forward a solution: This paper is not effectively written by anyone, we only recognize the paper written by respected old village chief, everybody knows the old village chief’s words. The old village chief write some paper, at the same time, send everyone an equal amount of paper according to various stock of gold, Family Zhang, for example, has 200 grams of gold, the old village chief sent Family Zhang 200 pieces of paper “one gram of gold”, at the same time, the gold of Family Zhang has taken as collateral. So, the old village chief get collected all gold reverted to his home, and issued to the equivalent paper according to golden number get from each family. At this time the villagers can trade with the paper as the gold, and we all know the old village chief’s word, other people can't make fake one. In addition, if the paper becomes abrasion, it can exchange with the new equivalent paper from old villager chief. In addition, the old village chief promised anyone if you want to trade for real gold, as long as send back the paper , the old villager chief will send the equivalent gold back to the people. Because the amount of paper written by old village chief is same as the real amount of gold in the home, so as long as in strict accordance with the destruction and write same of the paper principle, each valid paper can exchange for true gold.  
 
       At this point, the bit village entered a symbol currency (banknotes) era. The old village chief took on the government and the bank's role.

Central system virtual currency


       Then after a few years, the old village chief not only need to check a large number of old notes and write new banknotes every day, but also recorded the various accounts carefully. In the long run, the old village chief unfortunately died because of overwork.    
   
       Bit village held a general meeting again to discuss how to solve the problem. At this time the son of the old village chief took over his father's pen, to take the responsibility of currency. This young village head is very clever, After a few days, he found that it seems that you do not really write so much paper. It can be: the villagers handed over all the bill and destroyed, but the village head will record the number of banknotes per household. Later if you want to pay, such as Mr Zhang exchange a gram of gold to Mr Li for a sheep, they will make a phone call to village head that transfer one gram of gold from the name of Zhang to the name of Li, the village head took out books, to see whether there is a gram of gold under the name of Zhang, if it is then minus a gram from Zhang's name, and add a gram in the name of Li, thus completing the payment. This time when Mr Li heard on the phone that the village head confirm the transfer is complete, then he allowed Mr Zhang took the sheep away.  
 
       At this time, the bit village entered the era of central system of virtual currency. Each of the villagers do not need to pay real things, payment process changed to the maintenance of changes on the accounts.

Distributed virtual currency


       The new village head were smart, but this man was sometimes too clever by half. One day he stared at the book, thinking that the village households who have how much money is controlled by me, then I would ....... He was get a hot head, secretly made decagram gold to their name from Mr Zhang.

       The village head thought it is seamlessly as well, but he did not expect Zhang also have habit of charge, one day Mr Zhang was about to pay but was informed that the account does not have the money. Mr Zhang checked his own books, obviously there are 10 grams, and took the books to argue with the village head, after check the transfers was found without the consent of Mr Zhang.

       The village head's criminal conspiracy was unmasked! Bit village was hit by the news! The village head impeachment is inevitable, but through this thing, we found disadvantages of the books focus on the hands of a person:

       - The system is completely dependent on the books holder’s personal credit, if the people don't be honest, tampering with the books, then the whole monetary system will collapse.
        If book burned by home fire or stolen by theft, it will also bring a devastating blow to the entire system.

Just as people were overwhelmed, a scientist called Nakamoto otaku in the village went onto the stage, to tell you he has designed a bitcoin's virtual currency system which does not rely on any central processing, it can solve the problems above. Then he slowly tells his plan.

Here we take a look at how Nakamoto designed the system.

Infrastructure construction


Books open mechanism


       Firstly Nakamoto addressed that it need to reform the existing books are as follows:

       a. Books don’t record the balance of the accounts of the villagers , and only record each transaction. That is, the payer, recipient and the payment amount of each transaction. As long as the initial state of books  determination confirmed, each transaction records and reliable time series, currently everyone hold how much money can be calculated.

       b. Books status change from private to public, as long as any of the villagers need it, it can obtain the complete books, books recorded all transaction records from the beginning to the current.    These words immediately causing concern among the village, it does not matter for item 1, but the second one is simply unacceptable, because the books recorded all the transaction of the villagers, so everyone's privacy is exposing.

       Nakamoto unhurried took out a strange thing.

Identity and signature mechanism (public key encryption system)



Nakamoto said we do not panic. Under his mechanism, no one is using real identity transactions, but use of a unique code to do transactions.

       He demonstrated the magic thing, saying that the two things were called the seal and seal scanner. He will give each of the village a confidential seal and a seal scanner. The functions of the two things are as follows:

       Privacy seal can sign in paper, each seal’s sign implies that only one string of characters in the village, but it is invisible with the naked eye. And can not to create a corresponding seal by observation

       The seal scanner can scan a sign, read the implicit information and display a series of characters on the LCD screen.

       With these two magic things, we can do transaction and do not reveal the true identity, and the string implied  by the seal is the characters code of the family. How to use the secret seal and the seal scanner to transaction will be described below.

The establishment of Virtual Organization (Mining Group)


       The next step, Nakamoto recruit virtual miners in the village , the recruitment requirements as the follows:

       Miners take groups as units, a group can be one individual household or several households

       Become a miner will not affecting the normal use of money.

       Miners spend some time in the bitcoin mining activities every day, but different with dig gold, virtual miners don't need operate with a tool in the field, and can finish the work at home.

       The miners have possibility to get paid, more efforts in mining activities, the greater the possibility of remuneration

       The miners can withdraw any time or join in at any time.

       Soon, about 1/5 of the villagers joined the bitcoin miners, a total of 7 groups were divided.

The establishment of the initial books (the 1st block)


       Nakamoto announced that firstly according to the village head’s books, returned all the mortgage gold to each of the villagers according to the records of the balance , and completely destructed the books.

       Then Nakamoto took a new book, on the first page of the book record some transaction records, in particular, the payer column of these records is all "system", and the receiver respectively corresponding to hidden character of each seal, representing the initial moment, system default assigned a certain number of bitcoins for every household, but the number of bitcoins are very small, only a few pieces, and even some unfortunate households didn't get bitcoin.

       Then Nakamoto said that due to bitcoin is very rare in the current market, we can go back to the era of gold currency, because I am not the villager head, I have no right to force everyone to recognize bitcoin, we can decide whether or not to accept bitcoin. But with the flow of bitcoin and the activities of the miners, bitcoin will rise slowly.

Payment and transaction


       After set the stage, and finally let’s focus on how to complete the payment under such a system. For  example Mr Li want pay 10 bitcoin to Mr Zhang.

The payer signed a transaction


       In order to pay 10 bitcoins, Mr Zhang firstly need to ask Mr Li's identifier string, such as "ABCDEFG". At the same time, Mr Zhang also have an identification string, for example, HIJKLMN. Then Mr Zhang write a list, the content is "HILKLMN pay 10 bitcoin to ABCDEFG", then sign with their own privacy seal, the list will be handed over to Mr Li. Also in order to trace the source of the money, it indicate the page number that the source of this money in the list, for example in the list, Mr Zhang’s 10 coins come from the donation of system for established account books, record on the first page of the book.

The recipient confirm the signature of the bill


       Mr Li got the bill and need to confirm this bill is indeed signed by the man “HIJKLMN” (that is, Mr. Zhang), this is not difficult. Because there must be confidential seal in the bill, Mr Li take out of the seal scanner, scan the seal, if the characters display on the LCD screen is consistent (here is the "HIJKLMN")with the payer, then it can confirm the bill is indeed signed by the payer. Because according to the mechanism of the confidential seal, no other person can make a fake seal, Any person can confirm if the payer is the man who seal the bill by just simply scan a seal.

The recipient's balance is confirmed


       This system is still has problem at present. Through the confidential seal, although the recipient can confirm that the payer did sign the bill, but could not confirm whether the payer has enough balance to pay. In the central virtual currency system, and the village head is responsible for check the balance of payer, and notify the payee that the deal is valid, and now there is no village head, who is responsible for billing and confirm the validity of each transaction?

       As talked before, the system designed by Nakamoto is distributed currency system, it does not rely on any of the central characters, so there will be no one or a few people responsible for this matter, it is the miners organisation mentioned before eventually to undertake this work.Mr Zhang, Mr Li and any other villagers who use bitcoin transactions rely miners organisation in order to complete the transaction.

Miner's job


       Miners' work is the core of the system, but also the highest complexity work. The contents and purpose of the miners work are gradually introduced in the following.

Miner's tools


       As the proverb saying, to do his work well, firstly sharpen his tools. Though Bitcoin miners not use iron stick, shovel,search lights and other tools, but he must have some essential things.

       The initial books. Each group firstly make a copy of the initial books, the initial books only have one page, record first donation of system.

       Empty paper books. Each team has several books of paper, each page of paper only has books structure, did not fill content, the specific content of the rules will explain later. The following is how an empty paper books looks, each field meaning of items will explain later.

Code generator (Hashi function).


       Nakamoto distribute a number of code generators to each miners group, this thing is amazing, put a page of books filled with content into the machine, the machine will automatically print a string of numbers composed by "0" and "1" in the "the bill number" column of the books paper, totally 256 numbers. The most amazing is that the number generator has the following functions:

        The generated number is only related with the contents of paper books, had nothing to do with the people, the font, fill in time etc.

       The same books paper generated number is always the same, but even if the content only change a character, the generated number will beyond recognition.

       Code generators need all the transaction bill which filled in the books before printing code, the machine will scan the bills and filled in transactions consistency, especially the privacy seal, if privacy seal and payer’s seal found inconsistent, it will refuse to print the code - After a printed books put into the machine, the machine will determine whether the number is valid printed by machine, and determine if the number and content are the same, this number cannot be faked

       Transactions inbox. Each miner's team needs to hang a box at the door to collect the transaction orders.

       Bulletin board. Each miner's team also needs a bulletin board to announce some information.

       With the tools above, the miners can start!

Collect transaction orders


       Nakamoto make rule for the initiator of each transaction, not only send the transaction orders to the recipient, but also copy several same transaction sheet and send to the inbox of each miners.

       he miners' group regularly collects the collected transactions from their inbox and takes them out.

Fill in the books

       This people in the group took a blank books paper, fill these transactions to the "transaction list" column, and find the last page of the books, copied last page numbers to the "last bill number column". Note that there is a "lucky number", you can easily fill a number, such as 12345. Then, turn this paper into number generator, printed the generated numbers, a book is done.

       It would be wrong if you think the miners work is so simple. Nakamoto has an abnormal regulation: only if the first 10 numbers are 0 of the number, this page book paper will be effective.

       According to the prior description of number generator, if you want to modify the number, you can only modify the contents of books, the "transaction list" and "last paper number" cannot be easily changed, so it can only change the lucky numbers. So in order to generate a valid book paper, miners in the group will continue to copy books paper, but lucky number for each piece of paper are different, then repeating continuously put paper into the encoder, if the generated code does not meet the requirements, this piece of paper is waste, repeat this process until the formation of a series of effective number.

       We know that if every number of numbers is random, then write more than 1000 lucky numbers averagely to get a valid number.

       This is strange, why did the miners desperately do this seemingly meaningless thing? Remember that the miners have gift, this is the power of the miners. Nakamoto make rules: the first transaction of the trade list of every piece of book paper is "payment of 50 coins to the team". That is to say, if you generate a meaningful book paper, and it is accepted by all mining groups, then it means that the transactions have been accepted, your mining group received 50 coins.

       This is the reason why the miners were called the miners, that is why along with the transactions and  activities of the miners, the number of bitcoin will continue to increase. For example, the following is a mining process, the group's public bitcoin account is "UVWXYZ".



"To try in the lucky number 533", the system generated a valid page book.

Confirm the books

  
       When a mining group lucky generated a valid book, in order to get the reward, the group must immediately ask other groups to confirm their own work. Said before, the village currently has seven mining groups, so the team must send 6 copies of the valid book to the other six team for confirmation.

       Nakamoto make rule that when a group received the book paper from other team, the group must immediately stop mining work to confirm the book paper.

       There are three information need to confirm:
       1. The number of book is effective
       2. The previous page book is available
       3. Transaction list are valid

       Firstly this confirmation is relatively simple. Only send the book paper into the code generator to be verified, the number is effective if it passed the verification.

       Secondly it will compare the team’s last page of effective book with "last page book number" of the book. If they are same then confirmed, if they are different then need to down the existing books forward until you find the right number of page. If the specified " corresponding number of last book paper page " page not found, the team will abandon this page. No confirmation.

       Based on mechanism above can guarantee that if the book paper in the hands of each group are the same, then they can bind the same books by the same sequence. Because the paper number always rely on the number of front paper, the mechanism of code generators ensure the relative sequence of all legitimate ledger paper in each group are the same (may have branch, but does not appear to ring, explain the detail later ).

 
       Finally, how to confirm the transaction list is effective, in fact to confirm that the current payer of each transaction has enough balance to pay the money. As the transaction information contains how the money is coming, it also contains the bill number for recording source transaction. For example, HIJKLMN give 10 bitcoin to ABCDEFG and indicate the 10 coins come from the deal OPQRST payment to HIJKLMN, Prior to the confirm firstly confirm if the transaction exist, also check if HIJKLMN pay the 10 bitcoin to others before the transaction. After all of this confirmed, the validity of the deal was confirmed.

       The first deal is a reward system give 50 bitcoin to the group who generate this book page, we all default admit the deal, the following deals in accordance with the method of back tracing, you can confirm if HIJKLMN the current really paid 10 bitcoin to ABCDEFG.

       If the completion of all the validation, the team recognize the book paper above effective, then this book paper is incorporated into the main books of the group and abandon the ongoing work, the future mining work will based on the updated master books.

Confirming the feedback of books


        Also when the team generated new book paper or confirmed other groups book paper, then writes the acknowledged transaction in bulletin board, then the payee found that the related transactions are recognized by each group, then basically you can think the money has in your account, you can point the source of the money to this transaction when make a deal later.

        This is the entire bitcoin payment system. We analyze here why this system can work, and the risk of the system may be faced.

Working mechanism analysis


       Although we described the basic operating rules bitcoin, but the villagers still have many questions. So Nakamoto specifically to open a Q&A meeting. The most concentrated concern problem of the villagers sums up as follows:

Core questions answering


How to do if it received two legal books page at the same time?


       Note in the operating mechanism of the above, each mining group is working in parallel, so it possible to meet such a situation: a group received two different books page, they are based on the group's last page of main book, and the content are perfectly legal, how to do?

       For this issue, Nakamoto said that the team should not organize books in a linear way, and should to treelike organize books in a treelike way, Currently the longest branch should be the main books, but it need retain other branches. For example, a group received two books page A, B at same time, they are legal after accounting, this group should organize the two pages to bifurcation form as shown below:


       Black represents the current main books. At this time, you can choose a page as the main branch, such as the choice of A:


       If there is a new book page based on the A, then the trunk continues as follows:


       If this backbone continuously grows, we are basically use A as backbone, and B will be forgotten. But it is possible that B becomes longer suddenly:


       Then we need to use B as the current trunk, work based on this branch of follow-up work.


       From the local point of view, although the main trunk of each group may not consistent in some time, but the direction is consistent, Occasionally the small branches which have not synchronized will be submerged in history soon.

How to do if people do fake books in the mining group?


       On this issue, Nakamoto said as long as most people of mining organization are honest, the system is reliable, and the answer including several part:

Firstly, based on privacy seal mechanism, no one can fake identity to make a payment for others, because the code generators will check privacy seal of all transactions before printing code, it will refuse to print if the seal is inconsistency with the payer.

       And honest miners will not recognize illegal transactions (such as the balance of payer in a transaction is not enough).
       So there is only one possible attacks, namely after payee confirm receipt, established in a single transaction from another branch, cancel the prior payment and pay the same amount of money again to another person (the so-called double spending problem). The example illustrates the problem.

Assume that an attacker has 10 bitcoin, he is ready to pay the money to the two victims A and B, and they all recognized.

       The first step, the attacker ready to buy 10 bitcoin gold from the victim A, he signed a deal to the victim A, transfer 10 bitcoin to the victim A.


       The second step, the deal was confirmed in the new book page, and announced by each mining group. The victim A see the announcement, confirmed the bitcoin arrival in account, and give 10 bitcoin equivalent gold to the attacker.


       The third step, the attacker find books, make a branch in previous page of the page that contain book paper created just now, generate more page bill, just over the branch. Because at this time the branch created by the attacker's became the main branch, and the branch contains the victim A became sub-branch roadside, therefore mining group no longer recognize the transfers just now, victims of A’s 10 bitcoin was cancelled.


       The fourth step, the attacker can once again signed a transaction, pay the same amount of money to the victim B. After the victim B confirm the money to the account, pay the equivalent of gold to the attacker.


       So far, the attacker spend 10 bitcoin two times, purchase equivalent gold from two victims. The attacker can also work again, and cancel the victim B transfer, pay the same amount of money for other people......

       About this attack, the Nakamoto recommend solution is that the payee do not immediately to confirm the completion of the transaction when the announcement hang out, but should monitor for a period of time, waiting for the various mining groups hang 6 confirmation books, and the prior book is not canceled, then confirm the money has been credited into account.

       Nakamoto explained that the abnormal rules of number is to defend this point. According to the description it is not so simple to generate effective books, It spend a lot of trial of lucky numbers and the process is completely luck. If a book page contains the confirmation you receive the money and continuation of the six in the backward, then the attacker wants to catch up with the current main branch from a separate branch in the backward 6 pages is very difficult, unless the attacker has great human power more than all other honest miners.

       And if the attacker has so many human power, Rather than spend so vigorously power in this kind of attack , it  get more revenue by mining in law. This has effectively stop the formation of attacks.

Bitcoin will continue to increase, it will be serious inflation


       Nakamoto said I also thought of this. Forgot to say before, It will tell in the rules in the operation of manual for the miners association, When it started our agreement is reward 50 bitcoins to team for each generated page book, whenever the books increased 210000 pages and reward half, such as when the page reach to 210000, each generated page book awards 25 bitcoin, after 420000 pages, each generated page reward 12.5, and so on, when the books number reach to 6930000, new generated book page is no reward. At this time the total amount of about 21000000 bitcoin, which is the total amount of bitcoin, so it will not increase indefinitely.

During the no reward time, no one will be the miners, and no one to help confirm the transaction


       Then, the miners will get charges as mining income. For example, you can specify which 1% as procedures fee paid to the group who produce books page, each group will prior to confirm high fees transaction.

If miners increases, then bitcoin generated speed will become faster


       No, explained by Nakamoto, although it can be arbitrary to join and exit miners organisation, lead to changes in the number of miners, each miner will also get a code generator, but I have joined the regulation mechanism in the code generators, if it get more code generators, the efficiency of each machine is lower, to ensure the new books page generation rate unchanged.

Although each person's name is anonymous, but if someone leaked code and the account is public open, then does all of his accounts to be checked out?

       It's true.For example, if you want to trade with someone, you must get his code to fill in the transaction paper. Because the cashier must fill in the code of the person. But Nakamoto said it can provide unlimited privacy seal, it is recommended use different privacy seal for every deal, so all accounts of the person can not be checked.

       That’s all questions answer.


没有登录不能评论