Smart contract security detection method and device, equipment, storage medium and product

By selecting trusted nodes on the blockchain to decentralize the smart contracts, the problem that may be tampered with by unknown third parties during the smart contract compilation process is solved, and the security of the smart contract is improved.

CN119830287AActive Publication Date: 2025-04-15INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411973682.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-30
Publication Date
2025-04-15
Estimated Expiration
2044-12-30

AI Technical Summary

Technical Problem

In the prior art, smart contracts may be tampered with by unknown third parties during compilation, resulting in security issues.

Method used

By determining a set of blockchain nodes on the blockchain and selecting trusted nodes based on the contract attribute data, decentralized storage and compilation of the source code of the smart contract, generating authentication identifiers, and comparing whether the block identifier and authentication identifier are consistent, we can determine the security of the smart contract.

Benefits of technology

Ensure that the compiled code of the smart contract is generated by trusted nodes, improving the security of the smart contract and avoiding the situation where the code is tampered with by unknown third parties.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119830287A_ABST
    Figure CN119830287A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a smart contract security detection method and device, equipment, a storage medium and a product, and relates to the technical field of block chains. The method comprises the following steps: determining a group of block chain nodes according to contract attribute data to obtain at least one trusted node; performing decentralized storage processing on the source code of the smart contract to store the source code of the smart contract to a plurality of block chain nodes in a block manner; the source code of the smart contract is compiled through each trusted node until the last trusted node is compiled, a compiled code corresponding to each trusted node is obtained, and an authentication identifier is generated according to the certificate of each trusted node; and judging whether the block identifier of the source code corresponding to each trusted node is consistent with the authentication identifier, and when the detection result is consistent, obtaining a security detection result that the smart contract detection is passed. The method is used for solving the technical problem that the code of the smart contract is tampered by an unknown third party.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of blockchain technology, and in particular to a smart contract security detection method, device, equipment, storage medium and product. Background Art

[0002] Blockchain is a decentralized distributed ledger that is tamper-proof, secure and reliable. It combines distributed storage, peer-to-peer transmission, consensus mechanism, cryptography and other technologies to record transactions and information through a growing data chain (Blocks) to ensure data security and transparency. Smart contracts are self-executing programs that automatically trigger pre-defined actions when specific conditions are met. They usually run on blockchains to ensure data immutability and transparency. Smart contracts handle value and sensitive data, so it is crucial to protect them from attacks and vulnerabilities. Security issues may lead to financial losses, data leaks and paralysis of contract functions. Therefore, smart contracts are often tested for security.

[0003] In the prior art, a legal compilation tool is used to compile a smart contract. When a smart contract is generated, a signature is also generated. The signature is used to determine that the smart contract is compiled by the legal compilation tool. When the security of the smart contract is tested, the security test is performed on the legal compilation tool, that is, the security test result of the smart contract is determined by testing the signature.

[0004] The inventors have discovered that there are at least the following technical problems in the prior art: when the compilation tool is compiling a smart contract, the code may be tampered with by an unknown third party, causing security issues in the smart contract. Summary of the invention

[0005] The present application provides a smart contract security detection method, device, equipment, storage medium and product to solve the technical problem that the code of the smart contract is tampered with by an unknown third party.

[0006] In a first aspect, the present application provides a smart contract security detection method, comprising:

[0007] Obtaining source code and contract attribute data of the smart contract, wherein the contract attribute data is pre-set in the blockchain;

[0008] Determine a group of blockchain nodes according to the contract attribute data, and perform trusted node selection processing according to the group of blockchain nodes to obtain at least one trusted node;

[0009] The source code of the smart contract is subjected to decentralized storage processing, so as to store the source code of the smart contract in blocks to multiple blockchain nodes, wherein each blockchain node also stores multiple block identifiers of the smart contract;

[0010] Compile the source code of the smart contract through each trusted node until the last trusted node is compiled, obtain the compiled code corresponding to each trusted node, and generate an authentication mark according to the certificate of each trusted node;

[0011] Determine whether the block identifier and authentication identifier of the source code corresponding to each trusted node are consistent. When the test result is consistent, the security test result that the smart contract passes the test is obtained.

