Block chain transaction method and device, electronic equipment and computer program product

By setting decoy slippage in blockchain transactions and using proxy contracts to detect transaction risks, the problem of property loss caused by malicious sandwich attacks is solved, and the security and success rate of transactions are improved.

CN121389110APending Publication Date: 2026-01-23HANGZHOU HIGH-TECH ZONE (BINJIANG) INSTITUTE OF BLOCKCHAIN & DATA SECURITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511274305.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-08
Publication Date
2026-01-23

AI Technical Summary

Technical Problem

In blockchain transactions, there is a risk of malicious sandwich attacks that could lead to financial losses for the transacting parties, and existing technologies are unable to effectively prevent such attacks.

Method used

By setting decoy slippage for transactions and using proxy contracts to execute transactions, the actual slippage can be determined, transaction risks can be detected, and transactions can be processed based on the detection results, including rollback or on-chain operations, thereby reducing the risk of malicious attacks.

Benefits of technology

It effectively reduces the risk of financial loss for trading parties during transaction execution, decreases the probability of successful attacks by malicious traders, and improves transaction security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121389110A_ABST
    Figure CN121389110A_ABST
Patent Text Reader

Abstract

The invention discloses a block chain transaction method and apparatus, an electronic device and a computer program product, when a target transaction carrying a first sliding point is received, a bait sliding point is set for the target transaction, the first sliding point is a sliding point set by a user for the target transaction, and the target transaction is executed based on a proxy contract. The method comprises the steps of obtaining a bait sliding point, determining an actual transaction sliding point for executing a target transaction, detecting a transaction risk of the target transaction according to the actual transaction sliding point and the bait sliding point to obtain a detection result, and processing the target transaction based on the detection result so as to detect whether the target transaction has the transaction risk based on the bait sliding point. And the target transaction is processed based on the detection result of the transaction risk, so that the situation that the transaction is attacked by a malicious trader when the transaction is carried out under the condition that the transaction risk exists is reduced, and the risk that the property is lost when the transaction party executes the transaction is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application belongs to the technical field of blockchain and data processing, and particularly relates to a transaction method and device of a blockchain, an electronic device, and a computer program product. BACKGROUND

[0002] A blockchain is a distributed ledger that combines data blocks in the form of a chain, has characteristics such as decentralization and non-tampering, and guarantees the authenticity and security of data in the blockchain.

[0003] When a transaction is performed in a blockchain, a malicious sandwich attack may occur, resulting in loss of user property. How to avoid a sandwich attack during a transaction is a problem that needs to be solved. SUMMARY

[0004] Embodiments of the present application provide a transaction method and device of a blockchain, an electronic device, and a computer program product, aiming to solve the problem of property loss risk in existing block transactions.

[0005] In a first aspect, embodiments of the present application provide a transaction method of a blockchain, which includes:

[0006] When a target transaction carrying a first sliding point is received, a decoy sliding point is set for the target transaction; wherein the first sliding point is a sliding point set by a user for the target transaction;

[0007] The target transaction is executed based on a proxy contract, and an actual transaction sliding point of executing the target transaction is determined;

[0008] According to the actual transaction sliding point and the decoy sliding point, a transaction risk of the target transaction is detected, and a detection result is obtained;

[0009] Based on the detection result, the target transaction is processed.

[0010] In a possible implementation manner of the first aspect, according to the actual transaction sliding point and the decoy sliding point, the transaction risk of the target transaction is detected, and the detection result is obtained, which includes:

[0011] According to the first sliding point and the decoy sliding point, a risk sliding point range is determined;

[0012] When the actual transaction sliding point is in the risk sliding point range, it is determined that the detection result is that the target transaction has a transaction risk;

[0013] When the actual transaction sliding point is less than the minimum value of the risk sliding point range, it is determined that the detection result is that the target transaction does not have a transaction risk.

[0014] In a possible implementation manner of the first aspect, the determining the risk slippage range according to the first slippage point and the decoy slippage point comprises:

[0015] determining a maximum slippage point according to the first slippage point and the decoy slippage point, wherein the maximum slippage point is a sum of the first slippage point and the decoy slippage point;

[0016] determining the risk slippage range according to the maximum slippage point and the first slippage point, wherein a minimum value of the risk slippage range is the first slippage point, and a maximum value of the risk slippage range is the maximum slippage point.

[0017] In a possible implementation manner of the first aspect, the processing the target transaction based on the detection result comprises:

[0018] when the detection result indicates that the target transaction has a transaction risk, rolling back the target transaction;

[0019] when the detection result indicates that the target transaction has no transaction risk, uploading the target transaction to a chain.

[0020] In a possible implementation manner of the first aspect, the target transaction is a transaction in which a transaction party exchanges a first digital currency for a second digital currency, and the detection result indicating that the target transaction has a transaction risk when the actual transaction slippage point is in the risk slippage range comprises:

[0021] obtaining a historical transaction, wherein the historical transaction is a transaction in which a historical transaction party exchanges the first digital currency for the second digital currency in a historical time period;

[0022] determining a historical slippage point after the historical transaction is executed;

[0023] when the historical slippage point is in the risk slippage range and the actual transaction slippage point is in the risk slippage range, determining that the detection result indicates that the target transaction has a transaction risk.

[0024] In a possible implementation manner of the first aspect, the determining the historical slippage point after the historical transaction is executed comprises:

[0025] determining a first exchange ratio of the historical transaction, wherein the first exchange ratio is a ratio of the first digital currency to the second digital currency in the historical transaction;

[0026] determining a second exchange ratio of the first digital currency to the second digital currency after the historical transaction is executed according to a transaction quantity of the historical transaction, wherein the transaction quantity is a quantity of the first digital currency paid for the second digital currency in the historical transaction.

[0027] determine a historical slippage after the historical transaction is executed according to the first exchange ratio and the second exchange ratio. In a possible implementation manner of the first aspect, the executing the target transaction based on the proxy contract comprises:

[0028] determining the first slippage in the target transaction based on the proxy contract, and sending the first slippage to a smart contract, so that the smart contract executes the target transaction according to the first slippage; wherein the smart contract is configured to execute a transaction, and the proxy contract is configured to detect a transaction risk.

[0029] In a second aspect, an embodiment of the present application provides a transaction device of a block chain, the device comprising:

[0030] a setting module configured to set a decoy slippage for a target transaction when the target transaction carrying a first slippage is received; wherein the first slippage is a slippage set by a user for the target transaction;

[0031] a determining module configured to execute the target transaction based on a proxy contract, and determine an actual transaction slippage of the target transaction;

[0032] a detecting module configured to detect a transaction risk of the target transaction according to the actual transaction slippage and the decoy slippage, and obtain a detection result;

[0033] a processing module configured to process the target transaction based on the detection result.

[0034] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor executes the computer program to implement the transaction method of the block chain provided in the first aspect.

[0035] In a fourth aspect, an embodiment of the present application provides a computer program product, comprising a computer program, and when the computer program is executed on a computer, the computer program causes the computer to execute the transaction method of the block chain provided in the first aspect.

[0036] In a fifth aspect, an embodiment of the present application provides a computer readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the computer program implements the transaction method of the block chain provided in the first aspect.

[0037] It can be understood that the beneficial effects of the second aspect to the fifth aspect can be referred to the related description in the first aspect, and will not be repeated here.

[0038] Compared with the prior art, the embodiments of the present application have the beneficial effects that:

[0039] In the embodiments of the present application, when a target transaction carrying a first slip point is received, a decoy slip point is set for the target transaction, the first slip point is a slip point set by a user for the target transaction, the target transaction is executed based on a proxy contract, an actual transaction slip point of executing the target transaction is determined, a transaction risk of the target transaction is detected according to the actual transaction slip point and the decoy slip point, a detection result is obtained, and the target transaction is processed based on the detection result, so that whether the target transaction has a transaction risk can be detected based on the decoy slip point, and the target transaction is processed based on the detection result of the transaction risk, thereby reducing the case that the transaction is attacked by a malicious transactor in the case that the transaction has a transaction risk, and reducing the risk that the property of a transaction party is lost when the transaction is executed. BRIEF DESCRIPTION OF DRAWINGS

[0040] Figure 1 is a step flow chart of a transaction method of a block chain provided by an embodiment of the present application;

[0041] Figure 2 is a step flow chart of another transaction method of a block chain provided by an embodiment of the present application;

[0042] Figure 3 is a structural schematic diagram of a transaction device of a block chain provided by an embodiment of the present application;

[0043] Figure 4 is a structural block diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION

[0044] In order to make the technical problems, technical solutions and beneficial effects of the present application clearer, the present application will be further described in detail below in combination with the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and do not limit the present application.

[0045] As mentioned above, there may be a malicious sandwich attack when a transaction is made in the blockchain. For example, a transaction in the blockchain usually involves the exchange between two digital currencies, and the content of the transaction usually includes information such as the exchange ratio between the digital currencies. During the exchange between the two digital currencies, there may be a malicious sandwich attack. For example, in an actual transaction, a transaction party proposes a transaction of exchanging the required digital currency at a desired ratio, such as a transaction of exchanging 10 token A for 1 token B, and broadcasts the transaction to the blockchain. Each node in the blockchain can obtain the right to package the transaction based on a competition mechanism, which can be a mechanism such as proof of work, proof of stake, etc. When any node in the blockchain obtains the right to package the transaction, the node can verify and execute the transaction, and when executing the transaction, if the exchange ratio of the related digital currencies in the blockchain meets the desired ratio of the transaction party, the transaction is executed, i.e. the transaction is successful, otherwise, the execution of the transaction is interrupted, resulting in a failed transaction.

[0046] Since the exchange ratio of the digital currencies in the blockchain changes in real time, the actual exchange ratio of the digital currencies when the transaction is executed may be different from the desired ratio of the transaction party, resulting in a low probability of successful transaction. For example, the transaction party proposes a transaction of exchanging 10 token A for 1 token B, however, when executing the transaction proposed by the transaction party, since there is a transaction of exchanging token A for token B before the transaction, the number of token A and token B in the liquidity pool of the blockchain changes, thereby changing the exchange ratio of token A for token B, so that the transaction party can only exchange 0.8 token B for 10 token A, which is different from the desired exchange ratio of the transaction party, thereby resulting in a failed transaction.

[0047] Therefore, the transaction party can determine the range of the exchange ratio that can be traded in the actual transaction by setting a desired ratio range, and then execute the transaction when the actual exchange ratio of the digital currencies in the actual transaction is within the desired ratio range; or set a slippage to determine the maximum deviation between the actual exchange ratio and the desired exchange ratio of the transaction party based on the set slippage, and then execute the transaction when the deviation between the actual exchange ratio of the digital currencies in the actual transaction and the desired exchange ratio of the transaction party is less than the maximum deviation. In this way, the interruption of executing the transaction can be reduced and the success rate of the transaction can be improved in the case that the exchange ratio of the digital currencies changes in real time.

