区块链相关的计算题有哪些,区块链相关算法
请查看相关英文文档
⑴ Tutorials for getting started with blockchain
However, there are very few simple and easy-to-understand introductory articles. What exactly blockchain is and what makes it special is rarely explained.
Next, I will try to write a best-understood blockchain tutorial. After all, it is not difficult. The core concept is very simple and can be explained clearly in a few sentences. I hope that after reading this article, you will not only understand the blockchain, but also understand what mining is, why mining is getting more and more difficult, and other issues.
It should be noted that I am not an expert in this area. Although I have been paying attention to it for a long time, my detailed understanding of blockchain started at the beginning of this year. You are welcome to correct any errors or inaccuracies in the article.
1. The essence of blockchain
What is blockchain? In a word, it is a special distributed database.
First of all, the main function of blockchain is to store information. Any information that needs to be saved can be written to the blockchain and read from it, so it is a database.
Secondly, anyone can set up a server, join the blockchain network, and become a node. In the world of blockchain, there is no central node. Every node is equal and stores the entire database. You can write/read data to any node, because all nodes will eventually be synchronized to ensure that the blockchain is consistent.
2. The biggest features of blockchain
Distributed databases are not a new invention, and there have been such products on the market for a long time. However, blockchain has a revolutionary feature.
Blockchain has no administrator, it is completely centerless. Other databases have administrators, but blockchain does not. If one wanted to add auditing to the blockchain, it would not be possible because it is designed to prevent the emergence of a central authority.
It is precisely because it is unmanageable that blockchain can be uncontrollable. Otherwise, once big companies and large groups control the management, they will control the entire platform, and other users will have to take orders from them.
However, without an administrator, everyone can write data into it. How can we ensure that the data is trustworthy? What if it is modified by a bad person? Please read on, this is the wonderful thing about blockchain place.
3. Block
Blockchain is composed of blocks. Blocks are much like database records. Every time data is written, a block is created.
Each block contains two parts.
Head: records the characteristic values of the current block
Body: actual data
The block header contains multiple characteristic values of the current block.
Generation time
Hash of the actual data (i.e. block body)
Hash of the previous block
...
Here, you need to understand what a hash is , which is necessary to understand blockchain.
The so-called hashing means that the computer can calculate a characteristic value of the same length for any content. The hash length of the blockchain is 256 bits, which means that regardless of the originalWhatever the initial content is, a 256-bit binary number will be calculated in the end. And it can be guaranteed that as long as the original content is different, the corresponding hash must be different.
For example, the hash of the string 123 is (hexadecimal), which is 256 bits when converted to binary, and only 123 can get this hash. (Theoretically, it is possible for other strings to get this hash, but the probability is extremely low and can be approximated as impossible.)
Therefore, there are two important inferences.
Corollary 1: The hash of each block is different, and the block can be identified by the hash.
Corollary 2: If the content of the block changes, its hash will definitely change.
4. The non-modifiable nature of Hash
Blocks and hashes have a one-to-one correspondence, and the hash of each block is calculated based on the block header (Head). That is to say, the characteristic values of the block header are connected together in order to form a very long string, and then the hash is calculated on this string.
Hash = SHA256 (block header)
The above is the calculation formula of block hash. SHA256 is the hash algorithm of the blockchain. Note that this formula only contains the block header and not the block body. In other words, the hash is uniquely determined by the block header.
As mentioned before, the block header contains a lot of content, including the hash of the current block body. , and the hash of the previous block. This means that if the content of the current block body changes, or the hash of the previous block changes, it will definitely cause the hash of the current block to change.
This point has great significance for blockchain. If someone modifies a block, the hash of the block changes. In order for subsequent blocks to still be connected to it (because the next block contains the hash of the previous block), the person must modify all subsequent blocks in sequence, otherwise the modified block will be removed from the blockchain . Due to the reasons mentioned later, hash calculation is very time-consuming, and it is almost impossible to modify multiple blocks in a short period of time, unless someone controls more than 51% of the computing power of the entire network.
It is through this linkage mechanism that the blockchain ensures its own reliability. Once the data is written, it cannot be tampered with. This is just like history, what happened happened, and it can’t be changed from now on.
Each block is connected to the previous block, which is where the name blockchain comes from.
5. Mining
Since synchronization between nodes must be ensured, the adding speed of new blocks cannot be too fast. Just imagine, you have just synchronized a block and are preparing to generate the next block based on it, but at this time, another node generates a new block, and you have to give up half of the calculations and synchronize again. Because each block can only be followed by one block, you can only generate the next block after the latest block. So, you have no choice but to sync as soon as you hear the signal.
So, the inventor of the blockchain, Satoshi Nakamoto (this is a pseudonym, and his true identity is still unknown) deliberately made it difficult to add new blocks.His design is that on average, the entire network can generate a new block every 10 minutes, which is only six per hour.
This output speed is not achieved through commands, but by deliberately setting up massive calculations. In other words, only through an extremely large amount of calculations can the effective hash of the current block be obtained and the new block added to the blockchain. Because the amount of calculation is too large, it cannot be done quickly.
This process is called mining, because the difficulty of calculating a valid hash is like finding a grain of sand that meets the conditions among the sand in the world. The machine that calculates hashes is called a mining machine, and the person who operates the mining machine is called a miner.
6. Difficulty coefficient
After reading this, you may have a question. People say that mining is difficult, but isn’t mining just about using a computer to calculate a hash? This is the strength of computers. How could it be? It becomes very difficult, why can’t it be calculated?
It turns out that not just any hash can be used, only hashes that meet the conditions will be accepted by the blockchain. This condition is particularly harsh, causing most hashes to fail to meet the requirements and must be recalculated.
It turns out that the block header contains a difficulty coefficient (difficulty), which determines the difficulty of calculating the hash. For example, the difficulty coefficient of the 100,000th block is 14484.16236122.
The blockchain protocol stipulates that the target value (target) can be obtained by dividing the difficulty coefficient by a constant. Obviously, the greater the difficulty coefficient, the smaller the target value.
The validity of the hash is closely related to the target value. Only hashes smaller than the target value are valid, otherwise the hash is invalid and must be recalculated. Since the target value is very small, the chance that the hash is smaller than this value is extremely slim, and it may be calculated 1 billion times before it is considered a hit. This is the fundamental reason why mining is so slow.
As mentioned earlier, the hash of the current block is uniquely determined by the block header. If the hash of the same block needs to be calculated repeatedly, it means that the block header must keep changing, otherwise it is impossible to calculate different hashes. All feature values in the block header are fixed. In order to make the block header change, Satoshi Nakamoto deliberately added a random item called Nonce.
Nonce is a random value. The role of the miner is actually to guess the value of Nonce so that the hash of the block header can be smaller than the target value so that it can be written to the blockchain. Nonce is very difficult to guess. At present, we can only use trial and error one by one through exhaustive methods. According to the protocol, Nonce is a 32-bit binary value, which can reach a maximum of 2.147 billion. The Nonce value of the 100,000th block is 274148111. It can be understood that the miner started from 0 and calculated 274 million times before obtaining a valid Nonce value so that the calculated hash can meet the conditions.
If you are lucky, you may find Nonce in a while. If you are unlucky, you may have calculated 2.147 billion times without finding the Nonce, which is the current area.It is impossible for the block to calculate a hash that satisfies the condition. At this time, the protocol allows miners to change the block body and start a new calculation.
7. Dynamic adjustment of difficulty coefficient
As mentioned in the previous section, mining is random, and there is no guarantee that a block will be produced in exactly ten minutes. Sometimes it can be calculated in one minute, and sometimes it may take several hours. No result. Overall, with the improvement of hardware equipment and the increase in the number of mining machines, the computing speed will definitely become faster and faster.
In order to keep the output rate constant at ten minutes, Satoshi Nakamoto also designed a dynamic adjustment mechanism for the difficulty coefficient. He stipulated that the difficulty factor should be adjusted every two weeks (2016 blocks). If the average block generation speed in these two weeks is 9 minutes, it means that it is 10% faster than the legal speed, so the next difficulty factor will be increased by 10%; if the average block generation speed is 11 minutes, it means It is 10% slower than the legal speed, so the difficulty factor of the next step must be lowered by 10%.
The difficulty coefficient is adjusted higher and higher (the target value is getting smaller and smaller), which makes mining more and more difficult.
8. Forks of the blockchain
Even if the blockchain is reliable, there is still an unresolved problem: if two people write data to the blockchain at the same time, that is to say, two people write data to the blockchain at the same time. Blocks join because they are connected to the previous block, forming a fork. Which block should be adopted at this time?
The current rule is that new nodes always adopt the longest blockchain. If there is a fork in the blockchain, it will look at which branch is behind the fork to reach 6 new blocks first (called six confirmations). Based on a block calculation of 10 minutes, it can be confirmed in one hour.
Since the generation speed of new blocks is determined by computing power, this rule means that the branch with the most computing power is the authentic blockchain.
9. Summary
Blockchain, as an unmanaged distributed database, has been running for 8 years since 2009 without major problems. This proves it works.
However, in order to ensure the reliability of data, blockchain also has its own price. The first is efficiency. You have to wait at least ten minutes to write data to the blockchain. All nodes synchronize the data, which requires more time. The second is energy consumption. The generation of blocks requires miners to perform countless meaningless calculations. This is Very energy consuming.
Therefore, the applicable scenarios of blockchain are actually very limited.
There is no management authority that all members trust
The written data does not require real-time use
The benefits of mining can make up for its own costs
If the above conditions cannot be met, then the traditional database is Better solution.
Currently, the largest application scenario (and possibly the only application scenario) of blockchain is the cryptocurrency represented by Bitcoin.
⑵ Blockchain is not a multiple-choice database code
Blockchain is not an application or a scam. According to querying relevant public information: Blockchain is to superimpose encrypted data (blocks) in chronological order (chain). In a sense, blockchain technology is a new information transmission technology in the Internet era.
⑶ What is the hash algorithm in blockchain technology
1.1. Introduction
Practitioners in the computer industry should be very familiar with the word hash. Haha Hashes can map data from one dimension to another, usually using hash functions. Usually, the industry uses y = hash(x) to represent it. This hash function implements operations on x to calculate a hash value y.
Characteristics of hash functions in blockchain:
Function parameters are string type;
Fixed size output;
Efficient calculation;
collision-free means that the probability of conflict is small: Verification of transactions only requires verifying the information entropy of the transaction, without comparing the original information. There is no need to transmit the original data of the transaction between nodes, only the hash of the transaction. Common algorithms include the SHA series and MD5 algorithms
1.2. Usage of hash
Hash is widely used in blockchain, one of which is called Hash Pointer
Ha The hash pointer means that the value of the variable is calculated based on the actual data and points to the location of the actual data, that is, it can represent both the actual data content and the storage location of the actual data. The picture below is a schematic diagram of Hash Pointer
⑷ How can a novice understand the hash calculation in the blockchain in seconds
How can a novice understand the zone in seconds Hash calculation in blockchain
When I was learning about blockchain, I found that there was a word that appeared repeatedly like a ghost, "Hash", written in English as "HASH".
That classmate who said he had diarrhea, get out of here! !
This "hash" is said to be a function derived from cryptography. Try searching and you will find a bunch of papers, either horizontal or vertical, tables or pictures, and another Hei doesn't understand xyzabc. Brother, I just want to understand the basic knowledge of blockchain. Why is it so difficult for me? ! My longest password is 123456, and the more complicated one is 654321. When it is the most complicated, add an a at the end. The complicated password you wrote to me obviously feels like my brain is being drained, and my only brain cells are dying in batches! In order to let novice students like me understand this, I reluctantly tried to explain hash calculation in a fool's language, not seeking the most accurate but the simplest and easiest to understand. Let’s get started:
# 1. What is a hash algorithm
## 1. Definition: A hash algorithm converts a string of any length into a string of fixed length.
It can be seen from here that it can be understood as inputting a string of numbers to the "hash operation", and it will output a string of numbers.
If we define the "increment by one algorithm" ourselves, then if we input 1, it will output 2; if we input 100, it will output 101.
If we define the "uppercase algorithm" ourselves, then input "abc" and output "ABC".
Haha, don’t hit me yet! This is really just the concept of a function.
## 2. Features:
What are the characteristics of this hash algorithm compared with my "increment by one algorithm" and "uppercase algorithm"?
1) **Certainty, fast calculation**: The result is the same no matter how you calculate it, and the calculation efficiency is high.
2) **Irreversible**: It means knowing that the output cannot deduce the value of the input.
3) **Unpredictable results**: Just change the input a little, and the results will be completely irregular.
In short, this hash operation is a black box and a good helper for encryption! When you say "11111", it encrypts it into "" for you. When you say "11112", it encrypts it into "" for you. Anyway, the input and output are in the sky and under the ground. Even if the input is related, the two outputs are not related.
# 2. The use of hash operations in the blockchain
## 1. Data encryption
**Transaction data is processed through hashing Hash operation is performed to encrypt, and the corresponding hash value is written into the block header**. As shown in the figure below, a block header contains the hash value of the previous block and the hash value of the next block.
1), **Identify whether the block data has been tampered with**: The hash value of the blockchain can uniquely and accurately identify a block. Any node in the blockchain can pass a simple hash The hash value of this block can be obtained by hash calculation. The calculated hash value has not changed, which means that the information in the blockchain has not been tampered with.
2), **Connect each block into a blockchain**: Each block contains the hash value of the previous block and the value of the next block, which is equivalent to The hash value of the previous block is linked to the end of the previous block, and the hash value of the next block is linked to the head of the next blockchain, thus forming a blockchain with a chain structure.
## 2. Encrypted transaction address and hash
In the block header in the picture above, there is a hash value of the Merkle root. What is it used for?
First, understand what Merkle root is? It is the root of a binary tree structure. What is a binary tree? What is a root? Just look at the picture below to find out. One can be divided into two, two can be divided into four, and four can be divided into eight. It is called a binary tree. The root is the topmost node and is called the root.
Where does this root data come from? After the hash value of each transaction in a block is obtained, the hash values are then hashed, and then hashed, and then hashed again, until the top value is reached.
What’s going on after hashing like this for a long time? What does it do?
1), **Quickly locate each transaction**: Since transactions are stored linearly, locating a transaction requires traversal, which is inefficient and time-consuming. Such a binary tree can quickly Locate the deal you are looking for.
To give an inappropriate example: How to find an arbitrary integer between 0-100? (Assuming the answer is 88) A better way is to ask: 1. Is it larger or smaller than 50? 2. Is it larger or smaller than 75? 3. Is it larger or smaller than 88? You can quickly locate the answer with just a few questions.
2), **Verify whether the transaction data has been tampered with**: From the transaction to the hash value of each binary tree, any change in any number will cause the Merkle root value to change. At the same time, if an error occurs, you can quickly locate the error.
## 3. Mining
There is a parameter in our block header called **random number Nonce. The process of finding this random number is called "mining" **! Any machine on the network only needs to find a suitable number to fill in the Nonce position of its own block, so that the hash value of the data in the 6 fields (80 bytes) of the block header is more than 18 Starting with 0, whoever found "the gold"! Since there is no way for us to write a number that satisfies 18 zeros in advance and then infer Nounce, the only way is to try one by one starting from 0 to see if the result meets the requirements. If not, try the next one until it is found.
What are you looking for this number for? What's the point of doing this?
1), **Fairly find the computer with the strongest computing power**: This is a bit like I have a sand here, and let me tell you that it is the same as a grain of sand on that beach, you Find the same ones. The feasible way is to pick up each pill and compare them! Then the person with the fastest speed is most likely to reach the sand first. This is what is called a "certificate of work""Ming pow", if you find this sand first, I think you compare the most and do the most work.
2), **Dynamic adjustment of difficulty**: In order to ensure that Bitcoin is issued in 10 minutes For a block, the difficulty of finding this nonce number will be calculated every 2016 blocks (2 weeks). If the average time of these 2016 blocks is less than 10 minutes, the difficulty will be increased. If it is more than ten minutes, the difficulty will be decreased. . In this way, no matter how the mining power of the entire network changes, the random number nonce can be calculated within 10 minutes.
# 3. What are the hash operations?
Having said so many hash operations, it seems that hash operations are just one kind of thing. In fact, it is not! As hash operations in cryptography, many schools have been derived from the continuous development. I still feel that after watching "Man Tou Bao" The internal mechanism is too complicated, so I will list it as follows for the time being, so that novices can have an impression and know what is going on.
It can also be seen from the table below that hash operations are also constantly developing. There are various algorithms, and various applications are also flexibly applying single or multiple algorithms. In the Bitcoin system, hash operations basically use the SHA256 algorithm, while Litecoin uses the SCRYPT algorithm. Quark and DASH use many algorithms in series layer by layer, but Heavycoin (HAV) connects several algorithms in parallel and mixes parts of each for use. The POW stage of Ethereum uses the ETHASH algorithm , ZCASH uses EQUIHASH.
It should be noted that various algorithms for hash operations are constantly being upgraded and improved, and the algorithms used by various currencies are not static and are also constantly optimized. .
**Summary**: Hash operations are widely used in various blockchain projects. Taking Bitcoin as an example, we can see that in**data encryption, transactions Data positioning, mining, etc. all play an extremely important role**. As a direction of cryptography, hashing operations continue to develop and extend. As ordinary novices, we want to understand some aspects of the blockchain. It is enough to understand the basic concepts at this level.
⑸ How to calculate the results of Zhilian Blockchain Financial Application Practice Platform
1. Proof of Work (PoW)
Bitcoin (Bitcoin) proposed by Satoshi Nakamoto in 2009 is the earliest application of blockchain technology. It uses PoW as the consensus algorithm. Its core idea is to obtain accounting rights and Bitcoin through the competition of hash power between nodes. Reward. In PoW, different nodes compete to calculate the solution to a mathematical problem based on specific information. This mathematical problem is difficult to solve, but it is easy to verify the results. The node that solves the mathematical problem first can create the next block and obtain A certain number of coins are rewarded. Satoshi Nakamoto is comparingBitcoin uses the HashCash[4] mechanism to design this mathematical problem. This section will take the PoW algorithm used by Bitcoin as an example. The consensus steps of PoW are as follows:
The node collects the transactions to be confirmed on the entire network after the previous block was generated, and records the eligible transactions into the transaction memory pool. , then update and calculate the value of the Merkle root of the transaction in the memory pool, and write it into the block header;
In the block header, fill in the block version number and previous block as shown in Table 1.1 The hash value, timestamp, current target hash value and random number and other information;
Table 1.1 Block header information
The random number nonce takes a value between 0 and 232, and the block header Hash calculation is performed on the local information. When the hash value is less than or equal to the target value, the block is packaged and broadcast, and accounting is completed after verification by other nodes;
If a hash that meets the requirements cannot be calculated within a certain period of time value, repeat step 2. If other nodes complete the calculation during the calculation, start again from step 1.
The average time it takes for Bitcoin to generate a block is 10 minutes. If you want to maintain this speed, you need to adjust the target value (difficulty) based on the current computing power of the entire network [5]. Difficulty is a description of the difficulty of calculating a block that meets the requirements. When calculating blocks of the same height, the difficulty of all nodes is the same, which also ensures the fairness of mining. The relationship between difficulty and target value is:
Difficulty value = maximum target value/current target value (1.1)
The maximum target value and the current target value are both 256 bits in length, and the maximum target value is a difficulty of 1 The target value at that time is 2224. Assume that the current difficulty is, the computing power is, the current target value is, and the average calculation time to find a new block is, then
According to the design of Bitcoin, the system will adjust once every 2016 blocks are generated (about 2 weeks) Current target value. The node calculates the adjusted difficulty value according to formula (1.4) based on the actual production time of the first 2016 blocks. If the actual production time is less than 2 weeks, increase the difficulty value; if the actual time production is greater than 2 weeks, decrease the difficulty value. value. According to the longest chain principle, without the need for nodes to synchronize difficulty information, all nodes will get the same difficulty value after a certain period of time.
In a blockchain using PoW, due to network delays and other reasons, when two blocks of the same height are generated close to each other, a fork may occur. That is, different miners have calculated blocks that meet the requirements of a certain height and have been confirmed by nodes close to them. The nodes in the entire network will continue to mine based on the block received first based on the time when the block was received. . In this case, whichever block's subsequent blocks appear first will become longer, and this block will be included in the main chain. Nodes mining on the non-main chain will switch to the main chain to continue mining. .
The PoW consensus algorithm uses computing power as the basis for competition for accounting rights and workload as a guarantee of security. All miners follow the longest chain principle. Newly generated blockContaining the hash value of the previous block, all existing blocks form a chain. The length of the chain is proportional to the workload. All nodes trust the longest blockchain. If an organization acquires enough computing power, it can launch an attack on the Bitcoin network. When an attacker has enough computing power, he can calculate the latest block first and thus master the longest chain. At this time, most of the blocks on the Bitcoin main chain are generated by it. He can deliberately refuse to confirm certain transactions and carry out double-spend attacks. This will affect the credibility of the Bitcoin network, but this behavior will also causing losses to the attacker. By solving the one-dimensional random walk problem, the relationship between the probability of successful attack by malicious nodes and the computing power can be obtained:
Figure 1.1 The attacker’s computing power and the probability of successful attack
2. Proof of Stake (PoS)
As more and more people participate in Bitcoin mining, many problems of PoW gradually emerge. For example, as the competition for computing power rapidly intensifies, the energy consumed to obtain tokens increases significantly, and the accounting rights gradually increase. "Mining pools" that gather a large amount of computing power are concentrated [6-9]. To this end, researchers are trying to use new mechanisms to replace proof of work. The concept of PoS was mentioned in the earliest Bitcoin project, but was not used due to reasons such as robustness. The earliest application of PoS is PPCoin. PoS proposes the concept of currency age. Coin age is the accumulation of the product of the held tokens and the holding time. The calculation is as shown in formula (1.4). Utilizing currency age competition to replace computing power competition enables blockchain proof to no longer rely solely on workload, effectively solving the resource waste problem of PoW.
The holding time is the time since a certain currency was last traded on the network. The longer the currency held by each node, the more rights it has in the network. At the same time, the holder of the currency will also Obtain a certain amount of income based on the age of the currency. In the design of Peercoin, it is not completely separated from the proof of work. Obtaining the accounting rights of the PoS mechanism also requires simple hash calculation:
where proofhash is composed of weight factor, unconsumed output value and current time The fuzzy and hash values obtained also limit the computing power of each node. It can be seen that the currency age is inversely proportional to the difficulty of calculation. In PoS, the security of the blockchain increases as the value of the blockchain increases. Attacks on the blockchain require attackers to accumulate a large amount of currency age, which means they need to hold a large amount of digital currency for a long enough time. This also greatly increases the difficulty of the attack. Compared with PoW, blockchain systems using PoS may face Long Range Attack and Nothing at Stake.
In addition to Peercoin, many coins also use PoS, but they have different methods for allocating accounting rights. For example, Nxt and BlackCion combine the rights owned by nodes and use random algorithms to allocate accounting rights. Ethereum is also gradually adopting PoS instead of PoW.
3.Delegated Proof of Stake (DPoS)
At the beginning of the design of Bitcoin, it was hoped that all mining participants would use CPUs for calculations, and the computing power would match the nodes. Each node would have enough opportunities to participate in the decision-making of the blockchain. . With the development of technology, a large number of mining machines using GPU, FPGA, ASIC and other technologies have emerged. The computing power is concentrated in the hands of participants with a large number of mining machines, while the opportunities for ordinary miners to participate are greatly reduced.
In a blockchain using DPoS, each node can vote to select representatives based on the share rights it owns. The n nodes in the entire network that participate in the election and receive the most votes gain accounting rights in a predetermined order. Produce blocks in sequence and receive certain rewards for doing so. Representative nodes that succeed in the election need to pay a certain amount of deposit and must ensure online time. If the node that should generate blocks at a certain moment fails to perform its duties, he will be disqualified as a representative, and the system will continue to vote to elect a new representative. to replace him.
All nodes in DPoS can independently choose the objects to vote. The elected representatives are accounted for in order. Compared with PoW and PoS, computing resources are saved. Moreover, there are only a limited number of consensus nodes, and the efficiency is also improved. promote. Moreover, each participating node has the right to vote. When there are enough nodes in the network, the security and decentralization of DPoS are also guaranteed.
4. Practical Byzantine Fault Tolerance Algorithm (PBFT)
In the PBFT algorithm, all nodes run under the same configuration and have one master node, and other nodes serve as backup nodes. The primary node is responsible for sorting client requests and sending them to the backup node in order. There is the concept of View, and in each view, all nodes process messages normally. But when the backup node detects an exception on the primary node, it will trigger the View Change mechanism to replace the next numbered node as the primary node and enter a new view. The main process in PBFT from the client sending a request to receiving the reply is shown in Figure 4.1 [10] [11]. Information is exchanged between servers three times. The whole process includes the following five stages:
Figure 4.1 PBFT execution process
At present, Byzantine fault-tolerant algorithms represented by PBFT are used by many blockchain projects. In the alliance chain, the PBFT algorithm was first adopted by the Hyper ledger Fabric project. Hyperledger Fabric uses the PBFT consensus algorithm in version 0.6. The authorization and endorsement functions are integrated into the consensus nodes. All nodes are consensus nodes. This design results in an overly heavy burden on the nodes, which has a great impact on TPS and scalability. Impact. Versions after 1.0 have separated the functions of nodes. The nodes are divided into three endorsement nodes (Endorser), ordering nodes (Orderer) and block nodes (Committer). The functions of nodes are separated.The efficiency of consensus is improved to a certain extent.
The Tendermint[12] algorithm used by the Cosmos project combines the PBFT and PoS algorithms, and selects some consensus nodes for BFT consensus through token mortgage. It weakens the asynchronous assumption and incorporates locks on the basis of PBFT. The concept of consensus nodes in a partially synchronized network can reach consensus through two-phase communication. The system can tolerate 1/3 of failed nodes without causing forks. On the basis of Tendermint, Hotstuff [13] integrates the block chain structure of the blockchain with each stage of BFT. In each stage, the signature confirmation of the previous block and the construction of the new block are carried out simultaneously, making the algorithm realize Even simpler, Hotstuff also uses threshold signatures [14] to reduce the message complexity of the algorithm.
5. Paxos and Raft
The consensus algorithm is a set of mechanisms designed to ensure the accuracy and consistency of stored information. In traditional distributed systems, the most commonly used consensus algorithm is the Paxos-based algorithm. After the Byzantine Generals Problem [3] was raised, Lamport proposed the Paxos algorithm in 1990 to solve the system consistency problem under specific conditions. Lamport reorganized and published the Paxos paper [15] in 1998 and conducted a research on Paxos in 2001. was re-briefed [16]. Subsequently, Paxos dominated the field of consensus algorithms and was adopted by many companies, such as Tencent's Phxpaxos, Alibaba's X-Paxos, Amazon's AWS's DynamoDB, and Google's MegaStore [17]. This type of algorithm can quickly complete data synchronization in a distributed system when the number of nodes is limited and relatively trustworthy, while being able to tolerate crash faults. That is to say, in traditional distributed systems, there is no need to consider behaviors such as malicious tampering of data by participating nodes, and only need to be able to tolerate downtime errors on some nodes. However, the Paxos algorithm is too theoretical and is very difficult to understand and implement in engineering. Ongaro et al. published a paper in 2013 proposing the Raft algorithm [18]. Raft has the same effect as Paxos and is more convenient for engineering implementation.
The leader occupies an absolutely dominant position in Raft, and the absolute security of server nodes must be ensured. Once the leader is maliciously controlled, huge losses will be caused. And the transaction volume is limited by the maximum throughput of the node. Currently, many alliance chains use the Raft algorithm to improve consensus efficiency without considering Byzantine fault tolerance.
6. Consensus algorithm combined with VRF
In the existing alliance chain consensus algorithm, if the number of nodes participating in the consensus increases, the communication between nodes will also increase, and the performance of the system will also be affected. If you select some nodes from many candidate nodes to form a consensus group for consensus and reduce the number of consensus nodes, you canto improve system performance. But this will reduce security, and the higher the proportion of malicious nodes among candidate nodes, the higher the probability that the selected consensus group will not function properly. In order to select a consensus group that can operate normally from the candidate nodes and ensure the high availability of the system, on the one hand, it is necessary to design an appropriate random election algorithm to ensure the randomness of the selection and prevent malicious nodes from attacking the system. On the other hand, it is necessary to increase the proportion of honest nodes among candidate nodes and increase the probability of honest nodes being selected into the consensus group.
Currently, public chains are often based on PoS algorithms. Mortgage tokens increase the entry threshold for consensus nodes, increase the cost of malicious nodes through economic games, and then use random election algorithms among some nodes that pass the screening. Randomly select some nodes from qualified candidate nodes for consensus.
Dodis et al. proposed Verifiable Random Functions (VRF) in 1999 [19]. Verifiable random function is an application of zero-knowledge proof, that is, in the public-private key system, the person holding the private key can use the private key and a piece of known information to generate a random number according to specific rules without revealing the private key. Under the premise, the person holding the private key can prove to others the correctness of the random number generation. VRF can be constructed using RSA or elliptic curves. In 2002, Dodis et al. proposed a verifiable random function construction method based on the Diffie-Hellman difficulty problem [20]. Currently, verifiable random functions are widely used in the field of key transmission and blockchain. It has applications in many fields [21]. The specific process of the verifiable random function is as follows:
In the public chain, VRF has been applied in some projects. VRF is mostly combined with the PoS algorithm. All nodes that want to participate in the consensus pledge certain tokens to become candidate nodes. , and then randomly select some consensus nodes from many candidate nodes through VRF. New nodes in the Zilliqa network must first perform PoW. Existing nodes in the network verify the new node's PoW and authorize it to join the network. The consensus algorithm VBFT designed by the blockchain project Ontology combines VRF, PoS and BFT algorithms. VRF randomly selects consensus nodes among many candidate nodes and determines the order of consensus nodes, which can reduce the impact of malicious forks on the blockchain system. The impact ensures the fairness and randomness of the algorithm. Algorand[22] proposed by Turing Award winner Micali et al. combines PoS and VRF. Nodes can become candidate nodes by pledging tokens, and then select some nodes to form a consensus committee through the non-interactive VRF algorithm, and then this will Some nodes implement a consensus algorithm similar to PBFT and are responsible for rapid verification of transactions. Algorand can ensure the normal operation of the system when the nodes are honest nodes. Ouroboros [23] proposed by Kiayias et al. was introduced in the second version Praos [24]VRF replaces pseudo-random numbers to select the master node in the sharding. Taking the VRF algorithm used by Algorand and other algorithms as an example, the main process is as follows:
In the VRF designed and used in public chains, the probability of a node being selected as an accounting node is often positively related to the tokens it holds. The consensus node range of the public chain cannot be determined in advance. All nodes that meet the token holding conditions may become consensus nodes. The system needs to select some nodes among the nodes with random number and participation for consensus. Compared with the public chain, the number of nodes participating in the consensus of the alliance chain is limited and the nodes are known. In this case, the nodes of the alliance chain can interact through the known node list, which can effectively prevent possible problems when designing the VRF of the public chain. to the witch attack problem.
7. Formula algorithm combined with sharding technology
Sharding technology is a technology in databases that cuts the data in the database into multiple parts and then stores them in multiple servers. Improve the search performance of the server through distributed storage of data. In blockchain, sharding technology is a mechanism that allocates transactions to multiple consensus groups composed of node subsets for confirmation, and finally aggregates all results for confirmation. Sharding technology already has some applications in blockchain, and many blockchains have designed their own sharding solutions.
Luu et al. proposed the Elastico protocol in 2017, which was the first to apply sharding technology to the blockchain [25]. Elastico first competes to become the accounting node in the network through the PoW algorithm. These nodes are then assigned to different shard committees according to predetermined rules. Each sharding committee internally executes traditional Byzantine fault-tolerant consensus algorithms such as PBFT, and packages and generates transaction sets. After more than one node signs the transaction set, the transaction set is submitted to the consensus committee. After verifying the signatures, the consensus committee finally packages all the transaction sets into blocks and records them on the blockchain.
Elastico verifies the usability of sharding technology in blockchain. Within a certain scale, sharding technology can scale throughput nearly linearly. However, Elastico uses PoW to elect consensus nodes, which also causes the random number generation process and PoW competition for consensus nodes to take too long, resulting in high transaction delays. Moreover, the PBFT algorithm used within each shard has high communication complexity. Latency is also high when the number of nodes in a single shard is high.
Based on Elastico, Kokoris-Kogias and others proposed OmniLedger [26], which used an encrypted lottery protocol to replace PoW to select validator groups, and then classified the validators into different shards through the RandHound protocol [27]. OmniLedger. OmniLedger still uses the PBFT-based consensus algorithm as the consensus algorithm in sharding [28], and introduces the Atomix protocol to handle cross-shard transactions. The communication between nodes during the consensus process is complex.The degree is higher. When the number of nodes in a shard increases and cross-shard transactions increase, system TPS will drop significantly.
Wang et al. proposed Monoxide in 2019[29]. The sharding technology was introduced into the PoW blockchain system and the Chu ko-nu mining algorithm was proposed, which solved the problem of dispersion of computing power caused by sharding, allowing each miner to work on different locations at the same time. Sharding through sharding improves the TPS of PoW without reducing security.
⑹ What is the process of block formation in blockchain technology?
Jinwowo Network analyzes the block formation process in blockchain as follows:
1 -Record: Record the transaction information in the local memory into the block body
2-Generate: Generate the Merkle tree of all transaction information in this block in the block body, and save the value of the Merkle tree root in In the block header
3-Fill in the parent hash value: Use the SHA256 algorithm to generate a hash value from the block header data of the previous block just generated and fill it in the parent hash value of the current block< br />4-Time Saving: Save the current time in the timestamp field
5-Difficulty Coefficient: The difficulty value field will be adjusted based on the average generation time of blocks in the previous period to cope with the changing overall situation of the entire network The total amount of calculations. If the total amount of calculations increases, the system will increase the difficulty value of the math questions so that the expected time to complete the next block is still within a certain period of time.
⑺ Six core algorithms of blockchain technology
Six core algorithms of blockchain technology
Blockchain core algorithm 1: Byzantine Agreement
The story of Byzantium goes something like this: The Byzantine Empire has huge wealth, and its 10 neighboring countries have been around for a long time. However, Byzantium’s high walls are towering and impregnable, and no single neighbor can successfully invade. Any invasion by a single neighbor will fail, and it is also possible that it will be invaded by 9 other neighbors. The Byzantine Empire's defensive capabilities were so strong that at least half of its ten neighbors had to attack at the same time to be able to break through. However, if one or several of the neighbors agree to attack together, but betrayal occurs during the actual process, then the invaders may all be annihilated. So each party acted cautiously and did not dare to trust its neighbors easily. This is the Byzantine Generals Problem.
In this distributed network: each general has a message ledger that is synchronized with other generals in real time. The signature of each general in the ledger can be used to verify the identity. If any messages are inconsistent, you can know which generals the messages are inconsistent with. Even if there is inconsistent information, as long as more than half agree to attack, the minority obeys the majority, and a consensus is reached.
Thus, in a distributed system, although there are bad guys, bad guys can do anything (not restricted by the protocol), such as not responding, sending error messages,Different nodes send different decisions, different wrong nodes unite to do bad things, and so on. However, as long as most people are good people, it is entirely possible to achieve consensus in a decentralized manner
Blockchain Core Algorithm 2: Asymmetric Encryption Technology
In the above Byzantine Agreement, if one of the 10 generals Several messages initiated at the same time will inevitably cause chaos in the system, causing each to have its own attack time plan, making it difficult to act in a consistent manner. Anyone can initiate offensive information, but who will send it? In fact, this only requires adding a cost, that is: only one node can spread the information within a period of time. When a node sends a unified attack message, each node must sign and stamp the message from the initiator to confirm their identity.
It seems today that asymmetric encryption technology can completely solve this signature problem. The asymmetric encryption algorithm uses two different keys for encryption and decryption. These two keys are the "public key" and "private key" that we often hear. Public keys and private keys generally appear in pairs. If a message is encrypted with a public key, the private key corresponding to the public key is required to decrypt it; similarly, if a message is encrypted with a private key, the public key corresponding to the private key is required to decrypt it.
Blockchain Core Algorithm Three: Fault Tolerance Issue
We assume that in this network, messages may be lost, damaged, delayed, sent repeatedly, and the order received is inconsistent with the order sent. In addition, the behavior of nodes can be arbitrary: they can join and exit the network at any time, they can discard messages, forge messages, stop working, etc. Various human or non-human failures may also occur. Our algorithm provides excellent fault tolerance for a consensus system composed of consensus nodes. This fault tolerance includes both security and availability, and is applicable to any network environment.
Blockchain core algorithm 4: Paxos algorithm (consensus algorithm)
The problem solved by the Paxos algorithm is how a distributed system can reach agreement on a certain value (resolution). A typical scenario is that in a distributed database system, if the initial state of each node is consistent and each node performs the same sequence of operations, then they can finally obtain a consistent state. In order to ensure that each node executes the same command sequence, a "consistency algorithm" needs to be executed on each instruction to ensure that the instructions seen by each node are consistent. A general consensus algorithm can be applied in many scenarios and is an important issue in distributed computing. There are two models for node communication: shared memory and message passing. The Paxos algorithm is a consensus algorithm based on the message passing model.
Blockchain Core Algorithm Five: Consensus Mechanism
The blockchain consensus algorithm is mainly proof of work and proof of equity. Taking Bitcoin as an example, in fact, from a technical point of view, PoW can be regarded as reused Hashcash. Generating proof of work is a random process in terms of probability. To mine a new confidential currency, when generating a block, all participants must agree, and the miner must obtain all the data in the block.Based on PoW proof of work. At the same time, miners must constantly observe and adjust the difficulty of this work, because the network requirement is to generate a block every 10 minutes on average.
Blockchain Core Algorithm 6: Distributed Storage
Distributed storage is a data storage technology that uses the disk space on each machine through the network and combines these dispersed storage resources into a virtual Storage devices, data are stored dispersedly in every corner of the network. Therefore, distributed storage technology does not store complete data on each computer, but splits the data and stores it in different computers. It's like storing 100 eggs, not in the same basket, but in different places. The total sum is 100.
⑻ Blockchain technology
Background: After the birth of Bitcoin, it was discovered that the technology was very advanced, and blockchain technology was discovered. Bitcoin and blockchain technology were discovered at the same time.
1.1 The purpose of the birth of Bitcoin:
①Currency transactions have records, that is, ledgers;
②The disadvantages of centralized institution accounting - it can be tampered with; Yi Chaofa
Bitcoin solves the first problem: anti-tampering - hash function
1.2 hash function (encryption method)
① Function: convert any A string of length, converted to a fixed-length (sha256) output. The output is also called a hash value.
② Features: It is difficult to find two different x and y such that h(x)=h(y).
③Application: md5 file encryption
1.3 Blockchain
①Definition
Block: Split the general ledger into zones Block storage
Blockchain: On each block, add a block header. It records the hash value of the parent block. By storing the hash value of the parent block in each block, all blocks are connected in order to form a blockchain.
②How does the blockchain prevent transaction records from being tampered with?
After the blockchain is formed, tampering with any transaction will cause the hash value of the transaction block to be different from that of its sub-blocks. , tampering was discovered.
Even if you continue to tamper with the hash value in the sub-block header, the hash value in the sub-block will be different from that in the grandchild block, and the tampering will be discovered.
1.4 The essence of blockchain
①The essence of Bitcoin and blockchain: a big ledger visible to everyone, only recording transactions .
②Core technology: Through cryptographic hash function + data structure, it ensures that the ledger records cannot be tampered with.
③Core skillsCan: Create trust. Fiat currency relies on government credibility, and Bitcoin relies on technology.
1.5 How to trade
① To conduct transactions, you need an account number and password, corresponding to the public key and private key
Private key: a string of 256-bit binary numbers , no application is required to obtain it, and you don’t even need a computer. You can generate the private key by tossing a coin 256 times.
The address is converted from the private key. The address cannot reverse the private key.
The address is the identity, which represents the ID in the Bitcoin world.
After an address is generated, it can only be known by everyone if it enters the blockchain ledger.
②Digital signature technology
Signature function sign (Zhang San’s private key, transfer information: Zhang San transfers 10 yuan to Li Si) = signature of this transfer
< p> Verify Korean verify (Zhang San’s address, transfer information: Zhang San transfers 10 yuan to Li Si, signature of this transfer) = TrueZhang San uses his own signature function sign() The private key signs this transaction.
Anyone can verify whether the signature was issued by Zhang San himself who holds Zhang San's private key by verifying the Korean vertify(). It returns true, otherwise it returns false.
sign() and verify() are cryptographically guaranteed not to be cracked. ·
③Complete the transaction
Zhang San will provide the transfer information and signature to the entire network. Under the premise that the account has a balance, after verifying that the signature is true, it will be recorded in the blockchain ledger. Once recorded, Zhang San's account will be reduced by 10 yuan, and Li Si's account will be increased by 10 yuan.
Supports one-to-one, one-to-many, many-to-one, and many-to-many transactions.
In the Bitcoin world, private keys are everything! ! !
1.6 Centralized Accounting
① Advantages of Centralized Accounting:
a. No matter which center keeps accounts, don’t worry too much
< p> b. Centralized accounting, high efficiency②Disadvantages of centralized accounting:
a Denial of service attack
b Stop service after getting tired
p>c Central institutions are vulnerable to attacks. For example, destroying servers and networks, committing self-intrusion, legal termination, government intervention, etc.
All attempts at confidential currencies with centralized institutions in history have failed.
Bitcoin solves the second problem:How to decentralize
1.7 Decentralized accounting
① Decentralization: Everyone can keep accounts. Everyone can keep a complete ledger.
Anyone can download open source programs, participate in the P2P network, monitor transactions sent around the world, become an accounting node, and participate in accounting.
② Decentralized accounting process
After someone initiates a transaction, it is broadcast to the entire network.
Each accounting node continues to monitor and continue transactions across the entire network. When a new transaction is received and the accuracy is verified, it is put into the transaction pool and continues to be propagated to other nodes.
Due to network propagation, the transactions of different accounting nodes at the same time are not necessarily the same.
Every 10 minutes, one person is selected from all accounting nodes in a certain way, and his transaction pool is used as the next block and broadcast to the entire network.
Other nodes delete the transactions that have been recorded in their own transaction pool based on the transactions in the latest block, continue accounting, and wait for the next selection.
③ Features of decentralized accounting
A block is generated every 10 minutes, but not all transactions within these 10 minutes can be recorded.
The accounting node that obtains the accounting rights will be rewarded with 50 Bitcoins. After every 210,000 blocks (approximately 4 years), the reward is halved. The total amount is about 21 million, and it is expected to be mined in 2040.
Recording the reward of a block is also the only way to issue Bitcoin.
④ How to allocate accounting rights: POW (proof of work) method
Compete for accounting rights by calculating mathematical problems on several accounting points.
Find a random number that makes the following inequality true:
There is no other solution except traversing the random numbers starting from 0 and trying your luck. The process of solving the problem is also called mining.
Whoever solves the problem correctly first will get the accounting rights.
If a certain accounting node finds the solution first, it will announce it to the entire network. After other nodes verify that it is correct, a new round of calculation will start again after the new block. This method is called POW.
⑤ Difficulty adjustment
The generation time of each block is not exactly 10 minutes
As Bitcoin develops, the computing power of the entire network does not increase.
In order to cope with changes in computing power, the difficulty will be increased or decreased every 2016 blocks (about 2 weeks), so that the average time for each block to be generated is 10 minutes.
#欧易OKEx# #BTC[超话]##digitalcurrency#
- 上一篇: 区块链企业股权融资方式,区块链企业股权融资方案
- 下一篇: 区块链算法关系图,区块链算法关系模型