Asset cross-chain transaction method and device based on blockchain smart contract
By deploying a hash lock smart contract on the blockchain to encrypt and decrypt assets, the consistency problem in cross-chain transactions is solved, and the security of cross-chain transactions and contract assets is achieved.
Patent Information
- Application Number
- CN202310231527.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-10
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2043-03-10
AI Technical Summary
In cross-chain blockchain transactions, how to ensure transaction consistency to prevent asset theft.
By deploying the Hash Lock smart contract on the blockchain, generating random numbers and hash values to encrypt assets, store them on the blockchain, and decrypt them on the other party's blockchain, the Hash Lock smart contract is used to lock and unlock assets to ensure the consistency of transactions.
It achieves the security and consistency of cross-chain transactions, prevents asset theft by malicious nodes, and ensures the security of assets on the contract.
Smart Images

Figure CN116188166B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain technology, and more specifically, to a method and device for cross-chain asset transactions based on blockchain smart contracts. Background Art
[0002] Blockchain networks can guarantee data consistency within the network, but consistency is difficult to guarantee in cross-chain scenarios. When account A on blockchain A exchanges assets with account B on blockchain B, the complexity of cross-chain networks makes it easy for nodes to act maliciously, leading to asset theft. Ensuring the consistency of cross-chain transactions is a pressing technical issue that existing technologies need to address. Summary of the Invention
[0003] In order to solve at least one of the technical problems in the above-mentioned background technology, the present invention proposes a method and device for cross-chain asset transactions based on blockchain smart contracts.
[0004] To achieve the above objectives, according to one aspect of the present invention, a method for cross-chain asset transactions based on blockchain smart contracts is provided, the method comprising:
[0005] Upon receiving an asset cross-chain transaction initiated by a client, the first blockchain generates a random number through a first hash lock smart contract deployed on itself, generates a hash value based on the random number, encrypts the first asset in itself based on the hash value to obtain first encrypted data, stores the first encrypted data in the first blockchain, and sends the hash value to the second blockchain. The asset cross-chain transaction specifically involves trading the first asset in the first blockchain for the second asset in the second blockchain.
[0006] The second blockchain encrypts the second asset according to the hash value through a second hash lock smart contract deployed on the second blockchain to obtain second encrypted data, stores the second encrypted data in the second blockchain, and sends a data locking success notification to the first blockchain;
[0007] After receiving the notification of successful data locking, the first blockchain calls the second hash lock smart contract according to the random number through the first hash lock smart contract to decrypt the second encrypted data, thereby obtaining the second asset from the second blockchain;
[0008] The second blockchain calls the first hash lock smart contract according to the random number through the second hash lock smart contract to decrypt the first encrypted data, and then obtains the first asset from the first blockchain.
[0009] Optionally, before the second blockchain encrypts the second asset according to the hash value using a second hash lock smart contract deployed on the second blockchain to obtain second encrypted data, stores the second encrypted data in the second blockchain, and sends a data locking success notification to the first blockchain, the method further includes:
[0010] The second blockchain calls the first hash lock smart contract according to the hash value to confirm whether there is encrypted data encrypted by the hash value on the first blockchain;
[0011] If it does not exist, the transaction ends.
[0012] Optionally, the second blockchain encrypts the second asset according to the hash value through a second hash lock smart contract deployed on the second blockchain to obtain second encrypted data, stores the second encrypted data in the second blockchain, and sends a data locking success notification to the first blockchain, specifically including:
[0013] If there is encrypted data encrypted using the hash value on the first blockchain, the second blockchain encrypts the second asset according to the hash value through the second hash lock smart contract deployed on itself to obtain second encrypted data, stores the second encrypted data in the second blockchain, and sends a data locking success notification to the first blockchain.
[0014] Optionally, storing the first encrypted data in the first blockchain specifically includes:
[0015] Generate a hash value encrypted data key-value pair based on the first encrypted data and the hash value, and then store the hash value encrypted data key-value pair in the first blockchain.
[0016] Optionally, before the second blockchain encrypts the second asset according to the hash value using a second hash lock smart contract deployed on the second blockchain to obtain second encrypted data, stores the second encrypted data in the second blockchain, and sends a data locking success notification to the first blockchain, the method further includes:
[0017] The second blockchain calls the first hash lock smart contract according to the hash value to confirm whether a hash value encrypted data key-value pair corresponding to the hash value exists on the first blockchain;
[0018] If it does not exist, the transaction ends.
[0019] Optionally, the second blockchain encrypts the second asset according to the hash value through a second hash lock smart contract deployed on the second blockchain to obtain second encrypted data, stores the second encrypted data in the second blockchain, and sends a data locking success notification to the first blockchain, specifically including:
[0020] If a hash value encrypted data key-value pair corresponding to the hash value exists on the first blockchain, the second blockchain encrypts the second asset according to the hash value through the second hash lock smart contract deployed on itself to obtain second encrypted data, stores the second encrypted data in the second blockchain, and sends a data locking success notification to the first blockchain.
[0021] Optionally, storing the second encrypted data in the second blockchain specifically includes:
[0022] Generate a hash value encrypted data key-value pair based on the second encrypted data and the hash value, and then store the hash value encrypted data key-value pair in the second blockchain.
[0023] Optionally, generating a random number specifically includes:
[0024] The random number is generated according to the current time.
[0025] To achieve the above objectives, according to another aspect of the present invention, a cross-chain asset transaction device based on blockchain smart contracts is provided, the device comprising:
[0026] A first asset locking unit is configured to, upon receiving an asset cross-chain transaction initiated by a client, cause the first blockchain to generate a random number through a first hash lock smart contract deployed on the first blockchain, generate a hash value based on the random number, encrypt the first asset in the first blockchain based on the hash value to obtain first encrypted data, store the first encrypted data in the first blockchain, and send the hash value to the second blockchain, wherein the asset cross-chain transaction specifically involves trading the first asset in the first blockchain for the second asset in the second blockchain;
[0027] a second asset locking unit, configured to cause the second blockchain to encrypt the second asset according to the hash value through a second hash lock smart contract deployed on the second blockchain to obtain second encrypted data, store the second encrypted data in the second blockchain, and send a data locking success notification to the first blockchain;
[0028] a first asset transaction unit configured to, upon receiving the notification of successful data locking, cause the first blockchain to call the second hash lock smart contract according to the random number through the first hash lock smart contract to decrypt the second encrypted data, thereby obtaining the second asset from the second blockchain;
[0029] The second asset trading unit is configured to enable the second blockchain to call the first hash lock smart contract according to the random number through the second hash lock smart contract to decrypt the first encrypted data, and thereby obtain the first asset from the first blockchain.
[0030] In order to achieve the above-mentioned purpose, according to another aspect of the present invention, a computer device is further provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the above-mentioned cross-chain asset transaction method based on blockchain smart contracts are implemented.
[0031] In order to achieve the above-mentioned purpose, according to another aspect of the present invention, a computer-readable storage medium is further provided, on which a computer program / instruction is stored. When the computer program / instruction is executed by a processor, the steps of the above-mentioned cross-chain asset transaction method based on blockchain smart contracts are implemented.
[0032] In order to achieve the above-mentioned purpose, according to another aspect of the present invention, a computer program product is further provided, including a computer program / instruction, which, when executed by a processor, implements the steps of the above-mentioned asset cross-chain transaction method based on blockchain smart contracts.
[0033] The beneficial effects of the present invention are:
[0034] When conducting cross-chain asset transactions, the present invention first locks the assets to be traded (i.e., encrypts them before uploading them to the chain) through the Hash Lock smart contract deployed on the blockchain to prevent malicious behavior and ensure the consistency of cross-chain transactions. In addition, once the Hash Lock smart contract is successfully deployed on the blockchain, it will run automatically without human intervention, thus ensuring the security of the assets on the contract. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0036] Figure 1 This is the first flow chart of the cross-chain asset transaction method based on blockchain smart contracts in an embodiment of the present invention;
[0037] Figure 2 This is a second flow chart of the asset cross-chain transaction method based on blockchain smart contracts in an embodiment of the present invention;
[0038] Figure 3 Schematic diagram of the application scenario of the present invention;
[0039] Figure 4 This is a schematic diagram of the structure of the hash lock smart contract of the present invention;
[0040] Figure 5 This is a structural block diagram of an asset cross-chain transaction device based on a blockchain smart contract according to an embodiment of the present invention;
[0041] Figure 6 Schematic diagram of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0042] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
[0043] It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0044] It should be noted that the terms "including" and "having" and any variations thereof in the specification and claims of the present invention and the above-mentioned drawings are intended to cover non-exclusive inclusions. For example, a process, method, system, product or apparatus comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or are inherent to these processes, methods, products or apparatuses.
[0045] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments of the present invention can be combined with each other. The present invention will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0046] It should be noted that the acquisition, storage, use, and processing of data in the technical solution of this application comply with the relevant provisions of national laws and regulations.
[0047] It should be noted that the cross-chain asset transaction method and device based on blockchain smart contracts of the present invention can be used in the financial field, and can also be used in any field other than the financial field. The application field of the cross-chain asset transaction method and device based on blockchain smart contracts of the present invention is not limited.
[0048] Figure 3 It is a schematic diagram of the application scenario of the present invention, such as Figure 3 As shown, the application scenario of the present invention specifically includes: a first blockchain, a second blockchain, a cross-chain gateway, and a client. A first Hash Lock smart contract is deployed on the first blockchain, and a second Hash Lock smart contract is deployed on the second blockchain. It should be noted that the first blockchain and the second blockchain of the present invention are both blockchain networks.
[0049] The first blockchain and the second blockchain are two independent blockchains that join the cross-chain network. The information of the two blockchains is not interoperable and they are independent of each other.
[0050] Cross-chain gateway: used to connect the first blockchain and the second blockchain. Cross-chain transactions are carried out through the cross-chain gateway for protocol conversion and message forwarding.
[0051] Client: The client is used to initiate transactions on the blockchain network and receive transaction results returned by the blockchain network. The connection between the client and the blockchain can be one-to-many or one-to-one.
[0052] In the cross-chain scenario of the present invention, the cross-chain gateway needs to have the following functional modules: 1. Blockchain interaction module: used to interact with the blockchain, initiate blockchain calls, receive blockchain return information, and each blockchain connected to the cross-chain gateway is connected to an independent interaction module; 2. Information forwarding module, used to forward information from different blockchain interaction modules to facilitate the flow of information between different blockchains.
[0053] Figure 4 This is a schematic diagram of the structure of the hash lock smart contract of the present invention. Figure 4As shown, the hash lock smart contract of the present invention (the first hash lock smart contract and the second hash lock smart contract) needs to have the following functional modules: 1. Data storage module: used to store assets on the chain; 2. Data reading module: used to read assets on the chain. When the data is encrypted, the corresponding secret key must be entered to correctly read the data; otherwise, the data will be rejected; 3. Hash locking module: used to hash the data on the chain. It uses time t as a random seed to generate a random number R = random(t). The random number R is used to generate a hash value H = hash(R). The asset D and H are encrypted E(H, D) and stored in the blockchain in key / value format (H, E(H, D)). When using the data reading module, R must be entered. The data reading module calculates H = hash(R) to correctly unlock the asset; 4. Data confirmation module: used to confirm whether the asset on the chain exists. The hash value H can be entered to query. If the asset exists, true is returned, otherwise false is returned. 4. Cross-chain transaction module: used to send cross-chain transactions and send information to the cross-chain gateway.
[0054] Figure 1 This is the first flow chart of the asset cross-chain transaction method based on blockchain smart contract in an embodiment of the present invention. Figure 1 As shown, in one embodiment of the present invention, the cross-chain asset transaction method based on blockchain smart contract of the present invention includes steps S101 to S104.
[0055] Step S101: Upon receiving an asset cross-chain transaction initiated by a client, the first blockchain generates a random number through a first hash lock smart contract deployed on itself, generates a hash value based on the random number, encrypts the first asset in itself based on the hash value to obtain first encrypted data, stores the first encrypted data in the first blockchain, and sends the hash value to the second blockchain. The asset cross-chain transaction specifically involves trading the first asset in the first blockchain for the second asset in the second blockchain.
[0056] In one embodiment of the present invention, the present invention generates the random number specifically according to the current time.
[0057] In one embodiment of the present invention, storing the first encrypted data in the first blockchain in this step specifically includes:
[0058] Generate a hash value encrypted data key-value pair based on the first encrypted data and the hash value, and then store the hash value encrypted data key-value pair in the first blockchain.
[0059] In the present invention, the client initiates a cross-chain transaction on the first blockchain, sends the first asset D1 on the first blockchain to the second blockchain, and simultaneously obtains the second asset D2 on the second blockchain.
[0060] When the first blockchain receives an asset cross-chain transaction initiated by a client, it uses the hash lock module of the first Hash Lock smart contract deployed on it to generate a random number R = random(t) based on the current time t. It then uses this random number R to generate a hash value H = hash(R). It then encrypts the first asset D1 with the hash value H to generate the first encrypted data E(H, D1). This data is then stored in the first blockchain as a key / value pair (H, E(H, D1)), thus locking the first asset D1. The first blockchain then sends the hash value H to the second blockchain via the cross-chain transaction module of the first Hash Lock smart contract.
[0061] In step S102, the second blockchain encrypts the second asset according to the hash value through the second hash lock smart contract deployed on the second blockchain to obtain second encrypted data, stores the second encrypted data in the second blockchain, and sends a data locking success notification to the first blockchain.
[0062] In one embodiment of the present invention, the step of storing the second encrypted data in the second blockchain specifically includes:
[0063] Generate a hash value encrypted data key-value pair based on the second encrypted data and the hash value, and then store the hash value encrypted data key-value pair in the second blockchain.
[0064] In the present invention, the second blockchain uses the hash value H to lock the second asset D2 through the second hash lock smart contract deployed in itself, and saves it in the second blockchain in the form of a key-value pair key / value (H, E(H, D2)), and notifies the first blockchain through the cross-chain transaction module of the second hash lock smart contract, sending a data locking success notification to the first blockchain.
[0065] Step S103: After receiving the notification of successful data locking, the first blockchain calls the second hash lock smart contract according to the random number through the first hash lock smart contract to decrypt the second encrypted data, and then obtains the second asset from the second blockchain.
[0066] In the present invention, after receiving the data lock success notification, the first blockchain unlocks the asset through the cross-chain transaction module of the first Hash Lock smart contract and calls the data reading module of the second Hash Lock smart contract on the second blockchain according to the random number R, thereby obtaining the second asset D2. When the second Hash Lock smart contract is called according to the random number R, the random number R is exposed to the second blockchain.
[0067] In the present invention, the data reading module of the second hash lock smart contract first generates a hash value H based on the random number R, and then decrypts the second encrypted data according to the hash value H to obtain the second asset D2, and then sends the second asset D2 to the first blockchain.
[0068] In step S104, the second blockchain calls the first hash lock smart contract according to the random number through the second hash lock smart contract to decrypt the first encrypted data, and then obtains the first asset from the first blockchain.
[0069] In the present invention, the second blockchain uses the random number R to call the data reading module of the first Hash Lock smart contract on the first blockchain through the cross-chain transaction module of the second Hash Lock smart contract to unlock the asset and obtain the first asset D1. The transaction process ends.
[0070] In the present invention, the data reading module of the first hash lock smart contract first generates a hash value H based on the random number R, and then decrypts the first encrypted data according to the hash value H to obtain the first asset D1, and then sends the first asset D1 to the second blockchain to complete the transaction.
[0071] Figure 2 This is the second flow chart of the asset cross-chain transaction method based on blockchain smart contract in an embodiment of the present invention. Figure 2 As shown, in one embodiment of the present invention, the cross-chain asset transaction method based on blockchain smart contract of the present invention also includes steps S201 to S203.
[0072] In step S201, the second blockchain calls the first hash lock smart contract according to the hash value to confirm whether there is encrypted data encrypted using the hash value on the first blockchain.
[0073] Step S202: If it does not exist, then end the transaction.
[0074] In step S203, if encrypted data encrypted using the hash value exists on the first blockchain, the second blockchain encrypts the second asset according to the hash value through the second hash lock smart contract deployed on itself to obtain second encrypted data, stores the second encrypted data in the second blockchain, and sends a data locking success notification to the first blockchain.
[0075] In the present invention, before the second blockchain locks the second asset D2, the second blockchain first calls the data confirmation module of the first Hash Lock smart contract on the first blockchain based on the hash value H to confirm the existence of the first asset D1 under the hash value H. If so, the second asset D2 is locked; otherwise, the transaction process ends.
[0076] like Figure 1 and Figure 2 As shown, in one embodiment of the present invention, before performing the above step S102, the present invention first performs the above steps S201 and S202 of verifying whether the encrypted data exists.
[0077] In one embodiment of the present invention, the second blockchain in step S201 calls the first hash lock smart contract based on the hash value to confirm whether encrypted data encrypted using the hash value exists on the first blockchain, specifically including:
[0078] The second blockchain calls the first hash lock smart contract according to the hash value to confirm whether a hash value encrypted data key-value pair corresponding to the hash value exists on the first blockchain.
[0079] In one embodiment of the present invention, if encrypted data encrypted by the hash value exists on the first blockchain in step S203, the second blockchain encrypts the second asset according to the hash value using a second hash lock smart contract deployed on the second blockchain to obtain second encrypted data, stores the second encrypted data in the second blockchain, and sends a data locking success notification to the first blockchain, specifically including:
[0080] If a hash value encrypted data key-value pair corresponding to the hash value exists on the first blockchain, the second blockchain encrypts the second asset according to the hash value through the second hash lock smart contract deployed on itself to obtain second encrypted data, stores the second encrypted data in the second blockchain, and sends a data locking success notification to the first blockchain.
[0081] As can be seen from the above embodiments, the present invention utilizes the characteristics of openness, transparency and traceability of blockchain data, uses a hash lock mechanism to lock assets, prevents malicious behavior, ensures the consistency of cross-chain transactions, and uses smart contracts to manage locked assets. Before the smart contract is deployed on the blockchain, it will be audited by the participating parties. Once the smart contract is successfully deployed on the blockchain, it will run automatically without human intervention, thereby ensuring the security of the assets on the contract.
[0082] Some of the terms that appear in the above embodiments of the present invention are explained below:
[0083] Blockchain network: A decentralized network in which nodes jointly record information. Using cryptographic methods and proof-of-work accounting, blockchain networks ensure transparency and traceability. Information recorded in a blockchain network is highly tamper-proof and highly secure. Blockchain networks can be categorized into three types based on entry requirements: public, consortium, and private.
[0084] Smart contracts: A smart contract is a collection of code and data deployed on a network. When certain conditions are met, the code executes automatically without human intervention. Smart contracts effectively avoid credit issues between contracting parties. Once a contract is successfully deployed, execution is completed by nodes within the network, independent of the parties involved. Blockchain technology provides a trusted execution environment for smart contracts. Smart contracts deployed on a blockchain network have the following advantages: 1. Open and transparent rules: Contract rules are jointly formulated and deployed within the blockchain network by the contracting parties. 2. Secure and reliable transactions: Contracts are automatically executed by nodes within the blockchain network without human intervention, and their execution process is transparent and traceable.
[0085] Cross-chain technology: Cross-chain technology is a general term for technologies that enable data transmission between different chains. Through cross-chain technology, value can transcend the barriers between chains and transfer assets on one chain to another safely and reliably, thereby solving the problem of blockchain ecological islands.
[0086] Hash algorithm: A hash algorithm is a one-way encryption method, using the form H = hash(data). Data data is encrypted to form a hash value H. Its characteristic is that data cannot be reverse-calculated from H. Data with slightly different content often produce significantly different hash values. A good hash algorithm has an extremely low probability of data collisions. With limited data, data collisions are generally considered non-existent.
[0087] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0088] Based on the same inventive concept, embodiments of the present invention also provide a cross-chain asset transaction device based on a blockchain smart contract, which can be used to implement the cross-chain asset transaction method based on a blockchain smart contract described in the above embodiments, as described in the following embodiments. Since the principles of the problem solved by the cross-chain asset transaction device based on a blockchain smart contract are similar to those of the cross-chain asset transaction method based on a blockchain smart contract, the embodiments of the cross-chain asset transaction device based on a blockchain smart contract can refer to the embodiments of the cross-chain asset transaction method based on a blockchain smart contract, and the repeated parts will not be repeated. As used below, the terms "unit" or "module" can refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.
[0089] Figure 5 This is a block diagram of the structure of the cross-chain asset transaction device based on blockchain smart contracts in an embodiment of the present invention. Figure 5 As shown, in one embodiment of the present invention, the asset cross-chain transaction device based on blockchain smart contract of the present invention includes:
[0090] The first asset locking unit 1 is configured to, upon receiving an asset cross-chain transaction initiated by a client, cause the first blockchain to generate a random number through a first hash lock smart contract deployed on the first blockchain, generate a hash value based on the random number, encrypt the first asset in the first blockchain based on the hash value to obtain first encrypted data, store the first encrypted data in the first blockchain, and send the hash value to the second blockchain, wherein the asset cross-chain transaction specifically involves trading the first asset in the first blockchain for the second asset in the second blockchain;
[0091] A second asset locking unit 2 is configured to cause the second blockchain to encrypt the second asset according to the hash value through a second hash lock smart contract deployed on the second blockchain to obtain second encrypted data, store the second encrypted data in the second blockchain, and send a data locking success notification to the first blockchain;
[0092] The first asset trading unit 3 is configured to, upon receiving the notification of successful data locking, cause the first blockchain to call the second hash lock smart contract according to the random number through the first hash lock smart contract to decrypt the second encrypted data, thereby obtaining the second asset from the second blockchain;
[0093] The second asset trading unit 4 is configured to enable the second blockchain to call the first hash lock smart contract according to the random number through the second hash lock smart contract to decrypt the first encrypted data, and then obtain the first asset from the first blockchain.
[0094] In one embodiment of the present invention, the cross-chain asset transaction device based on blockchain smart contracts of the present invention further includes:
[0095] A first data verification unit is configured to enable the second blockchain to call the first hash lock smart contract according to the hash value to confirm whether encrypted data encrypted using the hash value exists on the first blockchain;
[0096] The first transaction termination processing unit is configured to terminate the transaction if the first transaction termination processing unit does not exist.
[0097] In one embodiment of the present invention, the second asset locking unit 2 is specifically configured to, if encrypted data encrypted using the hash value exists on the first blockchain, enable the second blockchain to encrypt the second asset according to the hash value through a second hash lock smart contract deployed on the second blockchain to obtain second encrypted data, store the second encrypted data in the second blockchain, and send a data locking success notification to the first blockchain.
[0098] In one embodiment of the present invention, the first asset locking unit 1 specifically includes:
[0099] A first storage module is configured to generate a hash value encrypted data key-value pair based on the first encrypted data and the hash value, and then store the hash value encrypted data key-value pair in the first blockchain.
[0100] In one embodiment of the present invention, the cross-chain asset transaction device based on blockchain smart contracts of the present invention further includes:
[0101] A second data verification unit is configured for the second blockchain to call the first hash lock smart contract according to the hash value to confirm whether a hash value encrypted data key-value pair corresponding to the hash value exists on the first blockchain;
[0102] The second transaction termination processing unit is configured to terminate the transaction if the second transaction termination processing unit does not exist.
[0103] In one embodiment of the present invention, the second asset locking unit 2 is specifically configured to, if a hash value encrypted data key-value pair corresponding to the hash value exists on the first blockchain, enable the second blockchain to encrypt the second asset according to the hash value through a second hash lock smart contract deployed on the second blockchain to obtain second encrypted data, store the second encrypted data in the second blockchain, and send a data locking success notification to the first blockchain.
[0104] In one embodiment of the present invention, the second asset locking unit 2 specifically includes:
[0105] A second storage module is configured to generate a hash value encrypted data key-value pair based on the second encrypted data and the hash value, and then store the hash value encrypted data key-value pair in the second blockchain.
[0106] In one embodiment of the present invention, the first asset locking unit 1 specifically includes:
[0107] The random number generation module is used to generate the random number according to the current time.
[0108] In order to achieve the above object, according to another aspect of the present application, a computer device is also provided. Figure 6 As shown, the computer device includes a memory, a processor, a communication interface and a communication bus. The memory stores a computer program that can be run on the processor. When the processor executes the computer program, the steps in the above embodiment method are implemented.
[0109] The processor may be a central processing unit (CPU). The processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or a combination of the above chips.
[0110] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs, non-transitory computer-executable programs, and units, such as the corresponding program units in the above-described method embodiments of the present invention. The processor executes the non-transitory software programs, instructions, and modules stored in memory to perform various processor functions and work data processing, thereby implementing the methods in the above-described method embodiments.
[0111] The memory may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created by the processor, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory may optionally include a memory remotely located relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0112] The one or more units are stored in the memory, and when executed by the processor, perform the method in the above embodiment.
[0113] The specific details of the above-mentioned computer device can be understood by referring to the corresponding descriptions and effects in the above-mentioned embodiments, and will not be repeated here.
[0114] To achieve the above objectives, according to another aspect of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed in a computer processor, the computer program implements the steps in the above-mentioned cross-chain asset transaction method based on blockchain smart contracts. Those skilled in the art will understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program. The program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above-mentioned types of memory.
[0115] In order to achieve the above-mentioned purpose, according to another aspect of the present application, a computer program product is also provided, including a computer program / instruction, which, when executed by a processor, implements the steps of the above-mentioned asset cross-chain transaction method based on blockchain smart contracts.
[0116] Obviously, those skilled in the art will appreciate that the modules or steps of the present invention described above can be implemented using a general-purpose computing device. They can be centralized on a single computing device or distributed across a network of multiple computing devices. Alternatively, they can be implemented using program code executable by a computing device, which can then be stored in a storage device and executed by the computing device. Alternatively, they can be fabricated into separate integrated circuit modules, or multiple modules or steps can be fabricated into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.
[0117] The foregoing description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Those skilled in the art will readily appreciate that various modifications and variations of the present invention are possible. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present invention are intended to be within the scope of protection of the present invention.
Claims
1. A cross-chain asset transaction method based on blockchain smart contracts, characterized in that: include: Upon receiving an asset cross-chain transaction initiated by a client, the first blockchain generates a random number through a first hash lock smart contract deployed on itself, generates a hash value based on the random number, encrypts the first asset in itself based on the hash value to obtain first encrypted data, stores the first encrypted data in the first blockchain, and sends the hash value to the second blockchain. The asset cross-chain transaction specifically involves trading the first asset in the first blockchain for the second asset in the second blockchain. The second blockchain encrypts the second asset according to the hash value through a second hash lock smart contract deployed on the second blockchain to obtain second encrypted data, stores the second encrypted data in the second blockchain, and sends a data locking success notification to the first blockchain; After receiving the notification of successful data locking, the first blockchain calls the second hash lock smart contract according to the random number through the first hash lock smart contract to decrypt the second encrypted data, thereby obtaining the second asset from the second blockchain; The second blockchain calls the first hash lock smart contract according to the random number through the second hash lock smart contract to decrypt the first encrypted data, and then obtains the first asset from the first blockchain.
2. The cross-chain asset transaction method based on blockchain smart contracts according to claim 1 is characterized in that: Before the second blockchain encrypts the second asset according to the hash value through a second hash lock smart contract deployed on the second blockchain to obtain second encrypted data, stores the second encrypted data in the second blockchain, and sends a data locking success notification to the first blockchain, the method further includes: The second blockchain calls the first hash lock smart contract according to the hash value to confirm whether there is encrypted data encrypted by the hash value on the first blockchain; If it does not exist, the transaction ends.
3. The cross-chain asset transaction method based on blockchain smart contract according to claim 2 is characterized in that: The second blockchain encrypts the second asset according to the hash value through a second hash lock smart contract deployed on the second blockchain to obtain second encrypted data, stores the second encrypted data in the second blockchain, and sends a data locking success notification to the first blockchain, specifically including: If there is encrypted data encrypted using the hash value on the first blockchain, the second blockchain encrypts the second asset according to the hash value through the second hash lock smart contract deployed on itself to obtain second encrypted data, stores the second encrypted data in the second blockchain, and sends a data locking success notification to the first blockchain.
4. The cross-chain asset transaction method based on blockchain smart contracts according to claim 1 is characterized in that: Storing the first encrypted data in the first blockchain specifically includes: Generate a hash value encrypted data key-value pair based on the first encrypted data and the hash value, and then store the hash value encrypted data key-value pair in the first blockchain.
5. The cross-chain asset transaction method based on blockchain smart contracts according to claim 4 is characterized in that: Before the second blockchain encrypts the second asset according to the hash value through a second hash lock smart contract deployed on the second blockchain to obtain second encrypted data, stores the second encrypted data in the second blockchain, and sends a data locking success notification to the first blockchain, the method further includes: The second blockchain calls the first hash lock smart contract according to the hash value to confirm whether a hash value encrypted data key-value pair corresponding to the hash value exists on the first blockchain; If it does not exist, the transaction ends.
6. The cross-chain asset transaction method based on blockchain smart contracts according to claim 5 is characterized in that: The second blockchain encrypts the second asset according to the hash value through a second hash lock smart contract deployed on the second blockchain to obtain second encrypted data, stores the second encrypted data in the second blockchain, and sends a data locking success notification to the first blockchain, specifically including: If a hash value encrypted data key-value pair corresponding to the hash value exists on the first blockchain, the second blockchain encrypts the second asset according to the hash value through the second hash lock smart contract deployed on itself to obtain second encrypted data, stores the second encrypted data in the second blockchain, and sends a data locking success notification to the first blockchain.
7. The cross-chain asset transaction method based on blockchain smart contracts according to claim 1 is characterized in that: Storing the second encrypted data in the second blockchain specifically includes: Generate a hash value encrypted data key-value pair based on the second encrypted data and the hash value, and then store the hash value encrypted data key-value pair in the second blockchain.
8. The cross-chain asset transaction method based on blockchain smart contract according to claim 1 is characterized in that: Generating a random number specifically includes: The random number is generated according to the current time.
9. An asset cross-chain transaction device based on blockchain smart contracts, characterized in that: include: A first asset locking unit is configured to, upon receiving an asset cross-chain transaction initiated by a client, cause the first blockchain to generate a random number through a first hash lock smart contract deployed on the first blockchain, generate a hash value based on the random number, encrypt the first asset in the first blockchain based on the hash value to obtain first encrypted data, store the first encrypted data in the first blockchain, and send the hash value to the second blockchain, wherein the asset cross-chain transaction specifically involves trading the first asset in the first blockchain for the second asset in the second blockchain; a second asset locking unit, configured to cause the second blockchain to encrypt the second asset according to the hash value through a second hash lock smart contract deployed on the second blockchain to obtain second encrypted data, store the second encrypted data in the second blockchain, and send a data locking success notification to the first blockchain; a first asset transaction unit configured to, upon receiving the notification of successful data locking, cause the first blockchain to call the second hash lock smart contract according to the random number through the first hash lock smart contract to decrypt the second encrypted data, thereby obtaining the second asset from the second blockchain; The second asset trading unit is configured to enable the second blockchain to call the first hash lock smart contract according to the random number through the second hash lock smart contract to decrypt the first encrypted data, and thereby obtain the first asset from the first blockchain.
10. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 8 are implemented.
11. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.
12. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
An asset cross-chain transaction method between block chains
CN109685489A
Hash time locking method and system based on cloud cross-chain transfer protocol
CN113269545A