[0048] For example, the transaction party can set the slippage as 20%, i.e., the maximum deviation between the actual exchange ratio and the expected exchange ratio is allowed to be 20%. For example, when the transaction party expects the exchange ratio to be: 10 token A exchanges 1 token B, the actual exchange ratio allowed by the transaction party is: 10 token A exchanges 1*(100%-20%) token B, i.e., the actual exchange ratio allowed by the transaction party is: 10 token A exchanges 0.8 token B. In the actual transaction process, the actual exchange ratio of token A to token B is 10 token A exchanges 0.7 token B, and it can be determined that the deviation between the actual exchange ratio and the expected exchange ratio is 30%, which is greater than the maximum deviation allowed by the set slippage, and the transaction is interrupted. In the case of the actual exchange ratio of 10 token A exchanges 0.9 token B, it can be determined that the deviation between the actual exchange ratio and the expected exchange ratio is 10%, which is less than the maximum deviation allowed by the set slippage, and the transaction is executed.

[0049] However, by setting the expected ratio range to execute the transaction, there is a risk that malicious traders will attack the transaction and cause the property loss of the transaction party, specifically, malicious traders exchange the digital currency required by the transaction party at a lower exchange ratio, and trade with the transaction party at the maximum exchange ratio set by the transaction party, causing the transaction party to always trade at the maximum exchange ratio set, and cannot trade at the normal exchange ratio, which poses a risk of property loss to the transaction party.

[0050] Specifically, the malicious trader can be a node in the blockchain that illegally arbitrages by maliciously inserting transactions to intentionally raise or lower the exchange ratio of the digital currency, i.e., an attack party that attacks the target transaction.

[0051] It should be understood that when the transaction party submits a transaction and broadcasts the submitted transaction to the blockchain, any node in the blockchain can store the transaction in the local memory pool, and then each node can select the transaction needed to be packaged by accessing the local memory pool, and obtain the right to package the transaction through the competition mechanism. When the node accesses the local memory pool, it can determine each transaction stored in the memory pool and determine the slippage set by each transaction.

[0052] Specifically, when the node accesses the local memory pool and retrieves a transaction with a large slippage, the attacker can construct a pre-transaction and a post-transaction for the transaction. The pre-transaction can be a transaction with a gas fee higher than that of the transaction submitted by the transaction party, and the pre-transaction is a transaction that, after execution, increases the exchange ratio of digital currency in the blockchain and the exchange ratio of the digital currency after the increase is still within the maximum deviation allowed by the transaction party. The post-transaction can be a transaction that exchanges the digital currency obtained by the pre-transaction for other digital currency at a higher exchange ratio, and the gas fee can be the transaction fee for executing the transaction. After constructing the pre-transaction and the post-transaction, the node can sort and pack the transactions in the memory pool based on the size of the gas fee, so that the pre-transaction can be executed before the transaction submitted by the transaction party, thereby obtaining the digital currency required by the transaction party at a lower exchange ratio and increasing the exchange ratio of the digital currency required by the transaction party. When the transaction submitted by the transaction party is executed, the transaction party is forced to trade at a higher exchange ratio, and after the transaction submitted by the transaction party is executed, the exchange ratio of the digital currency obtained by the transaction party also increases, and thus when the post-transaction is executed subsequently, the post-transaction can exchange the digital currency obtained by the pre-transaction for more other digital currency at a higher exchange ratio, thereby obtaining a profit. However, the transaction party can normally trade at a normal exchange ratio, but in this case, the transaction party is forced to trade at a higher exchange ratio, resulting in a loss of property.

[0053] For example, the liquidity pool of the blockchain includes 1000 token A and 100 token B, a transaction party proposes a transaction a of 10 token A for 1 token B, and sets a slippage of 50%. When the attacker detects the transaction and considers that the transaction is profitable, the attacker constructs a pre-transaction and a post-transaction, wherein the pre-transaction is a transaction of 24 token A for 2.4 token B, and the post-transaction can be a transaction of 2.4 token B for 25.7 token A. After executing the pre-transaction, the exchange ratio of token A for token B in the blockchain becomes 10.5 token A for 1 token B. In this case, the transaction a is executed, and the deviation between the exchange ratio in this case and the exchange ratio expected by the transaction party is 50%, which is within the maximum deviation allowed by the transaction party, so the transaction party exchanges 10.5 token A for 1 token B, and the exchange ratio of token A for token B in the blockchain becomes 10.7 token A for 1 token B. After executing the transaction a, the post-transaction is executed at the exchange ratio of 10.71 token A for 1 token B, i.e., the 2.4 token B obtained by the pre-transaction is exchanged for 25.7 token A, and the attacker can obtain a profit of 1.7 token A, while the transaction party can exchange 10 token A for 1 token B without being attacked by the attacker, and finally needs to spend 0.5 token A more to exchange 1 token B, or can exchange only 0.95 token B with 10 token A, resulting in a loss of property of the transaction party.

[0054] Based on this, the application provides a blockchain transaction method and device, electronic equipment and computer program product. When a target transaction carrying a first slippage is received, a decoy slippage is set for the target transaction, the first slippage is a slippage set by a user for the target transaction, the target transaction is executed based on a proxy contract, and an actual transaction slippage of the target transaction is determined. According to the actual transaction slippage and the decoy slippage, the transaction risk of the target transaction is detected to obtain a detection result. Based on the detection result, the target transaction is processed, so that whether the target transaction has a transaction risk can be detected based on the decoy slippage, and the target transaction is processed based on the detection result of the transaction risk, reducing the case that the transaction is attacked by a malicious transactioner when the transaction is performed in the case that the transaction has a transaction risk, and reducing the risk that the property of the transaction party is lost when the transaction is performed.

[0055] Referring to Figure 1 , Figure 1A step flowchart of a transaction method of a blockchain is shown, which can include the following steps:

[0056] S101, when receiving a target transaction carrying a first slippage, setting a decoy slippage for the target transaction.

