Smart contract processing method and system, electronic equipment and storage medium
By extracting the feature information of the smart contract code and using deep learning models for security risk analysis, the problem of low security detection efficiency of smart contracts in the existing technology is solved, and the security risks in smart contracts are effectively identified and optimized, ensuring blocks Stability and security of chain projects.
Patent Information
- Application Number
- CN202411417098.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-11
- Publication Date
- 2025-02-14
AI Technical Summary
The existing technology has low detection efficiency, incompleteness, and lacks targeted optimization guidance and automation optimization capabilities in the field of smart contract security, making it difficult to effectively identify and repair security risks in smart contracts.
By extracting the characteristic information of the smart contract code and using a multi-layer graph neural network model based on deep learning, the security risk analysis is carried out, and the security risk is identified, and specific optimization information or automatic optimization code is provided to achieve the security risk of the smart contract code. Efficient identification and precise repair and optimization.
It significantly improves the security risk detection efficiency and response speed of smart contract codes, can identify more unknown security issues, provide detailed vulnerability reports and optimization information, improves the targetedness and effectiveness of optimization, and ensures blockchain projects. stability and safety.
Smart Images

Figure CN119442244A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data security technology, and in particular to a method, system, electronic device and storage medium for processing smart contracts. Background Art
[0002] With the rapid development of blockchain technology, smart contracts, as one of the core applications of blockchain technology, have shown great potential and value in many fields such as finance, supply chain management, and the Internet of Things. Smart contracts, through automated execution logic, enable transactions and collaboration without the need for third-party trust, greatly improving the transparency and efficiency of transactions. However, the security issues of smart contracts have also become prominent, becoming a key bottleneck restricting their widespread application.
[0003] At present, in the field of smart contract security, we mainly rely on traditional security measures, such as code auditing, formal verification and vulnerability scanning, which play an important role in discovering and repairing known security vulnerabilities in smart contracts, and effectively ensure the stability and security of blockchain projects. However, in the face of increasingly complex and changing network environments and emerging new attack methods, these traditional methods have low detection efficiency, are not comprehensive, and lack targeted optimization guidance and automated optimization capabilities. Summary of the invention
[0004] The main purpose of this application is to overcome the shortcomings and deficiencies of the prior art and to provide a method, system, electronic device and storage medium for processing smart contracts. By performing a more comprehensive security analysis of the smart contract code based on the extracted features using a deep learning-based model, security risks can be quickly identified. After identifying the security risks, specific optimization information or automatic code optimization is provided, thereby achieving efficient identification and precise repair and optimization of security risks in the smart contract code.
[0005] In order to achieve the above objectives, this application adopts the following technical solutions:
[0006] In the first aspect, the present application provides a method for processing a smart contract, comprising the following steps:
[0007] Obtaining a smart contract code, and performing standardization processing on the obtained smart contract code to obtain a standardized smart contract code;
[0008] Extracting feature information from the standardized smart contract code, where the feature information is used to characterize constituent elements of the standardized smart contract code;
[0009] Performing security risk analysis on the feature information through a preset model to obtain security risk information;
[0010] Analyze the context code where the security risk information is located, determine the cause of the security risk, and generate the smart contract code optimization information according to the cause of the security risk;
[0011] Optimize the smart contract code according to the optimization information.
[0012] As a preferred technical solution, extracting feature information from the standardized smart contract code specifically includes:
[0013] Convert the source code of the standardized smart contract code into a token stream using a regular expression or a lexical analyzer;
[0014] Converting the token stream into an abstract syntax tree using a syntax analyzer;
[0015] Traversing the abstract syntax tree using a depth-first traversal strategy to extract first feature information of the smart contract code;
[0016] An intelligent control flow graph is constructed based on the abstract syntax tree, and second characteristic information of the intelligent contract code is extracted according to the control flow graph.
[0017] As a preferred technical solution, the first characteristic information includes: contract structure, function definition, state variables and event definition;
[0018] The second characteristic information includes: basic blocks, branch structures, loop structures and function calls.
[0019] As a preferred technical solution, after extracting feature information from the standardized smart contract code, it also includes:
[0020] Analyze the definition and use of the state variables and identify the data flow of key state variables;
[0021] converting the data flow of the key state variable, the extracted first feature information and the second feature information into a numerical vector;
[0022] The abstract syntax tree and the control flow graph are converted into graph structure data, and the numerical vector is encoded as attributes of the nodes and edges of the graph structure data.
[0023] As a preferred technical solution, the preset model includes a multi-layer graph neural network structure;
[0024] The security risk analysis of the feature information by using a preset model to obtain security risk information specifically includes:
[0025] Based on the multi-layer graph neural network structure, a multi-round message passing mechanism is adopted to transmit and aggregate information between the nodes to learn the local features and global features of the nodes;
[0026] Based on the local features and global features of the nodes, the importance of different nodes and edges is weighted through an attention mechanism to obtain key code structure and security risk information;
[0027] For the key code structure and security risk information, perform graph-level and node-level classification tasks, and use multi-label classification technology to output different types of security risk probabilities;
[0028] When the security risk probability exceeds a preset security risk probability threshold, it is determined that the security risk information exists.
[0029] As a preferred technical solution, the security risk information includes but is not limited to: reentrancy attack, integer overflow or underflow, unchecked external call, access control problem or denial of service attack.
[0030] As a preferred technical solution, the analyzing the context code where the security risk information is located, determining the cause of the security risk, and generating the smart contract code optimization information according to the cause of the security risk; specifically includes:
[0031] According to the identified security risk information type, the context code of the security risk information type is analyzed to determine the cause of the security risk;
[0032] Based on the cause of the security risk, a corresponding optimization template is selected from a predefined optimization template library;
[0033] The parameters in the optimization template are adjusted according to the context code where the security risk information type is located, optimization information is generated according to the adjusted optimization template, and the context code where the security risk information type is located is optimized according to the optimization information.
[0034] In a second aspect, the present application provides a smart contract processing system, which is applied to the smart contract processing method described above, including a standardization processing module, a feature information extraction module, a risk information type identification module, an optimization information generation module, and an optimization module;
[0035] The standardization processing module is used to obtain the smart contract code and perform standardization processing on the obtained smart contract code to obtain the standardized smart contract code;
[0036] The feature information extraction module is used to extract feature information from the standardized smart contract code, where the feature information is used to characterize the constituent elements of the standardized smart contract code;
[0037] The risk information type identification module is used to perform security risk analysis on the feature information through a preset model to obtain security risk information;
[0038] The optimization information generation module is used to analyze the context code where the security risk information is located, determine the cause of the security risk, and generate the smart contract code optimization information according to the cause of the security risk;
[0039] The optimization module is used to optimize the smart contract code according to the optimization information.
[0040] In a third aspect, the present application provides an electronic device, the electronic device comprising:
[0041] at least one processor; and a memory communicatively coupled to the at least one processor;
[0042] The memory stores computer program instructions that can be executed by the at least one processor, and the computer program instructions are executed by the at least one processor so that the at least one processor can execute the method for processing a smart contract.
[0043] In a fourth aspect, the present application provides a computer-readable storage medium storing a program, which, when executed by a processor, implements the method for processing a smart contract.
[0044] In summary, compared with the prior art, the effective effects brought about by the technical solution provided by this application include at least:
[0045] The present application proposes a method for processing smart contracts, which standardizes the acquired smart contract code to obtain the standardized smart contract code; extracts feature information from the standardized smart contract code; performs security risk analysis on the feature information through a preset model to obtain security risk information; analyzes the context code where the security risk information is located to determine the cause of the security risk, and generates the smart contract code optimization information according to the cause of the security risk; optimizes the smart contract code according to the optimization information. The present application extracts feature information from the smart contract code to accurately capture the key information in the code, and inputs it into a pre-established model for analysis. The model is a deep learning model, which can more efficiently and accurately identify the security risk information in the smart contract; in addition, after identifying the security risk information in the smart contract, the present application also analyzes the context code where the security risk information is located to determine the cause of the security risk information, and generates targeted optimization suggestions based on the cause, which greatly reduces the burden on developers, can quickly respond to and optimize and repair security issues, thereby reducing the risk of smart contracts being attacked. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0047] Figure 1 A flowchart of a method for processing a smart contract provided for one embodiment of the present application;
[0048] Figure 2 A flow chart of feature information extraction provided for one embodiment of the present application;
[0049] Figure 3 A flow chart for determining security risks of smart contract code provided for one embodiment of the present application;
[0050] Figure 4 A flowchart of generating optimization information provided for one embodiment of the present application;
[0051] Figure 5 A block diagram of a smart contract processing system provided for one embodiment of the present application;
[0052] Figure 6 A structural diagram of an electronic device provided for one embodiment of the present application. DETAILED DESCRIPTION
[0053] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present application.
[0054] Reference to "embodiments" in this application means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments.
[0055] At present, in the field of smart contract security, we mainly rely on traditional security measures, such as code auditing, formal verification and vulnerability scanning, which play an important role in discovering and repairing known security vulnerabilities in smart contracts, and effectively ensure the stability and security of blockchain projects. However, in the face of increasingly complex and changing network environments and emerging new attack methods, these traditional methods have low detection efficiency, are not comprehensive, and lack targeted optimization guidance and automated optimization capabilities.
[0056] In order to solve the problems of low detection efficiency, incompleteness, lack of targeted optimization guidance and automated optimization capabilities in the above-mentioned traditional methods, this application first uses feature extraction technology to extract multi-dimensional feature information closely related to security from the smart contract code, and inputs the extracted feature information into a pre-established model for in-depth analysis. The model is a deep learning model with strong learning and generalization capabilities, and can quickly and accurately identify security risk information in the smart contract code; when security risk information in the smart contract code is identified, a detailed vulnerability report can be generated, and by analyzing the identified security risk information type, an appropriate optimization template can be selected from the predefined optimization template library to optimize the context code where the security risk information type is located, which can quickly respond to and optimize and repair security issues, thereby reducing the risk of smart contracts being attacked.
[0057] Terminology explanation: The smart contract in this application refers to an automated contract or agreement based on blockchain technology, which allows for verifiable, executable and tamper-proof contract terms without a third-party intermediary; it is essentially a piece of program code deployed on the blockchain that defines the rules and terms of the contract and the operations that are automatically executed when specific conditions are met.
[0058] The technical solutions provided by the embodiments of the present application are described in detail below in conjunction with the accompanying drawings.
[0059] See also Figure 1 In one embodiment of the present application, a method for processing a smart contract is provided, comprising the following steps:
[0060] S1. Obtain a smart contract code, and perform standardization on the obtained smart contract code to obtain a standardized smart contract code.
[0061] Furthermore, the standardization process includes:
[0062] (1) Adjust the syntax elements (such as indentation, spaces, line breaks, etc.) in the smart contract code to a unified format to eliminate analysis interference caused by different writing styles;
[0063] (2) Remove comments, irrelevant documents, debugging statements, and other parts of the code that do not affect logical execution to reduce redundant information during the analysis process;
[0064] (3) Rename identifiers such as variables, functions, and contracts and unify naming conventions to improve code readability and analyzability.
[0065] A series of standardization processes are performed on the smart contract code to ensure the consistency and accuracy of subsequent analysis.
[0066] S2. Extract characteristic information from the standardized smart contract code, where the characteristic information is used to characterize constituent elements of the standardized smart contract code.
[0067] In this embodiment, feature information is extracted from the standardized smart contract code by combining the Abstract Syntax Tree (AST) and the Control Flow Graph (CFG) to extract the features of the smart contract code. Figure 2 , the specific steps include:
[0068] S21. Convert the source code of the standardized smart contract code into a token stream using a regular expression or a lexical analyzer;
[0069] Converting the source code of the standardized smart contract code into a token stream means decomposing the source code text into a series of units with specific grammatical meanings (such as keywords, identifiers, literals, operators, etc.), and the steps may include:
[0070] Define the token types that may appear in the smart contract source code, and define regular expressions for different types of tokens that may appear; its token types include:
[0071] (1) Keywords: such as contract, function, return, etc., which can be matched by building a regular expression that includes all keywords; (2) Identifiers: user-defined variable names, function names, etc., usually starting with a letter or underscore, followed by letters, numbers or underscores; (3) Numeric literals: integers and floating-point numbers; (4) String literals: text enclosed in single or double quotes, operators: such as +, -, *, / , =, etc., separators: such as {;}, {,}, etc.
[0072] Traverse the source code text of the smart contract and use the above regular expression pattern to match and extract tokens, specifically:
[0073] Read the entire source code text as a string and use a loop or the search function of the regular expression library to traverse the text; for each token type, use the corresponding regular expression to match; if the match is successful, extract the matched text as a token. Store the extracted tokens in a list, each token can be an object or data structure containing type, value, and position information.
[0074] S22, using a syntax analyzer to convert the token stream into an abstract syntax tree;
[0075] This embodiment can use the ANTLR (Another Tool for Language Recognition) parser, which is a powerful parser; after receiving the token stream of the smart contract code, the parser will gradually parse it according to the grammatical rules, decompose the code into a series of grammatical units (such as expressions, statements, function definitions, etc.), and build a hierarchical relationship between them. This process eventually generates an abstract syntax tree, where the abstract syntax tree is a tree structure that graphically represents the grammatical structure of the program; each node in the tree represents a grammatical unit, and the connection between the nodes reflects the grammatical relationship between them.
[0076] In this embodiment, developers only need to define the grammatical rules of the language using the ANTLR parser, and the ANTLR parser can automatically generate the corresponding parsing code without having to manually write complex parsing logic. This not only improves development efficiency, but also reduces the error rate, making the analysis of smart contract code more accurate and efficient. At the same time, the ANTLR parser also provides a rich API and extension mechanism, allowing developers to customize and optimize the parser as needed to meet specific analysis needs.
[0077] S23. Traverse the abstract syntax tree using a depth-first traversal strategy to extract first feature information of the smart contract code;
[0078] The first characteristic information includes: contract structure, function definition, state variables and event definition.
[0079] Among them, the contract structure can identify the overall structure of the contract from the contract definition and inheritance relationship; in the process of traversing the abstract syntax tree, the node representing the contract definition will be identified first, which is usually a node marked as "contract" or similar keywords, containing the name and other properties of the contract; if the contract has an inheritance relationship, it is necessary to further traverse the abstract syntax tree to find these inheritance relationships and understand how the child contract inherits the properties and methods of the parent contract; therefore, by identifying the contract definition and inheritance relationship, the inheritance hierarchy and overall architecture of the contract can be constructed.
[0080] A function definition refers to the complete declaration of a function in the smart contract source code, including the function name, parameter list, and any modifiers applied to the function; modifiers may include access control modifiers and state modifiers, etc., which define the visibility, behavior, and other properties of the function.
[0081] State variables are variables in smart contracts that are stored on the blockchain and are associated with the state of the contract. When traversing the abstract syntax tree, nodes representing state variable declarations are identified, and the variable names and types are extracted. These state variables are an important part of contract persistence storage and help understand the contract's data model and state management method.
[0082] Event definition is a way for contracts to notify the outside world that something important has happened. When traversing the abstract syntax tree, you will find the node representing the event definition and extract the event name and parameter list (including parameter name and type); event definition is one of the important means for contracts to interact with the outside world. By extracting event information, you can understand how contracts communicate with external systems (such as front-end applications or other contracts in the blockchain network).
[0083] The depth-first traversal strategy of this embodiment is an algorithm for traversing a search tree or graph. In the context of smart contracts, the abstract syntax tree is an abstract representation of the smart contract source code, which contains hierarchical information of all the structures and features of the contract (such as contract definitions, functions, state variables, events, etc.). By traversing the abstract syntax tree in depth first, each node in the abstract syntax tree can be systematically accessed. Starting from the root node (usually the contract definition node), each branch can be traversed along the depth of the tree until a leaf node (such as an expression, a literal, etc.) is reached, and then backtracking to the previous node, and other untraversed branches can be explored. This traversal method ensures that each node in the abstract syntax tree is systematically accessed, and the access order is clear and traceable. Secondly, during the traversal process, the corresponding operation is performed according to the type of the node to extract the required information. For example, when encountering a contract definition node, the name of the contract, inheritance relationship and other information can be extracted; when traversing to the function declaration node, the parameters, return type, modifiers and other properties of the function can be analyzed; for state variables and event nodes, their types, names and related configuration information can also be obtained. The extraction of this information not only helps to understand the business logic of the contract, but also provides important data support for subsequent code review, vulnerability detection, performance optimization and other tasks.
[0084] In addition, the depth-first traversal strategy also has a certain degree of flexibility, allowing pruning or backtracking as needed during the traversal process to adapt to different analysis needs. For example, when a branch is found to be irrelevant to the current analysis target, it can be skipped to save time; or, when a potential problem is found, it can be backtracked to the relevant node for more in-depth analysis and verification.
[0085] Therefore, this embodiment traverses the abstract syntax tree of the smart contract through a depth-first traversal strategy, thereby achieving comprehensive access to and in-depth understanding of the internal structure of the contract, ensuring the integrity and depth of the traversal, and avoiding the risk of missing any important information.
[0086] S24. Construct an intelligent control flow graph based on the abstract syntax tree, and extract second feature information of the smart contract code according to the control flow graph.
[0087] The control flow graph in this embodiment is a directed graph that represents all possible execution paths in the program, and also reveals complex control flow situations such as possible exception handling processes, loop structures, and conditional branches. This graphical representation helps developers deeply understand the execution logic of the contract, and also provides an important foundation for subsequent static analysis, dynamic testing, and vulnerability detection.
[0088] Furthermore, the second characteristic information includes: basic blocks, branch structures, loop structures and function calls.
[0089] Among them, a basic block is a series of statements executed continuously in the control flow graph, and there are no jump points (such as branches, loops, or function calls) between these statements. That is, once entering the basic block, all statements in it will be executed sequentially until the end of the basic block is reached.
[0090] Branching is a key part of control flow, allowing the program to choose different execution paths based on conditions. In a control flow graph, branching is represented by edges that connect different basic blocks that can be jumped to based on the results of the conditional judgment. For example, in an if-else statement, there will be at least two edges: one for the jump when the if condition is true, and another for the jump to the else part (or when the if condition is false). For a switch-case statement, there may be multiple such edges, one for each case.
[0091] Loop structures (such as for and while) allow a program to repeatedly execute a section of code until a certain condition is met.
[0092] In the control flow graph, internal and external function calls need to be extracted; function calls allow the program to execute code in another function, usually represented by an edge starting from the call point and pointing to the entry point of the called function; when the function returns, there will be an edge from the function return point back to the call point.
[0093] In this embodiment, after extracting features from the smart contract code after data standardization, it also includes: analyzing the definition and use of state variables, identifying the data flow of key state variables; converting the data flow of the key state variables, the extracted first feature and the second feature into numerical vectors; which can help understand the logical structure of the contract and the dependencies between state variables. In addition, it also includes converting the abstract syntax tree and the control flow graph into graph structure data, and encoding the numerical vectors into the attributes of the nodes and edges of the graph structure data. Among them, the key state variables refer to the state variables that have a direct impact on the contract state or behavior among many state variables.
[0094] S3. Perform security risk analysis on the feature information using a preset model to obtain security risk information.
[0095] Furthermore, the preset model mainly uses a deep learning model based on a graph neural network (GNN) to analyze the characteristic information of the smart contract and identify security risk information; that is, the preset model includes a multi-layer graph neural network structure.
[0096] Among them, a graph convolutional network (GCN) or a graph attention network (GAT) is used as the basic model. The model includes a multi-layer GNN structure, and each layer contains message passing and aggregation operations.
[0097] Specifically, input the feature information into the preset model for security risk analysis to obtain security risk information. Figure 3 , the steps include:
[0098] Furthermore, the graph data structure is used as the input of the model, including nodes, edges, node attributes, and edge attributes.
[0099] S31, based on the multi-layer graph neural network structure, adopt a multi-round message passing mechanism to transmit and aggregate information between the nodes, and learn the local features and global features of the nodes;
[0100] Specifically, first, different features in the smart contract code (such as contract structure, function definition, state variables and event definition, basic blocks, branch structure, loop structure and function call, etc.) are taken as nodes in the graph structure, and the interaction relationship between the features is taken as the edge; each node and edge is accompanied by an initialized feature vector, which may contain basic attributes such as code structure, semantic information or type information.
[0101] Secondly, according to the pre-designed model architecture, it contains a structure of multiple graph neural network layers. Each layer is responsible for further extracting and transforming the feature information of nodes in the graph structure. These layers can be simple graph convolution layers, graph attention layers, or more complex graph pooling layers, etc., depending on the complexity and requirements of the model design.
[0102] Then, after receiving information from neighboring nodes, each node performs an aggregation operation to combine this information with its own current state, with the goal of synthesizing the information of all neighboring nodes to form a richer node representation. After completing information aggregation, each node updates its feature vector through a nonlinear transformation (such as a neural network layer); this transformation process not only considers the characteristics of the node itself, but also incorporates the information of its neighboring nodes, so that the node representation can reflect its local context and global structure information.
[0103] Finally, the process from message passing to feature updating is repeated in a multi-layer graph neural network (GNN) structure, and each layer further refines and deepens the feature representation of the node. As the number of layers increases, the representation of the node will gradually contain more global and high-level information, providing a solid foundation for subsequent security risk analysis and classification tasks.
[0104] S32. Based on the local features and global features of the nodes, the importance of different nodes and edges is weighted by an attention mechanism to obtain key code structure and security risk information;
[0105] Furthermore, critical code structures refer to code snippets that have a significant impact on the security, functionality, or performance of the contract and are prone to errors or become security vulnerability attack points.
[0106] Specifically, the importance of each node and edge is evaluated using the learned local and global features of the nodes. This step usually involves one or more attention functions, which calculate the corresponding attention weights based on the feature vectors of the nodes and edges. These weights reflect the significance and influence of the node or edge in the overall code structure and security risk analysis. Secondly, during the message transmission process, the aggregation method of information between nodes is dynamically adjusted according to the calculated attention weights. Specifically, for each node, when receiving information from neighboring nodes, the information is weighted and summed according to the attention weights of the neighboring nodes to highlight the information provided by important nodes while relatively downplaying the influence of minor nodes. Finally, the model is further matched with the preset potential security risks. Through matching, the model can predict and identify security risk information that may exist in the smart contract code.
[0107] The weights of the attention mechanism are dynamically adjusted and optimized. As the model gains a deeper understanding of the code structure and security risks, the allocation of attention weights will become more accurate and effective, thereby better highlighting key code structures and security risk information.
[0108] S33, performing graph-level and node-level classification tasks on the key code structure and security risk information, and outputting different types of security risk probabilities using multi-label classification technology;
[0109] Furthermore, since the security risks in smart contracts may be multiple and complex, a node or the entire graph may involve multiple types of risks at the same time; therefore, it is necessary to perform graph-level and node-level classification tasks, and the use of multi-label classification technology can more comprehensively reflect this actual situation.
[0110] The graph-level classification in this embodiment focuses on the overall structure and systemic risks of the entire smart contract, while the node-level classification focuses more on the security of specific code segments or operations.
[0111] Specifically, the key code structure and security risk obtained by weighting each node with the attention mechanism are input into the node-level classifier for identification, and the probability of the security risk category to which the node belongs is obtained; the key code structure and security risk obtained after weighting each node with the attention mechanism are aggregated, and the aggregated results are input into the graph-level classifier to obtain the probability of the security risk information category to which the smart contract code as a whole belongs.
[0112] Multi-label classification is used to handle situations where an instance can belong to multiple categories (or labels) at the same time; unlike traditional single-label classification (each instance can only belong to one category), the output of multi-label classification is a set of labels, each label in the set represents an attribute or category that the instance may have.
[0113] S34: When the security risk probability exceeds a preset security risk probability threshold, it is determined that the security risk information exists.
[0114] Among them, one or more risk probability thresholds will be pre-set according to the specific application scenarios, security requirements and historical data of the smart contract. These thresholds are tested to ensure that they can effectively identify real security risks while avoiding too many false positives and reducing the burden on developers and security teams. The setting of thresholds may need to refer to industry standards or best practices; for each security risk type, if its probability value exceeds the corresponding threshold, it indicates that the risk is highly likely to exist in the smart contract code, and it is determined that the security risk information type exists.
[0115] Furthermore, in this embodiment, after determining that it is a security risk, the severity of the security risk is quantified using a confidence score; specifically, the following is included:
[0116] Select evaluation dimensions: First, you need to determine which dimensions will be used to evaluate the severity of security risks; the dimensions include the ease of exploitation of the vulnerability, the scope of impact, the severity of historical similar vulnerabilities, the vulnerability of the system environment, and the difficulty of optimization;
[0117] Set scoring criteria: Set specific scoring criteria for each evaluation dimension, which are usually quantitative indicators based on past experience and industry standards.
[0118] Single-dimension scoring: Security risks are scored according to the scoring criteria set for each assessment dimension.
[0119] Comprehensive score: The scores of each dimension are weighted and summed (the weights are set according to the importance and priority of the dimensions) to obtain the confidence score of the security risk.
[0120] The confidence score is a multi-dimensional metric that takes into account multiple factors, including but not limited to the ease of exploitation of the vulnerability, the potential impact on system security, the severity of historical similar vulnerabilities, and the extent to which specific configurations or dependencies in the current environment may exacerbate or mitigate risks. A specific confidence score is assigned to each security risk. This score not only helps developers and security teams quickly understand the urgency of the risk, but also provides a strong basis for setting priorities and allocating resources. For example, vulnerabilities with high confidence scores, easy to exploit, and that may cause serious data leakage or financial losses will be handled first. In addition, the confidence scoring mechanism in this embodiment also has the ability to adjust dynamically. With the disclosure of new vulnerabilities, the evolution of attack techniques, or changes in the system environment, the system can re-evaluate the severity of existing risks and adjust the confidence scores accordingly. This flexibility ensures the timeliness and accuracy of risk assessment, enabling security defense strategies to keep up with changes in threat situations. By introducing a confidence scoring mechanism, this embodiment not only improves the refinement and scientific level of smart contract security risk management, but also lays a solid foundation for building a more stable and reliable blockchain application environment.
[0121] Specifically, the security risks in this embodiment include but are not limited to: reentrancy attacks, integer overflow or underflow, unchecked external calls, access control issues, denial of service attacks, timestamp dependency, random number generation issues, uninitialized storage pointers, unprotected self-destruct operations, improperly implemented standards, gas limits and loops, short address attacks, foreground operation, privilege escalation, and logical errors.
[0122] S4. Analyze the context code where the security risk information is located, determine the cause of the security risk, and generate the smart contract code optimization information according to the cause of the security risk.
[0123] S5. Optimize the smart contract code according to the optimization information.
[0124] In addition to providing optimization information, this embodiment can also provide automatic optimization code to optimize the smart contract code. Please refer to Figure 4 , generating smart contract code optimization information, and optimizing the smart contract code include:
[0125] S41. Analyze the context code of the identified security risk information type to determine the cause of the security risk.
[0126] Furthermore, after determining the risk type and its location, start reading and understanding the context code around that location. This includes understanding the code's functions, logical flow, and the data structures involved. By deeply understanding the context code, you can better grasp the background and conditions under which the risk occurs.
[0127] In this embodiment, the context code of the security risk type is analyzed, including analyzing variable scope and function call relationship, etc.; wherein, in the context code analysis, the scope of the variable is analyzed, including analyzing how it is defined, assigned and used, and paying attention to checking whether the variable may be accessed or modified at an inappropriate time or in an inappropriate context, thereby causing security risks; the function call in the smart contract is one of the core mechanisms of code execution. Therefore, when analyzing security risks, it is necessary to track the function call relationship related to the risk, which includes identifying the starting point and end point of the call chain, understanding the role and contribution of each function in the call chain, and analyzing the data and status passed between functions, etc.; by tracking the function call relationship, the propagation path and impact range of the risk in the code can be revealed; through the above analysis, the cause of the security risk is obtained, and according to the cause of the security risk, the specific measures required to optimize the security risk can be evaluated.
[0128] S42: Based on the cause of the security risk, select a corresponding optimization template from a predefined optimization template library.
[0129] Furthermore, an optimization template that matches the evaluated optimization requirement is searched in a predefined optimization template library.
[0130] S43: adjusting parameters in the optimization template according to the context code where the security risk information type is located, generating optimization information according to the adjusted optimization template, and optimizing the context code where the security risk information type is located according to the optimization information.
[0131] Furthermore, the code can be automatically optimized according to the adjusted optimization template.
[0132] Specifically, first, you need to have an in-depth understanding of the structure and intended functions of the selected optimization template; optimization templates usually contain a series of predefined code snippets or logical structures designed to address specific types of security risks. By carefully reading the template documentation or source code, you can clarify the functions of each part of the template and the adjustable parameters.
[0133] Next, compare the context code where the security risk type is located with the expected code environment in the optimization template, and pay attention to identifying the differences between the two, including differences in variable naming, data types, function calling methods, control flow, etc. These differences will directly affect the adjustment of parameters in the optimization template.
[0134] Based on the specific differences in the context code, the parameters in the optimization template are adjusted one by one. This includes modifying the variable name to match the naming convention in the context code, adjusting the data type to ensure compatibility, changing the function call parameters to reflect the actual parameter list, or modifying the control flow to adapt to specific business logic, etc. When adjusting the parameters, keep the code clear and readable to avoid introducing new errors or security risks.
[0135] After adjusting the parameters, perform preliminary verification on the optimization template to ensure that it can run correctly in the context code and achieve the expected optimization effect. This can be achieved by simulating relevant scenarios in the local development environment, running unit tests or code reviews, etc. If it is found that the template is not applicable or has problems, it is necessary to reselect or adjust the optimization template.
[0136] After verification, specific optimization information or automatic optimization code is generated based on the adjusted optimization template. The optimization information can be a modification guide provided in text form for developers to manually implement optimization; while the automatic optimization code is a directly generated executable code snippet that can be directly inserted into the context code to optimize security risks. When generating optimization information or automatic optimization code, provide clear instructions and comments so that developers can understand and implement the optimization; finally, ensure that the optimization solution can accurately and effectively solve the current security vulnerability problem.
[0137] In order to ensure that the optimization operation not only solves known security issues, but also has no adverse effects on other functions of the smart contract, it is particularly important to implement a series of strict consistency and automated testing verification steps. Therefore, after optimizing the context code where the security risk type is located, this embodiment also includes a consistency check on the optimized smart contract code and the original smart contract code, including: by comparing and analyzing the behavioral output of the contract before and after optimization, verifying whether the two produce the same results under the same input conditions; whether the relevant development documents and user manuals are updated synchronously to reflect the latest code logic and functional changes. This helps maintainers and other developers understand the code and reduce misunderstandings or errors caused by information asymmetry. Finally, after a consistency check, it is ensured that the generated optimized code is functionally consistent with the original smart contract code.
[0138] In addition, in order to ensure the effectiveness of optimization and prevent the introduction of new errors or vulnerabilities, the optimized code is also automatically tested, so that potential problems can be discovered and optimized in a timely manner, ensuring the effectiveness and reliability of the optimization work.
[0139] In this embodiment, a vulnerability report is generated based on the security risk information in the smart contract code. The content of the vulnerability report includes the following nine parts:
[0140] 1. Summary: At the beginning of the vulnerability report, write a concise and clear summary that outlines the overall security assessment results and key findings; this part of the summary can quickly give you a preliminary understanding of the core content of the entire report.
[0141] 2. Vulnerability list: Based on the identified vulnerabilities, the discovered vulnerabilities are sorted by severity.
[0142] 3. Detailed description: For each identified vulnerability, write a detailed description, including: vulnerability type and severity, affected code location (file name, line number), potential attack scenarios, and technical cause analysis.
[0143] 4. Optimization information: For each vulnerability, specific optimization information and optimization solutions are provided. These optimization information are based on a predefined optimization template library and are adjusted based on the actual situation of the context code where the vulnerability is located.
[0144] 5. Code snippets: Show comparison snippets of problematic code and optimized code so that the development team can directly refer to and implement optimizations.
[0145] 6. Best Practices: General recommendations for improving code quality and security.
[0146] 7. Risk assessment: the potential impact and difficulty of exploitation of each vulnerability.
[0147] 8. References: relevant safety standards, documents or research papers.
[0148] 9. Appendix: Tools used, methodology, and complete code audit scope.
[0149] The smart contracts mentioned in this application can be applied to financial services (including decentralized finance (DeFi), lending, insurance, asset trading, etc.) and supply chain management to ensure that every step from production to consumption of goods can be traced to prevent counterfeiting and shoddy products; they can be applied to copyright protection, manage copyrights through smart contracts, and automatically execute royalty distribution; they can also be applied to voting systems or games (creating virtual assets, in-game economic systems and trading mechanisms). For example, in a newly developed blockchain game, the developer designed a smart contract for processing in-game currency transactions. The developer hopes to confirm that there are no security vulnerabilities to ensure the security of player transactions, so a smart contract processing method in this application can be adopted. (1) First, obtain the smart contract code for in-game currency transactions, standardize the smart contract code, and extract feature information from the smart contract code after data standardization. In the smart contract code in the game, the feature information includes functions for processing virtual item transactions, player identity authentication logic, etc.; (2) Input the feature information into a pre-established model for security risk analysis to obtain security risk information. In the game industry, security risk information includes checking whether there are vulnerabilities that may cause NFTs to be transferred or copied incorrectly, or whether game coins are invalid. (3) Analyze the security risk information, determine the cause of the security risk, and generate smart contract code optimization information based on the cause of the security risk. After obtaining the security risk information, it also includes generating a detailed report that lists all potential vulnerabilities detected and provides specific optimization information for each problem. For game developers, this can directly guide how to modify the smart contract code to prevent players from exploiting these vulnerabilities to cheat. Finally, the developer modifies the smart contract code based on the provided optimization information or the automatic optimization code, and re-enters it for testing. After confirming that there are no security vulnerabilities, the optimized smart contract is deployed on the blockchain to ensure that all transactions in the game are safe.
[0150] In summary, the present application provides a method for processing smart contracts, which extracts richer features from the smart contract code after data standardization processing, and based on the extracted features, uses a deep learning-based model to conduct a more comprehensive security analysis of the smart contract code, thereby quickly identifying security risk information and discovering more unknown security issues; compared with traditional manual code audits and vulnerability scanning, the detection efficiency and response speed are significantly improved; in addition, the present application can not only identify security risk information in the smart contract code, but also generate detailed reports and provide specific optimization information or automatically optimize the code, which enables developers to understand the problem more accurately and take effective measures to optimize, thereby improving the pertinence and effectiveness of the optimization and ensuring the stability and security of the blockchain project.
[0151] It should be noted that, for the sake of convenience of description, the aforementioned method embodiments are all expressed as a series of action combinations, but those skilled in the art should know that the present application is not limited to the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously.
[0152] Based on the same idea as the processing method of a smart contract in the above embodiment, the present application also provides a processing system for a smart contract, which can be used to execute the processing method of a smart contract. For ease of explanation, the structural diagram of an embodiment of a processing system for a smart contract only shows the parts related to the embodiment of the present application. Those skilled in the art can understand that the illustrated structure does not constitute a limitation on the system, and may include more or fewer components than the illustrated one, or combine certain components, or arrange the components differently.
[0153] See also Figure 5 In another embodiment of the present application, a smart contract processing system is provided, the system comprising a standardization processing module 101, a feature information extraction module 102, a risk information type identification module 103, an optimization information generation module 104, and an optimization module 105;
[0154] The standardization processing module 101 is used to obtain the smart contract code and perform standardization processing on the obtained smart contract code to obtain the standardized smart contract code;
[0155] The feature information extraction module 102 is used to extract feature information from the standardized smart contract code, where the feature information is used to characterize the constituent elements of the standardized smart contract code;
[0156] The risk information type identification module 103 is used to perform security risk analysis on the feature information through a preset model to obtain security risk information;
[0157] The optimization information generation module 104 is used to analyze the context code where the security risk information is located, determine the cause of the security risk, and generate the smart contract code optimization information according to the cause of the security risk;
[0158] The optimization module 105 is used to optimize the smart contract code according to the optimization information.
[0159] The feature information extraction module 102 is specifically used for:
[0160] Convert the source code of the standardized smart contract code into a token stream using a regular expression or a lexical analyzer;
[0161] Converting the token stream into an abstract syntax tree using a syntax analyzer;
[0162] Traversing the abstract syntax tree using a depth-first traversal strategy to extract first feature information of the smart contract code;
[0163] An intelligent control flow graph is constructed based on the abstract syntax tree, and second characteristic information of the intelligent contract code is extracted according to the control flow graph.
[0164] The first characteristic information includes: contract structure, function definition, state variables and event definition;
[0165] The second characteristic information includes: basic blocks, branch structures, loop structures and function calls.
[0166] After extracting feature information from the standardized smart contract code, it also includes:
[0167] Analyze the definition and use of the state variables and identify the data flow of key state variables;
[0168] converting the data flow of the key state variable, the extracted first feature information and the second feature information into a numerical vector;
[0169] The abstract syntax tree and the control flow graph are converted into graph structure data, and the numerical vector is encoded as attributes of the nodes and edges of the graph structure data.
[0170] The risk information type identification module 103 is specifically used for:
[0171] The preset model includes a multi-layer graph neural network structure;
[0172] The security risk analysis of the feature information by using a preset model to obtain security risk information specifically includes:
[0173] Based on the multi-layer graph neural network structure, a multi-round message passing mechanism is adopted to transmit and aggregate information between the nodes to learn the local features and global features of the nodes;
[0174] Based on the local features and global features of the nodes, the importance of different nodes and edges is weighted through an attention mechanism to obtain key code structure and security risk information;
[0175] For the key code structure and security risk information, perform graph-level and node-level classification tasks, and use multi-label classification technology to output different types of security risk probabilities;
[0176] When the security risk probability exceeds a preset security risk probability threshold, it is determined that the security risk information exists.
[0177] The security risk information includes, but is not limited to: reentrancy attacks, integer overflow or underflow, unchecked external calls, access control issues or denial of service attacks.
[0178] The generating optimization information module 104 is specifically used for:
[0179] According to the identified security risk information type, the context code of the security risk information type is analyzed to determine the cause of the security risk;
[0180] Based on the cause of the security risk, a corresponding optimization template is selected from a predefined optimization template library;
[0181] The parameters in the optimization template are adjusted according to the context code where the security risk information type is located, optimization information is generated according to the adjusted optimization template, and the context code where the security risk information type is located is optimized according to the optimization information.
[0182] It should be noted that a smart contract processing system of the present application corresponds one-to-one to a smart contract processing method of the present application. The technical features and beneficial effects described in the embodiment of the above-mentioned smart contract processing method are applicable to the embodiment of a smart contract processing system. For specific contents, please refer to the description in the embodiment of the method of the present application. It will not be repeated here. This is hereby declared.
[0183] In addition, in the implementation of a smart contract processing system in the above embodiment, the logical division of each program module is only an example. In actual applications, the above functions can be assigned to different program modules as needed, for example, for the convenience of corresponding hardware configuration requirements or software implementation. That is, the internal structure of the smart contract processing system is divided into different program modules to complete all or part of the functions described above.
[0184] See also Figure 6 In another embodiment, an electronic device for implementing a method for processing a smart contract is provided, comprising a processor, a memory, and a bus, and may also include a computer program stored in the memory and executable on the processor.
[0185] Exemplarily, in this embodiment, the computer program may be divided into one or more modules, which are stored in the memory and executed by the processor to complete the present application. The one or more module elements may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program in the device.
[0186] The electronic device may be a computing device such as a desktop computer, a notebook, a palm computer, a cloud server, etc. The device may include, but is not limited to, a processor and a memory.
[0187] In some embodiments, the processor may be composed of an integrated circuit, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center (Control Unit) of the device, and uses various interfaces and lines to connect the various components of the entire device; by running or executing the program or module stored in the memory, and calling the data stored in the memory, the various functions of the electronic device and the processing data are executed.
[0188] The memory can be used to store the computer program and / or module, and the processor realizes various functions of the device by running or executing the computer program and / or module stored in the memory, and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, at least one application required for a function, etc.; in addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0189] Among them, the memory may be an internal storage unit of an electronic device in some embodiments, such as a mobile hard disk of the electronic device. The memory may also be an external storage device of an electronic device in other embodiments, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device. Furthermore, the memory may also include both an internal storage unit of the electronic device and an external storage device. The memory can be used not only to store application software and various types of data installed in the electronic device, such as the code of the processing program of the smart contract, but also to temporarily store data that has been output or is to be output.
[0190] Figure 6 Only an electronic device with components is shown, and those skilled in the art will understand that Figure 6 The structure shown does not constitute a limitation on the electronic device, and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.
[0191] A smart contract processing program stored in the memory of the electronic device is a combination of multiple instructions, which, when executed in the processor, can achieve:
[0192] Obtaining a smart contract code, and performing standardization processing on the obtained smart contract code to obtain a standardized smart contract code;
[0193] Extracting feature information from the standardized smart contract code, where the feature information is used to characterize constituent elements of the standardized smart contract code;
[0194] Performing security risk analysis on the feature information through a preset model to obtain security risk information;
[0195] Analyze the context code where the security risk information is located, determine the cause of the security risk, and generate the smart contract code optimization information according to the cause of the security risk;
[0196] Optimize the smart contract code according to the optimization information.
[0197] Accordingly, the present application also provides a computer-readable storage medium, which includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute a smart contract processing method as described in any one of the above embodiments.
[0198] The computer program includes computer program code, which may be in source code form, object code form, executable file or some intermediate form, etc. The computer readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), flash memory, mobile hard disk, multimedia card, card-type memory (e.g., SD or DX memory, etc.), magnetic memory, magnetic disk, optical disk, etc.
[0199] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a non-volatile computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0200] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0201] The above embodiments are preferred implementation modes of the present application, but the implementation modes of the present application are not limited to the above embodiments. Any other changes, modifications, substitutions, combinations, and simplifications that do not deviate from the spirit and principles of the present application should be equivalent replacement methods and are included in the protection scope of the present application.
Claims
1. A method for processing a smart contract, characterized in that: The steps include: Obtaining a smart contract code, and performing standardization processing on the obtained smart contract code to obtain a standardized smart contract code; Extracting feature information from the standardized smart contract code, where the feature information is used to characterize constituent elements of the standardized smart contract code; Performing security risk analysis on the feature information through a preset model to obtain security risk information; Analyze the context code where the security risk information is located, determine the cause of the security risk, and generate the smart contract code optimization information according to the cause of the security risk; Optimize the smart contract code according to the optimization information.
2. A method for processing a smart contract according to claim 1, characterized in that: The extracting characteristic information from the standardized smart contract code specifically includes: Convert the source code of the standardized smart contract code into a token stream using a regular expression or a lexical analyzer; Converting the token stream into an abstract syntax tree using a syntax analyzer; Traversing the abstract syntax tree using a depth-first traversal strategy to extract first feature information of the smart contract code; An intelligent control flow graph is constructed based on the abstract syntax tree, and second characteristic information of the intelligent contract code is extracted according to the control flow graph.
3. A method for processing a smart contract according to claim 2, characterized in that: The first characteristic information includes: contract structure, function definition, state variables and event definition; The second characteristic information includes: basic blocks, branch structures, loop structures and function calls.
4. A method for processing a smart contract according to claim 3, characterized in that: After extracting feature information from the standardized smart contract code, the method further includes: Analyze the definition and use of the state variables and identify the data flow of key state variables; converting the data flow of the key state variable, the extracted first feature information and the second feature information into a numerical vector; The abstract syntax tree and the control flow graph are converted into graph structure data, and the numerical vector is encoded as attributes of the nodes and edges of the graph structure data.
5. A method for processing a smart contract according to claim 4, characterized in that: The preset model includes a multi-layer graph neural network structure; The security risk analysis of the feature information by using a preset model to obtain security risk information specifically includes: Based on the multi-layer graph neural network structure, a multi-round message passing mechanism is adopted to transmit and aggregate information between the nodes to learn the local features and global features of the nodes; Based on the local features and global features of the nodes, the importance of different nodes and edges is weighted through an attention mechanism to obtain key code structure and security risk information; For the key code structure and security risk information, perform graph-level and node-level classification tasks, and use multi-label classification technology to output different types of security risk probabilities; When the security risk probability exceeds a preset security risk probability threshold, it is determined that the security risk information exists.
6. A method for processing a smart contract according to claim 5, characterized in that: The security risk information includes, but is not limited to: reentrancy attacks, integer overflow or underflow, unchecked external calls, access control issues or denial of service attacks.
7. A method for processing a smart contract according to claim 1, characterized in that: The analyzing the context code where the security risk information is located to determine the cause of the security risk, and generating the smart contract code optimization information according to the cause of the security risk; Specifically include: According to the identified security risk information type, the context code of the security risk information type is analyzed to determine the cause of the security risk; Based on the cause of the security risk, a corresponding optimization template is selected from a predefined optimization template library; The parameters in the optimization template are adjusted according to the context code where the security risk information type is located, optimization information is generated according to the adjusted optimization template, and the context code where the security risk information type is located is optimized according to the optimization information.
8. A smart contract processing system, characterized in that: It includes a standardization processing module, a feature information extraction module, a risk information type identification module, an optimization information generation module, and an optimization module; The standardization processing module is used to obtain the smart contract code and perform standardization processing on the obtained smart contract code to obtain the standardized smart contract code; The feature information extraction module is used to extract feature information from the standardized smart contract code, where the feature information is used to characterize the constituent elements of the standardized smart contract code; The risk information type identification module is used to perform security risk analysis on the feature information through a preset model to obtain security risk information; The optimization information generation module is used to analyze the context code where the security risk information is located, determine the cause of the security risk, and generate the smart contract code optimization information according to the cause of the security risk; The optimization module is used to optimize the smart contract code according to the optimization information.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively coupled to the at least one processor; In which, the memory stores computer program instructions that can be executed by the at least one processor, and the computer program instructions are executed by the at least one processor so that the at least one processor can execute a smart contract processing method as described in any one of claims 1-7.
10. A computer-readable storage medium storing a program, characterized in that: When the program is executed by the processor, a method for processing a smart contract as described in any one of claims 1 to 7 is implemented.