Method, device and equipment for detecting vulnerabilities of smart contract based on frequency-aware low-rank adaptation and medium
By introducing Frequency Aware Low-Rank Adaptive (FA-LoRA) technology into smart contract vulnerability detection, and utilizing Fourier transform and frequency domain masking, the problems of insufficient detection accuracy and low efficiency in existing technologies are solved, achieving efficient and accurate vulnerability detection.
Patent Information
- Application Number
- CN202610264574.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-03-05
- Publication Date
- 2026-06-05
AI Technical Summary
Existing smart contract vulnerability detection technologies suffer from insufficient detection accuracy and low efficiency when faced with complex and ever-changing contract code structures and new attack vectors.
The method of frequency-aware low-rank adaptation (FA-LoRA) is adopted. By inserting a low-rank adaptation module into the pre-trained large language model, Fourier transform and frequency domain masking techniques are used to fine-tune the parameters, thereby improving the model's adaptability to smart contract code and detection accuracy.
It significantly improves the accuracy and efficiency of smart contract vulnerability detection, can quickly adapt to complex code logic, enhances the ability to identify diverse vulnerability features, and reduces the risk of overfitting.
Smart Images

Figure CN122153915A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of blockchain security technology, and in particular to a method, apparatus, electronic device and computer-readable storage medium for detecting smart contract vulnerabilities based on frequency-aware low-rank adaptation. Background Technology
[0002] With the rapid development of blockchain technology, smart contracts, as a core component of blockchain, are crucial for ensuring the stable operation of the entire blockchain ecosystem.
[0003] However, existing smart contract vulnerability detection technologies have gradually revealed many problems when faced with increasingly complex and varied contract code structures and emerging new attack vectors, such as insufficient detection accuracy and low efficiency.
[0004] In summary, existing smart contract vulnerability detection technologies suffer from insufficient detection accuracy and low efficiency when faced with increasingly complex and varied contract code structures and emerging new attack vectors. The applicant has made corresponding explorations to address these issues. Summary of the Invention
[0005] The purpose of this application is to solve the above problems by providing a smart contract vulnerability detection method, corresponding device, electronic device and computer-readable storage medium based on frequency-aware low-rank adaptation.
[0006] To achieve the various objectives of this application, the following technical solution is adopted:
[0007] A smart contract vulnerability detection method based on frequency-aware low-rank adaptation, proposed to meet one of the purposes of this application, includes:
[0008] Obtain the structured representation corresponding to the smart contract to be detected, and input the structured representation into a pre-trained large language model for semantic analysis and logical inference to identify the preliminary vulnerability types in the smart contract and their corresponding credibility.
[0009] The initial vulnerability type and its corresponding credibility are used as reference data for fine-tuning the pre-trained large language model using frequency-aware low-rank adaptation. Two low-rank adaptation modules are inserted into some linear layers of the large language model. The training update of the linear layer weights of the large language model is decomposed into the product of two low-rank matrices. Only the parameters of the low-rank adaptation modules are updated and the main parameters of the large language model are frozen.
[0010] The low-rank update information output by the low-rank adaptation module is subjected to discrete Fourier transform to map its feature dimensions to the frequency domain space, and the energy conservation in the frequency domain is maintained by using Passevar's theorem; a frequency domain mask matrix is constructed by using a preset binary frequency domain selection mask and a learnable gating vector to filter the frequency domain features.
[0011] The filtered frequency domain features are subjected to inverse Fourier transform to map back to the original feature space. The frequency-aware low-rank adaptive updated output feature representation is obtained by combining the projection matrix and scaling coefficient. This representation is then fused with the original output of the pre-trained large language model to complete the fine-tuning of the large language model.
[0012] The structured representation corresponding to the smart contract to be detected is input into the large language model after being fine-tuned by the frequency-aware low-rank adaptation, so as to output a smart contract vulnerability detection report and complete the smart contract vulnerability detection based on frequency-aware low-rank adaptation.
[0013] Optionally, the step of determining the structured representation corresponding to the smart contract to be detected includes:
[0014] The source code of the smart contract to be tested is obtained, and formatting, lexical analysis, and syntax parsing operations are performed on the source code in sequence. At the same time, the functions and variables, control flow and data flow information, interface names, function definitions and variable declaration class code attributes corresponding to each function definition are extracted from the source code to determine the preprocessed source code.
[0015] The preprocessed source code is converted into a structured representation that can be used by pre-trained large language models for semantic analysis and logical inference.
[0016] Optionally, the step of performing a discrete Fourier transform on the low-rank update information output by the low-rank adaptation module, mapping its feature dimensions to the frequency domain, and using Passevar's theorem to maintain energy conservation in the frequency domain includes:
[0017] The low-rank update information output by the low-rank adaptation module inserted in the linear layer of the large language model is processed by discrete Fourier transform, and the feature dimension of the low-rank update information is mapped to the frequency domain space by normalizing the discrete Fourier transform matrix.
[0018] The data processing of the discrete Fourier transform is constrained by Passevar's theorem to maintain the energy conservation of low-rank update information in the frequency domain space, and to perform lossless data mapping of the low-rank update information from the feature space to the frequency domain space.
[0019] Optionally, the step of constructing a frequency domain mask matrix using a preset binary frequency domain selection mask and a learnable gating vector to filter frequency domain features includes:
[0020] Obtain the preset binary frequency domain selection mask and learnable gating vector;
[0021] A frequency domain mask matrix is constructed from the binary frequency domain selection mask and the learnable gating vector. The frequency domain mask matrix is applied to the frequency domain features obtained by discrete Fourier transform to perform filtering processing on the frequency domain features, so as to suppress low contribution frequency band features and retain or amplify high contribution frequency band features.
[0022] Optionally, an inverse Fourier transform is performed on the filtered frequency domain features to map them back to the original feature space. The frequency-aware low-rank adaptive updated output feature representation is then obtained by combining the projection matrix and scaling coefficients. This updated representation is then fused with the original output of the pre-trained large language model to complete the fine-tuning of the large language model, including:
[0023] Perform an inverse Fourier transform on the frequency domain features filtered by the frequency domain mask matrix to map the frequency domain features back from the frequency domain space to the original feature space;
[0024] By combining the projection matrix and scaling factor, a linear transformation is performed on the inverse transformed features to obtain the frequency-aware low-rank adaptive updated output feature representation. The output feature representation is then fused with the original output of the pre-trained large language model to complete the frequency-aware low-rank adaptive fine-tuning of the pre-trained large language model.
[0025] Optionally, the smart contract to be tested includes multiple source code blocks, each source code block includes multiple code snippets, each code snippet represents a specific functional module, and the code attributes include interface names, function definitions, and their corresponding variable declarations.
[0026] Optionally, the smart contract vulnerability detection report includes the vulnerability type, vulnerability location, cause, risk level, attack consequences, and remediation suggestions.
[0027] A smart contract vulnerability detection device based on frequency-aware low-rank adaptation, provided for another purpose of this application, includes:
[0028] The basic vulnerability analysis module is configured to obtain the structured representation corresponding to the smart contract to be detected, and input the structured representation into a pre-trained large language model for semantic analysis and logical inference to identify the preliminary vulnerability type in the smart contract and its corresponding credibility.
[0029] The model building module is configured to use the initial vulnerability type and its corresponding credibility as reference data for fine-tuning the pre-trained large language model using frequency-aware low-rank adaptation. Two low-rank adaptation modules are inserted into some linear layers of the large language model. The training update of the linear layer weights of the large language model is decomposed into the product of two low-rank matrices. Only the parameters of the low-rank adaptation modules are updated and the main parameters of the large language model are frozen.
[0030] The frequency domain feature filtering module is configured to perform a discrete Fourier transform on the low-rank update information output by the low-rank adaptation module, map its feature dimensions to the frequency domain space, and use Passevar's theorem to maintain energy conservation in the frequency domain; a frequency domain mask matrix is constructed through a preset binary frequency domain selection mask and a learnable gate vector to filter frequency domain features.
[0031] The frequency domain feature fusion module is configured to perform an inverse Fourier transform on the filtered frequency domain features to map them back to the original feature space. It then combines the projection matrix and scaling factor to obtain the frequency-aware low-rank adaptive updated output feature representation, which is then fused with the original output of the pre-trained large language model to complete the fine-tuning of the large language model.
[0032] The smart contract vulnerability detection module is configured to input the structured representation corresponding to the smart contract to be detected into the large language model after being fine-tuned by the frequency-aware low-rank adaptation, so as to output a smart contract vulnerability detection report and complete the smart contract vulnerability detection based on frequency-aware low-rank adaptation.
[0033] An electronic device provided for another purpose of this application includes a central processing unit and a memory, the central processing unit being configured to invoke and run a computer program stored in the memory to perform the steps of the frequency-aware low-rank adaptive smart contract vulnerability detection method described in this application.
[0034] A computer-readable storage medium is provided for another purpose of this application, which stores, in the form of computer-readable instructions, a computer program implemented according to the frequency-aware low-rank adaptive smart contract vulnerability detection method, which, when invoked by a computer, executes the steps included in the corresponding method.
[0035] Compared to existing technologies, this application addresses the shortcomings of current smart contract vulnerability detection technologies, such as insufficient detection accuracy and low efficiency, when faced with increasingly complex and varied contract code structures and emerging new attack vectors. This application offers the following advantages, including but not limited to:
[0036] Firstly, the smart contract vulnerability detection method proposed in this application focuses on training large language models based on Frequency-Aware Low-Rank Adaptation (FA-LoRA). FA-LoRA is an efficient parameter fine-tuning method that significantly enhances the model's adaptability to smart contract code and detection accuracy by introducing frequency domain sparsity into the pre-trained large language model.
[0037] Secondly, one of the core innovations of Frequency-Aware Low-Rank Adaptation (FA-LoRA) lies in applying Fourier transform to the low-rank update process. Specifically, FA-LoRA maps the feature dimensions of the low-rank update to the frequency domain space through Fourier transform, selectively retaining the most informative spectral components, thereby reducing redundancy and enhancing the signal-to-noise ratio. This process not only improves the model's ability to understand complex code logic but also significantly reduces the risk of overfitting and improves the model's generalization ability.
[0038] In applications of Fourier transform, Frequency-Aware Low-Rank Adaptation (FA-LoRA) utilizes Parseval's theorem to ensure that energy remains constant in the frequency domain, thus preserving key information while removing noise. Furthermore, by applying masking and gating mechanisms in the frequency domain, FA-LoRA can further optimize low-rank updates, making them more adaptable to the semantic features of smart contract code.
[0039] Thirdly, this application inputs the smart contract code into a pre-trained large language model, leveraging its powerful syntactic and semantic understanding capabilities to perform in-depth parsing of the contract code. Based on this, FA-LoRA selectively preserves high-frequency information in low-rank updates through Fourier transform, effectively improving the model's ability to understand complex code logic. This technique not only improves detection accuracy but also significantly enhances the model's operating efficiency, enabling it to quickly adapt to diverse vulnerability features in smart contract code.
[0040] Furthermore, through efficient fine-tuning of Frequency Aware Low-Rank Adaptation (FA-LoRA), this application achieves efficient and accurate detection of smart contract vulnerabilities. In the detection process, the introduction of FA-LoRA technology enables the entire detection framework to perform exceptionally well when handling complex smart contract code, significantly improving the efficiency and accuracy of vulnerability detection. Attached Figure Description
[0041] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, wherein:
[0042] Figure 1This is a flowchart illustrating the smart contract vulnerability detection method based on frequency-aware low-rank adaptation in the embodiments of this application.
[0043] Figure 2 This is an exemplary network architecture diagram of the smart contract vulnerability detection system based on frequency-aware low-rank adaptation in the embodiments of this application;
[0044] Figure 3 This is an exemplary network architecture diagram of a large language model based on frequency-aware low-rank adaptation in the embodiments of this application;
[0045] Figure 4 This is a schematic diagram of the smart contract vulnerability detection device based on frequency-aware low-rank adaptation in the embodiments of this application;
[0046] Figure 5 This is a schematic diagram of the structure of the computer device in the embodiments of this application. Detailed Implementation
[0047] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain this application, and should not be construed as limiting this application.
[0048] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the term “comprising” as used in this application means the presence of the stated features, integers, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof. It should be understood that when we say an element is “connected” or “coupled” to another element, it can be directly connected or coupled to the other element, or there may be intermediate elements. Furthermore, “connected” or “coupled” as used herein can include wireless connections or wireless coupling. The term “and / or” as used herein includes all or any units and all combinations of one or more associated listed items.
[0049] Those skilled in the art will understand that, unless otherwise defined, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains. It should also be understood that terms such as those defined in general dictionaries should be understood to have the same meaning as in the context of the prior art, and should not be interpreted in an idealized or overly formal sense unless specifically defined as herein.
[0050] Those skilled in the art will understand that the terms "client," "terminal," and "terminal device" as used herein include both devices that receive wireless signals, devices that only possess wireless signal receiver capabilities without transmission capabilities, and devices with receiving and transmitting hardware, devices that have receiving and transmitting hardware capable of bidirectional communication over a bidirectional communication link. Such devices may include: cellular or other communication devices such as personal computers or tablets, having single-line displays, multi-line displays, or cellular or other communication devices without multi-line displays; PCS (Personal Communications Service) that can combine voice, data processing, fax, and / or data communication capabilities; PDAs (Personal Digital Assistants) that may include radio frequency receivers, pagers, internet / intranet access, web browsers, notebooks, calendars, and / or GPS (Global Positioning System) receivers; and conventional laptops and / or handheld computers or other devices that have and / or include radio frequency receivers. As used herein, "client," "terminal," and "terminal device" can be portable, transportable, installed in a means of transportation (air, sea, and / or land), or suitable and / or configured to operate locally and / or in a distributed manner, operating in any other location on Earth and / or in space. "Client," "terminal," and "terminal device" as used herein can also be a communication terminal, an internet access terminal, or a music / video playback terminal, such as a PDA, a MID (Mobile Internet Device), and / or a mobile phone with music / video playback capabilities, or a smart TV, set-top box, etc.
[0051] The hardware referred to by the names "server," "client," and "service node" in this application is essentially an electronic device with the equivalent capabilities of a personal computer. It is a hardware device with the necessary components revealed by the von Neumann architecture, such as a central processing unit (including an arithmetic logic unit and a control unit), memory, input devices, and output devices. The computer program is stored in its memory, and the central processing unit loads the program stored in the secondary storage into the main memory to run it, execute the instructions in the program, and interact with the input and output devices to complete specific functions.
[0052] It should be noted that the concept of "server" used in this application can also be extended to the case of server clusters. Based on the network deployment principles understood by those skilled in the art, the servers should be logically divided. Physically, these servers can be independent of each other but accessible through interfaces, or they can be integrated into a single physical computer or a computer cluster. Those skilled in the art should understand this flexibility and should not use it to constrain the implementation of the network deployment method in this application.
[0053] One or more of the technical features of this application, unless explicitly specified herein, can be deployed on a server and accessed by a client remotely calling the online service interface provided by the server, or can be directly deployed and run on a client for access.
[0054] Unless otherwise specified, the neural network models referenced or potentially referenced in this application may be deployed on a remote server and invoked remotely on the client, or deployed on a client with the capability to invoke directly. In some embodiments, when running on the client, the corresponding intelligence may be acquired through transfer learning in order to reduce the requirements on the client's hardware resources and avoid excessive consumption of the client's hardware resources.
[0055] Unless otherwise specified, all data involved in this application may be stored remotely on a server or on a local terminal device, as long as it is suitable for use by the technical solution of this application.
[0056] Those skilled in the art will understand that although the various methods in this application are described based on the same concept and thus present commonality among them, they can be performed independently unless otherwise specified. Similarly, the various embodiments disclosed in this application are all based on the same inventive concept; therefore, concepts expressed in the same way, as well as concepts that are appropriately changed for convenience but are expressed differently, should be understood equivalently.
[0057] Unless otherwise expressly stated, the various embodiments disclosed in this application can be combined in a cross-cutting manner to flexibly construct new embodiments, as long as such combination does not depart from the inventive spirit of this application and can meet the needs of the prior art or solve a certain deficiency in the prior art. Those skilled in the art should be aware of such modifications.
[0058] Please see Figure 1 as well as Figure 2 In one embodiment of the frequency-aware low-rank adaptive smart contract vulnerability detection method of this application, the method includes:
[0059] Step S10: Obtain the structured representation corresponding to the smart contract to be detected, and input the structured representation into a pre-trained large language model for semantic analysis and logical inference to identify the preliminary vulnerability type in the smart contract and its corresponding credibility.
[0060] A frequency-aware low-rank adaptive smart contract vulnerability detection system in a terminal device can acquire a structured representation of the smart contract to be detected. This structured representation is then input into a pre-trained large language model for semantic analysis and logical inference to identify the initial vulnerability type and its corresponding credibility in the smart contract. The smart contract to be detected comprises multiple source code blocks, each containing multiple code snippets. Each code snippet represents a specific functional module, and its attributes include interface names, function definitions, and corresponding variable declarations. The underlying network architecture of the large language model is a Transformer architecture, among others.
[0061] In some embodiments, the step of determining the structured representation corresponding to the smart contract to be detected includes:
[0062] Step S101: Obtain the source code of the smart contract to be tested, and perform formatting, lexical analysis, and syntax parsing operations on the source code in sequence. At the same time, extract the function and variable, control flow and data flow information, interface name, function definition and variable declaration class code attributes corresponding to each function definition in the source code to determine the preprocessed source code.
[0063] Step S102: Convert the preprocessed source code into a structured representation that can be used by a pre-trained large language model for semantic analysis and logical inference.
[0064] Specifically, taking the Transformer architecture as the basic network architecture of the large language model as an example, the smart contract to be detected is structurally transformed to adapt to the code understanding logic of the pre-trained large language model. Then, relying on the natural language and code semantic analysis capabilities of the large language model, the initial vulnerability screening of the smart contract is completed, and the initial vulnerability type with credibility is output. This provides targeted reference data for the subsequent frequency-aware low-rank adaptation (FA-LoRA) fine-tuning of the large language model, allowing the model fine-tuning to focus more on the vulnerability characteristics of the smart contract and improving the accuracy of subsequent fine-tuning and detection.
[0065] The frequency-aware low-rank adaptive smart contract vulnerability detection system for terminal devices first standardizes the original smart contract to be detected. It deconstructs the smart contract code according to the hierarchy of source code blocks, code snippets, and functional modules. At the same time, it extracts the core code attributes of the smart contract, including interface names, function definitions, and corresponding variable declarations. Then, it performs operations such as formatting, lexical analysis, syntax parsing, control flow and data flow analysis. Finally, it converts the unstructured smart contract source code into a structured representation that can be directly recognized and analyzed by a pre-trained large language model, thus solving the problem of incompatibility between the original code and the input format of the large language model.
[0066] The frequency-aware low-rank adaptive smart contract vulnerability detection system inputs the aforementioned structured representation into a pre-trained large language model. Utilizing the code patterns, semantic information, and vulnerability feature knowledge learned during the large language model's pre-training process, it performs deep semantic analysis and logical inference on the structured representation. This automatically identifies potential risk patterns in the contract, such as reentrancy risks, incorrect permission settings, arithmetic risks, and insecure calls, and outputs the preliminary vulnerability types identified. Simultaneously, it assigns a corresponding confidence level to each vulnerability type. The confidence level represents the degree of confidence the large language model has in its vulnerability assessment.
[0067] In some embodiments, users upload the source code corresponding to the smart contract. The system performs formatting, lexical analysis, and syntactic parsing on the smart contract to be tested, obtaining a structured representation of the smart contract. The calculation formula is as follows:
[0068] ;
[0069] in, This represents the preprocessing functions, which include lexical analysis and syntax parsing, encoding conversion, etc. This represents the structured representation of the smart contract to be tested.
[0070] Will The input is fed into the large language model fine-tuned by FA-LoRA to obtain the vulnerability analysis results, which are represented as follows:
[0071] ;
[0072] in, Vulnerability detection results of large language models are fine-tuned using Frequency Aware Low-Rank Adaptation (FA-LoRA).
[0073] Step S20: Use the preliminary vulnerability type and its corresponding credibility as reference data for fine-tuning the pre-trained large language model using frequency-aware low-rank adaptation. Insert two low-rank adaptation modules into some linear layers of the large language model. Decompose the training update of the linear layer weights of the large language model into the product of two low-rank matrices. Update only the parameters of the low-rank adaptation modules and freeze the main parameters of the large language model.
[0074] The structured representation corresponding to the smart contract to be detected is obtained. The structured representation is then input into a pre-trained large language model for semantic analysis and logical inference to identify the initial vulnerability types and their corresponding credibility in the smart contract. The initial vulnerability types and their corresponding credibility are then used as reference data for fine-tuning the pre-trained large language model using the Frequency Aware Low-Rank Adaptation (FA-LoRA) method. Two low-rank adaptation modules are inserted into some linear layers of the large language model. The training and update of the linear layer weights of the large language model are decomposed into the product of two low-rank matrices. Only the parameters of the low-rank adaptation modules are updated, and the main parameters of the large language model are frozen.
[0075] Specifically, the preliminary vulnerability types and their corresponding credibility obtained from the basic vulnerability analysis in step S10 are used as reference data for fine-tuning the pre-trained large language model, allowing the fine-tuning of the large language model to focus on the vulnerability characteristics of the smart contract to be detected; at the same time, through the transformation of the low-rank adaptive architecture, the pre-trained large language model is made lightweight, decomposing the training and updating of the linear layer weights into low-rank matrix operations, updating only the parameters of the newly added low-rank adaptive modules and freezing the main parameters of the model, realizing efficient parameter fine-tuning, significantly reducing computing power and memory consumption, and adapting to the application environment where blockchain resources are limited.
[0076] The preliminary vulnerability types and corresponding credibility output by the pre-trained large language model are used to enhance the model's sensitivity to smart contract vulnerability features. In this embodiment, the preliminary vulnerability types and corresponding credibility are used as dedicated reference data for frequency-aware low-rank adaptation (FA-LoRA) fine-tuning, so that subsequent low-rank adaptation module parameter updates and frequency domain feature processing are all centered around the potential vulnerability direction of the contract to be detected, avoiding aimless generalization fine-tuning, and making the fine-tuned model more accurately match the vulnerability identification requirements of the current detection task.
[0077] For further details, please refer to Figure 3 In the partially linear layers of the pre-trained large language model, that is Figure 3 In the linear layers corresponding to the multi-head attention layer and feedforward layer of the Transformer architecture, two small low-rank adaptation modules (adapter layers) are inserted. These two low-rank adaptation modules are the only parts that need to update parameters later, providing a physical architecture carrier for low-rank matrix operations.
[0078] Furthermore, let the original weight matrix of the linear layer in the large language model be... Its dimensions are ,in, The input feature dimension of the linear layer, This represents the output feature dimension of the linear layer. Low-rank adaptation (LoRA) updates the training parameters of the linear layer weights in a large language model. Decomposed into two low-dimensional matrices , The product of and is calculated using the following formula:
[0079] ;
[0080] in, This represents the amount of training update for the linear layer weights of a large language model, which is also the weight change value that LoRA fine-tuning needs to learn, replacing the full weight update of traditional full parameter fine-tuning. Let represent the first low-dimensional matrix, whose dimension is . To achieve input features from high dimensions to lower dimensions Mapping; Let this be the second low-dimensional matrix, with dimension 1. To achieve input features from low dimension To higher dimensions The restoration; This indicates a low-rank dimension.
[0081] As can be seen from the above calculation formula, the high-dimensional weight matrix that originally required a full update can be transformed. The training update is transformed into two low-dimensional matrices. , The product of these parameters significantly reduces the number of parameters that need to be updated when fine-tuning large language models, reducing the total number of parameters from [previous value]. Down to It realizes the core idea of Low Rank Adaptive (LoRA) "lightweight fine-tuning" to adapt to the environment where blockchain resources are limited.
[0082] Only the parameters of the low-rank adaptation module are updated, and the main parameters of the large language model are frozen, that is, all main parameters of the pre-trained large language model are frozen, including the original linear layer weights. The parameters of all core layers, including the multi-head attention layer and feedforward layer of the large language model, are updated to avoid disrupting the model's pre-trained general code understanding capabilities through fine-tuning; only the parameters of the two low-rank adaptation modules are updated, namely the two low-dimensional matrices mentioned above. , The parameters are reduced by an order of magnitude to achieve this reduction in the number of parameters.
[0083] Furthermore, the hidden state output formula for low-rank adaptation (LoRA) is expressed as:
[0084] ;
[0085] in, Represents the input hidden state of a large language model; The original output of the large language model is calculated from the frozen main parameters, ensuring the basic capabilities of the model. This represents low-rank update information, which is the output of the low-rank adaptation module and is calculated from the parameters of the low-rank matrix that are only updated. It focuses on learning the vulnerability features of smart contracts. This represents the scaling factor, used to balance the weights of the original output and the output of the low-rank adaptation module.
[0086] As can be seen from step S20 above, compared to full parameter fine-tuning which requires updating hundreds of millions or billions of parameters, this step only updates millions of parameters in two low-rank matrices, reducing training parameters by 10 to 100 times, and training can be completed on a single consumer-grade graphics card. Freezing the main parameters of the large language model avoids "catastrophic forgetting," allowing the large language model to still use pre-trained code syntax and semantic understanding capabilities to parse smart contracts. Using preliminary vulnerability results as reference data, the low-rank modules only learn features related to vulnerabilities, improving fine-tuning efficiency and the accuracy of subsequent vulnerability detection. The parameter-efficient and low-computing-power-requirement design perfectly matches the resource-constrained application scenarios of blockchain, solving the problem that traditional full parameter fine-tuning cannot be implemented in this environment.
[0087] Step S30: Perform a discrete Fourier transform on the low-rank update information output by the low-rank adaptation module, map its feature dimensions to the frequency domain space, and use Passevar's theorem to maintain energy conservation in the frequency domain; construct a frequency domain mask matrix through a preset binary frequency domain selection mask and a learnable gating vector to filter the frequency domain features.
[0088] The initial vulnerability types and their corresponding credibility are used as reference data for fine-tuning the pre-trained large language model using frequency-aware low-rank adaptation. Two low-rank adaptation modules are inserted into some linear layers of the large language model. The training update of the linear layer weights of the large language model is decomposed into the product of two low-rank matrices. After updating only the parameters of the low-rank adaptation modules and freezing the main parameters of the large language model, the low-rank update information output by the low-rank adaptation modules is subjected to discrete Fourier transform to map its feature dimensions to the frequency domain space. The energy conservation in the frequency domain is maintained using Passevar's theorem. A frequency domain mask matrix is constructed using a preset binary frequency domain selection mask and a learnable gating vector to filter the frequency domain features.
[0089] In some embodiments, the step of performing a discrete Fourier transform on the low-rank update information output by the low-rank adaptation module, mapping its feature dimensions to the frequency domain, and using Passevar's theorem to maintain energy conservation in the frequency domain includes:
[0090] Step S301: Perform Discrete Fourier Transform processing on the low-rank update information output by the low-rank adaptation module inserted in the linear layer of the large language model, and map the feature dimension of the low-rank update information to the frequency domain space through the normalized Discrete Fourier Transform matrix.
[0091] Step S302: The data processing of the discrete Fourier transform is constrained by Passevar's theorem to maintain the energy conservation of low-rank update information in the frequency domain space, and the low-rank update information is mapped from the feature space to the frequency domain space without loss.
[0092] In a further embodiment, the step of constructing a frequency domain mask matrix using a preset binary frequency domain selection mask and a learnable gating vector to filter frequency domain features includes:
[0093] Step S3001: Obtain the preset binary frequency domain selection mask and learnable gating vector;
[0094] Step S3002: A frequency domain mask matrix is constructed from the binary frequency domain selection mask and the learnable gating vector. The frequency domain mask matrix is applied to the frequency domain features obtained by discrete Fourier transform. Filtering is performed on the frequency domain features to suppress low-contribution frequency band features and retain or amplify high-contribution frequency band features.
[0095] Specifically, this is achieved by normalizing the Discrete Fourier Transform (DFT) matrix. Update low-rank information The formula for transforming from the original feature space to the frequency domain is expressed as follows:
[0096] ,
[0097] in, Represents the normalized discrete Fourier transform (DFT) matrix; Represents frequency domain characteristics; This represents low-rank update information, which is the output of the low-rank adaptation module.
[0098] As can be seen from the above calculation formula, the time-domain features focus on the sequence features and structural features of low-rank update information, such as the function call order and variable update sequence of smart contract code. The frequency-domain features can be decomposed into high-frequency components and low-frequency components. The high-frequency components correspond to the semantic details of smart contract code, such as interface names, function definitions, and variable declarations. The low-frequency components correspond to the global logical pattern of the contract, such as cross-function dependencies, call chain structure, and overall execution flow. After mapping the time-domain features to the frequency domain, it is possible to distinguish between effective features related to vulnerabilities and invalid features such as code redundancy and noise from the frequency dimension, which solves the problem that traditional LoRA is difficult to accurately filter features in the time domain.
[0099] The data processing of the discrete Fourier transform is constrained by Passevar's theorem to maintain the energy conservation of low-rank update information in the frequency domain. The calculation formula is as follows:
[0100] ;
[0101] in, Represents frequency domain characteristics; This represents low-rank update information, which is the output of the low-rank adaptation module.
[0102] As shown in the above calculation formula, the core of Parseval's theorem is that the total energy of a signal in the time domain is equal to its total energy in the frequency domain. Applying this to the frequency domain transformation of FA-LoRA ensures that the Discrete Fourier Transform only performs spatial transformation of the feature dimensions, without losing any feature information. This avoids energy loss of key features related to vulnerabilities due to frequency domain transformation, ensuring that subsequent frequency domain filtering only suppresses the energy of noise and redundant features, rather than destroying effective features. This achieves lossless feature space transformation, laying a data foundation for subsequent accurate screening of key features.
[0103] Furthermore, a frequency domain mask matrix is constructed from the binary frequency domain selection mask and the learnable gating vector. A preset binary frequency domain selection mask can be obtained first. Combined with learnable gating vectors Constructing a frequency domain mask matrix using Hadamard product Its calculation formula is expressed as:
[0104] ;
[0105] in, Represents the frequency domain mask matrix; This represents a binary frequency domain selection mask; Represents a learnable gated vector; This represents the Hadamard product (element-by-element multiplication).
[0106] More specifically, binary frequency domain selection mask The elements are only 0 or 1, representing a manually preset fixed mask. 1 indicates that features of the corresponding frequency band are retained (e.g., high-frequency semantic details and low-frequency global logic related to smart contract vulnerabilities), while 0 indicates preliminary filtering of noise and redundant features of the corresponding frequency band (e.g., meaningless code formatting and irrelevant variable naming), achieving a coarse screening of frequency domain features. Learnable gating vectors This is a continuous value vector that is automatically learned during the fine-tuning of the large language model. Its elements are weight values between 0 and 1, which realizes fine adjustment of features after binary mask screening. For frequency bands that contribute highly to vulnerability detection, the gating vector will learn a weight close to 1 to amplify its feature influence; for frequency bands that contribute little, it will learn a weight close to 0 to further suppress its influence.
[0107] Selecting a mask in the binary frequency domain With learnable gated vectors Element-wise multiplication is performed, combining a fixed preset binary filter with weight adjustments learned autonomously by the model, to obtain the final frequency domain mask matrix. It conforms to the prior knowledge of smart contract vulnerability detection and can adapt to the code characteristics of different contracts, thus improving the universality and accuracy of the mask.
[0108] Furthermore, the frequency domain mask matrix Applying to the frequency domain features obtained through the discrete Fourier transform For frequency domain features The filtering process is performed to suppress low-contribution frequency band features and preserve or amplify high-contribution frequency band features. The calculation formula is expressed as follows:
[0109] ;
[0110] in, This represents the filtered frequency domain characteristics; Represents the frequency domain mask matrix; It represents the frequency domain characteristics.
[0111] From the above calculation formula, it can be seen that the frequency domain mask matrix The element weights will be related to the frequency domain features The corresponding frequency bands are weighted element by element to suppress low-contribution frequency bands (such as noise features, redundancy features, etc.) and retain or amplify high-contribution frequency bands (key features related to vulnerabilities).
[0112] As can be seen from step S30 above, frequency domain decomposition distinguishes high-frequency features from low-frequency features, accurately capturing the semantic details and global logic of smart contracts; feature filtering enhances key features related to vulnerabilities, making it easier for the model to identify complex vulnerabilities and variant vulnerabilities; noise suppression and key feature enhancement prevent the model from overfitting to the code features of the training set, improving the ability to detect unknown smart contracts.
[0113] Step S40: Perform inverse Fourier transform on the filtered frequency domain features to map them back to the original feature space. Combine the projection matrix and scaling factor to obtain the frequency-aware low-rank adaptive updated output feature representation. Then fuse it with the original output of the pre-trained large language model to complete the fine-tuning of the large language model.
[0114] The low-rank update information output by the low-rank adaptation module is subjected to discrete Fourier transform to map its feature dimensions to the frequency domain space, and energy conservation in the frequency domain is maintained by using Passevar's theorem. A frequency domain mask matrix is constructed by using a preset binary frequency domain selection mask and a learnable gating vector to filter the frequency domain features. After filtering, the frequency domain features are subjected to inverse Fourier transform to map back to the original feature space. The output feature representation updated by the frequency-aware low-rank adaptation is obtained by combining the projection matrix and scaling coefficient. This updated feature representation is then fused with the original output of the pre-trained large language model to complete the fine-tuning of the large language model.
[0115] In some embodiments, an inverse Fourier transform is performed on the filtered frequency domain features to map them back to the original feature space. The frequency-aware low-rank adaptive updated output feature representation is then obtained by combining the projection matrix and scaling coefficients. This updated representation is then fused with the original output of the pre-trained large language model to complete the fine-tuning of the large language model. This process includes:
[0116] Step S401: Perform an inverse Fourier transform on the frequency domain features filtered by the frequency domain mask matrix to map the frequency domain features back from the frequency domain space to the original feature space.
[0117] Step S402: Combine the projection matrix and scaling factor to perform linear transformation on the inverse transformed features to obtain the frequency-aware low-rank adaptive updated output feature representation. Then, fuse the output feature representation with the original output of the pre-trained large language model to complete the frequency-aware low-rank adaptive fine-tuning of the pre-trained large language model.
[0118] Specifically, an inverse Fourier transform is performed on the frequency domain features filtered by the frequency domain mask matrix to map the frequency domain features back from the frequency domain space to the original feature space; this is achieved by using the conjugate transpose of the normalized Fourier transform (DFT) matrix. The filtered frequency domain features The formula for converting from the frequency domain space back to the original feature space that can be directly processed by a large language model is as follows:
[0119] ;
[0120] in, This represents the time-domain characteristics after the inverse transform; This represents the conjugate transpose of the normalized Fourier transform (DFT) matrix; This represents the frequency domain characteristics after filtering.
[0121] The inverse Fourier transform is the inverse operation of the discrete Fourier transform mentioned above. Together with the lossless frequency domain mapping based on Passevar's theorem, it forms a closed loop, ensuring that the vulnerability-related key features, after frequency domain filtering, maintain information integrity during spatial transformation, only completing the formal transformation from the frequency dimension to the feature dimension. The frequency domain is the optimization space for feature filtering, while subsequent feature fusion and output calculation of the large language model are based on the original feature space. This operation allows the frequency-domain optimized features to be re-adapted to the original architecture of the model, providing a format-compatible feature foundation for subsequent fusion with the model's original output. This is a crucial connecting step in the implementation of FA-LoRA frequency domain processing.
[0122] Furthermore, by combining the projection matrix and scaling factors, a linear transformation is performed on the inverse-transformed features to obtain the frequency-aware low-rank adaptive updated output feature representation, which is then used to transform the time-domain features of the inverse transformation. sequentially with the projection matrix Performing matrix multiplication and scaling factors Perform scalar multiplication to adapt the dimensions and adjust the weights of the filtered features, preparing them for fusion with the original model output.
[0123] More specifically, the time-domain features after frequency domain filtering and inverse transform Its dimensionality or feature distribution may differ from the original output of the large language model. There are differences, projection matrix Linear transformations are used to align feature dimensions and match feature distributions, ensuring that the two types of features have a basis for fusion and avoiding fusion failure due to inconsistencies in dimension and distribution. Scaling factor. As an adjustable scalar hyperparameter, The scaling factor is used to balance the feature weights optimized by FA-LoRA in the frequency domain and can be flexibly adjusted according to the task requirements of smart contract vulnerability detection. If it is necessary to strengthen the influence of vulnerability-related features, the scaling factor can be increased. If it is necessary to retain the general code comprehension capabilities of the model pre-training, the scaling factor can be reduced. This enables task-oriented feature weight control.
[0124] Furthermore, the features processed by the projection matrix and scaling factors are compared with the original output of the pre-trained large language model. The features are summed and fused to obtain the final output feature representation updated by FA-LoRA. The calculation formula is expressed as follows:
[0125] ;
[0126] in, This represents the final output feature representation after FA-LoRA update; Represents the projection matrix;
[0127] Indicates the scaling factor; This represents the raw output of the large language model; This represents the time-domain characteristics after the inverse transform.
[0128] When the final output feature representation After generating and replacing the original linear layer output, the FA-LoRA fine-tuning of the pre-trained large language model is completed, and the forward propagation logic of the large language model is officially updated to the mode of freezing the main parameters and optimizing feature fusion using FA-LoRA.
[0129] Step S50: Input the structured representation corresponding to the smart contract to be detected into the large language model after being fine-tuned by the frequency-aware low-rank adaptation, so as to output a smart contract vulnerability detection report and complete the smart contract vulnerability detection based on frequency-aware low-rank adaptation.
[0130] The filtered frequency domain features are subjected to an inverse Fourier transform to map back to the original feature space. The updated output feature representation, obtained by combining the projection matrix and scaling coefficients, is then fused with the original output of a pre-trained large language model to fine-tune the model. Finally, the structured representation corresponding to the smart contract to be detected is input into the fine-tuned large language model to output a smart contract vulnerability detection report, thus completing the smart contract vulnerability detection based on frequency-aware low-rank adaptation. The smart contract vulnerability detection report includes the vulnerability type, vulnerability location, cause, risk level, attack consequences, and remediation suggestions.
[0131] As can be seen from the above embodiments, compared with the prior art, the present application addresses the problems of insufficient detection accuracy and low efficiency in existing smart contract vulnerability detection technologies when facing increasingly complex and varied contract code structures and constantly emerging new attack vectors. The present application includes, but is not limited to, the following beneficial effects:
[0132] Firstly, the smart contract vulnerability detection method proposed in this application focuses on training large language models based on Frequency-Aware Low-Rank Adaptation (FA-LoRA). FA-LoRA is an efficient parameter fine-tuning method that significantly enhances the model's adaptability to smart contract code and detection accuracy by introducing frequency domain sparsity into the pre-trained large language model.
[0133] Secondly, one of the core innovations of Frequency-Aware Low-Rank Adaptation (FA-LoRA) lies in applying Fourier transform to the low-rank update process. Specifically, FA-LoRA maps the feature dimensions of the low-rank update to the frequency domain space through Fourier transform, selectively retaining the most informative spectral components, thereby reducing redundancy and enhancing the signal-to-noise ratio. This process not only improves the model's ability to understand complex code logic but also significantly reduces the risk of overfitting and improves the model's generalization ability.
[0134] In applications of Fourier transform, Frequency-Aware Low-Rank Adaptation (FA-LoRA) utilizes Parseval's theorem to ensure that energy remains constant in the frequency domain, thus preserving key information while removing noise. Furthermore, by applying masking and gating mechanisms in the frequency domain, FA-LoRA can further optimize low-rank updates, making them more adaptable to the semantic features of smart contract code.
[0135] Thirdly, this application inputs the smart contract code into a pre-trained large language model, leveraging its powerful syntactic and semantic understanding capabilities to perform in-depth parsing of the contract code. Based on this, FA-LoRA selectively preserves high-frequency information in low-rank updates through Fourier transform, effectively improving the model's ability to understand complex code logic. This technique not only improves detection accuracy but also significantly enhances the model's operating efficiency, enabling it to quickly adapt to diverse vulnerability features in smart contract code.
[0136] Furthermore, through efficient fine-tuning of Frequency Aware Low-Rank Adaptation (FA-LoRA), this application achieves efficient and accurate detection of smart contract vulnerabilities. In the detection process, the introduction of FA-LoRA technology enables the entire detection framework to perform exceptionally well when handling complex smart contract code, significantly improving the efficiency and accuracy of vulnerability detection.
[0137] Please see Figure 4A smart contract vulnerability detection device based on frequency-aware low-rank adaptation, provided to meet one of the purposes of this application, includes a basic vulnerability analysis module 1100, a model building module 1200, a frequency domain feature filtering module 1300, a frequency domain feature fusion module 1400, and a smart contract vulnerability detection module 1500. Among them, The basic vulnerability analysis module 1100 is configured to acquire the structured representation corresponding to the smart contract to be detected, input the structured representation into a pre-trained large language model for semantic analysis and logical inference, so as to identify the preliminary vulnerability type and its corresponding credibility in the smart contract; the model building module 1200 is configured to use the preliminary vulnerability type and its corresponding credibility as reference data for fine-tuning the pre-trained large language model using frequency-aware low-rank adaptation, insert two low-rank adaptation modules into some linear layers of the large language model, decompose the training update of the linear layer weights of the large language model into the product of two low-rank matrices, update only the parameters of the low-rank adaptation modules and freeze the main parameters of the large language model; the frequency domain feature filtering module 1300 is configured to perform discrete Fourier transform on the low-rank update information output by the low-rank adaptation modules. The system maps the feature dimensions to the frequency domain space and uses Passevar's theorem to maintain energy conservation in the frequency domain. A frequency domain mask matrix is constructed using a preset binary frequency domain selection mask and a learnable gating vector to filter the frequency domain features. A frequency domain feature fusion module 1400 performs an inverse Fourier transform on the filtered frequency domain features to map them back to the original feature space. It then combines the projection matrix and scaling coefficients to obtain the frequency-aware low-rank adaptive updated output feature representation, which is then fused with the original output of the pre-trained large language model to complete the fine-tuning of the large language model. A smart contract vulnerability detection module 1500 inputs the structured representation corresponding to the smart contract to be detected into the large language model after fine-tuning by the frequency-aware low-rank adaptation to output a smart contract vulnerability detection report, thus completing the smart contract vulnerability detection based on frequency-aware low-rank adaptation.
[0138] Based on any embodiment of this application, please refer to Figure 5 Another embodiment of this application also provides an electronic device, which can be implemented by a computer device, such as... Figure 5The diagram shows the internal structure of a computer device. The computer device includes a processor, a computer-readable storage medium, a memory, and a network interface connected via a system bus. The computer-readable storage medium stores an operating system, a database, and computer-readable instructions. The database may store control information sequences. When the computer-readable instructions are executed by the processor, the processor can implement a frequency-aware low-rank adaptive smart contract vulnerability detection method. The processor of the computer device provides computing and control capabilities to support the operation of the entire computer device. The memory of the computer device may store computer-readable instructions. When the computer-readable instructions are executed by the processor, the processor can execute the frequency-aware low-rank adaptive smart contract vulnerability detection method of this application. The network interface of the computer device is used for communication with a terminal. Those skilled in the art will understand that… Figure 5 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0139] In this embodiment, the processor is used to execute... Figure 4 The specific functions of each module are defined within the device, and the memory stores the program code and various data required to execute these modules. The network interface is used for data transmission between the user terminal and the server. In this embodiment, the memory stores the program code and data required to execute all modules in the frequency-aware low-rank adaptive smart contract vulnerability detection device of this application. The server can call the server's program code and data to execute the functions of all modules.
[0140] This application also provides a storage medium storing computer-readable instructions, which, when executed by one or more processors, cause the one or more processors to perform the steps of the frequency-aware low-rank adaptive smart contract vulnerability detection method described in any embodiment of this application.
[0141] This application also provides a computer program product, including a computer program / instructions that, when executed by one or more processors, implement the steps of the frequency-aware low-rank adaptive smart contract vulnerability detection method described in any embodiment of this application.
[0142] Those skilled in the art will understand that 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. This computer program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. The aforementioned storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0143] The above description is only a partial embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A smart contract vulnerability detection method based on frequency-aware low-rank adaptation, characterized in that, include: Obtain the structured representation corresponding to the smart contract to be detected, and input the structured representation into a pre-trained large language model for semantic analysis and logical inference to identify the preliminary vulnerability types in the smart contract and their corresponding credibility. The initial vulnerability type and its corresponding credibility are used as reference data for fine-tuning the pre-trained large language model using frequency-aware low-rank adaptation. Two low-rank adaptation modules are inserted into some linear layers of the large language model. The training update of the linear layer weights of the large language model is decomposed into the product of two low-rank matrices. Only the parameters of the low-rank adaptation modules are updated and the main parameters of the large language model are frozen. The low-rank update information output by the low-rank adaptation module is subjected to discrete Fourier transform to map its feature dimensions to the frequency domain space, and the energy conservation in the frequency domain is maintained by using Passevar's theorem; a frequency domain mask matrix is constructed by using a preset binary frequency domain selection mask and a learnable gating vector to filter the frequency domain features. The filtered frequency domain features are subjected to inverse Fourier transform to map back to the original feature space. The frequency-aware low-rank adaptive updated output feature representation is obtained by combining the projection matrix and scaling coefficient. This representation is then fused with the original output of the pre-trained large language model to complete the fine-tuning of the large language model. The structured representation corresponding to the smart contract to be detected is input into the large language model after being fine-tuned by the frequency-aware low-rank adaptation, so as to output a smart contract vulnerability detection report and complete the smart contract vulnerability detection based on frequency-aware low-rank adaptation.
2. The smart contract vulnerability detection method based on frequency-aware low-rank adaptation according to claim 1, characterized in that, The steps for determining the structured representation corresponding to the smart contract to be tested include: The source code of the smart contract to be tested is obtained, and formatting, lexical analysis, and syntax parsing operations are performed on the source code in sequence. At the same time, the functions and variables, control flow and data flow information, interface names, function definitions and variable declaration class code attributes corresponding to each function definition are extracted from the source code to determine the preprocessed source code. The preprocessed source code is converted into a structured representation that can be used by pre-trained large language models for semantic analysis and logical inference.
3. The smart contract vulnerability detection method based on frequency-aware low-rank adaptation according to claim 1, characterized in that, Perform a Discrete Fourier Transform on the low-rank update information output by the low-rank adaptation module to determine its feature dimensions. The steps for mapping to the frequency domain and using Passevar's theorem to maintain energy conservation in the frequency domain include: The low-rank update information output by the low-rank adaptation module inserted in the linear layer of the large language model is processed by discrete Fourier transform, and the feature dimension of the low-rank update information is mapped to the frequency domain space by normalizing the discrete Fourier transform matrix. The data processing of the discrete Fourier transform is constrained by Passevar's theorem to maintain the energy conservation of low-rank update information in the frequency domain space, and to perform lossless data mapping of the low-rank update information from the feature space to the frequency domain space.
4. The smart contract vulnerability detection method based on frequency-aware low-rank adaptation according to claim 1, characterized in that, The steps for filtering frequency domain features by constructing a frequency domain mask matrix using a preset binary frequency domain selection mask and a learnable gating vector include: Obtain the preset binary frequency domain selection mask and learnable gating vector; A frequency domain mask matrix is constructed from the binary frequency domain selection mask and the learnable gating vector. The frequency domain mask matrix is applied to the frequency domain features obtained by discrete Fourier transform to perform filtering processing on the frequency domain features, so as to suppress low contribution frequency band features and retain or amplify high contribution frequency band features.
5. The smart contract vulnerability detection method based on frequency-aware low-rank adaptation according to claim 4, characterized in that, The filtered frequency domain features are subjected to an inverse Fourier transform to map back to the original feature space. The frequency-aware low-rank adaptive updated output feature representation is then obtained by combining the projection matrix and scaling coefficients. This updated representation is then fused with the original output of the pre-trained large language model to complete the fine-tuning of the large language model, including: Perform an inverse Fourier transform on the frequency domain features filtered by the frequency domain mask matrix to map the frequency domain features back from the frequency domain space to the original feature space; By combining the projection matrix and scaling factor, a linear transformation is performed on the inverse transformed features to obtain the frequency-aware low-rank adaptive updated output feature representation. The output feature representation is then fused with the original output of the pre-trained large language model to complete the frequency-aware low-rank adaptive fine-tuning of the pre-trained large language model.
6. The smart contract vulnerability detection method based on frequency-aware low-rank adaptation according to any one of claims 1 to 5, characterized in that, The smart contract to be tested includes multiple source code blocks, each source code block includes multiple code snippets, each code snippet represents a specific functional module, and the code attributes include interface names, function definitions and their corresponding variable declarations.
7. The smart contract vulnerability detection method based on frequency-aware low-rank adaptation according to any one of claims 1 to 5, characterized in that, The smart contract vulnerability detection report includes the vulnerability type, vulnerability location, cause of occurrence, risk level, attack consequences, and remediation suggestions.
8. A smart contract vulnerability detection device based on frequency-aware low-rank adaptation, characterized in that, include: The basic vulnerability analysis module is configured to obtain the structured representation corresponding to the smart contract to be detected, and input the structured representation into a pre-trained large language model for semantic analysis and logical inference to identify the preliminary vulnerability type in the smart contract and its corresponding credibility. The model building module is configured to use the initial vulnerability type and its corresponding credibility as reference data for fine-tuning the pre-trained large language model using frequency-aware low-rank adaptation. Two low-rank adaptation modules are inserted into some linear layers of the large language model. The training update of the linear layer weights of the large language model is decomposed into the product of two low-rank matrices. Only the parameters of the low-rank adaptation modules are updated and the main parameters of the large language model are frozen. The frequency domain feature filtering module is configured to perform a discrete Fourier transform on the low-rank update information output by the low-rank adaptation module, map its feature dimensions to the frequency domain space, and use Passevar's theorem to maintain energy conservation in the frequency domain; a frequency domain mask matrix is constructed through a preset binary frequency domain selection mask and a learnable gate vector to filter frequency domain features. The frequency domain feature fusion module is configured to perform an inverse Fourier transform on the filtered frequency domain features to map them back to the original feature space. It then combines the projection matrix and scaling factor to obtain the frequency-aware low-rank adaptive updated output feature representation, which is then fused with the original output of the pre-trained large language model to complete the fine-tuning of the large language model. The smart contract vulnerability detection module is configured to input the structured representation corresponding to the smart contract to be detected into the large language model after being fine-tuned by the frequency-aware low-rank adaptation, so as to output a smart contract vulnerability detection report and complete the smart contract vulnerability detection based on frequency-aware low-rank adaptation.
9. An electronic device comprising a central processing unit and a memory, characterized in that, The central processing unit is used to invoke and run a computer program stored in the memory to perform the steps of the method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, It stores, in the form of computer-readable instructions, a computer program implemented according to any one of claims 1 to 7, which, when invoked by a computer, executes the steps included in the corresponding method.