Intelligent contract annotation generation method and system based on byte code, medium and equipment

By extracting structural information from the bytecode of a smart contract and combining it with a deep learning model to generate annotations, it solves the limitations of relying on source code in the existing technology, realizes the ability to generate smart contract annotations on the Ethereum blockchain, and improves User understanding and security.

CN118567656APending Publication Date: 2024-08-30SHANGHAI INST FOR ADVANCED STUDY OF ZHEJIANG UNIV
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410254867.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-03-06
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

Existing smart contract annotation generation methods rely on the availability of Solidity source code and are unable to handle most smart contracts with missing source code on the Ethereum blockchain, resulting in the inability to effectively generate smart contract annotations and bring understanding and understanding to novice users. Security risks.

Method used

Extract structural information and generate annotations from the bytecode of smart contracts, using a control flow graph generator and a similar annotation retriever combined with a deep learning model, and through an annotation generation model (SmartBT) that integrates attention mechanism, copy mechanism and coverage mechanism. Generate code comments for smart contracts directly from bytecode.

Benefits of technology

It realizes the generation of smart contract annotations without source code, improves users' ability to understand smart contracts, reduces the risk of false advertising and ICO scams, and shows its superiority in automatic and manual evaluation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118567656A
    Figure CN118567656A
Patent Text Reader

Abstract

The invention discloses an intelligent contract annotation generation method and system based on byte codes, a medium and equipment. Comprising the steps of obtaining an intelligent contract byte code of a to-be-generated annotation, and inputting the intelligent contract byte code into a control flow graph generator to obtain a code control flow graph of the intelligent contract byte code; inputting the code control flow diagram of the intelligent contract byte code into a similar annotation retriever to obtain a similar annotation corresponding to the intelligent contract byte code; and inputting the similar annotation and the code control flow diagram corresponding to the intelligent contract bytecode into a bytecode encoder which is trained and comprises a bytecode encoder, an annotation decoder, a fusion attention mechanism module, a fusion copy mechanism module and a fusion coverage mechanism module, and outputting a code annotation prediction result of the intelligent contract bytecode. And completing the generation of the intelligent contract annotation based on the byte code. Compared with the prior art, the method provided by the invention shows superiority in both automatic evaluation and manual evaluation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the fields of smart contracts, blockchain, and deep learning, and in particular, to a bytecode-based smart contract annotation generation method, system, medium, and device. Background Art

[0002] Created by Nick Szabo, a smart contract is a program (primarily written in Solidity) that can be triggered and executed on the Ethereum blockchain. It allows developers to write self-executing smart contracts that can be deployed on Ethereum, enabling the development of decentralized applications. The Ethereum blockchain has achieved significant growth driven by blockchain technology, with an average of more than 4,200 smart contracts deployed on Ethereum per month and an average of more than 82 million active Ethereum addresses per month. As a result, Ethereum has become one of the largest cryptocurrency platforms (with a total market capitalization of more than $228.38 billion), and smart contracts are increasingly used to automate financial and commercial transactions.

[0003] Despite the great success of smart contracts, obvious problems have also emerged, especially for novice users who are not familiar with smart contracts. Among them, false advertising is the most prominent key problem faced by smart contract end users. For example, smart contract end users may encounter ICO (initial coin offering) scams when investing. These scammers make false claims about the innovative technology and / or business logic of the project to attract investors with the promise of a substantial return on investment. However, the smart contracts they deploy lack such actual utility and value. The mismatch between the smart contract code implementation and what is described in the white paper, website, and announcement has caused serious financial losses to investors. Previous studies have pointed out that the 10 most high-profile ICO scams defrauded $687.4 million from unsuspecting investors. In order to help end users discover inconsistencies between smart contract source code and its documentation, researchers have explored methods to automatically convert Solidity source code into natural language descriptions. For example, Hu et al. proposed the SmartDoc method, a deep learning-based model that can be used to generate smart contract user notifications. In this way, end users without programming knowledge can understand and learn the logic of the original smart contract. Shi et al. proposed a reinforcement learning model called SolcTrans to generate comments for Solidity source code through AST traversal and probabilistic context-free grammar. However, previous studies have focused on generating high-level summaries from source code, but it is not guaranteed that the Solidity source code of each smart contract can be obtained on Ethereum. Usually, when developers deploy smart contracts on the Ethereum blockchain, they first compile the contract source code into bytecode and then deploy the bytecode to the blockchain. Developers can selectively upload their source code for verification, but this is not necessary. According to statistics obtained by Zellic, they collected more than 30 million smart contracts deployed on the Ethereum blockchain, of which only 13% of the smart contracts were able to obtain the relevant source code. In other words, the existing smart contract comment generation methods rely on the availability of Solidity source code and cannot handle most smart contracts on the Ethereum blockchain whose source code is missing. Therefore, the practical use of these tools is severely limited. Summary of the invention

[0004] Although the source code of smart contracts may not be publicly accessible, the bytecode of each smart contract deployed on the blockchain is available. This paper studies for the first time the possibility of generating smart contract code summaries directly from smart contract bytecodes and overcomes the limitations of existing methods that rely on smart contract source code. Generating annotations from bytecodes is a difficult task, as shown by:

[0005] (1) How to obtain structural information from bytecode. Solidity bytecode is generated by compiling Solidity source code into an instruction set that can be read and executed by the Ethereum Virtual Machine (EVM). Unlike human-readable source code, bytecode is a series of hexadecimal codes that are difficult to understand for people who lack professional knowledge. Therefore, how to extract the structure and behavior information of a smart contract from the bytecode of a smart contract, and how to learn the encoding logic and functional patterns in the Solidity bytecode are technical challenges that the present invention intends to solve.

[0006] (2) How to overcome the semantic gap between bytecode and natural language annotations. The semantic gap refers to the gap between low-level EVM bytecode and human-written code annotations. Compared with Solidity source code, the semantic gap between bytecode and natural language annotations is larger. How to effectively overcome this gap and convert bytecode into meaningful natural language code annotations is another technical challenge that the present invention intends to solve.

[0007] The purpose of the present invention is to solve the above-mentioned problems existing in the prior art and to provide a bytecode-based smart contract annotation generation method, system, medium and device.

[0008] The specific technical solutions adopted by the present invention are as follows:

[0009] First, the present invention provides a method for generating smart contract annotations based on bytecode, comprising the following steps:

[0010] S1. Obtain the smart contract bytecode to be annotated, input the smart contract bytecode into the control flow graph generator, and obtain the code control flow graph of the smart contract bytecode;

[0011] S2. Input the code control flow graph of the smart contract bytecode into the similar annotation retriever to obtain similar annotations corresponding to the smart contract bytecode;

[0012] S3. Obtain a trained annotation generation model, which includes a bytecode encoder, an annotation decoder, a fusion attention mechanism module, a fusion copy mechanism module and a fusion coverage mechanism module, input similar annotations and code control flow graphs corresponding to the smart contract bytecode into the bytecode encoder, and obtain fusion features including similar annotation features and code control flow graph features, input the fusion features into the fusion attention mechanism module, and obtain enhanced shallow fusion features, input the enhanced shallow fusion features into the fusion copy mechanism module, and obtain enhanced deeper fusion features, input the enhanced deeper fusion features into the fusion coverage mechanism module, and obtain enhanced deep fusion features; input the enhanced deep fusion features into the annotation decoder, output the code annotation prediction results of the smart contract bytecode, and complete the bytecode-based smart contract annotation generation.

[0013] Preferably, in the similar annotation retriever, a pre-constructed control flow graph database is utilized, and an information retrieval algorithm is utilized to retrieve the control flow graph database. By comparing the similarity between the code control flow graph and each control flow graph data in the control flow graph database, the control flow graph data most similar to the code control flow graph is returned, and the annotation corresponding to the most similar control flow graph data is used as the final similar annotation.

[0014] Preferably, the bytecode encoder adopts a bidirectional recurrent neural network (BRNN).

[0015] Preferably, the annotation decoder is formed by sequentially cascading two layers of long short-term memory networks (LSTM).

[0016] Preferably, the fusion attention mechanism module adopts the Bahdanau attention mechanism.

[0017] Preferably, the fusion copy mechanism module adopts a copy attention mechanism (Copy attention).

[0018] Preferably, the fusion coverage mechanism module adopts a coverage attention mechanism.

[0019] In a second aspect, the present invention provides a bytecode-based smart contract annotation generation system, comprising:

[0020] A code control flow graph acquisition module is used to acquire the smart contract bytecode to be annotated, input the smart contract bytecode into the control flow graph generator, and obtain the code control flow graph of the smart contract bytecode;

[0021] A similar annotation acquisition module is used to input the code control flow graph of the smart contract bytecode into the similar annotation retriever to obtain similar annotations corresponding to the smart contract bytecode;

[0022] A code annotation prediction result acquisition module is used to obtain a trained annotation generation model, wherein the annotation generation model includes a bytecode encoder, an annotation decoder, a fusion attention mechanism module, a fusion copy mechanism module, and a fusion coverage mechanism module. Similar annotations and code control flow graphs corresponding to the smart contract bytecode are input into the bytecode encoder to obtain fusion features including similar annotation features and code control flow graph features. The fusion features are input into the fusion attention mechanism module to obtain enhanced shallow fusion features. The enhanced shallow fusion features are input into the fusion copy mechanism module to obtain enhanced deeper fusion features. The enhanced deeper fusion features are input into the fusion coverage mechanism module to obtain enhanced deep fusion features. The enhanced deep fusion features are input into the annotation decoder to output the code annotation prediction results of the smart contract bytecode, thereby completing the generation of smart contract annotations based on bytecode.

[0023] In a third aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, a bytecode-based smart contract annotation generation method as described in any of the schemes of the first aspect above is implemented.

[0024] In a fourth aspect, the present invention provides a computer electronic device comprising a memory and a processor;

[0025] The memory is used to store computer programs;

[0026] The processor is used to, when executing the computer program, perform a bytecode-based smart contract annotation generation method as described in any of the schemes of the first aspect above.

[0027] Compared with the prior art, the present invention has the following beneficial effects:

[0028] Existing annotation generation methods rely on the availability of source code, while the source code of most deployed smart contracts is missing on the blockchain. In this paper, a new research topic of generating smart contract annotations from the bytecode level is first proposed. Specifically, this paper proposes an annotation generation model SmartBT that integrates the replication attention mechanism and the end-to-end architecture of the coverage attention mechanism, and extracts 30,742 CFG-annotation pairs from a smart contract dataset deployed in the real world. The dataset is processed by decompiling the creation code into a control flow graph, where the nodes on the control flow graph are in the form of instruction sets. A series of experiments are conducted based on this dataset to demonstrate the effectiveness of the annotation generation model SmartBT in generating smart contract annotations based on contract bytecode. The results show that the annotation generation model SmartBT can directly generate smart contract annotations using bytecode, and it shows superiority in both automatic and manual evaluation. In addition, the annotation generation model SmartBT outperforms several baseline methods and reduces the obstacles for users to understand smart contracts.

[0029] The present invention also builds the first dataset for the smart contract bytecode annotation generation task, which includes the smart contract source code and contract creation code. In addition, the present invention has released a replication package, which includes the dataset and source code of SmartBT, to facilitate other researchers and practitioners to reproduce and verify the method work of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Figure 1 is a flow chart of the steps of the present invention;

[0031] Figure 2 A workflow for the annotation generation model SmartBT of the present invention;

[0032] Figure 3 The following are examples of the Solidity source code, compiled bytecode, and control flow chart of the present invention;

[0033] Figure 4 This is an example of model size and BLEU and ROUGE scores in an embodiment of the present invention;

[0034] Figure 5 This is an example of ablation analysis according to an embodiment of the present invention;

[0035] Figure 6 A user study case for an embodiment of the present invention;

[0036] Figure 7 It is a system block diagram of the present invention. DETAILED DESCRIPTION

[0037] In order to make the above-mentioned purpose, features and advantages of the present invention more obvious and easy to understand, the specific implementation mode of the present invention is described in detail below in conjunction with the accompanying drawings. In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention can be implemented in many other ways different from those described herein, and those skilled in the art can make similar improvements without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below. The technical features in each embodiment of the present invention can be combined accordingly without conflicting with each other.

[0038] In an embodiment of the present invention, a method, system, medium and device for generating smart contract annotations based on bytecode are provided, such as Figure 1 As shown, the specific steps are as follows:

[0039] S1. Obtain the smart contract bytecode to be annotated, input the smart contract bytecode into the control flow graph generator, and obtain the code control flow graph of the smart contract bytecode.

[0040] S2. Input the code control flow graph of the smart contract bytecode into the similar annotation retriever to obtain the similar annotations corresponding to the smart contract bytecode.

