Method and related device for detecting compliance of smart contract of power-carbon service

Through the method of combining macro prediction and micro auditing with fine-grained feature alignment, the problem of consistency detection of contract logic and business rules in electric carbon trading smart contracts is solved, automatic compliance detection is realized, the accuracy and efficiency of detection is improved, and the security and standardization of transactions are ensured.

CN120296743APending Publication Date: 2025-07-11XI AN JIAOTONG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510351333.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-24
Publication Date
2025-07-11

AI Technical Summary

Technical Problem

The existing technology has conflicts with the complexity of contract logic and the diversity of business rules in the electric carbon trading smart contract, resulting in insufficient feasibility and accuracy of the detection model, insufficient analytical capabilities of automated detection tools, excessive professional terms for testing results and difficult for users of non-technical backgrounds to understand, forming cognitive impairments for audit confirmation, affecting the accuracy, efficiency and operability of the contract.

Method used

Using macro prediction and micro auditing methods, we use knowledge characteristics and code characteristics to extract the electric carbon business smart contract, use multi-dimensional fine-grained feature alignment and large language models for consistency detection, build a benchmark data set, optimize the mapping search space between regulations and code, and realize automatic compliance detection.

Benefits of technology

It has improved the accuracy and efficiency of compliance detection of smart contracts for electric carbon trading, ensured transaction security, enhanced user trust, promoted the standardized development of electric carbon trading, reduced manual intervention and complexity, and achieved wider social participation and effective emission reduction goals.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120296743A_ABST
    Figure CN120296743A_ABST
Patent Text Reader

Abstract

The invention discloses a compliance detection method of an electricity and carbon service smart contract and a related device, and belongs to the cross field of a block chain technology and an electricity and carbon scene. According to the method, a reference data set covering compliant and non-compliant smart contracts is constructed, four key steps of the smart contract business compliance detection method are designed, semantic rules of power-carbon transaction related laws and regulations are defined, and consistency judgment is performed on the contracts through an agent-based large language model. The invention aims at improving the reliability of the smart contract of the power-carbon transaction based on the block chain, providing an important technical guarantee for the security of the power-carbon transaction service, and reducing the economic loss caused by the non-compliance of the contract logic.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of electricity-carbon business based on smart contracts, and particularly relates to a compliance detection method and related device for electricity-carbon business smart contracts. Background Art

[0002] Regarding the problem of detecting the consistency between contract code logic and business behavior in the electricity-carbon trading process, there is a contradiction between the complexity of contract logic and the diversity of business rules. Particularly, electricity-carbon trading involves multiple participants and complex business agreements, and smart contracts need to accurately reflect these business requirements. In the field of consistency detection of electricity-carbon trading smart contracts, there are three core defects in the existing technologies: First, since the research on the blockchain electricity-carbon direction is still in its infancy, the open-source power and carbon emission data systems are not perfect. Coupled with the differences in regional policies and industry standards, the business rules are highly differentiated, and the existing data sets lack the diversity and representativeness of scenario coverage. Relying on limited publicly available smart contract samples for deep learning training directly restricts the feasibility and accuracy of the detection model. Second, the automated detection tools have insufficient parsing ability for complex business logic. Especially when dealing with multi-party agreements, manual intervention is still required to ensure the detection accuracy, resulting in low detection efficiency and high labor costs. Third, there are technical barriers in the presentation of the detection results of existing tools. The excessive use of technical terms and the unstructured output method make it difficult for non-technical background users to understand the mapping relationship between contract logic and business rules, forming a cognitive obstacle in the review and confirmation link. These technical defects together lead to the systematic deficiencies in the accuracy, efficiency, and operability of electricity-carbon trading smart contracts. Summary of the Invention

[0003] The purpose of this application is to solve the problems in the existing technologies and provide a compliance detection method and related device for electricity-carbon business smart contracts. This application aims to ensure that the smart contract logic is consistent with business requirements, legal contracts, or other relevant documents to prevent security vulnerabilities or legal liabilities caused by logical inconsistencies.

[0004] To achieve the above purpose, this application adopts the following technical solutions: In the first aspect, this application provides a compliance detection method for electricity-carbon business smart contracts, including the following steps: Make a macro prediction for the electricity-carbon business smart contract. If the macro prediction result meets the preset requirements, continue with the micro audit; otherwise, the electricity-carbon business smart contract does not meet the compliance requirements; Conduct a micro audit on the electricity-carbon business smart contract. If the micro audit result meets the preset requirements, the electricity-carbon business smart contract meets the compliance requirements; otherwise, the electricity-carbon business smart contract does not meet the compliance requirements; The micro audit is as follows: Extract the knowledge features and code features of the smart contract for the electricity-carbon business respectively to obtain the knowledge features and code features. Perform fine-grained feature alignment on the knowledge features and code features from multiple dimensions, and detect the consistency of the knowledge features and code features to obtain the micro-audit results.

[0005] In a second aspect, the present application provides a compliance detection system for a smart contract of an electricity-carbon business, including: A macro-prediction module for performing macro-prediction on the smart contract of the electricity-carbon business. If the macro-prediction result meets the preset requirements, continue with the micro-audit; otherwise, the smart contract of the electricity-carbon business does not meet the compliance requirements. A micro-audit module for performing micro-audit on the smart contract of the electricity-carbon business. If the micro-audit result meets the preset requirements, the smart contract of the electricity-carbon business meets the compliance requirements; otherwise, the smart contract of the electricity-carbon business does not meet the compliance requirements. The micro-audit is as follows: Extract the knowledge features and code features of the smart contract for the electricity-carbon business respectively to obtain the knowledge features and code features. Perform fine-grained feature alignment on the knowledge features and code features from multiple dimensions, and detect the consistency of the knowledge features and code features to obtain the micro-audit results.

[0006] In a third aspect, the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the above method are implemented.

[0007] In a fourth aspect, the present application provides a computer program product, characterized in that: the computer program product contains instructions, and when the instructions are executed by the processor, the compliance detection method of the smart contract for the electricity-carbon business is implemented.

[0008] Compared with the prior art, the present application has the following beneficial effects: The present application proposes a compliance detection method and related device for a smart contract of an electricity-carbon business, which is used to implement a solution for detecting the consistency between the smart contract and the business terms in the blockchain electricity and carbon trading scenario. It not only provides a practical solution for the compliance management of electricity-carbon trading, but also lays a foundation for promoting the application and development of blockchain technology in the field of electricity-carbon trading.

[0009] Furthermore, the present application constructs a benchmark dataset for the carbon trading business, deeply explores compliant and non-compliant smart contracts to provide accurate compliance evaluation, better ensures the security of transactions, improves user trust, and helps to promote the standardized development of electricity-carbon trading.

[0010] Furthermore, through fine-grained feature alignment, this application defines the semantic rules of regulations, optimizes the search space for the mapping problem from complex code to regulations, realizes the effective matching between smart contract code and power and carbon business regulations, and uses an agent-based large language model for consistency judgment to complete comprehensive automated compliance detection, achieving broader social participation and effective emission reduction goals. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] To illustrate the technical solutions of the embodiments of this application more clearly, the following briefly introduces the drawings required in the embodiments. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as limiting the scope. For those of ordinary skill in the art, without creative efforts, other relevant drawings can be obtained based on these drawings.

[0012] Figure 1 It is a flowchart of the method of this application.

[0013] Figure 2 It is a schematic diagram of the system of this application.

[0014] Figure 3 It is a flowchart block diagram of the method for generating and detecting the compliance of the power-carbon business smart contract of this application and related devices.

[0015] Figure 4 It is a flowchart block diagram of the compliance detection method.

[0016] Figure 5 It is a schematic diagram of the generation of smart contract source code.

[0017] Figure 6 It is a schematic diagram of the compliance verification of smart contract code. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0018] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the following will clearly and completely describe the technical solutions in the embodiments of this application with reference to the drawings in the embodiments of this application. Obviously, the described embodiments are some, but not all, of the embodiments of this application. Usually, the components of the embodiments of this application described and shown in the drawings here can be arranged and designed in various different configurations.

[0019] Therefore, the following detailed description of the embodiments of this application provided in the drawings is not intended to limit the scope of this application that is claimed, but merely represents the selected embodiments of this application. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the scope of protection of this application.

[0020] It should be noted that like reference numerals and letters refer to like items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.

[0021] In the description of the embodiments of the present application, it should be noted that if terms such as "upper", "lower", "horizontal", "inner", etc. indicate the orientation or positional relationship based on the orientation or positional relationship shown in the drawings, or the orientation or positional relationship in which the inventive product is usually placed during use, it is only for the convenience of describing the present application and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be construed as a limitation to the present application. In addition, terms such as "first", "second", etc. are only used for distinguishing descriptions and cannot be understood as indicating or implying relative importance.

[0022] In addition, if the term "horizontal" appears, it does not mean that the component is required to be absolutely horizontal, but it can be slightly inclined. For example, "horizontal" only means that its direction is more horizontal relative to "vertical", and does not mean that the structure must be completely horizontal, but it can be slightly inclined.

[0023] In the description of the embodiments of the present application, it should also be noted that unless otherwise clearly specified and limited, if terms such as "set", "installed", "connected", "connected" are understood in a broad sense. For example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be directly connected or indirectly connected through an intermediate medium, and it can be the communication inside two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the present application can be understood according to specific situations.

[0024] In the blockchain scenario of reliable electricity-carbon trading, the introduction of blockchain technology is regarded as an important driving force for promoting the collaborative technological innovation of electricity and carbon. In particular, the decentralized and immutable characteristics of the blockchain can significantly improve the transparency and trust of transactions and promote wider participation. The smart contract for open-source electricity-carbon trading stored on the blockchain can achieve the automatic execution and enforcement of contracts, minimizing the risk of human error. However, although blockchain technology provides new possibilities for electricity-carbon trading, the detection problem of smart contracts remains a major challenge in its application.

[0025] The consistency detection of code logic and business behavior is oriented to the security risks and security evaluation of smart contracts in the electric carbon field, preventing malicious smart contracts carrying false information or harmful content from passing the evaluation and audit at the code level. Although existing tools can detect common vulnerabilities in smart contracts, legal issues are often overlooked or mishandled by technical personnel because programmers tend to regard these legal provisions as secondary priorities. This situation may not only introduce malicious transactions that violate the initial business logic but also lead to direct economic losses and damage the interests of users. Therefore, smart contract code must comply with legal provisions. Currently, the research on blockchain-based trusted electric carbon trading is still in its infancy, and the open-source power or carbon emission data stored in the blockchain is not sound enough.