[0057] The first slippage can be a slippage set by a user for a target transaction. The slippage can be represented as a deviation between an actual exchange ratio of a digital currency and an expected exchange ratio expected by the user. The first slippage can be represented as a maximum deviation between the actual exchange ratio and the expected exchange ratio set by the user for the target transaction. The user can be a transaction party proposing the target transaction. The transaction party can be any node in the blockchain. The target transaction can be a transaction in which the transaction party exchanges a first digital currency for a second digital currency. The first digital currency and the second digital currency can be different types of digital currencies stored in a liquidity pool of the blockchain. Specifically, the first digital currency is any type of digital currency in the blockchain, and the second digital currency is a digital currency of a type different from that of the first digital currency. A digital currency can be represented as a digital asset proof based on a distributed ledger, i.e., a proof of ownership of a digital asset in the blockchain. Different types of digital currencies have different exchange ratios, and the specific exchange ratio depends on the total value of the digital currencies stored in the liquidity pool of the blockchain. The actual exchange ratio can be the exchange ratio of the first digital currency for the second digital currency when the target transaction is executed. The expected exchange ratio can be the exchange ratio of the first digital currency for the second digital currency expected by the transaction party. The decoy slippage can be a slippage set for a sandwich attack. The sandwich attack can be an attack by an attacker on the target transaction, specifically, the attacker maliciously creates a pre-transaction to raise the actual exchange ratio of the target transaction.

[0058] In actual application, when any node in the blockchain needs to exchange a first digital currency for a second digital currency at an expected exchange ratio, the node can construct the transaction, i.e., the transaction party can construct the target transaction and set a first slippage for the target transaction to improve the success rate of the target transaction. Before broadcasting the target transaction to other nodes in the blockchain, a decoy slippage for preventing a sandwich attack can be set for the target transaction.

[0059] As an example, after the transaction party constructs the target transaction, the transaction party can set a decoy slippage for the target transaction based on its own needs.

[0060] As another example, after detecting that the transaction party has constructed the target transaction, a decoy slippage corresponding to the size of the first slippage in the target transaction can be set.

[0061] In a specific implementation, different ranges of the slide point interval can be preset, and different slide point intervals correspond to different decoy slide points. Then, after determining the first slide point of the target transaction, the range of the first slide point can be determined, and the decoy slide point corresponding to the range is the decoy slide point of the target transaction. For example, the slide point interval A, the slide point interval B, and the slide point interval C can be preset, where the slide point interval A is a range of [0, 5%], the slide point interval B is a range of [5%, 10%], and the slide point interval C is a range of [10, 15%]. The decoy slide point corresponding to the slide point interval A is 5%, the decoy slide point corresponding to the slide point interval B is 10%, and the decoy slide point corresponding to the slide point interval C is 15%. When the first slide point is 10%, it can be determined that the first slide point is in the range corresponding to the slide point interval C, and the decoy slide point corresponding to the slide point interval C is set for the target transaction, that is, the decoy slide point of the target transaction is set to 15%.

[0062] Specifically, at least two different ranges of the slide point interval can be set based on experience, and the decoy slide point corresponding to each slide point interval can be determined.

[0063] S102, executing the target transaction based on the agent contract, and determining an actual transaction slide point of the target transaction.

[0064] The agent contract can be used to detect whether the target transaction has a transaction risk, and the actual transaction slide point can be a slide point of the target transaction in actual execution.

[0065] After the transaction party builds the target transaction, the agent contract can be used to execute the target transaction, and the actual transaction slide point of the target transaction can be determined.

[0066] In an embodiment of the present application, S102 can include the following steps:

[0067] The first slide point in the target transaction is determined based on the agent contract, and the first slide point is sent to the smart contract, so that the target transaction is executed based on the smart contract according to the first slide point.

[0068] The smart contract can be used to execute the transaction.

[0069] After the transaction party builds the target transaction, the target transaction can be broadcast in the blockchain. The nodes in the blockchain can compete for the right to package the target transaction, and after obtaining the right to package the transaction, the first slide point in the target transaction can be determined by using the agent contract preset in advance, and the first slide point is sent to the smart contract. Then, the target transaction can be executed by using the smart contract with the first slide point, so that the actual transaction slide point of the target transaction can be determined by using the agent contract.

[0070] In actual application, after the transaction party builds a target transaction and sets the first slippage and the decoy slippage, the target transaction can be encoded, i.e., the transaction content including the first slippage and the decoy slippage is encoded, and then the encoded data is broadcasted. The node in the block chain for packaging the target transaction can decode the encoded data based on the preset proxy contract, and identify the first slippage set in the target transaction, so as to send the first slippage to the smart contract to execute the target transaction according to the first slippage based on the smart contract in the case of identifying the first slippage of the target transaction.

[0071] It should be understood that the proxy contract can be used to detect the transaction risk of the target transaction, specifically, the first slippage and the decoy slippage in the target transaction are identified through the proxy contract, and then the transaction risk of the target transaction is detected based on the first slippage and the decoy slippage. If there is no proxy contract set in advance, only the smart contract for executing the target transaction is used to execute the target transaction, the first slippage and the decoy slippage in the target transaction cannot be identified, and then the target transaction is directly executed using the first slippage and the decoy slippage set in the target transaction, so that the actual transaction slippage of actually executing the target transaction is the sum of the first slippage and the decoy slippage.

[0072] S103, detecting the transaction risk of the target transaction according to the actual transaction slippage and the decoy slippage, and obtaining a detection result.

[0073] The detection result can be a result of detecting whether the target transaction has a transaction risk, and can specifically include a detection result that the target transaction has a transaction risk and a detection result that the target transaction has no transaction risk.

[0074] After the actual transaction slippage is determined, the transaction risk of the target transaction can be detected according to the actual transaction slippage and the decoy slippage, and a detection result of whether the target transaction has a transaction risk is determined.

[0075] In an embodiment of the present application, S103 can include steps S1031 to S1033:

[0076] S1031, determining a risk slippage range according to the first slippage and the decoy slippage.

[0077] The risk slippage range can be a range of slippages with transaction risks.

[0078] After the first slippage and the decoy slippage in the target transaction are identified, the range of slippages with transaction risks can be determined according to the first slippage and the decoy slippage, and a risk slippage range is obtained.

[0079] In an embodiment of the present application, S1031 can include the following steps:

[0080] According to the first slippage and the decoy slippage, a maximum slippage is determined, and according to the maximum slippage and the first slippage, a risk slippage range is determined.

[0081] The maximum slippage can be the sum of the first slippage and the decoy slippage, the minimum value of the risk slippage range is the first slippage, and the maximum value of the risk slippage range is the maximum slippage.

[0082] After identifying the first slippage and the decoy slippage in the target transaction, the first slippage and the decoy slippage can be summed to obtain the sum of the first slippage and the decoy slippage, i.e., the maximum slippage. After determining the maximum slippage, the risk slippage range can be determined according to the maximum slippage and the first slippage, i.e., taking the maximum slippage as the maximum value of the risk slippage range and taking the first slippage as the minimum value of the risk slippage range.

[0083] S1032, when the actual transaction slippage is in the risk slippage range, it is determined that the detection result is that the target transaction has a transaction risk.

[0084] After obtaining the risk slippage range, the actual transaction slippage can be compared with the risk slippage range. When the actual transaction slippage is in the risk slippage range, it can be determined that the detection result is that the target transaction has a transaction risk.

[0085] It should be understood that the attacker will retrieve profitable transactions, i.e., transactions with a larger slippage setting, by accessing the local memory pool of the node, and construct pre-transaction and post-transaction for the transactions with a larger slippage setting.

[0086] Specifically, the attacker will simulate the execution of transactions stored in the local memory pool of the node through the smart contract, derive the slippage set by each transaction, determine the deviation between the slippage of each transaction and the actual execution slippage at the current time, and determine the profitable transaction based on the deviation, i.e., determine the transaction with a deviation greater than a preset deviation as a profitable transaction.

[0087] However, since the first slippage and the decoy slippage are set in the target transaction, the smart contract cannot identify the first slippage and the decoy slippage in the target transaction. When the target transaction is executed by using the smart contract, the smart contract executes the target transaction by combining all the slippages set in the target transaction, and thus the slippage derived by the attacker on this basis is the slippage obtained by combining the first slippage and the decoy slippage in the target transaction, which is generally the sum of the first slippage and the decoy slippage. The sum of the first slippage and the decoy slippage is usually greater than the actually executed slippage, and thus the attacker can determine that the target transaction is a profitable transaction, and construct a pre-transaction that can increase the exchange ratio of the first digital currency for the second digital currency in the blockchain to exchange the second digital currency, so that the exchange ratio of the first digital currency for the second digital currency in the blockchain after the exchange is increased, and the deviation between the exchange ratio of the first digital currency for the second digital currency in the blockchain after the increase and the expected exchange ratio of the target transaction is still less than the sum of the first slippage and the decoy slippage in the target transaction. When the target transaction is executed under the condition that the exchange ratio of the first digital currency for the second digital currency in the blockchain is increased, the first slippage and the decoy slippage of the target transaction are identified by the proxy contract, and when the actually executed slippage is greater than the first slippage and less than the sum of the first slippage and the decoy slippage, it can be considered that there is no pre-transaction for the target transaction before the target transaction, that is, it can be determined that the probability of the target transaction being sandwiched is relatively high, and that there is a transaction risk.

[0088] S1033, when the actually executed slippage is less than the minimum value of the risk slippage range, it is determined that the detection result is that the target transaction has no transaction risk.

[0089] When the actually executed slippage is less than the minimum value of the risk slippage range, it can be considered that there is no pre-transaction for the target transaction before the target transaction, that is, it can be determined that the probability of the target transaction being sandwiched is relatively low, and it can be considered that the target transaction has no transaction risk or that the transaction risk of the target transaction is low.

[0090] S104, processing the target transaction based on the detection result.

[0091] After obtaining the detection result, the target transaction can be processed.

[0092] Specifically, when the proxy contract detects that the detection result of the target transaction is that the target transaction has a transaction risk, the proxy contract can interrupt the execution of the target transaction; when the proxy contract detects that the detection result of the target transaction is that the target transaction has no transaction risk, the proxy contract can execute the target transaction and broadcast the executed target transaction in the blockchain.

[0093] In an embodiment of the present application, S104 can include steps S1041 to S1042:

[0094] S1041, when the detection result is that the target transaction has transaction risk, rolling back the target transaction.

[0095] When the detection result of the target transaction detected by the agent contract is that the target transaction has transaction risk, the agent contract can generate an instruction for rolling back the target transaction, execute the instruction for rolling back the target transaction after executing the target transaction through the smart contract, thereby withdrawing the target transaction, restoring the data in the blockchain to the data before executing the target transaction, and completing the operation of rolling back the target transaction.

[0096] S1042, when the detection result is that the target transaction does not have transaction risk, uploading the target transaction to the chain.

[0097] When the detection result of the target transaction detected by the agent contract is that the target transaction does not have transaction risk, the agent contract can generate an instruction for uploading the target transaction to the chain, and then execute the instruction for uploading the target transaction to the chain after executing the target transaction, thereby broadcasting the executed target transaction to the blockchain and completing the operation of uploading the target transaction to the chain.

[0098] In the embodiment of the application, when the target transaction carrying the first slip point is received, a decoy slip point is set for the target transaction, the first slip point is a slip point set by a user for the target transaction, the target transaction is executed based on the agent contract, the actual transaction slip point of executing the target transaction is determined, the transaction risk of the target transaction is detected according to the actual transaction slip point and the decoy slip point, the detection result is obtained, and the target transaction is processed based on the detection result, so that whether the target transaction has transaction risk can be detected based on the decoy slip point, and the target transaction is processed based on the detection result of the transaction risk, reducing the case that the transaction is attacked by a malicious trader when the transaction is performed in the case of transaction risk, and reducing the risk of property loss of the transaction party when the transaction is performed.

