Intelligent contract gateway based on block chain CPOW consensus algorithmTechnical Field
The invention relates to a computer application program, in particular to an intelligent contract gateway based on a block chain CPOW consensus algorithm, which provides strong support based on a block chain for a third-party developer and enables the block chain to be applied to a client more quickly.
Background
The bitcoin is digital currency in a P2P form, is not issued by a specific currency institution, is generated through a large number of calculations according to a specific algorithm, is economically generated by using a distributed database consisting of a plurality of nodes in the whole P2P network to confirm and record all transaction behaviors, and is designed by using cryptography to ensure the safety of all links of currency circulation. The decentralized nature of P2P and the algorithm itself may ensure that monetary value cannot be manipulated artificially by making large quantities of bitcoins. The cryptology-based design may allow bitcoins to be transferred or paid only by the true owner. This also ensures anonymity of monetary ownership and currency transactions, technically the bitcoin is a point-to-point digital currency system, the entire system is built based on the UTXO transaction model, with emphasis on the layout and record of transactions and data structures. In calculating the hash and the proof of the workload, the bitcoin is based on the miner calculating the only correct hash value to prove the workload to obtain the accounting packing block right and thus obtain the reward, and the proof of the workload (Pow) is used.
The Ethenhouse is a point-to-point decentralized virtual machine and is a bottom system capable of realizing intelligent contracts and open sources on block chains. Technically speaking, an ethernet is a virtual machine, and the full term should be an intelligent contract virtual machine, i.e., a virtual machine that emphasizes executing contracts in accordance with the contract's mode. Therefore, etherhouses are based on the Account model (there are also places saying EVM, why accounting is the Account model in the case of smart contract virtual machines, etherhouses are based on the Account hierarchy). Although some EtFang has learned on the basis of the bitcoin, a new mode is created to provide ideas for later developers, and meanwhile, the later developers basically select one mode as the own application mode under the two modes. In computing hash and workload proofs, etherhouses want to optimize the work in bitcoin because this pattern of bitcoin mining is computationally intensive, such as the presence of a professional mining machine, and the second page is relatively wasteful of power and social resources. A rights and interests certification mechanism (Pos) is provided, which can avoid certain calculation power concentration and resource waste.
A block chain (Blockchain) is a distributed peer-to-peer network without a central control point, and a distributed collective operation method is used for realizing a set of non-falsifiable and trustable database technical scheme, and is characterized by decentralized storage, high information transparency, difficulty in falsification and the like. In another popular way, the blockchain is a "public big account book" that records all transaction information in the whole network by using a computer program. The nodes in the block chain network obtain the right of accounting by calculating a difficult calculation problem; the entire general ledger can be observed by any node on the blockchain network; block chain data is commonly maintained by each node, each node participating in maintenance can be copied to obtain a copy of a complete database, and unless more than 51% of nodes in the whole system can be controlled simultaneously, modification of the database on a single node is invalid, and data content on other nodes cannot be influenced. Bitcoin and ether house are both successful blockchain technology applications, and are the most typical representatives. In another word, only the bit coin has the block chain technology, and people in the Taifang can recognize that the block chain can be independent, not only the bit coin can have the block chain technology, but also the Taifang opens the idea of the block chain world. The underlying basic idea is the same, since all are applications of the blockchain technique. All are point-to-point network nodes, public accounts, consensus basic algorithms, all maintain the network by mining.
The compatibility problem exists in the two block chains of the bitcoin ecology and the ether house ecology, and although the operations of the bitcoin and the ether house are based on the principles of the distributed ledger and the encryption technology, the two block chains still have the following differences in numerous technical fields:
technically, bitcoin is a point-to-point digital currency system, and the whole system is established based on a transaction model of UTXO, and the emphasis is on the layout and recording of transactions and data structures. In calculating the hash and the proof of the workload, the bitcoin is based on the miner calculating the only correct hash value to prove the workload to obtain the accounting packing block right and thus obtain the reward, and the proof of the workload (Pow) is used. The bitcoin is used on the basic algorithm as the secure hash algorithm, SHA-256.
Technically, an ethernet is a virtual machine, and the complete statement should be an intelligent contract virtual machine, i.e., a virtual machine that emphasizes executing contracts in accordance with the mode of the contract. So the etherhouses are based on Account model (there are also places saying EVM, why accounting is the Account model in the case of smart contract virtual machine, etherhouses are based on Account system). Therefore, although some Ether Fang are learned on the basis of the bitcoin, a new mode is created to provide ideas for later developers, and meanwhile, the later developers basically select one of the two modes as the own application mode. In computing hash and workload proofs, etherhouses wish to optimize the work in this respect for bitcoin because this pattern of bitcoin mining is computationally intensive, such as the presence of a professional mining machine, the second page is relatively wasteful of power and social resources. A rights and interests certification mechanism (Pos) is provided, which can avoid certain calculation power concentration and resource waste. The ethereal uses ethash on the basis of the basic algorithm.
Verbally: the programming language used by EtherFang is Turning complete, while the bitcoin is a stack-based programming language.
Therefore, in the actual application process, if the bitcoin is fused and compatible with the application, the fusion process has considerable difficulty, time and labor.
The 51% attack problem of two blockchains, bitcoin and etherhouse: bit currency and most current cryptocurrency adopt a POW (programmable optical disk) mechanism, namely workload certification, to realize consensus, and a numerical value (nonce) is guessed through calculation, so that the specified hash problem can be solved. It is guaranteed that only a few legal results can be presented in the system over a period of time. At the same time, these small legal results are broadcast over the network, and the received user, after verification, will continue the computation of the puzzle based on the longest chain that it considers. Thus, a strand bifurcation (Fork) may occur in the system, but eventually one strand becomes the longest strand. The hash problem has the irreversible characteristic, so that no effective algorithm is available for solving except for brute force calculation. On the contrary, if the required nonce is obtained, the corresponding calculation force is probably exerted. The more powerful one is, the greater the probability of who solves the problem first. When the mastery exceeds half of the calculation power of the whole network, the trend of the chain in the network can be controlled in probability. This is also the origin of the so-called 51% attack. If one has more than 50% of the calculation power, he can find the random number needed for the mining area faster than others, so he actually has the valid right of which area. Enabling him to 1, modify his own transaction record, which may enable him to make double payments; 2. block validation is prevented for some or all transactions; 3. preventing some or all miners from mining to any active block.
Disclosure of Invention
The invention aims to provide an intelligent contract gateway based on a block chain CPOW consensus algorithm aiming at the compatibility problem of bit currency ecology and EtherFang ecology, a platform enables developers to establish and release next generation distributed application, various modules are provided on the platform to enable users to build the application, the cost and the speed of establishing the application are improved, the problem of 51% attack is solved, and the transaction performance is greatly improved.
In order to realize the purpose of the invention, the following technical scheme is adopted:
an intelligent contract gateway based on a block chain CPOW consensus algorithm, which comprises a protocol layer, an extension layer and an application layer, wherein,
the protocol layer comprises a network layer and a storage layer which are independent but not separable, and the network layer comprises a p2p network and a CPOW consensus algorithm. The storage layer stores data information on a block chain;
the extension layer provides a basic transaction type defined by a protocol mode compatible with the Ethengfang virtual machine based on a bit currency protocol and a programmable transaction script of an original system, and is matched with an advanced programmable transaction script provided by the system to achieve an intelligent contract which cannot be completed by the original bit currency;
the application layer comprises various services related to the intelligent contract gateway, and a service user provided by the application layer can select the various services according to the requirement, so that the user can be helped to quickly get up to the block chain service.
The working mechanism of the protocol layer is as follows:
(1) when the data is transmitted through the network layer, the transmitting node broadcasts a new data record to the whole network;
(2) the receiving node checks the received data record information, checks whether the record information is legal or not, and brings the data record into a block after the record information is verified;
(3) all receiving nodes of the whole network execute a CPOW consensus algorithm on the blocks;
(4) the blocks are formally stored in a block chain after passing through a consensus algorithm process, all network nodes indicate that the blocks are accepted, and the method for indicating acceptance is that the random hash value of the block is regarded as the latest block hash value, and the block is manufactured and extended on the basis of the block chain.
The application layer comprises the following services:
(1) authorization service and authentication service: and (3) using the login authorization service inherent in the gateway, and returning an openid to distinguish different users if the authorization is successful:
(2) identity management service: managing identity information of a user;
(3) characteristic service: storing the related data information;
(4) signature management service: providing signature processing in the data transmission process;
(5) intelligent contract management service: the contracts can be customized and the existing contracts can also be processed.
The intelligent contract gateway based on the block chain CPOW consensus algorithm is executed through a smart script, a customized contract is provided through an EVM (event-based management) protocol mode, communication is carried out through an API (application programming interface) and the block chain, and the content and the behavior of the intelligent contract are recorded on the block chain.
The CPOW consensus algorithm adopts a dynamic nonlinear workload proving mechanism on the basis of the bit currency POW, adjusts the difficulty of each miner in obtaining the verifier, avoids the possibility of tending to monopolize verification, solves the problem of 51% attack, and shortens the confirmation time of an average block.
The logic process of the CPOW consensus algorithm is as follows:
(1) packaging the transaction, searching a transaction memory pool to be confirmed, and selecting the transaction including the block;
(2) constructing a Coinbase, and counting the total amount of the block commission charge after determining a transaction set including the block, wherein miners can calculate the income of the block by combining with the output rule;
(3) constructing a hashMerkLeroot, and constructing Merkle numbers for all transactions;
(4) filling other fields to obtain a complete block header;
(5) CPOW operation, in the dynamic nonlinear workload proving mechanism, the N-1 blocks are calculated back according to the current time point, and each participating miner carries out CPOW operation on the block head according to the times of the chosen bit verifier in the N-1 blocks. Dynamically adjusting the difficulty of digging the mine at the moment, namely adjusting the expected value of the workload certification;
(6) verifying the result, if the difficulty is met, broadcasting to the whole network, and digging the next block; and if the difficulty is not met, changing the certain field according to a certain strategy, and then carrying out CPOW operation and verification.
The invention starts from a protocol layer of a block chain, points a development target to an application layer, provides strong support based on the block chain for a third-party developer, is compatible with more applications, and enables the block chain to be applied to a client more quickly;
the CPOW algorithm provided by the invention avoids the possibility of tending to monopolize verification by adjusting the difficulty of each miner for selecting the verifier, not only solves the problem of 51% attack, but also greatly improves the transaction performance.
If the building application is compared with a building house, the intelligent contract gateway based on the block chain CPOW consensus algorithm provides modules such as a wall surface, a roof, a floor and the like, and a user only needs to build the house like building blocks, so that the cost and the speed of building the application on the intelligent contract gateway based on the block chain CPOW consensus algorithm are greatly improved.
Drawings
FIG. 1 is an intelligent contract gateway infrastructure based on a blockchain CPOW consensus algorithm;
fig. 2 is the working mechanism of the intelligent contract gateway protocol layer.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention will be described in further detail below with reference to the accompanying drawings and specific embodiments.
FIG. 1 is an intelligent contract gateway infrastructure based on a blockchain CPOW consensus algorithm; in terms of architecture design, the intelligent contract gateway based on the blockchain CPOW consensus algorithm can be simply divided into three layers, namely a protocol layer, an extension layer and an application layer. Wherein,
1. the protocol layer comprises a network layer and a storage layer which are independent from each other but can not be divided, the storage layer mainly stores some data information on a block chain, and the network layer comprises a p2p network and a CPOW consensus algorithm. The protocol layer works as follows:
(1) when data is transmitted through a network layer, a transmitting node broadcasts a new data record to the whole network;
(2) the receiving node checks the received data record information, for example, whether the record information is legal, and the data record is included in a block after verification,
(3) CPOW consensus algorithm is executed on blocks by all receiving nodes in whole network
(4) The blocks are formally stored in a block chain after passing through a consensus algorithm process, all network nodes indicate that the blocks are accepted, and the method for indicating acceptance is that the random hash value of the block is regarded as the latest block hash value, and the block is manufactured and extended on the basis of the block chain.
2. The extension layer is also called an intelligent contract layer, the intelligent contract function is based on a bit currency protocol and an original programmable transaction script, although the bit currency can provide the programmable transaction script, the function is limited, various requirements cannot be met, and complicated calculation is not supported. Bitcoin tends to support relatively simple transaction scripts. Some more specific scripts are not guaranteed to be accepted by bitcoin segment network nodes. The intelligent contractual layer provides a base transaction category that may be defined in an agreed upon manner compatible with the etherhouse virtual machine. By matching with the advanced stylized transaction script provided by the system, the intelligent contract which cannot be completed by the original bitcoin can be achieved, for example, an automatic execution function is provided, namely the calculation which cannot be executed by the bitcoin. Meanwhile, the layer also provides a standardized contract which can be communicated with the gateway through the API provided by the gateway, and a user can quickly construct the contract belonging to the user without a special programming background. Based on the bitcoin, the transaction script of the intelligent contract layer can be made complete. The flexibility makes the gateway a solution to the general problem. Since the blockchain needs a plurality of nodes to verify whether the transaction passes, the gateway can become a universal solution with public trust and is suitable for being applied to various public solutions and private alliances.
3. The application layer comprises an authorization service, an authentication service, an identity management service, a feature service, a signature management service, an intelligent contract management service and the like, and helps a user to quickly start block chain service. The service user provided by the application layer can select the following services according to the requirement:
(1) authorization service and authentication service: the login authorization service inherent in the gateway can be used, and if the authorization is successful, an openid is returned to distinguish different users:
(2) identity management service: mainly managing identity information of a user;
(3) characteristic service: mainly storing some data information;
(4) signature management service: providing signature processing in the data transmission process;
(5) intelligent contract management service: the contracts can be customized and the existing contracts can also be processed.
The intelligent contract gateway based on the block chain CPOW consensus algorithm is mainly executed through a ring complete script, a customized contract is provided through an EVM (Ethernet Virtual machine) protocol mode, communication is carried out through an API (application programming interface) and a block chain, the content and the behavior of the intelligent contract are recorded on the block chain, and the intelligent contract gateway is beneficial to automatic contract fulfillment because the contract and data are completely put on the block chain, the contract fulfillment can be completely finished on the block chain without external intervention, and the contract is executed in the most efficient mode. The intelligent contract gateway based on the block chain CPOW consensus algorithm is a scheme capable of solving the general problem due to the fact that the graph is complete. The platform can realize the compatibility with the Bizhou ecology and the Ethengfang ecology, promotes the productization of the blockchain technology and improves the usability of the blockchain industry through the strategy of a mobile terminal, and aims to connect the real business society with the blockchain world. Making more applications correspondingly compatible.
For the 51% attack problem of bitcoin and ether house, we propose the CPOW consensus algorithm. The CPOW consensus algorithm is based on the bit currency POW, adopts a dynamic nonlinear workload proving mechanism, adjusts the difficulty of each miner to be selected as a verifier, avoids the possibility of tending to monopolize verification, and solves the problem of 51% attack. And the confirmation time of the average block is shortened, the creation time of the target block is 15s, and the creation time of the average block of the bitcoin is 10 minutes, so that the per-second transaction performance is greatly improved, which is equivalent to 40 times of the per-second transaction of the original bitcoin.
The logic process is as follows:
(1) and packaging the transactions, searching a transaction memory pool to be confirmed, and selecting the transactions contained in the block. Miners can choose at will, or even not (cut out blocks), and because each block has a capacity limit (currently 1M), miners cannot choose indefinitely. The most reasonable strategy for miners is to first rank the transaction sets to be validated by commission and then include as many transactions as possible from high to low.
(2) Constructing Coinbase, and counting the total amount of the block commission charge after determining the transaction set including the block, and combining the output rule, the miners can calculate the income of the block.
(3) Construct hashMerkleRoot, construct merkles number for all transactions.
(4) And filling other fields to obtain a complete block header.
(5) CPOW operation, in the dynamic nonlinear workload proving mechanism, the N-1 blocks are calculated back according to the current time point, and each participating miner carries out CPOW operation on the block head according to the times of the chosen bit verifier in the N-1 blocks. The difficulty of mining at the moment is dynamically adjusted, namely the expected value of the workload certification is adjusted.
(6) Verifying the result, if the difficulty is met, broadcasting to the whole network, and digging the next block; and if the difficulty is not met, changing the certain field according to a certain strategy, and then carrying out CPOW operation and verification.
Since all transaction data is displayed in the blockchain, miners can easily calculate how difficult other miners are at a certain point in time, and thus dynamic adjustment is possible. Through the simulation of the Markov chain. After considering the distribution and conversion relationship of all winning possibilities and comparing various nonlinear models, the invention discloses a collective verification algorithm by using an exponential model. If two miners have k times difference in their verification times, the workload proving difficulty of the miners with the larger verification times will be 2 times of d of the other miners.
By improving the current mainstream POW consensus mechanism and adding a calculation power authentication part, certain block chain networks with specific requirements can be greatly protected.
In conclusion, the intelligent contract gateway based on the blockchain CPOW consensus algorithm not only solves the compatibility problem of the bitcoin ecology and the ether house ecology, but also solves the 51% attack problem of the blockchain.
The intelligent contract gateway based on the block chain CPOW consensus algorithm solves the problems of the existing bit currency ecological and Ether house ecological systems, opens two block chains and connects the real business society with the block chain world.
The intelligent contract gateway based on the blockchain CPOW consensus algorithm can be used for various applications, such as: internet finance, network security, copyright protection, etc.
Internet finance: the intelligent contract gateway based on the block chain CPOW consensus algorithm can fundamentally repair and rebuild the Internet, the block chain based on the intelligent contract gateway is a novel decentralized protocol system, transactions or other data can be safely stored, any centralized organization is not required to audit, the transactions are checked by the whole network, the transactions are not necessarily financial transactions, the data are not necessarily currency, and the intelligent contract gateway based on the block chain CPOW consensus algorithm can be applied to a plurality of applications. On the basis of the safety of the inherent block chain, the running speed is increased, the butt joint of the bottom layer and the application layer is more convenient and faster, and the maintenance of the internet financial safety is facilitated. The block chain technology is a modern internet financial technology based on a big data sharing theory, and a financial black and white list is established by means of four advantages of decentralization, distrust, collective maintenance and a reliable database, so that a credit investigation system of modern finance is fundamentally changed, and financial risks and financial fraud risks are reduced. The blockchain technology can avoid a complicated system, a more direct payment process is created between a payer and a payee, and the mode has the characteristics of low price and rapidness no matter domestic transfer or cross-border transfer is carried out, and no intermediate commission is needed.
And (4) network security: although the system of block chain is disclosed, the data exchange process of checking, sending and the like adopts advanced encryption technology. This technique ensures not only the correct source of the data, but also that the data is not intercepted by a person in the middle of the process. If the blockchain technique is applied more widely, the probability of hacking may be reduced, and therefore, the blockchain system is considered to be more reliable than the conventional system. The blockchain system reduces the traditional network security risk for the big reason that it relieves the need for man-in-the-middle.
Copyright protection: the intelligent contract gateway based on the block chain CPOW consensus algorithm provides powerful safety support for copyright protection. The block chain copyright can protect the originality because the block chain copyright can solve the most urgent pain point under the current original environment, and the block chain copyright can be applicable to all current copyright maintenance scenes, thereby having certain legal effectiveness. The block chain copyright registration is equivalent to the technical characteristic of using a block chain to remove centralization, namely embedding a 16-system password for the original work, and the password can be simultaneously stored on all computers of the block chain, namely, the password is equivalent to registering an 'electronic identity card' for the original work, and is permanent and effective and cannot be tampered.
The intelligent contract gateway based on the block chain CPOW consensus algorithm is beneficial to saving the cost of developing the bottom layer of the block chain, providing safety support and greatly improving the data running speed per second.
The invention provides an intelligent contract gateway based on a block chain CPOW consensus algorithm by pointing a development target to an application layer from a protocol layer. The method solves the compatibility problem of the bit currency ecology and the Ethengfang ecology, solves the problems of two systems of the block chain and the two chains, and designs a basic chain which is better connected with the real commercial society and the block chain world.
The invention provides a CPOW consensus algorithm, which solves the 51% attack problem of a block chain by adjusting the difficulty of each miner to be selected as a verifier. A dynamic nonlinear workload proving mechanism is adopted on the basis of the bit coins POW, in the dynamic nonlinear workload proving mechanism, N-1 blocks are back calculated according to the current time point, and each involved miner dynamically adjusts the difficulty of mining at the current time according to the number of times of obtaining a position verifier in the N-1 blocks, namely, the expected value of workload proving is adjusted. The difficulty of each miner for being selected as the verifier is adjusted, the possibility of tending to monopolize verification is avoided, and the 51% attack problem is solved. And the confirmation time of the average block is shortened, the creation time of the target block is 15s, and the creation time of the average block of the bitcoin is 10 minutes, so that the per-second transaction performance is greatly improved, which is equivalent to 40 times of the per-second transaction of the original bitcoin.
The above-mentioned embodiments are intended to illustrate the objects, aspects and advantages of the present invention, and it should be understood that the above-mentioned embodiments are only exemplary embodiments of the present invention, and are not intended to limit the present invention, and any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the scope of the present invention.