为广大币圈朋友提供币圈基础入门专业知识!
当前位置首页 > 区块链知识> 正文

区块链算法系统,区块链算法有哪些

发布时间:2023-12-18-12:21:00 来源:网络 区块链知识 区块   算法   pbef

区块链算法系统,区块链算法有哪些


请查看相关英文文档

Ⅰ Six Core Algorithms of Blockchain Technology

Six Core Algorithms of Blockchain Technology
Blockchain Core Algorithm 1: Byzantine Agreement
The story of Byzantium probably goes 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, sending different decisions to different nodes, and combining different wrong nodes. Get up and do bad things, etc. 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. IOur 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 sequence of commands, 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 PoW proof of work for all data in the block. 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 dispersedly stored 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 Consensus Algorithm - (2) PoS Consensus (Proof of Stake)

In July 2011, a digital currency enthusiast named Quantum Mechanic published a The currency forum first proposed the PoS consensus algorithm. Subsequently, Sunny King implemented it for the first time in Peercoin (PPC) released in August 2012. PoS is accounted for by the node with the highest equity rather than the highest computing power in the system. Rights, where rights and interests are reflected in the node’s ownership of a specific amount of currency, called coin age or coin days

PoS takes into account PoSThe biggest flaw of W: It was proposed because of the waste of resources. Simply put, who has the final say has the greatest rights.

The PoS consensus mechanism (Proof of Stake) solves problems such as low efficiency, waste of resources, and node consistency through equity accounting.

Each node needs to meet certain conditions (such as mortgaging certain tokens) to become a verification node (increased equity). The system selects some of them as block-producing nodes (miners) through an algorithm, and every so often Re-select, the algorithm will ensure complete randomness and cannot be manipulated. Only block-producing nodes can process data and compete for accounting rights.

Equity is mainly determined by the equity factor, which can be the number of coins held, the age of the currency, or a combination of the two.

Ethereum is likely to switch to PoS for consensus in the future, which is more in line with the high efficiency of Ethereum.

III Hash algorithm in blockchain

Hash algorithm is the most important underlying technology in blockchain. It is a method used to identify transaction data and is unique. A cryptographic hash algorithm is a "fingerprint" of the data.

The cryptographic hash algorithm has 5 major characteristics:
1. It can quickly create hash values ​​for any type of data.
2. Certainty. Hash algorithms always produce the same hash value for the same input data.
3. Pseudo randomness. When the input data is changed, the hash value returned by the hash algorithm changes unpredictably. It is impossible to predict the hash value based on the input data.
4. One-way function. It is not possible to recover the original input data based on the hash value. It is impossible to learn anything about the input data based on the hash value alone.
5. Anti-collision. The chances of different blocks of data producing the same hash value are slim.

IV Blockchain --- Consensus Algorithm

The PoW algorithm is a mechanism to prevent the abuse of distributed service resources and denial of service attacks. It requires nodes to perform complex operations that consume a moderate amount of time and resources, and the operation results can be quickly verified by other nodes, using time and energy as a guarantee to ensure that services and resources are used according to real needs.

The most basic technical principle in the PoW algorithm is the use of hashing algorithms. Assume that the hash value Hash(r) is found. If the original data is r (raw), the operation result is R (Result).

R = Hash(r)

The characteristic of the hash function Hash() is that for any input value r, the result R is obtained, and r cannot be deduced from R. when loseWhen the input original data r changes by 1 bit, the resulting R value changes completely. In the Bitcoin PoW algorithm, the algorithm difficulty d and the random value n are introduced, and the following formula is obtained:

Rd = Hash(r+n)

This formula requires filling in the random In the case of value n, the first d bytes of the calculation result Rd must be 0. Due to the unknown nature of the hash function results, each miner has to do a lot of calculations to get the correct result. After the calculation result is broadcast to the entire network, other nodes only need to perform a hash operation to verify it. The PoW algorithm uses this method to consume resources for calculation, and verification only needs to be done once.

The PoS algorithm requires node verifiers to pledge a certain amount of funds to be eligible for mining and packaging, and the regional chain system uses a random method when selecting packaging nodes. When the node pledges The more funds there are, the greater the probability of being selected to package the block.

In POS mode, each coin generates 1 coin age every day. For example, if you hold 100 coins for a total of 30 days, then your coin age will be 3000 at this time. At this time, if you verify a POS block, your currency age will be cleared to 0, and the corresponding digital currency interest will be obtained from the block.

