A method and system for constructing a carbon transaction auction model based on a smart contract

By adopting a carbon trading auction model based on smart contracts, the problems of inconsistent trading rules and security in carbon trading are solved, and a transparent and secure carbon trading process is achieved. By utilizing the event-b formal model and CapsNet-ATt vulnerability detection technology, the reliability and security of the transaction are improved.

CN122115085APending Publication Date: 2026-05-29YUNNAN POWER GRID CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
YUNNAN POWER GRID CO LTD
Filing Date
2023-11-08
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

Existing carbon trading methods suffer from inconsistent trading rules, information asymmetry, and security issues related to carbon trading as an electronic protocol.

Method used

The carbon trading auction model based on smart contracts is constructed by transforming the event-b formal model into Solidity smart contract code and using the CapsNet-Att vulnerability detection model. The model includes key opcode sequence feature extraction and vulnerability detection, and combines capsule networks and attention mechanisms to achieve secure and transparent carbon trading.

Benefits of technology

It enhances the transparency and security of carbon trading, eliminates human error in intermediate links, improves the reliability of smart contracts, and avoids the accuracy of error mapping and vulnerability detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122115085A_ABST
    Figure CN122115085A_ABST
Patent Text Reader

Abstract

The application discloses a kind of based on smart contract's construction method and system of carbon trading auction model, it is related to carbon trading technical field, including establishing event-b formalization model, formalization model is converted into solidity smart contract code by EB2S;Extract the key opcode sequence features of smart contract as the source code features of smart contract, use network model CapsNet-Att to detect vulnerabilities of smart contract;Based on smart contract, build carbon trading auction model.The construction method of carbon trading auction model based on smart contract provided in the application can effectively enhance the transparency and security of transaction due to the decentralization and programmability of the construction method of carbon trading auction model based on smart contract, removes intermediate links, eliminates the influence of human error, etc.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of carbon trading technology, specifically to a method and system for constructing a carbon trading auction model based on smart contracts. Background Technology

[0002] Carbon trading is a market mechanism adopted to reduce global greenhouse gas emissions, especially carbon dioxide. Under this mechanism, carbon dioxide emission rights are regarded as a commodity. Buyers use carbon trading platforms to pay a certain amount of money to sellers and obtain a certain number of carbon dioxide emission rights from sellers, thus completing a carbon dioxide emission rights transaction.

[0003] Currently, my country's carbon emission trading market still faces numerous problems. For example, the various pilot exchanges are relatively independent and separate, and their trading rules are not entirely consistent. Under traditional carbon trading models, information asymmetry and a lack of transparency are common. With the emergence of blockchain technology, its completely transparent mathematical algorithms—asymmetric encryption and consensus algorithms—make malicious alteration of data stored on the chain extremely costly and unprofitable, ensuring the immutability of data stored on the chain. Its application in various industries has attracted widespread attention. Due to the decentralized nature of blockchain technology, it can be well applied to existing applications requiring third-party regulatory bodies, reducing regulatory expenditures. The main difference between carbon emission trading and other physical commodity trading lies in the fact that the trading object, "quota," is an electronic agreement, a virtual product, while the blockchain stores immutable electronic information. Therefore, blockchain technology can be well applied to the design of carbon trading systems. A smart contract is a collection of code (logical description) and data (state representation). When predetermined conditions occur, a transaction is sent to the contract address, all nodes on the network execute the opcodes generated by the compiled contract script, and finally, the execution result is written to the blockchain. Therefore, smart contracts can be understood as all the business logic code that executes operations on the blockchain. To enhance the security and transparency of carbon trading auction models, this invention proposes a carbon trading auction model based on smart contracts and improves the generation and vulnerability detection methods of smart contracts, thereby increasing their reliability. Summary of the Invention

[0004] In view of the above-mentioned problems, the present invention is proposed.

[0005] Therefore, the technical problem solved by this invention is: existing carbon trading methods suffer from inconsistent trading rules, information asymmetry, independent and separate exchanges, and the problem of how to ensure the security of carbon trading as an electronic protocol.

[0006] To address the aforementioned technical problems, this invention provides the following technical solution: a method for constructing a carbon trading auction model based on smart contracts, comprising: establishing an event-b formal model; converting the formal model into Solidity smart contract code using EB2S; extracting key opcode sequence features of the smart contract as features of the smart contract source code; using the network model CapsNet-Att to perform vulnerability detection on the smart contract; and constructing a carbon trading auction model based on the smart contract.

