Consistency detection method and device for decentralized application, medium and equipment
By performing functional entity and semantic matching analysis on the DApp description text and smart contract bytecode, the consistency problem between the DApp front-end description and the smart contract implementation is solved, ensuring user security and trust, and improving the quality of the DApp.
Patent Information
- Application Number
- CN202410866296.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-09-24
AI Technical Summary
Existing technology cannot effectively detect consistency issues between decentralized application (DApp) front-end descriptions and smart contract implementations, resulting in user losses and security threats during use, affecting user trust.
By obtaining the description text of the DApp and the bytecode of the smart contract, use the extraction model to extract the functional entities in the description text and the functional semantics of the smart contract, perform matching analysis, and determine the consistency between the two.
Identify consistency issues between DApp front-end description and smart contract implementation, prevent user losses, improve user trust in the DApp platform, protect user data security, and improve the quality and effectiveness of DApp.
Smart Images

Figure CN118689487A
Abstract
Description
Technical Field
[0001] This specification relates to the field of computers, and in particular to a consistency detection method, device, medium and equipment for decentralized applications. Background Art
[0002] With the development of computer technology, blockchain technology has been widely used in various scenarios. The rapid development of blockchain technology has also greatly promoted the development of decentralized applications (DApp) based on blockchain technology. DApp usually attracts users by describing the functions of the DApp on the front end, and then executes the corresponding functions based on smart contracts on the back end. In order to protect the personal data security of users using the DApp, the application platform should review the DApp before listing it and opening it for download and use to ensure the security of the DApp.
[0003] In the prior art, the application platform usually constructs a model through machine learning methods to review DApp. After obtaining the code of the smart contract of the DApp to be tested, the code of the smart contract is analyzed and tested through the constructed model, and the security of the DApp is determined based on the results of the analysis and testing.
[0004] However, it is impossible to determine the security of the DApp by only detecting the DApp based on the code of the smart contract to determine whether the smart contract of the DApp contains malicious code or vulnerabilities. For example, when a DApp describes the function on the front end, it guarantees that a certain function can be used without additional cost, but in the back-end smart contract, it is set that only a certain number of times a certain function can be used free of charge, and a fee will be charged according to a certain proportion in the future. This inconsistency between the front-end description and the functions implemented by the smart contract will cause users to suffer losses during the use of the DApp, threaten the safety of users, and also affect users' trust in the application platform of the DApp and the DApp. Therefore, this specification provides a consistency detection method, device, medium and equipment for decentralized applications. Summary of the invention
[0005] This specification provides a security detection method, device, medium and equipment for decentralized applications to partially solve the above-mentioned problems existing in the prior art.
[0006] This manual adopts the following technical solutions:
[0007] A method for detecting consistency of a decentralized application, the method comprising:
[0008] Get the description text of the application to be tested and the bytecode of the smart contract;
[0009] Input the description text into the trained extraction model, extract the text describing the function of the application to be detected from the description text as the first entity of the application to be detected, and construct a first entity set;
[0010] Decompiling the bytecode into a high-level representation code, extracting the functional semantics of the application to be detected according to the high-level representation code as a second entity of the application to be detected, and constructing a second entity set;
[0011] The first entity set is matched with the second entity set. When the match fails, it is determined that the description text of the application to be detected does not match the functional semantics and is not consistent.
[0012] Optionally, the extraction model is trained using the following method, including:
[0013] Acquire description texts of each application as training samples, and annotate texts describing functions in each description text to determine a first annotation;
[0014] Inputting the training sample into the extraction model to be trained, and determining a first output of the extraction model to be trained;
[0015] The extraction model to be trained is adjusted with minimizing the difference between the first output and the first annotation as an optimization goal.
[0016] Optionally, inputting the description text into a trained extraction model specifically includes:
[0017] Inputting the preset prompt words and the description text into the trained extraction model;
[0018] The preset prompt words are determined by the following method, including:
[0019] Obtaining description text of the annotated application annotated as inconsistent and bytecode of the corresponding smart contract, and determining corresponding first entities according to the vertex description text, and determining corresponding second entities according to the bytecode;
[0020] Matching the first entities with the second entities, and determining that the matching result is a first entity and / or a second entity that failed to match;
[0021] Determine the reason for the matching failure according to each pair of the first entity and / or the second entity that failed to match, and classify the reasons for each failure to determine the inconsistency type;
[0022] According to each inconsistency type, a prompt word corresponding to each inconsistency type is generated.
[0023] Optionally, inputting the preset prompt words and the description text into the trained extraction model specifically includes:
[0024] For each inconsistency type, determine each first entity corresponding to the inconsistency type as a second annotation;
[0025] Determine a prompt word corresponding to the inconsistency type, input the prompt word and the training sample into the trained extraction model, and determine a second output of the extraction model;
[0026] Taking the minimum difference between the second output and the second annotation as an optimization goal, adjusting the prompt word to determine a final prompt word of the inconsistency type;
[0027] Each final prompt word and the description text are input into the trained extraction model respectively.
[0028] Optionally, extracting the functional semantics of the application to be detected according to the high-level representation code specifically includes:
[0029] extracting instruction codes from the high-level representation code;
[0030] According to the high-level representation code, extracting state variables in the high-level representation code and determining dependencies between the state variables;
[0031] Constructing a state dependency graph of the smart contract according to the dependency relationship;
[0032] Performing data flow analysis on the high-level representation code and constructing a data transfer graph of the smart contract;
[0033] replacing numerical operations in the high-level representation code with symbolic operations, performing symbolic execution on the high-level representation code, and determining a symbolic execution result of the high-level representation code;
[0034] The functional semantics of the application to be detected are extracted according to at least two of the instruction code, the state dependency graph, the data transfer graph, and the symbolic execution result.
[0035] Optionally, matching the first entity set with the second entity set specifically includes:
[0036] For each inconsistency type, determine each first entity in the first entity set corresponding to the inconsistency type, and determine an entity set to be matched;
[0037] Matching the to-be-matched entity set with the second entity set, and determining whether there are second entities in the second entity set corresponding to the first entities in the to-be-matched entity set;
[0038] If not, it is determined that the application to be detected has inconsistency of this inconsistency type.
[0039] Optionally, matching the first entity set with the second entity set specifically includes:
[0040] Extract key texts from each first entity in the first entity set, determine a key text set, and determine key codes corresponding to each key text in the key text set;
[0041] For each key text in the key text set, searching the second entity set for a key code corresponding to the key text, and when the second entity set does not contain a key code corresponding to the key text in the first entity set, determining that the first entity set fails to match the second entity set;
[0042] Determine whether there is a second entity in the second entity set that has not been matched;
[0043] If so, the first entity set fails to match the second entity set.
[0044] This specification provides a decentralized application consistency detection device, the device comprising:
[0045] The acquisition module is used to obtain the description text of the application to be tested and the bytecode of the smart contract;
[0046] A first extraction module, configured to input the description text into a trained extraction model, extract the text describing the function of the application to be detected from the description text as the first entity of the application to be detected, and construct a first entity set;
[0047] A second extraction module is used to decompile the bytecode into a high-level representation code, extract the functional semantics of the application to be detected according to the high-level representation code as the second entity of the application to be detected, and construct a second entity set;
[0048] The matching module is used to match the first entity set with the second entity set, and when the matching fails, determine that the description text of the application to be detected does not match the functional semantics and is not consistent.
[0049] This specification provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the consistency detection method of the above-mentioned decentralized application.
[0050] This specification provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned consistency detection method for decentralized applications when executing the program.
[0051] At least one of the above technical solutions adopted in this specification can achieve the following beneficial effects:
[0052] In a consistency detection method for decentralized applications provided in this specification, the description text of the application to be detected and the bytecode of the smart contract are obtained, and then the text describing the function of the application to be detected in the description text is extracted as each first entity, and the functional semantics of the application to be detected are determined according to the bytecode of the smart contract of the application to be detected as the second entity of the application to be detected. The determined first entity and second entity are matched, and the consistency of the application to be detected is determined according to the matching result.
[0053] It can be seen from the above method that based on the analysis of the description text of the application to be detected and the bytecode of the smart contract, it is identified whether there is consistency between the description text of the front end of the application to be detected and the functions implemented by the smart contract, thereby determining the consistency of the application to be detected, preventing the inconsistency between the description text of the front end of the application to be detected and the functions implemented by the smart contract from causing risks to users who use the application to be detected, affecting users' trust in decentralized applications and application platforms that provide decentralized applications, protecting user data security, and improving the quality and effectiveness of decentralized applications. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] The drawings described herein are used to provide a further understanding of this specification and constitute a part of this specification. The illustrative embodiments and descriptions of this specification are used to explain this specification and do not constitute an improper limitation on this specification. In the drawings:
[0055] Figure 1 A schematic diagram of the process of a consistency detection method for a decentralized application provided in this specification;
[0056] Figure 2 Schematic diagram of the types of inconsistencies provided for this specification;
[0057] Figure 3 A schematic diagram of a consistency test process for an application to be tested provided in this specification;
[0058] Figure 4 A schematic diagram of a consistency detection device for a decentralized application provided in this specification;
[0059] Figure 5 The corresponding Figure 1 Schematic diagram of electronic equipment. DETAILED DESCRIPTION
[0060] In order to make the purpose, technical solutions and advantages of this specification more clear, the technical solutions of this specification will be clearly and completely described in combination with the specific embodiments of this specification and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0061] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0062] The technical solutions provided by the embodiments of this specification are described in detail below in conjunction with the accompanying drawings.
[0063] like Figure 1 As shown, Figure 1 This is a flowchart of a consistency detection method for a decentralized application provided in this specification, including the following steps:
[0064] S100: Obtain the description text of the application to be detected and the bytecode of the smart contract.
[0065] In one or more embodiments of this specification, it is not limited to which device is used to implement the consistency detection method of the decentralized application, such as a personal computer, a mobile terminal, and a server. However, since the subsequent steps involve operations such as model calling and code analysis, which are generally performed by a server, this specification will also take the server executing the consistency detection method as an example for description. Among them, the server can be a single device, or composed of multiple devices, such as a distributed server, and this specification does not limit this.
[0066] Of course, in one or more embodiments of this specification, the consistency detection method of the decentralized application can be performed by any organization or individual, such as by an application store that provides DApp download and installation, or by a user who needs to use a DApp to perform corresponding business. This specification does not limit this.
[0067] In order to detect the consistency of the application to be detected, the server should first obtain the description text of the front end of the application to be detected and the bytecode of the smart contract that implements the function.
[0068] Specifically, the server may pre-acquire the description text of the functions of the application to be detected that is disclosed by the application to be detected. Since the developer of DApp generally does not disclose the source code of the smart contract of the DApp, and the bytecode of the smart contract is the content that the developer of DApp must disclose, in one or more embodiments of this specification, in order to be applicable to the consistency detection of various DApps, when performing consistency detection on the application to be detected, the functional semantics of the smart contract of the application to be detected is analyzed through the bytecode of the smart contract. Therefore, after obtaining the description text, the server should also obtain the bytecode of the smart contract of the application to be detected.
[0069] At the same time, since the description text of the front end of the DApp and the bytecode of the smart contract are public, in one or more embodiments of this specification, the server is not limited to the specific method by which it obtains the description text of the application to be detected and the bytecode of the smart contract. It can be obtained through the official website of the application to be detected, or through the developer of the application to be detected. When obtaining the bytecode of the smart contract, it can also be directly obtained from the Ethereum virtual machine. Since there are many ways to obtain, this specification will not be repeated here.
[0070] In addition, in one or more embodiments of the present specification, it is not considered that the smart contract of the application to be tested itself may have malicious vulnerabilities, logical errors, etc., that is, the consistency detection method of the decentralized application provided in this specification can be executed after the security of the smart contract of the application to be tested is detected, so as to further ensure the safety of users.
[0071] Of course, when extracting the second entity of the smart contract of the application to be tested, the smart contract can be subjected to security tests such as vulnerability detection and logic detection. When there are security issues, consistency testing will no longer be performed.
[0072] S102: Input the description text into a trained extraction model, extract the text describing the function of the application to be detected from the description text as the first entity of the application to be detected, and construct a first entity set.
[0073] In order to implement consistency detection of the application to be detected, the server should extract the text describing the functions of the application to be detected in the description text, so as to match it with the functional semantics of the smart contract later.
[0074] Specifically, the server may input the acquired description text into an extraction model, identify text describing the function of the application to be detected in the description text through the extraction model as the first entity of the application to be detected, and then construct a first entity set based on the extracted first entities.
[0075] It should be noted that the text describing the application function to be detected in one or more embodiments of the present specification is a paragraph or a sentence of text, which may be the original text extracted from the description text, or may be a text summarized and generated based on the text describing the application function to be detected extracted from the description text.
[0076] In addition, the extraction model is a pre-trained model for text extraction. The description text of each DApp can be obtained as a training set, and then the text describing the corresponding function in each description text is used as the first annotation, and then the training set is input into the extraction model to determine the first output of the extraction model. Then, the difference is determined based on the first output and the first annotation, and the difference between the output and the annotation is minimized as the optimization goal to determine the trained extraction model.
[0077] It should be noted that in one or more embodiments of the present specification, the extraction model used is a large language model. In addition, when determining the difference based on the first output and the first annotation, each first entity included in the first output can be regarded as a text, and each first entity in the first annotation can also be regarded as a text, and then the similarity of the two texts is calculated, and the difference is determined based on the determined text similarity.
[0078] Of course, the order of the annotated entities can also be determined according to the order of the context of the annotated entities in the first annotation in the description text. Then the extraction model is made to output the first entities according to the context order of the description text, and the order of the first entities is determined. Then, according to the determined order of the annotated entities and the order of the first entities, the annotated entities are matched with the first entities to determine the corresponding relationship between the annotated entities and the first entities. Then, the similarity is calculated for each pair of annotated entities and the first entities, and the difference is determined according to the determined similarities.
[0079] Other methods may also be used to determine the difference, as long as it is ensured that the adjusted model can accurately extract the text describing the function of the application to be detected from the description text, and this specification does not impose any limitation on this.
[0080] S104: Decompile the bytecode into a high-level representation code, extract the functional semantics of the application to be detected according to the high-level representation code as a second entity of the application to be detected, and construct a second entity set.
[0081] In order to implement consistency detection of the application to be detected, the server should also analyze the smart contract of the application to be detected and determine the functional semantics of the application to be detected so as to subsequently perform consistency detection on the application to be detected.
[0082] Specifically, since bytecode is a code form close to machine language, it contains less semantic information and it is difficult to perform complex analysis directly on the bytecode. Therefore, in order to facilitate the extraction of the semantics of the smart contract, the server should decompile the bytecode into a high-level representation code. Among them, the high-level representation code is a kind of intermediate representation code (Intermediate Representation, IR) that is closer to the source code, that is, high-level IR. The original analysis and verification of the smart contract is converted into operations on IR. Of course, in one or more embodiments of this specification, there is no restriction on what method is used to achieve the decompilation of bytecode. There are many decompilation tools at present, and this specification does not list them one by one.
[0083] Then, after determining the high-level IR of the bytecode of the smart contract, the server can analyze the function of the smart contract according to the determined high-level IR, extract the functional semantics, and then construct a second entity set according to the extracted functional semantics, where each functional semantic is a second entity in the second entity set. Specifically, the server can determine the functional semantics of the smart contract according to the extracted operating instructions by extracting certain operating instructions from the IR. For example, extracting "totalSupply()" from the bytecode determines the token supply of the smart contract, extracting "pause()" from the bytecode determines the pause state of the smart contract, and so on.
[0084] In one or more embodiments of this specification, the specific content of the extracted functional semantics is not limited, and it may be the functions and expected behaviors of each part of the code in the determined high-level IR, or it may be a description of the core services provided by the determined smart contract, such as token transfer, voting mechanism, etc. It can also be a summary of the business logic of the application to be tested, such as resource flow rules, permission control strategies, incentive mechanisms, etc., which are not listed one by one in this specification. The specific form of expression of the extracted functional semantics is also not limited, and it can be a string of operating instructions, a natural language description of the function, or an annotation to the high-level IR. Of course, the functional semantics is not limited to the form of a string, and can specifically be a knowledge graph, a state tree, or other relationship diagram. In one or more embodiments of this specification, there is no limitation on this.
[0085] S106: Match the first entities with the second entities. When the first entity and / or the second entity fails to match, determine that the description text of the application to be detected does not match the functional semantics and is not consistent.
[0086] After extracting each first entity and each second entity of the application to be detected, the server may determine whether the application to be detected has consistency according to the matching conditions between each first entity and each second entity.
[0087] Specifically, the server matches each first entity with each second entity. If the first entity of the application to be detected contains "fixed reward rate is X%", the server searches the second entity to determine whether the second entity contains the corresponding operation instruction in the first entity. If the second entity does not retrieve the operation instruction related to the fixed interest rate, or the value is different, it can be regarded as the description text of the application to be detected does not match the functional semantics and does not have consistency. Then, after all the first entities in the first entity set are matched, it is determined whether the second entity set contains any second entities that have not been matched. If so, it means that there is a second entity that fails to match the first entity set, and the application to be detected is not consistent. -
[0088] When there is a mismatch between the first entity and the second entity, such as the first entity is "guaranteed reward rate of X%", and the second entity is "reward: Y%", or the second entity does not match the corresponding first entity, such as the second entity is "the developer can terminate the transaction at any time", and there is no content related to the claim in the first entity set, or the first entity does not match the corresponding second entity, such as the first entity is "withdrawals can be made without preconditions", but there is no second entity related to withdrawals in the second entity set, it can be determined that the description text of the application to be tested does not match the functional semantics and is not consistent.
[0089] based on Figure 1 A consistency detection method for decentralized applications is shown, which obtains the description text of the application to be detected and the bytecode of the smart contract, then extracts the text describing the function of the application to be detected in the description text as each first entity, and determines the functional semantics of the application to be detected according to the bytecode of the smart contract of the application to be detected as the second entity of the application to be detected. The determined first entity and second entity are matched, and the consistency of the application to be detected is determined according to the matching result.
[0090] It can be seen from the above method that based on the analysis of the description text of the application to be detected and the bytecode of the smart contract, it is identified whether there is consistency between the description text of the front end of the application to be detected and the functions implemented by the smart contract, thereby determining the consistency of the application to be detected, preventing the inconsistency between the description text of the front end of the application to be detected and the functions implemented by the smart contract from causing risks to users of the application to be detected, affecting users' trust in decentralized applications and application platforms that provide decentralized applications, and protecting users' safety.
[0091] In step S102, due to the diversity and complex structure of the front-end description text of the DApp, it is difficult to extract information related to user security. Conventional model training requires large training data and is costly. In order to reduce the model training cost and improve the extraction efficiency of the text describing the function of the application to be detected, the extraction model can also be obtained by fine-tuning the large language model (LLM). The outstanding performance of LLM in the field of natural language processing is used to extract the functional description text describing the application to be detected. The fine-tuning process of LLM can be the same as the process of extracting the model in step S102.
[0092] Furthermore, in order to make the large language model output the first entity better, the server can also design appropriate prompt words when inputting the description text into the extraction model, so that the extraction model can better extract the first entity from the description text, making the extracted first entity more convenient to match with the second entity later, such as focusing more on the extraction of functions related to numerical values, or making the extracted first entity pay more attention to the description of a certain function. For example, "Please help me extract sentences related to the description function from the provided text"
[0093] In addition, in order to better extract the first entity in the description text and thus realize consistency monitoring of the application to be detected, the server can also classify the inconsistencies of various DApps, and then set corresponding prompt words based on each classification.
[0094] Specifically, the DApps marked as inconsistent are determined as marked applications, and the description text of the marked applications and the bytecode of the corresponding smart contract are obtained. According to the description text of each DApp and the bytecode of the smart contract, the first entities and the second entities corresponding to each marked application are determined, and the first entities and the second entities are matched, and the matching result is determined as the first entity and / or the second entity that failed to match. For example, the first entity and the second entity do not match the first entity, the second entity does not match the corresponding first entity, or the first entity does not match the corresponding second entity.
[0095] According to each pair of first entities and / or second entities that failed to match, the reason for the match failure is determined, and the reasons for each failure are classified. It should be noted that in one or more embodiments of the present specification, there is no limitation on the specific method used for classification, nor is there a limitation on the number of classifications. Classification can be based on the reason for the match failure, such as the second entity does not contain an entity that matches the first entity, the first entity is inconsistent with the corresponding second entity description, etc. Classification of inconsistencies can also be achieved based on other methods, such as classification through an open card classification method, that is, Figure 2 As shown, Figure 2Schematic diagram of the types of inconsistencies provided for this specification.
[0096] Figure 2 The table shows three classification methods, namely, classification based on the reasons for matching failure, which can be divided into matching failure due to different numbers, and matching failure due to transparency issues, which leads to other functional semantics contained in the smart contract, but no description is provided to the user. Based on this, it can be further refined into matching failures due to non-guaranteed rewards, hidden fees, adjustable liquidity, etc. Of course, it can also be classified according to the type of application to be tested. In addition, other classification methods can be used, which will not be repeated in this manual.
[0097] The server can also perform separate tests on various inconsistency types based on the determined inconsistency types, thereby better implementing consistency testing of the application to be tested. Figure 2 Taking the provided inconsistency type as an example, if the determined inconsistency type is a general type of inconsistency type, the server, for the inconsistency type with different values, after extracting each first entity corresponding to the inconsistency type, determines the functional semantics related to the value in the second entity, and then matches the two to determine whether the values corresponding to each function are the same. For the inconsistency type related to transparency, after extracting each first entity related to permissions, determine the functional semantics related to permissions in the second entity, and then match the two to determine whether there is a functional semantics related to permissions in the second entity that does not have a corresponding description in the first entity. After matching for each inconsistency type, determine whether the application to be detected has a preset inconsistency, and if so, determine the inconsistency type.
[0098] When the determined inconsistency type is other inconsistency types, for non-guaranteed rewards, since this inconsistency type is caused by the DApp promoting high rewards to attract users, but in fact the implementation of the smart contract cannot guarantee the high rewards, therefore, when determining whether the application to be tested has an inconsistency type of non-guaranteed rewards, the first entity determined by the server should be related to the reward, such as "collect n% of the reward", and then determine the instructions related to the reward rate in the second entity, determine whether there are indeterminate variables in the process of determining the reward rate, or perform symbolic execution on the advanced IR to determine whether the final reward rate is n%.
[0099] Regarding hidden fees, this inconsistency type is caused by the fact that certain fees may be charged in the DApp to maintain operation, compensate for management and other resource consumption, but these do not appear in the description text. Therefore, when determining whether the application to be detected has an inconsistency type of hidden fees, the first entity determined by the server is related to fees, such as "no fees", "no other fees required", etc., and then determines whether there is "charged at m%" or other fees in the second entity. When it is determined that there are instructions or functions related to "charged at m%" or other fees in the second entity, it is determined that the application to be detected has inconsistencies in hidden fees. Of course, if there is no first entity related to fees in the description text, the server should also determine whether there are instructions or functions related to "charged at m%" or other fees in the second entity set when matching the first entity set and the second entity set.
[0100] Regarding adjustable liquidity, since this type of inconsistency is caused by the fact that DApp guarantees that the tokens of liquidity providers are locked in the smart contract for a period of time during promotion, but when the actual functions of the smart contract are implemented, certain specific users are allowed to schedule tokens at will, this type of inconsistency will affect the stability of the market. If the project party suddenly withdraws liquidity after raising funds, causing the token price to plummet, it will greatly affect the rights and interests of users. Based on this, when determining the first entity, the server should extract the description related to the liquidity lock time, and then determine whether the description of the liquidity lock time in the second entity is the same as that in the first entity. If different, it means that the application to be tested has an inconsistency in adjustable liquidity.
[0101] Regarding the unlimited token supply, since many DApps have their own native tokens, the maximum supply of the native tokens should generally be fixed to ensure market stability and user rights. However, there may be malicious developers who, when setting up smart contracts, allow certain specific users to generate or supply tokens on their own, resulting in damage to the rights of other users. Based on this, when determining the first entity, the server should determine the description related to the number of tokens claimed, and then determine the actual supply of tokens in the second entity. When the actual supply of tokens is different from the number of tokens described in the first entity, it is determined that the application to be tested has an inconsistency in the unlimited token supply.
[0102] Regarding the undeclared fund flow, this inconsistency type is caused by the fact that most DApps allow users to deposit or transfer funds to obtain returns, but in some cases, the owner of the DApp may have the ability to urgently withdraw tokens from the blockchain, which may greatly threaten the security of the user's assets. Based on this, when determining the first entity, the server should determine the description related to the fund flow, and then determine whether there is an operation code or instruction related to the contract funds that can be withdrawn by a specific user in the second entity. In this way, it is determined whether the application to be tested has an inconsistency in the unclaimed fund flow.
[0103] Regarding the changeable DApp state, the pause function in DApps provides developers with the ability to manage unexpected events, security issues, or implement updates. However, the lack of information about the user's pause state may cause transmission failures and weaken people's trust in DApps. Based on this, when determining the first entity, the server should determine the description related to the DApp's suspension right, and then determine whether the second entity contains the relevant functional semantics that the DApp can be suspended to prevent transactions, and determine whether the description extracted from the first entity is the same as the relevant functional semantics in the second entity. If different, it means that the application to be detected has inconsistencies in the changeable DApp state.
[0104] Regarding the accessibility of non-fungible tokens (NFTs) with unstable accessibility status, since NFTs represent the ownership of digital unique assets on the blockchain, it is crucial whether NFTs can be immortal on the blockchain. If the DApp guarantees the permanence of the smart contract, but in fact the smart contract is stored on a centralized server, it is possible that the smart contract will not be permanent due to the shutdown of the server. Based on this, the server can first determine whether there is a description related to the permanence of the smart contract in the first entity, and then determine the functional semantics related to the storage location of the smart contract in the second entity to determine whether the two correspond. If not, it means that the application to be tested has inconsistencies in the volatile NFT accessibility.
[0105] Of course, the above is only an embodiment provided in this specification. The server can determine different inconsistency types based on different inconsistency types. When a new inconsistency type appears, the server can also re-determine the corresponding first entity according to the new inconsistency type.
[0106] In addition, based on the determined inconsistency type, in order to better extract the first entity in the description text and facilitate subsequent matching, the server can also set prompt words for each inconsistency type, and then input the prompt words and description text into the prompt model. Of course, in one or more embodiments of the present specification, there is no restriction on the specific way to combine each prompt word and description text, that is, the server can input the prompt word and description text corresponding to a certain inconsistency type into the extraction model, and then input the prompt word and description text corresponding to another inconsistency type into the extraction model. Of course, each prompt word and description text can also be input into the extraction model together. This allows the server to better detect the determined inconsistency type.
[0107] Specifically, the server generates a prompt word corresponding to each inconsistency type according to each inconsistency type. Then, for each inconsistency type, each first entity corresponding to the inconsistency type is determined as the second annotation. Then, the prompt word corresponding to the inconsistency type is determined, and the prompt word and the training sample are input into the trained extraction model to determine the second output of the extraction model. With the minimum difference between the second output and the second annotation as the optimization goal, the prompt word is adjusted to determine the final prompt word of the inconsistency type. When determining the difference between the second output and the second annotation, the same method as that for determining the difference when training the extraction model in step S102 can be used. Other methods for determining the difference mentioned in step S102 can also be used.
[0108] It should be noted that, since both large language models and other types of models generally have restrictions on the number of input words, if the description text has a large number of words, the server can also cut the description text, and then combine each cut text with the prompt word and input them into the extraction model separately.
[0109] In step S104, in order to facilitate the server to analyze the semantics of the smart contract, when decompiling the bytecode of the smart contract of the application to be tested into high-level IR, the server can replace the instructions in the bytecode through preset operation instructions, such as SSTORE(s,y,z) means that statement s writes variable z to storage address y, x:=SLOAD(s,y) means that variable x is loaded from storage address y in statement s, CALL(s,arg) means that statement s executes an external contract call with parameter arg, etc. Then, according to the decompiled high-level IR, the smart contract is semantically analyzed according to the operation instructions therein.
[0110]
[0111] Among them, CA(cs, r, 0) indicates that the variable r is the 0th parameter in the external call with the calling position of cs, that is, the identification of the determined recipient, CA(cs, a, 1) indicates that the variable a is the 1st parameter in the external call with the calling position of cs, that is, the amount of the received transfer is determined, and EC(cs, *, fs) indicates that in the external call with the calling position of cs, the function fs under the contract address "*" is called. SF(cs, cf) indicates that the variable "cs" is in the public function "cf", "0xa9059..." indicates the function signature required for ERC20 token transfer, and C(fs) = "0xa9059..." indicates that the value of fs is equal to "0xa9059...". Therefore, the content on the horizontal line in the above rule formula indicates that a certain amount of transfer is transferred to the target recipient, and the cs in the cf function in the transfer initiation contract calls the function signature "0xa9059..." to transfer to the recipient "*". Transf(cs, r, a, cf) below the horizontal line indicates that in the function, its signature is cf, and the variables r and a are the receiver and transfer amount of the call point cs respectively. This rule formula indicates that when transferring money through a digital signature, the transfer function with the function signature of "0xa9059..." is called, that is, when the application to be tested transfers money, it transfers ERC20 tokens, and can identify the transfer target and transfer amount. Analyzing the calling relationship between the functions in the smart contract and the calling relationship of the function signature based on rule formulas similar to the above can help analyze and understand the contract functions and detect potential security issues.
[0112] In addition, in this specification, there is no restriction on the language into which the server decompiles the bytecode. It can be decompiled according to actual needs, or the bytecode can be decompiled into various high-level IRs at the same time, so that the functional semantics of the smart contract can be analyzed based on the high-level IRs in different languages later.
[0113] When extracting the functional semantics of the smart contract from the high-level IR of the smart contract, the server can also construct the state dependency graph and data transfer graph of the smart contract based on the high-level IR, so as to assist in extracting the functional semantics of the smart contract based on the state dependency graph and data transfer graph. Specifically, the state variables are extracted according to the high-level IR, and the dependency relationship between each state variable is determined, and then the state dependency graph of the smart contract is constructed based on the dependency relationship. Then, the high-level IR is subjected to data flow analysis, and the data transfer graph of the smart contract is constructed to analyze the complex execution logic of the smart contract. The data refers to the business data when the application to be tested executes the business.
[0114] In addition, the server can also perform symbolic execution on the high-level IR to determine the symbolic execution results and implement static analysis of the smart contract, thereby identifying the functional semantics of the smart contract.
[0115] Of course, at least two of the above three methods, namely data flow analysis, graph construction and symbolic execution, can be used in combination to better extract the functional semantics of the smart contract.
[0116] It should be noted that DApp can also be designed for scenarios related to finance. When DApp is used in scenarios related to finance, the consistency test of DApp is related to the user's fund security. Therefore, when performing consistency test on DApp used in scenarios related to finance, more attention should be paid to the financial description of the DApp and the functional semantics of the smart contract, such as return on investment, token supply, token liquidity, etc. When determining the data transfer graph based on the advanced IR, more attention should be paid to the flow of funds, so as to construct the fund transfer graph of the application to be tested as the data transfer graph of the application to be tested. Therefore, based on the fund transfer graph, the fund flow of the application to be tested can be better identified when it is working, the financial characteristics of the application to be tested can be better analyzed, and the user's fund security can be protected.
[0117] Specifically, if the consistency of a DApp with a high financial relevance is detected, in step S102, the server may first obtain the description text of the DApp front end, and then determine the prompt words corresponding to each inconsistency type, combine each prompt word with the description text, and input them into the trained extraction model, so that the trained extraction model extracts the description text related to the function corresponding to each inconsistency type from the description text according to each prompt word. For example, for non-guaranteed rewards, the extraction model can extract the description of the return on investment. For hidden fees, the extraction model can extract the fee statement in the description text. For adjustable liquidity, the extraction model can extract the description of the lock time in the description text. For undeclared fund flows, the extraction model can extract the situation of specific or privileged users withdrawing funds from the description text. If there is no description, it is empty or no relevant content is extracted. For unlimited token supply, the extraction model can extract descriptions related to the token casting ability or token supply of the contract from the description text. For DApps with changeable and unstable states of accessibility, the extraction model can extract descriptions related to the operation or stop of the DApp from the description text.
[0118] Then in step S104, the server can also obtain the bytecode of the smart contract of the DApp and decompile the bytecode into a high-level IR. For the decompiled high-level IR, the functional semantics of the DApp corresponding to each inconsistent type are extracted from the high-level IR. For example, for non-guaranteed rewards, the server can construct a fund transfer graph and a state dependency graph based on the high-level IR, and then identify whether the transfer amount depends on dynamic factors when the transfer target is a user based on the fund transfer graph, the state dependency graph and the operation execution in the high-level IR, thereby determining the reward mechanism of the DApp. For hidden fees, the server can symbolically represent the transfer amount in the high-level IR, and then symbolically execute the high-level IR, determine the symbolic amount finally output by a node in combination with the storage information of the on-chain contract account, and compare each transfer amount with the symbolic amount to determine whether there is a fee collection and determine the fee collection rate. For undeclared fund flows, the server analyzes the high-level IR to determine whether there are specific or privileged users who can extract funds from the smart contract. For adjustable liquidity, the server can analyze the liquidity lock time and the authority to modify the time in the high-level IR. For unlimited token supply, the server analyzes the minting capacity of tokens based on the IR. For changeable DApp states, the server can analyze the modifiability of DApp states based on the advanced IR and state dependency graph. For unstable accessible states, the server can obtain the storage method of the DApp's NFT based on the advanced IR.
[0119] Then, in step S106, for each inconsistency type, the server matches the extracted first entity and the second entity to determine whether there is an inconsistency in the DApp. If so, the inconsistency type is output, otherwise it is determined that the DApp is consistent.
[0120] In step S106, if the extracted functional semantics are operation instructions for implementing various functions, in order to better match the first entity and the second entity, the server can extract key texts in the first entity, such as extracting texts related to the reward mechanism and the execution mechanism, and generate corresponding operation instruction codes as corresponding key codes through various programming languages or high-level IR languages according to the determined key texts. If the key text is a fixed interest rate, the corresponding key code can be "RETURNPRIV ATE(t,v)", which means that at "t", the variable "v" is returned to the caller, where the variable can be replaced by symbols such as "&". Then, according to the determined key code, search in the second entity set to determine whether the key code exists in the second entity set. In this way, it is determined whether the functions promised by the smart contract are consistent with the functions described in the description text.
[0121] Of course, the server also executes in the advanced IR according to the determined key code to determine whether there is a corresponding function code in the smart contract. If there is a corresponding function code, it analyzes whether it corresponds. If so, it determines that the application to be tested is consistent. If it does not correspond or there is no corresponding function code, it determines that the application to be tested is not consistent.
[0122] In addition, when matching the first entity and the second entity, the server may also convert each first entity into a preset format, such as a key-value dictionary type, and then compare the values of the first entity and the second entity to determine that the first entity and the second entity are successfully matched, thereby achieving matching of the first entity and the second entity.
[0123] It should be noted that in one or more embodiments of the present specification, the order of extracting the first entity and the second entity is not limited, and they may also be performed simultaneously.
[0124] Based on the above content, this specification also provides a schematic diagram of the consistency detection process of the application to be detected, such as Figure 3 The server inputs the description text of the application to be detected into the trained large language model, extracts the first entity based on the large language model, converts the bytecode of the smart contract into IR and generates a corresponding fund transfer graph and state dependency graph, and executes the IR symbols to extract the functional semantics of the smart contract. Finally, the first entity and the functional semantics of the smart contract are matched to determine whether the application to be detected is consistent.
[0125] The above is a consistency detection method provided in one or more embodiments of this specification. Based on the same idea, this specification also provides a corresponding consistency monitoring device, such as Figure 4 shown.
[0126] The acquisition module 400 is used to acquire the description text of the application to be detected and the bytecode of the smart contract;
[0127] A first extraction module 401 is used to input the description text into a trained extraction model, extract the text describing the function of the application to be detected from the description text as the first entity of the application to be detected, and construct a first entity set;
[0128] A second extraction module 402 is used to decompile the bytecode into a high-level representation code, extract the functional semantics of the application to be detected according to the high-level representation code as a second entity of the application to be detected, and construct a second entity set;
[0129] The matching module 403 is used to match the first entity set with the second entity set, and when the matching fails, determine that the description text of the application to be detected does not match the functional semantics and is not consistent.
[0130] Optionally, the device also includes a training module 404, which is used to obtain the description text of each application as a training sample, and annotate the text of the function description in each description text to determine a first annotation; input the training sample into the extraction model to be trained to determine the first output of the extraction model to be trained; and adjust the extraction model to be trained with the minimum difference between the first output and the first annotation as the optimization goal.
[0131] Optionally, the first extraction module 401 is used to input preset prompt words and the description text into the trained extraction model; wherein the preset prompt words are determined by the following method, including: obtaining the description text of the annotation application marked as inconsistent and the bytecode of the corresponding smart contract, and determining the corresponding first entities according to the vertex description text, and determining the corresponding second entities according to the bytecode; matching the first entities with the second entities, and determining the matching result as the first entity and / or the second entity that failed to match; determining the reason for the matching failure according to each pair of the first entity and / or the second entity that failed to match, and classifying the reasons for each failure to determine the inconsistency type; generating a prompt word corresponding to each inconsistency type according to each inconsistency type.
[0132] Optionally, the first extraction module 401 is used to determine, for each inconsistency type, each first entity corresponding to the inconsistency type as a second annotation; determine a prompt word corresponding to the inconsistency type, input the prompt word and the training sample into the trained extraction model, and determine a second output of the extraction model; adjust the prompt word with the minimum difference between the second output and the second annotation as the optimization goal, and determine a final prompt word for the inconsistency type; and input each final prompt word and the description text into the trained extraction model respectively.
[0133] Optionally, a second extraction module 402 is used to extract instruction codes from the high-level representation code; extract state variables from the high-level representation code according to the high-level representation code, and determine the dependency relationship between each state variable; construct a state dependency graph of the smart contract according to the dependency relationship; perform data flow analysis on the high-level representation code, and construct a data transfer graph of the smart contract; replace numerical operations in the high-level representation code with symbolic operations, perform symbolic execution on the high-level representation code, and determine the symbolic execution result of the high-level representation code; extract the functional semantics of the application to be tested according to at least two of the instruction code, the state dependency graph and the data transfer graph, and the symbolic execution result.
[0134] Optionally, the matching module 403 is used to determine, for each inconsistency type, each first entity in the first entity set corresponding to the inconsistency type, and determine the entity set to be matched; match the entity set to be matched with the second entity set to determine whether there are second entities in the second entity set corresponding to the first entities in the entity set to be matched; if not, it is determined that the application to be detected has inconsistency of this inconsistency type.
[0135] Optionally, the matching module 403 is used to extract key texts from each first entity in the first entity set, determine a key text set, and determine key codes corresponding to each key text in the key text set; for each key text in the key text set, retrieve the key code corresponding to the key text in the second entity set, and when the corresponding key code in the first entity set does not exist in the second entity set, determine that the first entity set fails to match the second entity set; determine whether there is a second entity in the second entity set that has not been matched; if so, the first entity set fails to match the second entity set.
[0136] This manual also provides Figure 5 The schematic structure diagram of the electronic device shown in FIG. Figure 5 As shown, at the hardware level, the electronic device includes a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and may also include other hardware required for the business. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it to achieve the above Figure 1 Of course, in addition to the software implementation, this specification does not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0137] In the 1990s, improvements to a technology could be clearly distinguished as hardware improvements (for example, improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the method flow). However, with the development of technology, many improvements to the method flow today can be regarded as direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement in a method flow cannot be implemented using a hardware entity module. For example, a programmable logic device (PLD) (such as a field programmable gate array (FPGA)) is such an integrated circuit whose logical function is determined by the user's programming of the device. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to ask a chip manufacturer to design and produce a dedicated integrated circuit chip. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented by "logic compiler" software, which is similar to the software compiler used when developing and writing programs, and the original code before compilation must also be written in a specific programming language, which is called hardware description language (HDL). There is not only one HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also know that it is only necessary to program the method flow slightly in the above-mentioned hardware description languages and program it into the integrated circuit, and then it is easy to obtain the hardware circuit that implements the logic method flow.
[0138] The controller can be implemented in any appropriate manner, for example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing a computer-readable program code (such as software or firmware) that can be executed by the (micro)processor, a logic gate, a switch, an application-specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in a purely computer-readable program code manner, the controller can be implemented in the form of a logic gate, a switch, an application-specific integrated circuit, a programmable logic controller, and an embedded microcontroller by logically programming the method steps. Therefore, this controller can be considered as a hardware component, and the devices included therein for implementing various functions can also be regarded as structures within the hardware component. Or even, the devices for implementing various functions can be regarded as both software modules for implementing the method and structures within the hardware component.
[0139] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0140] For the convenience of description, the above device is described in various units according to their functions. Of course, when implementing this specification, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0141] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0142] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0143] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0144] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0145] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0146] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0147] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0148] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0149] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems or computer program products. Therefore, this specification may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0150] This specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. This specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0151] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0152] The above description is only an embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the scope of the claims of the present invention.
Claims
1. A method for detecting consistency of a decentralized application, the method comprising: Get the description text of the application to be tested and the bytecode of the smart contract; Input the description text into the trained extraction model, extract the text describing the function of the application to be detected from the description text as the first entity of the application to be detected, and construct a first entity set; Decompiling the bytecode into a high-level representation code, extracting the functional semantics of the application to be detected according to the high-level representation code as a second entity of the application to be detected, and constructing a second entity set; The first entity set is matched with the second entity set. When the match fails, it is determined that the description text of the application to be detected does not match the functional semantics and is not consistent.
2. The method according to claim 1, wherein the extraction model is trained by the following method, comprising: Acquire description texts of each application as training samples, and annotate texts describing functions in each description text to determine a first annotation; Inputting the training sample into the extraction model to be trained, and determining a first output of the extraction model to be trained; The extraction model to be trained is adjusted with minimizing the difference between the first output and the first annotation as an optimization goal.
3. The method according to claim 2, wherein the description text is input into the trained extraction model, specifically comprising: Inputting the preset prompt words and the description text into the trained extraction model; The preset prompt words are determined by the following method, including: Obtaining description text of the marked application marked as inconsistent and bytecode of the corresponding smart contract, and determining corresponding first entities according to the vertex description text, and determining corresponding second entities according to the bytecode; Matching the first entities with the second entities, and determining that the matching result is a first entity and / or a second entity that failed to match; Determine the reason for the matching failure according to each pair of the first entity and / or the second entity that failed to match, and classify the reasons for each failure to determine the inconsistency type; According to each inconsistency type, a prompt word corresponding to each inconsistency type is generated.
4. The method according to claim 3, wherein the preset prompt words and the description text are input into the trained extraction model, specifically comprising: For each inconsistency type, determine each first entity corresponding to the inconsistency type as a second annotation; Determine a prompt word corresponding to the inconsistency type, input the prompt word and the training sample into the trained extraction model, and determine a second output of the extraction model; Taking the minimum difference between the second output and the second annotation as an optimization goal, adjusting the prompt word to determine a final prompt word of the inconsistency type; Each final prompt word and the description text are input into the trained extraction model respectively.
5. The method according to claim 1, extracting the functional semantics of the application to be detected according to the high-level representation code, specifically comprising: extracting instruction codes from the high-level representation code; According to the high-level representation code, extracting state variables in the high-level representation code and determining dependencies between the state variables; Constructing a state dependency graph of the smart contract according to the dependency relationship; Performing data flow analysis on the high-level representation code and constructing a data transfer graph of the smart contract; replacing numerical operations in the high-level representation code with symbolic operations, performing symbolic execution on the high-level representation code, and determining a symbolic execution result of the high-level representation code; The functional semantics of the application to be detected are extracted according to at least two of the instruction code, the state dependency graph, the data transfer graph, and the symbolic execution result.
6. The method of claim 3, wherein matching the first entity set with the second entity set comprises: For each inconsistency type, determine each first entity in the first entity set corresponding to the inconsistency type, and determine an entity set to be matched; Matching the to-be-matched entity set with the second entity set, and determining whether there are second entities in the second entity set corresponding to the first entities in the to-be-matched entity set; If not, it is determined that the application to be detected has inconsistency of this inconsistency type.
7. The method of claim 1, matching the first entity set with the second entity set, specifically comprising: Extract key texts from each first entity in the first entity set, determine a key text set, and determine key codes corresponding to each key text in the key text set; For each key text in the key text set, searching the second entity set for a key code corresponding to the key text, and when the second entity set does not contain a key code corresponding to the key text in the first entity set, determining that the first entity set fails to match the second entity set; Determine whether there is a second entity in the second entity set that has not been matched; If so, the first entity set fails to match the second entity set.
8. A consistency detection device for a decentralized application, the device comprising: The acquisition module is used to obtain the description text of the application to be tested and the bytecode of the smart contract; A first extraction module, configured to input the description text into a trained extraction model, extract the text describing the function of the application to be detected from the description text as the first entity of the application to be detected, and construct a first entity set; A second extraction module is used to decompile the bytecode into a high-level representation code, extract the functional semantics of the application to be detected according to the high-level representation code as the second entity of the application to be detected, and construct a second entity set; The matching module is used to match the first entity set with the second entity set, and when the matching fails, determine that the description text of the application to be detected does not match the functional semantics and is not consistent.
9. A computer-readable storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method according to any one of claims 1 to 7 when executing the program.
Citation Information
Cited By
Scratch virtual teaching demonstration method based on large language model
CN120124664A
Dynamic interaction large model mistake awareness detection method and device
CN120780839A
A dynamic, interactive large-scale model fallacy awareness detection method and device
CN120780839B