[0026] The following further describes the present application in conjunction with the accompanying drawings: See Figure 1 , the embodiment of the present application discloses a compliance detection method for an electric carbon business smart contract, including the following steps: S1 Conduct a macro prediction on the electric carbon business smart contract. If the macro prediction result meets the preset requirements, continue with the micro audit; otherwise, the electric carbon business smart contract does not meet the compliance requirements. S2 Conduct a micro audit on the electric carbon business smart contract. If the micro audit result meets the preset requirements, the electric carbon business smart contract meets the compliance requirements; otherwise, the electric carbon business smart contract does not meet the compliance requirements. It should be noted that the micro audit involved in step S2 of the present application is as follows: S201 Extract knowledge features and code features from the electric carbon business smart contract respectively to obtain knowledge features and code features. S202 Align the knowledge features and code features in fine-grained manner from multiple dimensions, detect the consistency of the knowledge features and code features, and obtain the micro audit result.

[0027] In practical applications, the generation method of the electric carbon business smart contract of the present application includes: Generate an electric carbon business smart contract through a large language model; wherein, the electric carbon business smart contract includes a constructor, variable definitions, and preset function modules of the contract.

[0028] Constructor function: Ensure that all necessary parameters can be accurately initialized during design. At the same time, clearly allocate and set permissions in the constructor function, especially for the permissions of the contract administrator and controller, effectively preventing the contract from being attacked or suffering from permission abuse during the initialization phase. In an actual smart contract for electricity-carbon trading, the constructor function needs to accurately set the initial permissions of the participating parties. For example, some participating parties may only have the permission to view transaction data, while the administrator has the permission to modify contract parameters. By reasonably setting the constructor function permissions, a solid guarantee for the contract security is provided.

[0029] Variable definition: Strictly follow good programming specifications. All variables are named clearly and descriptively so that their semantics are easy to understand. Select appropriate data types according to the variable usage, and at the same time carefully set the access permissions. Take the variable recording carbon emission allowances in electricity-carbon trading as an example. A floating-point number type should be selected to accurately record the allowance value, and it should be set to be writable only by specific contract modules and readable by other modules to prevent data from being illegally tampered with and ensure the accuracy and security of transaction data.

[0030] Functional modules: Functional modules are the core part of the smart contract to implement business logic and also the key point for compliance inspection. Ensure that the contract is compatible with ERC standard-related functions during design. For example, in a smart contract involving electricity-carbon asset trading, follow the ERC-20 standard to implement the function of tokenized electricity-carbon asset transfer, which facilitates interaction with other systems following the same standard. At the same time, comprehensively consider and properly handle various possible boundary conditions and error situations. During the transaction process, if a network interruption occurs and the transaction is not completed, the smart contract should be able to automatically record the transaction status and attempt to automatically resume the transaction after the network resumes, preventing the transaction from being lost or falling into an error state due to abnormal situations and ensuring the stable operation of the smart contract in a complex environment.

[0031] It should be noted that after the smart contract for electricity-carbon business is generated in this application, it also includes: Verify the generated smart contract for electricity-carbon business through compilation, static analysis, dynamic testing, and simulation of the actual operating environment.

[0032] Compilation: Use the Solidity compiler to compile the generated smart contract code to initially check whether the code conforms to the programming language standard. If there are syntax errors in the code, such as incorrect variable declaration formats or mismatched function call parameters, the compiler will report errors in a timely manner, and developers can modify accordingly to ensure the correctness of the code at the basic syntax level and lay a foundation for subsequent detection and operation.

[0033] Static analysis: With the help of static analysis tools such as Slither, MythX, and Oyente, in-depth vulnerability scanning and code analysis are carried out on smart contracts. These tools can detect common security vulnerabilities, such as integer overflow vulnerabilities (when calculating the electricity-carbon trading quota, if the numerical range is not effectively checked, it may lead to calculation result overflow and cause trading errors), uninitialized variables (which may lead to unexpected results during the operation of the contract), and improper permission management (certain roles may obtain permissions beyond expectations, threatening the security of the contract), etc. By integrating these tools, potential code hazards can be quickly discovered and resolved.

[0034] Dynamic testing: Use dynamic testing tools such as Ganache and Truffle to conduct actual operation tests on the contract in a simulated environment. When simulating the electricity-carbon trading scenario, set different trading parameters, the number of concurrent transactions, and network latency and other conditions, and observe the running performance of the contract in various situations. For example, test the response speed and processing ability of the contract under high-concurrency transactions to ensure that it can meet the actual business needs and avoid performance bottlenecks or trading errors after being uploaded to the chain.

[0035] Through the above multi-layer verification, not only can it ensure that the generated smart contract complies with the standard specifications, but also effectively prevent vulnerabilities and security risks, timely discover and repair potential problems, and significantly improve the feasibility and anti-attack ability of the contract in actual applications.

[0036] In actual applications, use natural language processing technology to deeply analyze business regulation texts and extract key compliance requirements. In the electricity-carbon trading regulations, content such as carbon emission quota allocation rules, trading price limits, and trading entity qualification requirements are important compliance points. Through technical means such as text mining and semantic analysis, these key information are accurately identified and extracted from the regulation text to provide a basis for subsequent comparison with the code features of the smart contract. The extraction method of the knowledge features of this application includes: Through natural language processing (Natural Language Processing, NLP), a business structure representation graph is extracted from the business terms of the electricity-carbon business smart contract; Through vector learning, knowledge features are extracted from the business structure representation graph.

[0037] It should be noted that for the smart contract code, its logical structure and function implementation are analyzed in detail, and code features related to business regulations are extracted. In the smart contract code, code segments related to transaction process control, functions for permission management, and algorithms for data processing are all key features. Through technical means such as code parsing and abstract syntax tree construction, these code features are extracted and converted into a format that matches the results of business knowledge extraction for subsequent feature alignment operations. The extraction method of the code features of this application includes: Through Static Analysis Processing (SAP), a semantic relationship dependency graph is extracted from the source code of the carbon electricity business intelligent contract; Through vector learning, code features are extracted from the semantic relationship dependency graph.

[0038] Both of the above tasks utilize natural language processing techniques to automatically identify elements such as conditions, permissions, formulas, and behaviors in regulations. For a conditional statement in a regulation like "When the total carbon emissions in a certain region exceed the set threshold, the carbon electricity trading price in that region needs to increase by a certain percentage", through natural language processing algorithms, the premise for condition triggering (total carbon emissions exceeding the threshold), the object involved (carbon electricity trading in that region), and the corresponding operation (price increase by a certain percentage) can be accurately extracted, providing detailed feature information for subsequent compliance judgment.

[0039] In practical applications, when the present application conducts fine-grained feature alignment on knowledge features and code features from multiple dimensions, the multiple dimensions include: The condition part, the permission part, the formula part, and the behavior part.

[0040] Specifically, the following methods are included: Data processing: Using prompt engineering techniques, the model is guided to clean and format the extracted regulation and code features. There may be problems such as inconsistent expressions, abbreviations, and special symbols in the regulation text, and there may also be inconsistent data formats in the code features. By designing a special prompt, the model can automatically unify the expressions in the regulation text into a standard format and perform standardized conversion on the data types in the code features, such as unifying different time representations into a standard time format, making the regulation and code features compatible in format and facilitating subsequent feature alignment operations.

[0041] Feature alignment: The model meticulously compares the four key elements (conditions, permissions, formulas, and behaviors) in the business regulations and intelligent contracts according to the preset prompt. For the condition element in the regulation, it compares line by line with the corresponding condition judgment logic in the intelligent contract code to check whether the triggering conditions, judgment logics, and execution results of the conditions are consistent; for the permission element, it compares the permissions of each role stipulated in the regulation with the actual implemented permission control logic in the intelligent contract code to ensure that the permission allocation and use comply with the regulation requirements. Through this precise feature comparison, the compliance degree between the regulation and the code is judged.

[0042] Feedback and adjustment: During the feature alignment process, the model provides real-time feedback and makes adjustments based on the comparison results. If it is found that the matching degree of a certain conditional element is low, the model will automatically analyze the reasons, which may be due to inaccurate understanding of the regulatory text or incomplete extraction of code features. The model will re-adjust the text analysis strategy or code parsing method, and perform feature extraction and comparison again until a satisfactory matching effect is achieved. Through this continuously optimized process, the accuracy of compliance detection is continuously improved.

[0043] Through the collaborative work of the large model and the Agent, the fine-grained alignment verification can effectively detect and accurately judge the compliance between regulations and codes, providing a highly reliable basis for compliance detection.

[0044] It should be noted that to ensure that the model can accurately analyze the consistency between various features, special prompts are designed for each intermediate representation (conditions, permissions, formulas, behaviors). For conditional intermediate representations, the model is prompted to pay attention to the integrity of the conditions, the logical relationships between the conditions, and the consistency between the conditions and the business objectives; for permissions, the model is prompted to review whether the scope of permissions is reasonable, whether the permission granting and revocation mechanisms comply with regulatory requirements, and the checks and balances between the permissions of different roles. The model conducts in-depth analysis and judgment on the intermediate feature representations based on these special prompts. The analysis results of each category are integrated, and a compliance report is generated through comprehensive evaluation. The report not only clearly indicates whether the smart contract is compliant, but also details in which aspects it complies or does not comply with regulatory requirements, providing users with clear and comprehensive information. At the same time, the report results are fed back to the knowledge extraction and feature alignment links to optimize and improve the entire detection process, forming a closed-loop detection mechanism, and continuously improving the accuracy and efficiency of detection.

[0045] After obtaining the micro-audit results of this application, it further includes: If the micro-audit results do not meet the preset requirements, re-extract the knowledge features and code features of the electric carbon business smart contract, and conduct a micro-audit again.