[0041] It should be noted that the present invention faces two key challenges when directly processing smart contract bytecode. Challenge 1: How to effectively capture the structural information and logical details encoded in the smart contract bytecode. Challenge 2: How to effectively bridge the semantic gap between bytecode and natural language annotations. In order to address these two key challenges, the embodiment of the present invention adopts two components to process smart contract bytecode: a control flow graph generator and a similar annotation retriever. The control flow graph generator is responsible for constructing inputs containing structural information, and the similar annotation retriever is responsible for constructing inputs associated with semantic information. These two types of inputs are then used to train an end-to-end annotation generation model to automatically generate annotations from smart contract bytecode. The specific implementation processes of the control flow graph generator and the similar annotation retriever are described in detail below.

[0042] 1) Control Flow Graph Generator

[0043] Smart Contract Bytecode is interpreted and executed by EVM (Ethereum Virtual Machine), which is a series of hexadecimal numbers. When a transaction needs to be executed, EVM first splits the bytecode into bytes. Each byte represents a unique instruction called an opcode. For example, for the bytecode 0x6070604001, EVM first splits the bytecode into bytes (i.e. 0x60, 0x70, 0x60, 0x40, 0x01). Then EVM executes the first byte 0x60, which references the opcode PUSH1. PUSH1 pushes a byte of data (0x70) to the EVM stack. Then EVM executes the third byte 0x60 and pushes 0x40 to the stack. Finally, EVM executes 0x01, which is the opcode ADD. ADD gets two values ​​from the stack (i.e. 0x70 and 0x40) and performs a sum operation. From this, it can be seen that the smart contract bytecode contains detailed contract execution logic and structure information. In order to capture structural information and detailed logic, an embodiment of the present invention converts the smart contract bytecode into a code control flow graph (CFG). The code control flow graph (CFG) is a graphical representation of the code control flow during the execution of the smart contract. Each node in the code control flow graph (CFG) represents a basic block, which contains a straight-line sequence of opcodes without any jumps or jump targets. Blocks are connected by edges representing jumps to form a control flow graph. The code control flow graph (CFG) can capture all possible execution flows of all code blocks and can reflect the real-time execution of code snippets, which is very valuable for extracting structural information encoded in the smart contract bytecode.

[0044] For a given smart contract bytecode, the embodiment of the present invention first extracts the code control flow graph (CFG) for each function in the smart contract bytecode. Figure 3 As shown, a smart contract may contain multiple functions. After the extraction process, each function is converted into a control flow graph. In an embodiment of the present invention, the tool evm_cfg_builder is used to extract the code control flow graph, which uses value set analysis technology to reliably recover the code control flow graph (CFG) from the EVM bytecode. However, the code control flow graph cannot directly form a sequence model, so the embodiment of the present invention further uses DFS (depth-first search) to traverse the code control flow graph (CFG) to generate a target code control flow graph (CFG) sequence. The symbol -> connection is used when traversing from one node to another. So far, each function in the bytecode has been converted into a code control flow graph representation by the control flow graph generator, and the code control flow graph has been converted into a sequence containing structural information by depth-first traversal, which is ready for downstream model training.

[0045] 2) Similar Annotation Retriever

[0046] Compared with the source code, the semantic gap between the smart contract bytecode and the natural language code description is larger, which brings another key challenge to the conversion of bytecode into code summaries (similar annotations). In order to bridge the semantic gap between bytecode and annotations, the embodiment of the present invention introduces a similar annotation retriever. This component is responsible for retrieving similar annotations from the code base and using them as semantic inputs to the annotation generation model, using these retrieved similar annotations as useful references to improve the translation process. Specifically, the embodiment of the present invention has stored the CFG of all functions and their corresponding annotations as a code base.

[0047] When a new function bytecode is presented, it is first converted into its control flow graph using the CFG generator. Subsequently, an information retrieval algorithm (BM25) is used to retrieve the control flow graph database and search for similar control flow graphs by comparing the similarity between each control flow graph data in the control flow graph database and the control flow graph of the new function code. The most similar control flow graph is returned and its corresponding annotation is extracted as the final similar annotation of the new function bytecode, which is used as the semantic input of the annotation generation model. The similar annotation retriever component acts as a key connection component in the annotation generation model, which provides a way to connect bytecodes and natural language descriptions related to semantics, which can improve the credibility of the final reasoning of the method when generating code summaries. At this point, the similar annotation retriever has prepared the semantic input part for the construction of the annotation generation model.

[0048] S3. Obtain a trained annotation generation model, which includes a bytecode encoder, an annotation decoder, a fusion attention mechanism module, a fusion copy mechanism module and a fusion coverage mechanism module, input similar annotations and code control flow graphs corresponding to the smart contract bytecode into the bytecode encoder, and obtain fusion features including similar annotation features and code control flow graph features, input the fusion features into the fusion attention mechanism module, and obtain enhanced shallow fusion features, input the enhanced shallow fusion features into the fusion copy mechanism module, and obtain enhanced deeper fusion features, input the enhanced deeper fusion features into the fusion coverage mechanism module, and obtain enhanced deep fusion features; input the enhanced deep fusion features into the annotation decoder, output the code annotation prediction results of the smart contract bytecode, and complete the bytecode-based smart contract annotation generation.

[0049] It should be noted that in the present invention, in order to help end users better understand the implementation details of smart contracts deployed on the Ethereum blockchain, the embodiment of the present invention proposes a neural network-based annotation generation model (SmartContract Bytecode Translator, SmartBT), which can automatically convert smart contract bytecodes into human-readable natural language code summaries. The code annotation prediction results (code descriptions) generated by this technical solution can be used as functional code annotations to help users more easily and safely understand the code implementation of smart contracts and participate in the interaction of smart contracts.

[0050] The workflow of the annotation generation model (Smart Contract Bytecode Translator, SmartBT) is as follows Figure 2 As shown: In the process of training the annotation generation model, the embodiment of the present invention collects 30,742 <bytecode, annotation> pairs from 54,739 deployed smart contracts. In order to extract structural information from the bytecode, the present invention uses a control flow graph generator to convert the bytecode of each smart contract into a code control flow graph (CFG) to learn the structural information of the smart contract from the encoded bytecode. In order to fill the semantic gap between bytecode and annotations, the present invention introduces a similar annotation retriever to obtain relevant annotations from contracts with similar CFGs. Finally, the present invention constructs an information retrieval enhanced annotation generation model by integrating structural input (i.e., smart contract code control flow graph) and semantic input (i.e., smart contract related summaries). In addition, the present invention also introduces a copy mechanism (Copy mechanism) for copying rare words from information retrieval results and a coverage mechanism (Coverage mechanism) to eliminate word duplication problems. Both automatic evaluation and manual evaluation results show the advantages and superiority of the annotation generation model SmartBT of the present invention in generating smart contract annotations based on bytecode.

