Data provenance method, apparatus, computer device, and storage medium

By introducing a combination of the main chain and the traceability chain into the blockchain, the problem of low data traceability efficiency in blockchain is solved, and efficient data traceability and secure storage are achieved.

CN114490808BActive Publication Date: 2026-04-07SHENZHEN POWER SUPPLY BUREAU
View PDF 3 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-29
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

The problem of low query efficiency when performing full lifecycle data traceability in blockchain.

Method used

By combining the main chain and the traceability chain, the main chain stores transaction data, while the traceability chain stores the operational information of the transaction data. Through the one-to-one correspondence between the blocks of the main chain and the traceability chain, efficient data traceability is achieved.

Benefits of technology

It alleviates the pressure of storing transaction data on a single chain, improves the efficiency of data traceability, and ensures data security and privacy through attribute encryption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114490808B_ABST
    Figure CN114490808B_ABST
Patent Text Reader

Abstract

The application relates to a data traceability method and device, computer equipment and a storage medium. The method comprises the following steps: in response to a transaction data query request initiated by a user, obtaining target transaction data corresponding to the transaction data query request from a main chain; if a root hash value generated according to the target transaction data is different from a root hash value stored in the main chain, obtaining full life cycle information of the target transaction data from a traceability chain; the full life cycle information comprises all operation information performed on the target transaction data; wherein the main chain is a blockchain for storing transaction data, the traceability chain is a blockchain for storing all operation information performed on the transaction data, and the blocks in the main chain and the traceability chain are in one-to-one correspondence. In the method, different data is stored in the main chain and the traceability chain, so that the pressure of storing transaction data in a single chain can be relieved, and in addition, through the one-to-one correspondence relationship between the blocks in the main chain and the traceability chain, efficient data traceability can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of blockchains, and in particular to a data traceability method and device, a computer device, and a storage medium. BACKGROUND

[0002] Data traceability refers to tracking and recording the entire life cycle of data, including data generation, modification, use, and deletion. Through data traceability, the history of data can be reproduced, and the required records can be found according to time or specific behavior, providing a favorable approach to finding the source of improper behavior.

[0003] Generally, the decentralized, tamper-proof, non-forgery, and transparent features of blockchain technology can be used to store transaction data in a blockchain and record operations such as adding, modifying, and deleting transaction data, thereby achieving traceability of transaction data through a blockchain.

[0004] However, as the number of blocks in the blockchain increases, there is a problem of low query traceability efficiency when tracing the entire life cycle of transaction data. SUMMARY

[0005] Therefore, it is necessary to provide a data traceability method, device, computer device, and storage medium that can improve data traceability efficiency based on a blockchain.

[0006] In a first aspect, the present application provides a data traceability method. The method comprises:

[0007] In response to a transaction data query request initiated by a user, obtaining target transaction data corresponding to the transaction data query request from a main chain;

[0008] If the root hash value generated according to the target transaction data is different from the root hash value stored in the main chain, obtaining the entire life cycle information of the target transaction data from a traceability chain; the entire life cycle information includes all operation information performed on the target transaction data;

[0009] The main chain is a blockchain that stores transaction data, and the traceability chain is a blockchain that stores all operation information performed on the transaction data, and the blocks in the main chain and the traceability chain correspond one-to-one.

[0010] In one embodiment, the transaction data query request includes a transaction identifier and a user identifier;

[0011] Obtaining target transaction data corresponding to the transaction data query request from the main chain comprises:

[0012] According to the transaction identifier, obtaining the ciphertext of the target transaction data from the main chain;

[0013] According to the user identifier, decryption information is obtained, and the ciphertext of the target transaction data is decrypted according to the decryption information to obtain the target transaction data.

[0014] In one of the embodiments, the decryption information is obtained according to the user identifier, comprising:

[0015] According to the user identifier, corresponding user attribute information, a public key and a master key are obtained;

[0016] According to the user attribute information, the public key and the master key, an attribute private key of the user is generated;

[0017] The attribute private key and the public key are determined as the decryption information.

[0018] In one of the embodiments, the full life cycle information of the target transaction data is obtained from the traceability chain, comprising:

[0019] According to the belonging block of the target transaction data in the main chain, address information of a corresponding traceability block in the traceability chain is obtained;

[0020] According to the address information of the corresponding traceability block, the full life cycle information of the target transaction data is obtained from the corresponding traceability block.

[0021] In one of the embodiments, the method further comprises:

[0022] In the corresponding traceability block, operation information of obtaining the full life cycle information of the target transaction data is recorded.

[0023] In one of the embodiments, the method further comprises:

[0024] In response to a transaction data storage request sent by the user, the to-be-stored transaction data is obtained;

[0025] The root hash value of the stored transaction data is generated, and the to-be-stored transaction data is attribute-encrypted according to a preset access strategy to obtain the ciphertext of the to-be-stored transaction data;

[0026] The root hash value of the stored transaction data, the ciphertext of the to-be-stored transaction data and the user information of the user are stored into the main chain.

[0027] In one of the embodiments, the to-be-stored transaction data is attribute-encrypted according to the preset access strategy to obtain the ciphertext of the to-be-stored transaction data, comprising:

[0028] The encryption security parameter is obtained, and the public key and the master key of the to-be-stored transaction data are generated according to the encryption security parameter;

[0029] The to-be-stored transaction data is attribute-encrypted according to the access strategy and the public key to obtain the ciphertext of the to-be-stored transaction data.

[0030] In a second aspect, the present application also provides a data traceability device. The device comprises:

[0031] The acquisition module is configured to acquire target transaction data corresponding to the transaction data query request from the main chain in response to a transaction data query request initiated by a user;

[0032] The traceability module is configured to acquire full life cycle information of the target transaction data from the traceability chain if a root hash value generated according to the target transaction data is different from a root hash value stored in the main chain; the full life cycle information comprises all operation information performed on the target transaction data;

[0033] The main chain is a blockchain for storing transaction data, and the traceability chain is a blockchain for storing all operation information performed on the transaction data; the blocks in the main chain and the traceability chain correspond to each other one by one.

[0034] In a third aspect, the present application also provides a computer device. The computer device comprises a memory and a processor; the memory stores a computer program; and the processor implements the steps of any method embodiment of the first aspect when executing the computer program.

[0035] In a fourth aspect, the present application also provides a computer readable storage medium. The computer readable storage medium stores a computer program; and the computer program implements the steps of any method embodiment of the first aspect when executed by a processor.

[0036] In a fifth aspect, the present application also provides a computer program product. The computer program product comprises a computer program; and the computer program implements the steps of any method embodiment of the first aspect when executed by a processor.

[0037] The aforementioned data traceability method, apparatus, computer equipment, and storage medium, in response to a user-initiated transaction data query request, retrieve the target transaction data corresponding to the query request from the main chain. If the root hash value generated based on the target transaction data differs from the root hash value stored in the main chain, the full lifecycle information of the target transaction data is retrieved from the traceability chain. This full lifecycle information includes all operation information performed on the target transaction data. The main chain is the blockchain storing transaction data, and the traceability chain is the blockchain storing all operation information performed on the transaction data; blocks in the main chain and the traceability chain correspond one-to-one. In this method, when a user queries transaction data, the target transaction data can be retrieved from the main chain. When the target transaction data retrieved from the main chain changes, the corresponding block on the traceability chain can be determined based on the correspondence between blocks on the main chain and the traceability chain, according to the block to which the target transaction data belongs on the main chain. Operation information of the target transaction data can then be retrieved from the corresponding block on the traceability chain, thus achieving data traceability. In this way, by storing different data on the main chain and the traceability chain, the pressure of storing transaction data on a single chain can be alleviated. In addition, through the one-to-one correspondence between blocks on the main chain and the slave chain, efficient data traceability can be achieved. Attached Figure Description

[0038] Figure 1 This is a diagram illustrating the application environment of a data tracing method in one embodiment.

[0039] Figure 2 This is a flowchart illustrating a data tracing method in one embodiment;

[0040] Figure 3 This is a schematic diagram of the main chain structure in one embodiment;

[0041] Figure 4 This is a schematic diagram of the traceability chain structure in one embodiment;

[0042] Figure 5 This is a schematic diagram of the process for obtaining target transaction data in one embodiment;

[0043] Figure 6 This is a schematic diagram of the target transaction data traceability process in one embodiment;

[0044] Figure 7 This is a schematic diagram of the transaction data uploading process in one embodiment;

[0045] Figure 8 This is a schematic diagram illustrating an application scenario of the data tracing method in one embodiment;

[0046] Figure 9 This is a structural block diagram of a data traceability device in one embodiment;

[0047] Figure 10This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation

[0048] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0049] The data tracing method provided in this application can be applied to... Figure 1 The computer device shown is equipped with a transaction system and a query system, and it also participates in forming a blockchain for tracing transaction data. As an example, this computer device can be, but is not limited to, a server, a terminal, an IoT device, a portable wearable device, etc.