[0046] As Figure 2 shown, the embodiment of this application discloses a compliance detection system for an electric carbon business smart contract, including: A macro-prediction module for making a macro-prediction on the electric carbon business smart contract. If the macro-prediction result meets the preset requirements, continue with the micro-audit; otherwise, the electric carbon business smart contract does not meet the compliance requirements; A micro-audit module for conducting a micro-audit on the electric carbon business smart contract. If the micro-audit result meets the preset requirements, the electric carbon business smart contract meets the compliance requirements; otherwise, the electric carbon business smart contract does not meet the compliance requirements. The micro-audit method is as follows: The knowledge feature extraction and code feature extraction of the electric carbon business smart contract are respectively performed to obtain the knowledge feature and code feature; Fine-grained feature alignment is performed on knowledge features and code features from multiple dimensions, and the consistency of knowledge features and code features is tested to obtain micro-audit results.

[0047] like Figure 3 As shown, this application is dedicated to exploring the business compliance in the blockchain-based electric carbon trading smart contract, and the premise of compliance verification is to create a benchmark data set containing compliant and non-compliant smart contracts. This embodiment discloses a method for generating and complying with the smart contract for electric carbon business, including the following steps: S101: Build a benchmark data set for the electric carbon business. The benchmark data set covers compliant smart contracts and non-compliant smart contracts, providing a training and testing basis for subsequent compliance testing; so that the smart contract business compliance testing tool can effectively distinguish between compliant and non-compliant contracts, and improve the overall level, efficiency and accuracy of contract code generation through continuous training and optimization of large models.

[0048] The compliance in the benchmark data set refers to smart contracts that comply with the safety transactions of the electricity-carbon business, which serve as positive samples for compliance detection of smart contract business based on electricity-carbon transactions; while the illegal smart contracts come from the code generation of illegal businesses or malicious modifications to compliant codes, which serve as negative samples.

[0049] The benchmark data set for building electricity carbon trading business also includes: Smart contract standardization: To ensure the feasibility of smart contract compilation and execution, define typical rules of standard smart contracts and clearly list the constructor, variable definition and key functional modules of the contract; Diversification of smart contracts: using different types of large language model technologies to generate smart contract source code to achieve diversification of code paradigms, thereby covering a wider range of contract types and scenario requirements; Contract generation is automated, with model-generated contracts replacing manual code writing and auditing, and rapid iteration is achieved based on standard contract rules and cases, significantly improving the efficiency and accuracy of contract generation.

[0050] In order to ensure the standardization of smart contracts, the constructor, variable definitions and key functional modules of the contract are clearly listed, including: 1. The design of the constructor should ensure that it can correctly initialize all necessary parameters. At the same time, the constructor should clearly allocate and set permissions, especially the permissions of the contract administrator and controller, to prevent the contract from being attacked or abused during the initialization phase.

[0051] (2) Variable definitions should follow good programming practices. All variables should have clear and descriptive names to make their semantics easy to understand, and the appropriate data type should be selected according to the purpose of the variable. Special attention should be paid to setting appropriate access permissions.

[0052] (3) Functional modules are an important part of smart contracts to implement their logic and are also the key modules to check business compliance. When designing functional modules, functions that comply with ERC standards (such as ERC-20, ERC-721, etc.) should be ensured in the contract to improve compatibility. In addition, all possible boundary conditions and error situations need to be properly handled to prevent the contract from crashing or being maliciously exploited due to abnormal inputs.

[0053] To generate smart contracts that meet the standards and are safe and reliable, different large language models are used to generate contracts of various paradigms, so as to cover a wider range of contract types and scenario requirements. After the contract is generated, a multi-layer verification and testing strategy is adopted to evaluate its feasibility and security. The main verification means include compilation, static analysis, dynamic testing, and simulation of the actual operating environment.

[0054] (1) Compilation (such as the Solidity compiler solc) to initially confirm whether the code conforms to the language standard, identify irregularities in the contract, and ensure that the code logic is technically correct.

[0055] (2) Static analysis tools (such as Slither, MythX, Oyente) to conduct a detailed vulnerability scan and code analysis of the smart contract to identify known security vulnerabilities in the smart contract. Integrate static analysis tools to quickly detect vulnerabilities and ensure that the code has no potential problems.

[0056] (3) Dynamic testing tools (such as Ganache, Truffle) to test the actual performance of the contract in a simulated environment. Before the contract is deployed to the blockchain, simulate the operation of the contract in a real environment to confirm the performance of the contract under large-scale use and avoid uncontrollable problems after deployment.

[0057] Through the above multi-layer verification steps, including compilation, static analysis, dynamic testing, and simulation of the actual operating environment, not only can it be ensured that the generated smart contract conforms to the standard specifications, but also it can effectively prevent the emergence of vulnerabilities and security risks, timely discover and repair potential vulnerabilities, thereby improving the feasibility and attack resistance of the contract in actual applications.

[0058] S102: Compliance detection of smart contract business based on electricity-carbon trading, including: macro verification, which macroscopically evaluates the overall consistency between business documents and smart contracts by quickly identifying and excluding obviously irrelevant areas in complex business and technical scenarios without in-depth analysis of specific details; micro auditing, which ensures the compliance of smart contracts and the correctness of business logic at the detail level through efficient feature extraction, refined feature alignment, and consistency judgment. Macro verification and micro auditing adopt an agent mechanism to achieve automated compliance verification, reducing manual verification and realizing the independent development of the consistency detection function.