[0099] Referring to Figure 2 , Figure 2 A step flowchart of another blockchain transaction method provided by an embodiment of the application is shown, which can specifically include the following steps:

[0100] S201, when a target transaction carrying a first slip point is received, a decoy slip point is set for the target transaction.

[0101] S202, executing the target transaction based on the agent contract, and determining the actual transaction slip point of executing the target transaction.

[0102] S203, determining the risk slip point range according to the first slip point and the decoy slip point.

[0103] S204, when the actual transaction sliding point is in the risk sliding point range, determining that the detection result is that the target transaction has a transaction risk.

[0104] In an embodiment of the present application, S204 can include steps S2041-S2043:

[0105] S2041, obtaining historical transactions.

[0106] The historical transactions can be transactions of exchanging the first digital currency for the second digital currency in a historical time period, and the historical time period can be a certain period of time in the past.

[0107] After determining the risk sliding point range, the transactions of exchanging the first digital currency for the second digital currency in the past period of time can be determined to obtain at least one historical transaction.

[0108] S2042, determining a historical sliding point after executing the historical transaction.

[0109] The historical sliding point can be a deviation between an exchange ratio of the first digital currency for the second digital currency when the historical transaction is executed and an exchange ratio of the first digital currency for the second digital currency after the historical transaction is executed.

[0110] After determining the at least one historical transaction, for each historical transaction, an exchange ratio when the historical transaction is executed can be determined, i.e., an exchange ratio of the first digital currency for the second digital currency when the historical transaction is executed is determined, and an exchange ratio of the first digital currency for the second digital currency in the blockchain after the historical transaction is executed is determined, and then a deviation between the exchange ratio of the first digital currency for the second digital currency when the historical transaction is executed and the exchange ratio of the first digital currency for the second digital currency in the blockchain after the historical transaction is executed can be determined to obtain the historical sliding point of the historical transaction, thereby obtaining the historical sliding point of each historical transaction.

[0111] In an embodiment of the present application, S2042 can include the following steps:

[0112] Determining a first exchange ratio of the historical transaction, determining a second exchange ratio of the first digital currency for the second digital currency after executing the historical transaction according to a transaction quantity of the historical transaction, and determining a historical sliding point after executing the historical transaction according to the first exchange ratio and the second exchange ratio.

[0113] The first exchange ratio can be a ratio of the historical transaction of the first digital currency for the second digital currency, the second exchange ratio can be an exchange ratio of the first digital currency for the second digital currency after executing the historical transaction, and the transaction quantity can be a quantity of the first digital currency paid for the second digital currency in the historical transaction.

[0114] After determining the historical transaction, a conversion ratio of the first digital currency for the second digital currency when the historical transaction is executed can be determined, i.e., a conversion ratio of the first digital currency for the second digital currency when the historical transaction is actually executed is determined, and a first conversion ratio of the historical transaction is obtained.

[0115] After obtaining the first conversion ratio, the number of the first digital currency paid for the second digital currency in the historical transaction can be determined, and a transaction quantity of the historical transaction is obtained. Then, the number of the second digital currency that can be obtained when the historical transaction is executed can be determined according to the transaction quantity of the historical transaction and the first digital currency. The second conversion ratio of the first digital currency for the second digital currency after the historical transaction is executed can be determined based on the number of the second digital currency that can be obtained and the transaction quantity.

[0116] For example, when the historical transaction is executed, 1000 token A and 100 token B are included in the liquidity pool of the blockchain, token A can be the first digital currency, and token B can be the second digital currency. The historical transaction can be a transaction of paying 24 token A for token B, i.e., the transaction quantity of the historical transaction is paying 24 first digital currencies. It can be determined that the conversion ratio of the first digital currency for the second digital currency when the historical transaction is executed is 10:1, i.e., the first conversion ratio is 10:1. Then, the number of the second digital currency that can be obtained when the historical transaction is executed can be determined based on the transaction quantity of the historical transaction and the first conversion ratio, which is 2.4 token B. After determining the number of the second digital currency that can be obtained by the historical transaction, the second conversion ratio of the first digital currency for the second digital currency after the historical transaction is executed can be determined based on the number of the second digital currency obtained by the historical transaction and the transaction quantity thereof, i.e., it can be determined that 1024 token A and 97.6 token B are included in the liquidity pool of the blockchain after the historical transaction is executed. It can be determined that the conversion ratio of the first digital currency for the second digital currency after the historical transaction is executed is 10.5:1, i.e., the second conversion ratio is 10.5:1.

[0117] After obtaining the second conversion ratio, the deviation between the first conversion ratio and the second conversion ratio can be determined, and the historical slippage of the historical transaction is obtained.

[0118] For example, the first conversion ratio of the historical transaction is 10:1, and the second conversion ratio is 10.5:1. It can be determined that the deviation between the first conversion ratio and the second conversion ratio is 50%.

[0119] S2043, when the historical slippage is in the risk slippage range and the actual transaction slippage is in the risk slippage range, it is determined that the detection result is that the target transaction has a transaction risk.

[0120] After determining the historical slippage, the historical slippage can be compared with the risk slippage range, and the actual transaction slippage can be compared with the risk slippage range. When the historical slippage is in the risk slippage range, and the actual transaction slippage is in the risk slippage range, it can be determined that the detection result is that the target transaction has transaction risk.