[0012] In a second aspect, the present application provides a smart contract security detection device, comprising:

[0013] An acquisition module, used to acquire the source code and contract attribute data of the smart contract, wherein the contract attribute data is pre-set in the blockchain;

[0014] A trusted node determination module, used to determine a group of blockchain nodes according to the contract attribute data, and perform trusted node selection processing according to the group of blockchain nodes to obtain at least one trusted node;

[0015] A source code storage module, used to perform decentralized storage processing on the source code of the smart contract, so as to store the source code of the smart contract in a block manner to multiple blockchain nodes, wherein each blockchain node also stores multiple block identifiers of the smart contract;

[0016] A compilation module, used to compile the source code of the smart contract through each trusted node until the last trusted node is compiled, obtain the compiled code corresponding to each trusted node, and generate an authentication identifier according to the certificate of each trusted node;

[0017] The detection and judgment module is used to determine whether the block identifier and authentication identifier of the source code corresponding to each trusted node are consistent. When the detection result is consistent, the security detection result of the smart contract passing the detection is obtained.

[0018] In a third aspect, the present application provides an electronic device, comprising: a processor, and a memory communicatively connected to the processor;

[0019] The memory stores computer-executable instructions;

[0020] The processor executes the computer-executable instructions stored in the memory to implement the method described in the first aspect.

[0021] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the method described in the first aspect.

[0022] In a fifth aspect, the present application provides a computer program product, comprising a computer program, which implements the method described in the first aspect when executed by a processor.

[0023] The present application provides a smart contract security detection method, device, equipment, storage medium and product, wherein the method first determines a group of blockchain nodes according to the contract attribute data pre-set in the blockchain, and then performs trusted node selection processing according to the group of blockchain nodes to obtain at least one trusted node. Then, the source code of the smart contract is decentralized and stored in multiple blockchain nodes in a block manner, and each blockchain node also stores a block identifier corresponding to the encrypted smart contract block. Then, the source code of the smart contract is compiled by each trusted node until the last trusted node is compiled, and the compiled code corresponding to each trusted node is obtained, and the authentication identifier is generated according to the certificate of each trusted node. In this way, the security of the compiled code compiled by the trusted node is more guaranteed, and finally the source code and the compiled code identifier are compared to see if they are consistent, and the final security check result is obtained. Ensure that the smart contract composed of all compiled codes is credible, avoid the situation where the code is tampered by an unknown third party during the compilation of the smart contract, and improve the security of the smart contract. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0025] Figure 1 Schematic diagram of an application scenario of the smart contract security detection method provided in an embodiment of the present application.

[0026] Figure 2 A flowchart of a smart contract security detection method provided in an embodiment of the present application.

[0027] Figure 3 A schematic diagram of the overall structure of the smart contract security detection device provided in an embodiment of the present application.

[0028] Figure 4 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application.

[0029] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION

[0030] 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 the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0031] It should be noted that the smart contract security detection method, device, equipment, storage medium and product provided in this application can be used in the field of blockchain technology, and can also be used in any field outside the field of blockchain technology. The application field of the smart contract security detection method, device, equipment, storage medium and product in this application is not limited.

[0032] Figure 1 Schematic diagram of an application scenario of the smart contract security detection method provided in an embodiment of the present application.

[0033] like Figure 1 As shown, the scenario includes a smart contract development end 101 and a blockchain 102.

[0034] Among them, the smart contract development end 101 can be a computer device, which can be used to install legal compilation tools. The smart contract development end 101 can generate a smart contract in response to the smart contract development operation of the developer, and deploy the smart contract to the blockchain 102. The blockchain 102 can include multiple blockchain nodes, and different participants can link with the nodes to form a consortium chain. After the smart contract is deployed on the blockchain 102, it will automatically trigger pre-defined operations to ensure the immutability and transparency of the data, avoid losses, data leakage, and contract function paralysis. It is very important to perform security testing on smart contracts.