[0050] The server can be, but is not limited to, at least one of the following: a standalone server, a distributed server, a cloud server, or a server cluster. Specifically, a distributed server can be a blockchain structure, where any blockchain node can execute or participate in executing data traceability methods. The terminal can be, but is not limited to, software running on a physical device, such as applications or clients installed on the device, or at least one of the following types of physical devices: personal computers, desktop computers, tablets, laptops, smartphones, etc. IoT devices can be smart speakers, smart TVs, smart air conditioners, smart in-vehicle devices, etc. Portable wearable devices can be smartwatches, smart bracelets, head-mounted devices, etc.

[0051] In one possible implementation, the internal structure of the computer device is as follows: Figure 1 As shown, the processor in this internal structure provides data computation and analysis functions. The memory in this internal structure includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The database can be used to store transaction data and recorded operation information related to the transaction data. The network interface is used for communication with external terminals via a network connection. When the computer program is executed by the processor, it implements a data traceability method.

[0052] With the development of information technology and the arrival of the big data era, the importance of data has been elevated to a new level, becoming a crucial strategic resource for enterprises and society. While open data sharing can solve the problem of "data silos" and better utilize data resources to realize greater value, it also faces a series of problems such as privacy data leaks, theft and resale, and data falsification, posing unprecedented challenges to data security and effective record-keeping.

[0053] Data traceability refers to tracking and recording the entire lifecycle of data, including its generation, modification, use, and deletion. Through data traceability, the historical context of data can be reconstructed, allowing the retrieval of necessary data operation information based on time or specific actions. In related technologies, transaction data and operation information are centrally stored in a specific block of a blockchain. However, as the number of blocks in the blockchain increases, the efficiency of querying and tracing transaction data throughout its entire lifecycle becomes inefficient.

[0054] Based on this, this application provides a data traceability method, apparatus, computer equipment, and storage medium, which improves data traceability efficiency while ensuring secure storage of transaction data.

[0055] In one embodiment, such as Figure 2 As shown, a data tracing method is provided, which can be applied to... Figure 1 Taking a computer device as an example, the explanation includes the following steps:

[0056] Step 210: In response to the user's transaction data query request, retrieve the target transaction data corresponding to the transaction data query request from the main chain.

[0057] The transaction data query request includes the transaction identifier.

[0058] In one possible implementation, step 210 can be implemented as follows: based on the transaction data query request initiated by the user, obtain the transaction identifier and the user identifier; determine the block on the main chain that stores the target transaction data based on the transaction identifier, and then obtain the target transaction data from that block.

[0059] Step 220: If the root hash value generated based on the target transaction data is different from the root hash value stored in the main chain, then obtain the full lifecycle information of the target transaction data from the traceability chain.

[0060] The full lifecycle information includes all operational information performed on the target transaction data.

[0061] It should be noted that for the acquired target transaction data, the target transaction data can be directly sent to the user, and the user can decide whether to execute step 220; or, if the root hash value of the target transaction data is different from the root hash value stored in the main chain, step 220 can be executed automatically, and the target transaction data and the full lifecycle information of the target transaction data can be returned to the user. This application embodiment does not limit this.

[0062] In addition, in this embodiment of the application, a main chain and a traceability chain are pre-built. The main chain is a blockchain that stores transaction data, and the traceability chain is a blockchain that stores all operation information performed on the transaction data. The blocks in the main chain and the traceability chain correspond one-to-one.

[0063] In one possible implementation, newly generated transaction data in the transaction system is packaged into blocks and stored on the blockchain, with multiple new transaction data being packaged within a single block. The main chain only stores the initial transaction data and newly generated transaction data, without tracking and recording subsequent operations related to that transaction data, thus reducing the storage pressure on the main chain. The entire lifecycle information of the transaction data is packaged and stored in the traceability chain. That is, the traceability chain is responsible for recording all lifecycle operations that occur after the transaction data in the main chain, forming a reliable traceability and query capability for specific operations related to particular transaction data.

[0064] Furthermore, each block in the main chain corresponds to one or more blocks in the traceability chain. Thus, a block on the traceability chain only records the full lifecycle information of all transaction data within its corresponding block on the main chain. When a new block is generated on the main chain, a traceability block is generated on the traceability chain. This traceability block records the hash value of the corresponding main chain block and returns its own traceability block address, stored in the main chain block. This allows for quick location of the transaction's address on both the main chain and the traceability chain.

[0065] As an example, see Figure 3 The main chain includes multiple blocks. Each block stores the transaction data, the hash value of the transaction data, the corresponding traceability block address, and the root hash of the traceability chain according to the timestamp generated by the transaction data.

[0066] Optionally, the main chain also stores the Merkle tree root and parent node hash values. When transaction data needs to be retrieved from the main chain, the entire main chain is traversed based on the parent node hash value to determine the block where the transaction data is located. Furthermore, the main chain has pre-set block height and block limit.