[0059] As Figure 4 shown, the flowchart of the compliance detection method is as follows: S201: Macro prediction mechanism, which evaluates the domain attribution of code and business regulations from a macro perspective to ensure its match with relevant domains; directly excludes irrelevant items by determining domain relevance. After meeting the macro expectations, then implement micro auditing to minimize the loss of the large language model during the evaluation process; in complex business and technical scenarios, the goal of prediction is to quickly identify and exclude obviously inconsistent samples, rather than delving into the audit of every detail, helping reviewers focus on more relevant and potentially problematic areas, greatly improving efficiency, especially when faced with a large amount of information, reducing unnecessary review work.

[0060] S202: Intermediate feature representation, which extracts logical and semantic feature information at the contract and business levels respectively to generate intermediate representations of code and business; as the basis for compliance detection, it is divided into two parallel tasks: business knowledge extraction and code feature extraction.

[0061] Specifically, the intermediate feature representation includes: two parallel tasks, namely business knowledge extraction and code feature extraction. Both adopt natural language processing technology for efficient feature extraction and intermediate representation technology to optimize the search space, so as to bridge the gap between regulations and smart contracts. First, divide the intermediate representation into four main categories: conditions, privileges, formulas, and actions, and then use the large language model to automatically identify the four types of elements in the regulations. Business knowledge extraction is the identification of business regulations, aiming to extract key compliance requirements from business regulations. On the other hand, code feature extraction focuses on analyzing the code logic of smart contracts to ensure its implementation conforms to the requirements of business regulations.

[0062] Specifically, the intermediate representation (IR) includes: Condition knowledge, indicating under what circumstances the smart contract will perform specific operations. By extracting and analyzing the statements expressing conditions in the regulations, ensure that the smart contract triggers operations only when specific conditions are met, avoiding improper execution; Permission knowledge involves the definition of permissions for various roles in smart contracts. The extraction of permissions ensures that the operation permissions of each participant are consistent with regulatory requirements, thus preventing permission abuse; Formula knowledge covers the calculations and logical relationships involved in compliance. By extracting relevant formulas, it can be verified whether the mathematical calculations in smart contracts comply with the regulations in the laws, thus ensuring the accuracy and compliance of the calculations; Behavior knowledge refers to the actual execution behavior of smart contracts. The extraction and analysis of behaviors ensure that smart contracts exhibit behavior characteristics that comply with compliance during operation, avoiding illegal operations.

[0063] With the help of the capabilities of large model agents (intelligent agents), corresponding intermediate representation prompts (IR prompts) are constructed to automate this process. First, through the prompt for business clause segmentation, the clauses in the regulatory text are decomposed and their core elements are extracted; then, through the prompt for code segmentation, the logical structure in the smart contract code is refined and segmented according to four types of intermediate representations. Next, the key code intermediate representations are extracted from the segmented code through the IR prompt. Through these four types of intermediate representations, the relationship between regulations and code can be analyzed more systematically, the mapping from complex code to business rules can be realized using the four types of intermediate representations, and by refining the search space of the mapping, the gap between the business rule intention and the smart contract code can be bridged, providing support for the fine-grained feature alignment of subsequent compliance detection.

[0064] Business knowledge extraction focuses on the identification of regulatory intentions, aiming to extract key compliance requirements from regulatory texts.

[0065] Code feature extraction focuses on analyzing the code logic of smart contracts to ensure that its implementation complies with regulatory requirements.

[0066] All of the above are achieved through natural language processing technologies, which can automatically identify elements such as conditions, permissions, formulas, and behaviors in regulations.

[0067] S203: Fine-grained feature alignment, which is a key step in aligning the features of smart contract code and business regulations based on fine-grained features to determine whether the contract logic meets the requirements of business regulations and ensure an accurate match between the extracted regulatory and code features. In the process of aligning regulations and code, in addition to the systematic analysis based on four types of intermediate representations, data processing, feature alignment, feedback, and adjustment are also required; the realization of refined feature alignment mainly depends on the following steps: (1) Data processing: Guided by prompt engineering, the model automatically performs simple cleaning and formatting on the extracted regulatory and code features to make subsequent alignment operations smoother.

[0068] (ii) Feature alignment: The model performs feature matching based on preset prompts, directly comparing relevant elements in regulations and smart contracts to determine their degree of compliance.

[0069] (III) Feedback and Adjustment: During the alignment process, the model provides simple feedback and adjustments based on the results to continuously optimize the alignment effect and improve the accuracy of compliance testing.

[0070] Fine-grained alignment verification effectively detects and judges the compliance between regulations and codes through the combination of large models and agents, providing higher accuracy and reliability for compliance detection.

[0071] S204: Consistency judgment, the above intermediate feature representations are evaluated for consistency through a large language model to judge the compliance of the smart contract. Specific prompts are designed for each IR (such as conditions, permissions, formulas, behaviors) to ensure that the model can accurately analyze the consistency between various features.