[0121] It should be understood that the attacker will construct a pre-transaction and a post-transaction for the target transaction, and the pre-transaction can increase the exchange ratio of the first digital currency for the second digital currency in the blockchain, and the deviation between the exchange ratio of the first digital currency for the second digital currency in the blockchain after increasing and the expected exchange ratio of the target transaction is still less than the sum of the first slippage and the bait slippage in the target transaction. Based on this, the historical transaction in which the historical slippage is in the risk slippage range can be determined from the transactions in the past period of time, and it can be considered that the historical transaction is the pre-transaction set by the attacker for the target transaction.

[0122] In actual application, whether there is a pre-transaction in all historical transactions in the past period of time can be identified by comparing the historical slippage with the risk slippage range and comparing the actual transaction slippage with the risk slippage range. When the historical slippage is in the risk slippage range and the actual transaction slippage is in the risk slippage range, it can be considered that there is a pre-transaction for the target transaction before the target transaction, that is, it can be determined that the target transaction has a high probability of being sandwiched and has transaction risk.

[0123] S205, when the actual transaction slippage is less than the minimum value of the risk slippage range, determining that the detection result is that the target transaction does not have transaction risk.

[0124] S206, processing the target transaction based on the detection result.

[0125] In the embodiments of the present application, when the target transaction carrying the first slippage is received, the bait slippage is set for the target transaction, the target transaction is executed based on the proxy contract, the actual transaction slippage of executing the target transaction is determined, the risk slippage range is determined according to the first slippage and the bait slippage, when the actual transaction slippage is in the risk slippage range, it is determined that the detection result is that the target transaction has transaction risk, when the actual transaction slippage is less than the minimum value of the risk slippage range, it is determined that the detection result is that the target transaction does not have transaction risk, and the target transaction is processed based on the detection result, so that whether the target transaction has transaction risk can be detected based on the bait slippage, and the target transaction is processed based on the detection result of the transaction risk, reducing the case that the transaction is attacked by malicious traders when the transaction is performed in the case of transaction risk, and reducing the risk of property loss of the transaction party when performing the transaction.

[0126] ReferenceFigure 3 , Figure 3 A structural diagram of a transaction device of a blockchain is shown, which can include the following modules:

[0127] The setting module 301 is configured to set a decoy slippage for a target transaction when receiving the target transaction carrying a first slippage, wherein the first slippage is a slippage set by a user for the target transaction.

[0128] The determining module 302 is configured to execute the target transaction based on a proxy contract, and determine an actual transaction slippage of the target transaction.

[0129] The detecting module 303 is configured to detect a transaction risk of the target transaction according to the actual transaction slippage and the decoy slippage, and obtain a detection result.

[0130] The processing module 304 is configured to process the target transaction based on the detection result.

[0131] In an implementation manner, the detecting module 303 is further configured to:

[0132] determine a risk slippage range according to the first slippage and the decoy slippage;

[0133] when the actual transaction slippage is in the risk slippage range, determine that the detection result is that the target transaction has the transaction risk;

[0134] when the actual transaction slippage is less than a minimum value of the risk slippage range, determine that the detection result is that the target transaction does not have the transaction risk.

[0135] In an implementation manner, the detecting module 303 is further configured to:

[0136] determine a maximum slippage according to the first slippage and the decoy slippage, wherein the maximum slippage is a sum of the first slippage and the decoy slippage;

[0137] determine the risk slippage range according to the maximum slippage and the first slippage, wherein a minimum value of the risk slippage range is the first slippage, and a maximum value of the risk slippage range is the maximum slippage.

[0138] In an implementation manner, the processing module 304 is further configured to:

[0139] when the detection result is that the target transaction has the transaction risk, roll back the target transaction;

[0140] when the detection result is that the target transaction does not have the transaction risk, chain the target transaction.

[0141] In an implementation manner, the target transaction is a transaction in which a transaction party exchanges a first digital currency for a second digital currency, and the detecting module 303 is further configured to:

[0142] obtaining a historical transaction, wherein the historical transaction is a transaction of exchanging the first digital currency for the second digital currency in a historical time period;

[0143] determining a historical slippage after executing the historical transaction;

[0144] when the historical slippage is in the risk slippage range and the actual transaction slippage is in the risk slippage range, determining that the detection result is that the target transaction has a transaction risk.

[0145] In an implementation manner, the detection module 303 is further configured to:

[0146] determining a first exchange ratio of the historical transaction, wherein the first exchange ratio is a ratio of the historical transaction of exchanging the first digital currency for the second digital currency;

[0147] determining a second exchange ratio of the first digital currency for the second digital currency after executing the historical transaction according to a transaction quantity of the historical transaction, wherein the transaction quantity is a quantity of the first digital currency paid for the second digital currency in the historical transaction;

[0148] determining the historical slippage after executing the historical transaction according to the first exchange ratio and the second exchange ratio.

[0149] In an implementation manner, the determination module 302 is further configured to:

[0150] determining a first slippage in the target transaction based on the proxy contract, and sending the first slippage to the smart contract to execute the target transaction according to the first slippage based on the smart contract, wherein the smart contract is configured to execute a transaction, and the proxy contract is configured to detect a transaction risk.

[0151] In the embodiments of the present application, when the target transaction carrying the first slippage is received, a decoy slippage is set for the target transaction, the first slippage is a slippage set by a user for the target transaction, the target transaction is executed based on the proxy contract, and an actual transaction slippage of executing the target transaction is determined, a transaction risk of the target transaction is detected according to the actual transaction slippage and the decoy slippage, a detection result is obtained, and the target transaction is processed based on the detection result, so that whether the target transaction has a transaction risk can be detected based on the decoy slippage, and the target transaction is processed based on the detection result of the transaction risk, which reduces the case that the transaction is attacked by a malicious transactioner in the case that the transaction has a transaction risk, and reduces the risk that the property of the transaction party is damaged when the transaction is executed.

