Smart contract management method and device based on blockchain, and electronic equipment
By equipping the blockchain node device with a trusted execution environment to decrypt and execute the encrypted smart contract code on the blockchain, the problem of privacy protection and supervision of smart contracts is solved, and effective management and privacy protection of smart contracts are achieved, improving The security and privacy of blockchain.
Patent Information
- Application Number
- CN202011126863.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-05-30
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2039-05-30
AI Technical Summary
Existing blockchain technology has difficulties in privacy protection and content supervision of smart contracts. It is difficult to solve privacy and performance issues at the same time. Traditional encryption technology is highly complex and has poor versatility, and the execution process and results of smart contracts are difficult to supervise. .
Equipped with a trusted execution environment on the blockchain node device, by obtaining the encrypted smart contract code and determining whether it is a managed smart contract based on the smart contract management rules, if not, it will be decrypted and executed, and the execution result will be encrypted and stored. Realize content shielding and supervision of managed smart contracts.
On the basis of adequate privacy protection, effective management of smart contracts is achieved, improving the security and privacy of the blockchain, avoiding interference with unmanaged smart contracts, and enhancing content supervision of managed smart contracts. ability.
Smart Images

Figure CN113240519B_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of this specification relate to the field of blockchain technology, and in particular, to a blockchain-based smart contract management method and device, and electronic device. Background Art
[0002] Blockchain technology, also known as distributed ledger technology, is an emerging technology in which several computing devices jointly participate in "bookkeeping" and jointly maintain a complete distributed database. Blockchain technology has been widely used in many fields because of its decentralized, open and transparent characteristics, each computing device can participate in database records, and data can be quickly synchronized between computing devices. Summary of the invention
[0003] This specification proposes a blockchain-based smart contract management method, which is applied to a node device in a blockchain; wherein the node device is equipped with a trusted execution environment; the method comprises:
[0004] In response to a call transaction initiated by a client for a target smart contract, obtaining the encrypted contract code of the target smart contract stored in the distributed ledger of the blockchain, and sending the encrypted contract code of the target smart contract to the trusted execution environment;
[0005] Obtaining smart contract management rules, and determining whether the target smart contract is a managed smart contract based on the smart contract management rules in a trusted execution environment;
[0006] If the target smart contract is not a managed smart contract, extracting a decryption key corresponding to the contract code of the target smart contract stored in the trusted execution environment, and decrypting the contract code of the target smart contract based on the extracted decryption key;
[0007] The decrypted contract code of the target smart contract is executed in the trusted execution environment, and the execution result is encrypted and sent to the distributed ledger of the blockchain for storage.
[0008] Optionally, the trusted execution environment stores a decryption key corresponding to the contract code of the encrypted smart contract stored in the distributed ledger of the blockchain;
[0009] In which, the decryption key corresponding to the managed smart contract stored in the trusted execution environment is set to prohibit extraction; or, the decryption key stored in the trusted execution environment does not include the decryption key corresponding to the managed smart contract.
[0010] Optionally, the method further includes:
[0011] If the target smart contract is a managed smart contract, a prompt message indicating that the target smart contract call failed is returned to the client.
[0012] Optionally, the method further includes:
[0013] Receive a creation transaction initiated by a client for a target smart contract; wherein the creation transaction includes an encrypted contract code of the target smart contract;
[0014] In response to the creation transaction, a smart contract creation code is executed in the trusted execution environment, a contract account corresponding to the target smart contract is created in the blockchain, and the encrypted contract code of the target smart contract is sent to the distributed ledger of the blockchain for storage.
[0015] Optionally, obtaining smart contract management rules includes:
[0016] Obtain smart contract management rules from the distributed ledger of the management blockchain; wherein the smart contract management rules are generated by the management party calling the smart contract deployed on the management blockchain.
[0017] Optionally, the smart contract management rules include: a smart contract blacklist consisting of contract addresses of managed smart contracts;
[0018] The determining whether the target smart contract is a managed smart contract based on the smart contract management rule includes:
[0019] Obtain the contract address of the target smart contract in the calling transaction;
[0020] Matching the contract address of the target smart contract with the contract addresses in the smart contract blacklist;
[0021] If the contract address of the target smart contract matches any contract address in the smart contract blacklist, the target smart contract is determined to be a managed smart contract; otherwise, the target smart contract is determined not to be a managed smart contract.
[0022] Optionally, the encryption method used for the contract code of the target smart contract includes any one of the following encryption methods: a symmetric encryption method, an asymmetric encryption method, and a symmetric encryption combined with an asymmetric encryption method;
[0023] The encryption method used for the execution result of the contract code of the target smart contract includes: a symmetric encryption method; or an asymmetric encryption method.
[0024] Optionally, the symmetric encryption is combined with asymmetric encryption, including digital envelope encryption.
[0025] Optionally, the trusted execution environment includes Intel SGX.
[0026] This specification also proposes a blockchain-based smart contract management device, which is applied to a node device in a blockchain; wherein the node device is equipped with a trusted execution environment; the device comprises:
[0027] An acquisition module, in response to a call transaction initiated by a client for a target smart contract, acquires the encrypted contract code of the target smart contract stored in the distributed ledger of the blockchain, and sends the encrypted contract code of the target smart contract to the trusted execution environment;
[0028] A determination module is configured to obtain a smart contract management rule and determine whether the target smart contract is a managed smart contract based on the smart contract management rule in a trusted execution environment;
[0029] a decryption module, which, if the target smart contract is not a managed smart contract, extracts a decryption key corresponding to the contract code of the target smart contract stored in the trusted execution environment, and decrypts the contract code of the target smart contract based on the extracted decryption key;
[0030] The execution module executes the decrypted contract code of the target smart contract in the trusted execution environment, and encrypts the execution result and sends it to the distributed ledger of the blockchain for storage.
[0031] Optionally, the trusted execution environment stores a decryption key corresponding to the contract code of the encrypted smart contract stored in the distributed ledger of the blockchain;
[0032] In which, the decryption key corresponding to the managed smart contract stored in the trusted execution environment is set to prohibit extraction; or, the decryption key stored in the trusted execution environment does not include the decryption key corresponding to the managed smart contract.
[0033] Optionally, the device further comprises:
[0034] The return module returns a prompt message indicating that the target smart contract call failed to the client if the target smart contract is a managed smart contract.
[0035] Optionally, the device further comprises:
[0036] A receiving module, receiving a creation transaction initiated by a client for a target smart contract; wherein the creation transaction includes an encrypted contract code of the target smart contract;
[0037] A creation module, in response to the creation transaction, executes a smart contract creation code in the trusted execution environment, creates a contract account corresponding to the target smart contract in the blockchain, and sends the encrypted contract code of the target smart contract to the distributed ledger of the blockchain for storage.
[0038] Optionally, the acquisition module:
[0039] Obtain smart contract management rules from the distributed ledger of the management blockchain; wherein the smart contract management rules are generated by the management party calling the smart contract deployed on the management blockchain.
[0040] Optionally, the smart contract management rules include: a smart contract blacklist consisting of contract addresses of managed smart contracts;
[0041] The determination module:
[0042] Obtain the contract address of the target smart contract in the calling transaction;
[0043] Matching the contract address of the target smart contract with the contract addresses in the smart contract blacklist;
[0044] If the contract address of the target smart contract matches any contract address in the smart contract blacklist, the target smart contract is determined to be a managed smart contract; otherwise, the target smart contract is determined not to be a managed smart contract.
[0045] Optionally, the encryption method used for the contract code of the target smart contract includes any one of the following encryption methods: a symmetric encryption method, an asymmetric encryption method, and a symmetric encryption combined with an asymmetric encryption method;
[0046] The encryption method used for the execution result of the contract code of the target smart contract includes: a symmetric encryption method; or an asymmetric encryption method.
[0047] Optionally, the symmetric encryption is combined with asymmetric encryption, including digital envelope encryption.
[0048] Optionally, the trusted execution environment includes Intel SGX.
[0049] This specification also proposes a blockchain-based smart contract management method, which is applied to a node device in a blockchain; wherein the node device is equipped with a trusted execution environment; the trusted execution environment stores a decryption key corresponding to the contract code of the encrypted smart contract stored in the distributed ledger of the blockchain; the method comprises:
[0050] In response to a call transaction initiated by a client for a target smart contract, obtaining the encrypted contract code of the target smart contract stored in the distributed ledger of the blockchain, and sending the encrypted contract code of the target smart contract to the trusted execution environment;
[0051] Extracting a decryption key corresponding to the contract code of the target smart contract stored in the trusted execution environment, decrypting the contract code of the target smart contract based on the extracted decryption key, and executing the decrypted contract code of the target smart contract in the trusted execution environment;
[0052] Obtaining smart contract management rules, and determining whether the target smart contract is a managed smart contract based on the smart contract management rules in a trusted execution environment;
[0053] If the target smart contract is not a managed smart contract, the execution result of the contract code of the target smart contract is encrypted and sent to the distributed ledger of the blockchain for storage.
[0054] Optionally, the method further includes:
[0055] If the target smart contract is a managed smart contract, delete the execution result of the contract code of the target smart contract, and return a prompt message indicating that the call of the target smart contract failed to the client; or,
[0056] If the target smart contract is a managed smart contract, the execution result of the contract code of the target smart contract is stored in the trusted execution environment, and the execution result stored in the trusted execution environment is set to prohibit extraction; and a prompt message indicating that the call of the target smart contract failed is returned to the client.
[0057] This specification also proposes a blockchain-based smart contract management device, which is applied to a node device in a blockchain; wherein the node device is equipped with a trusted execution environment; the trusted execution environment stores a decryption key corresponding to the contract code of the encrypted smart contract stored in the distributed ledger of the blockchain; the device includes:
[0058] A second acquisition module, in response to a call transaction initiated by a client for a target smart contract, acquires the encrypted contract code of the target smart contract stored in the distributed ledger of the blockchain, and sends the encrypted contract code of the target smart contract to the trusted execution environment;
[0059] A first decryption module extracts a decryption key corresponding to the contract code of the target smart contract stored in the trusted execution environment, and decrypts the contract code of the target smart contract based on the extracted decryption key;
[0060] A second execution module executes the decrypted contract code of the target smart contract in the trusted execution environment;
[0061] The second determination module obtains the smart contract management rules, and determines whether the target smart contract is a managed smart contract based on the smart contract management rules in a trusted execution environment; if the target smart contract is not a managed smart contract, the execution result of the contract code of the target smart contract is encrypted and sent to the distributed ledger of the blockchain for storage.
[0062] Optionally, the device further comprises:
[0063] The second return module deletes the execution result of the contract code of the target smart contract if the target smart contract is a managed smart contract, and returns a prompt message indicating that the call of the target smart contract failed to the client; or
[0064] If the target smart contract is a managed smart contract, the execution result of the contract code of the target smart contract is stored in the trusted execution environment, and the execution result stored in the trusted execution environment is set to prohibit extraction; and a prompt message indicating that the call of the target smart contract failed is returned to the client.
[0065] Through the above technical solution, since when the node devices in the blockchain execute the encrypted contract code of the smart contract in the carried trusted execution environment, only the contract code of the unmanaged smart contract can be decrypted and executed; therefore, on the basis of sufficient privacy protection of the smart contract, the content of some managed smart contracts can be shielded through technical means to achieve supervision of the smart contract. BRIEF DESCRIPTION OF THE DRAWINGS
[0066] Figure 1 It is a schematic diagram of creating a smart contract provided by an exemplary embodiment;
[0067] Figure 2 is a schematic diagram of calling a smart contract provided by an exemplary embodiment;
[0068] Figure 3 It is a schematic diagram of creating and calling a smart contract provided by an exemplary embodiment;
[0069] Figure 4 It is a flowchart of a blockchain-based smart contract management method provided by an exemplary embodiment;
[0070] Figure 5 is a flowchart of another blockchain-based smart contract management method provided by an exemplary embodiment;
[0071] Figure 6 is a schematic structural diagram of an electronic device provided by an exemplary embodiment;
[0072] Figure 7 is a block diagram of a blockchain-based smart contract management device provided by an exemplary embodiment;
[0073] Figure 8 It is a block diagram of a blockchain-based smart contract management device provided by an exemplary embodiment. DETAILED DESCRIPTION
[0074] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
[0075] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0076] Blockchain is generally divided into three types: public blockchain, private blockchain and consortium blockchain. In addition, there are many types of combinations, such as private blockchain + consortium blockchain, consortium blockchain + public blockchain and other different combinations. Among them, the most decentralized is the public chain. Public chains are represented by Bitcoin and Ethereum. Participants who join the public chain can read data records on the chain, participate in transactions, and compete for the right to record new blocks. Moreover, each participant (i.e., node) can freely join and exit the network and perform related operations. On the contrary, the private chain has the write permission of the network controlled by a certain organization or institution, and the data reading permission is regulated by the organization. In short, the private chain can be a weakly centralized system with strictly limited and few participating nodes. This type of blockchain is more suitable for internal use in a specific organization.
[0077] The consortium chain is a blockchain between the public chain and the private chain, which can achieve "partial decentralization". Each node in the consortium chain usually has a corresponding entity or organization; participants join the network through authorization and form a stakeholder alliance to jointly maintain the operation of the blockchain.
[0078] Whether it is a public chain, a private chain or a consortium chain, it may provide the function of smart contract. Smart contracts on the blockchain are contracts that can be triggered and executed by transactions on the blockchain system. Smart contracts can be defined in the form of code.
[0079] Taking Ethereum as an example, supporting users to create and call some complex logic in the Ethereum network is the biggest challenge that distinguishes Ethereum from Bitcoin blockchain technology. The core of Ethereum as a programmable blockchain is the Ethereum Virtual Machine (EVM), and each Ethereum node can run EVM. EVM is a Turing-complete virtual machine, which means that various complex logics can be implemented through it. Users publish and call smart contracts in Ethereum on EVM. In fact, the virtual machine directly runs the virtual machine code (virtual machine bytecode, hereinafter referred to as "bytecode"). Smart contracts deployed on the blockchain can be in the form of bytecode.
[0080] like Figure 1As shown in the figure, after Bob sends a transaction containing the information of creating a smart contract to the Ethereum network, the EVM of node 1 can execute this transaction and generate the corresponding contract instance. "0x68e12cf284..." in Figure 1 represents the address of this contract, the data field of the transaction can store bytecode, and the to field of the transaction is an empty account. After the nodes reach an agreement through the consensus mechanism, the contract is successfully created and subsequent users can call this contract.
[0081] After the contract is created, a contract account corresponding to the smart contract appears on the blockchain with a specific address. The contract code and account storage will be saved in the contract account. The behavior of the smart contract is controlled by the contract code, while the smart contract account storage saves the state of the contract. In other words, the smart contract generates a virtual account on the blockchain that contains the contract code and account storage.
[0082] As mentioned above, the data field of the transaction that creates a smart contract can store the bytecode of the smart contract. The bytecode consists of a series of bytes, each of which can identify an operation. Based on development efficiency, readability and other considerations, developers can choose a high-level language to write smart contract code instead of writing bytecode directly. For example, high-level languages such as Solidity, Serpent, and LLL are used. For smart contract code written in a high-level language, it can be compiled by a compiler to generate bytecode that can be deployed on the blockchain.
[0083] Taking Solidity as an example, contracts written in it are very similar to classes in object-oriented programming languages. Multiple members can be declared in a contract, including state variables, functions, function modifiers, events, etc. State variables are values permanently stored in the account storage of smart contracts and are used to save the state of the contract.
[0084] Generally, when a smart contract is deployed on the blockchain, the storage state corresponding to the state variables in the contract code of the smart contract is in plain text, and anyone can see its state, with no privacy protection settings and capabilities.
[0085] like Figure 2As shown, still taking Ethereum as an example, after Bob sends a transaction containing information about calling a smart contract to the Ethereum network, the EVM of node 1 can execute this transaction and generate the corresponding contract instance. The from field of the transaction in Figure 2 is the address of the account that initiates the call to the smart contract, the "0x692a70d2..." in the to field represents the address of the smart contract being called, the value field is the value of Ether in Ethereum, and the data field of the transaction stores the method and parameters for calling the smart contract. After calling a smart contract, the value of balance may change. Later, a client can call a blockchain node (for example Figure 2 Node 6) in the table below checks the current value of balance.
[0086] Smart contracts can be executed independently on each node in the blockchain network in a prescribed manner, and all execution records and data are stored on the blockchain. Therefore, when such a transaction is completed, the blockchain stores transaction credentials that cannot be tampered with or lost.
[0087] The schematic diagram of creating and calling smart contracts is as follows: Figure 3 To create a smart contract in Ethereum, you need to go through the process of writing the smart contract, converting it into bytecode, and deploying it to the blockchain. To call a smart contract in Ethereum is to initiate a transaction pointing to the smart contract address. The smart contract code runs in a distributed manner in the virtual machines of each node in the Ethereum network.
[0088] The two biggest technical challenges for enterprise-level blockchain platforms are privacy and performance, and it is often difficult to solve these two challenges at the same time. Most solutions sacrifice performance in exchange for privacy, or pursue performance without considering privacy. Common encryption technologies that solve privacy issues, such as homomorphic encryption and zero-knowledge proof, are highly complex, have poor versatility, and may also cause serious performance losses.
[0089] In terms of privacy, Trusted Execution Environment (TEE) is another solution. TEE can act as a black box in hardware. The code and data executed in TEE cannot be peeped at the operating system layer. Only the pre-defined interfaces in the code can operate on them.
[0090] In terms of efficiency, due to the black box nature of TEE, the calculations performed in TEE are plain text data, not complex cryptographic operations in homomorphic encryption, and there is no loss in efficiency in the calculation process. Therefore, combining with TEE can greatly improve the security and privacy of blockchain with less performance loss. At present, the industry is paying close attention to TEE solutions. Almost all mainstream chip and software alliances have their own TEE solutions, including TPM (Trusted Platform Module) in software and Intel SGX (Software Guard Extensions), ARM Trustzone and AMD PSP (Platform Security Processor) in hardware.
[0091] In the traditional solution combining blockchain and TEE, in order to achieve privacy protection, the smart contract as a whole is treated as data that needs privacy protection and is called and executed in TEE, and all contract states are encrypted and stored on the blockchain. In this way, although the security level of privacy protection can be improved to a certain extent, it also makes data management difficult.
[0092] For example, in a management scenario shown, as the supervisory party of the smart contract, there may be a need to conduct content supervision on the execution process of the contract code of the smart contract and the corresponding execution results; however, in the traditional solution combining blockchain and TEE, the security level of smart contract execution is relatively high, and the execution process and results of the smart contract are in an invisible and private state; therefore, this makes it difficult to supervise the content of the smart contract.
[0093] This specification aims to propose a technical solution for further realizing the effective management of smart contracts on the basis of fully protecting the privacy of smart contracts in the application scenario of combining blockchain and TEE.
[0094] In implementation, the contract code of the smart contract deployed on the blockchain can be encrypted and persistently stored in the distributed ledger of the blockchain. In the trusted execution environment carried by the node device in the blockchain, the decryption key corresponding to the encrypted contract code of the smart contract stored in the distributed ledger of the blockchain can be pre-stored.
[0095] For example, taking the scenario of content supervision of smart contracts as an example, in one implementation, the decryption keys stored in the trusted execution environment may only include the decryption keys corresponding to those regulated smart contracts; that is, only the decryption keys corresponding to unregulated smart contracts may be stored in the trusted execution environment, while the decryption keys of those regulated smart contracts are not stored.
[0096] In another embodiment, the decryption keys corresponding to all smart contracts can be stored by default in the above-mentioned trusted execution environment; and the decryption keys corresponding to the regulated smart contracts stored in the above-mentioned trusted execution environment can be set to prohibit extraction; that is, the decryption keys corresponding to the contract codes that are not managed smart contracts can be extracted normally.
[0097] When a node device receives a call transaction initiated by a client for a target smart contract, it can obtain the encrypted contract code of the target smart contract stored in the distributed ledger of the blockchain, and send the obtained encrypted contract code of the target smart contract to the trusted execution environment carried by the node device.
[0098] After sending the encrypted contract code of the target smart contract to the trusted execution environment carried by the node device, the node device can obtain the smart contract management rules, and determine whether the target smart contract is a managed smart contract based on the obtained smart contract management rules in the carried trusted execution environment;
[0099] If it is confirmed that the target smart contract is not a managed smart contract, the node device can extract the decryption key corresponding to the contract code of the target smart contract stored in the trusted execution environment and decrypt the contract code of the target smart contract.
[0100] After the decryption is completed and the plaintext contract code of the above-mentioned target smart contract is obtained, the node device can execute the decrypted plaintext contract code in the above-mentioned trusted execution environment, and then encrypt the execution result and send it to the distributed ledger of the blockchain for storage.
[0101] In the above technical solution, since when the node devices in the blockchain execute the encrypted contract code of the smart contract in the carried trusted execution environment, only the contract code of the unmanaged smart contract can be decrypted and executed; therefore, on the basis of sufficient privacy protection of the smart contract, the content of some managed smart contracts can be shielded through technical means to achieve supervision of the smart contract.
[0102] See also Figure 4 , Figure 4 FIG. 1 is a flowchart of a blockchain-based smart contract management method provided by an exemplary embodiment. Figure 4As shown, the method is applied to a node device in a blockchain; wherein the node device is equipped with a trusted execution environment; the method comprises the following steps:
[0103] Step 402: in response to a call transaction initiated by the client for a target smart contract, obtaining the encrypted contract code of the target smart contract stored in the distributed ledger of the blockchain, and sending the encrypted contract code of the target smart contract to the trusted execution environment;
[0104] Step 404, obtaining smart contract management rules, and determining whether the target smart contract is a managed smart contract based on the smart contract management rules in a trusted execution environment;
[0105] Step 406: If the target smart contract is not a managed smart contract, extract the decryption key corresponding to the contract code of the target smart contract stored in the trusted execution environment, and decrypt the contract code of the target smart contract based on the extracted decryption key;
[0106] Step 408: execute the decrypted contract code of the target smart contract in the trusted execution environment, and encrypt the execution result and send it to the distributed ledger of the blockchain for storage.
[0107] In this specification, the management of smart contracts may specifically refer to the manager of the smart contract, who manages the execution process of the contract code of the smart contract and the corresponding execution results.
[0108] For example, in one management scenario shown, the management of smart contracts specifically refers to content supervision of the execution process of the contract code of the smart contract and the corresponding execution results; and in this management scenario, the above-mentioned management party may also refer to the regulator of the smart contract.
[0109] The following will describe the technical solution of this specification in detail in conjunction with the management scenario for supervising smart contracts. In this scenario, the above-mentioned managed smart contract is the supervised smart contract; the above-mentioned smart contract management rules are the smart contract supervision rules. In this specification, after the user has completed writing the contract code of the smart contract, based on the contract code of the smart contract, a creation transaction for creating a smart contract can be constructed on the client side, and the transaction can be sent to the blockchain node device connected to the client side.
[0110] For example, during implementation, if the user uses a high-level language to write the contract code of a smart contract, the client can further compile the contract code through a compiler to generate bytecode that can be deployed on the blockchain, and then "package" and generate a creation transaction for creating a smart contract based on the compiled bytecode of the smart contract, and send the transaction to the blockchain node device connected to the client.
[0111] It should be noted that in order to ensure the privacy of the contract code written by the user, the client can use a key to encrypt the written contract code.
[0112] For example, during implementation, the client may directly encrypt the entirety of the above-mentioned creation transaction; or, it may only encrypt the bytecode of the smart contract carried in the above-mentioned creation transaction; the specific encryption method can be flexibly selected by those skilled in the art when implementing the technical solution disclosed in this specification.
[0113] Among them, the encryption method used when encrypting the contract code can be symmetric encryption or asymmetric encryption.
[0114] For example, the encryption algorithm used in symmetric encryption may be DES algorithm, 3DES algorithm, TDEA algorithm, Blowfish algorithm, RC5 algorithm, IDEA algorithm, etc. The algorithm used in asymmetric encryption may be RSA, Elgamal, backpack algorithm, Rabin, DH, ECC (elliptic curve encryption algorithm), etc.
[0115] In addition, the encryption method used to encrypt the contract code can also be a combination of symmetric encryption and asymmetric encryption. This encryption method is generally called digital envelope encryption.
[0116] For example, the client uses a symmetric encryption algorithm to encrypt the contract code, that is, the private key of the symmetric encryption algorithm is used to encrypt the contract code, and then the public key of the asymmetric encryption algorithm is used to encrypt the private key used in the above symmetric encryption algorithm. In other words, the contract code is first encrypted with the key of the symmetric encryption algorithm; then the key of the asymmetric encryption algorithm is used to further encrypt the key used to encrypt the above contract code.
[0117] After receiving the above creation transaction sent by the client, the node device in the blockchain can check whether the transaction is valid, whether the format is correct, and whether the signature of the transaction is legal. After all checks and verifications are passed, the creation transaction can be executed in the trusted execution environment to complete the creation of the smart contract.
[0118] Specifically, before executing the creation transaction in the trusted execution environment, the function type of the transaction may be confirmed first;
[0119] For example, taking Ethereum as an example, the functional type of a transaction is usually determined based on the transaction content carried in the transaction; for example, if the to field in the transaction is an empty account, and the data field of the transaction carries the bytecode that needs to be deployed, then the transaction can be identified as a transaction for creating a smart contract; if the to field in the transaction points to the contract address of an existing smart contract, and the data field of the transaction carries the parameters required to call the smart contract, then the transaction can be identified as a transaction for calling a smart contract.
[0120] When it is confirmed that the transaction is a creation transaction for creating a smart contract, the smart contract creation code can be further executed in the above-mentioned trusted and secure environment, a contract account corresponding to the smart contract can be created on the blockchain, and the encrypted contract code of the smart contract in the creation transaction can be sent to the distributed ledger of the blockchain for storage.
[0121] For example, taking Ethereum as an example, the created contract account usually includes attribute fields such as Balance, Nonce, codehash and storaghash. After the node device completes the creation of the contract account, it will fill the hash value of the contract code in the creation transaction into the above codehash field, package the above creation transaction into a block and send it to other node devices in the blockchain, and store it in the distributed ledger of the blockchain. In other words, the original content of the contract code of the smart contract is still stored in the block of the original creation transaction saved in the blockchain, and the contract account corresponding to the smart contract only needs to maintain the hash pointer of the contract code of the smart contract.
[0122] Generally, the consensus algorithms supported in blockchain are usually divided into consensus algorithms in which node devices need to compete for the accounting rights of each accounting cycle, and consensus algorithms in which accounting nodes are elected in advance for each accounting cycle (without the need to compete for the accounting rights).
[0123] For example, the former is represented by consensus algorithms such as Proof of Work (POW), Proof of Stake (POS), and Delegated Proof of Stake (DPOS); the latter is represented by consensus algorithms such as Practical Byzantine Fault Tolerance (PBFT).
[0124] In blockchain networks that support smart contracts and use consensus algorithms such as Proof of Work (POW), Proof of Stake (POS), and Delegated Proof of Stake (DPOS), all nodes competing for the right to record can execute the transaction after receiving the creation transaction. One of the nodes competing for the right to record may win in this round of competition for the right to record and become the accounting node. The accounting node can package the creation transaction it receives with other transactions and generate a new block, and send the generated new block to other nodes for consensus.
[0125] In a blockchain network that supports smart contracts and adopts consensus algorithms such as Practical Byzantine Fault Tolerance (PBFT), the nodes with accounting rights have been agreed upon before this round of accounting. Therefore, after receiving the above-mentioned creation transaction, if the node device itself is not the accounting node of this round, it can send the creation transaction to the accounting node. For the accounting node of this round, the creation transaction can be executed before or during the process of packaging the creation transaction with other transactions and generating a new block. After the accounting node packages the creation transaction with other transactions to generate a new block, it can send the generated new block or the block header of the new block to other nodes for consensus.
[0126] As described above, no matter which consensus algorithm shown above is adopted by the blockchain, the accounting node of this round can package the creation transaction and generate a new block, and send the generated new block or block header to other node devices for consensus verification. If other node devices receive the new block or block header and verify that there is no problem, the new block can be appended to the end of the original blockchain, thereby completing the accounting process and reaching a consensus. When consensus is reached, the deployment of the smart contract on the blockchain is completed. Among them, other node devices can also execute the above-mentioned creation transaction contained in the block in the process of verifying the new block or block header sent by the accounting node.
[0127] In this specification, the specific process of executing the above-mentioned creation transaction in a trusted execution environment can be completed by a virtual machine deployed in the above-mentioned trusted execution environment; that is, the virtual machine deployed in the trusted execution environment is the execution subject of the above-mentioned creation transaction; for example, taking Ethereum as an example, the node device usually executes the transaction through the Ethereum Virtual Machine (EVM) carried by it.
[0128] In this specification, after the deployment of the smart contract is completed on the blockchain, the user can construct a call transaction on the client to call the target smart contract, and send the transaction to the blockchain node device connected to the client to initiate the call execution of the deployed target smart contract.
[0129] After receiving the above call transaction sent by the client, the node device in the blockchain can still check whether the transaction is valid, whether the format is correct, verify whether the signature of the transaction is legal, etc., and execute the call transaction in a trusted execution environment after all checks and verifications are passed.
[0130] Specifically, before executing the call transaction in the trusted execution environment, the functional type of the transaction can be confirmed first; when it is confirmed that the transaction is a call transaction for calling a smart contract, the encrypted contract code of the target smart contract stored in the distributed ledger of the blockchain can be further obtained, and the obtained encrypted contract code of the target smart contract can be sent to the above-mentioned trusted execution environment for execution in the above-mentioned trusted execution environment.
[0131] In this specification, in the above-mentioned trusted execution environment, the decryption key corresponding to the contract code of the encrypted smart contract stored in the distributed ledger of the blockchain can be stored and maintained. For example, in actual applications, the above-mentioned trusted execution environment can be equipped with a key generation algorithm. When a user successfully creates a contract account corresponding to a smart contract in the blockchain, the node device can call the equipped key generation algorithm in the trusted execution environment to create a root key for the contract account.
[0132] Among them, if asymmetric encryption is used, the root key includes a public-private key pair; the public key is used to encrypt the contract code and is held by the user; the private key is stored in a trusted execution environment and is used to decrypt the encrypted contract code; if symmetric encryption is used, the root key only includes one key for encrypting and decrypting the contract code.
[0133] The specific types of the key generation algorithms and the specific implementation process of creating the root key based on the key generation algorithms will not be described in detail in this specification.
[0134] In one embodiment shown, in order to achieve supervision of smart contracts, in the above-mentioned trusted execution environment, the decryption keys corresponding to the contract codes of all smart contracts included in the distributed ledger of the blockchain can be stored by default; wherein, in order to achieve the purpose of supervision, the decryption keys corresponding to the regulated smart contracts stored in the above-mentioned trusted execution environment can be set to a state where extraction is prohibited.
[0135] Among them, the implementation means of how to set the decryption key corresponding to the contract code of the regulated smart contract stored and maintained in the above-mentioned trusted execution environment to a non-extractable state is not particularly limited in this specification;
[0136] For example, in one implementation shown, a program code for controlling the extraction authority of the decryption key can be deployed in a trusted execution environment, and the program code can be independently called and executed by the hardware that carries the trusted execution environment (for example, a chip that serves as a trusted execution environment); and then the trusted execution environment can control the extraction authority of the stored and maintained decryption key by executing the above program code, so as to ensure that the decryption key corresponding to the contract code of the regulated smart contract stored and maintained in the trusted execution environment is in a state that cannot be extracted and exported. Of course, in addition to the implementation shown above, in actual applications, it can also be implemented through other implementations, which will not be listed one by one in this specification.
[0137] After the encrypted contract code of the target smart contract is sent to the trusted execution environment, the hardware carrying the trusted execution environment can further obtain the smart contract supervision rules, and determine whether the target smart contract is a regulated smart contract based on the obtained smart contract supervision rules in the trusted execution environment.
[0138] Among them, the above-mentioned smart contract regulatory rules can be specifically generated independently by the regulator, and can be updated and modified in real time by the regulator.
[0139] In one embodiment shown, based on the blockchain described above, an independent regulatory blockchain can be deployed, and a smart contract for generating smart contract regulatory rules can be deployed on the regulatory blockchain, and the generation logic for generating smart contract regulatory rules can be declared in the smart contract. Furthermore, the regulator can construct a call transaction based on actual regulatory needs to call the smart contract, dynamically generate smart contract regulatory rules, and store the generated smart contract regulatory rules in the distributed ledger of the regulatory blockchain.
[0140] The dynamically generated smart contract supervision rules refer to the smart contract supervision rules actually used when supervising smart contracts, and are always based on the latest generated smart contract supervision rules. If the supervisory requirements of the supervisor change, the supervisor can call the smart contract to regenerate new smart contract supervision rules based on the new supervision requirements.
[0141] In this way, regulators can flexibly and dynamically update smart contract regulatory rules based on actual regulatory needs.
[0142] For example, the above-mentioned smart contract supervision rules can specifically be a smart contract blacklist composed of the contract addresses of the regulated smart contracts. When the regulator needs to update the contract address of the regulated smart contract in the smart contract blacklist, it can regenerate a smart contract blacklist by calling the above-mentioned smart contract in the manner described above, and flexibly delete or add the contract address of the regulated smart contract in the smart contract blacklist.
[0143] Accordingly, when obtaining smart contract regulatory rules, the hardware carrying the above-mentioned trusted execution environment can access the distributed ledger of the regulatory blockchain and obtain the latest smart contract regulatory rules from the distributed ledger of the regulatory blockchain;
[0144] For example, during implementation, the smart contract regulatory rules generated after calling the smart contract deployed in the regulatory blockchain can be stored in the state database of the regulatory blockchain; for example, taking Ethereum as an example, the result of the smart contract call is usually stored in the receipt tree in the state database of the blockchain as part of the transaction receipt of the call transaction. The node device can monitor the data related to the smart contract stored in the state database of the regulatory blockchain in real time. After monitoring the latest smart contract regulatory rules generated by calling the smart contract, the smart contract regulatory rules can be stored locally. The hardware that carries the trusted execution environment can directly read the latest smart contract regulatory rules from the node device locally.
[0145] The specific form of the above-mentioned smart contract supervision rules is not specifically limited in this specification; for example, it can be a smart contract blacklist consisting of the contract addresses of the regulated smart contracts, or other forms other than the blacklist.
[0146] In one embodiment shown, the smart contract supervision rule is an example of a smart contract blacklist consisting of contract addresses of regulated smart contracts. In this case, when the hardware carrying the trusted execution environment determines whether the target smart contract is a regulated smart contract based on the latest smart contract supervision rule obtained, it can first obtain the contract address of the target smart contract carried in the call transaction, and then match the contract address of the target smart contract with the contract address of the regulated smart contract in the blacklist.
[0147] In this specification, the contract address is the account address of the contract account created for the smart contract; for example, taking Ethereum as an example, the address of the smart contract account is the address of the sender (such as Figure 1 0xf5e... or 0xf5e in the ) and the transaction random number (nonce) are used as input and generated by the encryption algorithm.
[0148] If the contract address of the target smart contract matches the contract address of any regulated smart contract in the above blacklist, it can be determined that the target smart contract is a regulated smart contract. On the contrary, if the contract address of the target smart contract does not match any of the contract addresses in the above blacklist, it can be determined that the target smart contract is not a regulated smart contract.
[0149] It should be noted that when the smart contract regulatory rules are other forms of regulatory rules other than the smart contract blacklist, the specific confirmation method for determining whether the target smart contract is a regulated smart contract based on the latest smart contract regulatory rules obtained will also change accordingly, and will not be listed one by one in this manual;
[0150] For example, in one case, the smart contract supervision rules may also be the encoding method of the contract address of the regulated smart contract. That is, the smart contract supervision rules can be used to supervise a class of smart contracts whose contract addresses meet a specific encoding method. In this case, when determining whether the target smart contract is a regulated smart contract based on the latest smart contract supervision rules obtained, it is a process of determining whether the encoding method of the contract address of the target smart contract matches the encoding method agreed upon in the smart contract supervision rules.
[0151] In one embodiment shown, in order to achieve supervision of smart contracts, the decryption keys stored in the above-mentioned trusted execution environment may not include the decryption keys corresponding to the regulated smart contracts; that is, the decryption keys corresponding to the contract codes of unregulated smart contracts can be stored in the above-mentioned trusted execution environment, while the decryption keys corresponding to the contract codes of regulated smart contracts are not stored and maintained.
[0152] For example, in implementation, when a user successfully creates a contract account corresponding to a smart contract in the blockchain, the key generation algorithm in the trusted execution environment can be called to create a root key for the contract account; when the root key is created, the smart contract supervision rules can be further obtained, and in the trusted execution environment, it can be determined whether the smart contract is a regulated smart contract based on the obtained smart contract supervision rules; the implementation process of determining whether the smart contract is a regulated smart contract will not be repeated.
[0153] If it is determined that the target smart contract is not a regulated smart contract, the generated root key can be further stored and maintained in the trusted execution environment. On the contrary, if it is determined that the target smart contract is a regulated smart contract, the trusted execution environment can no longer store and maintain the generated root key, and the generated root key can be discarded at this time; for example, if an asymmetric encryption method is used, the public key in the root key can be sent to the user for holding, and the private key in the root key can be discarded; if a symmetric encryption method is used, a copy of the generated key can be sent to the user, and then the generated key can be discarded.
[0154] In this specification, if the target smart contract is determined to be a regulated smart contract based on the acquired smart contract supervision rules in the trusted execution environment, the decryption key corresponding to the contract code of the regulated smart contract stored in the trusted execution environment is prohibited from being extracted; or, the decryption key corresponding to the contract code of the regulated smart contract is not stored in the trusted execution environment; at this time, the decryption key cannot be extracted to decrypt the contract code of the target smart contract; that is, the contract code of the target smart contract cannot be executed; therefore, in this case, the calling process for the target smart contract can be directly terminated, and a prompt message indicating that the call of the target smart contract failed is returned to the above-mentioned client.
[0155] If it is determined in the trusted execution environment based on the acquired smart contract supervision rules that the target smart contract is not a supervised smart contract, then the decryption key corresponding to the contract code of the target smart contract is further extracted from the trusted execution environment, and the contract code of the target smart contract is decrypted based on the decryption key. The method of decrypting the contract code of the target smart contract based on the extracted decryption key corresponds to the encryption method used when deploying the smart contract.
[0156] As mentioned above, if the contract code of the target smart contract is encrypted using symmetric encryption when deploying the target smart contract; for example, the private key of a symmetric encryption algorithm is used for encryption, then the private key of the symmetric encryption algorithm can be used directly for decryption.
[0157] If the contract code of the target smart contract is encrypted using asymmetric encryption when deploying the target smart contract; for example, it is encrypted using an asymmetric private key; in this case, the asymmetric public key can be used directly for decryption.
[0158] Furthermore, if the contract code of the target smart contract uses a combination of symmetric encryption and asymmetric encryption when deploying the target smart contract; for example, the contract code is encrypted with the private key of the symmetric encryption algorithm, and then the private key used in the above symmetric encryption algorithm is encrypted with the public key of the asymmetric encryption algorithm. At this time, the private key of the asymmetric encryption algorithm is first used to decrypt the private key used in the above symmetric encryption algorithm; then the encrypted contract code is decrypted using the decrypted private key used in the above symmetric encryption algorithm.
[0159] In this specification, the trusted execution environment carried by the above-mentioned node device can specifically be a trusted execution environment based on the security extension of CPU hardware and completely isolated from the outside.
[0160] The Trusted Execution Environment (TEE) was first proposed by Global Platform to solve the problem of secure isolation of resources on mobile devices and provide a trusted and secure execution environment for applications in parallel with the operating system. ARM's Trust Zone technology was the first to implement truly commercial TEE technology.
[0161] With the rapid development of the Internet, the demand for security is getting higher and higher. Not only mobile devices, but also cloud devices and data centers have put forward more requirements for TEE. The concept of TEE has also been rapidly developed and expanded. The TEE mentioned now is a more generalized TEE than the concept originally proposed. For example, server chip manufacturers such as Intel and AMD have successively launched hardware-assisted TEE and enriched the concept and characteristics of TEE, which has been widely recognized in the industry. The TEE mentioned now usually refers to this type of hardware-assisted TEE technology. Unlike mobile terminals, cloud access requires remote access, and the end user is invisible to the hardware platform. Therefore, the first step in using TEE is to confirm the authenticity of TEE. Therefore, the current TEE technology has introduced a remote proof mechanism, which is endorsed by hardware manufacturers (mainly CPU manufacturers) and ensures that users can verify the TEE status through digital signature technology. At the same time, security requirements that cannot be met by secure resource isolation alone have also been proposed. Further data privacy protection has also been proposed. Commercial TEEs including Intel SGX and AMD SEV also provide memory encryption technology, which limits trusted hardware to the CPU. The data of the bus and memory are all encrypted to prevent malicious users from snooping. For example, TEE technologies such as Intel's Software Guard Extensions (SGX) isolate code execution, remote attestation, secure configuration, secure storage of data, and a trusted path for executing code. Applications running in TEE are securely protected and almost impossible to be accessed by third parties.
[0162] In one embodiment shown, the above-mentioned trusted execution environment is Intel SGX as an example, SGX provides an enclave (also called an enclave), that is, an encrypted trusted execution area in the memory, and the CPU protects the data from being stolen. Taking the above-mentioned node device using a CPU that supports SGX as an example, the CPU can use the newly added processor instructions to allocate a part of the area EPC (Enclave Page Cache, enclave page cache or enclave page cache) in the memory, and encrypt the data therein through the encryption engine MEE (Memory Encryption Engine) in the CPU.
[0163] The encrypted content in the EPC will only be decrypted into plaintext after entering the CPU. Therefore, in SGX, users can distrust the operating system, VMM (Virtual Machine Monitor), and even BIOS (Basic InputOutput System). They only need to trust the CPU to ensure that private data will not be leaked. In practical applications, private data can be encrypted and passed to the enclave in ciphertext form, and the corresponding secret key can also be passed to the enclave through remote proof. Then, the data is used for calculations under the encryption protection of the CPU, and the results will be returned in ciphertext form. In this mode, you can take advantage of powerful computing power without worrying about data leakage.
[0164] In this case, the node device can load the deployed virtual machine into the enclosure provided by the SGX technology. After decrypting the contract code of the target smart contract based on the extracted decryption key and obtaining the plaintext contract code of the target smart contract, the node device can use the newly added processor instructions in the CPU to allocate a part of the EPC area in the memory, and encrypt the plaintext contract code obtained by the decryption through the encryption engine MEE in the CPU and store it in the EPC. The encrypted content in the EPC is decrypted into plaintext after entering the CPU. In the CPU, the plaintext code is operated to complete the code execution process.
[0165] When the node device executes the plaintext contract code of the above-mentioned target smart contract in the above-mentioned executable environment, it can also encrypt the execution result of the plaintext contract code, and then send the encrypted execution result to the distributed ledger of the above-mentioned blockchain for storage.
[0166] For example, since the execution result of the plaintext contract code of the above-mentioned target smart contract usually causes the state of the smart contract to change; therefore, the execution result of the above-mentioned plaintext contract code is usually stored in the state database of the above-mentioned blockchain; for example, taking Ethereum as an example, the execution result of the above-mentioned plaintext contract code is usually stored in the receipt tree in the state database of the blockchain as part of the transaction receipt of the call transaction of this call.
[0167] In this specification, the encryption method used to encrypt the execution result of the contract code of the target smart contract may be a symmetric encryption method or an asymmetric encryption method.
[0168] For example, still taking Intel SGX as the trusted execution environment, the encryption key used to write the execution result of the contract code in the distributed ledger of the blockchain is usually called secret_key. The secret_key can be a symmetric encryption key or an asymmetric encryption key; if the secret_key is a symmetric encryption key, it is usually called a seal (Simple Encrypted Arithmetic Library) key. Based on Intel SGX technology, the seal key can be a key sent to the blockchain node by the key management server after remote attestation.
[0169] In the above technical solution, since when the node devices in the blockchain execute the encrypted contract code of the smart contract in the carried trusted execution environment, only the contract code of the unmanaged smart contract can be decrypted and executed; therefore, on the basis of sufficient privacy protection of the smart contract, the content of some managed smart contracts can be shielded through technical means to achieve supervision of the smart contract.
[0170] See also Figure 5 , Figure 5 FIG. 1 is a flowchart of another blockchain-based smart contract management method provided by an exemplary embodiment. Figure 5 As shown, the method is applied to a node device in a blockchain; wherein the node device is equipped with a trusted execution environment; the trusted execution environment stores a decryption key corresponding to the contract code of the encrypted smart contract stored in the distributed ledger of the blockchain; the method comprises the following steps:
[0171] Step 502: in response to a call transaction initiated by the client for a target smart contract, obtaining the encrypted contract code of the target smart contract stored in the distributed ledger of the blockchain, and sending the encrypted contract code of the target smart contract to the trusted execution environment;
[0172] Step 504: extracting a decryption key corresponding to the contract code of the target smart contract stored in the trusted execution environment, decrypting the contract code of the target smart contract based on the extracted decryption key, and executing the decrypted contract code of the target smart contract in the trusted execution environment;
[0173] In this specification, in the above-mentioned trusted execution environment, the decryption keys corresponding to the contract codes of all smart contracts included in the distributed ledger of the blockchain can be stored by default.
[0174] After the encrypted contract code of the target smart contract is sent to the trusted execution environment carried by the node device, the decryption key corresponding to the target smart contract stored in the trusted execution environment can be extracted, the contract code of the target smart contract can be decrypted based on the decryption key, and the decrypted contract code can be executed in the trusted execution environment.
[0175] Step 506, obtaining smart contract management rules, and determining whether the target smart contract is a managed smart contract based on the smart contract management rules in a trusted execution environment;
[0176] Step 508: If the target smart contract is not a managed smart contract, the execution result of the contract code of the target smart contract is encrypted and sent to the distributed ledger of the blockchain for storage.
[0177] In this specification, when the contract code of the target smart contract is executed, the execution result of the above contract code can be cached in the above trusted execution environment, and by further determining whether the target smart contract is a regulated smart contract, it is decided whether the execution result of the above contract code needs to be encrypted and sent to the distributed ledger of the blockchain for storage.
[0178] Specifically, the hardware carrying the trusted execution environment can further obtain the smart contract supervision rules, and determine whether the target smart contract is a supervised smart contract based on the obtained smart contract supervision rules in the trusted execution environment. The specific implementation process will not be repeated here, and reference can be made to the records of the previous embodiments.
[0179] In one embodiment shown, if the target smart contract is a regulated smart contract, the cached execution result of the contract code of the target smart contract can be deleted, and a prompt message indicating that the target smart contract call failed can be returned to the above-mentioned client.
[0180] In another embodiment shown, if the target smart contract is a managed smart contract, the execution result of the contract code of the target smart contract can also be switched from the cache mode to persistent storage in a trusted execution environment, and the above-mentioned execution result persistently stored in the trusted execution environment can be set to a prohibited extraction state; at the same time, a prompt message indicating that the call of the target smart contract failed can also be returned to the above-mentioned client.
[0181] Of course, if the target smart contract is not a regulated smart contract, the execution result of the contract code of the target smart contract cached in the above-mentioned trusted execution environment can be encrypted, and then the encrypted execution result can be sent to the distributed ledger of the above-mentioned blockchain for storage. The specific implementation process will not be repeated here, and reference can be made to the records of the previous embodiments.
[0182] In the above technical solution, after the node device in the blockchain executes the decrypted contract code of the smart contract in the onboard trusted execution environment, only the execution result of the contract code of the unmanaged smart contract is further encrypted and sent to the distributed ledger of the blockchain for storage; therefore, on the basis of sufficient privacy protection of the smart contract, the content of some managed smart contracts can be shielded through technical means to achieve supervision of the smart contract.
[0183] Corresponding to the above method embodiments, the present application also provides device embodiments.
[0184] Corresponding to the above method embodiments, this specification also provides an embodiment of a blockchain-based smart contract management device. The embodiment of the blockchain-based smart contract management device of this specification can be applied to electronic devices. The device embodiment can be implemented through software, or through hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor of the electronic device in which it is located reading the corresponding computer program instructions in the non-volatile memory into the memory and running them. From the hardware level, if Figure 6 The figure is a hardware structure diagram of the electronic device where the blockchain-based smart contract management device of this specification is located, except Figure 6 In addition to the processor, memory, network interface, and non-volatile memory shown, the electronic device in which the device in the embodiment is located may also include other hardware according to the actual function of the electronic device, which will not be described in detail.
[0185] Figure 7 It is a block diagram of a blockchain-based smart contract management device shown in an exemplary embodiment of this specification.
[0186] Please refer to Figure 7The blockchain-based smart contract management device 70 can be applied in the aforementioned Figure 6 In the electronic device shown, the electronic device is equipped with a trusted execution environment; including:
[0187] The first acquisition module 701, in response to a call transaction initiated by a client for a target smart contract, acquires the encrypted contract code of the target smart contract stored in the distributed ledger of the blockchain, and sends the encrypted contract code of the target smart contract to the trusted execution environment;
[0188] The first determination module 702 obtains a smart contract management rule, and determines whether the target smart contract is a managed smart contract based on the smart contract management rule in a trusted execution environment;
[0189] The first decryption module 703 extracts a decryption key corresponding to the contract code of the target smart contract stored in the trusted execution environment if the target smart contract is not a managed smart contract, and decrypts the contract code of the target smart contract based on the extracted decryption key;
[0190] The first execution module 704 executes the decrypted contract code of the target smart contract in the trusted execution environment, and encrypts the execution result and sends it to the distributed ledger of the blockchain for storage.
[0191] In this embodiment, the trusted execution environment stores a decryption key corresponding to the contract code of the encrypted smart contract stored in the distributed ledger of the blockchain;
[0192] In which, the decryption key corresponding to the managed smart contract stored in the trusted execution environment is set to prohibit extraction; or, the decryption key stored in the trusted execution environment does not include the decryption key corresponding to the managed smart contract.
[0193] In this embodiment, the device 70 further includes:
[0194] The first return module 705 ( Figure 7 (not shown), if the target smart contract is a managed smart contract, a prompt message indicating that the target smart contract call failed is returned to the client.
[0195] In this embodiment, the device 70 further includes:
[0196] A receiving module 706 receives a creation transaction initiated by a client for a target smart contract; wherein the creation transaction includes an encrypted contract code of the target smart contract;
[0197] The creation module 707 executes the smart contract creation code in the trusted execution environment in response to the creation transaction, creates a contract account corresponding to the target smart contract in the blockchain, and sends the encrypted contract code of the target smart contract to the distributed ledger of the blockchain for storage.
[0198] In this embodiment, the first acquisition module 701:
[0199] Obtain smart contract management rules from the distributed ledger of the management blockchain; wherein the smart contract management rules are generated by the management party calling the smart contract deployed on the management blockchain.
[0200] In this embodiment, the smart contract management rules include: a smart contract blacklist consisting of the contract addresses of the managed smart contracts;
[0201] The first determining module 702:
[0202] Obtain the contract address of the target smart contract in the calling transaction;
[0203] Matching the contract address of the target smart contract with the contract addresses in the smart contract blacklist;
[0204] If the contract address of the target smart contract matches any contract address in the smart contract blacklist, the target smart contract is determined to be a managed smart contract; otherwise, the target smart contract is determined not to be a managed smart contract.
[0205] In this embodiment, the encryption method used for the contract code of the target smart contract includes any one of the following encryption methods: symmetric encryption method, asymmetric encryption method, and a combination of symmetric encryption and asymmetric encryption method;
[0206] The encryption method used for the execution result of the contract code of the target smart contract includes: a symmetric encryption method; or an asymmetric encryption method.
[0207] In this embodiment, the symmetric encryption is combined with asymmetric encryption, including a digital envelope encryption method.
[0208] In this embodiment, the trusted execution environment includes Intel SGX.
[0209] Figure 8 It is a block diagram of a blockchain-based smart contract management device shown in an exemplary embodiment of this specification.
[0210] Please refer to Figure 8The blockchain-based smart contract management device 80 can be applied in the aforementioned Figure 6 In the electronic device shown, the electronic device is equipped with a trusted execution environment; the trusted execution environment stores a decryption key corresponding to the contract code of the encrypted smart contract stored in the distributed ledger of the blockchain; including:
[0211] The second acquisition module 801, in response to the call transaction initiated by the client for the target smart contract, obtains the encrypted contract code of the target smart contract stored in the distributed ledger of the blockchain, and sends the encrypted contract code of the target smart contract to the trusted execution environment;
[0212] A first decryption module 802 extracts a decryption key corresponding to the contract code of the target smart contract stored in the trusted execution environment, and decrypts the contract code of the target smart contract based on the extracted decryption key;
[0213] A second execution module 803 executes the decrypted contract code of the target smart contract in the trusted execution environment;
[0214] The second determination module 804 obtains the smart contract management rules, and determines whether the target smart contract is a managed smart contract based on the smart contract management rules in a trusted execution environment; if the target smart contract is not a managed smart contract, the execution result of the contract code of the target smart contract is encrypted and sent to the distributed ledger of the blockchain for storage.
[0215] In this embodiment, the device 80 further includes:
[0216] The second return module 805 ( Figure 8 (not shown), if the target smart contract is a managed smart contract, the execution result of the contract code of the target smart contract is deleted, and a prompt message indicating that the call of the target smart contract failed is returned to the client; or
[0217] If the target smart contract is a managed smart contract, the execution result of the contract code of the target smart contract is stored in the trusted execution environment, and the execution result stored in the trusted execution environment is set to prohibit extraction; and a prompt message indicating that the call of the target smart contract failed is returned to the client.
[0218] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of 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 transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.
[0219] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0220] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0221] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0222] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0223] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0224] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0225] It should be understood that although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of this specification, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0226] The above description is merely a preferred embodiment of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present specification shall be included in the scope of protection of one or more embodiments of the present specification.
Claims
1. A blockchain-based smart contract management method, applied to node devices in the blockchain; wherein: The node device is equipped with a trusted execution environment; the method comprises: In response to a call transaction initiated by a client for a target smart contract, obtaining the encrypted contract code of the target smart contract stored in the distributed ledger of the blockchain, and sending the encrypted contract code of the target smart contract to the trusted execution environment; Obtaining smart contract management rules from a distributed ledger that manages the blockchain, and determining whether the target smart contract is a managed smart contract based on the smart contract management rules in a trusted execution environment; If the target smart contract is not a managed smart contract, extracting a decryption key corresponding to the contract code of the target smart contract stored in the trusted execution environment, and decrypting the contract code of the target smart contract based on the extracted decryption key; The decrypted contract code of the target smart contract is executed in the trusted execution environment, and the execution result is encrypted and sent to the distributed ledger of the blockchain for storage.
2. The method of claim 1, wherein the trusted execution environment stores a decryption key corresponding to the contract code of the encrypted smart contract stored in the distributed ledger of the blockchain; in, The decryption key corresponding to the managed smart contract stored in the trusted execution environment is set to prohibit extraction; or, the decryption key stored in the trusted execution environment does not include the decryption key corresponding to the managed smart contract.
3. The method of claim 2, further comprising: If the target smart contract is a managed smart contract, a prompt message indicating that the target smart contract call failed is returned to the client.
4. The method of claim 1, further comprising: Receive a creation transaction initiated by a client for a target smart contract; wherein the creation transaction includes an encrypted contract code of the target smart contract; In response to the creation transaction, a smart contract creation code is executed in the trusted execution environment, a contract account corresponding to the target smart contract is created in the blockchain, and the encrypted contract code of the target smart contract is sent to the distributed ledger of the blockchain for storage.
5. In the method as claimed in claim 1, the smart contract management rules include smart contract management rules generated by the management party calling the smart contract deployed on the management blockchain; smart contract management includes content supervision of the execution process of the contract code of the smart contract and the corresponding execution results.
6. The method according to claim 1 or 5, wherein the smart contract management rules include: A smart contract blacklist consisting of the contract addresses of managed smart contracts; The determining whether the target smart contract is a managed smart contract based on the smart contract management rule includes: Obtain the contract address of the target smart contract in the calling transaction; Matching the contract address of the target smart contract with the contract addresses in the smart contract blacklist; If the contract address of the target smart contract matches any contract address in the smart contract blacklist, the target smart contract is determined to be a managed smart contract; otherwise, the target smart contract is determined not to be a managed smart contract.
7. According to the method of claim 1, the encryption method used for the contract code of the target smart contract includes any one of the following encryption methods: symmetric encryption method, asymmetric encryption method, and a combination of symmetric encryption and asymmetric encryption method; The encryption method used for the execution result of the contract code of the target smart contract includes: Symmetric encryption method; or, asymmetric encryption method.
8. The method of claim 7, wherein: The symmetric encryption is combined with asymmetric encryption, including digital envelope encryption.
9. The method of claim 1, wherein: The trusted execution environment includes Intel SGX.
10. A blockchain-based smart contract management device, applied to a node device in a blockchain; wherein: The node device is equipped with a trusted execution environment; the device comprises: A first acquisition module, in response to a call transaction initiated by a client for a target smart contract, acquires the encrypted contract code of the target smart contract stored in the distributed ledger of the blockchain, and sends the encrypted contract code of the target smart contract to the trusted execution environment; A first determination module obtains a smart contract management rule from a distributed ledger of a management blockchain, and determines whether the target smart contract is a managed smart contract based on the smart contract management rule in a trusted execution environment; A first decryption module, if the target smart contract is not a managed smart contract, extracts a decryption key corresponding to the contract code of the target smart contract stored in the trusted execution environment, and decrypts the contract code of the target smart contract based on the extracted decryption key; The first execution module executes the decrypted contract code of the target smart contract in the trusted execution environment, and encrypts the execution result and sends it to the distributed ledger of the blockchain for storage.
11. The apparatus of claim 10, wherein the trusted execution environment stores a decryption key corresponding to the contract code of the encrypted smart contract stored in the distributed ledger of the blockchain; in, The decryption key corresponding to the managed smart contract stored in the trusted execution environment is set to prohibit extraction; or, the decryption key stored in the trusted execution environment does not include the decryption key corresponding to the managed smart contract.
12. The apparatus of claim 11, further comprising: The first returning module returns a prompt message indicating that the target smart contract call fails to the client if the target smart contract is a managed smart contract.
13. The apparatus of claim 10, further comprising: A receiving module, receiving a creation transaction initiated by a client for a target smart contract; wherein the creation transaction includes an encrypted contract code of the target smart contract; A creation module, in response to the creation transaction, executes a smart contract creation code in the trusted execution environment, creates a contract account corresponding to the target smart contract in the blockchain, and sends the encrypted contract code of the target smart contract to the distributed ledger of the blockchain for storage.
14. In the device as described in claim 10, the smart contract management rules include smart contract management rules generated by the management party calling the smart contract deployed on the management blockchain; smart contract management includes content supervision of the execution process of the contract code of the smart contract and the corresponding execution results.
15. The apparatus of claim 10 or 14, wherein the smart contract management rules include: A smart contract blacklist consisting of the contract addresses of managed smart contracts; The first determination module: Obtain the contract address of the target smart contract in the calling transaction; Matching the contract address of the target smart contract with the contract addresses in the smart contract blacklist; If the contract address of the target smart contract matches any contract address in the smart contract blacklist, determining that the target smart contract is a managed smart contract; Otherwise, it is determined that the target smart contract is not a managed smart contract.
16. The device according to claim 10, wherein the encryption method used for the contract code of the target smart contract includes any one of the following encryption methods: symmetric encryption method, asymmetric encryption method, and a combination of symmetric encryption and asymmetric encryption method; The encryption method used for the execution result of the contract code of the target smart contract includes: Symmetric encryption method; or, asymmetric encryption method.
17. The device of claim 16, wherein: The symmetric encryption is combined with asymmetric encryption, including digital envelope encryption.
18. The device of claim 10, wherein: The trusted execution environment includes Intel SGX.
19. A blockchain-based smart contract management method, applied to node devices in the blockchain; wherein: The node device is equipped with a trusted execution environment; The trusted execution environment stores a decryption key corresponding to the contract code of the encrypted smart contract stored in the distributed ledger of the blockchain; the method includes: In response to a call transaction initiated by a client for a target smart contract, obtaining the encrypted contract code of the target smart contract stored in the distributed ledger of the blockchain, and sending the encrypted contract code of the target smart contract to the trusted execution environment; Extracting a decryption key corresponding to the contract code of the target smart contract stored in the trusted execution environment, decrypting the contract code of the target smart contract based on the extracted decryption key, and executing the decrypted contract code of the target smart contract in the trusted execution environment; Obtaining smart contract management rules from a distributed ledger that manages the blockchain, and determining whether the target smart contract is a managed smart contract based on the smart contract management rules in a trusted execution environment; If the target smart contract is not a managed smart contract, the execution result of the contract code of the target smart contract is encrypted and sent to the distributed ledger of the blockchain for storage.
20. The method of claim 19, further comprising: If the target smart contract is a managed smart contract, delete the execution result of the contract code of the target smart contract, and return a prompt message indicating that the call of the target smart contract failed to the client; or, If the target smart contract is a managed smart contract, the execution result of the contract code of the target smart contract is stored in the trusted execution environment, and the execution result stored in the trusted execution environment is set to prohibit extraction; and a prompt message indicating that the call of the target smart contract failed is returned to the client.
21. A blockchain-based smart contract management device, applied to a node device in a blockchain; wherein: The node device is equipped with a trusted execution environment; The trusted execution environment stores a decryption key corresponding to the contract code of the encrypted smart contract stored in the distributed ledger of the blockchain; the device includes: A second acquisition module, in response to a call transaction initiated by a client for a target smart contract, acquires the encrypted contract code of the target smart contract stored in the distributed ledger of the blockchain, and sends the encrypted contract code of the target smart contract to the trusted execution environment; A second decryption module extracts a decryption key corresponding to the contract code of the target smart contract stored in the trusted execution environment, and decrypts the contract code of the target smart contract based on the extracted decryption key; A second execution module executes the decrypted contract code of the target smart contract in the trusted execution environment; The second determination module obtains the smart contract management rules from the distributed ledger of the management blockchain, and determines whether the target smart contract is a managed smart contract based on the smart contract management rules in a trusted execution environment; if the target smart contract is not a managed smart contract, the execution result of the contract code of the target smart contract is encrypted and sent to the distributed ledger of the blockchain for storage.
22. The apparatus of claim 21, further comprising: The second return module deletes the execution result of the contract code of the target smart contract if the target smart contract is a managed smart contract, and returns a prompt message indicating that the target smart contract call failed to the client; or, If the target smart contract is a managed smart contract, the execution result of the contract code of the target smart contract is stored in the trusted execution environment, and the execution result stored in the trusted execution environment is set to prohibit extraction; and a prompt message indicating that the call of the target smart contract failed is returned to the client.
23. An electronic device, comprising: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 9 by running the executable instructions.
24. An electronic device comprising: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 19-20 by running the executable instructions.
25. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the instruction is executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.
26. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the instruction is executed by a processor, the steps of the method as claimed in any one of claims 19 to 20 are implemented.
Citation Information
Patent Citations
Blockchain-based smart contract management methods, devices, and electronic equipment
CN110245506B