The process of a node producing blocks through the PoS algorithm is as follows: To become a block producing node, an ordinary node must first pledge its assets. When it is its turn to produce a block, it packages the block and then broadcasts it to the entire network. , other verification nodes will verify the legitimacy of the block.

The DPoS algorithm is similar to the PoS algorithm and also uses shares and equity pledges.

But the difference is that the DPoS algorithm uses a delegated pledge method, which is similar to the method of universal election of representatives to select N super nodes to record and produce blocks.

Voters cast their votes for a certain node. If a certain node is elected as an accounting node, then the accounting node can often use any method to reward its voters after obtaining the block reward.

These N accounting nodes will take turns to produce blocks, and the nodes will supervise each other. If they do evil, the pledge deposit will be deducted.

By trusting a small number of honest nodes, unnecessary steps in the block signing process can be removed, increasing the speed of transactions.

Byzantine problem:

Byzantium was the capital of the ancient Eastern Roman Empire. For defense, an army led by a single general was stationed in each fiefdom. The message could only be delivered by messenger. In war, all generalsA consensus must be reached to decide whether to go to war together.

However, there may be traitors within the army who will influence the generals to reach a consensus. The Byzantine Generals Problem refers to the problem of how the remaining generals can reach a unanimous decision when one of the generals is known to be a traitor.

BFT:

BFT is Byzantine fault tolerance. Byzantine fault tolerance technology is a type of fault tolerance technology in the field of distributed computing. The Byzantine hypothesis is a modeling of the real world, where computers and networks may behave unpredictably due to hardware errors, network congestion or outages, and malicious attacks. Byzantine fault tolerance techniques are designed to handle these abnormal behaviors and meet the specification requirements of the problem to be solved.

Byzantine fault-tolerant system:

The failed node is called a Byzantine node, and the normal node is a non-Byzantine node.

Assuming that the distributed system has n nodes, and assuming that the entire system has no more than m Byzantine nodes (n ≥ 3m + 1), the Byzantine fault-tolerant system needs to meet the following two conditions:

In addition, the Byzantine fault-tolerant system needs to achieve the following two indicators:

PBFT is the practical Byzantine fault-tolerant algorithm, which solves the problem of inefficiency of the original Byzantine fault-tolerant algorithm. The time complexity of the algorithm is O(n^2 ), so that Byzantine fault tolerance problems can be solved in actual system applications

PBFT is a state machine copy replication algorithm. All copies operate in the process of a view (view) rotation. The master The node is determined by the view number and the set of node numbers, that is: main node p = v mod |R|. v: view number, |R| number of nodes, p: primary node number.

The consensus process of the PBFT algorithm is as follows: the client (Client) initiates a message request (request) and broadcasts it to each replica node (Replica), and one of the master nodes (Leader) initiates a proposal message pre -prepare and broadcast. Other nodes obtain the original message and send prepare messages after the verification is completed. Each node receives 2f+1 prepare messages, that is, it is considered ready and sends a commit message. When the node receives 2f+1 commit messages and the client receives f+1 identical reply messages, it means that the request initiated by the client has reached a network-wide consensus.

The specific process is as follows:

Client c sends a request to master node p. o: the specific operation of the request, t: the timestamp appended by the client during the request, c: client identifier. REQUEST: Contains message content m, and message digest d(m). The client signs the request.

When the master node receives the client's request, it needs to conduct the following verifications:

a. Whether the signature of the client's request message is correct.

Illegal requests are discarded. For a correct request, a number n is assigned. The number n is mainly used to sort the client's requests. Then broadcast a <, m> message to other replica nodes. v: view number, d client message summary, m message content. performs master node signature. n is [h, H] to be within a certain range. For specific reasons, please refer to the Garbage Collection chapter.

When replica node i receives the PRE-PREPARE message from the master node, the following verification is required:

a. Whether the signature of the master node's PRE-PREPARE message is correct.

b. Whether the current replica node has received a PRE-PREPARE message under the same v and also numbered n, but with different signatures.

c. Whether the abstracts of d and m are consistent.

d. Whether n is within the interval [h, H].

Illegal requests are discarded. Correct request, replica node i sends a message to other nodes including the master node, v, n, d, m is the same as the content of the above PRE-PREPARE message, i is the current replica node number. Sign the replica node i. Record PRE-PREPARE and PREPARE messages to the log, which are used to restore unfinished request operations during the View Change process.

When the master node and replica node receive the PREPARE message, they need to conduct the following verifications:

a. Whether the signature of the replica node's PREPARE message is correct.

b. Whether the current replica node has received n under the same view v.