[0035] In the prior art, after a legal compilation tool compiles a smart contract, a signature is generated to confirm that the smart contract is compiled by the legal compilation tool. By detecting the signature, it is determined whether the smart contract is compiled by the legal compilation tool, and the smart contract security detection result is obtained.

[0036] When using the existing smart contract security detection method, the inventor found that when the developer uses legal compilation tools to compile the smart contract, the code may be tampered with by an unknown third party, causing security problems in the smart contract.

[0037] To this end, an embodiment of the present application provides a smart contract security detection method, which aims to authenticate the legitimacy of the code compilation in the smart contract through a trusted node on the blockchain, that is, only different participants can compile the source code of the smart contract through a trusted node, thereby ensuring the security of the smart contract to solve the above technical problems of the prior art.

[0038] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0039] Figure 2 A flow chart of a smart contract security detection method provided in an embodiment of the present application. The execution subject of the smart contract security detection method may be as follows: Figure 1 Any trusted node on the blockchain 102 shown. It can also be a computer-related device that becomes a trusted node after establishing a link with the blockchain 102. This embodiment does not limit this.

[0040] like Figure 2 As shown, the smart contract security detection method includes the following steps:

[0041] S201: Obtain smart contract source code and contract attribute data, where the contract attribute data is pre-set in the blockchain.

[0042] In this embodiment, the smart contract source code is developed and generated by the developer according to business requirements, and the contract attribute data may be information representing different attributes of the smart contract in the blockchain, such as: business type, smart contract developer, and smart contract participants. These contract attribute data may be pre-set in the blockchain according to business development requirements.

[0043] S202: Determine a group of blockchain nodes based on the contract attribute data, and perform trusted node selection processing based on the group of blockchain nodes to obtain at least one trusted node.

[0044] In this embodiment, the blockchain node refers to the node through which different participants in the alliance chain can access the complete smart contract. The blockchain node includes a compilation node and an execution node. At least one trusted node can be one or more trusted nodes. When it is a trusted node, it means that the computing power of other trusted nodes is insufficient. If the computing power of two or more trusted nodes is sufficient, multiple trusted nodes are obtained.

[0045] In an optional embodiment of the present application, the contract attribute data includes node contract attributes deployed by each blockchain node, and there is an association relationship between each node contract attribute and the attribute of the blockchain node;

[0046] Accordingly, according to the contract attribute data, a group of blockchain nodes is determined, including:

[0047] S202a: According to the contract attribute data, all blockchain nodes are matched through the association relationship between each node contract attribute and the attribute of the blockchain node to determine a group of blockchain nodes.

[0048] In this embodiment, the contract attribute data can be used to know the attribute information of all blockchain nodes associated with the smart contract. For example, the smart contract participant information in the smart contract attributes includes the configuration information of the server connected to the blockchain node A. At this time, a matching operation can be performed through the comparator to obtain each node associated with the smart contract attribute as a group of blockchain nodes.

[0049] In an optional embodiment of the present application, a trusted node selection process is performed according to a group of blockchain nodes to obtain one or more trusted nodes, including:

[0050] S202b: Perform trusted node selection processing based on a group of blockchain nodes through consensus or election operations to obtain one or more trusted nodes.

[0051] In this embodiment, the consensus or election operation includes: randomly selecting a compiling node as a trusted node, and the basis for random selection is to determine a node with better computing power according to node performance. This group of blockchain nodes includes compiling nodes and execution nodes, and the trusted node is the compiling node.

[0052] In this embodiment, trusted nodes are selected through consensus or election operations, which improves the credibility of trusted nodes, reduces the number of nodes for subsequent source code compilation, reduces the frequency of checking the security of compiled code, and thereby improves the efficiency of security checks.

[0053] S203: Decentralize the storage of the source code of the smart contract to store the source code of the smart contract in blocks to multiple blockchain nodes, where each blockchain node also stores multiple block identifiers of the smart contract.

[0054] In this embodiment, decentralized storage processing refers to the process of distributing and storing data on multiple nodes.

[0055] Specifically, in an optional embodiment of the present application, step S203 includes:

[0056] S203a: Split the source code of the smart contract to obtain smart contract blocks.