[0067] Similarly, see Figure 4The traceability chain also includes multiple traceability blocks. Each block writes the operation information of each transaction data into the traceability block corresponding to the main chain block containing that transaction data, based on the timestamp of the operation performed on the transaction data. Furthermore, the traceability block also includes the hash value of the operation information and the hash value of the main chain block corresponding to that traceability block.

[0068] The transaction data includes at least one action record.

[0069] Optionally, the traceability chain also stores the Merkle tree root and parent node hash values. When it is necessary to retrieve operation information of transaction data from the traceability chain, the entire traceability chain is traversed based on the parent node hash value to determine the traceability block where the operation information of the transaction data is located. Furthermore, the main chain has pre-set block height and block limit.

[0070] In other words, both the master and slave chains use a Merkle tree block structure to verify the authenticity of transactions, store transaction data in leaf nodes, and perform multiple hash calculations on adjacent leaf nodes to obtain the final root hash, which is then stored in the block header.

[0071] For the main chain, when a transaction needs to be verified, it only needs to download all the branch nodes where the transaction resides and compare them with the root hash value to prove the authenticity of the transaction. The root hash of the traceability chain is stored in the block header of the main chain. When querying data on the traceability chain, the specific traceability record is first found based on the traceability block address, and then the data in the traceability chain is verified to have not been tampered with by comparing whether the root hash values ​​in the main chain and the traceability chain are consistent.

[0072] In this application, in response to a user-initiated transaction data query request, the target transaction data corresponding to the query request is retrieved from the main chain. If the root hash value generated based on the target transaction data differs from the root hash value stored in the main chain, the full lifecycle information of the target transaction data is retrieved from the traceability chain. The full lifecycle information includes all operation information performed on the target transaction data. The main chain is the blockchain storing transaction data, and the traceability chain is the blockchain storing all operation information performed on the transaction data. Blocks in the main chain and the traceability chain correspond one-to-one. In this method, when a user queries transaction data, the target transaction data can be retrieved from the main chain. When the target transaction data retrieved from the main chain changes, the corresponding block on the traceability chain can be determined based on the correspondence between blocks on the main chain and the traceability chain, according to the block to which the target transaction data belongs on the main chain. Operation information of the target transaction data can then be retrieved from the corresponding block on the traceability chain, thus achieving data traceability. In this way, by storing different data on the main chain and the traceability chain, the pressure of storing transaction data on a single chain can be alleviated. In addition, through the one-to-one correspondence between blocks on the main chain and the slave chain, efficient data traceability can be achieved.

[0073] Based on the above embodiments, in one embodiment, the transaction data query request includes a transaction identifier and a user identifier, such as... Figure 5 As shown, retrieving the target transaction data corresponding to the transaction data query request from the main chain is executed by a query system deployed on computer devices. The specific implementation process includes the following steps:

[0074] Step 510: Obtain the encrypted target transaction data from the main chain based on the transaction identifier.

[0075] To prevent data tampering and ensure data security, transaction data is encrypted when stored on the main chain. Therefore, based on the transaction identifier, the target transaction data obtained from the main chain is the ciphertext, which can be decrypted to obtain the target transaction data.

[0076] In this application, the encryption of transaction data is implemented using attribute encryption technology based on a ciphertext policy. That is, the access policy of the transaction data is embedded in the ciphertext, and user attributes are embedded in the key. When transaction data is uploaded to the blockchain, the transaction system initializes and generates a public key and a master key, sets the corresponding access policy, and then encrypts the transaction data using the public key and access policy before storing it on the main chain. Simultaneously, it generates a private key for the ciphertext's attributes based on the access policy and the public key.

[0077] Each user has their own set of attributes. When a user accesses transaction data stored in the main chain, the query system will determine whether the user's attribute set matches the access policy according to the pre-set access policy. If they match, the system will pass the check and return the private key of the transaction data to the user.

[0078] In one possible implementation, step 510 can be implemented as follows: the query system determines the root hash value of the main chain block corresponding to the transaction identifier based on the transaction identifier, queries the block where the root hash value is located in the main chain, and obtains the ciphertext of the target transaction data from the block.

[0079] Step 520: Obtain decryption information based on the user identifier, and decrypt the ciphertext of the target transaction data based on the decryption information to obtain the target transaction data.

[0080] Based on the aforementioned attribute encryption method, the decrypted information includes the public key and the master key.