[0007] As a preferred embodiment of the construction method of the carbon trading auction model based on smart contracts of the present invention, the formal model is transformed into Solidity smart contract code through EB2S, including constructing a formal model based on event-b based on the user's carbon trading needs, setting a constant EC through assignment operation transformation rules, and recording the value of the expression E' before assignment, represented as: In this context, the horizontal line represents the horizontal line operator, indicating a finite number of logical derivations P→q, where p is the antecedent and q is the consequent. The area above the horizontal line operator describes the antecedent, and the area below the horizontal line describes the consequent. Pred refers to the Pred operator, which calculates Solidity variables and statements transformed from Event-B variables or single statements. EB2S is the EB2S operator, representing the result of the operation obtained by transforming Event-B code through the EB2S transformation rule. assert indicates assertion on the magnitude statement in a function. EC is a defined constant that records the value of the expression E' before assignment.

[0008] As a preferred embodiment of the construction method of the carbon trading auction model based on smart contracts of the present invention, the extraction of key opcode sequence features of the smart contract includes compiling the Solidity source code into a bytecode sequence using the Solc compiler, and converting the bytecode sequence into an opcode sequence according to the conversion rules between bytecode and opcode in the Ethereum white paper.

[0009] As a preferred embodiment of the construction method of the carbon trading auction model based on smart contracts of the present invention, the extraction of key opcode sequence features of smart contracts further includes selecting the opcodes CALL and DELEGATECALL that are used with the external calling functions address.call and address.delegatecall. After selecting the key opcodes, the opcode sequence is reorganized, and the hyperparameters of the selected key opcodes are used as the context sequence of the key opcodes. If the context sequences of two adjacent key opcodes overlap, one context sequence is retained to obtain the key opcode sequence. The obtained key opcode sequence is input into the code embedding vector learning module, and each code fragment is embedded in a numerical vector of fixed dimensions to obtain the key opcode feature vector. The code embedding vector learning module uses the Continuous Bag-of-Words (CBOW) model as the code embedding learning model.

[0010] As a preferred embodiment of the construction method of the carbon trading auction model based on smart contracts of the present invention, the method of using the network model CapsNet-Att to perform vulnerability detection on smart contracts includes vulnerability detection through an improved capsule network module. Gao Jin's capsule network module includes convolutional layers, a main capsule layer, convolutional capsule layers, and fully connected capsule layers. The convolutional layers extract local features of the smart contract, while the main capsule layer and convolutional capsule layers extract the positional relationship between the local and the overall system. Assuming an iteration count of 1, the weight factors between the child and parent capsules are calculated. Represented as: Among them, b jli The iterative coupling coefficient represents the connection strength between the child capsule and the parent capsule, and the weighting factor of the child capsule within the parent capsule is calculated. , is represented as: Among them, b jli The iterative coupling coefficient, representing the connection strength of a child capsule within its parent capsule, is calculated by fusing two weighting factors in a dot product form and then using the Softmax function. The resulting coupling coefficient is expressed as: Each parent capsule v j It is the prediction vector The weighted sum is expressed as: in, This represents the probability of the parent capsule's existence. After generating all parent capsules, the coupling coefficient is updated, expressed as: After the update is completed, the features extracted by the capsule network module and the attention mechanism module are concatenated and used as the input of the fully connected layer. The output of the fully connected layer is fed into the Softmax classifier to obtain the vulnerability detection results.

[0011] As a preferred embodiment of the method for constructing a carbon trading auction model based on smart contracts according to the present invention, the carbon trading auction model based on smart contracts includes: the buyer organizing a bidding message containing timestamp, transaction sequence number, and bid amount fields, signing it with private key sk, and sending it to the seller; the seller receiving the latest round of bidding messages from the buyers, and if they approve the bid, signing the bidding message and broadcasting it to the buyers; after receiving the latest bid approved by the seller, if the seller continues to bid, they use a hash algorithm to obtain the hash value of the corresponding transaction from the previous bidding message, and then organize a bidding message containing timestamp, transaction sequence number, the hash value of the previous double-signed bidding message, and a bid amount higher than the previous double-signed bidding message, signing it with their own private key sk, and sending it to the seller; the seller receiving the latest round of bidding messages from the buyers, and if they approve one of the bids, signing the bidding message and broadcasting it to the buyers, until the auction ends.