[0057] In this embodiment, the smart contract block can be a data block containing part of the source code of the smart contract. The segmentation process refers to dividing the source code of the smart contract into multiple small blocks containing the source code, and all the small blocks can form the complete source code of the smart contract.

[0058] S203b: Encrypt the smart contract blocks to obtain encrypted smart contract blocks.

[0059] In this embodiment, the encryption process may be to encrypt the source code in the smart contract block by using an encryption algorithm and a key to obtain the encrypted source code. The encrypted smart contract block needs to be decrypted before subsequent operations can be performed. For example, in this embodiment, the encryption algorithm may be a symmetric encryption algorithm.

[0060] S203c: Storing the encrypted smart contract block in multiple blockchain nodes, each blockchain node also stores a block identifier corresponding to the encrypted smart contract block.

[0061] In this embodiment, the encrypted smart contract block can be stored in multiple blockchain nodes according to the execution steps and execution nodes of the smart contract. The block identifier can be information indicating the uniqueness of the smart contract source code.

[0062] In this embodiment, the source code of the smart contract is first split by segmentation and then encrypted to improve the security of the source code and prevent it from being tampered with by an unknown third party.

[0063] S204: Compile the source code of the smart contract through each trusted node until the last trusted node is compiled, obtain the compiled code corresponding to each trusted node, and generate an authentication identifier based on the certificate of each trusted node.

[0064] In this embodiment, each trusted node compiles the source code contained in the encrypted smart contract block to obtain the corresponding compiled code. All compiled codes can form a complete smart contract, which can complete the steps described in the business requirements. The authentication identifier can be information indicating the uniqueness of the compiled code, which is used in the subsequent security detection process.

[0065] S205: Determine whether the block identifier and authentication identifier of the source code corresponding to each trusted node are consistent. When the test result is consistent, a security test result indicating that the smart contract has passed the test is obtained.

[0066] In this embodiment, whether the block identifier and the authentication identifier of the source code corresponding to each trusted node are consistent can be determined by comparing them through a comparison tool such as a comparator. If the detection results of the block identifier and the authentication identifier are consistent, it indicates that the source code has not been tampered with in the process of being compiled into compiled code. Finally, the security test of the entire smart contract obtained based on all compiled codes passes, and the smart contract is trustworthy and can complete the final chain operation, providing convenience for subsequent business.

[0067] The smart contract security detection method provided in an optional embodiment of the present application also includes: when an identification inconsistency is detected, a security detection result indicating that the smart contract has failed the detection is obtained.

[0068] In summary, the smart contract security detection method provided by the embodiment of the present application first determines a group of blockchain nodes according to the contract attribute data pre-set in the blockchain, and then performs trusted node selection processing according to a group of blockchain nodes to obtain at least one trusted node. Then the source code of the smart contract is decentralized and stored, and the source code of the smart contract is stored in multiple blockchain nodes in a block manner, and each blockchain node also stores a block identifier corresponding to the encrypted smart contract block. Then, the source code of the smart contract is compiled by each trusted node, until the last trusted node is compiled, and the compiled code corresponding to each trusted node is obtained, and the authentication identifier is generated according to the certificate of each trusted node. In this way, the security of the compiled code compiled by the trusted node is more guaranteed, and finally the source code and the compiled code identifier are compared to see if they are consistent, and the final security check result is obtained. Ensure that the smart contract composed of all compiled codes is credible, avoid the situation where the code is tampered by an unknown third party during the compilation of the smart contract, and improve the security of the smart contract.

[0069] The smart contract security detection method provided in an optional embodiment of the present application, when compiling the source code of the smart contract through each trusted node, further includes:

[0070] S204a: Multiple trusted nodes perform information exchange operations through the blockchain, so that each trusted node obtains the compilation status information of other trusted nodes, and determines whether other trusted nodes have completed compilation based on the compilation status information.

[0071] S204b: When it is detected that the last trusted node has completed compilation, the process jumps to the step of determining whether the block identifier and the authentication identifier of the source code corresponding to each trusted node are consistent.