[0081] In one possible implementation, the process of obtaining decryption information based on the user identifier can be as follows: obtain the corresponding user attribute information, public key, and master key based on the user identifier; generate the user's attribute private key based on the user attribute information, public key, and master key; and determine the attribute private key and public key as the decryption information.

[0082] As an example, a private key for an attribute can be generated using the key generator KeyGen, as shown in the following formula (1):

[0083] SK ABE =KeyGen(S, PK) ABE MK ABE (1)

[0084] In the formula, KeyGen is short for Key Generator, which is a program that generates the registration code required for software registration. SK ABE Here, S represents the user's attribute, and PK is the private key for the attribute. ABE For public key, MK ABE The master key.

[0085] Furthermore, the decryption tool Decrypt is used to decrypt the ciphertext of the target transaction data according to the decryption information, and the target transaction data is obtained as shown in the following formula (2).

[0086] Transaction′=Decrypt <SK ABE PK ABE EK Transaction (2)

[0087] In the formula, Transaction′ represents the decrypted transaction data, and SK represents the transaction data. ABE Here, S represents the user's attribute, and PK is the private key for the attribute. ABE For public key, EK Transaction This is the encrypted data of the target transaction.

[0088] It should be understood that the decrypted transaction data and the target transaction data may be the same or different. Optionally, this application may also perform a consistency check on the decrypted transaction data. The consistency check process is as follows:

[0089] S1: Calculate the root hash value of the transaction data Transaction′;

[0090] Hash′ ROOT =Hash(Hash1(Transaction′1,Transaction′2),Hash2,...) (3)

[0091] Among them, Hash′ ROOT The root hash value is calculated, and Transaction′1, Transaction′2, etc. are the related transaction data that participated in generating the root hash value of transaction data Transaction′.

[0092] S2: Obtain the root hash value of the target transaction data from the main chain. ROOT Analysis using the irreversibility and strong collision properties of hash algorithms shows that if

[0093] Hash ROOT =Hash' ROOT

[0094] This indicates that the transaction data is consistent and reliable, and the decrypted transaction data is the target transaction data queried by the user. If the two are inconsistent, it is necessary to trace the source of the transaction data behavior.

[0095] In this embodiment, the transaction data stored on the main chain is based on attribute encryption. Therefore, the ciphertext of the target transaction data is obtained from the main chain based on the transaction identifier; decryption information is obtained based on the user identifier, and the ciphertext of the target transaction data is decrypted using the decryption information to obtain the target transaction data. In this way, the access control mechanism based on attribute encryption can verify the identity of the initiator of the target transaction data access behavior, ensuring the privacy and security of the data on the main chain.

[0096] Based on the above embodiments, the process of obtaining the full lifecycle information of the target transaction data will be explained below.

[0097] In one embodiment, such as Figure 6 As shown, the process of retrieving the full lifecycle information of target transaction data from the traceability chain is performed by a query system deployed on computer devices. The specific implementation process includes the following steps:

[0098] Step 610: Based on the block to which the target transaction data belongs in the main chain, obtain the address information of the corresponding traceability block in the traceability chain.

[0099] The main chain stores the address information of the corresponding traceability block on the traceability chain in each block. Therefore, the address information of the traceability block can be obtained from the block where the target transaction data is located.

[0100] Step 620: Based on the address information of the corresponding traceability block, obtain the full lifecycle information of the target transaction data from the corresponding traceability block.

[0101] The full lifecycle information includes all operational information performed on the target transaction data, which can be specifically multiple behavior records.

[0102] Optionally, after obtaining the full lifecycle information of the target transaction data and completing data tracing, it is also necessary to record the operation information of obtaining the full lifecycle information of the target transaction data in the corresponding tracing block.

[0103] In this embodiment, since the main chain stores the address information of the traceability block, at least one traceability block recording all operations performed on the target transaction data can be quickly identified within the traceability block. Furthermore, the entire lifecycle information of the target transaction data can be obtained from this traceability block, achieving data traceability while simultaneously improving data traceability efficiency through the setup of the main chain and the traceability chain.

[0104] Based on any of the above embodiments, in one embodiment, such as Figure 7 As shown, this application also provides a method for uploading transaction data to the blockchain. Taking a transaction system deployed on a computer device as the execution subject as an example, the method includes the following steps:

[0105] Step 710: In response to the transaction data storage request sent by the user, obtain the transaction data to be stored.

[0106] The transaction data to be stored can be real-time transaction data or transaction data to be stored in batches; this application embodiment does not impose any restrictions on this.

[0107] Step 720: Generate the root hash value of the transaction data to be stored, and encrypt the attributes of the transaction data to be stored according to the preset access policy to obtain the ciphertext of the transaction data to be stored.