[0051] It should be noted that the main purpose of the present invention is to obtain information directly from the bytecode to improve the understanding of smart contracts. Therefore, a new task is proposed - generating smart contract code annotations from the corresponding bytecodes of the smart contract. Inspired by the great success of using the NMT framework in previous studies, in the training process of the annotation generation model, the present invention formulates the task as an end-to-end sequence-to-sequence learning problem. Assuming that X is a bytecode sequence of a smart contract function, the goal of an embodiment of the present invention is to generate the corresponding annotation Y that describes the smart contract function. Specifically, the goal is to learn the underlying conditional probability distribution P θ (Y|X), that is, using<X,Y> To train an annotation generation model parameter θ, so that the probability P θ(Y|X) is maximized on a given training dataset. The annotation generation model training objective function can be expressed as maximizing the log-likelihood function:

[0052]

[0053] It should be noted that after training the annotation generation model, the present invention uses the bytecode encoder to extract shallow features, uses the fusion attention mechanism module, the fusion copy mechanism module and the fusion coverage mechanism module to gradually enhance the features, and uses the annotation decoder to obtain the code annotation prediction results of the smart contract bytecode. The specific implementation processes of the fusion attention mechanism module, the fusion copy mechanism module and the fusion coverage mechanism module are described below.

[0054] 1) Bytecode Encoder

[0055] After preparing the structural input (i.e., the code control flow graph) and the semantic input (i.e., the similarity annotations), the two inputs are connected and input into the bytecode encoder. In this embodiment, the bytecode encoder uses a bidirectional recurrent neural network (Bi-directional RNN, BRNN), which can improve the ability of the annotation generation model to understand the input sequence from both forward and reverse directions, capture more comprehensive semantic background information, and help the annotation decoder generate more accurate target sequences. The bytecode encoder aims to learn contextual representations from bytecode input sequences (including the generated control flow graph and the retrieved similar annotations). Specifically, the code control flow graph obtained by the control flow graph generator and the similar annotations obtained by the similarity annotation retriever are embedded into a vector X=x1,x2,…,x before being input into the encoder. m The calculation equations of the forward RNN and the reverse RNN are:

[0056]

[0057]

[0058] in, represents the hidden state of the forward RNN at time t; represents the hidden state of the reverse RNN at time t; x t Represents the input sequence at time t.

[0059] The hidden states of the forward RNN and the reverse RNN can be calculated by the order of time steps, or by reverse calculation (starting from the last time step). In the bidirectional recurrent neural network (BRNN), the hidden states of these two directions are concatenated to obtain a complete bidirectional representation. Then, through concatenation, the bidirectional recurrent neural network (BRNN) provides richer bidirectional semantic background information for subsequent decoding.

[0060]

[0061] is the positive hidden state; is the reverse hidden state; h t is the hidden state after splicing; the semicolon (;) indicates the splicing operation.

[0062] 2) Annotation Decoder

[0063] In this embodiment, the annotation decoder uses a two-layer LSTM network, which is a specific recurrent neural network structure that consists of two layers of LSTM stacked together. Each LSTM layer has its own set of LSTM units responsible for capturing and storing information over time. The output of one LSTM layer serves as the input to the next layer, enabling the network to learn hierarchical representations of sequential data. This deeper architecture enables the annotation generation model to capture more complex dependencies and make more complex predictions than a single-layer LSTM. For the decoding process, each word of the smart contract code comment will be embedded into a vector (i.e., Y = y1, y2, …, y m ). Assume that Cword t is the target word of the real annotation data at time t, y t It's Cword t For the first and second layers of LSTM, the calculation process is as follows:

[0064] L1 t =LSTM1(y t ,h t-1 )

[0065] L2 t =LSTM2(y t ,h t-1 )

[0066] Where t is the time step, h t is the hidden state at time t.

[0067] For the second layer LSTM, h t The initial value of is the output hidden state of the first layer LSTM. The annotation decoder generates one word at a time and stops when the END symbol is generated. The only change to the annotation decoder when testing is that it uses the output of the previous word emitted by the decoder instead of Cword t-1 .

[0068] 3) Fusion attention mechanism module

[0069] The fusion attention mechanism module of the embodiment of the present invention adopts Bahdanau Attention as the global attention mechanism, so that the annotation decoder can more flexibly weigh the hidden state of the bytecode encoder, thereby better capturing the relevant information of the input sequence. Global attention requires a matrix and a query vector. It calculates a parameterized convex combination of the matrix based on the input query. Then a unit is constructed to map the query vector q of size dim and the source matrix H of size n×dim to an output of size dim. The calculation formula of its attention score is as follows:

[0070]

[0071] in, W a and U a Both represent model parameters, h j represents the bidirectional concatenated latent vector. Then a projection layer is applied to [q,c] and the attention score a is used j To generate the semantic background vector c, the function form of calculating the output semantic background vector c of the fusion attention mechanism module is as follows:

[0072]

[0073] Among them, H j is the concatenation of the forward and backward hidden states of the bytecode encoder; SeqLength represents the sequence length.

[0074] The embodiment of the present invention further uses the semantic context vector c to obtain the probability distribution of words in the vocabulary, and assumes the probability P(Cword) of a word during decoding. During the training process of each word at each timestamp, the loss associated with generating annotations is as follows:

[0075]

[0076] This attention mechanism allows the model to focus on words with information association in the input sequence. For example, in this embodiment, in the smart contract at address 0xbdb41493614f3a261712bd18adfeac37433fb2c0, the transfer function is used, and it is found that there are 4 CALLs, 9 SLOADs, 2 SSTOREs, 0 BALANCEs, 17 JUMPs, 5 JUMPIs, 90 PUSHs, and 56 DUPs in the transfer function. Therefore, these significant features (e.g., opcode type, approximate number of opcodes, and chronological order of appearance) can be associated with words that may appear in related target annotations (e.g., transfer, wallet, balance, transaction, etc.). In this way, the semantic context vector c highlights the relevant hidden states with high scores and suppresses the irrelevant hidden states with low scores, which enables the model with fusion attention mechanism to produce better results than the model without attention mechanism.