[0072] In this embodiment, the signal interaction operation can be mutual access between the trusted nodes in the blockchain, and the interactive compilation process information can be used to quickly perform subsequent security checks as soon as all the last trusted nodes on the blockchain complete the compilation, thereby improving the efficiency of the security check.

[0073] Based on the above embodiment, in an optional embodiment of the present application, before the source code of the smart contract is compiled by each trusted node, it also includes:

[0074] Step A: Determine whether the source code of the smart contract is submitted by a trusted node.

[0075] Step B: If yes, jump to the step of compiling the source code of the smart contract according to the corresponding source code through each trusted node.

[0076] In this embodiment, by judging whether the source code is submitted by a trusted node or an untrusted node, the security check work before compiling the source code can be saved, and the subsequent compilation and security detection steps can be directly entered, thereby improving the security detection efficiency.

[0077] In an optional embodiment of the present application, after determining whether the source code of the smart contract is submitted by a trusted node, the process further includes:

[0078] Step C: If not, perform a regular security test on the source code of the smart contract submitted by the untrusted node to obtain the smart contract test result corresponding to the untrusted node.

[0079] In this embodiment, by performing conventional security checks on the source code of the smart contract submitted by the untrusted node, the security of the final smart contract can be improved to avoid the situation where the source code has been tampered with before being stored on the blockchain node, further improving the security of the smart contract.

[0080] Based on the above embodiment, in an optional embodiment of the present application, a conventional security test is performed on the source code of the smart contract submitted by the untrusted node, including:

[0081] Perform code source detection on the block identifiers of the source code of the smart contract submitted by the untrusted node to obtain the source detection result; or

[0082] Perform code vulnerability detection on the source code of the smart contract submitted by the untrusted node to obtain the code vulnerability detection result.

[0083] In this embodiment, the signature in the block identifier, such as the developer information, is used to determine whether the source code of the smart contract submitted by the untrusted node is safe, or a code vulnerability detection tool is used to detect whether the source code has security issues such as code vulnerabilities. This provides the first security guarantee for the subsequent compilation and security check process of the source code of the smart contract submitted by the untrusted node.

[0084] The overall structural diagram of the smart contract security detection device provided in the embodiment of the present application is credible.

[0085] like Figure 3 As shown, the smart contract security detection device provided in the embodiment of the present application includes: an acquisition module 31, a trusted node determination module 32, a source code storage module 33, a compilation module 34 and a detection and judgment module 35.

[0086] The acquisition module 31 is used to obtain the source code and contract attribute data of the smart contract, wherein the contract attribute data is pre-set in the blockchain.

[0087] The trusted node determination module 32 is used to determine a group of blockchain nodes according to the contract attribute data, and perform trusted node selection processing based on the group of blockchain nodes to obtain at least one trusted node.

[0088] The source code storage module 33 is used to perform decentralized storage processing on the source code of the smart contract, so as to store the source code of the smart contract in blocks to multiple blockchain nodes, wherein each blockchain node also stores multiple block identifiers of the smart contract.

[0089] The compilation module 34 is used to compile the source code of the smart contract through each trusted node until the last trusted node is compiled, obtain the compiled code corresponding to each trusted node, and generate an authentication identifier based on the certificate of each trusted node.

[0090] The detection and judgment module 35 is used to determine whether the block identifier and the authentication identifier of the source code corresponding to each trusted node are consistent. When the detection result is consistent, the security detection result that the smart contract passes the detection is obtained.

[0091] In an optional embodiment of the present application, the trusted node determination module 32 is specifically used to: perform trusted node selection processing based on a group of blockchain nodes through consensus or election operations to obtain one or more trusted nodes.

[0092] In an optional embodiment of the present application, the source code storage module 33 is specifically used to: split the source code of the smart contract to obtain smart contract blocks; encrypt the smart contract blocks to obtain encrypted smart contract blocks; store the encrypted smart contract blocks in multiple blockchain nodes, and each blockchain node also stores a block identifier corresponding to the encrypted smart contract block.