[0012] As a preferred embodiment of the method for constructing a carbon trading auction model based on smart contracts according to the present invention, the construction of the carbon trading auction model based on smart contracts further includes, within the specified upload time set by the system, the emission-controlled enterprise acting as the seller records the latest double-signature bid message of this auction on the blockchain by calling the smart contract. The smart contract verifies the double signature contained in the bid information. When all signatures pass the verification, and no reports are made during the challenge period or the relevant departments determine that the auction result is invalid after processing, the smart contract is triggered to complete the transfer of funds and carbon emission credits and update the credit scores of both the buyer and seller.

[0013] Another objective of this invention is to provide a system for constructing a carbon trading auction model based on smart contracts. This system can consider the relationships within the parent capsule through an improved capsule network module, thus solving the problem that current carbon trading methods do not consider the relationships within the corresponding parent capsule, which leads to incorrect mappings during dynamic learning.

[0014] As a preferred embodiment of the construction system for the carbon trading auction model based on smart contracts of the present invention, the system includes: a code conversion module, a vulnerability detection module, and an auction model construction module; the code conversion module establishes an event-b formal model and converts the formal model into Solidity smart contract code using EB2S; the vulnerability detection module extracts the key opcode sequence features of the smart contract as features of the smart contract source code and uses the CapsNet-Att network model to perform vulnerability detection on the smart contract; the auction model construction module constructs a carbon trading auction model based on the smart contract.

[0015] A computer device, including a memory and a processor, wherein the memory stores a computer program and the processor executes the computer program, is a step in implementing a method for constructing a carbon trading auction model based on smart contracts.

[0016] A computer-readable storage medium having a computer program stored thereon, wherein the steps of a method for constructing a carbon trading auction model based on smart contracts are implemented when the computer program is executed by a processor.

[0017] The beneficial effects of this invention are as follows: The method for constructing a carbon trading auction model based on smart contracts provided by this invention effectively enhances the transparency and security of transactions due to its decentralization and programmability. Compared with traditional contract methods, it eliminates intermediate links and the impact of human error. The vulnerability detection method based on capsule networks and attention mechanisms avoids the weakening effect of extracting too many smart contract features, thus improving the security of smart contracts. Calculating the relationships within the parent capsule avoids errors in the mapping process. Therefore, this invention achieves better results in terms of both security and transparency. Attached Figure Description

[0018] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0019] Figure 1 The first embodiment of the present invention provides an overall flowchart of a method for constructing a carbon trading auction model based on smart contracts.

[0020] Figure 2 This is a schematic diagram of a smart contract generation method based on the event-b model, which is a method for constructing a carbon trading auction model based on smart contracts provided in the first embodiment of the present invention.

[0021] Figure 3 This is a schematic diagram of the internal structure of the EB2S tool, which is a method for constructing a carbon trading auction model based on smart contracts, as provided in the first embodiment of the present invention.

[0022] Figure 4 This is a schematic diagram of the smart contract conversion process for a method of constructing a carbon trading auction model based on smart contracts, provided in the first embodiment of the present invention.

[0023] Figure 5The flowchart illustrates the extraction of key opcode sequence features in a method for constructing a carbon trading auction model based on smart contracts, as provided in the first embodiment of the present invention.

[0024] Figure 6 The diagram shows the result of calling the Emissions contract data upload function of a method for constructing a carbon trading auction model based on smart contracts, as provided in the second embodiment of the present invention.

[0025] Figure 7 The diagram shows the result of calling the Emissions contract emission data report upload function of a method for constructing a carbon trading auction model based on smart contracts, as provided in the second embodiment of the present invention.

[0026] Figure 8 The image shows the result of uploading the Emissions contract verification report, which is part of a method for constructing a carbon trading auction model based on smart contracts, as provided in the second embodiment of the present invention.

[0027] Figure 9 The diagram shows the result of calling the function to publish auction information in a method for constructing a carbon trading auction model based on smart contracts, as provided in the second embodiment of the present invention.

[0028] Figure 10 The image shows the result of the registration and participation function call for a carbon trading auction model construction method based on smart contracts, provided in the second embodiment of the present invention.

[0029] Figure 11 The image shows the result of uploading auction results, which is part of a method for constructing a carbon trading auction model based on smart contracts, as provided in the second embodiment of the present invention.

[0030] Figure 12 The diagram shows the result of the function call for allocating carbon emission quotas in a method for constructing a carbon trading auction model based on smart contracts, as provided in the second embodiment of the present invention.

[0031] Figure 13 The diagram shows the result of calling the carbon emission quota collection function in a method for constructing a carbon trading auction model based on smart contracts, as provided in the second embodiment of the present invention.

[0032] Figure 14 The graph shows the execution time of the Emissions contract function, which is part of a method for constructing a carbon trading auction model based on smart contracts, as provided in the second embodiment of the present invention.

