Blockchain smart contract safe operation method and device and related equipment
By verifying the legitimacy of contract signing objects and ensuring secure compilation on the blockchain, combined with sandbox operation and advanced cryptographic algorithms, the security issues of smart contracts are solved, enabling secure contract loading and data protection, and improving the overall security of the blockchain.
Patent Information
- Application Number
- CN202211215174.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-30
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2042-09-30
AI Technical Summary
Existing smart contracts that support Turing-complete languages have security issues, which pose security threats to business applications, necessitating improvements in the operational security of smart contracts.
By verifying the legitimacy of the contract signing object on the blockchain, the contract is generated in a secure environment and business data is encrypted. Secure compilation methods are used and the contract is run in a sandbox to limit the contract's resource consumption and time. Advanced cryptographic algorithms are combined to protect sensitive data, and a trusted execution environment is used to isolate contract execution.
It improves the operational security of smart contracts, prevents the execution of illegal contracts, protects the security of the contract generation process and business data, and enhances the overall security of the blockchain.
Smart Images

Figure CN115879936B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of blockchain technology, and in particular to a method and apparatus for secure operation of smart contracts on a blockchain, an electronic device, and a computer-readable storage medium. Background Technology
[0002] A smart contract is an event-driven, stateful code contract and algorithmic contract that has flourished alongside blockchain technology. Smart contracts are a core component of blockchain and are widely used in technology.
[0003] While smart contracts that support Turing-complete languages offer great flexibility, their execution suffers from security issues, making their application in business applications extremely precarious and posing significant challenges to business security.
[0004] It should be noted that the information disclosed in the background section above is only used to enhance the understanding of the background of this disclosure. Summary of the Invention
[0005] The purpose of this disclosure is to provide a method, apparatus, electronic device, and computer-readable storage medium for the secure operation of smart contracts on a blockchain, which can improve the operational security of smart contracts.
[0006] Other features and advantages of this disclosure will become apparent from the following detailed description, or may be learned in part from practice of this disclosure.
[0007] This disclosure provides a method for securely operating a smart contract on a blockchain, comprising: in response to a loading instruction for a target contract, a first node on the blockchain provides contract signing information to the blockchain; the first node receives a consent loading instruction for the target contract returned by the blockchain, the consent loading instruction being generated by the blockchain after determining that the signing object is a legitimate object, wherein determining that the signing object is a legitimate object means determining that the target contract is a contract generated by the signing object in a secure environment through a secure compilation method and whose business data is encrypted; and the first node loading the target contract in response to the consent loading instruction.
[0008] In some embodiments, the target contract is published by a second node in the blockchain; wherein, before responding to a load instruction for the target contract, the method further includes: the second node signing the target contract to demonstrate through signing information that the target contract was generated after secure compilation in a secure environment; after the second node completes the signing, the second node sends the target contract to the blockchain, the target contract including the contract signing information; the second node receives a consent to publish instruction returned by the blockchain, the consent to publish instruction being generated by the blockchain after determining that the signing object is a legitimate object.
[0009] In some embodiments, before the second node signs the target contract, the method further includes: the second node performing secure compilation of the target contract; wherein, during the secure compilation of the target contract by the second node, the contract interface corresponding to the target contract and the methods in the target contract are checked to see if they conform to the specifications; during the secure compilation of the target contract by the second node, a blacklist is used to determine whether the target contract includes disabled packages, disabled interfaces, disabled classes, and disabled methods; when it is determined that the contract interface corresponding to the target contract and the methods in the target contract conform to the specifications, and it is determined that the target contract does not include disabled packages, disabled interfaces, disabled classes, and disabled methods, the secure compilation of the target contract is completed, so that the target contract can be signed after the secure compilation of the target contract is completed.
[0010] In some embodiments, the method further includes: stopping the secure compilation of the target contract and issuing an alarm when it is determined that the contract interface corresponding to the target contract or the method in the target contract does not conform to the specification, or when it is determined that the target contract includes a disabled package, a disabled interface, a disabled class, or a disabled method.
[0011] In some embodiments, before the second node performs secure compilation of the target contract, the method further includes: encrypting sensitive business data in the target contract to hide the business intent in the target contract.
[0012] In some embodiments, the first node loading the target contract includes: the first node running the target contract in a target sandbox to isolate the target contract from damaging the blockchain on the first node; wherein the target sandbox is equipped with a security policy that restricts the security permissions of the target contract when it is running.
[0013] In some embodiments, the first node loading the target contract includes: the first node limiting the maximum execution time of the target contract through timeout configuration; the first node limiting the maximum resource consumption of the target contract through resource consumption configuration; the first node limiting the maximum call stack depth of the target contract through stack depth configuration; if the execution time of the target contract exceeds the maximum time, or the execution consumption of the target contract exceeds the maximum resource consumption, or the call stack depth of the target contract exceeds the maximum call stack depth, then the first node stops loading the target contract.
[0014] This disclosure provides a smart contract secure operation device for blockchain, which is deployed in the blockchain. The smart contract secure operation device includes: a loading instruction response module, used to respond to a loading instruction for the target contract, whereby a first node on the blockchain provides contract signing information to the blockchain; an agreement loading instruction acquisition module, used to receive an agreement loading instruction for the target contract returned by the blockchain through the first node, wherein the agreement loading instruction is generated by the blockchain after determining that the signing object is a legitimate object, wherein determining that the signing object is a legitimate object means determining that the target contract is a contract generated by the signing object in a secure environment using a secure compilation method and whose business data is encrypted; and a loading module, used to load the target contract through the first node in response to the agreement loading instruction.
[0015] This disclosure provides an electronic device comprising: a memory and a processor; the memory for storing program instructions; and the processor for calling the program instructions stored in the memory to implement the blockchain smart contract secure operation method described in any of the preceding embodiments.
[0016] This disclosure provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements a secure operation method for blockchain smart contracts as described in any of the preceding embodiments.
[0017] This disclosure provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the aforementioned method for securely operating smart contracts on a blockchain.
[0018] The blockchain smart contract secure operation method, apparatus, electronic device, and computer-readable storage medium provided in this disclosure can verify whether the signing object of the target contract is a legitimate object when the target contract is loaded, thereby determining whether the target contract is a contract generated by the signing object in a secure environment using a secure compilation method and with encrypted business data; and only allows the loading of the target contract when it is determined that the target contract is a contract generated by the signing object in a secure environment using a secure compilation method and with encrypted business data. The above scheme, through the verification of signature information, on the one hand, avoids running contracts packaged with illegal objects, improving the security of the target contract's operation, and thus providing blockchain security; on the other hand, it ensures that the target contract is a contract generated by the signing object in a secure environment using a secure compilation method and with encrypted business data, guaranteeing the security of the target contract generation process and the security of the business data within the target contract.
[0019] It should be understood that the above general description and the following detailed description are merely exemplary and do not limit this disclosure. Attached Figure Description
[0020] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure. It is obvious that the drawings described below are merely some embodiments of this disclosure, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.
[0021] Figure 1A This is a schematic diagram of the architecture of a blockchain smart contract secure operation system provided by an embodiment of the present invention.
[0022] Figure 1B This is a schematic diagram of a blockchain structure provided in an embodiment of the present invention.
[0023] Figure 1C This is a schematic diagram of a process for generating a new block provided by an embodiment of the present invention.
[0024] Figure 2 This is a flowchart illustrating a method for securely operating a smart contract on a blockchain, according to an exemplary embodiment.
[0025] Figure 3 This is a flowchart illustrating a secure publishing method for smart contracts on a blockchain, according to an exemplary embodiment.
[0026] Figure 4 This is a flowchart illustrating a method for securely operating a smart contract on a blockchain, according to an exemplary embodiment.
[0027] Figure 5This is a schematic diagram illustrating a secure compilation structure according to an exemplary embodiment.
[0028] Figure 6 This is a flowchart illustrating a method for securely operating a smart contract on a blockchain, according to an exemplary embodiment.
[0029] Figure 7 This is a flowchart illustrating a method for securely operating a smart contract on a blockchain, according to an exemplary embodiment.
[0030] Figure 8 This is a schematic diagram illustrating a contract execution platform according to an exemplary embodiment.
[0031] Figure 9 This is a contract security execution model illustrated according to an exemplary embodiment.
[0032] Figure 10 This is a block diagram illustrating a blockchain smart contract secure operation device according to an exemplary embodiment.
[0033] Figure 11 A schematic diagram of the structure of an electronic device suitable for implementing embodiments of the present disclosure is shown. Detailed Implementation
[0034] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the embodiments set forth herein; rather, they are provided so that this disclosure will be thorough and complete, and will fully convey the concept of the exemplary embodiments to those skilled in the art. The same reference numerals in the drawings denote the same or similar parts, and therefore repeated descriptions of them will be omitted.
[0035] The features, structures, or characteristics described in this disclosure can be combined in any suitable manner in one or more embodiments. Numerous specific details are provided in the following description to give a thorough understanding of embodiments of this disclosure. However, those skilled in the art will recognize that the technical solutions of this disclosure can be practiced with one or more specific details omitted, or other methods, components, apparatuses, steps, etc., can be employed. In other instances, well-known methods, apparatuses, implementations, or operations are not shown or described in detail to avoid obscuring various aspects of this disclosure.
[0036] The accompanying drawings are merely illustrative of this disclosure, and the same reference numerals in the drawings denote the same or similar parts, thus omitting repeated descriptions of them. Some block diagrams shown in the drawings do not necessarily correspond to physically or logically independent entities. These functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.
[0037] The flowchart shown in the accompanying drawings is merely illustrative and does not necessarily include all content and steps, nor does it require execution in the described order. For example, some steps may be broken down, while others may be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.
[0038] In the description of this application, unless otherwise stated, " / " means "or," for example, A / B can mean A or B. "And / or" in this document is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, and B alone. Furthermore, "at least one" means one or more, and "multiple" means two or more. The terms "first," "second," etc., do not limit the quantity or order of execution, and "first," "second," etc., do not necessarily imply differences; the terms "contains," "includes," and "has" are used to indicate an open-ended inclusion and mean that additional elements / components / etc. may exist besides the listed elements / components / etc.
[0039] To better understand the above-mentioned objectives, features and advantages of the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that, unless otherwise specified, the embodiments and features in the embodiments of this application can be combined with each other.
[0040] Figure 1A This is a schematic diagram of the architecture of a blockchain smart contract secure operation system provided in an embodiment of the present invention.
[0041] Please see Figure 1AThe smart contract secure operation system of this blockchain includes a blockchain network 10 and terminal devices 20. The blockchain network 10 refers to a network used for data sharing between nodes, and may include multiple nodes 101. Each node 101, in normal operation, receives input information and maintains the shared data (i.e., the blockchain) within the network based on the received input information. To ensure information exchange within the blockchain network, information connections can exist between each node, enabling peer-to-peer (P2P) communication between any two nodes. This P2P communication can be conducted via wired or wireless communication links. For example, when any node in the blockchain network receives input information, other nodes obtain this input information according to a consensus algorithm and store it as data in the shared data, ensuring consistency of data stored on all nodes in the blockchain network.
[0042] Terminal device 20 can access the blockchain network and communicate with nodes in the blockchain network, such as submitting transactions to be uploaded to the chain, obtaining data from the nodes, and so on. Specifically, terminal device 20 can be a smartphone, tablet, laptop, desktop computer, in-vehicle smart terminal, etc., and this embodiment of the invention does not limit the scope.
[0043] It should be noted that, Figure 1A The number of nodes shown is merely illustrative; any number of nodes can be used.
[0044] Each node in the blockchain network has a corresponding node identifier, and each node can also store the node identifiers of other nodes in the blockchain network. This allows the generated blocks to be broadcast to other nodes in the blockchain network based on their node identifiers. Each node can maintain a node identifier list as shown in the table below, storing the node name and node identifier in this list. The node identifier can be an Internet Protocol (IP) address or any other information that can be used to identify the node. Table 1 only uses IP addresses as an example.
[0045] Node Name Node identifier Node 1 XXXXXX Node 2 XXXXXX … … Node N XXXXXX
[0046] In this blockchain network, each node stores an identical copy of the blockchain. A blockchain is composed of multiple blocks and can be modularized as needed; see [link to relevant documentation]. Figure 1BA blockchain consists of multiple blocks. The genesis block includes a block header and a block body. The block header stores input information feature values, version number, timestamp, and difficulty value, while the block body stores the input information. The next block after the genesis block takes the genesis block as its parent block. The next block also includes a block header and a block body. The block header stores the input information feature values of the current block, the block header feature values of the parent block, version number, timestamp, and difficulty value, and so on. This ensures that the block data stored in each block is related to the block data stored in the parent block, guaranteeing the security of the input information in the blocks.
[0047] When generating the various blocks in the blockchain, see [link / reference]. Figure 1C When a node in the blockchain receives input information, it verifies the input information. After verification, it stores the input information in a memory pool and updates its hash tree used to record the input information. Then, it updates the timestamp to the time the input information was received and tries different random numbers multiple times to calculate the feature value, ensuring that the calculated feature value satisfies the following formula:
[0048] SHA256(SHA256(version+prev_hash+merkle_root+ntime+nbits+x)) <T ARGET。
[0049] Wherein, SHA256 is the feature value algorithm used to calculate the feature value; version (version number) is the version information of the relevant block protocol in the blockchain; prev_hash is the block header feature value of the parent block of the current block; merkle_root is the feature value of the input information; ntime is the update time of the update timestamp; nbits is the current difficulty, which is a fixed value for a period of time and is determined again after exceeding the fixed time period; x is a random number; TARGET is the feature value threshold, which can be determined based on nbits.
[0050] Thus, when a random number satisfying the above formula is calculated, the information can be stored accordingly, generating a block header and a block body to obtain the current block. Subsequently, the node containing the blockchain sends the newly generated block to other nodes in its blockchain network based on the node identifiers of other nodes in the blockchain network. The other nodes verify the newly generated block and, after verification, add the newly generated block to their stored blockchain.
[0051] In this blockchain network, smart contracts can run on nodes. A smart contract is a code implementation that is executed when certain conditions are met. Developers can define the contract logic using a programming language and publish it to the blockchain (smart contract registration). According to the logic of the contract terms, the execution is triggered by calling a key or other events to complete the contract logic. It also provides functions for upgrading and canceling smart contracts.
[0052] Figure 2 This is a flowchart illustrating a method for securely operating a smart contract on a blockchain, according to an exemplary embodiment.
[0053] Reference Figure 2 The method for secure operation of smart contracts in a blockchain provided in this disclosure may include the following steps.
[0054] In step S202, in response to the loading instruction for the target contract, the first node on the blockchain provides contract signing information to the blockchain.
[0055] The target contract mentioned above can be published on the blockchain by a second node. This second node can be the same as or different from the first node. That is, the node loading the target contract can include the second node that published the target contract, or it can be other nodes on the blockchain. This application does not impose any restrictions on this.
[0056] The first node mentioned above can be one or more, and this application does not impose any restrictions on this.
[0057] In some embodiments, the target contract may be loaded when a transaction exists in the blockchain.
[0058] In some embodiments, during the loading of the target contract, the first node on the blockchain provides the blockchain with the contract signing information of the target contract.
[0059] In some embodiments, the blockchain will reach a consensus on the signing objects in the contract signing information. When the consensus operation determines that the signing object corresponding to the target contract is a legitimate object, the blockchain will send an agreement loading instruction to the first node.
[0060] In some embodiments, determining that the signing object corresponding to the target contract is a legitimate object can mean determining that the target contract is a contract generated by a legitimate object in a secure environment using a secure compilation method, and that the business data in the target contract has been encrypted.
[0061] In step S204, the first node receives the consent loading instruction for the target contract returned by the blockchain. The consent loading instruction is generated by the blockchain after determining that the signing object is a legitimate object. Determining that the signing object is a legitimate object means determining that the target contract is a contract generated by the signing object in a secure environment through a secure compilation method and whose business data is encrypted.
[0062] In step S206, the first node responds to the loading instruction and loads the target contract.
[0063] In some embodiments, the first node will only load the target contract upon receiving a consent loading instruction from the blockchain.
[0064] The technical solution provided in the above embodiments can verify whether the signing object of the target contract is a legitimate object through the blockchain when the target contract is loaded, thereby determining whether the target contract is a contract generated by the signing object in a secure environment using a secure compilation method and whose business data is encrypted; and only allows the loading of the target contract when it is determined that the target contract is a contract generated by the signing object in a secure environment using a secure compilation method and whose business data is encrypted. By verifying the signing information, the above solution, on the one hand, avoids running contracts packaged with illegal objects, improving the security of the target contract's operation and thus providing blockchain security; on the other hand, it ensures that the target contract is a contract generated by the signing object in a secure environment using a secure compilation method and whose business data is encrypted, guaranteeing the security of the target contract generation process and the security of the business data within the target contract.
[0065] Figure 3 This is a flowchart illustrating a secure publishing method for smart contracts on a blockchain, according to an exemplary embodiment.
[0066] In some embodiments, the target contract described above may be published by a second node in the blockchain.
[0067] refer to Figure 3 The secure deployment method for smart contracts on the aforementioned blockchain may include the following steps.
[0068] In step S302, the second node signs the target contract to demonstrate that the target contract was generated in a secure environment after secure compilation through the signing information.
[0069] In some embodiments, after the second node generates the target contract, it will sign the target contract. The specific signing technology can refer to the signature technology in the blockchain, and this application does not limit it.
[0070] Step S304: After the second node completes the signing, the second node sends the target contract to the blockchain. The target contract includes the contract signing information.
[0071] In some embodiments, once the second node has signed, it will send the target contract to the blockchain so that the target contract can be published on the blockchain.
[0072] In some embodiments, when the blockchain receives the target contract, it will reach a consensus on the signing information in the target contract.
[0073] In some embodiments, when the consensus operation determines that the signing object corresponding to the target contract is a legitimate object, the blockchain will agree to the second node publishing the target contract and return an agreement to publish instruction to the second node.
[0074] In some embodiments, if consensus on the signing information of the target contract is not reached, the blockchain disagrees with the second node in publishing the target contract and returns a disagreement to the second node.
[0075] In step S306, the second node receives the consent release instruction returned by the blockchain. The consent release instruction is generated by the blockchain after determining that the signing object is a legitimate object.
[0076] In some embodiments, the second node only completes the publication of the target contract after receiving the consent publication instruction from the blockchain.
[0077] In the above embodiment, when the blockchain publishes the target contract at the second node, it uses a consensus operation to determine whether the target contract was generated by a legitimate object in a secure environment using a secure compilation method, and whether the business data is encrypted. If the consensus operation determines that the target contract was not generated by a legitimate object in a secure environment using a secure compilation method, and that the business data is not encrypted, the blockchain considers the target contract insecure and therefore rejects its publication. This technical solution only allows target contracts generated by legitimate objects in a secure environment to be published on the blockchain, thus improving the blockchain's security.
[0078] Figure 4 This is a flowchart illustrating a method for securely operating a smart contract on a blockchain, according to an exemplary embodiment.
[0079] refer to Figure 4 The above-mentioned method for securely operating smart contracts on a blockchain may include the following steps.
[0080] Step S402: The second node performs secure compilation of the target contract; during the secure compilation process of the target contract in the second node, it checks whether the contract interface corresponding to the target contract and the methods in the target contract conform to the specifications; during the secure compilation process of the target contract in the second node, it determines whether the target contract includes disabled packages, disabled interfaces, disabled classes and disabled methods through a blacklist.
[0081] In some embodiments, the target contract needs to be securely compiled before it can be published, for example, by using a contract compiler.
[0082] In some embodiments, when the second node performs secure compilation of the target contract, it can check whether the contract interface corresponding to the target contract and the methods in the target contract conform to the specifications. It can also determine whether the target contract includes disabled packages, disabled interfaces, disabled classes and disabled methods through a blacklist.
[0083] It is understandable that those skilled in the art can perform security checks on the target contract during the secure compilation phase, based on actual needs.
[0084] In some embodiments, the target contract can use Maven (a project management tool) as the build management tool for the code project, and implement the compilation, packaging (packaging into binary files), and deployment of the contract through the contract-maven-plugin.
[0085] In some embodiments, after the target contract is compiled into bytecode by the contract compiler, the contract development framework interface and contract methods can be checked during the secure compilation process to see if they conform to the specifications and constraints. For example, whether predefined annotations are added to the contract interface, and whether the contract instance implements the Aware interface to obtain context information and necessary initialization or resource reclamation operations before and after the contract method runs.
[0086] In addition, such as Figure 5 As shown, the contract compiler can use ASM (Java Bytecode Manipulation Framework) technology to perform legality checks on contract code, with the checks being precise down to the method level. The checks recursively examine the classes and methods involved in the contract call stack, and combine this with a blacklist / whitelist strategy to check whether the contract method dependencies contain disabled packages, interfaces, classes, and specific methods, preventing unauthorized operations. For illegal operations, warnings are issued, and contract compilation is terminated.
[0087] Step S404: Determine whether the contract interface and methods in the target contract conform to the specifications, and whether the target contract does not contain disabled packages, disabled interfaces, disabled classes, and disabled methods.
[0088] If it is determined that the contract interface corresponding to the target contract or the method in the target contract does not conform to the specification, or if it is determined that the target contract includes a disabled package, disabled interface, disabled class or disabled method, execute step S406 to stop the secure compilation of the target contract and issue an alarm.
[0089] Once it is determined that the contract interface corresponding to the target contract and the methods in the target contract conform to the specifications, and it is determined that the target contract does not contain disabled packages, disabled interfaces, disabled classes and disabled methods, step S408 is executed to complete the secure compilation of the target contract; and after the target contract has been securely compiled, the target contract is signed and published.
[0090] like Figure 5 As shown, contract code that passes security verification and is successfully compiled still needs to be signed and edited. The signing information will be verified during the contract release and loading phases. Contracts that are not signed will be restricted from being released.
[0091] The above signing and publication process can be referenced. Figure 3 The embodiments described above will not be repeated here.
[0092] In step S410, in response to the loading instruction for the target contract, the first node on the blockchain provides contract signing information to the blockchain.
[0093] In step S412, the first node receives the consent loading instruction for the target contract returned by the blockchain. The consent loading instruction is generated by the blockchain after determining that the signing object is a legitimate object. Determining that the signing object is a legitimate object means determining that the target contract is a contract generated by the signing object in a secure environment through a secure compilation method and whose business data is encrypted.
[0094] In step S414, the first node responds to the loading instruction and loads the target contract.
[0095] The technical solution provided by the above embodiments can verify the legality of methods and the standardization of interfaces in the target contract during the compilation process, so that the target contract that is finally published and executed on the blockchain is legal and standardized, which greatly improves the security and legality of the target contract.
[0096] Figure 6 This is a flowchart illustrating a method for securely operating a smart contract on a blockchain, according to an exemplary embodiment.
[0097] refer to Figure 6 The above-mentioned method for securely operating smart contracts on a blockchain may include the following steps.
[0098] Step S602: Encrypt sensitive business data in the target contract to hide the business intent in the target contract.
[0099] In some embodiments, the target contract may include some business data, through which business information of the target contract may be obtained.
[0100] If an unauthorized entity obtains the target contract, it can access the business information within the contract through the business data, thereby causing the leakage of the business data corresponding to the target contract.
[0101] For example, in business areas such as finance, expense reimbursement, and real estate, where the confidentiality of business data is extremely stringent, the leakage of business data can lead to unpredictable losses.
[0102] Therefore, when generating the target contract, the embodiment uses encryption algorithms to encrypt the business data in the target contract. For example, it can use Paillier homomorphic encryption algorithm (a public-key encryption algorithm), Bulletproofs zero-knowledge proof algorithm (a zero-knowledge proof algorithm), and advanced cryptographic algorithms such as Shamir secret sharing (a secret sharing algorithm, the basic idea of which is that the distributor decomposes the secret s into n secrets through a secret polynomial and distributes them to the holder, where any number of secrets not less than t can recover the ciphertext) to encrypt the business data, so that illegal objects cannot obtain the business data in the target contract when they obtain the target contract.
[0103] Step S604: The second node performs secure compilation of the target contract; during the secure compilation process of the target contract in the second node, it checks whether the contract interface corresponding to the target contract and the methods in the target contract conform to the specifications; during the secure compilation process of the target contract in the second node, it determines whether the target contract includes disabled packages, disabled interfaces, disabled classes and disabled methods through a blacklist.
[0104] Step S606: Determine whether the contract interface corresponding to the target contract and the methods in the target contract conform to the specifications, and whether the target contract does not contain disabled packages, disabled interfaces, disabled classes and disabled methods.
[0105] If it is determined that the contract interface corresponding to the target contract or the method in the target contract does not conform to the specification, or if it is determined that the target contract includes a disabled package, disabled interface, disabled class or disabled method, execute step S608 to stop the secure compilation of the target contract and issue an alarm.
[0106] If it is determined that the contract interface corresponding to the target contract and the methods in the target contract conform to the specifications, and it is determined that the target contract does not contain disabled packages, disabled interfaces, disabled classes and disabled methods, then step S610 is executed to complete the secure compilation of the target contract; and after the target contract has been securely compiled, the target contract is signed and published.
[0107] In step S612, in response to the loading instruction for the target contract, the first node on the blockchain provides contract signing information to the blockchain.
[0108] In step S614, the first node receives the consent loading instruction for the target contract returned by the blockchain. The consent loading instruction is generated by the blockchain after determining that the signing object is a legitimate object. Determining that the signing object is a legitimate object means determining that the target contract is a contract generated by the signing object in a secure environment through a secure compilation method and whose business data is encrypted.
[0109] In step S616, the first node responds to the loading instruction and loads the target contract.
[0110] The technical solution provided in this embodiment, in order to meet the security requirements of business data such as the confidentiality of transaction amounts and the anonymity of sender and receiver addresses, can provide advanced cryptographic algorithms such as Paillier homomorphic encryption algorithm, Bulletproofs zero-knowledge proof algorithm, and Shamir secret sharing algorithm. These algorithms support application developers in using them in contracts to protect sensitive business data, hide transaction intentions, and achieve project security from the source code.
[0111] Figure 7 This is a flowchart illustrating a method for securely operating a smart contract on a blockchain, according to an exemplary embodiment.
[0112] refer to Figure 7 The above-mentioned method for securely operating smart contracts on a blockchain may include the following steps.
[0113] In step S702, in response to the loading instruction for the target contract, the first node on the blockchain provides contract signing information to the blockchain.
[0114] Step S704: The first node receives the consent loading instruction for the target contract returned by the blockchain. The consent loading instruction is generated by the blockchain after determining that the signing object is a legitimate object. Determining that the signing object is a legitimate object means determining that the target contract is a contract generated by the signing object in a secure environment through a secure compilation method and whose business data is encrypted.
[0115] Step S706: The first node runs the target contract in the target sandbox to isolate the target contract from damaging the blockchain on the first node; wherein, the target sandbox is customized with a security policy, which is used to restrict the security permissions of the target contract when running the target contract.
[0116] To further enhance the security of the smart contract execution environment, this embodiment strengthens the security integration of software and hardware by binding the target contract to a trusted execution environment. The trusted execution environment is a security-hardened zone within the CPU, ensuring the confidentiality and integrity of its software logic and data. This hardware and software environment can be considered isolated from the outside world; programs running within this environment cannot be read or written to by external entities, including the operating system, nor can their code execution logic be interfered with. After the privacy contract is executed in the trusted environment, sensitive data exists in encrypted form in the blockchain ledger. Users decrypt the data within the trusted execution environment, and the plaintext of the sensitive data cannot be obtained outside the trusted execution environment.
[0117] In some embodiments, after receiving the consent loading instruction, the first node can run the contract in the Trusted Execution Environment (TEE) of the contract execution platform.
[0118] like Figure 8 As shown, the Trusted Execution Environment (TEE) can deploy system resources, through which containers can be deployed, and then virtual machines (such as Java Virtual Machines, JVMs) can be deployed in the containers, and finally a security sandbox can be deployed in the virtual machines.
[0119] In order to make the privacy contract run in a lightweight manner, this embodiment deploys the target contract into a Docker container, which also further isolates the adverse effects of smart contract anomalies on the security of the entire system.
[0120] In some embodiments, the target contract can be loaded in a sandbox within the aforementioned trusted execution environment.
[0121] A sandbox is a restricted environment for program execution. The sandbox mechanism confines Java code to a specific runtime scope of the JVM and strictly limits its access to local system resources. This ensures effective code isolation and prevents contract code from damaging the local blockchain system. Sandboxes primarily restrict access to system resources, including CPU, memory, file system, and network. Different sandbox levels can have different restrictions on resource access. All Java programs can specify a sandbox and customize security policies (i.e., different sandboxes can have different security policies).
[0122] Sandboxes and containers serve different purposes. The purpose of a sandbox is to ensure that any operations performed within it have no impact on the outside world; you can do whatever you want. Containers, on the other hand, are for convenient application deployment, isolating you in a separate environment where external changes won't affect the application's normal operation. One prevents the inside from affecting the outside, while the other prevents the outside from affecting the inside.
[0123] By using the aforementioned nested mechanism, the operation of the target contract at the first node can be neither interfered with by external factors nor interfere with external factors, thereby improving the security of the target contract's operation.
[0124] In step S708, the first node limits the maximum execution time of the target contract by configuring a timeout.
[0125] Step S710: The first node limits the maximum resource consumption of the target contract by configuring resource consumption.
[0126] In step S712, the first node limits the maximum call stack depth of the target contract by configuring the stack depth.
[0127] Step S714: If the execution time of the target contract exceeds the maximum time, or the execution consumption of the target contract exceeds the maximum resource consumption, or the call stack depth of the target contract exceeds the maximum call stack depth, then the first node stops loading the target contract.
[0128] To prevent system errors caused by internal circular calls or time-consuming calls within contracts, this embodiment adds a contract execution timeout mechanism. This mechanism limits the maximum execution time of a contract by configuring a timeout; controls the reasonable range of resource consumption during contract execution by configuring maximum resource consumption; and limits the execution of abnormal contracts by configuring the maximum call stack depth. Timeouts, excessive resource consumption, and excessive call stack depth are all handled as exceptions, thereby ensuring the normal, safe, and effective operation of the contract execution platform.
[0129] Furthermore, to prevent malicious contracts from threatening normal contracts and the system itself during runtime, and to achieve isolation of the contract execution context, this embodiment also employs a secure parent delegation model class loader mechanism. It uses a custom ClassLoader to layer the entire system's ClassLoaders, starting with the innermost JVM-provided class loader. Malicious classes with the same name on the outer layer are not loaded and therefore cannot be used. The class loader categorizes code into protected domains, determining which operations the code can perform. Because access domains are strictly differentiated by package, malicious classes on the outer layer cannot gain access to inner classes through built-in code, thus rendering malicious code ineffective. For detailed process information, please refer to [link to relevant documentation]. Figure 9 The illustrated embodiment. Figure 9 This is an exemplary contract execution model. The contract execution model can be set in the first node.
[0130] like Figure 9As shown, maximum time, maximum resource consumption, and maximum call stack depth can be set through security management policies so that loading of the target contract stops when the execution time of the target contract exceeds the maximum time, the execution consumption of the target contract exceeds the maximum resource consumption, or the call stack depth of the target contract exceeds the maximum call stack depth.
[0131] In some embodiments, the contract security execution model of the first node may also include a contract cache, which may cache several recently invoked contracts so that the contract can be invoked directly from the cache the next time it is invoked, thereby reducing the call time and improving the operating speed and security of the blockchain.
[0132] The technical solution provided in this embodiment offers a nested model that utilizes a multi-layered security mechanism combining a trusted hardware execution environment, Docker, JVM (virtual machine), Sandbox (Security Manager + layered Custom ClassLoader), and a privacy contract software implementation (homomorphic encryption and zero-knowledge proof) to explore the implementation of the contract execution environment. This model can prevent contracts from unauthorized access to the CPU and I / O, and limit the impact of erroneous contracts. It also ensures the reliability of financial asset data and voting system data.
[0133] This embodiment maximizes the security of contract execution by combining multiple security mechanisms, thereby avoiding unnecessary financial losses;
[0134] Based on the same inventive concept, this disclosure also provides a smart contract security operation device for blockchain, as shown in the following embodiment. Since the principle by which this device embodiment solves the problem is similar to that of the above method embodiment, the implementation of this device embodiment can refer to the implementation of the above method embodiment, and repeated details will not be described again.
[0135] Figure 10 This is a block diagram illustrating a blockchain smart contract secure operation device according to an exemplary embodiment. The blockchain smart contract secure operation device 1000 provided in this disclosure embodiment can be deployed in a blockchain. (Refer to...) Figure 10 The aforementioned smart contract security operation device for the blockchain may include: a loading instruction response module 1001, an agreement loading instruction acquisition module 1002, and a loading module 1003.
[0136] The loading instruction response module 1001 can be used to respond to a loading instruction for the target contract, with the first node on the blockchain providing contract signing information to the blockchain; the consent loading instruction acquisition module 1002 can be used to receive the consent loading instruction for the target contract returned by the blockchain through the first node. The consent loading instruction is generated by the blockchain after determining that the signing object is a legitimate object. Determining that the signing object is a legitimate object means determining that the target contract is a contract generated by the signing object in a secure environment through a secure compilation method and whose business data is encrypted; the loading module 1003 can be used to load the target contract in response to the consent loading instruction through the first node.
[0137] It should be noted that the aforementioned loading instruction response module 1001, loading instruction acquisition module 1002, and loading module 1003 can correspond to S202 to S206 in the method embodiments. The examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the content disclosed in the above method embodiments. It should be noted that the above modules, as part of the apparatus, can be executed in a computer system such as a set of computer-executable instructions.
[0138] In some embodiments, the target contract is published by a second node in the blockchain; wherein, the smart contract security operation device of the blockchain may include: a signing module, a sending module, and a consent publishing instruction receiving module.
[0139] The signing module can be used to sign the target contract through the second node before responding to the loading instruction for the target contract, so as to show that the target contract was generated in a secure environment after secure compilation through the signing information; the sending module can be used to send the target contract to the blockchain through the second node after the signing is completed, and the target contract includes the contract signing information; the consent release instruction receiving module can be used to receive the consent release instruction returned by the blockchain through the second node, and the consent release instruction is generated by the blockchain after determining that the signing object is a legitimate object.
[0140] In some embodiments, a secure execution device for blockchain smart contracts may include a secure compilation module.
[0141] The secure compilation module is used to securely compile the target contract through the second node before the second node signs it. During this process, the module checks whether the contract interface and methods within the target contract conform to specifications. It also uses a blacklist to determine if the target contract contains any disabled packages, interfaces, classes, or methods. Once it is confirmed that the contract interface and methods conform to specifications and that the target contract does not contain any disabled packages, interfaces, classes, or methods, the secure compilation of the target contract is completed, allowing for its signing after secure compilation.
[0142] In some embodiments, when it is determined that the contract interface corresponding to the target contract or the method in the target contract does not conform to the specification, or when it is determined that the target contract includes a disabled package, a disabled interface, a disabled class, or a disabled method, the secure compilation of the target contract is stopped and an alarm is issued.
[0143] In some embodiments, the device for secure operation of smart contracts on a blockchain may include an encryption processing module.
[0144] The encryption module is used to encrypt sensitive business data in the target contract before the second node performs secure compilation of the target contract, in order to hide the business intent in the target contract.
[0145] In some embodiments, the loading module 1003 may include a running unit.
[0146] The running unit can be used by the first node to run the target contract in the target sandbox, so as to isolate the target contract from the blockchain on the first node through the target sandbox; the target sandbox is customized with a security policy, which is used to restrict the security permissions of the target contract when running the target contract.
[0147] In some embodiments, the first node limits the maximum execution time of the target contract through timeout configuration; the first node limits the maximum resource consumption of the target contract through resource consumption configuration; the first node limits the maximum call stack depth of the target contract through stack depth configuration; wherein, the loading module 1003 may include: a limiting unit.
[0148] The limiting unit can be used to stop loading the target contract if the execution time of the target contract exceeds the maximum time, the execution consumption of the target contract exceeds the maximum resource consumption, or the call stack depth of the target contract exceeds the maximum call stack depth.
[0149] Since the functions of the device 1000 have been described in detail in their respective method embodiments, they will not be repeated here.
[0150] The modules and / or units described in the embodiments of this application can be implemented in software or hardware. The described modules and / or units can also be located in a processor. The names of these modules and / or units do not, in some cases, constitute a limitation on the module and / or unit itself.
[0151] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0152] Furthermore, the above figures are merely illustrative of the processes included in the method according to exemplary embodiments of this disclosure and are not intended to be limiting. It is readily understood that the processes shown in the above figures do not indicate or limit the temporal order of these processes. Additionally, it is readily understood that these processes may be executed synchronously or asynchronously, for example, in multiple modules.
[0153] Figure 11 A schematic diagram of the structure of an electronic device suitable for implementing embodiments of the present disclosure is shown. It should be noted that... Figure 11 The illustrated electronic device 1100 is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments disclosed herein.
[0154] like Figure 11 As shown, the electronic device 1100 includes a central processing unit (CPU) 1101, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1102 or a program loaded from a storage section 1108 into a random access memory (RAM) 1103. The RAM 1103 also stores various programs and data required for the operation of the electronic device 1100. The CPU 1101, ROM 1102, and RAM 1103 are interconnected via a bus 1104. An input / output (I / O) interface 1105 is also connected to the bus 1104.
[0155] The following components are connected to I / O interface 1105: an input section 1106 including a keyboard, mouse, etc.; an output section 1107 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 1108 including a hard disk, etc.; and a communication section 1109 including a network interface card such as a LAN card, modem, etc. The communication section 1109 performs communication processing via a network such as the Internet. A drive 1110 is also connected to I / O interface 1105 as needed. Removable media 1111, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., are installed on drive 1110 as needed so that computer programs read from them can be installed into storage section 1108 as needed.
[0156] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a computer-readable storage medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 1109, and / or installed from removable medium 1111. When the computer program is executed by central processing unit (CPU) 1101, it performs the functions defined above in the system of this application.
[0157] It should be noted that the computer-readable storage medium disclosed herein may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium may be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable storage medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable storage medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0158] In another aspect, this application also provides a computer-readable storage medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled into the device. The aforementioned computer-readable storage medium carries one or more programs, which, when executed by the device, enable the device to perform the following functions: in response to a loading instruction for a target contract, a first node on the blockchain provides contract signing information to the blockchain, wherein the signing object in the contract signing information is a second node that generated the target contract; the first node receives a consent loading instruction for the target contract returned by the blockchain, the consent loading instruction being generated by the blockchain after determining that the signing object is a legitimate object, wherein determining that the signing object is a legitimate object means determining that the target contract is a contract generated by the signing object in a secure environment through a secure compilation method and whose business data is encrypted; the first node, in response to the consent loading instruction, loads the target contract.
[0159] According to one aspect of this application, a computer program product or computer program is provided, comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the methods provided in various optional implementations of the above embodiments.
[0160] Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions of the embodiments of this disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) and includes several instructions to cause a computing device (such as a personal computer, server, mobile terminal, or smart device, etc.) to execute the method according to the embodiments of this disclosure, for example... Figures 2-4 , Figures 6-7 One or more of the steps shown in the diagram.
[0161] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not claimed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the claims.
[0162] It should be understood that this disclosure is not limited to the detailed structures, drawing arrangements or implementations shown herein; rather, this disclosure is intended to cover various modifications and equivalent arrangements contained within the spirit and scope of the appended claims.
Claims
1. A method for securely operating smart contracts on a blockchain, characterized in that, The method includes: In response to a load instruction for the target contract, the first node on the blockchain provides contract signing information to the blockchain; The first node receives an agreement loading instruction for the target contract returned by the blockchain. The agreement loading instruction is generated by the blockchain after determining that the signing object is a legitimate object. Determining that the signing object is a legitimate object means determining that the target contract is a contract generated by the signing object in a secure environment through a secure compilation method and whose business data is encrypted. The first node, in response to the agreed loading instruction, loads the target contract; Wherein, the target contract is published by a second node in the blockchain; wherein, prior to responding to a load instruction for the target contract, the method further includes: The second node signs the target contract to demonstrate that the target contract was generated in a secure environment after secure compilation through the signing information; After the second node completes the signing, the second node sends the target contract to the blockchain, the target contract including the contract signing information; The second node receives the consent release instruction returned by the blockchain, which is generated by the blockchain after determining that the signing object is a legitimate object; The method further includes the following steps before the second node signs the target contract: The second node performs secure compilation of the target contract; During the secure compilation of the target contract in the second node, it is checked whether the contract interface corresponding to the target contract and the methods in the target contract conform to the specifications. During the secure compilation of the target contract in the second node, a blacklist is used to determine whether the target contract includes disabled packages, disabled interfaces, disabled classes, and disabled methods. Once it is determined that the contract interface corresponding to the target contract and the methods in the target contract conform to the specifications, and it is determined that the target contract does not contain disabled packages, disabled interfaces, disabled classes, and disabled methods, the secure compilation of the target contract is completed so that the target contract can be signed after the secure compilation of the target contract is completed.
2. The method according to claim 1, characterized in that, The method further includes: If it is determined that the contract interface corresponding to the target contract or the method in the target contract does not conform to the specification, or if it is determined that the target contract includes a disabled package, a disabled interface, a disabled class, or a disabled method, the secure compilation of the target contract shall be stopped and an alarm shall be issued.
3. The method according to claim 1, characterized in that, Before the second node performs secure compilation of the target contract, the method further includes: Sensitive business data in the target contract is encrypted to hide the business intent within the target contract.
4. The method according to claim 1, characterized in that, The first node loads the target contract, including: The first node runs the target contract in the target sandbox to isolate the target contract from the blockchain on the first node. The target sandbox is equipped with a security policy, which is used to restrict the security permissions of the target contract when it is run.
5. The method according to claim 1, characterized in that, The first node loads the target contract, including: The first node limits the maximum execution time of the target contract through timeout configuration; The first node limits the maximum resource consumption of the target contract through resource consumption configuration; The first node limits the maximum call stack depth of the target contract through stack depth configuration; If the execution time of the target contract exceeds the maximum time, or the execution consumption of the target contract exceeds the maximum resource consumption, or the call stack depth of the target contract exceeds the maximum call stack depth, then the first node stops loading the target contract.
6. A smart contract security operation device for blockchain, characterized in that, The smart contract security operation device is deployed in the blockchain; wherein, the smart contract security operation device includes: A loading instruction response module is used to respond to a loading instruction for a target contract by providing contract signing information to the blockchain through a first node on the blockchain; wherein the target contract is published by a second node in the blockchain; The consent loading instruction acquisition module is used to receive the consent loading instruction for the target contract returned by the blockchain through the first node. The consent loading instruction is generated by the blockchain after determining that the signing object is a legitimate object. Determining that the signing object is a legitimate object means determining that the target contract is a contract generated by the signing object in a secure environment through a secure compilation method and whose business data is encrypted. The loading module is used to load the target contract in response to the agreed loading instruction via the first node; The signing module is used to sign the target contract via a second node before responding to a load instruction for the target contract, so as to show that the target contract was generated in a secure environment after secure compilation through the signing information; The sending module is used to send the target contract to the blockchain after the second node has completed signing, the target contract including the contract signing information; A consent release instruction receiving module is used to receive a consent release instruction returned by the blockchain through the second node. The consent release instruction is generated by the blockchain after determining that the signing object is a legitimate object. A secure compilation module is used to securely compile the target contract through the second node before the second node signs the target contract. During the secure compilation process, the module checks whether the contract interface and methods of the target contract conform to specifications. It also uses a blacklist to determine whether the target contract includes disabled packages, disabled interfaces, disabled classes, and disabled methods. If the module determines that the contract interface and methods of the target contract conform to specifications and that the target contract does not contain disabled packages, disabled interfaces, disabled classes, and disabled methods, the secure compilation of the target contract is completed, allowing the target contract to be signed after secure compilation.
7. An electronic device, characterized in that, include: Memory; as well as A processor coupled to the memory, the processor being used to execute the blockchain smart contract secure operation method as described in any one of claims 1-5, based on instructions stored in the memory.
8. A computer-readable storage medium having stored thereon program instructions that, when executed by a processor, implement the secure operation method of a smart contract for a blockchain as described in any one of claims 1-5.
Citation Information
Patent Citations
Encrypted smart contract privacy protection method based on trusted execution environment
CN113726733A