[0093] In an optional embodiment of the present application, the compilation module 34 is also used for: performing information exchange operations between multiple trusted nodes through the blockchain, so that each trusted node obtains the compilation status information of other trusted nodes, and determines whether other trusted nodes have completed the compilation based on the compilation status information; when it is detected that the last trusted node has completed the compilation, jump to the step of determining whether the block identifier and the authentication identifier of the source code corresponding to each trusted node are consistent.

[0094] In an optional embodiment of the present application, the acquisition module 31 is also used to: determine whether the source code of the smart contract is submitted by a trusted node; if so, jump to the step of compiling the source code of the smart contract according to the corresponding source code through each trusted node.

[0095] In an optional embodiment of the present application, the judgment detection module 35 is also used to: if not, perform a conventional security test on the source code of the smart contract submitted by the untrusted node to obtain the smart contract detection result corresponding to the untrusted node.

[0096] In an optional embodiment of the present application, the judgment detection module 35 is specifically used to: perform code source detection on the block identifiers of the source code of the smart contract submitted by the untrusted node to obtain a source detection result; or perform code vulnerability detection on the source code of the smart contract submitted by the untrusted node to obtain a code vulnerability detection result.

[0097] The smart contract security detection device provided in this embodiment can be used to execute the above Figure 2 The technical solution of the method embodiment shown has similar implementation principles and technical effects, and will not be described in detail in this embodiment.

[0098] Figure 4 The hardware structure diagram of the electronic device provided in the embodiment of the present application is shown in FIG. Figure 4 As shown, the electronic device includes: a processor 401 and a memory 402 communicatively connected to the processor 401 .

[0099] The memory 402 stores computer-executable instructions.

[0100] The processor 401 executes the computer-executable instructions stored in the memory 402 to implement the various steps involved in the method embodiment of the above-mentioned smart contract security detection method. For details, please refer to the relevant description in the above-mentioned method embodiment.

[0101] Optionally, the memory 402 may be independent or integrated with the processor 401 .

[0102] When the memory 402 is independently provided, the electronic device further includes a bus 403 for connecting the memory 402 and the processor 401 .

[0103] An embodiment of the present application also provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, the above-mentioned smart contract security detection method is implemented.

[0104] An embodiment of the present application also provides a computer program product, including a computer program, which implements the above smart contract security detection method when executed by a processor.

[0105] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.

[0106] It should be further noted that, although the various steps in the flowchart are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowchart may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.

[0107] It should be understood that the above-mentioned device embodiments are only illustrative, and the device of the present application can also be implemented in other ways. For example, the division of units / modules in the above-mentioned embodiments is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units, modules or components can be combined, or can be integrated into another system, or some features can be ignored or not executed.

[0108] In addition, unless otherwise specified, each functional unit / module in each embodiment of the present application may be integrated into one unit / module, each unit / module may exist physically separately, or two or more units / modules may be integrated together. The above-mentioned integrated unit / module may be implemented in the form of hardware or in the form of a software program module.

[0109] If the integrated unit / module is implemented in the form of hardware, the hardware may be a digital circuit, an analog circuit, etc. The physical implementation of the hardware structure includes but is not limited to transistors, memristors, etc. Unless otherwise specified, the processor may be any appropriate hardware processor, such as a CPU, a GPU, an FPGA, a DSP, an ASIC, etc. Unless otherwise specified, the storage unit may be any appropriate magnetic storage medium or magneto-optical storage medium, such as a resistive random access memory (RRAM), a dynamic random access memory (DRAM), a static random access memory (SRAM), an enhanced dynamic random access memory (EDRAM), a high-bandwidth memory (HBM), a hybrid memory cube (HMC), etc.

[0110] If the integrated unit / module is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a memory, including a number of instructions to enable a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned memory includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or CD-ROM and other media that can store program codes.

[0111] In the above embodiments, the description of each embodiment has its own emphasis. For the part not described in detail in a certain embodiment, please refer to the relevant description of other embodiments. The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0112] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.