c. Whether n is within the interval [h, H].

d. Whether d is the same as d in the currently received PRE-PPREPARE

Illegal request is discarded. If replica node i receives 2f+1 verified PREPARE messages, it sends a message to other nodes including the master node, where v, n, d, i is the same as the content of the above PREPARE message. same. performs the signature of replica node i. Record CThe OMMIT message is sent to the log and is used to restore unfinished request operations during the View Change process. Record PREPARE messages sent by other replica nodes to the log.

When the master node and replica node receive the COMMIT message, they need to conduct the following verifications:

a. Whether the signature of the COMMIT message of the replica node is correct.

b. Whether the current replica node has received n under the same view v.

c. Whether the abstracts of d and m are consistent.

d. Whether n is within the interval [h, H].

Illegal requests are discarded. If replica node i receives 2f+1 verified COMMIT messages, it means that most nodes in the current network have reached a consensus, run the client's request operation o, and return For the client, r: is the result of the request operation. If the client receives f+1 identical REPLY messages, it means that the request initiated by the client has reached the consensus of the entire network. Otherwise, the client needs to determine whether to resend the request to the master node. Record COMMIT messages sent by other replica nodes to the log.

If the master node does evil, it may assign the same sequence number to different requests, or not allocate sequence numbers, or make adjacent sequence numbers discontinuous. The backup node should have the responsibility to actively check the validity of these sequence numbers.

If the master node goes offline or acts maliciously and does not broadcast the client's request, the client sets a timeout mechanism. If the timeout occurs, the request message is broadcast to all replica nodes. The replica node detects that the master node has done something evil or is offline, and initiates the View Change protocol.

View Change protocol:

The replica node broadcasts ​​messages to other nodes. n is the number of the latest stable checkpoint, C is the 2f+1 verified CheckPoint message set, and P is the PRE-PREPARE and PREPARE message set of outstanding requests by the current replica node.

When the master node p = v + 1 mod |R| receives 2f valid VIEW-CHANGE messages, it broadcasts messages to other nodes. V is a valid set of VIEW-CHANGE messages. O is the set of uncompleted PRE-PREPARE messages reinitiated by the master node. Selection rules for PRE-PREPARE message sets:

The replica node receivesVerify the validity of the node's NEW-VIEW message. If it is valid, enter the v+1 state and start the PRE-PREPARE message processing process in O.

In the above algorithm process, in order to ensure that the previous request can be restored during the View Change process, each replica node records some messages to the local log. After executing the request The replica node needs to clear the record messages of the previous request.

The simplest way is to execute the consensus synchronization of the current state again after the Reply message. This is relatively expensive, so it can be executed after executing multiple requests K (for example: 100). A status synchronization. This status synchronization message is the CheckPoint message.

Replica node i sends to other nodes, n is the last view request number retained by the current node, d is a summary of the current status, and the CheckPoint message record to the log. If replica node i receives 2f+1 verified CheckPoint messages, the messages in the previous log are cleared and n is used as the current stable checkpoint.

This is an ideal situation. In fact, when the replica node i sends a CheckPoint message to other nodes, the other nodes have not completed K requests, so they will not respond to i's request immediately. It will also follow its own rhythm, moving forward, but the CheckPoint issued at this time does not form stable.

In order to prevent i from processing requests too quickly, set a high and low water level interval [h, H] mentioned above to solve this problem. The low water level h is equal to the number of the previous stable checkpoint, and the high water level H = h + L, where L is the value we specify, which is equal to an integer multiple of the number of requests processed in the checkpoint cycle K, and can be set to L = 2K. When the request processed by replica node i exceeds the high water mark H, it will stop and wait for the stable checkpoint to change before continuing.

In blockchain scenarios, it is generally suitable for private chain and alliance chain scenarios that require strong consistency. For example, in the IBM-led blockchain Hyperledger project, PBFT is an optional consensus protocol. In Hyperledger's Fabric project, the consensus module is designed as a pluggable module and supports consensus algorithms such as PBFT and Raft.

Raft is based on a leader-driven consensus model in which an outstanding leader will be electedLeader (Leader), and the Leader will be fully responsible for managing the cluster. The Leader is responsible for managing the replication logs between all nodes of the Raft cluster.

In the figure below, the Leader (S1) of the cluster will be selected during the startup process and serve all commands/requests from clients. All nodes in a Raft cluster maintain a distributed log (replicated log) to store and submit commands (log entries) issued by clients. The Leader accepts log entries from clients and replicates them among all followers (S2, S3, S4, S5) in the Raft cluster.