[0033] Figure 15 The graph shows the execution time of the Auction contract, a smart contract, in a method for constructing a carbon trading auction model based on smart contracts, as provided in the second embodiment of the present invention.

[0034] Figure 16 The graph shows the execution time of the Quota contract, a smart contract component, in a method for constructing a carbon trading auction model based on smart contracts, as provided in the second embodiment of the present invention.

[0035] Figure 17 The diagram shows the delay time of the Emissions contract, a smart contract component, in a method for constructing a carbon trading auction model based on smart contracts, as provided in the second embodiment of the present invention.

[0036] Figure 18 The diagram shows the delay time of the Auction contract, a smart contract, in a method for constructing a carbon trading auction model based on smart contracts, as provided in the second embodiment of the present invention.

[0037] Figure 19 The diagram shows the delay time of the Quota contract, a part of the smart contract, in a method for constructing a carbon trading auction model based on smart contracts, provided in the second embodiment of the present invention.

[0038] Figure 20 The following is an overall flowchart of a system for constructing a carbon trading auction model based on smart contracts, provided as a third embodiment of the present invention. Detailed Implementation

[0039] To make the above-mentioned objects, features, and advantages of the present invention more apparent and understandable, specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the protection scope of the present invention.

[0040] Example 1 Reference Figures 1-5 As an embodiment of the present invention, a method for constructing a carbon trading auction model based on smart contracts is provided, comprising: S1: Establish the event-b formal model and convert the formal model into Solidity smart contract code through EB2S.

[0041] Furthermore, a normal event can be transformed into two Solidity functions: a guard function to test whether the guard conditions for the corresponding event are met, and an execution function to execute the action for the corresponding event. The first case is when the event's guard conditions are not met, meaning the `run_evt` method cannot be executed. We define its postcondition as the value of variables in the contract cannot be changed. To determine whether variables in the contract have been modified, we define a `can_assign` function and two global array variables, G and G'. Since the number of global state variables in the contract is fixed, we can define an array G to store all global variables in the contract. G' represents G after a certain `run_evt` method. If the `run_evt` method did not modify the variable, then G = G'; otherwise, G ≠ G'. The second case is when the event's guard conditions are met, in which case the `run_evt` method is executed.

[0042] It should be noted that variables in Solidity are all value types, and their comparison operation uses the == symbol. Considering that the expression E after assignment may change, and the assigned variable should be equal to the assigned expression, this invention defines a constant EC to record the value of the expression E' before assignment. The formal model is transformed into Solidity smart contract code through EB2S, including building a formal model based on event-b based on the user's carbon trading needs. The constant EC is set through assignment operation transformation rules to record the value of the expression E' before assignment, expressed as: In this context, the horizontal line represents the horizontal line operator, indicating a finite number of logical derivations P→q, where p is the antecedent and q is the consequent. The area above the horizontal line operator describes the antecedent, and the area below the horizontal line describes the consequent. Pred refers to the Pred operator, which calculates Solidity variables and statements transformed from Event-B variables or single statements. EB2S is the EB2S operator, representing the result of the operation obtained by transforming Event-B code through the EB2S transformation rule. assert indicates assertion on the magnitude statement in a function. EC is a defined constant that records the value of the expression E' before assignment.

[0043] It should also be noted that the EB2S tool was developed using Java based on the EB2S conversion rules. The EB2S tool was developed using Java as a Rodin plugin and was tested and applied on Rodin version 3.5. Figure 3The overall architecture of the tool is shown. The EB2S tool calls the API provided by the Rodin platform to obtain elements from the Event-B machine, such as sets and constants. Then, by applying transformation rules, the corresponding Solidity contract file can be obtained. Rodin, as a platform developed based on Eclipse, consists of many plugins. Figure 3 The dashed rectangles represent plugins, such as editors, proof obligation generators, provers, model checking tools, and theorem provers. EB2S is a new plugin from Rodin that takes an Event-B model as input and transforms it into a Solidity contract.

[0044] Furthermore, the EB2S tool is implemented based on Rodin's plugin development model and is integrated into the Rodin platform as a plugin. Users need to install the Rodin platform and the EB2S plugin simultaneously. After installation, clicking the EB2S icon on the Rodin main view will open the plugin, which will bring up an interactive tool interface, such as... Figure 5 As shown, the tool displays the message "Please select an Event-B project for conversion." The tool automatically identifies all Event-B projects located in the Event-B Explorer. Users can select the project name to be converted via a drop-down menu, and then choose either "Convert All" or "Convert Partially." The former directly converts all machines and their referenced text within the entire project, while the latter provides a drop-down menu to specify the machines to be converted. After entering the specified project file, the tool generates a Solidity folder in the project's directory, containing the generated log files and Solidity contract files. The "Convert All" mode directly converts based on the machines obtained from the last refinement.