[0072] Specifically, consistency judgment includes: isolating the features of different categories (four categories) to ensure that their evaluation results do not affect each other, thereby improving the accuracy and reliability of the judgment. This consistency judgment is different from the model of the previous macro prediction mechanism. Each extracted category is analyzed and judged independently. In the implementation process of consistency judgment, different intermediate representations need to be independently evaluated according to specific regulations and smart contract characteristics. To this end, specific prompts are designed for each intermediate representation (such as conditions, permissions, formulas, and behaviors) to ensure that the model can accurately analyze the consistency between various features, and then be able to evaluate more detailed and accurate. The model generates analysis results based on the prompts, and then integrates and feedback mechanisms to finally generate a detailed compliance report.

[0073] Specifically, the compliance report includes: independent assessment model, designing an independent assessment model for each feature category to ensure that each model is optimized for specific regulations and smart contract features.

[0074] Multi-dimensional analysis uses multi-dimensional evaluation criteria to judge the consistency between regulations and code features from multiple aspects, including functional consistency, logical consistency, and behavioral consistency.

[0075] Result integration and feedback: The evaluation results of each model are integrated, and the final compliance report is generated through comprehensive analysis, which is then fed back to the knowledge extraction and feature alignment stages to achieve closed-loop optimization.

[0076] like Figure 5As shown in the figure, it is a schematic diagram of the generation of smart contract source code. In view of the problems of code standardization and transaction compliance that usually occur in manually writing smart contracts, the coding task is handed over to a large language model to achieve automatic code generation and construct datasets of compliant and non-compliant smart contracts. Non-compliant smart contracts can be obtained based on the following two routes. One is the code generation from illegal business terms, which refer to the behaviors of smart contracts that do not conform to standard agreements or laws and regulations, and are also a series of problems that occur when signing contracts in daily life, such as hidden terms or other hidden fees that users often overlook. The other is the malicious modification of compliant code, which means that during the writing process of an originally compliant smart contract, it is intentionally or unintentionally modified to generate malicious code leaving potential vulnerability hazards. This application designs and develops a method for detecting the business compliance of smart contracts. During the compliance detection process, semantic rules related to electricity-carbon trading regulations are defined, and the consistency of the contract is judged through a large language model based on an agent.

[0077] As Figure 6 shown in the figure, it is a schematic diagram of the verification of smart contract code compliance. The detection method of this application includes four key steps: macro prediction mechanism, intermediate feature representation, fine-grained feature alignment, and consistency judgment. First, a macro consistency judgment is made on the smart contract and the business to exclude completely irrelevant items to avoid wasting the resources of the large language model, and the domain relevance is determined to ensure that the content focused on by the model is closely related to electricity-carbon business regulations, improving the efficiency of the evaluation. Then, logical and semantic feature information is extracted respectively at the contract and business levels. On this basis, fine-grained feature alignment between the smart contract code and electricity-carbon business regulations is achieved at the micro level to ensure that the contract logic meets the requirements of business regulations. During the fine-grained feature alignment process, four main categories are defined to realize the mapping between the code and the regulations. By introducing an agent with a large language model, the complex logic of the smart contract is effectively matched with the compliant business regulations in an intermediate representation manner, reducing manual verification and realizing the independent development of the consistency detection function. Finally, the large language model conducts a consistency evaluation on the above intermediate feature representation to judge the compliance of the smart contract.

[0078] A computer device provided by an embodiment of this application. The computer device of this embodiment includes: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps in the above-mentioned method embodiments are implemented. Or, when the processor executes the computer program, the functions of each module / unit in the above-mentioned device embodiments are implemented.

[0079] The computer program can be divided into one or more modules / units. One or more modules / units are stored in the memory and executed by the processor to complete this application.

[0080] A computer device can be a computing device such as a desktop computer, a notebook, a handheld computer, and a cloud server. The computer device may include, but is not limited to, a processor and a memory.

[0081] The processor can be a Central Processing Unit (CPU), or can also be other general-purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field-Programmable Gate Arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.

[0082] The memory can be used to store computer programs and / or modules. By running or executing the computer programs and / or modules stored in the memory, and by invoking the data stored in the memory, the processor implements various functions of the computer device.

[0083] If the modules / units integrated in the computer device are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, to implement all or part of the processes in the above method embodiments of this application, it can also be completed by a computer program instructing relevant hardware. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, it can implement the steps of the above various method embodiments. Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, executable file, or some intermediate form, etc. The computer-readable medium can include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard disk, a magnetic disk, an optical disc, a computer memory, a Read-Only Memory (ROM), a Random Access Memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium, etc. It should be noted that the content included in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electrical carrier signals and telecommunication signals.

[0084] The embodiments of the present application also provide a computer program product or a computer program. The computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes Figure 1 the methods provided in the various alternative manners in

[0085] In the embodiments of the present application, the terms "first", "second", etc. in the description, claims and drawings of the present application are used to distinguish different objects, rather than to describe a specific order. In addition, the term "comprising" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, apparatus, product or device that includes a series of steps or units is not limited to the listed steps or modules, but optionally further includes steps or modules not listed, or optionally further includes other step units inherent to these processes, methods, apparatuses, products or devices.

[0086] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program with a predetermined function, which works with other related parts to achieve a predetermined goal, and can be fully or partially implemented by using software, hardware (such as a processing circuit or a memory), or a combination thereof. Similarly, one processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be a part of an overall module or unit that includes the function of the module or unit.