In a Raft cluster, a minimum number of nodes is required to provide the expected level of consensus guarantee, also known as a quorum. The minimum number of votes required to perform an operation in a Raft cluster is (N / 2 +1), where N is the total number of members in the group, that is, at least more than half of the votes, which is why cluster nodes usually have an odd number of nodes. So, in the example above, we need at least 3 nodes to have consensus guarantees.

If the legal quorum node is unavailable for any reason, that is, the votes do not exceed half, the negotiation will not reach an agreement and new logs cannot be submitted.

Data storage: Tidb/TiKV

Log: Alibaba's DLedger

Service discovery: Consul& etcd

< p> Cluster scheduling: HashiCorp Nomad

Can only accommodate faulty nodes (CFT), not evil nodes

Sequential voting, only serial apply, so high concurrency Poor performance in scenarios

Raft solves the distributed consensus problem by solving the three main sub-problems surrounding Leader election and managing the security functions of distributed logs and algorithms.

When we start a new Raft cluster or a leader is unavailable, a new leader will be elected through negotiation among all member nodes in the cluster. Therefore, in a given instance, a node of a Raft cluster can be in any of the following states: Follower, Candidate, or Leader.

When the system first starts, all nodes are followers. If they do not receive the heartbeat signal from the Leader within a period of time, the followers will convertis a Candidate;

If a Candidate node receives votes from the majority of nodes, the Candidate can be converted into a Leader, and the remaining Candidate nodes will return to the Follower state;

Once If a Leader finds that there is a Leader node with a higher term than itself in the system, it will convert to a Follower.

Raft uses a heartbeat-based RPC mechanism to detect when a new election starts. During normal times, the Leader will regularly send heartbeat messages to all available Followers (in practice, the log and heartbeat may be sent together). Therefore, the other node starts in the Follower state and remains in the Follower state as long as it receives periodic heartbeats from the current Leader.

When the Follower reaches its timeout, it will start the election process in the following way:

Based on the responses that the Candidate receives from other nodes in the cluster, the three steps for the election can be derived result.

The implementation of consensus algorithms is generally based on replicated state machines. What is a replicated state machine:

In simple terms: the same initial recognition state + the same input = Same end state. Different nodes should use the same and deterministic function to process input, rather than introducing uncertain values, such as local time, etc. It is a good idea to use replicated log. Log has the characteristics of persistence and order preservation, and is the cornerstone of most distributed systems.

With the Leader, all concurrent requests from the client can form an orderly log (status) sequence on the Leader's side to represent the order in which these requests are processed. The Leader then sends its log sequence to the Followers to maintain the global consistency of the entire system. Note that this is not strong consistency, but eventual consistency.

The log consists of log entries with a sequential number (log index). Each log entry consists of the term when it was created, and the data contained in the log, which can be of any type, from simple types to blocks of the blockchain. Each log entry can be represented by a [term, index, data] sequence pair, where term represents the term, index represents the index number, and data represents the log data.

The Leader attempts to execute replication commands on a majority of the nodes in the cluster. If the replication is successful, the command is submitted to the cluster and the response is sent back to the client. Similar to two-phase commit (2PC), but the difference from 2PC is that the leader only needs the consent of more than half of the nodes (in a working state).

Both leader and follower may crash, so the log maintained by the follower may have the following situation compared with the leader

When the leader and follower are inconsistent, the leader forces the follower to copy its own log, the Leader will try from back to front. Each time AppendEntries fails, it will try the previous log entry (decrementing the nextIndex value) until it successfully finds the consistent position point of each Follower's log (based on the two guarantees mentioned above), and then moves backward one by one. Overrides the Followers entry after this position. So missing or extra entries may persist for multiple terms.

Requires the candidate's log to be at least as up-to-date as other nodes. If not, the follower node will not vote for the candidate.

Means that each submitted entry must exist in at least one of these servers. If a candidate's log is at least as up-to-date as the other logs in the majority, it will save all committed entries, avoiding a log rollback event.

That is, at most one leader can be elected in any term. This is very important, there can only be one leader in a replica set at any time. There is more than one leader in the system at the same time, which is called brain split. This is a very serious problem and will cause data coverage loss. In raft, two points guarantee this property:

Therefore, there must be only one leader in a certain term.

When the status of nodes in the cluster changes (the cluster configuration changes), the system is vulnerable to system failure. So, to prevent this, Raft uses something called a two-phase approach to changing cluster membership. Therefore, in this approach, the cluster first changes to an intermediate state (called federated consensus) before implementing a new membership configuration. Federated consensus enables the system to be used to respond to client requests even when transitioning between configurations, and its main purpose is to improve the availability of distributed systems.