[0113] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A smart contract security detection method, characterized in that: include: Obtaining source code and contract attribute data of the smart contract, wherein the contract attribute data is pre-set in the blockchain; Determine a group of blockchain nodes according to the contract attribute data, and perform trusted node selection processing according to the group of blockchain nodes to obtain at least one trusted node; The source code of the smart contract is subjected to decentralized storage processing, so as to store the source code of the smart contract in blocks to multiple blockchain nodes, wherein each blockchain node also stores multiple block identifiers of the smart contract; Compile the source code of the smart contract through each trusted node until the last trusted node is compiled, obtain the compiled code corresponding to each trusted node, and generate an authentication mark according to the certificate of each trusted node; Determine whether the block identifier and authentication identifier of the source code corresponding to each trusted node are consistent. When the test result is consistent, the security test result that the smart contract passes the test is obtained.

2. The method according to claim 1, characterized in that: The step of performing trusted node selection processing according to the group of blockchain nodes to obtain one or more trusted nodes includes: A trusted node selection process is performed according to the group of blockchain nodes through consensus or election operations to obtain one or more trusted nodes.

3. The method according to claim 1, characterized in that The decentralized storage processing of the source code of the smart contract to store the source code of the smart contract in blocks to multiple blockchain nodes includes: Splitting the source code of the smart contract to obtain smart contract blocks; Encrypting the smart contract blocks to obtain encrypted smart contract blocks; The encrypted smart contract block is stored in multiple blockchain nodes, and each blockchain node also stores a block identifier corresponding to the encrypted smart contract block.

4. The method according to claim 1, characterized in that: When the source code of the smart contract is compiled by each trusted node, it also includes: Multiple trusted nodes interact with each other through blockchain, so that each trusted node can obtain the compilation status information of other trusted nodes and determine whether other trusted nodes have completed compilation based on the compilation status information. When it is detected that the last trusted node has completed compilation, the process jumps to the step of determining whether the block identifier and the authentication identifier of the source code corresponding to each trusted node are consistent.

5. The method according to any one of claims 1 to 4, characterized in that Before the source code of the smart contract is compiled by each trusted node, the process further includes: Determine whether the source code of the smart contract is submitted by a trusted node; If so, jump to the step of compiling the source code of the smart contract according to the corresponding source code through each trusted node.

6. The method according to claim 5, characterized in that After determining whether the source code of the smart contract is submitted by a trusted node, the method further includes: If not, a conventional security test is performed on the source code of the smart contract submitted by the untrusted node to obtain the smart contract test result corresponding to the untrusted node.

7. The method according to any one of claims 6, characterized in that The conventional security testing of the source code of the smart contract submitted by the untrusted node includes: Perform code source detection on the block identifiers of the source code of the smart contract submitted by the untrusted node to obtain a source detection result; or Perform code vulnerability detection on the source code of the smart contract submitted by the untrusted node to obtain a code vulnerability detection result.

8. A smart contract security detection device, characterized in that: include: An acquisition module, used to acquire the source code and contract attribute data of the smart contract, wherein the contract attribute data is pre-set in the blockchain; A trusted node determination module, used to determine a group of blockchain nodes according to the contract attribute data, and perform trusted node selection processing according to the group of blockchain nodes to obtain at least one trusted node; A source code storage module, used to perform decentralized storage processing on the source code of the smart contract, so as to store the source code of the smart contract in a block manner to multiple blockchain nodes, wherein each blockchain node also stores multiple block identifiers of the smart contract; A compilation module, used to compile the source code of the smart contract through each trusted node until the last trusted node is compiled, obtain the compiled code corresponding to each trusted node, and generate an authentication identifier according to the certificate of each trusted node; The detection and judgment module is used to determine whether the block identifier and authentication identifier of the source code corresponding to each trusted node are consistent. When the detection result is consistent, the security detection result of the smart contract passing the detection is obtained.

9. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 7 when executed by a processor.

11. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 7 when being executed by a processor.

Citation Information

Patent Citations

  • Method, device and storage medium for installing intelligent contract in block chain network

    CN109213501A

  • Block chain alliance chain intelligent contract iteration method, system and device

    CN115495090A

  • Block chain system, intelligent contract synchronization method, computer equipment and storage medium

    CN117333175A

  • Code development method and device for smart contract, equipment, medium and program product

    CN118778938A

  • Group collaborative decision-making by decentralized network nodes

    WO2020058655A1