Smart contract scanning method and device, computer equipment and storage medium
By generating and executing scanning scripts, multiple scanning operators are used to perform multi-dimensional scanning of smart contracts, which solves the problem of low efficiency of traditional scanning and realizes an automated and efficient smart contract scanning process.
Patent Information
- Application Number
- CN202310475626.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-25
- Publication Date
- 2024-10-25
AI Technical Summary
Traditional smart contract scanning methods are inefficient, causing developers to waste time and inefficiency from contract code submission to receiving contract security test reports.
By responding to the smart contract scanning trigger event, the target smart contract is determined and multi-dimensional scanning parameters are obtained, a scanning script is generated, multiple scanning operators are used for scanning detection, and the scanning results are automatically output to realize multi-dimensional automatic scanning.
The efficiency of smart contract scanning is improved. The entire process does not require external intervention and can be completed automatically in a streamlined manner, quickly generating scan results.
Smart Images

Figure CN118839337A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a smart contract scanning method, apparatus, computer equipment, storage medium and computer program product. Background Art
[0002] Blockchain is a technology that is jointly maintained by multiple parties, uses cryptography to ensure transmission and access security, and can achieve consistent data storage, is difficult to tamper with, and prevents denial of ownership. It is also called distributed ledger technology. Smart contracts usually refer to unchangeable computer programs written in a specific high-level language, running on a blockchain virtual machine, and implementing decentralized applications in a deterministic manner.
[0003] Traditional security testing for smart contracts is divided into static scanning and dynamic scanning. Static scanning mainly involves secondary analysis of the contract's ast file, while dynamic scanning mainly involves deploying the contract to the blockchain and performing runtime vulnerability scanning. Based on the traditional smart contract scanning method, developers waste a certain amount of time from submitting the contract code to receiving the contract security test report, which leads to low efficiency. Summary of the invention
[0004] Based on this, it is necessary to provide a smart contract scanning method, device, computer equipment, computer-readable storage medium and computer program product that can improve scanning efficiency in response to the above technical problems.
[0005] In a first aspect, the present application provides a smart contract scanning method. The method comprises:
[0006] In response to a smart contract scanning trigger event, determine a target smart contract to be scanned, and obtain multi-dimensional scanning parameters matching the smart contract scanning trigger event;
[0007] Based on the target smart contract and the multi-dimensional scanning parameters, a scanning script for triggering the operation of a scanning tool is generated; the scanning tool is deployed with multiple scanning operators;
[0008] Execute the scanning script so that the scanning tool scans and detects the target smart contract through a scanning operator that matches the scanning parameters, and obtains detection data that matches the scanning parameters of each dimension;
[0009] By executing the scan result output command in the scan script, a smart contract scan result containing each of the detection data is generated and output.
[0010] In a second aspect, the present application also provides a smart contract scanning device. The device comprises:
[0011] A trigger response module, configured to determine a target smart contract to be scanned in response to a smart contract scanning trigger event, and obtain multi-dimensional scanning parameters configured for the target smart contract;
[0012] A script generation module, used to generate a scanning script for triggering the operation of a scanning tool based on the multi-dimensional scanning parameters; the scanning tool is deployed with multiple scanning operators;
[0013] A scanning detection module, used to execute the scanning script so that the scanning tool scans and detects the target smart contract through a scanning operator that matches the scanning parameters, and obtains detection data that matches the scanning parameters of each dimension;
[0014] The result output module is used to generate and output the smart contract scanning result containing each of the detection data by executing the scanning result output command in the scanning script.
[0015] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0016] In response to a smart contract scanning trigger event, determine a target smart contract to be scanned, and obtain multi-dimensional scanning parameters matching the smart contract scanning trigger event;
[0017] Based on the target smart contract and the multi-dimensional scanning parameters, a scanning script for triggering the operation of a scanning tool is generated; the scanning tool is deployed with multiple scanning operators;
[0018] Execute the scanning script so that the scanning tool scans and detects the target smart contract through a scanning operator that matches the scanning parameters, and obtains detection data that matches the scanning parameters of each dimension;
[0019] By executing the scan result output command in the scan script, a smart contract scan result containing each of the detection data is generated and output.
[0020] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0021] In response to a smart contract scanning trigger event, determine a target smart contract to be scanned, and obtain multi-dimensional scanning parameters matching the smart contract scanning trigger event;
[0022] Based on the target smart contract and the multi-dimensional scanning parameters, a scanning script for triggering the operation of a scanning tool is generated; the scanning tool is deployed with multiple scanning operators;
[0023] Execute the scanning script so that the scanning tool scans and detects the target smart contract through a scanning operator that matches the scanning parameters, and obtains detection data that matches the scanning parameters of each dimension;
[0024] By executing the scan result output command in the scan script, a smart contract scan result containing each of the detection data is generated and output.
[0025] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0026] In response to a smart contract scanning trigger event, determine a target smart contract to be scanned, and obtain multi-dimensional scanning parameters matching the smart contract scanning trigger event;
[0027] Based on the target smart contract and the multi-dimensional scanning parameters, a scanning script for triggering the operation of a scanning tool is generated; the scanning tool is deployed with multiple scanning operators;
[0028] Execute the scanning script so that the scanning tool scans and detects the target smart contract through a scanning operator that matches the scanning parameters, and obtains detection data that matches the scanning parameters of each dimension;
[0029] By executing the scan result output command in the scan script, a smart contract scan result containing each of the detection data is generated and output.
[0030] The above-mentioned smart contract scanning method, device, computer equipment, storage medium and computer program product, by responding to the smart contract scanning trigger event, determine the target smart contract to be scanned, and obtain the multi-dimensional scanning parameters matching the smart contract scanning trigger event, so as to automatically generate a scanning script based on the target smart contract and the multi-dimensional scanning parameters to trigger the scanning tool to work. Since the scanning tool is deployed with multiple scanning operators, it can realize multi-dimensional smart contract scanning. In the implementation process, the scanning tool is started by executing the scanning script, so that the scanning tool scans and detects the target smart contract through the scanning operator matching the scanning parameter, and obtains the detection data matching the scanning parameters of each dimension, so as to realize multi-dimensional automatic scanning. By executing the scanning result output command in the scanning script, the scanning tool can be automatically triggered to scan through the scanning script, and the smart contract scanning result containing each detection data is quickly generated and output. The whole process does not require external intervention and can be completed automatically in a pipeline manner, which effectively improves the efficiency of scanning the target smart contract. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 An application environment diagram of a smart contract scanning method in one embodiment;
[0032] Figure 2 Schematic diagram of a flow chart of a smart contract scanning method in one embodiment;
[0033] Figure 3 A schematic diagram of the relationship between the first step and the second step of the pipeline mechanism in one embodiment;
[0034] Figure 4 A schematic diagram of the relationship between various steps of a pipeline mechanism in an embodiment;
[0035] Figure 5 A schematic diagram of an interface for configuring a triggered event type in an embodiment;
[0036] Figure 6 A schematic diagram of an interface showing smart contract scanning results in one embodiment;
[0037] Figure 7 A schematic diagram of an interface showing a smart contract call relationship diagram in one embodiment;
[0038] Figure 8 A schematic diagram of an interface showing a smart contract control flow graph in one embodiment;
[0039] Fig. 9 It is a structural block diagram of a smart contract scanning device in one embodiment;
[0040] Fig.10 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0042] Blockchain is a technology that is jointly maintained by multiple parties, uses cryptography to ensure transmission and access security, and can achieve consistent data storage, is difficult to tamper with, and prevents denial of ownership. It is also called distributed ledger technology. Smart contracts usually refer to unchangeable computer programs written in high-level languages such as solidity and vyper, running on blockchain virtual machines to implement decentralized applications in a deterministic manner. Smart contracts can be understood as computer programs that run on blockchains with preset rules, states, and conditional responses, can encapsulate, verify, and execute complex behaviors of distributed nodes, and complete information exchange, value transfer, and asset management. Based on the distributed architecture and consensus algorithm of blockchain, smart contracts allow users who do not trust each other to complete transactions without the need for any third-party trusted intermediary or authority. At the same time, digital smart contracts can be flexibly embedded in various tangible or intangible assets, transactions, and data to achieve active or passive asset and information management and control, and gradually build programmable smart assets and systems.
[0043] In the blockchain system, smart contracts can be understood as a code that can be understood and executed by each node of the blockchain (including consensus nodes), which can execute any logic and obtain results. Business objects (which can be users who request to execute transaction services or users who request to deploy smart contracts) can call smart contracts that have been deployed in the blockchain system by initiating a contract call request (also called a transaction service request) through the client on the user terminal. It should be understood that the blockchain system may include one or more smart contracts, which can be distinguished by contract identifiers (such as identification numbers (ID) or names, and can also include contract addresses or contract function names (also called contract method names)), and the contract call request initiated by the client can also carry the address, identification number or name of the smart contract to specify the smart contract that the blockchain needs to run. If the smart contract specified by the client is a contract that needs to read data, the relevant nodes will access the local storage to read the data. For transactions that need to be on the chain, the consensus nodes will finally verify whether the execution results are consistent with each other (that is, consensus is reached). If they are consistent, the execution results can be stored in their respective local ledgers and returned to the client.
[0044] Smart contracts are essentially computer program codes. Traders can convert the content and execution conditions of their contracts into recognizable program codes through computers. When the conditions set by the program are met, the system is triggered to automatically execute the corresponding contract terms, thereby realizing the transaction. Smart contracts on the blockchain can be widely used in fields such as evidence storage, energy, finance, and charity. However, in the process of using smart contracts, due to the developers' programming habits, boundaries, or special circumstances, they may encounter a variety of security issues such as permission control, integer overflow, and business logic implementation. These problems will cause significant economic and resource losses. With the explosive growth of smart contracts, there are more and more incidents caused by smart contract security issues. Since smart contracts cannot be modified once deployed, this means that once there is a bug in the code, it is very likely to be exploited. The fault tolerance rate of smart contracts is extremely low. Therefore, it is necessary to perform security testing by scanning smart contracts before deploying them on the blockchain.
[0045] The smart contract scanning method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other servers. The server 104 determines the target smart contract to be scanned by responding to the smart contract scan trigger event, and obtains the multi-dimensional scanning parameters that match the smart contract scan trigger event, and generates a scanning script for triggering the scanning tool based on the target smart contract and the multi-dimensional scanning parameters; the scanning tool is deployed with multiple scanning operators; execute the scanning script so that the scanning tool scans and detects the target smart contract through the scanning operator that matches the scanning parameter, and obtains the detection data that matches each dimension of the scanning parameter; by executing the scan result output command in the scanning script, a smart contract scanning result containing each detection data is generated, and the smart contract scanning result is sent to the terminal 102 logged in by the developer of the target smart contract, so that the developer can repair the vulnerability of the target smart contract based on the vulnerability problems found in the smart contract scanning result.
[0046] The terminal 102 may be, but is not limited to, various desktop computers, laptop computers, smart phones, tablet computers, IoT devices, and portable wearable devices. The IoT devices may be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. The portable wearable devices may be smart watches, smart bracelets, head-mounted devices, etc. The server 104 may be implemented as an independent server or a server cluster consisting of multiple servers.
[0047] In one embodiment, Figure 2As shown, a smart contract scanning method is provided, and the method is applied to a computer device as an example for explanation. The computer device can be used as a scanning platform. The computer device can be specifically Figure 1 In other embodiments, the computer device may also be a terminal capable of implementing the following method steps. The smart contract scanning method includes the following steps:
[0048] Step 202, in response to a smart contract scanning trigger event, determine a target smart contract to be scanned, and obtain multi-dimensional scanning parameters that match the smart contract scanning trigger event.
[0049] Among them, the smart contract scanning trigger event refers to an event that triggers the scanning of a specified smart contract. It is understandable that the triggering method of the smart contract scanning trigger event can be pre-configured. Specifically, the smart contract scanning trigger event can be manually triggered, or it can be automatically triggered by setting trigger conditions when the trigger conditions are met. For example, manual triggering can be a user uploading a smart contract that needs to be scanned and detected through a scanning platform. Automatic triggering can be achieved by monitoring events on other platforms associated with the scanning platform or other databases used to store smart contracts. When a smart contract that meets the trigger conditions is detected, a scan of the smart contract is triggered.
[0050] The target smart contract to be scanned can be determined based on the smart contract indicated by the smart contract scanning trigger event. For example, in the case of manual triggering, the smart contract manually uploaded, and in the case of automatic triggering, the smart contract that meets the triggering condition. Among them, the number of target smart contracts to be scanned can be one or more. The number of target smart contracts to be scanned can be at least a part of the smart contracts indicated by the smart contract scanning trigger event. For example, the computer device can scan the smart contracts indicated by the smart contract scanning trigger event at one time to achieve centralized scanning and processing of multiple smart contracts. For another example, when the number of smart contracts to be scanned is greater than the threshold value of the number of smart contracts that can be scanned at a time, the smart contracts indicated by the smart contract scanning trigger event can be scanned in batches, and part of the smart contracts can be scanned each time, wherein the threshold value of the number of smart contracts that can be scanned at a time can be set according to the data processing capability of the computer device. When the data processing capability of the computer device is strong, the threshold value of the number of smart contracts that can be scanned at a time can be larger, and when the data processing capability of the computer device is weak, the threshold value of the number of smart contracts that can be scanned at a time can be smaller. It can be understood that the method of determining the target smart contract to be scanned can be achieved by configuring the smart contract selection conditions on the scanning platform.
[0051] Scan parameters are parameters used to define the scanning method for smart contracts. The scanning parameters may specifically include which dimensions of scanning need to be implemented for smart contracts, and which scanning operators in the scanning tool are used for scanning detection. In some embodiments, for different target smart contracts, the scanning parameters may be the same or configured differently. For smart contract scanning trigger events, the trigger event type to which the smart contract scanning trigger event belongs can be found to find scanning parameters that match the trigger event type. Different smart contract scanning trigger events may belong to the same or different trigger event types. The scanning parameters may be pre-configured based on the trigger event type, and the scanning parameters that match the smart contract scanning trigger event may be obtained directly by finding the configuration data based on the trigger event type. In order to achieve multi-dimensional scanning of smart contracts, when configuring the scanning parameters, multi-dimensional scanning parameters may be configured so that the scanning results obtained are multi-dimensional scanning detection results. For example, multi-dimensional security scanning may be performed for different types of security vulnerabilities. For another example, when there are multiple target smart contracts, it may be possible to perform contract relationship analysis on multiple target smart contracts while performing security scanning.
[0052] In some embodiments, the computer device triggers a smart contract scanning trigger event by receiving a smart contract uploaded by a user, determines the smart contract uploaded by the user as the target smart contract to be scanned by responding to the smart contract scanning trigger event, and obtains the multi-dimensional scanning parameters pre-configured for the trigger event type by looking up the trigger event type to which the smart contract scanning trigger event belongs.
[0053] In other embodiments, the computer device monitors the smart contract database, and when a smart contract that meets the trigger conditions is detected, a smart contract scanning trigger event is triggered. By responding to the smart contract scanning trigger event, the smart contract that meets the trigger conditions is determined as the target smart contract to be scanned, and by looking up the trigger event type to which the smart contract scanning trigger event belongs, the multi-dimensional scanning parameters pre-configured for the trigger event type are obtained.
[0054] Step 204: Generate a scanning script for triggering the scanning tool based on the target smart contract and multi-dimensional scanning parameters; the scanning tool is deployed with multiple scanning operators.
[0055] Among them, the scanning script is a script file used to define the execution logic of the scanning process. The scanning script is a script automatically generated based on the target smart contract and scanning parameters. The scanning script can trigger the scanning tool to work, and can determine the target smart contract that the scanning tool needs to scan, and which scanning operators in the scanning tool need to be used to scan the target smart contract.
[0056] In some embodiments, a script template of a scanning script can be pre-configured in a computer device. After determining the target smart contract and scanning parameters, the identification data and scanning parameters of the target smart contract are filled into the script template to automatically generate a scanning script for scanning the target smart contract. Among them, the identification data of the target smart contract can be identification data that uniquely identifies the smart contract, or it can be data that characterizes the storage address of the target smart contract. In the scanning script, there are multiple control commands, and different data processing processes can be achieved by executing different control commands. In the scanning script, the execution logic between each control command is defined. For example, control command A, control command B, and control command C can be executed in parallel. For another example, after the execution of control command A is completed, control command B and control command C are executed in parallel. After the execution of control command B and control command C is completed, control command D is executed.
[0057] The scanning tool is a tool used to scan the specified smart contract. Multiple scanning operators are deployed in the scanning tool. The scanning operator refers to a data processing unit that implements a specific scanning detection function based on a specific scanning logic during the scanning process. Each scanning operator in the scanning tool can be deployed in the scanning tool in a plug-in manner. Through the plug-in deployment method, the deployed scanning operators can be added, deleted, and modified dynamically based on the actual scanning needs without affecting the normal operation of the scanning tool, which can effectively improve the deployment efficiency and convenience of the scanning operators.
[0058] The scanning tool can scan one smart contract or multiple smart contracts at the same time. The specific scanning object and scanning quantity are determined based on the contract identifier of the target smart contract defined in the scanning script. For example, when the identification data of the target smart contract in the scanning script is the storage address of the target smart contract, and there are multiple smart contracts in the storage address of the target smart contract, the scanning object is the multiple smart contracts existing in the storage address. For another example, when the identification data of the target smart contract in the scanning script is multiple smart contract identifiers, the scanning object is the smart contract represented by each of the multiple smart contract identifiers.
[0059] Step 206, execute the scanning script so that the scanning tool scans and detects the target smart contract through the scanning operator that matches the scanning parameters, and obtains the detection data that matches the scanning parameters of each dimension.
[0060] The scanning tool is triggered by executing the scanning script. After the scanning tool works, the scanning tool can scan and detect the target smart contract specified in the scanning script based on the scanning operator defined in the scanning script that matches the scanning parameters, thereby obtaining detection data that matches the scanning parameters of each dimension.
[0061] In the specific implementation process, when there is no logical dependency between the scanning operators, the scanning tool can synchronously implement scanning detection of different dimensions based on different scanning operators. For example, the target smart contract can be scanned and detected based on different scanning operators through different threads. The scanning and detection processes implemented based on each scanning operator do not interfere with each other. For another example, when there is a logical dependency between the scanning operators, the scanning and detection of the target smart contract can be implemented in sequence through each scanning operator according to the front-end relationship shown by the logical dependency.
[0062] In some specific applications, such as Figure 3 As shown, the data processing flow of the scanning platform can be pre-defined based on the pipeline mechanism, and the parameters of each step in the pipeline processing process can be pre-defined in the process of building the scanning platform. For example, in the first step of the pipeline mechanism, the triggering method of the smart contract scanning trigger event is pre-built. Specifically, it can include manual triggering and Git (distributed version control system) event triggering. In the second step of the pipeline mechanism, the execution environment can be pre-built, for example, the constructed execution environment can be a Windows environment or a Linux environment. In the case where the constructed execution environment includes multiple types, the execution environment of this scan also needs to be defined in the scanning script based on the scanning parameters. Before the scanning tool performs scanning detection, the computer device needs to initialize the execution environment first, and scan and detect the target smart contract through the scanning tool in the initialized execution environment.
[0063] Step 208, by executing the scan result output command in the scan script, a smart contract scan result containing various detection data is generated and output.
[0064] Among them, the scan result output command is used to instruct the generation and output of the smart contract scan results for the target smart contract. By defining the scan result output command in the scan script, the smart contract scan results can be automatically generated and output based on the detection data obtained by the scan detection that matches the scan parameters of each dimension during the execution of the scan script, which facilitates the quick and easy acquisition of the smart contract scan results without manual triggering, and can effectively improve the efficiency of obtaining the smart contract scan results.
[0065] In one embodiment, the data processing flow of the scanning platform can be predefined based on the pipeline mechanism as an example. The processing mechanisms of the first two steps of the pipeline mechanism are introduced above. Figure 4As shown, in the third step of the pipeline mechanism, the detection data of the scan detection of the target smart contract by the scanning tool in the second step will be integrated and processed to obtain a report on the smart contract scanning results, and the report will be sent to a designated terminal, such as the terminal where the developer of the target smart contract is located, so that the developer can perform corresponding processing based on the smart contract scanning results.
[0066] The above-mentioned smart contract scanning method determines the target smart contract to be scanned by responding to the smart contract scanning trigger event, and obtains the multi-dimensional scanning parameters matching the smart contract scanning trigger event, so as to automatically generate a scanning script based on the target smart contract and the multi-dimensional scanning parameters to trigger the scanning tool to work. Since the scanning tool is deployed with multiple scanning operators, it can realize multi-dimensional smart contract scanning. In the implementation process, the scanning tool is started by executing the scanning script, so that the scanning tool scans and detects the target smart contract through the scanning operator matching the scanning parameters, and obtains the detection data matching the scanning parameters of each dimension, so as to realize multi-dimensional automatic scanning. By executing the scanning result output command in the scanning script, the scanning tool can be automatically triggered to scan through the scanning script, and the smart contract scanning results containing various detection data are quickly generated and output. The whole process does not require external intervention and can be completed automatically in a pipeline manner, which effectively improves the efficiency of scanning the target smart contract.
[0067] In some embodiments, the method further includes: determining a scan event trigger mechanism configured for the smart contract. The scan event trigger mechanism includes at least one of a manual trigger mechanism and a Git event trigger mechanism. Different smart contract scan triggering methods are provided for different scan event trigger mechanisms.
[0068] Furthermore, in some of the embodiments, when the scanning event triggering mechanism includes a manual triggering mechanism, the computer device determines the submitted smart contract as the target smart contract to be scanned in response to the smart contract submission operation triggered on the scanning platform, and generates a scanning script that conforms to the scanning logic of the pre-configured manual triggering mechanism based on the manual triggering mechanism.
[0069] Furthermore, in some other embodiments, when the scanning event trigger mechanism includes a Git event trigger mechanism, the computer device determines the smart contract corresponding to the smart contract processing event as the target smart contract to be scanned by responding to the smart contract processing event that complies with the Git event trigger mechanism, and generates a scanning script that complies with the scanning logic of the pre-configured Git event trigger mechanism based on the Git event trigger mechanism.
[0070] In some embodiments, the scanning event trigger mechanism includes both a manual trigger mechanism and a Git event trigger mechanism. The computer device can respond to the smart contract submission operation triggered on the scanning platform, or respond to the smart contract processing event that complies with the Git event trigger mechanism, determine the target smart contract to be scanned based on the response operation or event, and generate a corresponding scanning script.
[0071] In this embodiment, the computer device provides a variety of different triggering methods for smart contract scanning events. Based on the manual trigger mechanism, it can scan directly based on the scanning platform. Based on the Git event trigger mechanism, it can configure the association relationship and realize remote triggering through condition monitoring. It can realize the diversification of triggering scenarios and improve the scanning efficiency and convenience of smart contract scanning.
[0072] In some embodiments, when the scanning event trigger mechanism includes a Git event trigger mechanism, responding to a smart contract processing event that complies with the Git event trigger mechanism, determining the smart contract corresponding to the smart contract processing event as a target smart contract to be scanned includes:
[0073] When the scanning event trigger mechanism includes a Git event trigger mechanism, the trigger event type indicated by the Git event trigger mechanism and the monitoring interval of the Git repository are determined; when there is a smart contract processing event that belongs to the trigger event type, and the storage location of the smart contract corresponding to the smart contract processing event in the Git repository is within the monitoring interval, the smart contract corresponding to the smart contract processing event is determined as the target smart contract to be scanned.
[0074] Among them, the Git event trigger mechanism needs to configure the corresponding trigger conditions. In the specific implementation process, in order to further realize the rapid and accurate positioning of the smart contracts that meet the conditions, the monitoring conditions can be limited by pre-configuring the trigger event type and the monitoring interval of the Git repository. Only the smart contracts that meet the monitoring conditions need to be monitored, which can avoid wasting the data processing resources of computer equipment by monitoring and processing irrelevant data.
[0075] By pre-configuring the trigger event type and the monitoring interval of the Git repository, it is only necessary to monitor the smart contract processing events of the configured trigger event type and the smart contracts whose storage locations are in the monitoring interval of the Git repository. When there is a smart contract processing event that belongs to the trigger event type, and the storage location of the smart contract corresponding to the smart contract processing event in the Git repository is within the monitoring interval, the smart contract corresponding to the smart contract processing event is determined as the target smart contract to be scanned.
[0076] Specifically, when configuring the Git event trigger mechanism, you can configure the event types that can be monitored in the Git event trigger mechanism, such as Figure 5As shown, the event types may include Commit Push Hook, Tag Push Hook, Merge Request Hook, Merge Request Accept Hook, Code Review Hook, Issue Hook, Note Hook, etc. The monitoring interval of the Git repository can be to set a specified branch in the code base, or to exclude a specified branch in the code base. Filtering can also be achieved by setting the path filter type, where the path filter type can include matching by path prefix and matching by wildcard.
[0077] When a contract developer submits the smart contract code to the Git repository, if the triggered smart contract processing event belongs to the trigger event type that needs to be monitored, and the storage location of the smart contract in the Git repository is within the defined monitoring interval, a scan of the submitted smart contract is automatically triggered.
[0078] In this embodiment, the computer device monitors the smart contract processing events of the pre-configured trigger event type and the smart contract whose storage location is in the monitoring interval of the Git repository, which can effectively narrow the monitoring scope, realize targeted monitoring, reduce unnecessary consumption of data processing resources of the computer device, and improve resource utilization.
[0079] In some embodiments, the scanning script is executed so that the scanning tool scans and detects the target smart contract through the scanning operator matching the scanning parameters, and obtains the detection data matching the scanning parameters of each dimension, including:
[0080] When there are multiple scanning scripts, determine the scanning operators corresponding to the detection methods indicated by each scanning script respectively; execute each scanning script respectively, call each scanning operator through the scanning tool, perform multi-dimensional scanning and detection on the target smart contract, and obtain detection data that matches the scanning parameters of each dimension respectively.
[0081] Different scanning scripts can be used to implement different scanning functions. For example, a computer device can use the security scanning script contract scan.bat to execute the vulnerability detection of the scanning tool to detect the security vulnerabilities of the target smart contract and obtain the following: Figure 6 The computer device can call the relationship printing script contract print_call graph.bat to realize the contract call graph printing function of the scanning tool, and obtain the following Figure 7The computer device can also realize the contract control flow graph printing function of the scanning tool through the control relationship printing script contract print_cfg.bat, and obtain the following Figure 8 The contract control flow graph is shown.
[0082] The type of scanning script can indicate a specific detection method to achieve different functions, and different functions need to be implemented by different scanning operators. In the case of multiple scanning scripts, the computer device can respectively determine the scanning operator corresponding to the detection method indicated by each scanning script, and the implementation logic between different functions does not interfere with each other. Therefore, the computer device can synchronously execute each execution scanning script to improve the scanning detection efficiency. It can be understood that in other embodiments, the computer device can also asynchronously execute each execution scanning script, call each scanning operator through the scanning tool, perform multi-dimensional scanning detection on the target smart contract, and obtain detection data that matches the scanning parameters of each dimension respectively.
[0083] In this embodiment, different functions are implemented through different scanning scripts, which can effectively implement the scanning detection processing of different functions, obtain detection results of different dimensions, improve the comprehensiveness of the scanning analysis of the target smart contract, and thus obtain more comprehensive scanning results. Furthermore, since different functions are implemented through different scanning scripts, each execution scanning script can be executed synchronously to improve the scanning detection efficiency.
[0084] In some embodiments, there are multiple target smart contracts; executing the scanning script enables the scanning tool to scan and detect the target smart contract through the scanning operator matching the scanning parameters, and obtains the detection data matching the scanning parameters of each dimension, including:
[0085] Get the scan control command in the scan script; when the detection method indicated by the scan control command is security scanning, call the security scan operator that matches the scan parameter, so that the scanning tool performs a security scan on each target smart contract based on the security scan operator, and obtains the security scan result of each target smart contract; when the detection method indicated by the scan control command is contract relationship analysis detection, call the contract relationship analysis operator, so that the scanning tool performs a contract relationship analysis on each target smart contract based on the contract relationship analysis operator, and obtains the contract relationship analysis result between each target smart contract.
[0086] Among them, the scan control command is part of the scan script and is the core command line for implementing the corresponding functions of the scan script. Different scan control commands have different processing logic. For example, the scan control command that needs to be executed for vulnerability scanning is slither.exe D:\work\contract_sec\reentry.sol; the scan control command that needs to be executed to generate the contract call graph CallGraph is: slither.exe D:\work\contract_sec\reentry.sol--print call-graph; the scan control command that needs to be executed to generate the contract control flow graph CFG is: slither.exe D:\work\contract_sec\reentry.sol--print cfg.
[0087] Among them, the detection methods of scanning control command instructions mainly include two categories, one is to perform security scanning on the target smart contract, and the other is to perform contract relationship analysis on multiple target smart contracts. Furthermore, contract relationship analysis can be further divided into call relationship analysis and control relationship analysis.
[0088] In the specific implementation process, for the security scanning detection method, the computer device needs to call the security scanning operator that matches the scanning parameters, so that the scanning tool can perform security scans on each target smart contract based on the security scanning operator to obtain the security scanning results of each target smart contract. During the security scanning process, each target smart contract is independent of each other, so each target smart contract can be security scanned separately.
[0089] For the contract relationship analysis detection method, the computer device needs to call the contract relationship analysis operator so that the scanning tool can perform contract relationship analysis on each target smart contract based on the contract relationship analysis operator to obtain the contract relationship analysis results between each target smart contract. During the security scanning process, it is necessary to analyze the relationship between each target smart contract. Therefore, it is necessary to analyze and process each target smart contract at the same time to obtain the contract relationship analysis results between each target smart contract.
[0090] In this embodiment, for multiple target smart contracts, different functions can be tried based on the scanning control commands for different categories of detection methods. It can realize scanning and detection of multiple target smart contracts at a time, and can determine the relationship between multiple target smart contracts. It can not only realize local scanning of a single target smart contract, but also realize global detection of multiple target smart contracts.
[0091] In one of the embodiments, a contract relationship analysis is performed on a target smart contract based on a contract relationship analysis operator to obtain a contract relationship analysis result, including: when the contract relationship analysis operator includes a contract call graph generation operator, the source code of each target smart contract is compiled separately to obtain an abstract syntax tree for each target smart contract; based on the abstract syntax tree, a call relationship analysis is performed on each target smart contract to generate a contract call graph between each target smart contract.
[0092] Among them, when the contract relationship analysis is a contract call relationship analysis, the contract relationship analysis operator includes a contract call graph generation operator. The scanning tool can perform call relationship analysis on each target smart contract by calling the contract call graph generation operator.
[0093] Specifically, for each target smart contract, the corresponding abstract syntax tree can be obtained by compiling the source code. The abstract syntax tree is an abstract representation of the syntax structure of the source code. The abstract syntax tree represents the syntax structure of the programming language in a tree form, and each node on the tree represents a structure in the source code. In the case where the contract relationship analysis operator includes a contract call graph generation operator, the computer device can compile the source code of each target smart contract separately to obtain the abstract syntax tree of each target smart contract. By analyzing the structure and association relationship of the abstract syntax tree, the calling relationship between the target smart contracts can be determined. Based on the target smart contracts with calling relationships, the contract call graph is generated according to the calling relationship.
[0094] In this embodiment, the computer device compiles the source code of the target smart contract to obtain an abstract syntax tree for call relationship analysis, which can quickly and accurately locate two or more target smart contracts with call relationships, thereby generating a contract call graph between the target smart contracts. Furthermore, based on the contract call graph and outputting it to the smart contract developer, it is convenient for the developer to quickly and conveniently sort out the relationship between smart contracts, thereby accurately repairing smart contracts with vulnerability issues.
[0095] In another embodiment, a contract relationship analysis is performed on the target smart contract based on a contract relationship analysis operator to obtain a contract relationship analysis result, including: when the contract relationship analysis operator includes a contract control flow graph generation operator, the source code of each target smart contract is compiled separately to obtain an abstract syntax tree for each target smart contract; control flow analysis is performed on each target smart contract based on the abstract syntax tree to generate a contract control flow graph between each target smart contract.
[0096] Among them, in the case where the contract relationship analysis is the contract control flow relationship analysis, the contract relationship analysis operator includes the contract control flow graph generation operator, and the scanning tool can perform control flow relationship analysis on each target smart contract by calling the contract control flow graph generation operator. Specifically, for each target smart contract, the corresponding abstract syntax tree can be obtained by compiling the source code, and the abstract syntax tree is an abstract representation of the syntax structure of the source code. In the case where the contract relationship analysis operator includes the contract call graph generation operator, the computer device can compile the source code of each target smart contract separately to obtain the abstract syntax tree of each target smart contract. By analyzing the structure and association relationship of the abstract syntax tree, the control flow relationship between each target smart contract can be determined, and based on each target smart contract with a control relationship, a contract control flow graph is generated according to the control flow.
[0097] In this embodiment, the computer device compiles the source code of the target smart contract to obtain an abstract syntax tree for control flow analysis, which can quickly and accurately locate two or more target smart contracts with a control relationship, thereby generating a contract control flow graph between the target smart contracts. Furthermore, based on the contract control flow graph and outputting it to the smart contract developer, it is convenient for the developer to quickly and conveniently sort out the relationship between smart contracts, thereby accurately repairing smart contracts with vulnerability issues.
[0098] In some embodiments, a smart contract scanning result including various detection data is generated and output, including: when the detection data includes vulnerability problems, finding optimization suggestions corresponding to the vulnerability problems, and counting the number of vulnerability problems in each detection data; generating scanning conclusion data based on the number of target smart contracts that have completed the scan, the number of scanning operators called during the scanning process, and the number of vulnerability problems; generating and outputting a smart contract scanning result including vulnerability problems, optimization suggestions for vulnerability problems, and scanning conclusion data.
[0099] Among them, smart contract vulnerability issues refer to the problems in smart contracts that affect the security of the execution process and need to be fixed. Smart contract vulnerability issues include integer overflow vulnerabilities, short address vulnerabilities, denial of service vulnerabilities, reentrancy vulnerabilities, unchecked return values, timestamp dependency vulnerabilities, predictable random processing, etc.
[0100] Among them, regarding integer overflow vulnerabilities: In the smart contract code, all integer types are unsigned integers, and the smallest is 0. If there is an out-of-bounds error in arithmetic operations, an integer overflow vulnerability will occur. When the maximum representation range of the integer type is exceeded, the number will change from a maximum value to a minimum value or directly return to zero, which is called "overflow". For example, if the maximum value in the contract is X, an integer overflow vulnerability occurs when X+1=0; when the minimum representation range of the integer type is exceeded, the number will change from a minimum value or zero to a maximum value, such as 0-1=X, which means an integer underflow vulnerability occurs.
[0101] About the short address vulnerability: The short address vulnerability is a byproduct of the virtual machine failing to accept the correct parameters. Attackers can exploit this weakness through specially crafted addresses and fill in parameters for some clients with encoding errors.
[0102] Denial of service vulnerability: Denial of service vulnerability means that the target machine stops providing services, which is usually used by hackers to attack using denial of service attack. This attack method can disrupt, terminate, and freeze the normal transaction operations of the contract, and more seriously, make the logic of the contract itself unable to run.
[0103] Regarding reentrancy vulnerabilities: Although the execution of smart contracts is an atomic and sequential transaction operation, when a user calls a smart contract, if the called function is not found in the called contract, the rollback mechanism of calling the fallback function will be triggered. Attackers can attack smart contracts with reentrancy vulnerabilities by constructing special fallback functions. For example, the fallback function contains a function in the attacked contract that transfers money to the attacker, thereby exhausting the resources of the attacked contract through recursive calls.
[0104] Regarding unchecked return values: Taking Solidity as an example, its function calls generally set return values like other high-level languages, but when low-level function calls such as send, call, delegatecall fail, the transaction will not be rolled back, but the exception will be indicated in the return value. An attacker can deliberately send failed operations to make the program execution different from the expected settings, thereby causing confusion in the state of the smart contract.
[0105] Regarding the timestamp dependency vulnerability: In smart contracts, block timestamps can be used as a basis for conditional judgment, which has little use value for ordinary attackers. However, for miners who can manipulate timestamps within a certain range, they can bypass the relevant judgment conditions by constructing malicious timestamps.
[0106] Regarding predictable random processing: When contract developers write random number generation functions, they sometimes use timestamps, block numbers and other block-related parameters to generate random numbers. However, the above data on the blockchain is public, which makes the generated random numbers predictable and may be exploited by attackers.
[0107] In this embodiment, for different vulnerability problems, the scanning platform can pre-configure optimization suggestions corresponding to various vulnerability problems based on the causes of the vulnerability problems. When the scanning tool detects the corresponding vulnerability problem through the corresponding scanning operator, the optimization suggestions corresponding to the vulnerability problem can be displayed in the smart contract scanning result, which is convenient for developers to refer to the optimization suggestions for vulnerability repair. In addition, the computer device generates scanning conclusion data by counting the number of vulnerability problems in each detection data, based on the number of target smart contracts that have completed the scan, the number of scanning operators called during the scanning process, and the number of vulnerability problems, and can intuitively display various scanning statistics in the smart contract scanning results. Understand the overall vulnerability distribution in the target smart contract.
[0108] In one embodiment, when there are multiple target smart contracts, the smart contract scanning result also includes a contract relationship analysis result; the method also includes: when the smart contract scanning result shows that there is a security vulnerability, based on at least one of the contract call graph and the contract control flow graph in the contract relationship analysis result, locating the problematic smart contract with the security vulnerability and the associated smart contract that has a contractual relationship with the problematic smart contract; based on the optimization suggestions for the vulnerability problem and the associated smart contracts, repairing the vulnerability of the problematic smart contract.
[0109] When there are multiple target smart contracts, by performing contract relationship analysis on the target smart contracts, a contract call graph representing the call relationship between the target smart contracts and a contract control flow graph representing the control flow relationship between the target smart contracts can be obtained. Based on at least one of the contract call graph and the contract control flow graph, the problematic smart contract with security vulnerabilities can be quickly located from a global perspective, and the associated smart contracts that have contractual relationships with the problematic smart contract can be intuitively understood, so that the vulnerability repair method of the problematic smart contract can be directly determined based on the optimization suggestions for the vulnerability problem and the associated smart contracts, so as to avoid affecting the associated smart contracts while repairing the vulnerability of the problematic smart contract, thereby achieving vulnerability repair of the problematic smart contract.
[0110] In this embodiment, the computer device can quickly locate the problematic smart contract with security vulnerabilities based on at least one of the contract call graph and the contract control flow graph through the smart contract scanning results, and can intuitively understand the associated smart contracts that have a contractual relationship with the problematic smart contract, formulate reasonable vulnerability repair methods, and achieve effective repairs.
[0111] In some embodiments, the scanning operator deployed by the scanning tool is a scanning operator implemented as a plug-in; the method also includes: in response to a new scanning operator addition event triggered for the scanning tool, determining the scanning operator type to which the newly added scanning operator belongs; and deploying the newly added scanning operator to the scanning tool through a plug-in implementation method that matches the scanning operator type.
[0112] In this embodiment, the scanning operator addition event refers to a request for a newly deployed scanning operator in the scanning tool. Different types of scanning operators can be implemented in different plug-in ways. The computer device can first determine the scanning operator type to which the newly added scanning operator belongs in response to the scanning operator addition event triggered for the scanning tool, and then determine the plug-in implementation method that matches the scanning operator type based on the association relationship between the pre-configured scanning operator type and the plug-in method, and deploy the newly added scanning operator to the scanning tool according to the plug-in implementation method.
[0113] In this embodiment, the scanning tool uses a plug-in design concept. It only needs to implement the plug-in method to customize the scanning operator, which can easily realize the expansion of scanning detection with different functions. Through the plug-in deployment method, the deployed scanning operators can be added, deleted, and modified dynamically based on actual scanning needs without affecting the normal operation of the scanning tool, which can effectively improve the deployment efficiency and convenience of the scanning operator.
[0114] In some of the embodiments, a newly added scanning operator is deployed to a scanning tool through a plug-in implementation method that matches the scanning operator type, including: when the plug-in implementation method that matches the scanning operator type is a registration implementation method, the newly added scanning operator is deployed to the scanning tool by dynamically registering the plug-in and the plug-in instance through an interface; when the plug-in implementation method that matches the scanning operator type is a monitoring implementation method, the newly added scanning operator is deployed to the scanning tool by creating a plug-in instance by monitoring the added plug-in instance file.
[0115] Specifically, the plug-in implementation method can be implemented based on a plug-in system including a plug-in abstract layer, a plug-in implementation layer, a plug-in usage layer and a presentation layer. Among them, the plug-in abstract layer is an abstract interface of the plug-in, and it is as versatile as possible, which is conducive to adding it to a project as a feature. For example, if a project needs a plug-in feature, it only needs to copy the code of the plug-in abstract layer to the corresponding project, reducing unnecessary duplication of work. The plug-in abstract layer includes a plug-in manager. The plug-in manager can be implemented by various means, such as registration or monitoring. The registration type opens registration and deregistration interfaces, dynamically registers plug-ins and plug-in instances through interfaces, and the monitoring type can monitor a certain directory. When a plug-in file is added, the plug-in is loaded, and when a plug-in instance file is added, a plug-in instance is created. The plug-in implementation layer is the implementation of the plug-in abstract layer, which is used to connect specific functions and business logic. The plug-in usage layer is where plug-ins are used to organize business logic. The presentation layer provides system presentation methods, such as pages, interfaces, etc.
[0116] The present application also provides an application scenario, which applies the above-mentioned smart contract scanning method.
[0117] Specifically, the application of the smart contract scanning method in this application scenario is as follows:
[0118] Existing smart contract security scanning tools often support vulnerability scanning by providing APIs, command line tools or platforms, but these methods are not at the first site of development. After developers complete code submission, they often need to manually upload contract files, vulnerability scanning options, and download security test reports. These processes are time-consuming and labor-intensive, and do not meet the corporate goal of reducing costs and increasing efficiency.
[0119] like Figure 4 As shown, the processing flow of contract security scanning is configured based on the pipeline mechanism in this application. In the first step of the pipeline mechanism, the triggering method of the smart contract scanning trigger event is pre-built. Specifically, it can include manual triggering and Git (distributed version control system) event triggering. In the second step of the pipeline mechanism, the execution environment can be pre-built, for example, the execution environment built can be a windows environment or a Linux environment. In the case where the execution environment built includes multiple situations, the execution environment of this scan also needs to be defined based on the scanning parameters in the scanning script. Before the scanning tool performs the scanning detection, the computer device needs to initialize the execution environment first, and scan and detect the target smart contract through the scanning tool in the initialized execution environment. In the third step of the pipeline mechanism, the detection data of the scanning and detection of the target smart contract by the scanning tool in the second step will be integrated and processed to obtain a report on the smart contract scanning results, and the report will be sent to the specified terminal, such as the terminal where the developer of the target smart contract is located, so that the developer can perform corresponding processing based on the smart contract scanning results.
[0120] There are two ways to configure the triggering of contract security scanning: manual triggering and Git event triggering, where Git events can be customized, such as commit events, push events, etc. Based on Git event triggering, contract developers can submit smart contract codes to the Git repository, remotely execute smart contract scanning and obtain smart contract scanning results.
[0121] The purpose of building an execution environment is to remotely execute the scanning script and trigger an online remote contract security scan. Among them, the type of the execution environment can be a Windows environment, a Linux environment, etc. Before the scanning tool performs scanning detection, the computer device needs to initialize the execution environment first, and scan and detect the target smart contract through the scanning tool in the initialized execution environment. The scope of the target smart contract involved in the executed scanning script can be customized, such as scanning all contracts or specified contracts. The computer device can implement security vulnerability detection of the target smart contract based on the vulnerability detection implemented by the scanning tool by executing the scanning script, and obtain the security vulnerability detection result. The computer device can implement the contract call graph printing function of the scanning tool by calling the relationship printing script and obtain the contract call graph. The computer device can also implement the contract control flow graph printing function of the scanning tool by controlling the relationship printing script to obtain the contract control flow graph. The computer device can also notify the developer or tester of the multi-dimensional smart contract scanning results and reports.
[0122] Furthermore, the plug-ins that need to be developed based on the pipeline mechanism include vulnerability scanning, call graph printing, control flow graph CFG printing, etc. Among them, the main scanning control command that needs to be executed for vulnerability scanning is slither.exe D:\work\contract_sec\reentry.sol; the main scanning control command that needs to be executed to generate the contract call graph CallGraph is: slither.exe D:\work\contract_sec\reentry.sol--print call-graph; the main scanning control command that needs to be executed to generate the contract control flow graph CFG is: slither.exe D:\work\contract_sec\reentry.sol--print cfg.
[0123] In addition to the above scanning operators, the scanning tool also supports custom vulnerability scanning operators. The scanning tool uses a plug-in design idea. You only need to implement the plug-in method to customize the scanning operator, which can easily realize the expansion of scanning detection with different functions. The vulnerability issues of smart contracts that can be detected by the scanning tool include integer overflow vulnerabilities, short address vulnerabilities, denial of service vulnerabilities, reentrancy vulnerabilities, unchecked return values, timestamp dependency vulnerabilities, and predictable random processing.
[0124] In order to explain the scanning process of this application in detail, the following is an explanation of this solution through the short address vulnerability detection process. The short address vulnerability occurs in the user's transfer operation. The most commonly used transfer function in the contract is the transfer function. The definition of the transfer method in the ERC20 standard is function transfer(address to,uint tokens)public returns(bool success), where the first input parameter to represents the address of the virtual resource recipient, and the second parameter tokens represents the number of virtual resources sent. When the user calls the transfer function of the contract, the input data of the transaction is divided into the following three parts:
[0125] (1) A total of 4 bytes, representing the hash value of the calling function
[0126] (2) A total of 32 bytes, representing the receiving address. The current address is set to 20 bytes, so the high bits need to be filled with 0
[0127] (3) A total of 32 bytes, indicating the number of virtual resources to be sent. If it is less than 32 bytes, the high bits are also filled with 0
[0128] These three pieces of data together constitute the input value of the transaction, such as the following:
[0129] a9059cbb000000000000000000000000012345678901234567890123456789012345678900000000000000000000000000000000000000000000000000000000000000000000000000000000adba0ce53620000, when the user initiates a transfer operation, the application layer does not check the length of the input address, for example, the user enters a short address 0x1234567890123456789012345678901234567700, ignoring the 00 at the end, and directly converts 0x123456789012345 67890123456789012345677 is sent to the contract. The parameters will be encoded according to the ABI specification. It is possible to send encoded parameters that are shorter than the expected parameter length (for example, sending an address with only 38 hexadecimal characters (19 bytes) instead of the standard 40 hexadecimal characters (20 bytes)). In this case, the virtual machine in the smart contract execution environment will get 00 from the high bit of the next parameter to fill in the expected length, which will cause some security issues. Therefore, when writing transfer-type smart contracts, it is necessary to strictly verify the validity of the address, such as adding the following verification code to the transfer function, and verifying the length and legitimacy of the user input address from the application layer and the presentation layer. The short address detection operator of the transfer function is built into the security detection framework to identify whether the contract transfer operation has a short address vulnerability. The specific process is as follows: input the path of the contract to be tested; compile the source code of the contract to be tested to obtain the AST tree, and identify the transfer function; input the parameters and implementation process of the transfer function into the short address vulnerability detection operator; output a test report to determine whether the contract to be tested has a short address vulnerability.
[0130] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these 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 part of the steps or stages in other steps.
[0131] Based on the same inventive concept, the embodiment of the present application also provides a smart contract scanning device for implementing the smart contract scanning method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more smart contract scanning device embodiments provided below can refer to the limitations of the smart contract scanning method above, and will not be repeated here.
[0132] In one embodiment, Fig. 9 As shown, a smart contract scanning device is provided, including: a trigger response module 902, a script generation module 904, a scanning detection module 906 and a result output module 908, wherein:
[0133] A trigger response module 902 is used to determine a target smart contract to be scanned in response to a smart contract scanning trigger event, and obtain multi-dimensional scanning parameters configured for the target smart contract;
[0134] A script generation module 904 is used to generate a scanning script for triggering the operation of a scanning tool based on the multi-dimensional scanning parameters; the scanning tool is deployed with multiple scanning operators;
[0135] A scanning detection module 906 is used to execute the scanning script so that the scanning tool scans and detects the target smart contract through a scanning operator that matches the scanning parameters, and obtains detection data that matches the scanning parameters of each dimension;
[0136] The result output module 908 is used to generate and output the smart contract scanning result containing each of the detection data by executing the scanning result output command in the scanning script.
[0137] In some embodiments, the trigger response module is also used to determine a scanning event trigger mechanism configured for a smart contract; when the scanning event trigger mechanism includes a manual trigger mechanism, in response to a smart contract submission operation triggered on the scanning platform, the submitted smart contract is determined as a target smart contract to be scanned.
[0138] In some embodiments, the trigger response module is also used to determine a scanning event trigger mechanism configured for a smart contract; when the scanning event trigger mechanism includes a Git event trigger mechanism, it responds to a smart contract processing event that complies with the Git event trigger mechanism, and determines the smart contract corresponding to the smart contract processing event as the target smart contract to be scanned.
[0139] In some embodiments, the trigger response module is also used to determine the trigger event type indicated by the Git event trigger mechanism and the monitoring interval of the Git repository when the scanning event trigger mechanism includes a Git event trigger mechanism; when there is a smart contract processing event belonging to the trigger event type, and the storage location of the smart contract corresponding to the smart contract processing event in the Git repository is within the monitoring interval, the smart contract corresponding to the smart contract processing event is determined as the target smart contract to be scanned.
[0140] In some embodiments, the scanning detection module is also used to, when there are multiple scanning scripts, determine the scanning operators corresponding to the detection methods indicated by each scanning script respectively; execute each scanning script respectively, call each scanning operator through the scanning tool, perform multi-dimensional scanning detection on the target smart contract, and obtain detection data that matches the scanning parameters of each dimension respectively.
[0141] In some embodiments, there are multiple target smart contracts; the scanning detection module is also used to obtain the scanning control command in the scanning script; when the detection method indicated by the scanning control command is security scanning, the security scanning operator matching the scanning parameters is called, so that the scanning tool performs a security scan on each of the target smart contracts based on the security scanning operator, and obtains the security scanning results of each target smart contract; when the detection method indicated by the scanning control command is contract relationship analysis detection, the contract relationship analysis operator is called, so that the scanning tool performs a contract relationship analysis on each of the target smart contracts based on the contract relationship analysis operator, and obtains the contract relationship analysis results between the target smart contracts.
[0142] In some embodiments, the scanning detection module is also used to compile the source code of each of the target smart contracts separately to obtain an abstract syntax tree for each of the target smart contracts when the contract relationship analysis operator includes a contract call graph generation operator; perform call relationship analysis on each of the target smart contracts based on the abstract syntax tree to generate a contract call graph between each of the target smart contracts.
[0143] In some embodiments, the scanning detection module is also used to compile the source code of each of the target smart contracts separately to obtain an abstract syntax tree of each of the target smart contracts when the contract relationship analysis operator includes a contract call graph generation operator; perform control flow analysis on each of the target smart contracts based on the abstract syntax tree to generate a contract control flow graph between each of the target smart contracts.
[0144] In some embodiments, the result output module is also used to find optimization suggestions corresponding to the vulnerability problems when the detection data contains vulnerability problems, and count the number of vulnerability problems in each of the detection data; generate scanning conclusion data based on the number of target smart contracts that have completed the scan, the number of scanning operators called during the scanning process, and the number of vulnerability problems; generate and output smart contract scanning results containing the vulnerability problems, optimization suggestions for the vulnerability problems, and the scanning conclusion data.
[0145] In some embodiments, when there are multiple target smart contracts, the smart contract scanning result also includes a contract relationship analysis result; the device also includes a vulnerability repair module, which is used to locate the problem smart contract with the security vulnerability and the associated smart contract that has a contractual relationship with the problem smart contract based on at least one of the contract call graph and the contract control flow graph in the contract relationship analysis result when the smart contract scanning result shows that there is a security vulnerability; based on the optimization suggestions for the vulnerability problem and the associated smart contract, the vulnerability of the problem smart contract is repaired.
[0146] In some embodiments, the scanning operator deployed by the scanning tool is a scanning operator implemented as a plug-in; the device also includes a scanning operator deployment module, which is used to determine the scanning operator type to which the newly added scanning operator belongs in response to a new scanning operator event triggered for the scanning tool; and deploy the newly added scanning operator to the scanning tool through a plug-in implementation method that matches the scanning operator type.
[0147] In some embodiments, the scanning operator deployment module is used to deploy the newly added scanning operator to the scanning tool by dynamically registering the plug-in and the plug-in instance through an interface when the plug-in implementation method matching the scanning operator type is a registration implementation method; when the plug-in implementation method matching the scanning operator type is a monitoring implementation method, the newly added scanning operator is deployed to the scanning tool by creating a plug-in instance by monitoring the added plug-in instance file.
[0148] The above-mentioned smart contract scanning device determines the target smart contract to be scanned by responding to the smart contract scanning trigger event, and obtains the multi-dimensional scanning parameters matching the smart contract scanning trigger event, so as to automatically generate a scanning script based on the target smart contract and the multi-dimensional scanning parameters to trigger the scanning tool to work. Since the scanning tool is deployed with multiple scanning operators, it can realize multi-dimensional smart contract scanning. In the implementation process, the scanning tool is started by executing the scanning script, so that the scanning tool scans and detects the target smart contract through the scanning operator matching the scanning parameters, and obtains the detection data matching the scanning parameters of each dimension, so as to realize multi-dimensional automatic scanning. By executing the scanning result output command in the scanning script, the scanning tool can be automatically triggered to scan through the scanning script, and the smart contract scanning results containing various detection data are quickly generated and output. The whole process does not require external intervention and can be completed automatically in a pipeline manner, which effectively improves the efficiency of scanning the target smart contract.
[0149] Each module in the above-mentioned smart contract scanning device can be implemented in whole or in part by software, hardware and their combination. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the corresponding operations of each of the above modules.
[0150] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig.10 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data such as smart contracts and smart contract scanning results. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a smart contract scanning method is implemented.
[0151] Those skilled in the art will understand that Fig.10The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0152] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps of the above-mentioned method embodiments when executing the computer program.
[0153] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0154] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0155] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0156] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0157] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are 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.
[0158] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A smart contract scanning method, characterized in that: The method comprises: In response to a smart contract scanning trigger event, determine a target smart contract to be scanned, and obtain multi-dimensional scanning parameters matching the smart contract scanning trigger event; Based on the target smart contract and the multi-dimensional scanning parameters, a scanning script for triggering the operation of a scanning tool is generated; the scanning tool is deployed with multiple scanning operators; Execute the scanning script so that the scanning tool scans and detects the target smart contract through a scanning operator that matches the scanning parameters, and obtains detection data that matches the scanning parameters of each dimension; By executing the scan result output command in the scan script, a smart contract scan result containing each of the detection data is generated and output.
2. The method according to claim 1, characterized in that The method further comprises: Determine the scanning event trigger mechanism for smart contract configuration; The step of determining a target smart contract to be scanned in response to a smart contract scanning triggering event includes: In a case where the scanning event triggering mechanism includes a manual triggering mechanism, in response to a smart contract submission operation triggered on the scanning platform, determining the submitted smart contract as a target smart contract to be scanned; In the case where the scanning event triggering mechanism includes a Git event triggering mechanism, in response to a smart contract processing event that complies with the Git event triggering mechanism, the smart contract corresponding to the smart contract processing event is determined as a target smart contract to be scanned.
3. The method according to claim 2, characterized in that When the scanning event triggering mechanism includes a Git event triggering mechanism, responding to a smart contract processing event that complies with the Git event triggering mechanism, and determining the smart contract corresponding to the smart contract processing event as a target smart contract to be scanned, includes: In a case where the scanning event trigger mechanism includes a Git event trigger mechanism, determining a trigger event type indicated by the Git event trigger mechanism and a monitoring interval of a Git repository; When there is a smart contract processing event that belongs to the trigger event type, and the storage location of the smart contract corresponding to the smart contract processing event in the Git repository is within the monitoring interval, the smart contract corresponding to the smart contract processing event is determined as the target smart contract to be scanned.
4. The method according to claim 1, characterized in that The executing the scanning script so that the scanning tool scans and detects the target smart contract through a scanning operator matching the scanning parameters, and obtains detection data matching the scanning parameters of each dimension, including: In the case where there are multiple scanning scripts, respectively determine the scanning operators corresponding to the detection methods indicated by each scanning script; Execute each of the scanning scripts respectively, call each of the scanning operators through the scanning tool, perform multi-dimensional scanning detection on the target smart contract, and obtain detection data that matches the scanning parameters of each dimension respectively.
5. The method according to claim 1, characterized in that There are multiple target smart contracts; The executing the scanning script so that the scanning tool scans and detects the target smart contract through a scanning operator matching the scanning parameters, and obtains detection data matching the scanning parameters of each dimension, including: Obtaining a scan control command in the scan script; In the case where the detection mode indicated by the scanning control command is security scanning, calling a security scanning operator that matches the scanning parameter, so that the scanning tool performs security scanning on each of the target smart contracts based on the security scanning operator, and obtains a security scanning result for each of the target smart contracts; When the detection method indicated by the scanning control command is contract relationship analysis detection, the contract relationship analysis type operator is called to enable the scanning tool to perform contract relationship analysis on each of the target smart contracts based on the contract relationship analysis type operator to obtain the contract relationship analysis result.
6. The method according to claim 5, characterized in that The performing contract relationship analysis on the target smart contract based on the contract relationship analysis operator to obtain a contract relationship analysis result includes: In the case where the contract relationship analysis operator includes a contract call graph generation operator, the source code of each of the target smart contracts is compiled respectively to obtain an abstract syntax tree of each of the target smart contracts; Based on the abstract syntax tree, a call relationship analysis is performed on each of the target smart contracts to generate a contract call graph between the target smart contracts.
7. The method according to claim 5, characterized in that The performing contract relationship analysis on the target smart contract based on the contract relationship analysis operator to obtain a contract relationship analysis result includes: In the case where the contract relationship analysis operator includes a contract control flow graph generation operator, the source code of each of the target smart contracts is compiled respectively to obtain an abstract syntax tree of each of the target smart contracts; Based on the abstract syntax tree, control flow analysis is performed on each of the target smart contracts to generate a contract control flow graph between the target smart contracts.
8. The method according to claim 5, characterized in that The generating and outputting of the smart contract scanning results containing each of the detection data includes: In the case where the detection data contains vulnerability problems, searching for optimization suggestions corresponding to the vulnerability problems, and counting the number of vulnerability problems in each of the detection data; Generate scanning conclusion data based on the number of target smart contracts that have completed the scan, the number of scanning operators called during the scanning process, and the number of vulnerability issues; Generate and output a smart contract scanning result including the vulnerability problem, optimization suggestions for the vulnerability problem, and the scanning conclusion data.
9. The method according to claim 8, characterized in that In the case where there are multiple target smart contracts, the smart contract scanning result also includes a contract relationship analysis result; the method further includes: When the smart contract scanning result indicates that there is a security vulnerability, based on at least one of the contract call graph and the contract control flow graph in the contract relationship analysis result, locate the problematic smart contract with the security vulnerability and the associated smart contracts that have a contractual relationship with the problematic smart contract; Based on the optimization suggestions for the vulnerability problem and the associated smart contract, the vulnerability of the problematic smart contract is repaired.
10. The method according to any one of claims 1 to 9, characterized in that The scanning operator deployed by the scanning tool is a scanning operator implemented as a plug-in; the method further includes: In response to a scan operator addition event triggered for the scan tool, determining a scan operator type to which the newly added scan operator belongs; The newly added scanning operator is deployed to the scanning tool through a plug-in implementation that matches the scanning operator type.
11. The method according to claim 10, characterized in that The deploying the newly added scanning operator to the scanning tool by means of a plug-in implementation matching the scanning operator type includes: In the case where the plug-in implementation method matching the scanning operator type is a registration-based implementation method, the newly added scanning operator is deployed to the scanning tool by dynamically registering the plug-in and the plug-in instance through an interface; In the case that the plug-in implementation method matching the scanning operator type is a monitoring implementation method, the newly added scanning operator is deployed to the scanning tool by creating a plug-in instance through monitoring the added plug-in instance file.
12. A smart contract scanning device, characterized in that: The device comprises: A trigger response module, configured to determine a target smart contract to be scanned in response to a smart contract scanning trigger event, and obtain multi-dimensional scanning parameters configured for the target smart contract; A script generation module, used to generate a scanning script for triggering the operation of a scanning tool based on the multi-dimensional scanning parameters; the scanning tool is deployed with multiple scanning operators; A scanning detection module, used to execute the scanning script so that the scanning tool scans and detects the target smart contract through a scanning operator that matches the scanning parameters, and obtains detection data that matches the scanning parameters of each dimension; The result output module is used to generate and output the smart contract scanning result containing each of the detection data by executing the scanning result output command in the scanning script.
13. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 11 are implemented.
14. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.
15. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.