[0077] 4) Fusion replication mechanism module

[0078] Copy attention is commonly used in tasks such as machine translation and text summarization. Its goal is to allow the model to copy or directly extract information from the input sequence and use it to generate the output sequence. Some words are much less frequent than other words, which may make the decoder less likely to generate these words. In this case, it may be necessary to copy words that may be rare in the input sequence from the source code fragment to the target annotation. Therefore, an embodiment of the present invention incorporates a copy mechanism to deal with the rare word problem in the annotation generation process.

[0079] In the embodiment of the present invention, based on the attention distribution Calculate p cg ∈[0,1], which determines whether to generate a word from the vocabulary or copy the word directly from the input sequence:

[0080]

[0081] Among them, W eh , W sh , W x and b cg are all trainable model parameters; p cg represents a soft switch that chooses between generating words from the vocabulary or copying words from the input sequence. The final probability of decoding a word is given by the following functional form:

[0082]

[0083] Where P(Cword) is the final distribution of the union of the vocabulary and the input sequence; represents the attention vector. The word not in the output vocabulary has a probability P(Cword)=0, and in this case, the fusion copy mechanism module of the embodiment of the present invention will <unk>The token is replaced by the attention distribution in the input sequence The copy mechanism allows the annotation generation model to locate a segment of the input sequence and put that segment into the output sequence.

[0084] 5) Fusion coverage mechanism

[0085] Coverage attention is an improved attention mechanism method that aims to enhance the model's attention to information at different positions in the input sequence. Since repetition is a common problem in sequence-to-sequence end-to-end models, and in order to prevent meaningless repetition, the embodiment of the present invention incorporates a coverage attention mechanism into the annotation generation model. First, the embodiment of the present invention obtains a word coverage vector cov, which is the attention distribution a under all previous decoder time steps. t′ sum:

[0086]

[0087] Among them, cov t is the distribution over the input tokens, which represents the coverage these tokens have received from the attention mechanism so far. Since no words were generated before timestamp 0, is a zero vector. The calculation method of the embodiment of the present invention is as follows:

[0088]

[0089] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0090] On the contrary, the present invention covers any substitution, modification, equivalent method and scheme made on the essence and scope of the present invention as defined by the claims. Further, in order to make the public have a better understanding of the present invention, some specific details are described in detail in the detailed description of the present invention below. Those skilled in the art can fully understand the present invention without the description of these details.

[0091] Example

[0092] To illustrate the effectiveness of SmartBT, the present invention adopts two widely used indicators in annotation and code generation tasks:

[0093] BLEU: is a precision-oriented metric that measures the average n-gram accuracy of a set of reference sentences and penalizes sentences that are too short. In addition, the embodiment of the present invention introduces a smoothing function Smooth2 in the BLEU evaluation, which can improve the stability of the BLEU score and more accurately reflect the translation quality. The embodiment of the present invention has fewer reference translations and longer candidate translations, and Smooth2 can improve the calculation results of the BLEU score. In order to evaluate different models, the embodiment of the present invention uses four indicators, BLEU-1, BLEU-2, BLEU-3 and BLEU-4, for scoring.

[0094] ROUGE: is a recall-oriented metric widely used in summary tasks. It judges the quality of the summary generated by the model through the basic units of overlap between the summary generated by the system and the reference sentence. ROUGE-1 and ROUGE-2 measure the overlap of unigrams and bigrams respectively, and ROUGE-1 reflects the intra-sequence matching that reflects the word order at the sentence level. In order to evaluate different models, the embodiment of the present invention considers four indicators, ROUGE-1, ROUGE-2 and ROUGE-L, for scoring.

[0095] In addition, the embodiments of the present invention conducted multiple experiments and studied the following issues:

[0096] Question 1. How effective is the annotation generation method of the embodiment of the present invention?

[0097] Question 2. Can using information retrieval techniques improve performance?

[0098] Question 3. What is the impact of removing the replication and overlay mechanisms in the ablation experiments?

[0099] Question 4. What is the impact of different information retrieval levels on annotation generation?

[0100] Question 5. How effective is the method of the embodiment of the present invention under manual evaluation?

[0101] The specific research status of each problem in the embodiments of the present invention is listed one by one below, so that those skilled in the art can better understand the present invention.

[0102] Question 1. Effectiveness of the annotation generation model SmartBT

[0103] 1. Introduction to the experimental model

[0104] Baseline: Since no previous work has generated contract annotations based on bytecode, the embodiment of the present invention applies several different categories of baselines to compare the annotation generation model SmartBT. First, the embodiment of the present invention uses a similarity matching algorithm to generate annotations. Subsequently, the embodiment of the present invention uses various popular models in NLP, including some methods based on large language models (LLM) and pre-trained models. Finally, the embodiment of the present invention considers the graph structure of the source data, combines transformers and graph neural networks (GNNs), and establishes a model for baseline comparison.

[0105] Similarity matching: In this embodiment of the present invention, the data set is divided into two parts: D train Contains 24594 code-comment pairs, D test Contains 3074 code-annotation pairs. Then based on BM25, the embodiment of the present invention uses the code of each test sample in the test data set to match D train until the embodiment of the present invention finds the most similar code and uses the subscript max-sim to represent the sample. Finally, the embodiment of the present invention uses D train Sample max-sim The comments as D test Sample i The generated result.

[0106] GPT-3: GPT is a popular language model with many versions. It is widely used in the field of machine learning. Since the dataset of the embodiment of the present invention is proposed for the first time and GPT has not been trained on a similar dataset, the embodiment of the present invention needs to fine-tune the GPT model. Fine-tuning is currently only applicable to the following basic models. The embodiment of the present invention uses the Ada and Babbage models for the following reasons. First, within the GPT framework, these models are smaller in scale than Curie and Davinci. Ada has 400 million parameters and Babbage has 1.3 billion parameters, which makes them more suitable for experiments with limited computing resources and faster training speeds.

[0107] CodeT5: CodeT5 is built on an encoder-decoder framework with the same architecture as T5. CodeT5 provides multiple model versions, each optimized for different encoding tasks, and the size of the parameters also varies. The more parameters there are, the better the representation and learning ability of the model, but it also requires more computing resources and time for training and reasoning. Considering that the data set of the embodiment of the present invention is small in size and requires faster training, the embodiment of the present invention selected CodeT5-small and CodeT5-base for experiments.