IV What is the core algorithm (distributed storage) of Jinwowo blockchain technology?

Distributed storage is a data storage technology that uses eachThe disk space on each machine is used, and these scattered storage resources are formed into a virtual storage device, and the data is stored in various corners of the network.

VI Blockchain encryption technology

Digital encryption technology is the key to the application and development of blockchain technology. Once the encryption method is cracked, the data security of the blockchain will be challenged, and the tamperability of the blockchain will no longer exist. Encryption algorithms are divided into symmetric encryption algorithms and asymmetric encryption algorithms. Blockchain primarily uses asymmetric encryption algorithms. Public key cryptography systems in asymmetric encryption algorithms are generally divided into three categories according to the problems they are based on: large integer differentiation problems, discrete logarithm problems and elliptic curve problems. First, introduce blockchain encryption technology. Encryption algorithms are generally divided into symmetric encryption and asymmetric encryption. Asymmetric encryption refers to encryption technology integrated into the blockchain to meet security requirements and ownership verification requirements. Asymmetric encryption usually uses two asymmetric keys, called public and private keys, in the encryption and decryption process. Asymmetric key pairs have two characteristics: First, after one key (public key or private key) encrypts information, it can only decrypt the other corresponding key. Second, the public key can be disclosed to others, but the private key is kept confidential, and others cannot calculate the corresponding private key through the public key. Asymmetric encryption is generally divided into three main types: large integer differentiation problems, discrete logarithm problems and elliptic curve problems. The problem class of large integer differentiation refers to using the product of two large prime numbers as the encrypted number. Since the appearance of prime numbers is irregular, solutions can only be found through constant trial calculations. The discrete logarithm problem class refers to an asymmetric distributed encryption algorithm based on the difficulty of discrete logarithms and strong one-way hash functions. Elliptic curve refers to the use of flat elliptic curves to calculate a set of asymmetric special values. Bitcoin uses this encryption algorithm. The application scenarios of asymmetric encryption technology in blockchain mainly include information encryption, digital signature and login authentication. (1) In the information encryption scenario, the sender (denoted as A) encrypts the information with the public key of the receiver (denoted as B) and sends it to

B, who uses his own private key Decrypt the information. Encryption of Bitcoin transactions falls into this scenario. (2) In a digital signature scenario, sender A uses its own private key to encrypt the information and sends it to B. B uses A's public key to decrypt the information and then ensures that the information was sent by A. (3) In the login authentication scenario, the client uses the private key to encrypt the login information and sends it to the server. The server then uses the client's public key to decrypt the authenticated login information. Please note the differences between the above three encryption schemes: information encryption is public key encryption and private key decryption, ensuring the security of the information; digital signature is private key encryption and public key decryption, ensuring the ownership of the digital signature. Authenticated private key encryption and public key decryption. Taking the Bitcoin system as an example, its asymmetric encryption mechanism is shown in Figure 1: The Bitcoin system generally generates a 256-bit random number as a private key by calling the random number generator at the bottom of the operating system. The total amount of Bitcoin’s private keys is large, and it is extremely difficult to traverse all private key spaces to obtain Bitcoin’s private keys.So cryptography is safe. In order to facilitate identification, the 256-bit binary Bitcoin private key will be converted through the SHA256 hash algorithm and Base58 to form a 50-character long private key, which is easy for users to identify and write. Bitcoin's public key is a 65-byte random number generated by the private key through the Secp256k1 elliptic curve algorithm. Public keys can be used to generate addresses used in Bitcoin transactions. The generation process is that the public key is first hashed through SHA256 and RIPEMD160 to generate a 20-byte summary result (that is, the result of Hash160), and then converted through the SHA256 hash algorithm and Base58 to form a 33-character Bitcoin address. The public key generation process is irreversible, that is, the private key cannot be derived from the public key. Bitcoin’s public and private keys are usually stored in Bitcoin wallet files, with the private key being the most important. Losing the private key means losing all the Bitcoin assets of the corresponding address. In the existing Bitcoin and blockchain systems, multi-private key encryption technology has been derived based on actual application requirements to meet more flexible and complex scenarios such as multi-signatures.

Ⅶ In-depth understanding of the consensus mechanism and algorithm principles of the blockchain