[0108] In one possible implementation, step 720 can be implemented as follows: obtaining encryption security parameters, and generating a public key and a master key for the transaction data to be stored based on the encryption security parameters; and performing attribute encryption on the transaction data to be stored based on the access policy and the public key to obtain the ciphertext of the transaction data to be stored.

[0109] As an example, in practical applications, users specify the access policy T for transaction data through the terminal, and the transaction system performs attribute encryption on the transaction data according to the access policy T.

[0110] First, output the public key PK based on the security parameter λ. ABE and master key MK ABE As shown in the following formula (4):

[0111] (PK ABE MK ABE )=setup(λ) (4)

[0112] Then, using the access policy T and public key PK ABE The transaction data is encrypted using attributes to obtain the ciphertext EK of the transaction data. Transaction As shown in the following formula (5):

[0113] EK Transaction =Encrypt(PK)ABE (5)

[0114] Step 730: Store the root hash value of the transaction data, the ciphertext of the transaction data to be stored, and the user's information in the main chain.

[0115] The system transmits the root hash value of the transaction data to be stored, the encrypted transaction data, and user information to the blockchain network. After receiving the transaction information, the main chain nodes execute the smart contract and broadcast the above information to other main chain nodes to perform the same operation. The main chain nodes jointly run a consensus algorithm. After reaching a consensus, they write the root hash value and the encrypted transaction data into the blockchain ledger and return the transaction data storage block information and index to achieve evidence storage traceability and consistency verification.

[0116] In this embodiment, after encrypting the transaction data to be stored using a preset access strategy, the root hash value of the transaction data, the ciphertext of the transaction data, and the user's information are stored in the main chain. Thus, attribute encryption enables many-to-one data access, and storing the ciphertext of the transaction data on the blockchain prevents data tampering, ensuring the security of the transaction data.

[0117] In summary, combined with the above embodiments, Figure 8 The data application scenarios shown illustrate the data traceability method provided in this application. The transaction system, query system, main chain, and traceability chain can all be deployed and implemented using computer equipment.

[0118] (1) Transaction data is uploaded to the blockchain

[0119] Users generate transaction data. The transaction system calculates the root hash of the transaction data, encrypts the user's transaction data, and executes a smart contract to upload the root hash and encrypted transaction data to the blockchain. Nodes on the main chain generate new transaction blocks using a consensus algorithm and store the transaction data. Simultaneously, a traceability block corresponding to the main chain transaction block is generated from the blockchain, and the address of the traceability block generated on the traceability chain is returned and stored in the main chain node block header.

[0120] (2) Transaction data query

[0121] When a user requests a transaction query, the query system verifies the user's identity. Once verified, the query system obtains the root hash of the block containing the requested transaction from the transaction system. Then, based on the root hash address returned by the query system, it queries the main chain for the block containing the root hash, retrieves the transaction data query results, and returns the results to the user.

[0122] In addition, during the query process, the main chain system sends a request to the traceability chain to record the query transaction on the chain. The traceability chain then returns the traceability block address and root hash to the main chain.

[0123] (3) Transaction data traceability

[0124] When a user requests a transaction traceability record, the query system verifies the user's identity. Upon successful verification, the query system obtains the root hash of the block containing the transaction from the transaction system. Then, based on the root hash address returned by the query system, it queries the main chain for the block containing the root hash. From the block containing the root hash in the main chain, it obtains the hash address of the traceability chain and queries the traceability chain for the transaction traceability record. The traceability chain then returns the query results.

[0125] The implementation principle and technical effect of the data tracing method in this embodiment are similar to those of the above-described method embodiments, and will not be repeated here.

[0126] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.

[0127] Based on the same inventive concept, this application also provides a data traceability apparatus for implementing the data traceability method described above. The solution provided by this apparatus is similar to the implementation scheme described in the above method; therefore, the specific limitations in one or more data traceability apparatus embodiments provided below can be found in the limitations of the data traceability method described above, and will not be repeated here.

[0128] In one embodiment, such as Figure 9 As shown, a data traceability device 900 is provided, comprising: an acquisition module 910 and a traceability module 920, wherein:

[0129] The first acquisition module 910 is used to respond to the transaction data query request initiated by the user and obtain the target transaction data corresponding to the transaction data query request from the main chain;

[0130] The traceability module 920 is used to obtain the full lifecycle information of the target transaction data from the traceability chain if the root hash value generated based on the target transaction data is different from the root hash value stored in the main chain; the full lifecycle information includes all operation information performed on the target transaction data;