[0108] Plbart: Plbart is a BART-like model that can be used to perform code summarization, code generation, and code translation tasks. It uses a seq2seq Transformer architecture with a 6-layer encoder and a 6-layer decoder. In addition, it includes an additional layer - a normalization layer - on top of both the encoder and the decoder.

[0109] Model combined with graph neural network: The embodiment of the present invention creates a heterogeneous graph on CFG, which includes instruction set node v I and function node v F .when Include When the embodiment of the present invention is in the function and instruction set An undirected edge is introduced between Node feature , where d is the dimension of the feature. The instruction set nodes are initialized to the instructions they contain, while the function nodes are initialized to a one-hot vector. The GNN model is used to propagate messages across nodes. The output characteristics of the k-th layer GNN can be expressed as Calculated, where ρ is a correction function, such as GraphSAGE, GAT, etc. Only the feature vectors of the output function nodes are used for subsequent decoding tasks.

[0110] 2. Experimental results

[0111] The evaluation results of the annotation generation model SmartBT and the above baselines are summarized in Table 1.

[0112] Table 1: Results of automatic annotation generation evaluation using BLEU and ROUGE (%)

[0113]

[0114] The following analysis results can be obtained from Table 1 above:

[0115] (1) In terms of BLEU, the annotation generation model SmartBT outperforms other methods in terms of overall performance of smart contract annotation generation. When testing BLEU-1, SmartBT scores 37.18%, which is significantly higher than GPT-3Ada's 3.17%, an improvement of nearly 34.01%. This significant improvement can be attributed to the unique characteristics of the dataset, as it is in CFG format and the GPT-3 model has never been trained on it.

[0116] (2) In terms of ROUGE, the annotation generation model SmartBT showed strong performance and obtained higher scores than other methods. This shows that the proposed method effectively captures the similarity of vocabulary and syntax between the generated code comments and the reference comments. In addition, the embodiment of the present invention found that the ROUGE score is always better than the BLEU score, which indicates that there is a higher level of content overlap and semantic consistency between the generated text and the reference text.

[0117] It can be seen that the annotation generation model of the embodiment of the present invention has significant advantages over the baseline, which can be proved by its superiority over the baseline in the automated evaluation. Figure 4 As shown, the annotation generation model SmartBT achieves significant generation effects (far exceeding other models) while being the smallest in size.

[0118] Problem 2. Improvement through Information Retrieval

[0119] 1. Introduction to the experimental model

[0120] The embodiment of the present invention uses multiple information retrieval to enhance the generation effect of the annotation generation model, and does not use information retrieval (ie, IR) none ) model as a baseline for comparison.

[0121] There are many existing similarity matching algorithms. The following will briefly compare and analyze the algorithms used:

[0122] BM25: Taking into account word frequency and document length, BM25 is suitable for long documents and large corpora.

[0123] TF-IDF: Calculates word importance based on term frequency and inverse text frequency index.

[0124] Cosine similarity: measures vector similarity by calculating the cosine of the angle between vectors.

[0125] Jaccard similarity: quantifies the similarity between sets by calculating the ratio of the intersection of the sets to their union.

[0126] Word2Vec: Embedding words into a low-dimensional vector space to capture semantic similarity.

[0127] GraphCodeBert: When using GraphCodeBert to calculate the similarity of CFG, first, convert the CFG into a feature representation vector, and then calculate the cosine similarity, because cosine similarity works better in calculating vector similarity.

[0128] 2. Experimental results

[0129] Table 2: Impact of different information retrieval methods on the task: BLEU and ROUGE score results (%)

[0130]

[0131]

[0132] After evaluation, the analysis results are shown in Table 2, from which we can obtain:

[0133] (1) By comparing TF-ID, Jaccard similarity, and Word2Vec with the baseline, the embodiments of the present invention found that the automatic evaluation scores of these methods were lower than the baseline, that is, the performance of these methods was low. This may be because they rely on statistical methods (such as word bag models and word vectors), which may cause the model to be unable to effectively capture the semantic and contextual information that is critical to generating code comments.

[0134] (2) The present invention finds that the scores of cosine similarity and GraphCodeBert are higher than the baseline values, which indicates that the performance of annotation generation can be improved by using semantic similarity and graph-based representation.

[0135] (3) The annotation generation model using the BM25 algorithm for information retrieval in the embodiment of the present invention achieved the highest scores in all indicators, which highlights the effectiveness of integrating domain-specific retrieval methods to improve the relevance and quality of generated code annotations.

[0136] The results show that the performance of code comment generation can be greatly improved by utilizing appropriate information retrieval techniques, thereby improving the lexical and semantic similarity to reference comments.

[0137] Question 3. Impact of copy and overwrite mechanisms

[0138] 1. Introduction to the experimental model

[0139] After adding a copy mechanism and an overwrite mechanism to the annotation generation model architecture, the annotation generation model in the embodiment of the present invention performs well in annotation generation. In this research problem, the embodiment of the present invention verifies the effectiveness of these two mechanisms through ablation experiments. That is, the embodiment of the present invention compares the annotation generation model SmartBT with different models that delete some mechanisms to verify the effectiveness:

[0140] 1) Model basic : When adding a control flow graph generator, similar annotation retriever and basic attention mechanism to the annotation generation model, the copy mechanism and overwrite mechanism are removed.

[0141] 2) Model basic+copy : When adding a control flow graph generator, similar annotation retriever and basic attention mechanism to the annotation generation model, the coverage mechanism is removed.

[0142] 3) Model basic+coverage : Remove the copy mechanism when adding a control flow graph generator, similar annotation retriever and basic attention mechanism to the annotation generation model.

[0143] 4) Model basic+copy+coverage : When adding a control flow graph generator, a similar annotation retriever, and a basic attention mechanism to the annotation generation model, the copy mechanism and the overwrite mechanism are retained.

[0144] 2. Experimental results

[0145] Table 3: Ablation experiment evaluation of attention mechanism using BLEU and ROUGE scores (%)

[0146]

[0147] The results of the ablation experiment are shown in Table 3. It can be seen from the table that:

[0148] By comparing Model basic+copy and Model basic As a result, the embodiment of the present invention finds that it is of great significance to improve performance through the fusion replication mechanism. basic+copy The BLEU and ROUGE scores are better than Model basic Much higher. Figure 5 As shown, the red words rarely appear in the vocabulary of the model, but they can be copied into the generated annotations. In addition, the embodiment of the present invention can note that these words also appear in the ground truth annotations, which to some extent explains how SmartBT can generate annotations with higher relevance.