[0087] Those of ordinary skill in the art can realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the components and steps of the examples have been generally described according to their functions in this description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present application.

[0088] The method and related devices provided by the embodiments of the present application are described with reference to the method flowcharts and / or structural schematic diagrams provided by the embodiments of the present application. Specifically, each process and / or block of the method flowchart and / or structural schematic 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 the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable devices generate a device for implementing the functions specified in one process Figure 1 one process or multiple processes and / or structural schematic Figure 1 one block or multiple blocks. These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable devices to work in a specific manner, so that the instructions stored in the computer-readable memory generate a manufactured product including an instruction device, or are transmitted through a computer-readable storage medium. The computer instructions can be transmitted from a website, computer, server, or data center to another website, computer, server, or data center in a wired manner (for example, coaxial cable, optical fiber, digital line (DSL)) or wirelessly (for example, infrared, wireless, microwave, etc.). The instruction device implements the functions specified in one process Figure 1 one process or multiple processes and / or structural schematic Figure 1 one block or multiple blocks. These computer program instructions can also be loaded onto a computer or other programmable devices, so that a series of operation steps are executed on the computer or other programmable devices to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable devices provide steps for implementing the functions specified in one process Figure 1 one process or multiple processes and / or structural schematic one block or multiple blocks.

[0089] The steps in the method of the embodiments of the present application can be adjusted, combined, and deleted according to actual needs.

[0090] The modules in the device of the embodiments of the present application can be combined, divided, and deleted according to actual needs.

[0091] The above-disclosed content is only the preferred embodiments of the present application. Of course, the scope of the rights of the present application cannot be limited by this. Therefore, equivalent changes made according to the claims of the present application still fall within the scope covered by the present application.

Claims

1. A compliance detection method for an intelligent contract of the electro-carbon business, characterized in that It includes the following steps: Conduct a macro prediction on the carbon electricity business smart contract. If the macro prediction result meets the preset requirements, continue with the micro audit; otherwise, the carbon electricity business smart contract does not meet the compliance requirements; Conduct a micro audit on the carbon electricity business smart contract. If the micro audit result meets the preset requirements, the carbon electricity business smart contract meets the compliance requirements; otherwise, the carbon electricity business smart contract does not meet the compliance requirements; The micro audit is as follows: Extract the knowledge features and code features from the carbon electricity business smart contract respectively to obtain the knowledge features and code features; Perform fine-grained feature alignment on the knowledge features and code features from multiple dimensions, and detect the consistency of the knowledge features and code features to obtain the micro audit result.

2. The compliance detection method for the electric carbon business smart contract according to claim 1, wherein The generation method of the carbon electricity business smart contract includes: Generate the carbon electricity business smart contract through a large language model; wherein, the carbon electricity business smart contract includes the constructor, variable definition, and preset function modules of the contract.

3. The compliance detection method for the electro-carbon business smart contract according to claim 1, wherein After generating the carbon electricity business smart contract, it further includes: Verify the generated carbon electricity business smart contract through compilation, static analysis, dynamic testing, and simulation of the actual operating environment.

4. The compliance detection method of the electro-carbon business smart contract according to claim 1, wherein The extraction method of the knowledge features includes: Extract the business structure representation graph from the business terms of the carbon electricity business smart contract through natural language processing; Extract the knowledge features from the business structure representation graph through vector learning.

5. The compliance detection method for the e-carbon business smart contract according to claim 1, characterized in that, The extraction method of the code features includes: Extract the semantic relationship dependency graph from the source code of the carbon electricity business smart contract through static analysis processing; Extract the code features from the semantic relationship dependency graph through vector learning.

6. The compliance detection method for the intelligent contract of the electro-carbon business according to claim 1, characterized in that, In the fine-grained feature alignment of the knowledge features and code features from multiple dimensions, the multiple dimensions include: The condition part, permission part, formula part, and behavior part.

7. The compliance detection method for the intelligent contract of the electro-carbon business according to claim 1, characterized in that, After obtaining the micro audit result, it further includes: If the micro audit result does not meet the preset requirements, re-extract the knowledge features and code features of the carbon electricity business smart contract and conduct the micro audit again.

8. A compliance detection system for an electric carbon business intelligent contract, characterized in that, It includes: A macro prediction module for conducting a macro prediction on the carbon electricity business smart contract. If the macro prediction result meets the preset requirements, continue with the micro audit; otherwise, the carbon electricity business smart contract does not meet the compliance requirements; A micro audit module for conducting a micro audit on the carbon electricity business smart contract. If the micro audit result meets the preset requirements, the carbon electricity business smart contract meets the compliance requirements; otherwise, the carbon electricity business smart contract does not meet the compliance requirements; The micro audit is as follows: Extract the knowledge features and code features from the carbon electricity business smart contract respectively to obtain the knowledge features and code features; Perform fine-grained feature alignment on the knowledge features and code features from multiple dimensions, and detect the consistency of the knowledge features and code features to obtain the micro audit result.

9. An electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1-7.

10. A computer program product, characterized in that: The computer program product contains instructions, and when the instructions are executed by the processor, it implements the compliance detection method of the carbon electricity business smart contract according to any one of claims 1-7.