Introduction: Bitcoin, as the most successful digital cryptocurrency in recent years, has attracted great attention from the world. Unlike other digital currencies, Bitcoin uses a decentralized distributed network consisting of many nodes to record transaction information. The key is blockchain: a technology that may bring huge changes to the financial industry and other industries in the next decade. Today, let's learn about blockchain technology in conjunction with Bitcoin. 1. Scenario description Imagine there are two banks in the world: Bank A and Bank B, and two users: User C and User D. User C also uses a third-party payment software E. Bank A uses its own information system to record account balances for users, Bank B also uses its own information system to record account balances for users, and third-party payment E also uses a system to record the account balance of user C. This is basically what the financial world looks like today, as shown in the following figure: We can clearly see the following facts: Bank A's system records that Bank B owes it $8 million, and Bank B's system also records that it owes Bank A $8 million. In other words, the same information is recorded twice by different systems of the two banks. Similar information is also recorded in Bank B and third-party payment E. User C has an overdraft of RMB 15,000 at Bank A, a deposit of RMB 68,000 at Bank B, and a balance of RMB 5,000 at third-party payment E. Therefore, only through the three systems of two banks and one third-party payment can the actual property owned by user C be calculated. We can see that each bank has to spend a lot of time and money to develop and maintain a system to record information. What’s more serious is that they need to spend more time and money to check and reconcile accounts between banks. Banking data needs to be recorded in at least two different systems. In order to ensure that the information of all parties is correct, a costly reconciliation process is required. Let's make a change and use only one table to record all the data in the above example, as shown below: The table above has the same contents as the previous five tables, the only difference is that this table has one more column. With this table, banks and users do not need to maintain their own systems, and most importantly, the process of reconciliation between banks is completely eliminated. So, why can't the world have a unified ledger? Some people may immediately ask, which single system is capable of maintaining this ledger? How high is the cost of maintaining this ledger? If this system fails, how big will the impact on the world be? What if this central system cheats in the ledger? It seems not feasible to create a central system to maintain a unified ledger. So, can we create a shared network where all banks and users are in the network? There is no central system to maintain the ledger. Instead, all banks and users in the network have the latest content of the ledger. The ledger is maintained by all participants in the network. This prevents the loss of the ledger caused by the failure of the central system. If a participant wants to cheat, others will not agree. It is equivalent to each participant contributing to ensure the security and stability of the ledger. Is the above technical solution feasible? It is feasible; What is this technical solution called? Blockchain; Is there any successful case now? Bitcoin. 2. Blockchain concept Blockchain is a decentralized, distributed, shared ledger or database on the Internet. Through certain technologies, the consistency, security, and maintainability of this ledger or database can be guaranteed. Bitcoin is the first large-scale application of blockchain to the global network. Blockchain technology itself is not limited to digital currencies such as Bitcoin. It can also be applied to many fields such as payment, securities trading, stock trading, Internet of Things, identity authentication, electronic contracts, etc. 3. Blockchain in Bitcoin Bitcoin Overview In 2008, a mysterious person named Satoshi Nakamoto published a paper that expounded the concept and related technologies of Bitcoin. This paper was later called the Bitcoin White Paper or the Satoshi Nakamoto White Paper. In 2009, Satoshi Nakamoto and others realized the related technologies, and the system was officially running on the Internet, marking the official birth of Bitcoin, which is not controlled by central banks and any financial institutions. Two years later, Satoshi Nakamoto suddenly disappeared from the Internet, and until now no one knows the true identity of this person who is equivalent to the prophet of creation in the Bitcoin world. The current overall value of Bitcoin he created has exceeded 10 billion US dollars, and millions of Bitcoins are traded on the Internet every day. Bitcoin Principles Bitcoin runs on the P2P network based on the Internet. P2P is an application layer protocol running on the TCP protocol. In the P2P network, each device connected to the network is equal to each other. There is no central node in the network. Each node randomly connects to many other nodes, provides services for these nodes, and also obtains services from these nodes. Therefore, the P2P network has the characteristics of decentralization, reliability and openness. In recent years, the most successful P2P network applications have occurred in the field of file sharing, such as BitTorrent abroad and Xunlei in China, which all download files through P2P networks. In Bitcoin's P2P network, each transaction information will be notified to all nodes in the network for verification in a one-to-ten, ten-to-a-hundred manner. Only when most of the nodes on the network have verified it will the transaction be recorded in the current block of the blockchain. In the Bitcoin network, a block is generated every 10 minutes on average. The block records all transactions on the network in the previous 10 minutes. Each node has the right to generate a block. As long as the node can calculate the solution to a specific math problem within these 10 minutes, other nodes will recognize the block and add the block to their own blockchain. The node that obtains the solution will receive a certain number of bitcoins as a reward. In the Bitcoin network, nodes that attempt to generate blocks and get rewards are usually called miners. The process of generating blocks is called mining. Since 2009, the difficulty of dynamically adjusted math problems has resulted in an average of one block being generated every 10 minutes in the Bitcoin network (a miner has found a solution to the math problem). With each block generated, a certain number of bitcoins are generated as rewards to the miner. Initially, the reward for each block is 50 bitcoins, and this number will be halved every four years. After 2140, the number of bitcoins will be fixed at 21 million, and no new bitcoins will be generated at that time. Any machine can run a complete Bitcoin node. A complete Bitcoin node includes the following functions: Bitcoin wallet, which allows users to trade on the Bitcoin network; complete blockchain, which records all transactions in Bitcoin history, ensures the security of historical transactions through a special structure, and is used to verify the legitimacy of new transactions; miners, who generate new blocks by recording transactions and decrypting math problems, and can earn rewards if successful; routing function, which transmits transaction data and other information sent by other nodes to more nodes. In the Bitcoin network, nodes, except for the routing function, are not required to have other functions. Some nodes only have wallet functions, and some nodes are only responsible for mining. The data structure of blockchain The Bitcoin blockchain records transaction information. Each complete node stores a complete blockchain locally. Each complete blockchain records all transaction information that has occurred since the birth of Bitcoin in 2009. Whenever a new transaction application is generated, the node can verify the correctness of the new transaction through the complete blockchain. The verified transaction will be recorded in the next new block to be generated. Each block consists of a block header containing metadata and a block body containing transaction information in the previous period. The size of the block header is 80 bytes, and the block body is usually very large. If an average block contains 400 transactions, then the block body is usually more than 1,000 times larger than the block header. Therefore, the block body is only responsible for recording transaction information, and most of the functions of the blockchain are implemented by the block header. The block header mainly includes the following information: Version number, 4 bytes, indicating the version information of the software and protocol; Parent block hash value, 32 bytes, the hash value of the parent block header in the referenced blockchain. Through this value, each block is connected end to end to form a blockchain, and this value plays a vital role in the security of the blockchain, which will be introduced in detail later; Merkle tree root, 32 bytes. This value is calculated by hashing the hash values of all transactions in the block body in pairs. It is mainly used to verify whether a transaction exists in this block. Timestamp, 4 bytes, records the time when the block was generated, accurate to seconds; Difficulty value, 4 bytes, the difficulty target of the math problem related to this block; Nonce, 4 bytes, records the value of the answer to the math problem related to decrypting the block; The block header of each block records the hash value of the parent block it references. This hash value is calculated by performing a secondary hash calculation on the block header of the parent block using the SHA256 algorithm. The information of some blocks in a blockchain is as follows: The process of building a blockchain The process of generating new blocks and adding them to the blockchain is called mining in the Bitcoin network. Through mining, transaction information can be recorded in the blockchain, and it is precisely because of the proof-of-work mechanism (solving math problems) that the consistency and security of transaction information in the blockchain are guaranteed; for Bitcoin, the reward mechanism after successful mining allows new Bitcoins to enter the Bitcoin network for circulation. In the Bitcoin network, some nodes are called miner nodes. This miner node can be an ordinary PC machine of a user, a computing cluster composed of hundreds of machines in an enterprise computer room, or a mining pool composed of multiple miners. Bitcoin has no restrictions on the machines of miner nodes, but miner nodes with higher computing performance will be more likely to solve math problems than other nodes to obtain the right to record accounts and Bitcoin rewards. While miners are working hard to generate blocks, they will also save new transaction information to local memory to be put into the next block. After the current block is generated and verified by themselves or other miners, all miners will immediately start generating the next block. At this time, the transaction information in the local memory will be recorded in the block body, and the Merkle tree of all transaction information in this block will be generated in the block body, and the value of the Merkle tree root will be saved in the block header. The Merkle tree is a hash binary tree that can be used to quickly verify the integrity of large-scale data. In the Bitcoin network, the Merkle tree is used to summarize all transaction information in a block, and finally generate a unified hash value for all transaction information in this block. Any change in transaction information in the block will cause the Merkle tree to change. Assume that there are four transactions in a block, namely A, B, C and D. First, the transaction data is passed through the SHA256 algorithm twice to generate a 32-byte hash value. These values are stored as leaf nodes in the Merkle tree. Then, the two 32-byte hash values of adjacent leaf nodes are concatenated into a 64-byte string. Then, this string is passed through the SHA256 algorithm twice to generate a 32-byte hash value as the parent node of the two leaf nodes and stored in the Merkle tree. And so on, finally a unified hash value of all transaction information in the block is generated. This hash value is the root node of the Merkle tree. The hash value of the root node is stored in the block header, as shown in the following figure:
After the Merkle root is filled into the block header, the system will generate a 32-bit hash value from the block header of the last generated block through the SHA256 algorithm and fill it into the parent hash value of the current block, and then save the current Unix time in the timestamp field. The difficulty value field will also be adjusted according to the average generation time of blocks in the previous period to cope with the changing total amount of calculations in the entire Bitcoin network. If the total amount of calculations increases, the system will increase the difficulty value of the math problem so that the expected time to complete the next block is still around ten minutes. The last field in the block header is Nonce, with an initial value of 0. After the block header and the main body of the block are constructed, mining, which is to solve math problems, can begin. The goal of mining is to make the hash value obtained by using the SHA256 algorithm on the block header meet the difficulty value requirements by constantly changing the Nonce value in the block header. The SHA256 algorithm is a cryptographic hash algorithm. The characteristic of this algorithm is that different inputs will produce completely different hash values, without any rules to follow, and no matter how large the input is, the length of the output of the SHA256 algorithm is always 256 bits, or 32 bits. The goal of Bitcoin mining is to find a Nonce value so that the output of the SHA256 hash value of the block header under this value must be less than the value set in the difficulty value. This difficulty value usually starts with multiple 0s. The current latest difficulty requirement is that the first 68 bits of the 256-bit hash value must be 0. This requires the entire Bitcoin network to perform about 6x1020 hash calculations per second so that miners can find a Nonce value that meets the requirements within about 10 minutes. During the mining process, since the timestamp in the new block header created by each miner may be different, and since each miner chooses a different set of transactions to enter the block, the value of the Merkle root in the block header is also different. Therefore, even if many miners start to accumulate and search for qualified hash values from Nonce equals 0, they are still searching in their respective locations. The mining process is the process of finding the answer by adding up the computing power of all miner nodes in the entire Bitcoin network. Every miner has the opportunity to find the correct answer, but miners with higher computing performance have a greater probability of finding the answer. When a miner successfully finds a Nonce value that makes the block header hash value less than the target difficulty, he will immediately broadcast the block to the Bitcoin network. After a few seconds, all miners in the network will receive the block. When they verify it successfully, they will immediately stop their efforts to generate the current block, add the block found by the miner to the blockchain, and immediately start the process of generating the next block. In this way, a block is added to the complete blockchain. Consistency and security of blockchain The above describes the data structure and construction process of the blockchain, but there are still two most critical issues that need to be explained: How the entire blockchain maintains its consistency across all nodes in a distributed network. How to ensure that no node maliciously tampers with the information in the blockchain (transaction information in Bitcoin), that is, how to make us believe that the information in the blockchain is true. As for the consistency issue, it has been explained at the end of the blockchain construction process above. All nodes in the network will strive to get the right to create the current block by solving math problems. When a node successfully solves the problem, it will send the answer to the problem and the constructed block to other nodes through the Bitcoin network. As long as other nodes verify the answer, they will immediately stop their efforts to create the current block, add the transmitted block to the local blockchain, and then fill the information in the block header of the next block according to the hash value of the block header of this block, and immediately start the construction of the next block. In this way, the network completes the construction process of a new block in the blockchain. This process seems to be fine, but consider the following situation: at the same time (within 1 second), two or more different nodes may find the answer, and they immediately send the answer and the block to the nodes connected to them. After verification, these nodes will immediately start building the next block based on this block. Since the blocks generated by each node are different (there are multiple solutions to the math problem), the hash value of each block is also different, and the hash values of subsequent blocks will also change. In this way, multiple blockchain forks are formed in the entire network, and different nodes build new blocks on different forks.
How to solve the fork problem? The answer is to wait until the next block or the next block. Multiple nodes have solved the answer to the current block at the same time, but the next block will most likely be solved in sequence. After the fork that solves the next block first is recognized by the entire network, the nodes that were previously on the wrong fork will replace the previous wrong blocks on their own forks, making the entire network unified again. This is why Bitcoin limits the time required to solve each block to about 10 minutes. The more difficult the problem and the longer the time required to solve it, the lower the probability of finding the answer at the same time. In the history of Bitcoin, it is rare for a fork to contain two blocks. Therefore, the latest blocks generated in the blockchain may indeed have consistency issues, but all blocks before 6 blocks are definitely consistent.
The security and trust issues are mainly reflected in two aspects: one is that a node attempts to change the transaction information on a previous block, and the other is that a node attempts to control the generation of a new block. The key to solving these two problems lies in the guarantee of the huge computing power behind the math problem. If a node wants to change the transaction information of a previous block, as long as the transaction information is changed, the hash value of this information will change, which will eventually cause the Merkle tree and value representing all transaction information in the block header to change. The hash value of this block header will also change, and the previous Nonce value is no longer the solution of this changed block header. The math problem of this block needs to be recalculated. What's more serious is that the parent hash value referenced by the next block of this block has also changed, so the next block also needs to be recalculated, and so on. All subsequent blocks need to be recalculated and generated. That is to say, only after recalculating all subsequent blocks of the changed block and catching up with the progress of the legitimate blockchain in the network, and submitting this long blockchain fork to other nodes in the network, can it be recognized. Regenerating only the maliciously tampered block and submitting it will not be recognized by the honest nodes on the network. In the context of the current huge computing power of the entire network, it is difficult for a malicious node to recalculate multiple blocks and catch up with the entire network. It is generally believed that all blocks before the 6th block cannot be changed. So what if you try to control the generation of new blocks? That is to say, each new block is first recognized by the malicious node to obtain the solution to the math problem. In this way, since the transactions contained in the block are freely determined by the node, the malicious node can never allow a transaction to be added to the blockchain and recognized in this way. In theory, this method is possible. If the computing power of the malicious node is higher than the sum of the computing power of all other nodes in the network, that is, the malicious node occupies 51% of the computing power of the entire network, he can control the generation of new blocks. This attack is called a 51% attack. Of course, in reality, it is very difficult for a node to have a computing power that exceeds the sum of all other nodes. Due to space limitations, there are many security issues such as solutions to DoS attacks that are not discussed here one by one. 4. Summary The foundation of the modern Internet is TCP/IP technology. Based on this technology, all nodes on the network can communicate with any other node fairly and freely. However, this technology only solves the decentralized communication problem, but not the decentralized credit problem. The emergence of blockchain technology gives us hope to solve this problem, and its large-scale application in Bitcoin also shows its technical feasibility. This article introduces the relevant technologies of blockchain based on Bitcoin, but the application of blockchain technology is not limited to the field of digital currency. Its attempts in various industries have already begun. Let us follow the latest technology and make our own contribution to its final maturity. The author of this article: Luo Yuxiang, has worked in the Web and big data fields, knows a little about data mining, has implemented recommendation systems, likes to explore new technical fields, and pays attention to the combination of theory and practice. He currently works in the Dianrong Beijing team . |
<<: Bryce Masters seeks investors for his blockchain startup
>>: The Bitcoin industry is in a difficult situation of financing difficulties
On July 26, electric car maker Tesla delivered a ...
Source: People's Daily Online - Blockchain Ch...
A person's fortune cannot remain in a stable ...
The so-called physiognomy is an academic discipli...
In fact, a woman's destiny can be directly de...
Bad feet Flat feet People with flat and thin feet...
Bitcoin didn’t have the best of times in the seco...
There are many lines on our palms that represent ...
Last week, there were rumors that some funds were...
One thing that needs to be made clear here is tha...
People with straight noses are particularly stron...
The financial industry is currently undergoing a ...
Many people have signs of moles on their faces, a...
1. Thick palms Men with such palm lines are all f...
Baozou Comment : Proof of concept is very common ...