[0149] In addition, the present invention also finds that incorporating an overlay mechanism can improve the effectiveness of comment generation. basic+coverage Model basic As can be seen from the comments generated after removing the overwriting mechanism, the model tends to generate repeated words (e.g. Figure 5 This may cause the model to perform poorly when generating annotations.

[0150] Without these mechanisms, each evaluation metric will decline overall. In particular, the model basic+copy+coverage With Model basic When compared, the former's overall evaluation score dropped by nearly 10%, which just verifies the importance and effectiveness of these mechanisms.

[0151] From the above analysis, it can be seen that by combining these mechanisms, the performance of the annotation generation model SmartBT in smart contract annotation generation has been greatly improved.

[0152] Question 4. The impact of different information retrieval levels

[0153] 1. Introduction to the experimental model

[0154] In order to further study the impact of different information retrieval intensities on the task, the present invention uses the BM-25 algorithm to conduct experiments on information input at different levels. k , where k represents the number of information attachments. Based on the findings of RQ3, the embodiment of the present invention uses the k most relevant annotations to increase the input sequence of the annotation generation model to improve its performance.

[0155] 2. Experimental results

[0156] Table 4: Effects of different levels of information retrieval on annotation generation

[0157]

[0158] Based on the experimental results shown in Table 4, the embodiment of the present invention can be analyzed to obtain:

[0159] The annotation generation model SmartBT uses information retrieval technology with k=1, that is, the embodiment of the present invention only adds one annotation that is most similar to the input sequence. Compared with the case of k=0 (no information retrieval), the method of the embodiment of the present invention improves the overall index by nearly 19%. This shows the significant impact of the annotation generation model used in the embodiment of the present invention and the appropriate k value.

[0160] When considering k∈[2,3,5], the embodiment of the present invention finds that the BLEU and ROUGE scores drop a lot. This is because the addition of a highly relevant and accurate approximate information can provide sufficient contextual clues and relevant insights to the annotation generation model, enabling it to generate more accurate and meaningful annotations.

[0161] It can be seen that information retrieval at different levels has an important impact on generating annotations. Incorporating an appropriate amount of additional information, such as k = 1, can effectively improve the performance of the model.

[0162] Problem 5. Human Evaluation

[0163] 1. Introduction to the experimental model

[0164] Since automatic evaluation indicators such as BlEU and ROUGE cannot truly reflect the effect of generated annotations, the embodiment of the present invention conducted a user study for a more realistic evaluation. In this user study, the embodiment of the present invention invited individuals to manually evaluate the generated annotations. The embodiment of the present invention compared SmartBT with BM-25, CodeT5, and Plbart (because these models showed relatively good results in problem one) as baselines. The embodiment of the present invention asked participants to evaluate the generated annotations from two perspectives:

[0165] 1) Naturalness (N) evaluates the grammatical correctness and fluency of the generated annotations. It assesses the extent to which the annotations read and flow in natural language, ensuring that they are easily understood by human readers.

[0166] 2) Relevance (R) evaluates the consistency of annotations with ground truth annotations. It measures the degree of relevance and consistency between the generated annotations and the reference annotations, that is, how well the generated annotations capture the intended meaning and information that appears in the original code.

[0167] Figure 6 is an example of a user study of an embodiment of the present invention. In each case, the embodiment of the present invention presents the ground truth annotation and four candidate annotations generated by the selected method. The participants are then required to compare the candidate annotations with the ground truth annotations and rate their naturalness and relevance on a 5-point scale, with 1 being the worst and 5 being the best. In the embodiment, the annotation generated by SmartBT is option "cadidate-4", and its naturalness and relevance scores both reach 5 points, which means that the annotations generated by SmartBT are of high quality, fluent grammar, and consistent with the real annotations. The embodiment of the present invention recruited 20 experts with rich expertise in computer science, who have a master's or doctoral degree and a certain level of knowledge of blockchain technology. Then the embodiment of the present invention randomly selected 25 data samples from the dataset and divided the 20 participants into 5 groups. Each group was assigned 5 data samples. Therefore, each sample was scored by four participants. The embodiment of the present invention considers 1 and 2 points as low quality, 3 points as medium quality, and 4 and 5 points as high quality. After collecting the answers of all evaluators, the embodiment of the present invention calculated the average score and the proportion of each quality type.

[0168] 2. Experimental results

[0169] Table 5: Manual evaluation results

[0170]

[0171] The average scores of quality distribution, naturalness and relevance of each method are shown in Table 5. From the table, the following conclusions can be drawn from the embodiment of the present invention:

[0172] When the naturalness of the generated annotations is taken into account, the performance of the annotation generation model SmartBT is better than other methods. It is worth noting that the proportion of low-quality annotations is 0% and the proportion of high-quality annotations is 88%. This shows that the method of the embodiment of the present invention is good at generating fluent and grammatically correct annotations.

[0173] In terms of relevance scores, the annotation generation model SmartBT also outperforms other methods, which indicates that the generated annotations have a higher degree of similarity with the real annotations in terms of meaning and sentence structure. For example, SmartBT has an average relevance score of 3.72, the highest among all methods. In addition, the proportion of 64% indicates that the vast majority of generated annotations are of high quality.

[0174] It can be seen that in the user study experiment, the annotation generation model SmartBT has excellent performance in terms of the naturalness and relevance of the generated annotations. The high-quality generated annotations and excellent average scores demonstrate the superiority of SmartBT in generating fluent and grammatically correct annotations.

[0175] It should also be noted that the bytecode-based smart contract annotation generation method in the above embodiment can essentially be executed by a computer program or module. Therefore, similarly, based on the same inventive concept, another preferred embodiment of the present invention also provides a bytecode-based smart contract annotation generation system corresponding to the bytecode-based smart contract annotation generation method provided in the above embodiment, such as Figure 7 As shown, including:

[0176] A code control flow graph acquisition module is used to acquire the smart contract bytecode to be annotated, input the smart contract bytecode into the control flow graph generator, and obtain the code control flow graph of the smart contract bytecode;

[0177] A similar annotation acquisition module is used to input the code control flow graph of the smart contract bytecode into the similar annotation retriever to obtain similar annotations corresponding to the smart contract bytecode;