[0131] The main chain is a blockchain that stores transaction data, while the traceability chain is a blockchain that stores information about all operations performed on the transaction data. The blocks in the main chain and the traceability chain correspond one-to-one.

[0132] In one embodiment, a transaction data query request includes a transaction identifier and a user identifier;

[0133] The first acquisition module 910 includes:

[0134] The first acquisition unit is used to obtain the encrypted target transaction data from the main chain based on the transaction identifier;

[0135] The decryption unit is used to obtain decryption information based on the user identifier, and to decrypt the ciphertext of the target transaction data based on the decryption information to obtain the target transaction data.

[0136] In one embodiment, the decryption unit includes:

[0137] The acquisition sub-unit is used to obtain the corresponding user attribute information, public key, and master key based on the user identifier;

[0138] The private key generation subunit is used to generate the user's attribute private key based on the user attribute information, public key, and master key;

[0139] The determined sub-unit is used to identify the attribute private key and public key as decryption information.

[0140] In one embodiment, the tracing module 920 includes:

[0141] The second acquisition unit is used to obtain the address information of the corresponding traceability block in the traceability chain based on the block to which the target transaction data belongs in the main chain.

[0142] The third acquisition unit is used to obtain the full lifecycle information of the target transaction data from the corresponding traceability block based on the address information of the corresponding traceability block.

[0143] In one embodiment, the device 900 further includes:

[0144] The recording module is used to record the operation information of obtaining the full lifecycle information of the target transaction data in the corresponding traceability block.

[0145] In one embodiment, the device 900 further includes:

[0146] The second acquisition module is used to acquire the transaction data to be stored in response to the transaction data storage request sent by the user;

[0147] The encryption module is used to generate the root hash value of the transaction data to be stored, and to perform attribute encryption on the transaction data to be stored according to the preset access policy to obtain the ciphertext of the transaction data to be stored.

[0148] The storage module is used to store the root hash value of the transaction data, the ciphertext of the transaction data to be stored, and the user's information in the main chain.

[0149] In one embodiment, the encryption module includes:

[0150] The fourth acquisition unit is used to acquire encryption security parameters and generate the public key and master key of the transaction data to be stored based on the encryption security parameters.

[0151] The encryption unit is used to encrypt the attributes of the transaction data to be stored according to the access policy and the public key, so as to obtain the ciphertext of the transaction data to be stored.

[0152] Each module in the aforementioned data traceability device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.

[0153] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 10 As shown, the computer device includes a processor, memory, communication interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, carrier networks, NFC (Near Field Communication), or other technologies. When the computer program is executed by the processor, it implements a data traceability method. The display screen can be an LCD screen or an e-ink screen. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the computer device casing, or an external keyboard, touchpad, or mouse.

[0154] Those skilled in the art will understand that Figure 10The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0155] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:

[0156] In response to a user's transaction data query request, retrieve the target transaction data corresponding to the transaction data query request from the main chain;

[0157] If the root hash value generated based on the target transaction data is different from the root hash value stored in the main chain, then the full lifecycle information of the target transaction data is obtained from the traceability chain; the full lifecycle information includes all operation information performed on the target transaction data;

[0158] The main chain is a blockchain that stores transaction data, while the traceability chain is a blockchain that stores information about all operations performed on the transaction data. The blocks in the main chain and the traceability chain correspond one-to-one.

[0159] The computer device provided in this embodiment implements the above steps in a similar manner to the above method embodiments, and will not be described again here.

[0160] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, the computer program performing the following steps when executed by a processor:

[0161] In response to a user's transaction data query request, retrieve the target transaction data corresponding to the transaction data query request from the main chain;

[0162] If the root hash value generated based on the target transaction data is different from the root hash value stored in the main chain, then the full lifecycle information of the target transaction data is obtained from the traceability chain; the full lifecycle information includes all operation information performed on the target transaction data;

[0163] The main chain is a blockchain that stores transaction data, while the traceability chain is a blockchain that stores information about all operations performed on the transaction data. The blocks in the main chain and the traceability chain correspond one-to-one.

[0164] The computer-readable storage medium provided in this embodiment implements the above steps in a similar manner to the method embodiments described above, and will not be repeated here.

[0165] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, performs the following steps:

[0166] In response to a user's transaction data query request, retrieve the target transaction data corresponding to the transaction data query request from the main chain;

[0167] If the root hash value generated based on the target transaction data is different from the root hash value stored in the main chain, then the full lifecycle information of the target transaction data is obtained from the traceability chain; the full lifecycle information includes all operation information performed on the target transaction data;

[0168] The main chain is a blockchain that stores transaction data, while the traceability chain is a blockchain that stores information about all operations performed on the transaction data. The blocks in the main chain and the traceability chain correspond one-to-one.

