WO2020155811A1 - 区块链的智能合约执行方法及装置和电子设备 - Google Patents
区块链的智能合约执行方法及装置和电子设备 Download PDFInfo
- Publication number
- WO2020155811A1 WO2020155811A1 PCT/CN2019/120639 CN2019120639W WO2020155811A1 WO 2020155811 A1 WO2020155811 A1 WO 2020155811A1 CN 2019120639 W CN2019120639 W CN 2019120639W WO 2020155811 A1 WO2020155811 A1 WO 2020155811A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- contract
- source code
- execution
- blockchain
- party
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Ceased
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L9/00—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
- H04L9/06—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols the encryption apparatus using shift registers or memories for block-wise or stream coding, e.g. DES systems or RC4; Hash functions; Pseudorandom sequence generators
- H04L9/0618—Block ciphers, i.e. encrypting groups of characters of a plain text message using fixed encryption transformation
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/60—Protecting data
- G06F21/64—Protecting data integrity, e.g. using checksums, certificates or signatures
- G06F21/645—Protecting data integrity, e.g. using checksums, certificates or signatures using a third party
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06Q—INFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
- G06Q40/00—Finance; Insurance; Tax strategies; Processing of corporate or income taxes
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06Q—INFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
- G06Q40/00—Finance; Insurance; Tax strategies; Processing of corporate or income taxes
- G06Q40/04—Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L9/00—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
- H04L9/32—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials
- H04L9/3236—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials using cryptographic hash functions
- H04L9/3239—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials using cryptographic hash functions involving non-keyed hash functions, e.g. modification detection codes [MDCs], MD5, SHA or RIPEMD
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L9/00—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
- H04L9/50—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols using hash chains, e.g. blockchains or hash trees
Definitions
- the embodiments of this specification relate to the field of blockchain technology, and in particular to a method and device for executing a smart contract on a blockchain, and electronic equipment.
- Blockchain technology also known as distributed ledger technology, is an emerging technology in which several computing devices participate in “bookkeeping" and jointly maintain a complete distributed database. Because the blockchain technology has the characteristics of decentralization, openness and transparency, each computing device can participate in database records, and the rapid data synchronization between computing devices, the blockchain technology is widely used in many fields. application.
- a method for executing smart contracts on a blockchain is provided, the blockchain is docked with a trusted third party, and a contract engine for executing smart contracts is deployed in the trusted third party,
- the method includes:
- the node device in the blockchain receives the target transaction initiated by the client to call the target smart contract
- the contract source code is sent to the trusted third party, so that the contract engine of the trusted third party executes the contract source code and returns the execution result to the node device.
- the target transaction includes the name of the target smart contract; and, the name of the target function called in the target smart contract;
- the obtaining the contract source code of the target smart contract from the distributed database of the blockchain specifically includes:
- the contract source code corresponding to the target function name is obtained from the obtained contract source code.
- the transaction includes input parameters
- the sending the contract source code to the trusted third party so that the contract engine of the trusted third party executes the contract source code includes:
- the contract source code and the input parameters are sent to the trusted third party, so that the trusted third party obtains the input data corresponding to the input parameters from the node device, and loads the input data to The contract source code and execute the contract source code.
- another trusted third party as a verifier is connected to the blockchain;
- the method also includes:
- the execution result is released to all node devices in the blockchain for consensus processing, and after the consensus is passed, the execution result is stored in the blockchain.
- the execution result is a result set generated by the trusted third party based on the execution result of the contract source code; wherein, the result set includes a read-write set generated during the execution of the contract source code and after the execution of the contract source code The execution result obtained;
- the verification process for the execution result includes:
- the contract engine of the other trusted third party reads input data from the read-write set, loads the read input data into the contract source code, and simulates execution of the contract source code;
- the execution result is a result set generated by the trusted third party based on the execution result of the contract source code; wherein, the result set includes a read-write set generated during the execution of the contract source code and after the execution of the contract source code The execution result obtained;
- the verification process for the execution result includes:
- the contract engine of the other trusted third party reads input data from the read-write set, loads the read input data into the contract source code, and simulates execution of the contract source code;
- the blockchain is a consortium chain.
- a method for executing smart contracts on a blockchain is provided.
- the blockchain is docked with a trusted third party, and a contract engine for executing smart contracts is deployed in the trusted third party.
- the method includes:
- the contract engine of the trusted third-party receives the contract source code sent by the node device in the blockchain; wherein, the node device is a target in the blockchain that responds to the client to initiate a target smart contract
- the contract source code is the contract source code of the target smart contract
- the transaction includes input parameters
- the receiving the contract source code sent by the node device in the blockchain specifically includes:
- the execution of the contract source code specifically includes:
- the method further includes:
- the result set Upon receiving a verification request for the result set of the contract engine of another trusted third party sent by the node device, the result set is verified; wherein the result set includes the source code generated during the execution of the contract The read-write set and the execution result obtained after executing the contract source code;
- the execution result in the result set is released to all node devices in the blockchain for consensus processing, and after the consensus is passed, the execution result in the result set is stored in all nodes.
- the block chain
- the verification process for the second execution result includes:
- Read input data from the read-write set load the read input data into the contract source code, and simulate execution of the contract source code
- the verification process for the second execution result includes:
- Read input data from the read-write set load the read input data into the contract source code, and simulate execution of the contract source code
- the blockchain is a consortium chain.
- a smart contract execution device for a blockchain is provided, the blockchain is docked with a trusted third party, and a contract engine for executing smart contracts is deployed in the trusted third party,
- the device includes:
- the receiving unit, the node device in the blockchain receives the target transaction initiated by the client for invoking the target smart contract
- a response unit in response to the target transaction, obtains the contract source code of the target smart contract from the distributed database of the blockchain;
- the execution unit sends the contract source code to the trusted third party, so that the contract engine of the trusted third party executes the contract source code and returns the execution result to the node device.
- a smart contract execution device for a blockchain is provided, the blockchain is docked with a trusted third party, and a contract engine for executing smart contracts is deployed in the trusted third party,
- the method includes:
- the receiving unit the contract engine of the trusted third party receives the contract source code sent by the node device in the blockchain; wherein, the node device is a response to the client initiated in the blockchain for invoking the target intelligence
- the target transaction request node of the contract where the contract source code is the contract source code of the target smart contract;
- the execution unit executes the contract source code and returns the execution result to the node device and the node device.
- an electronic device including:
- a memory for storing processor executable instructions
- the processor is configured as any one of the smart contract execution methods of the blockchain.
- the embodiment of this specification provides a block chain smart contract execution scheme, which decouples the smart contract from the block chain node.
- the node device in the block chain no longer stores the smart contract or is responsible for the operation of the smart contract.
- the contract engine deployed in the trusted third party docked by the blockchain is responsible for running the smart contract; in this way, when the node device in the blockchain that responds to the client initiates a transaction needs to execute related business logic, it can call the trusted third party's Contract engine, which runs the related smart contract to get the execution result.
- the smart contract is separated and run by the contract engine, which simplifies the function of the node device and reduces the performance requirements of the node device (for example, devices with low performance can also be used as nodes
- the device is connected to the blockchain).
- consensus when consensus is reached between node devices in the blockchain, it is no longer dependent on smart contracts for consensus. Instead, consensus can be achieved by comparing the result set with the world state. It is not necessary for each node device to participate in smart contract operations, which greatly improves Consensus efficiency.
- the trusted third party connected to the blockchain as a node dedicated to running smart contracts, can be pre-set with powerful storage and computing capabilities to deploy a large number of smart contracts, and the business logic of smart contracts can be designed relatively Complex, in order to cope with the business needs of large calculation volume and high business complexity.
- Fig. 1 is a flowchart of a block chain smart contract execution method provided by an embodiment of this specification
- FIG. 2 is a schematic diagram of the architecture of a blockchain system provided by an embodiment of the present specification
- FIG. 3 is a flowchart of a method for executing a smart contract on a blockchain according to an embodiment of this specification
- FIG. 4 is a hardware structure diagram of a smart contract execution device for a blockchain provided by an embodiment of this specification
- Fig. 5 is a schematic diagram of a block chain smart contract execution device provided by an embodiment of this specification.
- FIG. 6 is a schematic diagram of modules of a smart contract execution device for a blockchain provided by an embodiment of this specification.
- first, second, third, etc. may be used in this specification to describe various information, the information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other.
- first information may also be referred to as second information, and similarly, the second information may also be referred to as first information.
- word “if” as used herein can be interpreted as "when” or “when” or "in response to determination”.
- Smart contract is a computer protocol designed to spread, verify, or execute contracts in an information-based way that can be deployed on the blockchain. The corresponding operations can be implemented by declaring the business logic in the smart contract. Smart contracts allow trusted transactions without a third party. These transactions are traceable and irreversible. Smart contracts can provide better security than traditional contract methods and reduce other transaction costs related to contracts.
- the traditional smart contract is directly deployed on the node device in the blockchain, and when the node device executes a transaction request, it directly runs the corresponding smart contract deployed locally. For situations where consensus is required, the execution results are also thrown out for consensus by all node devices in the blockchain, and each node device needs to run a locally deployed smart contract for consensus. It can be seen that, on the one hand, traditional smart contracts and node devices are strongly coupled.
- Each node device needs to deploy smart contracts and need to run smart contracts, which undoubtedly increases a lot of burdens for node devices (node devices need to have certain Computing power);
- node devices need to have certain Computing power
- each node device needs to re-execute a smart contract to determine whether the execution result is correct, resulting in a low consensus efficiency;
- due to limited storage and computing power of node devices Correspondingly limit the number and complexity of smart contracts, and traditional smart contracts cannot execute business logic with a large amount of calculation and complexity.
- This manual proposes a blockchain smart contract execution plan. By optimizing traditional smart contracts, it can improve the performance and efficiency of node devices in the blockchain, the efficiency of consensus among node devices, and the execution of smart contracts. Efficiency, etc., thereby improving the overall performance of the blockchain.
- the smart contract is decoupled from the blockchain node.
- the node device in the blockchain no longer stores the smart contract or is responsible for the operation of the smart contract. Instead, it is a trusted third party connected to the blockchain.
- the deployed contract engine is responsible for running the smart contract; in this way, when the node device in the blockchain that responds to the client-initiated transaction needs to execute related business logic, the contract engine can run the related smart contract by calling the contract engine of a trusted third party To get the execution result.
- the smart contract is separated and run by the contract engine, which simplifies the function of the node device and reduces the performance requirements of the node device (for example, devices with low performance can also be used as nodes
- the device is connected to the blockchain).
- consensus when consensus is reached between node devices in the blockchain, it is no longer dependent on smart contracts for consensus. Instead, consensus can be achieved by comparing the result set with the world state. It is not necessary for each node device to participate in smart contract operations, which greatly improves Consensus efficiency.
- the trusted third party connected to the blockchain as a node dedicated to running smart contracts, can be pre-set with powerful storage and computing capabilities to deploy a large number of smart contracts, and the business logic of smart contracts can be designed relatively Complex, in order to cope with the business needs of large calculation volume and high business complexity.
- the blockchain described in this specification may specifically include a private chain, a public chain, and an alliance chain, etc., which are not particularly limited in this specification.
- the above-mentioned blockchain may specifically be a consortium chain composed of headquarters organizations, branches, agencies, node devices, etc. as consortium members; the operator of the consortium chain can rely on the consortium chain to come Deploy the corresponding services; and the headquarters, branches, and agencies as members of the alliance described above can all be used as a business node for the above services.
- Each business node can publish its own generated or received results and execution results in the alliance chain in the form of transactions, and after the transaction is processed by the consensus nodes in the alliance chain, the distributed database in the alliance chain Perform storage and complete the "chain" deposit of the above transaction information.
- the transaction described in this specification refers to a piece of data that is created by the client of the blockchain and needs to be finally released to the distributed database of the blockchain.
- a transaction in a narrow sense refers to a transfer of value issued by a user to the blockchain; for example, in a traditional Bitcoin blockchain network, a transaction can be a transfer initiated by the user in the blockchain.
- a transaction refers to a piece of business data with business intent released by a user to the blockchain; for example, an operator can build a consortium chain based on actual business needs, and rely on the consortium chain to deploy some other types that are not related to value transfer Online business (for example, it can be broadly divided into query business, call business, etc.), and in this type of alliance chain, the transaction can be a business message or business request with business intentions released by the user in the alliance chain.
- the above-mentioned client may include any type of upper-layer application that uses the underlying business data stored in the blockchain as data support to implement specific business functions.
- Figure 1 is a flowchart of a blockchain smart contract execution method provided by an embodiment of this specification.
- the blockchain is docked with a trusted third party, and the trusted third party is deployed with execution intelligence.
- the contract engine of the contract, the method may include the following steps:
- Step 110 The node device in the blockchain receives the target transaction initiated by the client for invoking the target smart contract
- Step 120 In response to the target transaction, obtain the contract source code of the target smart contract from the distributed database of the blockchain;
- Step 130 Send the contract source code to the trusted third party, so that the contract engine of the trusted third party executes the contract source code, and returns the execution result to the node device.
- the client initiates a target transaction to the blockchain, and calls the smart contract function via the SDK.
- the SDK sends the target transaction to a node device on the blockchain, which can be called a calling node; the target transaction can be carried There are related execution parameters, such as contract name, calling function name, input parameters, transaction ID, time stamp, etc.
- the node device in this manual is not responsible for the operation of the smart contract; therefore, after receiving the target transaction initiated by the client, the calling node needs to call the contract engine of a trusted third party to execute the business logic of the corresponding smart contract.
- the calling node first needs to obtain the contract source code for the contract engine to execute the corresponding smart contract:
- the target transaction includes the name of the target smart contract; and, the name of the target function called in the target smart contract;
- the obtaining the contract source code of the target smart contract from the distributed database of the blockchain specifically includes:
- the contract source code corresponding to the target function name is obtained from the obtained contract source code.
- the node device can obtain the contract source code required by the target smart contract from the distributed database of the blockchain.
- the contract source code is composed of functions, and each function has a certain logic function, and the corresponding logic can be executed in the contract engine; the corresponding function can be determined through the target call function name to ensure that the contract source code contains The function is consistent with the target calling function.
- the contract source code of the smart contract is stored in the distributed database of the blockchain; when the smart contract needs to be used, the calling node first Obtain the corresponding contract source code from the distributed database, and then send the contract source code to the contract engine of a trusted third party; in this way, the smart contract executed by the contract engine every time is temporarily provided by the calling node.
- the target transaction further includes input parameters
- the sending the contract source code to the trusted third party so that the contract engine of the trusted third party executes the contract source code includes:
- the contract source code and the input parameters are sent to the trusted third party, so that the trusted third party obtains the input data corresponding to the input parameters from the node device, and loads the input data to The contract source code and execute the contract source code.
- some business types may not need to transmit data, the node device does not need to transmit input parameters (or, the input parameters may be empty), and the contract engine does not need to obtain input data from the node device.
- input data is required, and the user needs to submit input parameters when initiating a transaction.
- the contract engine can obtain input data from the node device according to the input parameter.
- the input parameters may be provided by the client (ie, the user), and the input data may be other data required to execute the smart contract.
- the transaction request sent by the client is, let a+1. Then the field a and plus 1 are the input parameters, and the current value of a is the input data.
- the contract engine can obtain the input data related to the input parameters stored locally by the node device from the node device.
- the contract engine can inject the contract source code, after obtaining the input data, load the input data into the contract source code, and execute the contract source code to obtain the execution result.
- the contract engine will also generate a read-write set during the execution of the contract source code.
- the read-write set may include input data required when executing the contract source code and output data corresponding to the input data.
- the input data and output data can contain multiple groups, that is, the read-write set is all the input data and corresponding output data required in the execution of the contract source code.
- the data set constitutes can truly reflect the entire contract source code. Perform the calculation process. Please refer to the examples shown in Table 1 or Table 2 below.
- the execution result is a result set generated by the trusted third party based on the execution result of the contract source code; wherein, the result set includes the read-write set generated during the execution of the contract source code and the execution contract The execution result obtained after the source code.
- the contract engine can package the input parameters, contract source code (or contract source code hash), read-write set, and execution result into a result set, and add the signature of the contract engine to the result set; add the signed result set Return to the node device as the execution result.
- the node device receives the result set returned by the contract engine; wherein, the result set is the input parameter, contract source code (or contract source code hash), read-write set and execution result packaged by the contract engine and then added The signature collection of this contract engine.
- the result set is the input parameter, contract source code (or contract source code hash), read-write set and execution result packaged by the contract engine and then added The signature collection of this contract engine.
- the contract engine needs to add a signature to the result set to ensure the validity of the smart contract execution. For the result set without signature, the node device will not confirm it and it is deemed invalid.
- the contract source code hash refers to the hash value obtained based on the contract source code; the contract source code hash can be used to verify whether the contract source code called by the contract engine has been tampered with. For example, suppose the contract source code provided by the node device is A, and the correct hash is (A) hash; then the node device or other nodes only need to compare the hash value of the contract source code of the target smart contract with the hash value of the contract source code in the result set. It can be judged whether the contract engine has tampered with the contract source code.
- the blockchain is docked with another trusted third party as a verifier
- the method also includes:
- the execution result is released to all node devices in the blockchain for consensus processing, and after the consensus is passed, the execution result is stored in the blockchain.
- the contract engine of another trusted third party is referred to as the second contract engine in the following, and the contract engine that runs the smart contract is referred to as the first contract engine.
- the node device can verify the execution result of the first contract engine through the second contract engine.
- the verification process for the execution result includes:
- the second contract engine reads input data from the read and write set, loads the read input data into the contract source code, and simulates execution of the contract source code;
- the verification process for the execution result includes:
- the verification process for the execution result includes:
- the contract engine of the other trusted third party reads input data from the read-write set, loads the read input data into the contract source code, and simulates execution of the contract source code;
- Table 2 is the read and write set in the result set returned by the first contract engine
- Table 1 is the read and write set obtained after the second contract engine simulating the contract source code running
- the second contract engine determines whether the read-write set returned by the first contract engine is true and valid.
- the read-write set includes a series of inputs and outputs. After the input data is read from the read-write set and the output data is simulated and executed, one by one Confirm whether the output data obtained is consistent with the read-write set (that is, the calculation results of all links in the entire process are consistent with expectations); if all are consistent, it is proved that the read-write set is valid and has not been tampered with, and then the final execution will be further carried out The result is matched with the result in the result set. This verification process can avoid cheating by the first contract engine.
- the node device needs to publish the execution result to all node devices in the blockchain for consensus processing, and after the consensus is passed, store the execution result in The blockchain.
- the consensus process here can be:
- the execution result sent by other node devices can be compared with the execution result in the local state database to reach a consensus on the execution result.
- the read-write set in addition to saving the execution result, can also be saved:
- the read-write set sent by other node devices can be compared with the read-write set in the local state database to reach a consensus on the execution result.
- FIG. 3 is a flowchart of a method for executing a smart contract on a blockchain according to an embodiment of this specification.
- the blockchain is docked with a trusted third party, and the trusted third party is deployed with execution intelligence.
- the contract engine of the contract, the method can be applied to the contract engine, and the method can include the following steps:
- Step 210 The contract engine of the trusted third party receives the contract source code sent by the node device in the blockchain; wherein, the node device is a response to the client initiated in the blockchain for invoking the target intelligence The target transaction request node of the contract, where the contract source code is the contract source code of the target smart contract;
- Step 220 Execute the contract source code to the node device, and return the execution result to the node device.
- the transaction includes input parameters
- the receiving the contract source code sent by the node device in the blockchain specifically includes:
- the execution of the contract source code specifically includes:
- the method further includes:
- the result set Upon receiving a verification request for the result set of the contract engine of another trusted third party sent by the node device, the result set is verified; wherein the result set includes the source code generated during the execution of the contract The read-write set and the execution result obtained after executing the contract source code;
- the execution result in the result set is released to all node devices in the blockchain for consensus processing, and after the consensus is passed, the execution result in the result set is stored in all nodes.
- the block chain
- the verification process for the second execution result includes:
- Read input data from the read-write set load the read input data into the contract source code, and simulate execution of the contract source code
- the verification process for the second execution result includes:
- Read input data from the read-write set load the read input data into the contract source code, and simulate execution of the contract source code
- the embodiments shown above provide a block chain smart contract execution scheme, which decouples the smart contract from the block chain node.
- the node device in the block chain no longer stores the smart contract and is not responsible for the operation of the smart contract.
- the contract engine deployed in the trusted third party connected to the blockchain is responsible for running the smart contract; in this way, when the node device in the blockchain that responds to the client initiates a transaction needs to execute related business logic, it can call the trusted third party
- the three-party contract engine the contract engine runs the related smart contract to get the execution result.
- the smart contract is separated and run by the contract engine, which simplifies the function of the node device and reduces the performance requirements of the node device (for example, devices with low performance can also be used as nodes
- the device is connected to the blockchain).
- consensus when consensus is reached between node devices in the blockchain, it is no longer dependent on smart contracts for consensus. Instead, consensus can be achieved by comparing the result set with the world state. It is not necessary for each node device to participate in smart contract operations, which greatly improves Consensus efficiency.
- the trusted third party connected to the blockchain as a node dedicated to running smart contracts, can be pre-set with powerful storage and computing capabilities to deploy a large number of smart contracts, and the business logic of smart contracts can be designed relatively Complex, in order to cope with the business needs of large calculation volume and high business complexity.
- this specification also provides an embodiment of the smart contract execution device of the blockchain.
- the device embodiments can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a logical device, it is formed by reading the corresponding computer business program instructions in the non-volatile memory into the memory through the processor of the device where it is located.
- FIG 4 a hardware structure diagram of the device where the smart contract execution device of the blockchain of this specification is located, except for the processor, network interface, memory, and non-volatile properties shown in Figure 4
- the device where the device is located in the embodiment usually performs actual functions according to the smart contract of the blockchain, and may also include other hardware, which will not be repeated here.
- FIG. 5 is a block diagram of a block chain smart contract execution device provided by an embodiment of this specification.
- the device corresponds to the embodiment shown in FIG. 1, and the block chain is docked with a trusted third party.
- a contract engine for executing smart contracts is deployed in the trusted third party, and the device includes:
- the receiving unit 310, the node device in the blockchain receives the target transaction initiated by the client for invoking the target smart contract;
- the response unit 320 in response to the target transaction, obtains the contract source code of the target smart contract from the distributed database of the blockchain;
- the execution unit 330 sends the contract source code to the trusted third party, so that the contract engine of the trusted third party executes the contract source code, and returns the execution result to the node device.
- the target transaction includes the name of the target smart contract; and, the name of the target function called in the target smart contract;
- the response unit 320 specifically includes:
- the target transaction In response to the target transaction, based on the target smart contract name contained in the target transaction, obtain the contract source code corresponding to the target smart contract name from the distributed database of the blockchain; and, based on the target smart contract The target function name to be called, and the contract source code corresponding to the target function name is obtained from the obtained contract source code.
- the transaction includes input parameters
- the execution unit 330 includes:
- the contract source code and the input parameters are sent to the trusted third party, so that the trusted third party obtains the input data corresponding to the input parameters from the node device, and loads the input data to The contract source code, and execute the contract source code; and return the execution result to the node device.
- another trusted third party as a verifier is connected to the blockchain;
- the device also includes:
- the verification unit sends the execution result to the another trusted third party, so that the contract engine of the other trusted third party will verify the execution result; if the execution result is verified Pass, release the execution result to all node devices in the blockchain for consensus processing, and after the consensus is passed, store the execution result in the blockchain.
- the execution result is a result set generated by the trusted third party based on the execution result of the contract source code; wherein, the result set includes a read-write set generated during the execution of the contract source code and after the execution of the contract source code The execution result obtained;
- the verification process for the execution result includes:
- the contract engine of the other trusted third party reads input data from the read-write set, loads the read input data into the contract source code, and simulates execution of the contract source code;
- the execution result is a result set generated by the trusted third party based on the execution result of the contract source code; wherein, the result set includes a read-write set generated during the execution of the contract source code and after the execution of the contract source code The execution result obtained;
- the verification process for the execution result includes:
- the contract engine of the other trusted third party reads input data from the read-write set, loads the read input data into the contract source code, and simulates execution of the contract source code;
- the blockchain is a consortium chain.
- Figure 6 is a block diagram of a block chain smart contract execution device provided by an embodiment of this specification.
- the device corresponds to the embodiment shown in Figure 3.
- the block chain is connected to a trusted third party, so A contract engine for executing smart contracts is deployed in the trusted third party, and the device includes:
- the receiving unit 410 the contract engine of the trusted third party receives the contract source code sent by the node device in the blockchain; wherein, the node device is a call target initiated in the blockchain in response to the client The target transaction request node of the smart contract, where the contract source code is the contract source code of the target smart contract;
- the execution unit 420 executes the contract source code and returns the execution result to the node device and the node device.
- the transaction includes input parameters
- the receiving unit 410 receives the contract source code sent by the node device in the blockchain, which specifically includes:
- the execution of the contract source code in the execution unit 420 specifically includes:
- the device further includes:
- the verification unit upon receiving a verification request for the result set of the contract engine of another trusted third party sent by the node device, verifies the result set; wherein, the result set includes the execution contract The read-write set generated during the source code process and the execution result obtained after executing the contract source code;
- the consensus unit if the result set is verified, publish the execution result in the result set to all node devices in the blockchain for consensus processing, and after the consensus is passed, collect the execution result of the result set Store to the blockchain.
- the verification process for the second execution result includes:
- Read input data from the read-write set load the read input data into the contract source code, and simulate execution of the contract source code
- the verification process for the second execution result includes:
- Read input data from the read-write set load the read input data into the contract source code, and simulate execution of the contract source code
- the blockchain is a consortium chain.
- a typical implementation device is a computer.
- the specific form of the computer can be a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email receiving and sending device, and a game control A console, a tablet computer, a wearable device, or a combination of any of these devices.
- the relevant part can refer to the part of the description of the method embodiment.
- the device embodiments described above are merely illustrative.
- the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in One place, or it can be distributed to multiple network units.
- Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution in this specification. Those of ordinary skill in the art can understand and implement it without creative work.
- FIG. 1 depicts the internal functional modules and structure of the smart contract execution device of the blockchain.
- the actual execution subject can be an electronic device, including:
- a memory for storing processor executable instructions
- the processor is configured to:
- the node device in the blockchain receives the target transaction initiated by the client for invoking the target smart contract; wherein, the blockchain is docked with a trusted third party, and the trusted third party is deployed with a contract for executing the smart contract engine;
- the contract source code is sent to the trusted third party, so that the contract engine of the trusted third party executes the contract source code and returns the execution result to the node device.
- Figure 6 above depicts the internal functional modules and structure of the blockchain-based logistics price insuring device.
- the actual execution subject can be an electronic device, including:
- a memory for storing processor executable instructions
- the processor is configured to:
- the contract engine of the trusted third party receives the contract source code sent by the node device in the blockchain; wherein, the node device is a target in the blockchain for invoking the target smart contract initiated in response to the client
- the contract source code is the contract source code of the target smart contract
- the blockchain is docked with a trusted third party, and the trusted third party is deployed with a contract engine that executes the smart contract;
- the processor may be a central processing unit (English: Central Processing Unit, abbreviated as: CPU), or other general-purpose processors or digital signal processors (English: Digital Signal Processor). , Abbreviation: DSP), Application Specific Integrated Circuit (English: Application Specific Integrated Circuit, Abbreviation: ASIC), etc.
- the general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc.
- the aforementioned memory can be read-only memory (English: read-only memory, abbreviation: ROM), random access memory (English : Random access memory, referred to as RAM), flash memory, hard disk or solid state hard disk.
- the steps of the method disclosed in the embodiments of the present invention may be directly embodied as being executed and completed by a hardware processor, or executed and completed by a combination of hardware and software modules in the processor.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computer Security & Cryptography (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Business, Economics & Management (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- General Engineering & Computer Science (AREA)
- Accounting & Taxation (AREA)
- Finance (AREA)
- Databases & Information Systems (AREA)
- Development Economics (AREA)
- Computer Hardware Design (AREA)
- Technology Law (AREA)
- Strategic Management (AREA)
- Health & Medical Sciences (AREA)
- Bioethics (AREA)
- General Health & Medical Sciences (AREA)
- General Business, Economics & Management (AREA)
- Software Systems (AREA)
- Marketing (AREA)
- Economics (AREA)
- Computing Systems (AREA)
- Data Mining & Analysis (AREA)
- Management, Administration, Business Operations System, And Electronic Commerce (AREA)
- Financial Or Insurance-Related Operations Such As Payment And Settlement (AREA)
Abstract
一种区块链的智能合约执行方法及装置和电子设备,所述区块链对接有可信第三方,所述可信第三方中部署有执行智能合约的合约引擎,所述方法包括:区块链中的节点设备接收客户端发起的用于调用目标智能合约的目标交易(110);响应于所述目标交易,从所述区块链的分布式数据库中获取所述目标智能合约的合约源码(120);将所述合约源码发送给所述可信第三方,以使所述可信第三方的合约引擎执行所述合约源码,并向所述节点设备返回执行结果(130)。
Description
本说明书实施例涉及区块链技术领域,尤其涉及一种区块链的智能合约执行方法及装置和电子设备。
区块链技术,也被称之为分布式账本技术,是一种由若干台计算设备共同参与“记账”,共同维护一份完整的分布式数据库的新兴技术。由于区块链技术具有去中心化、公开透明、每台计算设备可以参与数据库记录、并且各计算设备之间可以快速的进行数据同步的特性,使得区块链技术在众多的领域中广泛的进行应用。
发明内容
本说明书实施例提供的一种区块链的智能合约执行方法及装置和电子设备:
根据本说明书实施例的第一方面,提供一种区块链的智能合约执行方法,所述区块链对接有可信第三方,所述可信第三方中部署有执行智能合约的合约引擎,所述方法包括:
区块链中的节点设备接收客户端发起的用于调用目标智能合约的目标交易;
响应于所述目标交易,从所述区块链的分布式数据库中获取所述目标智能合约的合约源码;
将所述合约源码发送给所述可信第三方,以使所述可信第三方的合约引擎执行所述合约源码,并向所述节点设备返回执行结果。
可选的,所述目标交易包括所述目标智能合约名称;以及,所述目标智能合约中被调用的目标函数名称;
所述从所述区块链的分布式数据库中获取所述目标智能合约的合约源码,具体包括:
基于所述目标交易包含的目标智能合约名称,从所述区块链的分布式数据库中获取该目标智能合约名称对应的合约源码;
基于所述目标智能合约中被调用的目标函数名称,从所获取的合约源码获取该目标 函数名称对应的合约源码。
可选的,所述交易包含有输入参数;
所述将所述合约源码发送给所述可信第三方,以使所述可信第三方的合约引擎执行所述合约源码,包括:
将所述合约源码以及所述输入参数发送给所述可信第三方,以使所述可信第三方向所述节点设备获取与所述输入参数对应的输入数据,将所述输入数据加载到所述合约源码,并执行所述合约源码。
可选的,所述区块链对接有作为校验方的另一可信第三方;
所述方法还包括:
将所述执行结果发送给所述另一可信第三方,以由所述另一可信第三方的合约引擎,针对所述执行结果进行校验;
如果所述执行结果校验通过,将所述执行结果发布至所述区块链中的所有节点设备进行共识处理,并在共识通过后,将所述执行结果存储至所述区块链。
可选的,所述执行结果为所述可信第三方基于所述合约源码的执行结果生成的结果集;其中,所述结果集包括执行合约源码过程中产生的读写集和执行合约源码后得到的执行结果;
针对所述执行结果的校验过程,包括:
所述另一可信第三方的合约引擎从所述读写集中读取输入数据,将读取到的输入数据加载到所述合约源码,并模拟执行所述合约源码;
确定模拟执行所述合约源码产生的执行结果,与所述结果集中的执行结果是否一致;
如果是,确定所述执行结果校验通过。
可选的,所述执行结果为所述可信第三方基于所述合约源码的执行结果生成的结果集;其中,所述结果集包括执行合约源码过程中产生的读写集和执行合约源码后得到的执行结果;
针对所述执行结果的校验过程,包括:
所述另一可信第三方的合约引擎从所述读写集中读取输入数据,将读取到的输入数据加载到所述合约源码,并模拟执行所述合约源码;
确定模拟执行所述合约源码产生的读写集,与所述结果集中的读写集是否一致;
如果是,确定所述执行结果校验通过。
可选的,所述区块链为联盟链。
根据本说明书实施例的第二方面,提供一种区块链的智能合约执行方法,所述区块链对接有可信第三方,所述可信第三方中部署有执行智能合约的合约引擎,所述方法包括:
所述可信第三方的合约引擎接收所述区块链中的节点设备发送的合约源码;其中,所述节点设备为所述区块链中响应客户端发起的用于调用目标智能合约的目标交易请求的节点,所述合约源码为所述目标智能合约的合约源码;
执行所述合约源码并向所述节点设备,并向所述节点设备返回执行结果。
可选的,所述交易包含有输入参数;
所述接收所述区块链中的节点设备发送的合约源码,具体包括:
接收所述区块链中的节点设备发送的合约源码以及所述输入参数;
所述执行所述合约源码,具体包括:
向所述节点设备获取与所述输入参数对应的输入数据,将所述输入数据加载到所述合约源码,并执行所述合约源码。
可选的,所述方法还包括:
在接收到所述节点设备发送的针对其它可信第三方的合约引擎的结果集进行的校验请求时,对所述结果集进行校验;其中,所述结果集包括执行合约源码过程中产生的读写集和执行合约源码后得到的执行结果;
如果所述结果集校验通过,将所述结果集中的执行结果发布至所述区块链中的所有节点设备进行共识处理,并在共识通过后,将所述结果集中的执行结果存储至所述区块链。
可选的,针对所述第二执行结果的校验过程,包括:
从所述读写集中读取输入数据,将读取到的输入数据加载到所述合约源码,并模拟执行所述合约源码;
确定模拟执行所述合约源码产生的执行结果,与所述结果集中的执行结果是否一致;
如果是,确定所述执行结果校验通过。
可选的,针对所述第二执行结果的校验过程,包括:
从所述读写集中读取输入数据,将读取到的输入数据加载到所述合约源码,并模拟执行所述合约源码;
确定模拟执行所述合约源码产生的读写集,与所述结果集中的读写集是否一致;
如果是,确定所述执行结果校验通过。
可选的,所述区块链为联盟链。
根据本说明书实施例的第三方面,提供一种区块链的智能合约执行装置,所述区块链对接有可信第三方,所述可信第三方中部署有执行智能合约的合约引擎,所述装置包括:
接收单元,区块链中的节点设备接收客户端发起的用于调用目标智能合约的目标交易;
响应单元,响应于所述目标交易,从所述区块链的分布式数据库中获取所述目标智能合约的合约源码;
执行单元,将所述合约源码发送给所述可信第三方,以使所述可信第三方的合约引擎执行所述合约源码,并向所述节点设备返回执行结果。
根据本说明书实施例的第四方面,提供一种区块链的智能合约执行装置,所述区块链对接有可信第三方,所述可信第三方中部署有执行智能合约的合约引擎,所述方法包括:
接收单元,所述可信第三方的合约引擎接收所述区块链中的节点设备发送的合约源码;其中,所述节点设备为所述区块链中响应客户端发起的用于调用目标智能合约的目标交易请求的节点,所述合约源码为所述目标智能合约的合约源码;
执行单元,执行所述合约源码并向所述节点设备,并向所述节点设备返回执行结果。
根据本说明书实施例的第五方面,提供一种电子设备,包括:
处理器;
用于存储处理器可执行指令的存储器;
其中,所述处理器被配置为上述任一项区块链的智能合约执行方法。
本说明书实施例,提供了一种区块链的智能合约执行方案,将智能合约与区块链节点解耦合,区块链中节点设备不再存储智能合约也不负责智能合约的运行,而是由区块链对接的可信第三方中部署的合约引擎负责运行智能合约;如此,当区块链中响应客户端发起交易的节点设备需要执行相关业务逻辑时,可以通过调用可信第三方的合约引擎,由合约引擎运行相关的智能合约从而得到执行结果。一方面,通过将智能合约与节点设备解绑,从而将智能合约分离出来由合约引擎运行,简化了节点设备功能从而降低了对节点设备性能的要求(比如,性能不高的设备也可以作为节点设备接入区块链)。另一方面,区块链中节点设备间进行共识时,不再依赖智能合约进行共识,而是将结果集同世界状态比较就可以实现共识,无需每个节点设备参与智能合约运算,大大提升了共识效率。再一方面,区块链对接的可信第三方作为专用于运行智能合约的节点,可以预先设置强大的存储和计算能力,以此部署大量的智能合约,并且智能合约的业务逻辑可以设计的较为复杂,以应对计算量较大、业务复杂度较高的业务需求。
图1是本说明书一实施例提供的区块链的智能合约执行方法的流程图;
图2是本说明书一实施例提供的区块链系统的架构示意图;
图3是本说明书一实施例提供的区块链的智能合约执行方法的流程图;
图4是本说明书一实施例提供的区块链的智能合约执行装置的硬件结构图;
图5是本说明书一实施例提供的区块链的智能合约执行装置的模块示意图;
图6是本说明书一实施例提供的区块链的智能合约执行装置的模块示意图。
这里将详细地对示例性实施例进行说明,其示例表示在附图中。下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的要素。以下示例性实施例中所描述的实施方式并不代表与本说明书相一致的所有实施方式。相反,它们仅是与如所附权利要求书中所详述的、本说明书的一些方面相一致的装置和方法的例子。
在本说明书使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本说明书。在本说明书和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包括多数形式,除非上下文清楚地表示其他含义。还应当理解,本文中使用的术语“和 /或”是指并包含一个或多个相关联的列出项目的任何或所有可能组合。
应当理解,尽管在本说明书可能采用术语第一、第二、第三等来描述各种信息,但这些信息不应限于这些术语。这些术语仅用来将同一类型的信息彼此区分开。例如,在不脱离本说明书范围的情况下,第一信息也可以被称为第二信息,类似地,第二信息也可以被称为第一信息。取决于语境,如在此所使用的词语“如果”可以被解释成为“在……时”或“当……时”或“响应于确定”。
智能合约(Smart contract)是一种旨在应用在可以部署在区块链上的以信息化方式传播、验证或执行合同的计算机协议。通过在智能合约中声明业务逻辑可以实现执行相应操作。智能合约允许在没有第三方的情况下进行可信交易。这些交易可追踪且不可逆转。智能合约能够提供优于传统合同方法的安全,并减少与合同相关的其他交易成本。
首先,介绍传统区块链中智能合约的部署方式。传统智能合约是直接部署在区块链中节点设备上,并在节点设备执行交易请求时,直接运行本地部署的相应智能合约。对于需要行共识的情况,同样将执行结果抛出由区块链中所有节点设备进行共识,每个节点设备都需要运行本地部署的用于共识的智能合约。可见,一方面,传统智能合约与节点设备之间是强耦合的,每个节点设备都需要部署智能合约并需要运行智能合约,对于节点设备来说无疑增加了许多负担(节点设备需要具备一定的计算能力);另一方面,在节点设备间共识时,每个节点设备均需要重新执行一次智能合约判断执行结果是否正确,导致共识效率不高;再一方面,由于节点设备存储、计算能力有限,相应就限制了智能合约的数量以及复杂程度,传统智能合约无法执行计算量、复杂度较大的业务逻辑。
本说明书提出了一种区块链的智能合约执行方案,通过对传统智能合约进行优化,可以提升包括区块链中节点设备的性能和效率,节点设备间进行共识的效率,以及智能合约执行的效率等,从而提升区块链整体性能。
在本说明实现方式中,将智能合约与区块链节点解耦合,区块链中节点设备不再存储智能合约也不负责智能合约的运行,而是由区块链对接的可信第三方中部署的合约引擎负责运行智能合约;如此,当区块链中响应客户端发起交易的节点设备需要执行相关业务逻辑时,可以通过调用可信第三方的合约引擎,由合约引擎运行相关的智能合约从而得到执行结果。一方面,通过将智能合约与节点设备解绑,从而将智能合约分离出来由合约引擎运行,简化了节点设备功能从而降低了对节点设备性能的要求(比如,性能不高的设备也可以作为节点设备接入区块链)。另一方面,区块链中节点设备间进行共识时,不再依赖智能合约进行共识,而是将结果集同世界状态比较就可以实现共识,无 需每个节点设备参与智能合约运算,大大提升了共识效率。再一方面,区块链对接的可信第三方作为专用于运行智能合约的节点,可以预先设置强大的存储和计算能力,以此部署大量的智能合约,并且智能合约的业务逻辑可以设计的较为复杂,以应对计算量较大、业务复杂度较高的业务需求。
在本说明书所描述的区块链,具体可以包括私有链、共有链以及联盟链等,在本说明书中不进行特别限定。
例如,在一个场景中,上述区块链具体可以是由总部机构、分支机构、代理机构、节点设备等作为联盟成员组成的一个联盟链;该联盟链的运营方可以依托于该联盟链,来部署相应的业务;而以上所描述的作为联盟成员的总部机构、分支机构、代理机构都可以作为上述业务的一个业务节点。各个业务节点可以将自身所产生或者接收到的与执行结果以交易的形式在联盟链中进行发布,并在该交易经过联盟链中的共识节点的共识处理之后,在联盟链中的分布式数据库进行存储,完成上述交易信息的“上链”存证。
其中,需要说明的是,在本说明书中所描述的交易(Transaction),是指通过区块链的客户端创建,并需要最终发布至区块链的分布式数据库中的一笔数据。
区块链中的交易,通常存在狭义的交易以及广义的交易之分。狭义的交易是指用户向区块链发布的一笔价值转移;例如,在传统的比特币区块链网络中,交易可以是用户在区块链中发起的一笔转账。而广义的交易是指用户向区块链发布的一笔具有业务意图的业务数据;例如,运营方可以基于实际的业务需求搭建一个联盟链,依托于联盟链部署一些与价值转移无关的其它类型的在线业务(比如,宽泛的可以分为查询业务、调用业务等),而在这类联盟链中,交易可以是用户在联盟链中发布的一笔具有业务意图的业务消息或者业务请求。
上述客户端,可以包括任意类型的以区块链中存储的底层业务数据作为数据支撑,来实现特定的业务功能的上层应用。
请参考图1,图1为本说明书一实施例提供的区块链的智能合约执行方法的流程图,所述区块链对接有可信第三方,所述可信第三方中部署有执行智能合约的合约引擎,所述方法可以包括以下步骤:
步骤110:区块链中的节点设备接收客户端发起的用于调用目标智能合约的目标交易;
步骤120:响应于所述目标交易,从所述区块链的分布式数据库中获取所述目标智 能合约的合约源码;
步骤130:将所述合约源码发送给所述可信第三方,以使所述可信第三方的合约引擎执行所述合约源码,并向所述节点设备返回执行结果。
以下结合图2所示的区块链系统的示意图为例加以说明:
客户端向区块链发起一笔目标交易,经由SDK调用智能合约函数,SDK将该目标交易发送到区块链的一个节点设备上,该节点设备可以称为调用节点;所述目标交易可以携带有相关的执行参数,例如可以包括合约名称、调用函数名、输入参数、交易ID、时间戳等。
如前所述,本说明书中节点设备不负责智能合约运行;因此,调用节点在接收到客户端发起的目标交易后,需要调用可信第三方的合约引擎来执行相应智能合约的业务逻辑。
其中,该调用节点首先需要获取供合约引擎执行相应智能合约的合约源码:
在一实施例中,所述目标交易包括所述目标智能合约名称;以及,所述目标智能合约中被调用的目标函数名称;
所述从所述区块链的分布式数据库中获取所述目标智能合约的合约源码,具体包括:
基于所述目标交易包含的目标智能合约名称,从所述区块链的分布式数据库中获取该目标智能合约名称对应的合约源码;
基于所述目标智能合约中被调用的目标函数名称,从所获取的合约源码获取该目标函数名称对应的合约源码。
也就是说,基于所述目标智能合约名称和目标调用函数名称,节点设备就可以从所述区块链的分布式数据库中获取所述目标智能合约所需的合约源码。
其中,所述合约源码是由一个个函数构成的,每个函数具有一定的逻辑功能,可以在合约引擎中执行相应逻辑;通过目标调用函数名称可以确定相应的函数,以保证确定合约源码包含的函数与目标调用函数一致。
该实施例中,对于可信第三方的合约引擎来说,为了避免合约引擎作恶,智能合约的合约源码是存放在区块链的分布式数据库中的;当需要使用智能合约时,调用节点首先从分布式数据库中获取相应的合约源码,然后再将合约源码发送给可信第三方的合约引擎;如此,每次合约引擎执行的智能合约都是临时由调用节点提供的。
在一实施例中,所述目标交易还包含有输入参数;
所述将所述合约源码发送给所述可信第三方,以使所述可信第三方的合约引擎执行所述合约源码,包括:
将所述合约源码以及所述输入参数发送给所述可信第三方,以使所述可信第三方向所述节点设备获取与所述输入参数对应的输入数据,将所述输入数据加载到所述合约源码,并执行所述合约源码。
在实际应用中,有的业务类型可以不需要传输数据,则节点设备无需传输输入参数(或者,输入参数可以为空),合约引擎也无需向节点设备获取输入数据。
对于有些复杂业务,需要用到输入数据,则需要用户在发起交易时提交输入参数。
如图2所示,节点设备在调用合约引擎时,需要提供了合约源码和输入参数。此时,合约引擎可以根据该输入参数从节点设备处获取输入数据。其中,所述输入参数可以是由客户端(即用户)提供的,所述输入数据可以是执行智能合约所需的其它数据。
以下举例说明输入参数和输入数据的区别:
假设客户端发送的交易请求是,令a+1。则字段a和加1即为输入参数,而a当前的值即为输入数据。在实际运算a+1时,首先需要获取a的原始值(输入数据),然后在原始值基础上加1才能得到执行结果。
由于区块链具有不可篡改的特性,以及节点设备存储有全量账本(即数据),因此合约引擎可以向节点设备获取该节点设备本地存储的输入参数相关的输入数据。
合约引擎可以注入合约源码,在获取到输入数据后,将所述输入数据加载到所述合约源码,并执行所述合约源码得到执行结果。
需要说明的是,合约引擎在执行合约源码过程中还会产生读写集。所述读写集可以包括执行合约源码时需要的输入数据,和输入数据对应的输出数据。对于复杂的合约源码,输入数据和输出数据可以包含多组,即读写集是合约源码执行过程中所需的所有输入数据和对应的输出数据,构成的数据集合,可以真实反映合约源码的整个执行计算过程。请参考后续表1或表2所示的示例。
在一实施例中,所述执行结果为所述可信第三方基于所述合约源码的执行结果生成的结果集;其中,所述结果集包括执行合约源码过程中产生的读写集和执行合约源码后得到的执行结果。
其中,合约引擎可以将输入参数、合约源码(或者合约源码hash)、读写集和执行结果打包为结果集,并为所述结果集添加本合约引擎的签名;将所述签名后的结果集作为执行结果返回给所述节点设备。
相应地,节点设备接收所述合约引擎返回的结果集;其中,所述结果集为所述合约引擎将所述输入参数、合约源码(或者合约源码hash)、读写集和执行结果打包后添加本合约引擎的签名的集合。
该实施例中,合约引擎需要为结果集添加签名,以保证智能合约执行的有效性。对于没有签名的结果集,节点设备是不予确认的,视为无效。
值得一提的是,合约源码hash是指基于合约源码得到的hash值;所述合约源码hash可以用于校验合约引擎调用的合约源码是否存在篡改。举例说明,假设节点设备提供的合约源码为A,正确的hash为(A)hash;那么节点设备或者其他节点只需要将目标智能合约的合约源码的hash值与结果集中合约源码hash值比对,就可以判断合约引擎是否篡改了合约源码。假设合约引擎擅自篡改了合约源码,假设篡改后的合约源码为A+1;那么返回的合约源码hash就变为(A+1)hash,显然与原始合约源码的(A)hash不一致。
在一实施例中,所述区块链对接有作为校验方的另一可信第三方;
所述方法还包括:
将所述执行结果发送给所述另一可信第三方,以由所述另一可信第三方的合约引擎,针对所述执行结果进行校验;
如果所述执行结果校验通过,将所述执行结果发布至所述区块链中的所有节点设备进行共识处理,并在共识通过后,将所述执行结果存储至所述区块链。
为了便于区分,以下将另一可信第三方的合约引擎简称为第二合约引擎,并将前述运行智能合约的合约引擎简称为第一合约引擎。
如图2所示,节点设备可以通过第二合约引擎对第一合约引擎的执行结果进行检验。
在一实施例中,针对所述执行结果的校验过程,包括:
所述第二合约引擎从所述读写集中读取输入数据,将读取到的输入数据加载到所述合约源码,并模拟执行所述合约源码;
确定模拟执行所述合约源码产生的执行结果,与所述结果集中的执行结果是否一致;
如果是,确定所述执行结果校验通过。
还可以为第一合约引擎的结果集添加该第二合约引擎的签名。
在一实施例中,针对所述执行结果的校验过程,包括:
针对所述执行结果的校验过程,包括:
所述另一可信第三方的合约引擎从所述读写集中读取输入数据,将读取到的输入数据加载到所述合约源码,并模拟执行所述合约源码;
确定模拟执行所述合约源码产生的读写集,与所述结果集中的读写集是否一致;
如果是,确定所述执行结果校验通过。
还可以为第一合约引擎的结果集添加该第二合约引擎的签名。
举例说明,针对a+2,a+2;相应地读写集如下表1所示:
| 读 | 写 |
| a=0 | a=2 |
| a=2 | a=4 |
上述表1的含义,首先计算a+2;产生第一次的读数据a=0,运行a+1后,产生第一次的写数据a=2;然后计算a+2;产生第二次的读数据a=2,运行a+2,产生第二次的写数据a=4。
如果第一合约引擎作恶篡改了计算过程,将a+2,a+2;篡改为a+1,a+3;那么读写集如下表2所示:
| 读 | 写 |
| a=0 | a=1 |
| a=1 | a=4 |
假设表2为第一合约引擎返回的结果集中的读写集,表1为第二合约引擎模拟合约源码运行后得到的读写集;比对表1和表2就可以确定表1存在问题,说明第一合约引擎存在篡改。
而如果仅通过比对执行结果,则表1和表2的执行结果均为4,容易造成误判。
通过第二合约引擎判断第一合约引擎返回的读写集是否真实有效,如前所述读写集包括一系列的输入和输出,从读写集中读取输入数据模拟执行得到输出数据后,逐个确认得到的输出数据是否跟读写集一致(即整个过程各个环节的运算算结果都符合预期);如果全部一致,证明读写集有效,没有被人篡改,此时才会进一步将最终的执行结果,与结果集中的结果进行匹配。如此校验过程可以避免第一合约引擎作弊。
以下介绍本说明书中节点设备间共识的机制:
如前所述如果所述执行结果校验通过,节点设备需要将所述执行结果发布至所述区块链中的所有节点设备进行共识处理,并在共识通过后,将所述执行结果存储至所述区块链。
这里的共识过程,可以为:
首先将执行结果在本地的状态数据库保存(更新自己的世界状态)。在对智能合约的执行结果进行共识时,可以将收到的其它节点设备发送的执行结果与本地的状态数据库中的执行结果进行比较,来对执行结果进行共识。
如果所有节点设备返回的执行结果,或者大多数节点设备返回的执行结果,与自己的世界状态中的执行结果一致,则共识通过。
在一可选的实施例中,除了保存执行结果还可以保存读写集:
首先将返回的读写集在本地的状态数据库保存(更新自己的世界状态)。在对智能合约的执行结果进行共识时,可以将收到的其它节点设备发送的读写集与本地的状态数据库中的读写集进行比较,来对执行结果进行共识。
如果所有节点设备返回的读写集,或者大多数节点设备返回的读写集,与自己的世界状态中的读写集一致,则共识通过。
该实施例,在区块链中节点设备间进行共识时,不再需要重新执行智能合约,对智能合约的执行结果进行共识校验,而是直接将结果集同世界状态进行比较就可以完成对智能合约的执行结果的共识;因此可以大大提升共识效率。
请参考图3,图3为本说明书一实施例提供的区块链的智能合约执行方法的流程图,所述区块链对接有可信第三方,所述可信第三方中部署有执行智能合约的合约引擎,所述方法可以应用于合约引擎,所述方法可以包括以下步骤:
步骤210:所述可信第三方的合约引擎接收所述区块链中的节点设备发送的合约源码;其中,所述节点设备为所述区块链中响应客户端发起的用于调用目标智能合约的目标交易请求的节点,所述合约源码为所述目标智能合约的合约源码;
步骤220:执行所述合约源码并向所述节点设备,并向所述节点设备返回执行结果。
该实施例是以合约引擎为执行主体进行描述的,相关的节点设备可以参考前述图1所示实施例,在该实施例不再进行赘述。
在一实施例中,所述交易包含有输入参数;
所述接收所述区块链中的节点设备发送的合约源码,具体包括:
接收所述区块链中的节点设备发送的合约源码以及所述输入参数;
所述执行所述合约源码,具体包括:
向所述节点设备获取与所述输入参数对应的输入数据,将所述输入数据加载到所述合约源码,并执行所述合约源码。
在一实施例中,所述方法还包括:
在接收到所述节点设备发送的针对其它可信第三方的合约引擎的结果集进行的校验请求时,对所述结果集进行校验;其中,所述结果集包括执行合约源码过程中产生的读写集和执行合约源码后得到的执行结果;
如果所述结果集校验通过,将所述结果集中的执行结果发布至所述区块链中的所有节点设备进行共识处理,并在共识通过后,将所述结果集中的执行结果存储至所述区块链。
在一实施例中,针对所述第二执行结果的校验过程,包括:
从所述读写集中读取输入数据,将读取到的输入数据加载到所述合约源码,并模拟执行所述合约源码;
确定模拟执行所述合约源码产生的执行结果,与所述结果集中的执行结果是否一致;
如果是,确定所述执行结果校验通过。
在一实施例中,针对所述第二执行结果的校验过程,包括:
从所述读写集中读取输入数据,将读取到的输入数据加载到所述合约源码,并模拟执行所述合约源码;
确定模拟执行所述合约源码产生的读写集,与所述结果集中的读写集是否一致;
如果是,确定所述执行结果校验通过。
综上所示实施例,提供了一种区块链的智能合约执行方案,将智能合约与区块链节点解耦合,区块链中节点设备不再存储智能合约也不负责智能合约的运行,而是由区块链对接的可信第三方中部署的合约引擎负责运行智能合约;如此,当区块链中响应客户端发起交易的节点设备需要执行相关业务逻辑时,可以通过调用可信第三方的合约引擎,由合约引擎运行相关的智能合约从而得到执行结果。一方面,通过将智能合约与节点设备解绑,从而将智能合约分离出来由合约引擎运行,简化了节点设备功能从而降低了对节点设备性能的要求(比如,性能不高的设备也可以作为节点设备接入区块链)。另一方面,区块链中节点设备间进行共识时,不再依赖智能合约进行共识,而是将结果集同世界状态比较就可以实现共识,无需每个节点设备参与智能合约运算,大大提升了共识效率。再一方面,区块链对接的可信第三方作为专用于运行智能合约的节点,可以预先设置强大的存储和计算能力,以此部署大量的智能合约,并且智能合约的业务逻辑可以设计的较为复杂,以应对计算量较大、业务复杂度较高的业务需求。
与前述区块链的智能合约执行方法实施例相对应,本说明书还提供了区块链的智能合约执行装置的实施例。所述装置实施例可以通过软件实现,也可以通过硬件或者软硬件结合的方式实现。以软件实现为例,作为一个逻辑意义上的装置,是通过其所在设备的处理器将非易失性存储器中对应的计算机业务程序指令读取到内存中运行形成的。从硬件层面而言,如图4所示,为本说明书区块链的智能合约执行装置所在设备的一种硬件结构图,除了图4所示的处理器、网络接口、内存以及非易失性存储器之外,实施例中装置所在的设备通常根据区块链的智能合约执行实际功能,还可以包括其他硬件,对此不再赘述。
请参见图5,为本说明书一实施例提供的区块链的智能合约执行装置的模块图,所述装置对应了图1所示实施例,所述区块链对接有可信第三方,所述可信第三方中部署有执行智能合约的合约引擎,所述装置包括:
接收单元310,区块链中的节点设备接收客户端发起的用于调用目标智能合约的目标交易;
响应单元320,响应于所述目标交易,从所述区块链的分布式数据库中获取所述目标智能合约的合约源码;
执行单元330,将所述合约源码发送给所述可信第三方,以使所述可信第三方的合约引擎执行所述合约源码,并向所述节点设备返回执行结果。
可选的,所述目标交易包括所述目标智能合约名称;以及,所述目标智能合约中被调用的目标函数名称;
所述响应单元320,具体包括:
响应于所述目标交易,基于所述目标交易包含的目标智能合约名称,从所述区块链的分布式数据库中获取该目标智能合约名称对应的合约源码;并,基于所述目标智能合约中被调用的目标函数名称,从所获取的合约源码获取该目标函数名称对应的合约源码。
可选的,所述交易包含有输入参数;
所述执行单元330,包括:
将所述合约源码以及所述输入参数发送给所述可信第三方,以使所述可信第三方向所述节点设备获取与所述输入参数对应的输入数据,将所述输入数据加载到所述合约源码,并执行所述合约源码;以及向所述节点设备返回执行结果。
可选的,所述区块链对接有作为校验方的另一可信第三方;
所述装置还包括:
校验单元,将所述执行结果发送给所述另一可信第三方,以由所述另一可信第三方的合约引擎,针对所述执行结果进行校验;如果所述执行结果校验通过,将所述执行结果发布至所述区块链中的所有节点设备进行共识处理,并在共识通过后,将所述执行结果存储至所述区块链。
可选的,所述执行结果为所述可信第三方基于所述合约源码的执行结果生成的结果集;其中,所述结果集包括执行合约源码过程中产生的读写集和执行合约源码后得到的执行结果;
针对所述执行结果的校验过程,包括:
所述另一可信第三方的合约引擎从所述读写集中读取输入数据,将读取到的输入数据加载到所述合约源码,并模拟执行所述合约源码;
确定模拟执行所述合约源码产生的执行结果,与所述结果集中的执行结果是否一致;
如果是,确定所述执行结果校验通过。
可选的,所述执行结果为所述可信第三方基于所述合约源码的执行结果生成的结果集;其中,所述结果集包括执行合约源码过程中产生的读写集和执行合约源码后得到的执行结果;
针对所述执行结果的校验过程,包括:
所述另一可信第三方的合约引擎从所述读写集中读取输入数据,将读取到的输入数据加载到所述合约源码,并模拟执行所述合约源码;
确定模拟执行所述合约源码产生的读写集,与所述结果集中的读写集是否一致;
如果是,确定所述执行结果校验通过。
可选的,所述区块链为联盟链。
请参见图6,为本说明书一实施例提供的区块链的智能合约执行装置的模块图,所述装置对应了图3所示实施例,所述区块链对接有可信第三方,所述可信第三方中部署有执行智能合约的合约引擎,所述装置包括:
接收单元410,所述可信第三方的合约引擎接收所述区块链中的节点设备发送的合约源码;其中,所述节点设备为所述区块链中响应客户端发起的用于调用目标智能合约的目标交易请求的节点,所述合约源码为所述目标智能合约的合约源码;
执行单元420,执行所述合约源码并向所述节点设备,并向所述节点设备返回执行结果。
可选的,所述交易包含有输入参数;
所述接收单元410中接收所述区块链中的节点设备发送的合约源码,具体包括:
接收所述区块链中的节点设备发送的合约源码以及所述输入参数;
所述执行单元420中执行所述合约源码,具体包括:
向所述节点设备获取与所述输入参数对应的输入数据,将所述输入数据加载到所述合约源码,并执行所述合约源码。
可选的,所述装置还包括:
校验单元,在接收到所述节点设备发送的针对其它可信第三方的合约引擎的结果集进行的校验请求时,对所述结果集进行校验;其中,所述结果集包括执行合约源码过程中产生的读写集和执行合约源码后得到的执行结果;
共识单元,如果所述结果集校验通过,将所述结果集中的执行结果发布至所述区块链中的所有节点设备进行共识处理,并在共识通过后,将所述结果集中的执行结果存储至所述区块链。
可选的,针对所述第二执行结果的校验过程,包括:
从所述读写集中读取输入数据,将读取到的输入数据加载到所述合约源码,并模拟执行所述合约源码;
确定模拟执行所述合约源码产生的执行结果,与所述结果集中的执行结果是否一致;
如果是,确定所述执行结果校验通过。
可选的,针对所述第二执行结果的校验过程,包括:
从所述读写集中读取输入数据,将读取到的输入数据加载到所述合约源码,并模拟执行所述合约源码;
确定模拟执行所述合约源码产生的读写集,与所述结果集中的读写集是否一致;
如果是,确定所述执行结果校验通过。
可选的,所述区块链为联盟链。
上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机,计算机的具体形式可以是个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件收发设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任意几种设备的组合。
上述装置中各个单元的功能和作用的实现过程具体详见上述方法中对应步骤的实现过程,在此不再赘述。
对于装置实施例而言,由于其基本对应于方法实施例,所以相关之处参见方法实施例的部分说明即可。以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者 也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本说明书方案的目的。本领域普通技术人员在不付出创造性劳动的情况下,即可以理解并实施。
以上图5描述了区块链的智能合约执行装置的内部功能模块和结构示意,其实质上的执行主体可以为一种电子设备,包括:
处理器;
用于存储处理器可执行指令的存储器;
其中,所述处理器被配置为:
区块链中的节点设备接收客户端发起的用于调用目标智能合约的目标交易;其中,所述区块链对接有可信第三方,所述可信第三方中部署有执行智能合约的合约引擎;
响应于所述目标交易,从所述区块链的分布式数据库中获取所述目标智能合约的合约源码;
将所述合约源码发送给所述可信第三方,以使所述可信第三方的合约引擎执行所述合约源码,并向所述节点设备返回执行结果。
以上图6描述了基于区块链的物流保价装置的内部功能模块和结构示意,其实质上的执行主体可以为一种电子设备,包括:
处理器;
用于存储处理器可执行指令的存储器;
其中,所述处理器被配置为:
所述可信第三方的合约引擎接收所述区块链中的节点设备发送的合约源码;其中,所述节点设备为所述区块链中响应客户端发起的用于调用目标智能合约的目标交易请求的节点,所述合约源码为所述目标智能合约的合约源码;所述区块链对接有可信第三方,所述可信第三方中部署有执行智能合约的合约引擎;
执行所述合约源码并向所述节点设备,并向所述节点设备返回执行结果。
在上述电子设备的实施例中,应理解,该处理器可以是中央处理单元(英文:Central Processing Unit,简称:CPU),还可以是其他通用处理器、数字信号处理器(英文:Digital Signal Processor,简称:DSP)、专用集成电路(英文:Application Specific Integrated Circuit,简称:ASIC)等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等,而前述的存储器可以是只读存储器(英文:read-only memory,缩写:ROM)、随机存取存储器(英文:random access memory,简称:RAM)、快闪存储器、硬盘或者固态硬盘。结合本发明实施例所公开的方法的步骤可以直接体现为硬件处理器执行完成,或者用处理器中的硬件及软件模块组合执行完成。
本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于电子设备实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。
本领域技术人员在考虑说明书及实践这里公开的发明后,将容易想到本说明书的其它实施方案。本说明书旨在涵盖本说明书的任何变型、用途或者适应性变化,这些变型、用途或者适应性变化遵循本说明书的一般性原理并包括本说明书未公开的本技术领域中的公知常识或惯用技术手段。说明书和实施例仅被视为示例性的,本说明书的真正范围和精神由下面的权利要求指出。
应当理解的是,本说明书并不局限于上面已经描述并在附图中示出的精确结构,并且可以在不脱离其范围进行各种修改和改变。本说明书的范围仅由所附的权利要求来限制。
Claims (16)
- 一种区块链的智能合约执行方法,所述区块链对接有可信第三方,所述可信第三方中部署有执行智能合约的合约引擎,所述方法包括:区块链中的节点设备接收客户端发起的用于调用目标智能合约的目标交易;响应于所述目标交易,从所述区块链的分布式数据库中获取所述目标智能合约的合约源码;将所述合约源码发送给所述可信第三方,以使所述可信第三方的合约引擎执行所述合约源码,并向所述节点设备返回执行结果。
- 根据权利要求1所述的方法,所述目标交易包括所述目标智能合约名称;以及,所述目标智能合约中被调用的目标函数名称;所述从所述区块链的分布式数据库中获取所述目标智能合约的合约源码,具体包括:基于所述目标交易包含的目标智能合约名称,从所述区块链的分布式数据库中获取该目标智能合约名称对应的合约源码;基于所述目标智能合约中被调用的目标函数名称,从所获取的合约源码获取该目标函数名称对应的合约源码。
- 根据权利要求1所述的方法,所述交易包含有输入参数;所述将所述合约源码发送给所述可信第三方,以使所述可信第三方的合约引擎执行所述合约源码,包括:将所述合约源码以及所述输入参数发送给所述可信第三方,以使所述可信第三方向所述节点设备获取与所述输入参数对应的输入数据,将所述输入数据加载到所述合约源码,并执行所述合约源码。
- 根据权利要求3所述的方法,所述区块链对接有作为校验方的另一可信第三方;所述方法还包括:将所述执行结果发送给所述另一可信第三方,以由所述另一可信第三方的合约引擎,针对所述执行结果进行校验;如果所述执行结果校验通过,将所述执行结果发布至所述区块链中的所有节点设备进行共识处理,并在共识通过后,将所述执行结果存储至所述区块链。
- 根据权利要求4所述的方法,所述执行结果为所述可信第三方基于所述合约源码的执行结果生成的结果集;其中,所述结果集包括执行合约源码过程中产生的读写集和执行合约源码后得到的执行结果;针对所述执行结果的校验过程,包括:所述另一可信第三方的合约引擎从所述读写集中读取输入数据,将读取到的输入数据加载到所述合约源码,并模拟执行所述合约源码;确定模拟执行所述合约源码产生的执行结果,与所述结果集中的执行结果是否一致;如果是,确定所述执行结果校验通过。
- 根据权利要求4所述的方法,所述执行结果为所述可信第三方基于所述合约源码的执行结果生成的结果集;其中,所述结果集包括执行合约源码过程中产生的读写集和执行合约源码后得到的执行结果;针对所述执行结果的校验过程,包括:所述另一可信第三方的合约引擎从所述读写集中读取输入数据,将读取到的输入数据加载到所述合约源码,并模拟执行所述合约源码;确定模拟执行所述合约源码产生的读写集,与所述结果集中的读写集是否一致;如果是,确定所述执行结果校验通过。
- 根据权利要求1所述的方法,所述区块链为联盟链。
- 一种区块链的智能合约执行方法,所述区块链对接有可信第三方,所述可信第三方中部署有执行智能合约的合约引擎,所述方法包括:所述可信第三方的合约引擎接收所述区块链中的节点设备发送的合约源码;其中,所述节点设备为所述区块链中响应客户端发起的用于调用目标智能合约的目标交易请求的节点,所述合约源码为所述目标智能合约的合约源码;执行所述合约源码并向所述节点设备,并向所述节点设备返回执行结果。
- 根据权利要求8所述的方法,所述交易包含有输入参数;所述接收所述区块链中的节点设备发送的合约源码,具体包括:接收所述区块链中的节点设备发送的合约源码以及所述输入参数;所述执行所述合约源码,具体包括:向所述节点设备获取与所述输入参数对应的输入数据,将所述输入数据加载到所述合约源码,并执行所述合约源码。
- 根据权利要求8所述的方法,所述方法还包括:在接收到所述节点设备发送的针对其它可信第三方的合约引擎的结果集进行的校验请求时,对所述结果集进行校验;其中,所述结果集包括执行合约源码过程中产生的读写集和执行合约源码后得到的执行结果;如果所述结果集校验通过,将所述结果集中的执行结果发布至所述区块链中的所有节点设备进行共识处理,并在共识通过后,将所述结果集中的执行结果存储至所述区块 链。
- 根据权利要求10所述的方法,针对所述第二执行结果的校验过程,包括:从所述读写集中读取输入数据,将读取到的输入数据加载到所述合约源码,并模拟执行所述合约源码;确定模拟执行所述合约源码产生的执行结果,与所述结果集中的执行结果是否一致;如果是,确定所述执行结果校验通过。
- 根据权利要求10所述的方法,针对所述第二执行结果的校验过程,包括:从所述读写集中读取输入数据,将读取到的输入数据加载到所述合约源码,并模拟执行所述合约源码;确定模拟执行所述合约源码产生的读写集,与所述结果集中的读写集是否一致;如果是,确定所述执行结果校验通过。
- 根据权利要求8所述的方法,所述区块链为联盟链。
- 一种区块链的智能合约执行装置,所述区块链对接有可信第三方,所述可信第三方中部署有执行智能合约的合约引擎,所述装置包括:接收单元,区块链中的节点设备接收客户端发起的用于调用目标智能合约的目标交易;响应单元,响应于所述目标交易,从所述区块链的分布式数据库中获取所述目标智能合约的合约源码;执行单元,将所述合约源码发送给所述可信第三方,以使所述可信第三方的合约引擎执行所述合约源码,并向所述节点设备返回执行结果。
- 一种区块链的智能合约执行装置,所述区块链对接有可信第三方,所述可信第三方中部署有执行智能合约的合约引擎,所述方法包括:接收单元,所述可信第三方的合约引擎接收所述区块链中的节点设备发送的合约源码;其中,所述节点设备为所述区块链中响应客户端发起的用于调用目标智能合约的目标交易请求的节点,所述合约源码为所述目标智能合约的合约源码;执行单元,执行所述合约源码并向所述节点设备,并向所述节点设备返回执行结果。
- 一种电子设备,包括:处理器;用于存储处理器可执行指令的存储器;其中,所述处理器被配置为上述权利要求1-13中任一项所述的方法。
Priority Applications (3)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| SG11202104418XA SG11202104418XA (en) | 2019-01-31 | 2019-11-25 | Methods and apparatuses for executing smart contract of blockchain, and electronic devices |
| EP19912802.6A EP3859585B1 (en) | 2019-01-31 | 2019-11-25 | Block chain intelligent contract execution method, device and electronic apparatus |
| US17/244,719 US11108541B1 (en) | 2019-01-31 | 2021-04-29 | Methods and apparatuses for executing smart contract of blockchain, and electronic devices |
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201910095127.9A CN110060155B (zh) | 2019-01-31 | 2019-01-31 | 区块链的智能合约执行方法及装置和电子设备 |
| CN201910095127.9 | 2019-01-31 |
Related Child Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| US17/244,719 Continuation US11108541B1 (en) | 2019-01-31 | 2021-04-29 | Methods and apparatuses for executing smart contract of blockchain, and electronic devices |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2020155811A1 true WO2020155811A1 (zh) | 2020-08-06 |
Family
ID=67316430
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2019/120639 Ceased WO2020155811A1 (zh) | 2019-01-31 | 2019-11-25 | 区块链的智能合约执行方法及装置和电子设备 |
Country Status (6)
| Country | Link |
|---|---|
| US (1) | US11108541B1 (zh) |
| EP (1) | EP3859585B1 (zh) |
| CN (1) | CN110060155B (zh) |
| SG (1) | SG11202104418XA (zh) |
| TW (1) | TWI738046B (zh) |
| WO (1) | WO2020155811A1 (zh) |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN114297119A (zh) * | 2021-12-30 | 2022-04-08 | 北京百度网讯科技有限公司 | 智能合约执行方法、装置、设备以及存储介质 |
| US20230112806A1 (en) * | 2021-10-07 | 2023-04-13 | Capital One Services, Llc | Secure serverless computing framework |
Families Citing this family (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN110060155B (zh) | 2019-01-31 | 2021-03-23 | 创新先进技术有限公司 | 区块链的智能合约执行方法及装置和电子设备 |
| CN110659907B (zh) * | 2019-09-24 | 2021-11-12 | 北京海益同展信息科技有限公司 | 用于执行智能合约的方法和装置 |
| CN110955724B (zh) * | 2019-11-21 | 2024-11-08 | 腾讯科技(深圳)有限公司 | 基于区块链的数据处理方法、装置、节点设备及存储介质 |
| CN111355718B (zh) * | 2020-02-25 | 2022-04-15 | 中国工商银行股份有限公司 | 区块链智能合约云化部署系统及方法 |
| CN112380149B (zh) * | 2021-01-18 | 2021-04-06 | 腾讯科技(深圳)有限公司 | 基于节点内存的数据处理方法、装置、设备以及介质 |
| CN116821242B (zh) * | 2023-06-30 | 2026-02-24 | 蚂蚁区块链科技(上海)有限公司 | 区块同步方法、装置及区块链系统 |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20130326008A1 (en) * | 2012-06-04 | 2013-12-05 | American Express Travel Related Services Company, Inc. | Systems and Methods for Delivering Tailored Content Based Upon a Consumer Profile |
| CN107526624A (zh) * | 2017-07-18 | 2017-12-29 | 杭州趣链科技有限公司 | 一种基于Java虚拟机的智能合约执行引擎 |
| CN109146679A (zh) * | 2018-06-29 | 2019-01-04 | 阿里巴巴集团控股有限公司 | 基于区块链的智能合约调用方法及装置、电子设备 |
| CN109189396A (zh) * | 2018-08-16 | 2019-01-11 | 北京京东尚科信息技术有限公司 | 智能合约引擎组件、运行方法及存储介质 |
| CN110060155A (zh) * | 2019-01-31 | 2019-07-26 | 阿里巴巴集团控股有限公司 | 区块链的智能合约执行方法及装置和电子设备 |
Family Cites Families (11)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US10046228B2 (en) * | 2016-05-02 | 2018-08-14 | Bao Tran | Smart device |
| US10447478B2 (en) * | 2016-06-06 | 2019-10-15 | Microsoft Technology Licensing, Llc | Cryptographic applications for a blockchain system |
| US10158479B2 (en) * | 2017-02-06 | 2018-12-18 | Northern Trust Corporation | Systems and methods for generating, uploading and executing code blocks within distributed network nodes |
| US10362517B2 (en) * | 2017-04-07 | 2019-07-23 | Vapor IO Inc. | Distributed handoff-related processing for wireless networks |
| CN107103054B (zh) * | 2017-04-12 | 2019-03-26 | 北京航空航天大学 | 一种私有区块链的智能合约异步执行存储系统与实现方法 |
| CN107423945B (zh) * | 2017-04-13 | 2020-12-29 | 葛武 | 基于区块链技术的智能能源交易管理系统及方法 |
| CN107464118A (zh) * | 2017-08-16 | 2017-12-12 | 济南浪潮高新科技投资发展有限公司 | 一种基于区块链智能合约的数据交易方法 |
| CN108830606B (zh) * | 2018-05-30 | 2021-12-28 | 创新先进技术有限公司 | 智能合约的部署、调用、执行方法和装置 |
| CN108833161B (zh) * | 2018-06-11 | 2020-09-15 | 北京航空航天大学 | 一种建立基于雾计算的智能合约微服务模型的方法 |
| US11245576B2 (en) * | 2018-09-07 | 2022-02-08 | Dell Products L.P. | Blockchain-based configuration profile provisioning system |
| US20200242595A1 (en) * | 2019-01-30 | 2020-07-30 | Salesforce.Com, Inc. | Systems, methods, and apparatuses utilizing a blended blockchain ledger in a cloud service to address local storage |
-
2019
- 2019-01-31 CN CN201910095127.9A patent/CN110060155B/zh active Active
- 2019-09-02 TW TW108131513A patent/TWI738046B/zh active
- 2019-11-25 EP EP19912802.6A patent/EP3859585B1/en active Active
- 2019-11-25 SG SG11202104418XA patent/SG11202104418XA/en unknown
- 2019-11-25 WO PCT/CN2019/120639 patent/WO2020155811A1/zh not_active Ceased
-
2021
- 2021-04-29 US US17/244,719 patent/US11108541B1/en active Active
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20130326008A1 (en) * | 2012-06-04 | 2013-12-05 | American Express Travel Related Services Company, Inc. | Systems and Methods for Delivering Tailored Content Based Upon a Consumer Profile |
| CN107526624A (zh) * | 2017-07-18 | 2017-12-29 | 杭州趣链科技有限公司 | 一种基于Java虚拟机的智能合约执行引擎 |
| CN109146679A (zh) * | 2018-06-29 | 2019-01-04 | 阿里巴巴集团控股有限公司 | 基于区块链的智能合约调用方法及装置、电子设备 |
| CN109189396A (zh) * | 2018-08-16 | 2019-01-11 | 北京京东尚科信息技术有限公司 | 智能合约引擎组件、运行方法及存储介质 |
| CN110060155A (zh) * | 2019-01-31 | 2019-07-26 | 阿里巴巴集团控股有限公司 | 区块链的智能合约执行方法及装置和电子设备 |
Non-Patent Citations (1)
| Title |
|---|
| See also references of EP3859585A4 * |
Cited By (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20230112806A1 (en) * | 2021-10-07 | 2023-04-13 | Capital One Services, Llc | Secure serverless computing framework |
| US11962705B2 (en) * | 2021-10-07 | 2024-04-16 | Capital One Services, Llc | Secure serverless computing framework |
| CN114297119A (zh) * | 2021-12-30 | 2022-04-08 | 北京百度网讯科技有限公司 | 智能合约执行方法、装置、设备以及存储介质 |
Also Published As
| Publication number | Publication date |
|---|---|
| TWI738046B (zh) | 2021-09-01 |
| US11108541B1 (en) | 2021-08-31 |
| EP3859585A1 (en) | 2021-08-04 |
| SG11202104418XA (en) | 2021-05-28 |
| EP3859585B1 (en) | 2023-08-02 |
| CN110060155B (zh) | 2021-03-23 |
| EP3859585A4 (en) | 2021-12-29 |
| TW202030691A (zh) | 2020-08-16 |
| CN110060155A (zh) | 2019-07-26 |
| US20210250164A1 (en) | 2021-08-12 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| TWI738046B (zh) | 區塊鏈的智慧型合約執行方法及裝置和電子設備 | |
| CN108833398B (zh) | 一种区块链智能合约更新方法、装置及设备 | |
| TWI737944B (zh) | 基於區塊鏈的交易執行方法及裝置、電子設備 | |
| CN109003078B (zh) | 基于区块链的智能合约调用方法及装置、电子设备 | |
| CN109981679B (zh) | 在区块链网络中执行事务的方法和装置 | |
| CN110135844B (zh) | 基于区块链的信用记录、查询方法及装置和电子设备 | |
| TWI726573B (zh) | 基於區塊鏈的資料壓縮、查詢方法及裝置和電子設備 | |
| CN112966311B (zh) | 智能合约校验方法及装置和电子设备 | |
| TWI714308B (zh) | 基於區塊鏈的發票真偽驗證方法及裝置和電子設備 | |
| TW202022857A (zh) | 基於區塊鏈的發票創建方法及裝置、電子設備 | |
| TW202001656A (zh) | 基於區塊鏈的智能合約調用方法及裝置、電子設備 | |
| TWI719797B (zh) | 區塊鏈中智能合約的儲存、執行方法及裝置和電子設備 | |
| TWI734217B (zh) | 基於區塊鏈的發票沖紅方法及裝置和電子設備 | |
| CN110033244A (zh) | 基于区块链的智能合约执行方法及装置和电子设备 | |
| CN110009497B (zh) | 基于区块链的决策方法及装置和电子设备 | |
| CN111431908B (zh) | 一种访问处理方法、装置,管理服务器及可读存储介质 | |
| CN114741446B (zh) | 一种数据上链方法、装置、终端及存储介质 | |
| WO2023231335A1 (zh) | 在区块链中执行交易的方法及区块链的主节点 | |
| CN113095828A (zh) | 基于区块链的数据存证方法及装置 | |
| HK40011363B (zh) | 区块链的智能合约执行方法及装置和电子设备 | |
| CN118250292A (zh) | 一种基于云服务器的信息共享方法及装置 | |
| CN113538138A (zh) | 一种分组共识模型生成方法、装置和计算机设备 |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 19912802 Country of ref document: EP Kind code of ref document: A1 |
|
| ENP | Entry into the national phase |
Ref document number: 2019912802 Country of ref document: EP Effective date: 20210426 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |