Methods and systems for detecting smart contract vulnerabilities in Hyperledger Fabric

By combining graph learning and fuzzing methods, an abstract syntax tree and key data flow graph are generated. Combined with the blockchain network state, dynamic and static detection is performed, which solves the problem that existing tools cannot be applied to smart contract vulnerability detection in Hyperledger Fabric, and achieves efficient and accurate vulnerability detection.

CN118626379BActive Publication Date: 2025-12-02XIDIAN UNIV
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202410779520.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-17
Publication Date
2025-12-02
Estimated Expiration
2044-06-17

AI Technical Summary

Technical Problem

Existing smart contract vulnerability detection tools cannot be directly applied to Hyperledger Fabric, and existing tools are insufficient in terms of detection accuracy and coverage. They mainly rely on static detection, which is not very practical and cannot meet actual needs.

Method used

This paper adopts a method that combines graph learning vulnerability detection with fuzz testing. It performs static analysis by generating abstract syntax trees and key data flow graphs, and performs dynamic testing by combining the blockchain network operation status. It improves detection efficiency by using a multi-layer buffer structure and batch processing.

Benefits of technology

It significantly improves the detection capability and accuracy for complex vulnerability types, enhances vulnerability location capabilities and detection efficiency, and improves code coverage and detection accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118626379B_ABST
    Figure CN118626379B_ABST
Patent Text Reader

Abstract

A method and system for smart contract vulnerability detection on Hyperledger Fabric are disclosed. The method includes uploading the chaincode to be tested, auxiliary chaincode, and test parameters; analyzing and processing the chaincode to be tested to generate an Abstract Syntax Tree (AST); generating a data flow graph and a key data flow graph based on the AST; using the chaincode to be tested and the generated key data flow graph as input for vulnerability detection, obtaining graph learning vulnerability detection results; installing the chaincode to be tested and the auxiliary chaincode on two channels of the blockchain network respectively; acquiring the blockchain network's operating status; generating test cases based on the test parameters; executing the test cases to verify the existence of vulnerabilities, obtaining fuzzing vulnerability detection results; and integrating and displaying the graph learning vulnerability detection results and fuzzing vulnerability detection results. This invention can achieve dynamic and static combined vulnerability detection of chaincode, enhancing the accuracy and efficiency of vulnerability detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of blockchain technology, and specifically to a method and system for detecting smart contract vulnerabilities in Hyperledger Fabric. Background Technology

[0002] Hyperledger Fabric is an open-source, cross-industry collaborative blockchain technology. It's part of the Hyperledger project led by the Linux Foundation, aiming to facilitate cross-industry blockchain technology. Fabric is designed as a modular, configurable, and pluggable blockchain solution to meet the needs of various business scenarios. As an open-source blockchain platform, Hyperledger Fabric features permission control, modular design, and high throughput, making it a preferred platform for enterprises to build distributed applications in recent years. However, as blockchain applications become more complex and smart contract security vulnerabilities are frequently exposed, timely detection and remediation of these vulnerabilities has become a research hotspot in both academia and industry.

[0003] Currently, existing smart contract vulnerability detection methods are primarily designed and implemented for Ethereum. However, Hyperledger Fabric differs significantly from Ethereum in terms of vulnerability types and operational mechanisms, making these vulnerability detection tools unsuitable for direct application. Hyperledger Fabric smart contracts are also known as chaincode, and the few vulnerability detection tools available for Hyperledger Fabric chaincode suffer from low accuracy and narrow coverage. Their detection techniques are mainly static, resulting in unsatisfactory results, and their methods remain largely theoretical with limited practical application, failing to meet real-world needs. Summary of the Invention

[0004] The purpose of this invention is to address the problems in the prior art by providing a method and system for detecting smart contract vulnerabilities in Hyperledger Fabric, enabling dynamic and static vulnerability detection of Hyperledger Fabric chaincode.

[0005] To achieve the above objectives, the present invention provides the following technical solution:

[0006] Firstly, a method for detecting smart contract vulnerabilities in Hyperledger Fabric is provided, including:

[0007] Upload the chaincode to be tested, the auxiliary chaincode, and the test parameters;

[0008] The chain code under test is analyzed and processed to generate an abstract syntax tree (AST). Based on the AST, a data flow graph and a key data flow graph are generated. The chain code under test and the generated key data flow graph are used as inputs for vulnerability detection to obtain graph learning vulnerability detection results.

[0009] The chaincode to be tested and the auxiliary chaincode are installed on two channels, channel1 and channel2, of the blockchain network. The blockchain network operation status is obtained, test cases are generated in combination with test parameters, test cases are executed to test, the existence of vulnerabilities is verified, and the fuzz test vulnerability detection results are obtained.

[0010] The results of graph learning vulnerability detection and fuzzing vulnerability detection are integrated and displayed.

[0011] As a preferred embodiment, the step of uploading the chaincode to be tested, the auxiliary chaincode, and the test parameters performs a validity test on the uploaded file. The chaincode to be tested and the auxiliary chaincode are files with the ".go" extension, and the test parameters are files with the ".txt" extension.

[0012] As a preferred approach, the step of analyzing and processing the chain code to be tested and generating an abstract syntax tree (AST) is completed using the Tree-sitter-go tool.

[0013] As a preferred embodiment, the steps of generating data flow graphs and key data flow graphs based on the Abstract Syntax Tree (AST) include: traversing the AST using a For statement, executing a type judgment method, and performing corresponding operations based on different chaincode statement types: for assignment statements and variable declaration statements, recursively processing the left and right child nodes of the statement, extracting data flow information, generating a data flow graph, and updating the state trajectory; for control flow statements, recursively processing the corresponding child nodes of the statement, and executing different branches according to conditions, extracting data flow information and updating variable state trajectories during the execution of different branches;

[0014] After generating the data flow graph, the nodes of the data flow graph are verified using vulnerability features. Nodes irrelevant to the vulnerability are deleted, and a critical data flow graph is generated.

[0015] As a preferred embodiment, the step of using the chaincode to be tested and the generated key data flow graph as input for vulnerability detection to obtain graph learning vulnerability detection results includes:

[0016] The test set's chaincode source code and the generated key data flow graph are used as inputs to a pre-trained vulnerability detection model for vulnerability detection. The vulnerability detection model is the GraphCodeBERT model, which pre-processes the text using the tokenizer of the RoBERTa model to match the input data with the model's tokenization method.

[0017] As a preferred approach, the steps of installing the chaincode to be tested and the auxiliary chaincode on two channels (channel1 and channel2) of the blockchain network, obtaining the blockchain network's operating status, generating test cases based on test parameters, and executing the test cases involve: first, obtaining the blockchain network's operating status and accepting the file path; obtaining the initial test parameters from the parameter file; generating a seed queue based on the network status and parameters; determining whether the coverage is empty during the generation process; if not empty, adding the test cases corresponding to the coverage; then, mutating the seed queue; and finally, using the FFUF tool to initiate a test request.

[0018] Test requests are scheduled using a multi-layered buffer structure and batch processing. During this process, the blockchain network is linked, and the test requests are transmitted to the chaincode for execution. In the linking process, the linking parameters are set through the node configuration file connection.yaml. Then, a Hyperledger Fabric gateway is created as a bridge between the application and the blockchain network. Subsequently, the chaincode on the specific channel is obtained through the Hyperledger Fabric gateway, and the methods defined in the chaincode are called and parameters are passed.

[0019] The chaincode executes the test requests sequentially and records the chaincode coverage of the corresponding test cases;

[0020] The existence of the cross-channel chaincode call vulnerability was verified based on the execution results of the chaincode.

[0021] As a preferred embodiment, the step of integrating and displaying the graph learning vulnerability detection results and the fuzzing vulnerability detection results includes:

[0022] The vulnerability detection results are integrated with the vulnerability detection results from graph learning and fuzzing, and the chaincode to be tested and the corresponding vulnerability hints are displayed. The vulnerability hints can locate the vulnerability location, vulnerability type and the cause of the vulnerability.

[0023] Secondly, a smart contract vulnerability detection system for Hyperledger Fabric is provided, including:

[0024] The data upload module is used to upload the chaincode to be tested, the auxiliary chaincode, and the test parameters;

[0025] The graph learning vulnerability detection module is used to analyze and process the chain code under test, generate an abstract syntax tree (AST), generate a data flow graph and a key data flow graph based on the AST, and use the chain code under test and the generated key data flow graph as input for vulnerability detection to obtain the graph learning vulnerability detection results.

[0026] The fuzzing vulnerability detection module is used to install the chaincode to be tested and the auxiliary chaincode on two channels, channel1 and channel2, of the blockchain network, respectively, to obtain the blockchain network's operating status, generate test cases based on test parameters, execute the test cases to test, verify whether the vulnerability exists, and obtain the fuzzing vulnerability detection results.

[0027] The results display module is used to integrate and display the results of graph learning vulnerability detection and fuzzing vulnerability detection.

[0028] Thirdly, an electronic device is provided, comprising:

[0029] Memory, storing at least one instruction; and

[0030] The processor executes instructions stored in the memory to implement the smart contract vulnerability detection method for Hyperledger Fabric as described in the first aspect.

[0031] Fourthly, a computer-readable storage medium is provided, the computer-readable storage medium storing a computer program, which, when executed by a processor, implements the smart contract vulnerability detection method for Hyperledger Fabric as described in the first aspect.

[0032] Compared with the prior art, the present invention has at least the following beneficial effects:

[0033] For Hyperledger Fabric chaincode, this invention employs graph learning-based vulnerability detection and fuzzing-based vulnerability detection, combining the advantages of static and dynamic vulnerability detection methods to detect different types of vulnerabilities that may exist in the target smart contract. Specifically, the chaincode vulnerability detection method based on data flow graph deep learning enhances the model's perception and understanding of code data flow information, thereby significantly improving the detection capability for complex vulnerability types. The fuzzing-based chaincode vulnerability detection method takes the blockchain's operational state into account, effectively improving the efficiency of fuzzing and the code coverage of test cases, thus enhancing the accuracy and efficiency of vulnerability detection. In graph learning-based vulnerability detection, this invention uses a key data flow graph as input to the model for training and detection tasks. Compared to using ordinary data flow graphs, key data flow graphs significantly improve training efficiency and accuracy, thereby helping to strengthen the deep learning model's localization capabilities and vulnerability detection performance.

[0034] Furthermore, in fuzzing vulnerability detection, the present invention's detection method, which dynamically updates the seed queue using coverage information, can effectively improve the code coverage of test cases, thereby increasing the likelihood of discovering potential vulnerabilities. Simultaneously, the multi-layered buffer structure and batch request processing method proposed in this invention can improve the efficiency of processing test requests. Attached Figure Description

[0035] Figure 1 This invention presents an architecture diagram of a smart contract vulnerability detection system for Hyperledger Fabric.

[0036] Figure 2 This invention includes an embodiment of the Hyperledger Fabric blockchain network environment architecture diagram.

[0037] Figure 3 Data upload flowchart of an embodiment of the present invention;

[0038] Figure 4 The diagram below shows the architecture of the vulnerability detection module in this embodiment of the invention.

[0039] Figure 5 The embodiment of this invention illustrates the principle of vulnerability detection.

[0040] Figure 6 Flowcharts for generating data flow graphs and key data flow graphs in embodiments of the present invention;

[0041] Figure 7 This invention provides a flowchart of a graph learning-based vulnerability detection process using a vulnerability detection model.

[0042] Figure 8 Vulnerability detection model architecture diagram of this invention embodiment;

[0043] Figure 9 Architecture diagram of the fuzzing vulnerability detection module in this invention;

[0044] Figure 10 A flowchart illustrating the workflow of the fuzzing vulnerability detection module in this invention.

[0045] Figure 11 Workflow diagram of the use case generation submodule in this embodiment of the invention;

[0046] Figure 12 A schematic diagram of the multi-layer buffer structure proposed in this embodiment of the invention. Detailed Implementation

[0047] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0048] As a distributed ledger technology, blockchain provides security for data across various industries, including finance, supply chain management, the Internet of Things, digital copyright, and healthcare, thanks to its immutable nature. [1] Hyperledger Fabric [2] HF (Headquarters for short) is a blockchain platform designed to meet the needs of enterprise-level applications. Built with the support of the Linux Foundation, HF achieves a secure, scalable, and privacy-preserving enterprise-grade blockchain network through the collaborative work of key components such as nodes, sorting nodes, chaincode, channels, and ledgers. Based on its permissioned control, modular design, and high throughput, HF is gradually becoming the preferred blockchain platform for enterprises building distributed applications. However, as smart contract applications become increasingly complex, many security issues are emerging, such as reentrancy vulnerabilities, timestamp dependencies, and integer overflows. [3] To date, there have been several serious smart contract security incidents. For example, the DAO attack. [4] Fomo3D [5] Attacks and other vulnerabilities in smart contracts have led to substantial economic losses. Against this backdrop, numerous detection tools have been developed using various methods to identify security issues in smart contracts, including traditional feature matching tools, formal verification tools, symbolic execution tools, fuzzing tools, and deep learning tools. However, these tools, and most current ones, are designed and implemented specifically for Ethereum smart contracts. Due to significant differences between Ethereum and HF in their operating mechanisms, programming languages, and consensus algorithms, these tools cannot be directly used for vulnerability detection in HF smart contracts. Currently, there are few vulnerability detection tools for HF chaincode. Most tools rely on pattern matching techniques, while a few employ fuzzing and symbolic execution. Furthermore, current HF chaincode vulnerability detection tools suffer from insufficient detection accuracy and low coverage. Detection techniques are primarily static, resulting in unsatisfactory results, and the detection methods remain largely theoretical with limited practical application.

[0049] Revive-cc [6]It is one of the earliest static analysis tools for HF smart contracts, an extension of the open-source Go static analysis tool revive, capable of performing security analysis on Go chaincode files using pattern matching. This tool can detect some types of HF chaincode vulnerabilities. Chaincode Scanner [7] CCDetector is one of the earliest static security analyzers designed for high-frequency (HF) smart contracts. It typically takes Go-language smart contracts as input and utilizes automated security analysis methods, such as control flow graph analysis and dependency graph analysis, to check for nine types of HF chaincode vulnerabilities. [8] Knowledge graphs are used to assist in vulnerability detection. First, the contract source code is converted into an Abstract Syntax Tree (AST). Then, a knowledge graph is built based on the AST, including the ontology layer and the instance layer. Finally, pattern matching in the knowledge graph is used to detect vulnerabilities, including vulnerability pattern analysis and vulnerability localization. HFContractFuzzer [9] It is a Go-fuzz-based

[10] This document describes the design and implementation of a fuzzing tool. The tool uses the MockStub class to simulate the operation of a state database in a blockchain network. It improves fuzzing efficiency by enhancing the mutation algorithm of Go-fuzz. (HFCCT)

[11] A chaincode vulnerability detection framework was designed using a combination of dynamic symbolic execution and static abstract syntax tree techniques. This tool utilizes dynamic symbolic execution for certain vulnerability types and can detect 15 types of vulnerabilities. (Reference)

[12] A vulnerability detection tool based on static analysis was designed. It detects the existence of vulnerabilities by converting code into an Abstract Syntax Tree (AST) and performing pattern matching by traversing the AST nodes.

[0050] Revive-cc [6] CCDetector [8] ,literature

[12] The designed vulnerability detection tools based on static analysis all rely on pattern matching methods, which result in a high false positive rate for complex vulnerabilities.

[0051] Chaincode Scanner [7] Since the official documentation does not describe it in detail and the project website is no longer available, the principles and performance of the tool cannot be fully understood.

[0052] literature [9] The designed vulnerability detection tool based on fuzzing does not consider the operational state of the blockchain network during fuzzing. Therefore, for network state-related vulnerability types, the tool has poor detection efficiency and low coverage.

[0053] HFCCT

[11] For some vulnerability types, dynamic symbolic execution methods are used. While these methods offer high accuracy, they suffer from low detection efficiency and difficulty in generating high-quality test cases. Furthermore, for another group of vulnerability types, HFCCT still relies on pattern matching methods, which, although efficient, cannot overcome the problem of a high false positive rate.

[0054] [1] Shen Chuannian. A review of research on cross-chain technology in blockchain [J]. Journal of Internet of Things, 2022, 6(04): 183-96.

[0055] [2]Androulaki E,Barger A,Bortnikov V,et al.HF:a distributed operating system for permissioned blockchains[C].Proceedings of the thirteenth EuroSysconference.2018:1-15.

[0056] [3] Qian Peng, Liu Zhenguang, He Qinming, et al. A review of research on smart contract security vulnerability detection technology [J]. Journal of Software, 2022, 33(08):3059-3085.

[0057] [4]Dhillon V,Metcalf D,Hooper M,et al.The DAO hacked[J].blockchainenabled applications:Understand the blockchain Ecosystem and How to Make it work for you,2017:67-78.

[0058] [5]He D, Deng Z, Zhang Y, et al.Smart contract vulnerability analysis and security audit[J]. IEEE Network, 2020, 34(5):276-282.

[0059] [6]Sivachokkapu.revive-cc[CP / OL].https: / / github.com / sivachokkapu / revive-cc,2020.

[0060] [7]ChainSecurity.ChaincodeScanner[CP / OL].https: / / medium.com / chainsecurity / release-of-hyperchecker-2dff2ebe30cc,2019.

[0061] [8]Xu X,Hu T,Li B,et al.CCDetector:Detect Chaincode VulnerabilitiesBased on Knowledge Graph[C].2023IEEE 47th Annual Computers,Software,andApplications Conference(COMPSAC),2023:699-704.

[0062] [9]Ding M,Li P,Li S,et al.Hfcontractfuzzer:Fuzzing HF smart contractsfor vulnerability detection[M].Evaluation and Assessment in SoftwareEngineering,2021:321-328.

[0063]

[10] Dmitry Vyukov.Dvyukov Go-fuzz[CP / OL].https: / / github.com / dvyukov / gofuzz,2015.

[0064]

[11] Li P,Li S,Ding M,et al.A vulnerability detection framework for HFsmart contracts based on dynamic and static analysis[C].Proceedings of the26th International Conference on Evaluation and Assessment in SoftwareEngineering,2022:366-374.

[0065]

[12] Yamashita K, Nomura Y, Zhou E, et al. Potential risks of HF smartcontracts[C]. 2019IEEE International Workshop on Blockchain Oriented SoftwareEngineering(IWBOSE). IEEE, 2019:1-10.

[0066] Please see Figure 1 This invention proposes a smart contract vulnerability detection method for Hyperledger Fabric, which realizes dynamic and static vulnerability detection of HF chaincode. The system architecture of this invention consists of a data upload module, a graph learning vulnerability detection module, a fuzzing vulnerability detection module, and a result display module.

[0067] To facilitate vulnerability detection, the system pre-built an HF blockchain network environment and maintained two channels, channel1 and channel2. For example... Figure 2 As shown, HF achieves its security, privacy, and scalability through the synergistic effect of key components such as nodes, sorting nodes, chaincode, channels, and ledgers.

[0068] The smart contract vulnerability detection method for Hyperledger Fabric according to embodiments of the present invention includes:

[0069] Upload the chaincode to be tested, the auxiliary chaincode, and the test parameters;

[0070] The chain code under test is analyzed and processed to generate an abstract syntax tree (AST). Based on the AST, a data flow graph and a key data flow graph are generated. The chain code under test and the generated key data flow graph are used as inputs for vulnerability detection to obtain graph learning vulnerability detection results.

[0071] The chaincode to be tested and the auxiliary chaincode are installed on two channels, channel1 and channel2, of the blockchain network. The blockchain network operation status is obtained, test cases are generated in combination with test parameters, test cases are executed to test, the existence of vulnerabilities is verified, and the fuzz test vulnerability detection results are obtained.

[0072] The results of graph learning vulnerability detection and fuzzing vulnerability detection are integrated and displayed.

[0073] The above method can be implemented using a smart contract vulnerability detection system for Hyperledger Fabric, including:

[0074] The data upload module is used to upload the chaincode to be tested, the auxiliary chaincode, and the test parameters;

[0075] The graph learning vulnerability detection module is used to analyze and process the chain code under test, generate an abstract syntax tree (AST), generate a data flow graph and a key data flow graph based on the AST, and use the chain code under test and the generated key data flow graph as input for vulnerability detection to obtain the graph learning vulnerability detection results.

[0076] The fuzzing vulnerability detection module is used to install the chaincode to be tested and the auxiliary chaincode on two channels, channel1 and channel2, of the blockchain network, respectively, to obtain the blockchain network's operating status, generate test cases based on test parameters, execute the test cases to test, verify whether the vulnerability exists, and obtain the fuzzing vulnerability detection results.

[0077] The results display module is used to integrate and display the results of graph learning vulnerability detection and fuzzing vulnerability detection.

[0078] In one possible implementation, the specific details of each module are as follows:

[0079] 1. Data Upload Module

[0080] The data upload module provides an interactive interface for users to upload the chaincode to be tested, auxiliary chaincode, and test parameter files provided by the user to the system server.

[0081] like Figure 3 As shown, the data upload module process is as follows:

[0082] Users upload the chaincode to be tested, auxiliary chaincode, and test parameters through three data upload interfaces. The system will then perform a validity test on the uploaded files. The chaincode must be a file with the ".go" extension, and the test parameters must be a file with the ".txt" extension. If the uploaded file is of another type, the user will be prompted to re-upload. If the file is valid, the system will proceed to the next step.

[0083] 2. Graph Learning Vulnerability Detection Module

[0084] This module is used for graph learning-based vulnerability detection of chaincode. For example... Figure 4 As shown, the graph learning vulnerability detection module consists of a preprocessing submodule, a graph generation submodule, and a graph detection submodule. Their specific functions are as follows:

[0085] 1) Preprocessing Submodule. The preprocessing submodule uses the Tree-sitter-go tool to convert chained code into an Abstract Syntax Tree (AST). Tree-sitter-go utilizes advanced syntax analysis algorithms to accurately capture the syntactic structure and key elements of the code, quickly generating the AST corresponding to the source code.

[0086] 2) Graph Generation Submodule. The graph generation submodule is responsible for analyzing the AST to generate data flow graphs and key data flow graphs.

[0087] 3) Graph Detection Submodule. The graph detection submodule is responsible for inputting the source code and key data flow graphs into the vulnerability detection model for vulnerability detection.

[0088] like Figure 5 As shown in the figure, this is the overall workflow diagram of the graph learning vulnerability detection module. First, the chaincode to be tested is analyzed and processed to generate an abstract syntax tree (AST). Then, a data flow graph and a key data flow graph are generated based on the AST. Finally, the chaincode to be tested and the generated key data flow graph are used as inputs for vulnerability detection.

[0089] The workflow of each submodule is as follows:

[0090] Preprocessing submodule: The preprocessing submodule analyzes and processes the chain code to be tested and generates an abstract syntax tree (AST).

[0091] Graph generation submodule: such as Figure 6 As shown, the AST is first traversed using a For loop, then a type judgment method is executed. Based on different chaincode statement types (such as assignment statements, variable declaration statements, if statements, for statements, etc.), corresponding operations are performed. For assignment statements and variable declaration statements, their left and right child nodes are recursively processed to extract data flow information for generating a data flow graph and updating the state trajectory. For control flow statements such as if statements and for statements, their child nodes are recursively processed, and different branches are executed based on conditions. During the execution of different branches, data flow information is extracted and variable state trajectories are updated. After generating the data flow graph, vulnerability features are used to verify the nodes in the data flow graph, and nodes irrelevant to the vulnerability are deleted to generate a critical data flow graph.

[0092] Image detection submodule: such as Figure 7 As shown, RoberTa was used first.

[13] The model's tokenizer ensures that the input data matches the model's tokenization method during text processing. Then, the trained HF chaincode vulnerability detection model is used for vulnerability detection. After model evaluation, vulnerability detection labels are automatically generated to determine the presence of vulnerabilities in the source code. Finally, the prediction results are stored in a file for further processing.

[0093] Among them, the vulnerability detection model for HF chaincode uses GraphCodeBERT as input, along with key data flow graphs and source code.

[14] The model is obtained by fine-tuning the pre-trained model, and its architecture is as follows: Figure 8As shown, during vulnerability detection, the source code of the test set and the key data flow graph it generates are used as inputs to the pre-trained vulnerability detection model for vulnerability detection.

[0094] 3. Fuzzing vulnerability detection module

[0095] This module is used for coverage-based fuzzing vulnerability detection of chaincode. For example... Figure 9 As shown, the fuzzing vulnerability detection module consists of a chaincode installation submodule, a test case generation submodule, and a test execution submodule. Its specific functions are as follows:

[0096] 1) Chaincode Installation Submodule. This module installs the chaincode onto the blockchain network for testing.

[0097] 2) Test Case Generation Submodule. The test case generation module is responsible for obtaining relevant data such as blockchain network status, test parameters, and coverage information, and then generating test cases through a mutation algorithm.

[0098] 3) Test Execution Submodule. The test execution module is responsible for connecting to the blockchain network to execute test cases, verifying the existence of vulnerabilities, and recording the results.

[0099] like Figure 10 As shown in the diagram, this is a flowchart of the fuzzing vulnerability detection module. First, the chaincode is installed on the blockchain network and awaits testing. Then, the blockchain network state is read. Next, a large number of test cases are generated based on the test parameters. Finally, the test cases are executed to verify the existence of vulnerabilities and the detection results are recorded.

[0100] The workflow of each submodule is as follows:

[0101] Chaincode Installation Submodule: This module uses the command-line tool provided by HF to install the chaincode to be tested and the auxiliary chaincode uploaded by the user on channel1 and channel2 respectively, waiting for testing.

[0102] Test case generation submodule: such as Figure 11 As shown, this module first obtains the blockchain network's operating status, then accepts the file path and retrieves the initial test parameters from the parameter file. Based on the network status and parameters, a seed queue is generated. During the generation process, the Coverage parameter is considered to be empty; if not empty, the corresponding test cases are added. The seed queue is then mutated, and subsequently, the FFUF tool is used to initiate test requests.

[0103] Test execution submodule: This module first utilizes, for example... Figure 12 The multi-layered buffer structure and batch processing method shown efficiently schedule test requests. This process requires connecting to the blockchain network and then transmitting the test requests to the chaincode for execution.

[0104] During the connection process, the application first sets connection parameters via the node configuration file `connection.yaml`, including the network's TLS certificate, sorted node address, chaincode, etc. Then, an HF gateway is created as a bridge between the application and the blockchain network. Subsequently, the application retrieves the chaincode for a specific channel through the gateway and calls the methods defined within the chaincode, passing the necessary parameters.

[0105] Subsequently, the chaincode executes the test requests sequentially, and the chaincode coverage of the corresponding test cases is recorded. Finally, the existence of the cross-channel chaincode call vulnerability is verified based on the chaincode execution results, and a test report is generated. The report is saved for further processing.

[0106] 4. Results Display Module

[0107] The graph learning vulnerability detection module and the fuzzing vulnerability detection module generate chaincode vulnerability detection results. This module will read and display the detection results. This module consists of a reading submodule and a display submodule. Specific functions are as follows:

[0108] 1) Reading Submodule: Reads and integrates the vulnerability detection reports generated by the graph learning vulnerability detection module and the fuzzing vulnerability detection module.

[0109] 2) Display submodule: Displays vulnerability detection results to users, including the source code, the corresponding vulnerability type, and the possible causes of the vulnerability.

[0110] The workflow of each submodule is as follows:

[0111] Reading submodule: Reads the prediction results stored in the graph learning vulnerability detection module and the test reports saved in the fuzzing vulnerability detection module respectively, and then integrates them according to the order in which the vulnerabilities appeared and stores them as a new detection report.

[0112] Display Submodule: Analyzes and processes the detection report generated by the reading submodule, and then displays the chaincode to be tested on the left side of the results display window and the vulnerability prompts on the right side. Clicking on the vulnerability prompts on the right side can locate the vulnerability.

[0113] This invention proposes a dynamic and static combined chaincode vulnerability detection method. This method combines a data flow graph-based deep learning chaincode vulnerability detection method and a coverage-guided fuzzing chaincode vulnerability detection method for Hyperledger Fabric (HF) smart contract vulnerability detection. The data flow graph-based deep learning chaincode vulnerability detection method analyzes vulnerability characteristics, identifies key nodes, generates a key data flow graph, and represents Hyperledger Fabric chaincode using a graph structure, thereby improving the detection capability for complex vulnerability types. The coverage-guided fuzzing chaincode vulnerability detection method fully considers the characteristics of dynamic vulnerability types, taking the blockchain network state, initial test parameters, and coverage as necessary dependencies for generating the seed queue. It uses a mutation algorithm to mutate the seeds, generating diverse test cases and performing fuzzing tests.

[0114] This invention designs and implements a chaincode vulnerability detection system for Hyperledger Fabric, consisting of four modules: data upload, graph learning vulnerability detection, fuzzing vulnerability detection, and result display. It effectively detects security vulnerabilities in Hyperledger Fabric chaincode through a combination of dynamic and static methods. The data upload module provides a user-interactive interface with three data upload interfaces, primarily responsible for uploading the user-provided chaincode to be tested, auxiliary chaincode, and test parameter files to the system server. The graph learning vulnerability detection module utilizes graph learning-based vulnerability detection technology, primarily responsible for inputting the chaincode to be tested and the generated key data flow graph into a pre-trained vulnerability detection model to automatically identify potential vulnerabilities in the chaincode. The fuzzing vulnerability detection module is primarily responsible for performing coverage-based fuzzing vulnerability detection on the chaincode. The result display module is responsible for reading and displaying the chaincode vulnerability detection results from the graph learning and fuzzing vulnerability detection modules.

[0115] This invention combines the advantages of static and dynamic vulnerability detection methods to detect different types of vulnerabilities that may exist in target smart contracts. The chaincode vulnerability detection method based on data flow graph deep learning enhances the model's perception and understanding of code data flow information, thereby significantly improving the detection capability for complex vulnerability types. The coverage-guided fuzzing chaincode vulnerability detection method takes the blockchain's operational state into account, improving the efficiency of fuzzing and the code coverage of test cases, thus enhancing the accuracy and efficiency of vulnerability detection. Compared with existing technologies, this invention uses a key data flow graph as input to the model for training and detection tasks. Compared with using ordinary data flow graphs, the key data flow graph can significantly improve training efficiency and accuracy, thereby helping to strengthen the localization ability and vulnerability detection performance of the deep learning model. The method of dynamically updating the seed queue using coverage information can effectively improve the code coverage of test cases, thereby increasing the probability of discovering potential vulnerabilities. The multi-layer buffer structure and batch request processing method proposed in this invention can improve the efficiency of processing test requests.

[0116]

[13] Liu Y,Ott M,Goyal N,et al.Roberta:A robustly optimized bertpretraining approach[J].arXiv preprint arXiv:1907.11692,2019.

[0117]

[14] Xu

[0118] This invention also proposes an electronic device, comprising: a memory storing at least one instruction; and a processor executing the instructions stored in the memory to implement a smart contract vulnerability detection method for Hyperledger Fabric.

[0119] This invention also proposes a computer-readable storage medium storing a computer program that, when executed by a processor, implements a smart contract vulnerability detection method for Hyperledger Fabric.

[0120] For example, the instructions stored in the memory can be divided into one or more modules / units. These modules / units are stored in a computer-readable storage medium and executed by the processor to complete the smart contract vulnerability detection method for Hyperledger Fabric according to the present invention. The one or more modules / units can be a series of computer-readable instruction segments capable of performing specific functions, which describe the execution process of the computer program on the server.

[0121] The electronic device may be a smartphone, laptop, PDA, or cloud server, among other computing devices. It may include, but is not limited to, a processor and memory. Those skilled in the art will understand that the electronic device may also include more or fewer components, or combinations of certain components, or different components; for example, it may also include input / output devices, network access devices, buses, etc.

[0122] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor.

[0123] The memory can be an internal storage unit of the server, such as a hard drive or RAM. Alternatively, it can be an external storage device, such as a plug-in hard drive, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card. Furthermore, the memory can include both internal and external storage units. The memory is used to store computer-readable instructions and other programs and data required by the server. It can also be used to temporarily store data that has been output or will be output.

[0124] It should be noted that the information interaction and execution process between the above-mentioned module units are based on the same concept as the method embodiment. For details on their specific functions and technical effects, please refer to the method embodiment section. They will not be repeated here.

[0125] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0126] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of this application can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include at least: any entity or device capable of carrying the computer program code to a photographing device / terminal device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks.

[0127] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0128] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.

Claims

1. A method for detecting smart contract vulnerabilities in Hyperledger Fabric, characterized in that, include: Upload the chaincode to be tested, the auxiliary chaincode, and the test parameters; The chain code under test is analyzed and processed to generate an abstract syntax tree (AST). Based on the AST, a data flow graph and a key data flow graph are generated. The chain code under test and the generated key data flow graph are used as inputs for vulnerability detection to obtain graph learning vulnerability detection results. The chaincode to be tested and the auxiliary chaincode are installed on two channels, channel1 and channel2, of the blockchain network. The blockchain network operation status is obtained, test cases are generated in combination with test parameters, test cases are executed to test, the existence of vulnerabilities is verified, and the fuzz test vulnerability detection results are obtained. The results of graph learning vulnerability detection and fuzzing vulnerability detection are integrated and displayed. The steps involve installing the chaincode to be tested and the auxiliary chaincode on two channels (channel1 and channel2) of the blockchain network, obtaining the blockchain network's operating status, generating test cases based on test parameters, and executing the test cases. First, after obtaining the blockchain network's operating status, the file path is accepted. Initial test parameters are obtained from the parameter file. A seed queue is generated based on the network status and parameters. During the generation process, it is determined whether the coverage is empty. If not, the test cases corresponding to the coverage are added. Then, the seed queue is mutated, and subsequently, a test request is initiated using the FFUF tool. Test requests are scheduled using a multi-layered buffer structure and batch processing. During this process, the blockchain network is linked, and the test requests are transmitted to the chaincode for execution. In the linking process, the linking parameters are set through the node configuration file connection.yaml. Then, a Hyperledger Fabric gateway is created as a bridge between the application and the blockchain network. Subsequently, the chaincode on the specific channel is obtained through the Hyperledger Fabric gateway, and the methods defined in the chaincode are called and parameters are passed. The chaincode executes the test requests sequentially and records the chaincode coverage of the corresponding test cases; The existence of the cross-channel chaincode call vulnerability was verified based on the execution results of the chaincode.

2. The smart contract vulnerability detection method for Hyperledger Fabric according to claim 1, characterized in that, The steps of uploading the chaincode to be tested, the auxiliary chaincode, and the test parameters are used to perform a legality test on the uploaded files. The chaincode to be tested and the auxiliary chaincode are files with the ".go" extension, and the test parameters are files with the ".txt" extension.

3. The smart contract vulnerability detection method for Hyperledger Fabric according to claim 1, characterized in that, The step of analyzing and processing the chain code to be tested and generating an abstract syntax tree (AST) is completed using the Tree-sitter-go tool.

4. The smart contract vulnerability detection method for Hyperledger Fabric according to claim 3, characterized in that, The steps of generating data flow graphs and key data flow graphs based on the Abstract Syntax Tree (AST) include: The AST is traversed using a For loop, and the type judgment method is executed. Based on different chain code statement types, corresponding operations are performed: for assignment statements and variable declaration statements, the left and right child nodes of the statement are processed recursively, the data flow information is extracted, a data flow graph is generated, and the state trajectory is updated; for control flow statements, the corresponding child nodes of the statement are processed recursively, and different branches are executed according to the conditions. During the execution of different branches, data flow information is extracted and the variable state trajectory is updated. After generating the data flow graph, the nodes of the data flow graph are verified using vulnerability features. Nodes irrelevant to the vulnerability are deleted, and a critical data flow graph is generated.

5. The smart contract vulnerability detection method for Hyperledger Fabric according to claim 4, characterized in that, The step of using the chaincode to be tested and the generated key data flow graph as input to perform vulnerability detection and obtain graph learning vulnerability detection results includes: taking the source code of the chaincode to be tested and the generated key data flow graph of the test set as input and inputting them into a pre-trained vulnerability detection model for vulnerability detection; the vulnerability detection model is the GraphCodeBERT model, which uses the tokenizer of the RoBERTa model for text processing in advance to match the input data with the model's tokenization method.

6. The smart contract vulnerability detection method for Hyperledger Fabric according to claim 1, characterized in that, The steps for integrating and displaying the graph learning vulnerability detection results and the fuzzing vulnerability detection results include: The vulnerability detection results are integrated with the vulnerability detection results from graph learning and fuzzing, and the chaincode to be tested and the corresponding vulnerability hints are displayed. The vulnerability hints can locate the vulnerability location, vulnerability type and the cause of the vulnerability.

7. A smart contract vulnerability detection system for Hyperledger Fabric, characterized in that, include: The data upload module is used to upload the chaincode to be tested, the auxiliary chaincode, and the test parameters; The graph learning vulnerability detection module is used to analyze and process the chain code under test, generate an abstract syntax tree (AST), generate a data flow graph and a key data flow graph based on the AST, and use the chain code under test and the generated key data flow graph as input for vulnerability detection to obtain the graph learning vulnerability detection results. The fuzzing vulnerability detection module is used to install the chaincode to be tested and the auxiliary chaincode on two channels, channel1 and channel2, of the blockchain network, respectively, to obtain the blockchain network's operating status, generate test cases based on test parameters, execute the test cases to test, verify whether the vulnerability exists, and obtain the fuzzing vulnerability detection results. The results display module is used to integrate and display the results of graph learning vulnerability detection and fuzzing vulnerability detection. The fuzzing vulnerability detection module installs the chaincode to be tested and the auxiliary chaincode on two channels, channel1 and channel2, of the blockchain network, respectively. It obtains the blockchain network's operating status, generates test cases based on test parameters, and executes the test cases. First, it obtains the blockchain network's operating status and then accepts the file path. It retrieves the initial test parameters from the parameter file, generates a seed queue based on the network status and parameters, and checks whether the coverage is empty during the generation process. If it is not empty, it adds the test cases corresponding to the coverage. Then, it mutates the seed queue and uses the FFUF tool to initiate test requests. Test requests are scheduled using a multi-layered buffer structure and batch processing. During this process, the blockchain network is linked, and the test requests are transmitted to the chaincode for execution. In the linking process, the linking parameters are set through the node configuration file connection.yaml. Then, a Hyperledger Fabric gateway is created as a bridge between the application and the blockchain network. Subsequently, the chaincode on the specific channel is obtained through the Hyperledger Fabric gateway, and the methods defined in the chaincode are called and parameters are passed. The chaincode executes the test requests sequentially and records the chaincode coverage of the corresponding test cases; The existence of the cross-channel chaincode call vulnerability was verified based on the execution results of the chaincode.

8. An electronic device, characterized in that, include: Memory, storing at least one instruction; and The processor executes instructions stored in the memory to implement the smart contract vulnerability detection method for Hyperledger Fabric as described in any one of claims 1 to 6.

9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the smart contract vulnerability detection method for Hyperledger Fabric as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Dynamic and static combined Hyperledger Fabric chain code vulnerability detection method

    CN115618351A