[0178] A code annotation prediction result acquisition module is used to obtain a trained annotation generation model, wherein the annotation generation model includes a bytecode encoder, an annotation decoder, a fusion attention mechanism module, a fusion copy mechanism module, and a fusion coverage mechanism module. Similar annotations and code control flow graphs corresponding to the smart contract bytecode are input into the bytecode encoder to obtain fusion features including similar annotation features and code control flow graph features. The fusion features are input into the fusion attention mechanism module to obtain enhanced shallow fusion features. The enhanced shallow fusion features are input into the fusion copy mechanism module to obtain enhanced deeper fusion features. The enhanced deeper fusion features are input into the fusion coverage mechanism module to obtain enhanced deep fusion features. The enhanced deep fusion features are input into the annotation decoder to output the code annotation prediction results of the smart contract bytecode, thereby completing the generation of smart contract annotations based on bytecode.

[0179] Similarly, based on the same inventive concept, another preferred embodiment of the present invention also provides a computer electronic device corresponding to the bytecode-based smart contract annotation generation method provided in the above embodiment, which includes a memory and a processor;

[0180] The memory is used to store computer programs;

[0181] The processor is used to implement a bytecode-based smart contract annotation generation method in the above embodiment when executing the computer program.

[0182] In addition, the logic instructions in the above-mentioned memory can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention.

[0183] Therefore, based on the same inventive concept, another preferred embodiment of the present invention also provides a computer-readable storage medium corresponding to the bytecode-based smart contract annotation generation method provided in the above embodiment, and a computer program is stored on the storage medium. When the computer program is executed by the processor, it can implement the bytecode-based smart contract annotation generation method in the above embodiment.

[0184] It is understandable that the above storage medium may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage. The storage medium may also be a U disk, a mobile hard disk, a magnetic disk or an optical disk, etc., which can store program codes.

[0185] It is understandable that the above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0186] It should also be noted that those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the system described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. In the various embodiments provided in this application, the division of steps or modules in the system and method is only a logical function division, and there may be other division methods in actual implementation, such as multiple modules or steps can be combined or integrated together, and a module or step can also be split.

[0187] The above-described embodiment is only a preferred solution of the present invention, but it is not intended to limit the present invention. A person skilled in the relevant technical field may make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, any technical solution obtained by equivalent replacement or equivalent transformation falls within the protection scope of the present invention.< / unk>

Claims

1. A method for generating smart contract annotations based on bytecode, characterized in that: The following steps are involved: S1. Obtain the smart contract bytecode to be annotated, input the smart contract bytecode into the control flow graph generator, and obtain the code control flow graph of the smart contract bytecode; S2. Input the code control flow graph of the smart contract bytecode into the similar annotation retriever to obtain similar annotations corresponding to the smart contract bytecode; S3. Obtain a trained annotation generation model, the annotation generation model includes a bytecode encoder, an annotation decoder, a fusion attention mechanism module, a fusion replication mechanism module and a fusion coverage mechanism module, input similar annotations and code control flow graphs corresponding to the smart contract bytecode into the bytecode encoder, obtain fusion features including similar annotation features and code control flow graph features, input the fusion features into the fusion attention mechanism module, obtain enhanced shallow fusion features, input the enhanced shallow fusion features into the fusion replication mechanism module, obtain enhanced deeper fusion features, input the enhanced deeper fusion features into the fusion coverage mechanism module, obtain enhanced deep fusion features; The enhanced deep fusion features are input into the annotation decoder, and the code annotation prediction results of the smart contract bytecode are output to complete the bytecode-based smart contract annotation generation.

2. A method for generating smart contract annotations based on bytecode as claimed in claim 1, characterized in that: In the similar annotation retriever, a pre-built control flow graph database is used, and an information retrieval algorithm is used to retrieve the control flow graph database. By comparing the similarity between the code control flow graph and each control flow graph data in the control flow graph database, the control flow graph data most similar to the code control flow graph is returned, and the annotation corresponding to the most similar control flow graph data is used as the final similar annotation.

3. A method for generating smart contract annotations based on bytecode as claimed in claim 1, characterized in that: The bytecode encoder adopts a bidirectional recurrent neural network.

4. A method for generating smart contract annotations based on bytecode as claimed in claim 1, characterized in that: The annotation decoder is formed by cascading two layers of long short-term memory networks in sequence.

5. A method for generating smart contract annotations based on bytecode as claimed in claim 1, characterized in that: The fusion attention mechanism module adopts the Bahdanau attention mechanism.

6. A method for generating smart contract annotations based on bytecode as claimed in claim 1, characterized in that: The fusion replication mechanism module adopts a replication attention mechanism.

7. A method for generating smart contract annotations based on bytecode as claimed in claim 1, characterized in that: The fusion coverage mechanism module adopts a coverage attention mechanism.

8. A bytecode-based smart contract annotation generation system, characterized in that: include: A code control flow graph acquisition module is used to acquire the smart contract bytecode to be annotated, input the smart contract bytecode into the control flow graph generator, and obtain the code control flow graph of the smart contract bytecode; A similar annotation acquisition module is used to input the code control flow graph of the smart contract bytecode into the similar annotation retriever to obtain similar annotations corresponding to the smart contract bytecode; A code annotation prediction result acquisition module is used to acquire a trained annotation generation model, wherein the annotation generation model includes a bytecode encoder, an annotation decoder, a fusion attention mechanism module, a fusion replication mechanism module, and a fusion coverage mechanism module. Similar annotations and code control flow graphs corresponding to the smart contract bytecode are input into the bytecode encoder to obtain fusion features including similar annotation features and code control flow graph features. The fusion features are input into the fusion attention mechanism module to obtain enhanced shallow fusion features. The enhanced shallow fusion features are input into the fusion replication mechanism module to obtain enhanced deeper fusion features. The enhanced deeper fusion features are input into the fusion coverage mechanism module to obtain enhanced deep fusion features. The enhanced deep fusion features are input into the annotation decoder, and the code annotation prediction results of the smart contract bytecode are output to complete the bytecode-based smart contract annotation generation.

9. A computer-readable storage medium, characterized in that: A computer program is stored on the storage medium. When the computer program is executed by the processor, a bytecode-based smart contract annotation generation method as described in any one of claims 1 to 7 is implemented.

10. A computer electronic device, characterized in that: including memory and processor; The memory is used to store computer programs; The processor is used to implement a bytecode-based smart contract annotation generation method as described in any one of claims 1 to 7 when executing the computer program.

Citation Information

Cited By

  • Smart contract test method and device, electronic equipment and storage medium

    CN119848851A