[0045] S2: Extract the key opcode sequence features of the smart contract as the source code features of the smart contract, and use the network model CapsNet-Att to detect vulnerabilities in the smart contract.

[0046] Furthermore, a mathematical model for feature extraction of key opcode sequences is constructed, and the flowchart of the mathematical model is as follows: Figure 4As shown, the mathematical model describes the process as follows: Solidity contract source code needs to be compiled before execution, resulting in a stack-based bytecode. The Ethereum Virtual Machine (EVM) is defined as a stack-based virtual machine that performs operations by interacting with the operand stack. Therefore, what is actually executed in the EVM is the previously compiled bytecode. The Ethereum white paper specifies the correspondence between byte values ​​and instruction types (i.e., opcodes), and also establishes rules for dividing opcodes and operation data. Each opcode specifies how many bytes of data it needs to operate on. For example, byte value 0x60 corresponds to opcode PUSH1, which requires operating on 1 byte of data, and byte value 0x61 corresponds to opcode PUSH2, which requires operating on 2 bytes of data.

[0047] It should be noted that extracting the key opcode sequence features of a smart contract involves using the Solc compiler to compile the Solidity source code into a bytecode sequence, and then converting the bytecode sequence into an opcode sequence according to the bytecode and opcode conversion rules in the Ethereum white paper.

[0048] It should also be noted that extracting key opcode sequence features from smart contracts also includes selecting the opcodes CALL and DELEGATECALL that are used with the external calling functions address.call and address.delegatecall. After selecting the key opcodes, the opcode sequence is reorganized, and the hyperparameters of opcodes before and after the selected key opcode are used as the context sequence of the key opcode. If the context sequences of two adjacent key opcodes overlap, one context sequence is retained to obtain the key opcode sequence. The obtained key opcode sequence is input into the code embedding vector learning module. Each code fragment is embedded in a numerical vector of fixed dimensions to obtain the key opcode feature vector. The code embedding vector learning module uses the Continuous Bag-of-Words (CBOW) model as the code embedding learning model.

[0049] Furthermore, the principles underlying the types of smart contract vulnerabilities are analyzed, and key opcodes related to the occurrence of vulnerabilities are selected. For example, an unchecked external call vulnerability exists. Solidity implements multiple external call functions to transfer Ether or call external contract functions. When these function calls encounter problems, such as not being called correctly, encountering network anomalies, or insufficient gas, they only return False without throwing an exception. If the caller does not verify the return value, it may lead to errors in the code execution logic, thus creating a vulnerability. The opcodes CALL and DELEGATECALL are related to the external call functions address.call() and address.delegatecall(), therefore they are selected as the critical opcodes. After selecting the critical opcodes, the opcode sequence needs to be reorganized. This involves using the n (n is a hyperparameter, to be determined experimentally) opcodes before and after the selected critical opcode as the context sequence. If the context sequences of two adjacent critical opcodes overlap, only one context sequence is retained, resulting in the final critical opcode sequence. Based on vulnerability analysis, this invention selects ADDRESS, BALANCE, ORIGIN, CALLER, CALLDATALOAD, DELEGATECALL, BLOCKHASH, TIMESTAMP, GASLIMIT, CALLVALUE, CALL, GAS, CALLCODE, GASPRICE, and SELFDESTRUCT as key opcodes. The obtained key opcode sequence is input into a code embedding vector learning module, where each code fragment is embedded into a fixed-dimensional numerical vector, ultimately yielding the key opcode feature vector. The code embedding vector learning module uses the Continuous Bag-of-Words (CBOW) model as the code embedding learning model and employs hierarchical softmax as a means to accelerate training and reduce the computational cost of training the CBOW model.

[0050] Furthermore, the capsule network module mainly includes convolutional layers, a main capsule layer, convolutional capsule layers, and fully connected capsule layers. The convolutional layers are used to extract local features of the smart contract, while the main capsule layer and convolutional capsule layers are used to extract the positional relationship between the local and global components. This invention improves the structure of the capsule network, with specific improvements as follows: Capsule networks utilize dynamic routing strategies to adjust the connections between each child capsule and its parent capsule, thereby achieving the goal of automatically learning the relationship between parts and the whole.

[0051] Assuming the number of iterations is 1, the dynamic routing algorithm process in each iteration is as follows: For each given prediction vector, in a traditional dynamic routing mechanism, the iterative coupling coefficient c for each connection strength is expressed as: Among them, b jliThis represents the coupling coefficient.

[0052] However, this method only measures the relationship between child capsules and parent capsules, without considering their relationships within the corresponding parent capsule. Therefore, incorrect mappings may occur during dynamic learning. To address this issue, this invention considers the relationships between child capsules and parent capsules.

[0053] Vulnerability detection of smart contracts using the CapsNet-Att network model includes vulnerability detection through an improved capsule network module; Gao Jin's capsule network module includes convolutional layers, a main capsule layer, convolutional capsule layers, and fully connected capsule layers. The convolutional layers extract local features of the smart contract, while the main capsule layer and convolutional capsule layers extract the positional relationship between the local and the overall system. Assuming an iteration count of 1, the weight factors between the child and parent capsules are calculated. Represented as: Among them, b jli The iterative coupling coefficient represents the connection strength between the child capsule and the parent capsule, and the weighting factor of the child capsule within the parent capsule is calculated. , is represented as: Among them, b jli The iterative coupling coefficient, representing the connection strength of a child capsule within its parent capsule, is calculated by fusing two weighting factors in a dot product form and then using the Softmax function. The resulting coupling coefficient is expressed as: Each parent capsule v j It is the prediction vector The weighted sum is expressed as: in, This represents the probability of the parent capsule's existence. After generating all parent capsules, the coupling coefficient is updated, expressed as: After the update is completed, the features extracted by the capsule network module and the attention mechanism module are concatenated and used as the input of the fully connected layer. The output of the fully connected layer is fed into the Softmax classifier to obtain the vulnerability detection results.

[0054] S3: Building a carbon trading auction model based on smart contracts.

[0055] Furthermore, the carbon trading auction model built on smart contracts includes a buyer organizing a bid message containing timestamp, transaction sequence number, and bid amount fields, signing it with their private key sk, and sending it to the seller. The seller receives the latest bid message from the buyer, and if they approve the bid, they sign the bid message and broadcast it to the buyer. After receiving the latest bid approved by the seller, if the seller continues to bid, they use a hash algorithm to obtain the hash value of the corresponding transaction from the previous bid message, then organize a bid message containing a timestamp, transaction sequence number, the hash value of the previous double-signed bid message, and a bid amount higher than the previous double-signed bid message, sign it with their own private key sk, and send it to the seller. The seller receives the latest bid messages from the buyer, and if they approve a bid, they sign the bid message and broadcast it to the buyer, until the auction ends.

[0056] It should be noted that building a carbon trading auction model based on smart contracts also includes, within the specified upload time set by the system, the emission-controlled enterprise acting as the seller records the latest double-signature bid message for this auction on the blockchain by calling the smart contract. The smart contract verifies the double signature contained in the bid information. When all signatures pass verification, and no reports are filed during the challenge period or the relevant departments determine that the auction result is invalid after handling, the smart contract is triggered to complete the transfer of funds and carbon emission credits and update the credit scores of both the buyer and seller.

[0057] If anyone believes the auction results are incorrect, they can report it to the relevant government department, providing the double-signed bid message containing the hash value of the last double-signed bid message as evidence. If the seller uploads an invalid or fraudulent bid message to the system, the government department will penalize the seller, and their deposit will be reduced. Similarly, the reporting party must also submit a deposit; if they cannot provide valid evidence, their deposit will be forfeited.

[0058] Example 2 Reference Figures 6-19 As an embodiment of the present invention, a method for constructing a carbon trading auction model based on smart contracts is provided. In order to verify the beneficial effects of the present invention, scientific demonstration is carried out through economic benefit calculation and simulation experiments.

[0059] Smart contracts are used to implement three functional modules of this system: carbon emission module, carbon trading module, and carbon emission quota management module. In the carbon emission module, the Emissions contract enables emission-controlled enterprises and third-party verification agencies to upload data, and government authorities to monitor the process. In the carbon trading module, the Auction contract enables emission-controlled enterprises to publish auction information, register for auctions, and upload auction results. In the carbon emission quota management module, the Quota contract enables government authorities to allocate carbon emission quotas and handle payment collection.

[0060] The smart contract code is written in the Solidity programming language; therefore, the online compiler Remix is ​​used to test the relevant functionalities of the smart contract. The tests include smart contract deployment and function calls. The functionalities to be tested and the expected goals are shown in Tables 1-3.