[0169] The computer program product provided in this embodiment implements the above steps in a similar manner to the method embodiment described above, and will not be repeated here.

[0170] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, or optical storage, etc. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.

[0171] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0172] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.

Claims

1. A data tracing method, characterized in that, The method includes: In response to a user-initiated transaction data query request, the encrypted target transaction data corresponding to the transaction data query request is obtained from the main chain according to the transaction identifier included in the transaction data query request, and a user attribute private key is generated according to the user identifier included in the transaction data query request. The encrypted data is then decrypted using the attribute private key and the public key to obtain the target transaction data. The root hash value generated based on the target transaction data is compared with the root hash value stored in the block header of the main chain; if the root hash value generated based on the target transaction data is different from the root hash value stored in the main chain, the full lifecycle information of the target transaction data is obtained from the traceability chain; the full lifecycle information includes all operation information performed on the target transaction data; The main chain is a blockchain that stores transaction data, and the traceability chain is a blockchain that stores all operation information performed on the transaction data. The blocks in the main chain and the traceability chain correspond one-to-one. Each block in the main chain stores the address information of the corresponding traceability block on the traceability chain. Each block header in the traceability chain contains the hash value of the corresponding main chain block to achieve two-way verification between the main chain and the traceability chain. When a new block is generated on the main chain, a corresponding traceability block is generated on the traceability chain.

2. The method according to claim 1, characterized in that, The step of obtaining decryption information based on the user identifier includes: Based on the user identifier, obtain the corresponding user attribute information, public key, and master key; Generate the user's attribute private key based on the user attribute information, the public key, and the master key; The attribute private key and the public key are identified as the decryption information.

3. The method according to any one of claims 1-2, characterized in that, The process of obtaining the full lifecycle information of the target transaction data from the traceability chain includes: Based on the target transaction data in the block of the main chain, obtain the address information of the corresponding traceability block in the traceability chain; Based on the address information of the corresponding traceability block, obtain the full lifecycle information of the target transaction data from the corresponding traceability block.

4. The method according to claim 3, characterized in that, The method further includes: The corresponding traceability block records the operation information for obtaining the full lifecycle information of the target transaction data.

5. The method according to any one of claims 1-2, characterized in that, The method further includes: In response to a user's request to store transaction data, retrieve the transaction data to be stored; Generate the root hash value of the transaction data to be stored, and perform attribute encryption on the transaction data to be stored according to the preset access strategy to obtain the ciphertext of the transaction data to be stored; The root hash value of the stored transaction data, the ciphertext of the transaction data to be stored, and the user's user information are stored in the main chain.

6. The method according to claim 5, characterized in that, The step of encrypting the transaction data to be stored according to a preset access policy to obtain the ciphertext of the transaction data to be stored includes: Obtain the encryption security parameters, and generate the public key and master key of the transaction data to be stored based on the encryption security parameters; Based on the access policy and the public key, the transaction data to be stored is encrypted using attributes to obtain the ciphertext of the transaction data to be stored.

7. The method according to claim 1, characterized in that, The main chain and the tracing chain store the hash values ​​of the Merkle tree root and parent nodes.

8. A data traceability device, characterized in that, The device includes: The acquisition module is used to respond to a transaction data query request initiated by a user, obtain the ciphertext of the target transaction data corresponding to the transaction data query request from the main chain according to the transaction identifier included in the transaction data query request, generate the user's attribute private key according to the user identifier included in the transaction data query request, and decrypt the ciphertext using the attribute private key and public key to obtain the target transaction data. The tracing module is used to generate a root hash value based on the target transaction data and compare it with the root hash value stored in the block header of the main chain; if the root hash value generated based on the target transaction data is different from the root hash value stored in the main chain, the full lifecycle information of the target transaction data is obtained from the tracing chain; the full lifecycle information includes all operation information performed on the target transaction data; The main chain is a blockchain that stores transaction data, and the traceability chain is a blockchain that stores all operation information performed on the transaction data. The blocks in the main chain and the traceability chain correspond one-to-one. Each block in the main chain stores the address information of the corresponding traceability block on the traceability chain. Each block header in the traceability chain contains the hash value of the corresponding main chain block to achieve two-way verification between the main chain and the traceability chain. When a new block is generated on the main chain, a corresponding traceability block is generated on the traceability chain.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Anti-counterfeiting traceability method and device based on block chain and storage medium

    CN109785132A

  • Tobacco traceability method and device based on blockchain double-chain structure and medium

    CN111125754A

  • Blockchain extension method, blockchain node and blockchain system

    CN111597268A