[0152] It should be noted that the information interaction and execution process between the above devices are based on the same concept as the method embodiments of the present application, and the specific functions and the technical effects brought by them can be referred to the method embodiments part, which will not be described here.

[0153] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the above-mentioned division of each functional unit and module is exemplified, and in actual application, the above-mentioned functions can be completed by different functional units and modules according to needs, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the above-described functions. Each functional unit and module in the embodiment can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of software functional unit. In addition, the specific name of each functional unit and module is only for convenient distinction, and does not limit the protection scope of the present application. The specific working process of the unit and module in the above system can refer to the corresponding process in the foregoing method embodiments, which will not be repeated here.

[0154] Reference Figure 4 , Figure 4 A structural block diagram of an electronic device provided by an embodiment of the present application is shown, as shown in Figure 4 The embodiment of the present application further provides an electronic device 41, which comprises at least one processor 411, a memory 412, and a computer program 4121 stored in the memory 412 and capable of running on the at least one processor 411, wherein the processor 411 implements the steps in any of the method embodiments described above when executing the computer program 4121.

[0155] The embodiment of the present application further provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the steps in any of the method embodiments described above.

[0156] The embodiment of the present application provides a computer program product, which, when running on a mobile terminal, enables the mobile terminal to execute the steps in any of the method embodiments described above.

[0157] The integrated unit, if implemented in the form of a software function unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, all or part of the processes in the above-mentioned embodiment methods can be completed by a computer program instructing related hardware, and the computer program can be stored in a computer readable storage medium. When the computer program is executed by a processor, the steps of the above-mentioned various method embodiments can be implemented. The computer program includes computer program code, which can be in the form of source code, object code, executable files or some intermediate forms. The computer readable medium at least includes any entity or device capable of carrying the computer program code to the device / computer equipment, recording medium, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal and software distribution medium.

[0158] The above-described embodiments are only used to illustrate the technical solutions of the present application, rather than limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacements for some technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application.

Claims

1. A transaction method of a blockchain, characterized by, The method comprises: setting a decoy slippage for a target transaction when a target transaction carrying a first slippage is received, wherein the first slippage is a slippage set by a user for the target transaction; executing the target transaction based on a proxy contract, and determining an actual transaction slippage of the target transaction; detecting a transaction risk of the target transaction according to the actual transaction slippage and the decoy slippage, and obtaining a detection result; processing the target transaction based on the detection result. 2.The transaction method of the blockchain of claim 1, wherein, The detecting a transaction risk of the target transaction according to the actual transaction slippage and the decoy slippage, and obtaining a detection result, comprises: determining a risk slippage range according to the first slippage and the decoy slippage; determining that the target transaction has a transaction risk when the actual transaction slippage is in the risk slippage range; determining that the target transaction has no transaction risk when the actual transaction slippage is less than a minimum value of the risk slippage range. 3.The transaction method of the blockchain of claim 2, wherein, The determining a risk slippage range according to the first slippage and the decoy slippage, comprises: determining a maximum slippage according to the first slippage and the decoy slippage, wherein the maximum slippage is a sum of the first slippage and the decoy slippage; determining a risk slippage range according to the maximum slippage and the first slippage, wherein a minimum value of the risk slippage range is the first slippage, and a maximum value of the risk slippage range is the maximum slippage. 4.The transaction method of the blockchain of claim 2, wherein, The processing the target transaction based on the detection result, comprises: rolling back the target transaction when the detection result is that the target transaction has a transaction risk; uploading the target transaction to a chain when the detection result is that the target transaction has no transaction risk.

5. The method of claim 2 to 4, wherein, The target transaction is a transaction in which a first digital currency is exchanged for a second digital currency, and the determining that the target transaction has a transaction risk when the actual transaction slippage is in the risk slippage range, comprises: obtaining a historical transaction, wherein the historical transaction is a transaction in which the first digital currency is exchanged for the second digital currency in a historical time period; determining a historical slippage after the historical transaction is executed; determining that the target transaction has a transaction risk when the historical slippage is in the risk slippage range and the actual transaction slippage is in the risk slippage range. 6.The transaction method of the blockchain of claim 5, wherein, The determining a historical slippage after the historical transaction is executed, comprises: determining a first exchange ratio of the historical transaction, wherein the first exchange ratio is a ratio of the first digital currency exchanged for the second digital currency in the historical transaction; determining a second exchange ratio of the first digital currency exchanged for the second digital currency after the historical transaction is executed according to a transaction quantity of the historical transaction, wherein the transaction quantity is a quantity of the first digital currency paid for the second digital currency in the historical transaction; determining a historical slippage after the historical transaction is executed according to the first exchange ratio and the second exchange ratio. 7.The method of Claim 4, wherein, The executing the target transaction based on a proxy contract, comprises: determine the first slippage in the target transaction based on the agent contract, and send the first slippage to a smart contract, so that the smart contract executes the target transaction according to the first slippage based on the smart contract; wherein the smart contract is used to execute a transaction, and the agent contract is used to detect a transaction risk. 8.A transaction apparatus of a blockchain, characterized by, The apparatus comprises: a setting module configured to set a decoy slippage for a target transaction when the target transaction carrying a first slippage is received, wherein the first slippage is a slippage set by a user for the target transaction; a determining module configured to execute the target transaction based on an agent contract, and determine an actual transaction slippage of the target transaction; a detecting module configured to detect a transaction risk of the target transaction according to the actual transaction slippage and the decoy slippage, and obtain a detection result; a processing module configured to process the target transaction based on the detection 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, The processor executes the computer program to implement the method of any one of claims 1 to 7.

10. A computer program product comprising a computer program, characterized in that, The computer program is executed on the computer to enable the computer to implement the method of any one of claims 1 to 7.