[0061] Table 1. Functionality Test Table for the Emissons Smart Contract

[0062] The following is a screenshot showing the results of some function calls in the Emissions contract. Figure 6 , 7 As shown in Figure 8. Figure 6 This demonstrates how emission-controlled enterprises upload the hash value and encrypted text of their emission data to a blockchain system via smart contracts. Figure 7 This demonstrates how emission-controlled enterprises upload encrypted emission data reports to a blockchain system via smart contracts. Figure 8 This demonstrates how a third-party verification agency uploads encrypted verification reports to a blockchain system via a smart contract. It's easy to see that the main determinant of the gas fee required for the upload function in the Emissions contract is the size of the uploaded data; as the input parameters increase, the gas consumption also increases.

[0063] Table 2. Functionality Test Table for the Smart Contract Auction

[0064] The results of some function calls in the Auction contract are shown in Figures 9, 10, and 11 below. Figure 9 shows how the controlling company publishes information such as the selling quota, starting price, and auction time to the blockchain system through a smart contract. Figure 10 The demonstration showed that companies subject to emission control measures could register to participate in the auction via smart contracts. Figure 11The demonstration showed that the controlling company initiating the auction uploads the final double-signature transaction and other auction information to the blockchain via a smart contract. The gas cost of registering to participate in the auction is the lowest, followed by publishing auction information, while the gas cost of uploading auction results is the highest. This is because uploading auction results requires two hash calculations and signature verifications, thus consuming more gas than other functions.

[0065] Table 3. Functionality Test Table for the Quota Smart Contract

[0066] The results of calling some functions of the Quota contract are shown in the image below. Figure 12 , 13 As shown. Figure 12 This demonstrates how government authorities allocate carbon emission allowances to controlled-emission enterprises through smart contracts. Figure 13 This demonstrates how emission-controlled enterprises can settle their carbon emission allowances via smart contracts. The allocation and settlement of carbon emission allowances only involve modifying state variables in the Quota contract, so the gas consumption is around 30,000 to 50,000.

[0067] Example 3 Reference Figure 20 As an embodiment of the present invention, a system for constructing a carbon trading auction model based on smart contracts is provided, including a code conversion module, a vulnerability detection module, and an auction model construction module. The code conversion module establishes an event-b formal model and converts it into Solidity smart contract code using EB2S; the vulnerability detection module extracts key opcode sequence features of the smart contract as features of the smart contract source code and uses the CapsNet-Att network model to detect vulnerabilities in the smart contract; and the auction model construction module builds a carbon trading auction model based on the smart contract.

[0068] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0069] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-including system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device.

[0070] More specific examples (a non-exhaustive list) of computer-readable media include: electrical connections (electronic devices) having one or more wires, portable computer disk drives (magnetic devices), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Furthermore, computer-readable media can even be paper or other suitable media on which programs can be printed, because programs can be obtained electronically, for example, by optically scanning the paper or other media, followed by editing, interpreting, or otherwise processing as necessary, and then stored in computer memory.

[0071] It should be understood that various parts of the present invention can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc. It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.

[0072] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.

Claims

1. A method for constructing a carbon trading auction model based on smart contracts, characterized in that, include: Establish a formal model of event-b, and transform the formal model into Solidity smart contract code through EB2S; The key opcode sequence features of smart contracts are extracted as features of smart contract source code, and the CapsNet-Att network model is used to detect vulnerabilities in smart contracts. A carbon trading auction model is built based on smart contracts.

2. The method for constructing a carbon trading auction model based on smart contracts as described in claim 1, characterized in that: The formal model is transformed into Solidity smart contract code using EB2S. This includes building a formal model based on event-b based on user carbon trading needs, setting a constant EC through assignment operations and recording the value of the expression E' before assignment, represented as: In this context, the horizontal line represents the horizontal line operator, indicating a finite number of logical derivations P→q, where p is the antecedent and q is the consequent. The area above the horizontal line operator describes the antecedent, and the area below the horizontal line describes the consequent. Pred refers to the Pred operator, which calculates Solidity variables and statements transformed from Event-B variables or single statements. EB2S is the EB2S operator, representing the result of the operation obtained by transforming Event-B code through the EB2S transformation rule. assert indicates assertion on the magnitude statement in a function. EC is a defined constant that records the value of the expression E' before assignment.

3. The method for constructing a carbon trading auction model based on smart contracts as described in claim 2, characterized in that: Extracting key opcode sequence features from smart contracts involves compiling Solidity source code into a bytecode sequence using the Solc compiler, and then converting the bytecode sequence into an opcode sequence according to the bytecode-opcode conversion rules in the Ethereum white paper.