The so-called "consensus mechanism" is to complete the verification of transactions in a very short time through the voting of special nodes and confirmation; for a transaction, if several nodes with unrelated interests can reach a consensus, we can think that the entire network can also reach a consensus on it. To put it more simply, if a Chinese Weibo influencer, a virtual currency player in the United States, an African student and a European traveler do not know each other, but they all agree that you are a good person, then it can basically be concluded that You're not a bad person.

In order for the entire blockchain network node to maintain the same data and ensure the fairness of each participant, all participants in the entire system must have a unified agreement, which is what we have here The consensus algorithm to be used. All Bitcoin nodes follow unified protocol specifications. The protocol specification (consensus algorithm) consists of relevant consensus rules, which can be divided into two major cores: proof of work and the longest chain mechanism. The ultimate expression of all rules (consensus) is the longest chain of Bitcoin. The purpose of the consensus algorithm is to ensure that Bitcoin continues to operate on the longest chain, thereby ensuring the consistency and reliability of the entire accounting system.

Users in the blockchain do not need to consider the credit of the other party when conducting transactions, do not need to trust the other party, and do not need a trusted intermediary or central agency. They only need to follow the blockchain protocol. Realize the transaction. The premise for smooth transactions without the need for a trusted third-party intermediary is the consensus mechanism of the blockchain, that is, in a market environment of mutual understanding and trust, each node participating in the transaction considers its own interests and does not violate any regulations. Motives and behaviors of cheating, so each node will actively and consciously abide by the preset rules to judge the authenticity and reliability of each transaction, and write the record of passing inspection into the blockchain. The interests of each node are different, logically there is no incentive for them to collude to deceive, and this is especially obvious when some nodes in the network have public reputation. Blockchain technology uses a consensus algorithm based on mathematical principles to establish a "trust" network between nodes, and uses technical means to achieve an innovative credit network.

At present, the mainstream consensus algorithm mechanisms in the district industry include: workload proof mechanism, equity proof mechanism, share authorization proof mechanism and Pool verification pool.

The workload proof mechanism is the proof of workload, which is a requirement that must be met when generating a new transaction information (i.e. a new block) to be added to the blockchain. In a blockchain network built based on the proof-of-work mechanism, nodes compete for accounting rights by calculating the numerical solution of random hashing. The ability to obtain the correct numerical solution to generate blocks is a specific manifestation of the node's computing power. The proof-of-work mechanism has the advantage of being completely decentralized. In a blockchain with a proof-of-work mechanism as the consensus, nodes can enter and exit freely. The well-known Bitcoin network uses a proof-of-work mechanism to produce new currencies. However, since the application of the workload proof mechanism in the Bitcoin network has attracted most of the computing power of computers around the world, it is difficult for other blockchain applications that want to try to use this mechanism to obtain the same scale of computing power to maintain their own security. At the same time, mining based on the proof-of-work mechanism also causes a lot of waste of resources, and the period required to reach consensus is also long, so this mechanism is not suitable for commercial applications.

In 2012, a netizen with the pseudonym Sunny King launched Peercoin. This encrypted electronic currency uses a proof-of-work mechanism to issue new coins and a proof-of-stake mechanism to maintain network security. This is the role of the proof-of-stake mechanism in encrypted electronic currency. first application in . Rather than requiring the certifier to perform a certain amount of computational work, Proof of Stake simply requires the certifier to provide ownership of a certain amount of cryptocurrency. The way the proof-of-stake mechanism works is that when a new block is created, the miner needs to create a "coin rights" transaction, which sends a number of coins to the miners themselves according to a preset ratio. The proof-of-stake mechanism reduces the mining difficulty of nodes in equal proportions based on the proportion and time of tokens owned by each node based on the algorithm, thus speeding up the search for random numbers. This consensus mechanism can shorten the time required to reach consensus, but essentially still requires nodes in the network to perform mining operations. Therefore, the PoS mechanism does not fundamentally solve the problem that the PoW mechanism is difficult to apply in the commercial field.

The share authorization certification mechanism is a new consensus mechanism to ensure network security. While trying to solve the problems of the traditional PoW mechanism and PoS mechanism, it can also offset the negative effects of centralization by implementing technological democracy.

The share authorization proof mechanism is similar to board voting. This mechanism has a built-in real-time shareholder voting system.system, just like the system is convening a never-ending shareholders' meeting at any time, where all shareholders vote to decide company decisions. The decentralization of the blockchain established based on the DPoS mechanism relies on a certain number of representatives rather than all users. In such a blockchain, all nodes vote to elect a certain number of node representatives, who act on behalf of all nodes to confirm blocks and maintain the orderly operation of the system. At the same time, all nodes in the blockchain have the power to remove and appoint representatives at any time. If necessary, all nodes can vote to disqualify the current node representatives and re-elect new representatives to achieve real-time democracy.