4. The method for constructing a carbon trading auction model based on smart contracts as described in claim 3, characterized in that: Extracting key opcode sequence features from smart contracts also includes selecting the opcodes CALL and DELEGATECALL that are used with external call functions address.call and address.delegatecall. After selecting the key opcodes, the opcode sequence is reorganized, and the hyperparameters of opcodes before and after the selected key opcode are used as the context sequence of the key opcode. If the context sequences of two adjacent key opcodes overlap, one context sequence is retained to obtain the key opcode sequence. The obtained key opcode sequence is input into the code embedding vector learning module. Each code fragment is embedded in a fixed-dimensional numerical vector to obtain the key opcode feature vector. The code embedding vector learning module uses the Continuous Bag-of-Words (CBOW) model as the code embedding learning model.

5. The method for constructing a carbon trading auction model based on smart contracts as described in claim 4, characterized in that: Vulnerability detection of smart contracts using the CapsNet-Att network model includes vulnerability detection through an improved capsule network module; Gao Jin's capsule network module includes convolutional layers, a main capsule layer, convolutional capsule layers, and fully connected capsule layers. The convolutional layers extract local features of the smart contract, while the main capsule layer and convolutional capsule layers extract the positional relationship between the local and the overall system. Assuming an iteration count of 1, the weight factors between the child and parent capsules are calculated. Represented as: Among them, b jli The iterative coupling coefficient represents the connection strength between the child capsule and the parent capsule, and the weighting factor of the child capsule within the parent capsule is calculated. , is represented as: Among them, b jli The iterative coupling coefficient, representing the connection strength of a child capsule within its parent capsule, is calculated by fusing two weighting factors in a dot product form and then using the Softmax function. The resulting coupling coefficient is expressed as: Each parent capsule v j It is the prediction vector The weighted sum is expressed as: in, This represents the probability of the parent capsule's existence. After generating all parent capsules, the coupling coefficient is updated, expressed as: After the update is completed, the features extracted by the capsule network module and the attention mechanism module are concatenated and used as the input of the fully connected layer. The output of the fully connected layer is fed into the Softmax classifier to obtain the vulnerability detection results.

6. The method for constructing a carbon trading auction model based on smart contracts as described in claim 5, characterized in that: The carbon trading auction model built on smart contracts involves the buyer organizing a bid message containing timestamp, transaction number, and bid amount fields, signing it with their private key sk, and sending it to the seller. The seller receives the latest bid message from the buyer, and if they approve the bid, they sign the bid message and broadcast it to the buyer. After receiving the latest bid approved by the seller, if the seller continues to bid, they use a hash algorithm to obtain the hash value of the corresponding transaction from the previous bid message, then organize a bid message containing a timestamp, transaction number, the hash value of the previous double-signed bid message, and a bid amount higher than the previous double-signed bid message, sign it with their own private key sk, and send it to the seller. The seller receives the latest bid messages from the buyer, and if they approve one of the bids, they sign the bid message and broadcast it to the buyer, until the auction ends.

7. The method for constructing a carbon trading auction model based on smart contracts as described in claim 6, characterized in that: The carbon trading auction model based on smart contracts also includes the following: within the specified upload time set by the system, the emission-controlled enterprise acting as the seller records the latest double-signature bid message of this auction on the blockchain by calling the smart contract. The smart contract verifies the double signature contained in the bid information. When all signatures pass the verification and no reports are made during the challenge period or the relevant departments determine that the auction result is invalid after handling, the smart contract is triggered to complete the transfer of funds and carbon emission credits and update the credit scores of both the buyer and seller.

8. A system employing the method for constructing a carbon trading auction model based on smart contracts as described in any one of claims 1 to 7, characterized in that: Includes a code conversion module, a vulnerability detection module, and an auction model construction module; The code conversion module establishes an event-b formal model and then uses EB2S to convert the formal model into Solidity smart contract code. The vulnerability detection module is used to extract key opcode sequence features of smart contracts as features of smart contract source code, and uses the network model CapsNet-Att to detect vulnerabilities in smart contracts. The auction model building module constructs carbon trading auction models based on smart contracts.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, The steps of constructing a carbon trading auction model based on any one of claims 1 to 7 when the processor executes a computer program.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, The steps of constructing a carbon trading auction model based on a smart contract, as described in any one of claims 1 to 7, are implemented when the computer program is executed by a processor.