The share authorization certification mechanism can greatly reduce the number of nodes participating in verification and accounting, thereby achieving second-level consensus verification. However, this consensus mechanism still cannot perfectly solve the application problems of blockchain in business, because this consensus mechanism cannot get rid of its dependence on tokens, and the existence of tokens is not required in many commercial applications.

The Pool verification pool is based on traditional distributed consistency technology and is supplemented by a data verification mechanism. It is a consensus mechanism widely used in current blockchains.

The Pool verification pool can work without relying on tokens. Based on mature distributed consensus algorithms (Pasox, Raft), it can achieve second-level consensus verification, which is more suitable for multi-party participation. Polycentric business model. However, the Pool verification pool also has some shortcomings. For example, the degree of distribution that the consensus mechanism can achieve is not as good as the PoW mechanism.

Here we mainly explain some algorithm principles of the blockchain workload proof mechanism and the Bitcoin network. How to prove your workload? I hope everyone can have a basic understanding of the consensus algorithm.

The main feature of the proof-of-work system is that the client has to do a certain amount of difficult work to get a result, and the verifier can easily use the results to check whether the client has done the corresponding work. A core feature of this scheme is asymmetry: the work is modest for the requester and easy to verify for the verifier. It differs from CAPTCHAs, which are easier to solve by humans rather than easier to solve by computers.

The figure below shows the workload proof process.

For example, give a basic character "hello, world!", the workload requirement we give is that you can add a nonce (random number) after this character creation Integer value, perform SHA-256 operation on the changed (nonce added) character creation, if the result (expressed in hexadecimal form) starts with "0000", the verification is passed. In order to achieve this workload proof goal, it is necessary to continuously increase nonce value, perform a SHA-256 hash operation on the resulting character. According to this rule, it takes 4251 operations to find the hash with leading 4 zeros.

Through this example, we have a preliminary understanding of the proof-of-work mechanism. Some people may think that if proof of work is just such a process, then it is enough to remember that the nonce is 4521 so that the calculation can pass verification. Of course not, this is just an example.

Next we simply change the input to "Hello, World! + integer value". The integer value ranges from 1 to 1000, which means that the input is turned into an array of 1 to 1000: Hello, World !1;Hello,World!2;...;Hello,World!1000. Then perform the above proof of work on each input in the array in turn - find the hash with leading 4 zeros.

Due to the pseudo-random nature of the hash value, it is easy to calculate based on the relevant knowledge of probability theory. It is expected that it will take 2 to the 16th power of attempts to obtain a hash hash with four leading zeros. List. If you count the actual results of the 1,000 calculations just performed, you will find that the average number of calculations is 66,958, which is very close to 2 to the 16th power (65,536). In this example, the number of calculations expected by mathematics is actually the required "workload". Repeating the workload proof multiple times will be a probability event that conforms to statistical laws.

The actual number of calculations used to count the input characters and obtain the corresponding target result is as follows:

For any node in the Bitcoin network, if you want to generate a new block To join the blockchain, you must solve this puzzle of the Bitcoin network. The key elements of this question are the proof-of-work function, block and difficulty value. The workload proof function is the calculation method of this question, the block is the input data of this question, and the difficulty value determines the amount of calculation required to understand this question.

The proof-of-work function used in the Bitcoin network is the SHA-256 mentioned above. Blocks are actually generated in the proof-of-work process. Kuangong constantly constructs block data and checks whether each calculated result meets the required workload, thereby determining whether the block meets the network difficulty. The block header is the input data of the Bitcoin proof-of-work function.

The difficulty value is an important reference indicator for miners to mine. It determines how many hash operations it takes for miners to generate a legal block. The Bitcoin network generates a block approximately every 10 minutes. If the generation of new blocks basically maintains this speed under different network computing power conditions, the difficulty value must be adjusted according to changes in the computing power of the entire network. The general principle is that no matter what the mining power is, the network always remainsA new block is generated every 10 minutes.

The adjustment of the difficulty value occurs independently and automatically in each complete node. Every 2016 blocks, all nodes will automatically adjust the difficulty value according to a unified format. This formula is based on the time spent in the latest 2016 blocks and the expected time (assuming a withdrawal is generated every 10 minutes, the expected time is 20160 minutes) and adjusted according to the ratio of actual duration to expected duration. That is, if blocks are generated faster than 10 minutes, increase the difficulty value; anyway, decrease the difficulty value. The formula is expressed as follows:

New difficulty value = old difficulty value * (20160 minutes/time spent in the past 2016 blocks).

Proof of work requires a target value. The calculation formula of the target value (Target) of Bitcoin's proof of work is as follows:

Target value = maximum target value/difficulty value, where the maximum target value is a constant value

The size of the target value is inversely proportional to the difficulty value. To achieve the Bitcoin workload proof, the block hash value calculated in the mine must be less than the target value.

We can also simply understand the process of Bitcoin workload as performing SHA-256 hash operation by constantly changing the block header (that is, trying different nonce values) and using it as input. Find a process that has a hash value in a specific format (that is, requires a certain number of leading 0s), and the more leading 0s required, the more difficult it becomes.

The steps of Bitcoin’s proof-of-work puzzle can be roughly summarized as follows:

The process can be represented by the following figure:

Bitcoin’s proof of work is the main work we commonly call “mining”. Understanding the workload proof mechanism will lay the foundation for us to further understand the consensus mechanism of the Bitcoin blockchain.

Ⅷ How to understand the consensus algorithm pbft in IBM blockchain technology hyperledger-fabric in a popular way

1. What is the technology of blockchain? If we assume that the database is a ledger , reading and writing a database can be regarded as a kind of bookkeeping behavior. The principle of blockchain technology is to find the person with the fastest and best bookkeeping within a period of time. This person will do the bookkeeping, and then this part of the ledger will be recorded. Page information is sent to everyone else in the entire system.

Ⅸ Let you quickly understand the technical model architecture of blockchain in 1 minute

Blockchain technology is not a single technology, but a combination of multiple technologies that are innovative. As a result, it is essentially a weakly centered, self-reliant underlying architecture technology.
The blockchain technical model includes the data information layer, the consensus layer of the transmission layer, the incentive layer, the contract layer and the network layer from top to bottom. Each layer has an important role, and different levels cooperate with each other to build a value transfer system that goes to the management center.

The characteristics of the data information layer are that it cannot be forged, fully backed up data, and completely fair (data information, management permissions, coding), and its algorithm design is a blockchain, including blockchain headers and blocks material. The blockchain header consists of three sets of blockchain databases. One set of databases is the parent blockchain hash value, which is used to connect the block to the previous block in the blockchain. The second set of databases is the Merkle root. An algorithm designed to effectively summarize all transactions in the blockchain; the three sets of databases are the difficulty target, time format and Nonce related to the production of the blockchain.

The transport layer encapsulates technologies such as P2P network mechanism, dissemination and authentication mechanism. In the transport layer, new transactions are broadcast to major websites. Each node will include the received transaction information in a blockchain, and each node will try to add it to its own blockchain. Find a proof of workload with sufficient difficulty. When a node finds a proof of workload (qualified to package the blockchain), it broadcasts the program (newly packaged blockchain) to major websites. When And only if all transactions included in the block are valid and have not existed before, other nodes will recognize the validity of the block, and the way to express acceptance is to follow the block. At the end of the block, a new block is created to add to the chain, and any hash of the accepted block is treated as any hash of the new block.

The consensus layer encapsulates various consensus algorithms of nodes, which is the key technology of the blockchain, because this determines the formation of the blockchain, and the accounting decision-making method may affect the entire system. Software safety and stability. At present, more than ten consensus mechanism algorithms have been produced, among which the well-known ones are the proof-of-work mechanism (POW), the easy-to-use Byzantine fault tolerance algorithm (PBFT), the proof-of-interest mechanism (POS), and the equity authorization proof mechanism.

The encouragement layer includes an offering system and an incentive system. Simply put, the incentive system is to encourage nodes to participate in maintaining the optimal operation of the blockchain system in a balanced economic manner, to avoid falsification of the general ledger, and to maintain the driving force for the operation of the blockchain network in the long term.

The contract layer has the characteristics of a programmable controller, which mainly includes smart contracts, consensus algorithms, scripting, and coding. It is the basis for the characteristics of a blockchain programmable controller. Insert the code into the blockchain or dynamic password to implement a customizable smart contract, and under certain specific constraints, it can be executed automatically without going through a third party, which is trustworthy in the blockchain. baseBook.
The network layer encapsulates various application fields and examples of blockchain, which is very similar to computer applications and portals on computer browsers. It deploys blockchain core technologies on things such as Ethereum. , EOS and implemented in practice.

#BTC[超话]# #digital currency#