Multi-dimensional data verifiable query method and query system in block chain scene

By using an extensible hash table and a Merkle multi-tree to build an extensible hash tree (MEHT) in the blockchain scenario, verifiable query of multi-dimensional data is realized and the low query performance caused by the coupling of auxiliary index and verification structure is solved. problem, improving query efficiency and performance.

CN118536142APending Publication Date: 2024-08-23EAST CHINA NORMAL UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310157289.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-02-23
Publication Date
2024-08-23

AI Technical Summary

Technical Problem

Existing verifiable query technology is difficult to support verifiable queries of multi-dimensional data, especially in untrusted environments. The coupling of auxiliary indexes and verification structures results in low query performance and the inability to execute concurrently, affecting query efficiency.

Method used

An extensible hash table is used as the auxiliary index, and the Merkle multi-tree is used as the verification structure. By constructing an extensible hash tree (MEHT), the separation of the data and the verification structure is achieved, allowing the concurrent construction of the verification objects of the auxiliary index and the primary index, improving Query performance.

Benefits of technology

It significantly improves the speed of verifiable query of multi-dimensional data, avoids the delay caused by serialized query, improves the overall query performance, and realizes fast and reliable query of multi-dimensional data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118536142A
    Figure CN118536142A
Patent Text Reader

Abstract

The invention discloses a multi-dimensional data verifiable query method in a block chain scene, which can be used for querying and obtaining primary key information corresponding to non-primary attribute multi-dimensional data and / or obtaining complete information corresponding to the non-primary attribute multi-dimensional data, and comprises the following steps: step 1, initiating query, querying for a pre-constructed verifiable auxiliary index Merkel extensible hash tree MEHT according to the queried non-primary attribute to obtain corresponding primary key information; 2, querying on a main index by using the main key information obtained in the step 1 to obtain complete multi-dimensional data and a verification object VO1, and constructing a verification object VO2 on an auxiliary index MEHT; and 3, returning the query result K and the verification object VO2 of the auxiliary index and the query result d and the verification object VO1 on the main index as verifiable query results, and verifying the correctness and integrity of the query. The invention further discloses a query system for implementing the query method.
Need to check novelty before this filing date? Find Prior Art

Description

Technical field

[0001] The invention belongs to the field of verifiable query technology and relates to a multi-dimensional data verifiable query method and query system in a blockchain scenario. Background technology

[0002] As a decentralized and non-tamperable distributed database, blockchain can achieve trusted data sharing among multiple parties that do not trust each other without going through a trusted third party. However, when users (light nodes in the blockchain system, which only have block header data) query the data in the blockchain, they cannot determine whether the blockchain node is malicious and the correctness of the query results, so verifiable query technology is needed to ensure Query results can be verified. Existing verifiable query technology is generally implemented through the Merkle tree, that is, the parent node stores the hash value calculated after splicing its child nodes, and then uses the hash value to connect from the bottom up to form a Merkle tree. When performing a verifiable query, in addition to returning the query content, a verification object will also be returned, which is the hash of the sibling nodes on the path from the Merkle root node to the leaf node. Users can use the verification object to verify the correctness of the query result (the blockchain will The hash value of the root node of the Merkle tree is stored in the block header, and the user can compare the hash value calculated by the query structure with the one in the block header to determine whether it is correct). The more common Merkle variants include MerklePatriciaTree (MPT), MerkleB+Tree (MBT), etc. However, existing verifiable queries are all for one-way queries and lack verifiable queries for multi-dimensional data.

[0003] In order to support secondary attribute queries on multidimensional data, the most common method is to introduce auxiliary indexes. However, in untrusted environments, auxiliary indexes also need to be verifiable. Existing verifiable indexes generally use a method of fully coupling the verification structure and data. For example, when MPT queries data, it starts from the root node and queries downward, and obtains verifiable objects and data at the same time. In the scenario of multi-dimensional data verifiable query, the first thing needed to query the auxiliary index is the primary key information, so that the complete record can be queried in the primary index. At this stage, there is no need to obtain the verifiable object of the auxiliary index. This kind of data is coupled with the verification structure. As a result, many-to-many verifiable queries can only be executed serially, resulting in low query performance. Contents of the invention

[0004] In order to solve the shortcomings of the existing technology, the purpose of the present invention is to provide a multi-dimensional data verifiable query method in a blockchain scenario. Please refer to the appendix. Figure 6 , can be used to query only the primary key of non-primary attribute multi-dimensional data and / or to query the complete information corresponding to non-primary attribute multi-dimensional data. The method includes the following steps:

[0005] Step 1: Initiate a query, and query the verifiable auxiliary index Merkel Extensible Hash Tree (MEHT) constructed in the present invention according to the non-primary attribute of the query to obtain the corresponding primary key information k. This query will not obtain the MEHT Verify object VO2. MEHT serves as a verifiable auxiliary index that stores the mapping of non-primary attributes to primary keys in multidimensional data.

[0006] Step 2: Use the primary key information k obtained in step 1 to query the primary index to obtain the complete multidimensional data d and verification object (VO1). At the same time, concurrently construct the verification object (VO2) on the auxiliary index MEHT. Among them, the primary index can use, for example, the most widespread verifiable index MPT. The primary index is constructed according to the primary key and stores complete multi-dimensional data. Because MPT is a structure that couples data and verification objects, the multidimensional data d and the MPT verification object VO1 will be obtained together during the query process. There is no overlap between MEHT and the main index, so there will be no concurrency conflicts. Therefore, concurrently constructing the verification object of MEHT in step 2 will not affect the query on the main index.

[0007] Step 3: Return the query result of the auxiliary index (primary key information k) and the verification object VO2, as well as the query result d on the primary index and the verification object VO1 together as the result of a verifiable query. The user can use the verification object to verify the query. correctness and completeness.

[0008] The query result on the auxiliary index is the primary key information k, and the query result on the primary index is the complete multidimensional data record d. The primary key k is the primary key of the multidimensional data record d.

[0009] When the user only needs to obtain the primary key information, only step one can be performed.

[0010] In step one, the blockchain-oriented verifiable auxiliary index Merkle Extensible Hash Tree (MEHT) is constructed in advance. Its characteristic is that the data index and verification structure are separated, so MEHT can query and obtain primary key information faster without the verification structure. (Step 1), so that you can go to the main index for query faster (Step 2). In step two, the verification object construction of the auxiliary index can be concurrent with the query and verification object construction of the primary index, further accelerating the verifiable query performance of multi-dimensional data for non-primary attributes.

[0011] The multi-dimensional data verifiable query method in the present invention realizes the separation of data and verification structures by using an extensible hash table as a data index and a Merkle multi-tree as a verification structure. It is mainly divided into two aspects. One is to use hash The hash table decouples the query and verification structure of data, so that when used as an auxiliary index, the primary key information can be obtained without going through the verification structure, so that the verification information of the auxiliary index and the verification information of the primary index can be constructed concurrently; the second is to use the available Extend the features of the hash table, that is, control the amount of data in the bucket (for example, each bucket can store 512 data items). When a hash conflict occurs, only the conflicting bucket needs to be split and the array rearranged (split). Reduce the impact of hash table expansion on index performance.

[0012] In the present invention, a method for constructing a verifiable auxiliary index Merkle extensible hash tree (MEHT) for blockchain specifically includes the following steps:

[0013] Step 1: Initialize the Merkle extensible hash tree according to parameters, that is, the construction of the data index extensible hash table (EH) and the upper Merkle multi-tree (MMT) of the verification structure, which specifically includes the following sub-steps:

[0014] Step 1-1: Initialize the data index extensible hash table (EH) using initialization parameters including the number of buckets (BucketNums), the capacity of the bucket (MaxEntry), and the length of the segment in the bucket (SegLength), where BucketNums represents the EH initialization The number of buckets, MaxEntry represents the number of data items that each bucket can store in EH, and SegLength is the segment length of the bucket (that is, the storage space of each bucket will be divided into multiple groups, called segments, and the data that each segment can store The number of items is the segment length (SegLength), which is divided into the following sub-steps:

[0015] Step 1-1-1: The bucket is identified by BucketID (BID). Each bucket has multiple slots. The number of slots is determined by the bucket capacity MaxEntry in the initialization parameter. Each slot can store a Key-Value pair (KV right);

[0016] Step 1-1-2: Calculate the global depth (GD) based on the number of buckets. GD means that the last GD bit of the key in the written KV pair will be used to calculate the bucket BID that the KV pair should be stored in. For example, when there are eight buckets, GD is 3(2 3 =8), if the last 3 digits of the Key in the KV pair are 011 2 , then the KV pair will be stored in bucket 3 (011 2 =3 10 );

[0017] In addition, the bucket depth array (BDs) is constructed to represent the depth (BD) corresponding to each bucket. The depth of the bucket BD represents the Key value of all KV pairs stored in the bucket, and the BD bit is the bucket's BID, assuming the depth of bucket 3 is 4, then the last 4 digits of the Key of all KV pairs stored in bucket 3 must be 0011 2 (=3 10 ). The bucket depth array BDs is used because buckets will be split due to hash conflicts, making the depths of different buckets different. The changes in the BDs array and its use in queries can be seen in steps 3-1 and 5. During initialization, the size of the BDs array is determined by BucketNums, and the values ​​are all GD. For example, when there are eight buckets in the initialization, the size of the BDs array is 8, and each item in the array is 3;

[0018] Step 1-1-3: Determine the segment length of each bucket according to the initialization parameter segment length (SegLength), that is, divide all slots in the bucket into multiple segments, each segment is identified by SegID (SID), and the number of slots contained in the segment That is SegLength; determine the segment depth SegBits through SegLength. For example, the segment length is 16, then the segment depth SegBits is 4 (2 4 =16). The segment depth SegBits is used to determine the segment SID of the KV pair that will be stored in the bucket. That is, the first SegBits bits of the Key in the KV pair will be used to determine the segment SID of the KV pair stored in the bucket. For example, when SegBits is 4, Assume that the first four digits of the KV pair Key value are 0001 2 (=1 10 ), then the KV pair will be stored in segment 1 of the bucket. The SegBits before the Key value of all KV pairs stored in the same segment are the same; the segment is mainly used to keep the data in the bucket in order and speed up data search. And reduce the computational overhead of bucket hashing;

[0019] Step 1-2: Create a corresponding fingerprint array for each bucket. Each fingerprint array and bucket have the same number of slots, which are used to record the fingerprint of the data stored in each slot in the bucket. The fingerprint of the data is generated using a hash function. n bits, where n can be determined by the user. The fingerprint data of the bucket is resident in memory. Before retrieving the data in the bucket, the fingerprint array corresponding to the bucket will be retrieved for filtering, thereby reducing disk read operations and improving query performance;

[0020] Step 1-3: Initialize the upper Merkle multi-tree, including the following sub-steps:

[0021] Step 1-3-1: Construct a corresponding leaf node for each bucket. The node stores the hash value of each segment of the bucket. The hash value is the root of the Merkle binary tree constructed from the KV pairs stored in each segment in slot order. The node hash is obtained, the Merkle binary tree of the segment will not be stored, and will only be rebuilt when needed, and the hash value is initialized to Nil;

[0022] Step 1-3-2: Determine the number of branches of the intermediate nodes of the upper Merkle multi-tree based on the initialization parameter branch number (Branch), and generate intermediate nodes by layer. Each intermediate node stores the hash value of the child node;

[0023] Step 2: When a new KV pair is written, it is necessary to determine the storage bucket and its location in the bucket based on the Key value of the data, and update the verification structure, which specifically includes the following sub-steps:

[0024] Step 2-1: Based on the Key value in the KV pair, determine the bucket BID and segment SID that need to be written, including the following sub-steps:

[0025] Step 2-1-1: Set the depth of Key to GD;

[0026] Step 2-1-2: Use the last BD bit of the Key value to calculate the bucket BID, and use this BID to check the BDs array;

[0027] Step 2-1-3: If BDs[BID] does not exist, or BDs[BID] is less than BD, then BD is reduced by 1 and repeat step 2-1-2:

[0028] Step 2-1-4: If BDs[BID] is equal to BD, get the bucket BID that should be written;

[0029] Step 2-1-5: Use the first SegBits of the Key value to calculate the segment SID that should be written;

[0030] Step 2-2: Check the segment corresponding to the bucket obtained in step 2-1 to determine whether the KV pair can be written, including the following sub-steps:

[0031] Step 2-2-1: Calculate the fingerprint of the Key, read the fingerprint array of the bucket created in Step 1-2, and compare the fingerprint of the Key with the fingerprint of each slot in the segment;

[0032] Step 2-2-2: If the fingerprint of Key is different from the fingerprint in the fingerprint array, compare the next slot;

[0033] Step 2-2-3: If the fingerprint of the Key is the same as the fingerprint in the fingerprint array, read the data in the slot of the bucket BID and compare the Key values ​​of both parties. If the Key values ​​are the same, it is an update operation, and the Value of the new KV pair is updated. At this slot, data writing is completed; if the Key values ​​of both parties are not the same, continue to check the fingerprints in the fingerprint array;

[0034] Step 2-2-4: If the existing data Key value in the segment is different from the KV pair Key to be written, select an idle slot in the segment as the data writing location and proceed to step 2-3; if If there is no free space, it means that a hash conflict has occurred. Go to step 3;

[0035] Step 2-3: Write the KV pair into the slot corresponding to the SID segment of the bucket, and write the fingerprint of the KV pair into the position corresponding to the fingerprint array. The data writing is completed;

[0036] Step 3: When the new KV pair cannot be written into the corresponding bucket BIDold, it means that a hash conflict has occurred. The corresponding segment of the bucket BIDold is full, and a split operation is required. Split specifically includes the following sub-steps:

[0037] Step 3-1: Calculate the new bucket BIDnew generated by split, and update the corresponding metadata (such as GD, BDs, etc.), including the following sub-steps:

[0038] Step 3-1-1: Calculate the new bucket BIDnew based on the conflicting bucket BIDold, and create the corresponding fingerprint array and leaf node for the bucket BIDnew. Assume that a hash conflict occurs in bucket 3, and the depth of bucket 3 is 2. by in barrel 3(11 2 ) before adding one bit to get the new bucket BIDnew, which is 7(111 2 ,011 2 for the original bucket 3);

[0039] Step 3-1-2: Read the BDold corresponding to the bucket BIDold from the BDs array. If BDold is less than GD, then update BDold to BDold+1; if BDold and GD are equal, then update both BDold and GD to BDold+1 ;Set the BD of BIDnew to the updated BDold;

[0040] Step 3-2: Read all the KV pairs stored in the BIDold slot of the conflicting bucket, and reclassify each KV pair, including the following sub-steps:

[0041] Step 3-2-1: Read the BDold corresponding to the bucket BIDold from the BDs array, calculate the last BDold bit of the Key value to get the KV corresponding to the bucket BIDsplit that should be written;

[0042] Step 3-2-2: If BIDsplit is equal to BIDold (that is, the KV pair is still in the bucket BIDold), no operation is performed on the KV pair; if BIDsplit is BIDnew, the contents of the fingerprint array corresponding to the slot in the bucket BIDold are deleted. , the KV pairs in the bucket BIDold are not deleted. Because judging whether there is content in the bucket's slot is checked through the fingerprint array, the content in the bucket BIDold slot is not deleted here to reduce the write operation to the disk, and the KV pair is written to the slot corresponding to the bucket BIDnew. The fingerprint of the KV pair is written into the fingerprint array of the bucket BIDnew, and the re-division of the KV pair is completed;

[0043] Step 3-3: Rewrite the KV pair that failed to be written in step 2. If the writing still fails, repeat step 3 for the bucket that caused the hash conflict until it can be written;

[0044] Step 4: Recalculate hash values ​​for all buckets that have been written to, including buckets that have been split, and update the upper Merkle multi-tree, including the following sub-steps:

[0045] Step 4-1: For each bucket, read all written segments, reconstruct the Merkle binary tree for each segment, and write the hash value of the root node of the Merkle binary tree to the corresponding leaf node;

[0046] Step 4-2: According to the bucket BID, obtain all the intermediate nodes in the upper Merkle multi-tree corresponding to the bucket, and update the hash values ​​stored in these intermediate nodes from bottom to top.

[0047] The present invention also provides a system for implementing the above verifiable query method. The system includes:

[0048] Input module, verifiable query module, output module;

[0049] The input module is used to input the non-primary attribute information to be queried into the system;

[0050] The verifiable query module is used to query the non-primary attribute information based on METH to obtain the primary key information corresponding to the non-primary attribute multi-dimensional data and / or obtain the complete information corresponding to the non-primary attribute multi-dimensional data;

[0051] The output module returns the query results for subsequent verification of the correctness and completeness of the query.

[0052] Compared with the existing technology, the present invention has the ability to construct the auxiliary index verifiable object and the main index verifiable object concurrently when performing a verifiable query on the secondary attributes, thereby increasing the speed of the multi-dimensional data verifiable query by about 2 times. , thus avoiding the high query delay caused by serialized queries. Using the decoupling method of data index and verifiable structure to construct an auxiliary index better solves the problem of using the coupling structure as an auxiliary index, which causes the query of the auxiliary index to obtain the primary key information and verifiable objects at the same time, making the query of the primary key and The construction of the auxiliary index verification object is separated, which enables faster querying of the main index and improves the overall query performance. Description of the drawings

[0053] Figure 1 This is a schematic structural diagram of the specific Merkle expandable hash tree METH of the present invention.

[0054] Figure 2 Schematic diagram for MEHT data writing.

[0055] Figure 3 Schematic diagram of split operation for MEHT.

[0056] Figure 4 Schematic diagram for verifiable queries on MEHT.

[0057] Figure 5(1) is a schematic diagram of using MPT as an auxiliary index.

[0058] Figure 5(2) is a schematic diagram of using MEHT as an auxiliary index.

[0059] Figure 6 Verifiable query flow chart for multidimensional data when using MEHT as a secondary index. Detailed implementation

[0060] The invention will be further described in detail with reference to the following specific embodiments and drawings. The process, conditions, experimental methods, etc. for implementing the present invention, except those specifically mentioned below, are common knowledge and common sense in the field, and the present invention has no special limitations.

[0061] The present invention designs a blockchain-oriented verifiable auxiliary index Merkel extensible hash tree (MEHT) for the verifiable query method of multi-dimensional data, which solves the multi-dimensional problem caused by the coupling of the existing verifiable index data and the verification structure. The data validates query inefficiencies. Using an extensible hash table as the data index and the Merkle multi-tree as the upper-level verification structure, a Merkle multi-tree leaf node is generated for each bucket of the extensible hash table, and the verification structure is built from the bottom up, making MEHT When used as an auxiliary index, the primary key information can be directly obtained by querying the extensible hash table and queried in the primary index. Then the verifiable query of the primary index and the verifiable object construction of the auxiliary index can be performed concurrently, avoiding the need for data and verification information. The query serialization problem caused by coupled verifiable indexes greatly improves the performance of verifiable queries on multidimensional data.

[0062] In the present invention, a multi-dimensional data verifiable query method based on Merkel extensible hash tree in a blockchain scenario can be used to query only the primary keys of non-primary attribute multi-dimensional data and / or to query non-primary attributes. Complete information corresponding to attribute multidimensional data.

[0063] When MEHT is used as a secondary index, it stores the mapping of non-primary attributes of multidimensional data records to primary keys. Suppose there is multidimensional data <ID card, name, age, address>, in which ID card is the primary key and name is a non-primary attribute. Then when MEHT is used as an auxiliary index, it will store the mapping from name to ID card. Suppose you only want to query a person's ID number, then it is a covering index query; if you want to query a person's complete information, then it is the corresponding query when METH is used as an auxiliary index. Querying only the primary key of multidimensional data (that is, covering index) is a common situation in multidimensional data query. Covering index is considered in common databases such as MySQL.

[0064] When only querying the primary key information corresponding to non-primary attributes through MEHT, that is, only querying the primary key without querying the complete multi-dimensional data record (that is, covering the index), it can be completed only on MEHT, which includes the following steps:

[0065] Step 1: Calculate the bucket and segment where the data should be stored based on the Key value of the data to be queried;

[0066] Step 2: Check whether the Key value exists based on the BID and SID obtained in step 1, including the following sub-steps:

[0067] Step 2.1: Calculate the fingerprint of the Key value, read the fingerprint array corresponding to the bucket BID, and compare the fingerprint of the Key value with the fingerprints in all slots in the segment of the fingerprint array;

[0068] Step 2.2: If the fingerprints are the same, read the data in the slot corresponding to the bucket, and compare the Key value of the data in the slot with the data Key value of this query. If the Key values ​​are the same, the data query ends; otherwise, continue to check other slots. fingerprint;

[0069] Step 2.3: If the fingerprints or keys of all slots in the segment do not match the queried Key value, the queried data does not exist and the end of the query can be verified;

[0070] Step 3: Based on the BID and SID obtained in step 1, construct the verification object VO2 on MEHT, which specifically includes the following steps:

[0071] Step 3.1: Read all the data contents in the corresponding segment of the bucket, reconstruct the Merkle binary tree, and obtain the verification object VO of this Merkle binary tree based on the location of the query data. seg (That is, the way Merkle tree constructs verification objects);

[0072] Step 3.2: Read the leaf node corresponding to the bucket, and use the hash value corresponding to the segment SID in the leaf node as the verification object VO leaf ;

[0073] Step 3.3: Based on the BID and BD information, obtain the search path of the upper Merkle multi-tree corresponding to the bucket to construct the verification object VO merkle ;

[0074] Step 4: Combine the data obtained in step 2 and the VO2(VOseg +VO leaf +VO merkle ) is returned as the result of a verifiable query;

[0075] When using MEHT as a verifiable auxiliary index, you need to obtain the primary key information on METH and then go to the primary index to query the complete record and query the multidimensional data records corresponding to non-primary attributes, which specifically includes the following sub-steps:

[0076] Step a: When a write occurs, write the new data record to the primary index (the primary index is indexed according to the primary key. The primary index here can be any verifiable index structure, such as MPT, etc.), and use the secondary attributes and primary keys as The KV pair is written to MEHT (the secondary attribute is the Key in MEHT, and the primary key is the Value in MEHT). For the specific writing steps of MEHT, refer to the initialization process of Merkel's extensible hash tree;

[0077] Step b: When using secondary attributes for verifiable query, first use the secondary attributes as Key to query MEHT to obtain the primary key information (same as step 2). If the secondary attributes exist, use the primary key obtained from querying MEHT to go to the primary index for verifiable query. Verify the query. At the same time, the verification object VO2 of MEHT is constructed concurrently (same as step 3); if the secondary attribute does not exist, the verification query ends.

[0078] See attached Figure 1 , the present invention supports efficient verifiable multi-dimensional data query and decouples the data from the verification structure. The initialization process of the Merkle extensible hash tree is carried out according to the following steps:

[0079] Step 1: Initialize the scalable hash table and determine the number and capacity of its buckets. The number of initialized buckets in the figure is 4, each is identified by BID as [0-3], and the bucket capacity is initialized to 8, that is, each bucket Contains slots [0-7], each slot can store a KV pair;

[0080] Step 2: Calculate GD based on the number of buckets. The number of buckets in the figure is 4, so GD is 2 during initialization (2Bit can represent 0-3). GD will be used to calculate the KV corresponding to the bucket BID of the storage, such as writing KV The correct Key is 000011 2 , followed by GD bit 11 2 , then this KV pair should be stored in bucket 3; construct an array of BDs based on GD to store the Depth of each bucket, where the BDs are initialized to [2,2,2,2] (for convenience, in the figure BDs are expressed as <BID, BD format>, that is, <0, 2> means that the BD of bucket 0 is 2). When the bucket is split due to a hash conflict, the Depth of different buckets will be different. For details, please refer to the attachment. Figure 3 ;

[0081] Step 3: Divide the slots in the bucket into multiple segments according to the segment length. The segment length in the figure is 4, that is, every four slots in the bucket is a segment. Each segment is identified by SID as [0-1]; calculate SegBits based on the number of segments. , the number of segments in the figure is 2, so SegBits is initialized to 1 (1Bit can represent 0-1), SegBits will be used to calculate the KV corresponding to the segment SID stored, for example, the Key is 000011 2 When, its first SegBits bit is 0 2 , combined with step 2, it can be obtained that this KV correspondence should be stored in segment 0 of bucket 3; the segment is mainly used to keep the data part of the bucket in order and speed up data search, for example, the search key is 000011 2 At this time, you only need to check segment 0 of bucket 3 (including four slots, up to four reads) to know whether the key exists, reducing data reading operations on the disk (if there is no segment, you need to check all slots, up to eight times read);

[0082] Step 4: Create a corresponding fingerprint array for each bucket. The fingerprint array has the same number of slots as the buckets. Each slot of the fingerprint array records the fingerprint of the KV pair stored in the corresponding bucket slot. The bucket is empty during initialization and the fingerprint array It is also empty. The figure only shows the fingerprint array of bucket 0. The array stores the key 001000 in slot 0. 2 The fingerprint of the KV pair, i.e. 0010 2 (The first 4 digits of the Key are used here as the fingerprint for convenience of description, and other methods can also be used to calculate the fingerprint);

[0083] Step 5: Initialize the upper Merkle multi-tree. First, generate leaf nodes according to the number of buckets. In the figure, 4 leaf nodes [0-3] are generated corresponding to buckets [0-3]. Each leaf node stores the hash value of each segment in the bucket. H30 in leaf node 3 in the figure indicates that it records the hash value of segment 0 of bucket 3. H30 is obtained by hashing the root of the Merkle binary tree composed of segment 0 of bucket 3. This Merkle binary tree does not store , it is rebuilt every time it is needed. The hash value stored in the leaf node is initialized to Nil. When the data in the segment changes, the Merkle binary tree is reconstructed and the leaf node content is updated;

[0084] Step 6: Determine the number of branches of the upper Merkle multi-tree based on the number of branches (Branch) in the initialization parameters. The number of branches in the figure is 2, that is, each intermediate node will have two child nodes, and the slot of the intermediate node is [0-1 ] store the hash values ​​of the two child nodes respectively. Slot 0 of the middle node 0 in the figure stores the hash value of the middle node 1, slot 1 stores the hash value of the middle node 2, and the middle nodes 1 and 2 serve as the last layer. The intermediate node stores the hash value of the leaf node; starting from the root node (i.e., intermediate node 0) and walking to leaf node 2, the intermediate node slots passed are 0 (slot 0 of intermediate node 0) and 1 (intermediate node 1) slot 1), after splicing is 10 2 (The slot numbers passed from the root node to the leaf nodes are obtained by adding them in front of the existing numbers), that is, bucket 2 (10 2 ), so all the intermediate nodes related to the BID can be calculated through the BID of the bucket, and the BID of the bucket can also be obtained through the path of the intermediate nodes traveled;

[0085] See attached Figure 2 , a verifiable auxiliary index Merkle extensible hash tree for blockchain according to the present invention. When data writing occurs, the writing process is carried out according to the following steps:

[0086] Step 1: According to the written KV pair <001111 2 , the Key value in value4> uses GD and BDs to determine the bucket BID. In the figure, GD is 2, and the last two digits of the Key value are 11. 2 (That is, BID is 3), then compare BDs[BID] and GD, which are equal here, so bucket 3 is the bucket to be written to (if not equal, you need to use GD-recalculate the comparison, for details, please refer to the steps of the invention) 2);

[0087] Step 2: SegBits in the picture is 1, and the first digit of the Key value is 0 2 , combined with step 1, this KV correspondence should be written to segment 0 of bucket 3;

[0088] Step 3: Check fingerprint array 3 corresponding to bucket 3 and find that all fingerprints in fingerprint array 3 are consistent with the fingerprint of Key value 0011 2 Does not match (if it matches, you need to read the contents of the bucket for comparison. If the key is the same, update and write, otherwise continue to check), so you need to find a free slot in segment 0 of bucket 3 for writing, which is slot 3 in the picture. , and set fingerprint 0011 2 Write to slot 3 of fingerprint array 3; if there is no free slot, refer to the attached Figure 3 ;

[0089] Step 4: After writing or updating the KV pair into the bucket, update the hash values ​​of the leaf nodes and intermediate nodes corresponding to the bucket where the write occurred. Segment 0 of bucket 3 in the figure has been written, so Merkle is reconstructed for this segment. Binary tree, h2 and h0 in the new Merkle binary tree have been updated compared to before, because slot 3 is written, and other slots of segment 0 are not written. After that, the upper Merkle multi-tree is updated according to the root node hash of the Merkle binary tree. , namely H30, HashL3 and Hash2, data writing is completed;

[0090] This invention is applied to the blockchain environment. Data writing is based on blocks. One block contains multiple KV pairs. Therefore, the update of the upper Merkle multi-tree will result in all KV pairs in the block being written to the available This is done after expanding the hash table, instead of updating the Merkle multi-tree every time a KV pair is written, thereby reducing the overhead caused by updating the verification structure.

[0091] See attached Figure 3 , the data index used by the present invention is an expandable hash table. When a hash conflict occurs in a bucket, only the conflicting bucket performs a split operation. The split process is carried out according to the following steps:

[0092] Step 1: When the written KV pair cannot find a free slot in the corresponding bucket, it means that a hash conflict has occurred, and a split operation is required to expand the hash table. Figure 3 for attached Figure 2 On the basis of continuing to write KV pair <010111 2 ,value5>, the last 2 bits of the Key value (GD value before split) are 11 2 , the first 1 (SegBits) bit is 0 2 , however, there is no Key value 010111 in segment 0 of bucket 3. 2 KV pair and there is no free slot, so the split operation needs to be performed on bucket 3;

[0093] Step 2: The BID of the bucket that needs to be split is 3 (11 2 ), the new bucket generated by split is calculated by adding one bit before the BID of the original bucket. The added bit can be 0. 2 or 1 2 , increase by 0 2 Then it is the original bucket 3 (011 2 ), increase by 1 2 Then it is the newly generated bucket 7 (111 2 ); Create a new leaf node 7 and fingerprint array 7 for bucket 7, both initialized to Nil, and create a new intermediate node 3 as the parent node of leaf nodes 3 and 7;

[0094] Step 3: Now you need to determine whether it should be stored in bucket 3 or 7 by calculating the last 3 digits of the Key value, so update the GD and BDs arrays. In this example, BDs[3] and GD are the same, so BDs[3] and GD is increased by one, and GD and BDs[3] in the figure are both 3;

[0095] Step 4: Read all the KV pairs in the bucket where the hash conflict occurs and reclassify them. The picture shows all the KV pairs in bucket 3. The last three bits of the KV pairs in slots 0 and 2 are 011. 2 , so it is still in bucket 3, no need to divide; the last three digits of the KV pair Key value in slot 1 and slot 3 are 111 2 , needs to be divided into bucket 7, then write the Key value 000111 in segment 0 of bucket 7 2 and 001111 2 KV pair, and write the fingerprint in the slot corresponding to fingerprint array 7; delete the contents of slot 1 and slot 3 in fingerprint array 3, but do not delete the contents of slot 1 and slot 3 in bucket 3, thereby reducing the impact on the disk write operation. This will not affect subsequent operations, because the next time bucket 3 is queried, fingerprint array 3 has no content in slots 1 and 3, and it will be considered that there is no content in slots 1 and 3 of bucket 3. If it is a write operation, it will Directly overwrites the original contents in slots 1 and 3, so the correctness is not affected;

[0096] Step 5: Continue writing the KV pair that failed due to hash conflict, Key value 010111 2 The last three digits are 111 2 , the first digit is 0 2 , there is a free slot in segment 0 of bucket 7, so it is written to slot 2 of bucket 7 and fingerprint 0101 2 Write to slot 2 of fingerprint array 7;

[0097] Step 6: Update the upper-layer Merkle multi-tree based on data writing and newly generated buckets. In the figure, because bucket 3 has data deleted, bucket 7 is newly generated and has data written, so the segments of bucket 3 and bucket 7 are recalculated. The hash value is updated to leaf nodes 3 and 7, and then the update is passed upward, that is, H30, H70, HashL3, HashL7, Hash3 and Hash2 need to be updated;

[0098] If after a split operation, the previously failed KV pair still cannot be written, then determine the bucket BID that failed to write now, and continue the split operation on this BID until the KV pair can be written; after a split occurs, go from intermediate node 0 The slot numbers passed to leaf node 3 are 1 (slot 1 of intermediate node 0), 1 (slot 1 of intermediate node 2) and 0 (slot 0 of intermediate node 3), which can be spliced ​​to get 011 2 , which is bucket 3, so the split operation does not affect the correspondence between intermediate nodes and buckets.

[0099] See attached Figure 4 , when performing a verifiable query on MEHT, you need to first use the Key value to be queried to determine the possible buckets and segments of the KV pair, and then check the corresponding fingerprint array. If it exists, read the data and obtain the corresponding verifiable structure as verification. The object is returned, otherwise the query content does not exist. The query can be verified according to the following steps:

[0100] Step 1: Key value 000111 in the picture 2 Perform a verifiable query, use GD as 3 to get the bucket BID as 7, and BDs[7] is the same as GD, so bucket 7 is a possible bucket, and the first digit of the Key value is 0 2 , so check segment 0 of bucket 7; check fingerprint array 7, where the fingerprint of slot 0 is the same as the fingerprint of the Key value. Read the KV pair in slot 0 of bucket 7, compare its Key value with the queried Key value, and find are equal, so slot 0 is the KV pair of the query;

[0101] Step 2: Read all KV pairs in segment 0 of bucket 7, reconstruct the Merkle binary tree, and use the hash value of slot 1 and h2 as VO seg , H71 in leaf node 7 is used as VO leaf , HashL3 in intermediate node 3, HashL2 in intermediate node 2 and Hash1 in intermediate node 0 as VO merkle , which is the verification object VO2 returned by this verifiable query;

[0102] Step 3: After receiving the content returned by the query, the user can verify its correctness based on the query results. In the example in the figure, the user can use the returned KV pair <000111 2 , value2> and the hash value of slot 1 are calculated to get h1, use h1 and h2 to calculate h0 and then get H70, go up in order until the hash value of intermediate node 0 is obtained, and store this hash value with the blockchain in The hash values ​​in the block header are compared. If they are equal, the returned result is correct, otherwise it is an error;

[0103] Refer to Figure 5. When using MEHT as an auxiliary index, for queries on secondary attributes, the verification objects of the auxiliary index and the primary index can be constructed concurrently, which can greatly improve the performance of many-to-many verifiable queries; Figure 5(1)( 2) Multidimensional data verifiable query processes using MPT and MEHT proposed by the present invention as auxiliary indexes, where the primary index is an index from the primary key to the record, and the auxiliary index is an index from the secondary attributes to the primary key;

[0104] In Figure 5(1), MPT is used as an auxiliary index. It can be seen that the data and verification structure of MPT are completely coupled. The secondary attribute is used as the key in the auxiliary index MPT, and the primary key information is stored in the leaf node. Step (A) Query downwards from the root node of the auxiliary index MPT to the leaf nodes to obtain the primary key information and verification object, and steps (A) and (B) use the primary key information to query the entire record in the primary index MPT are completely serial. , however step (B) only requires the primary key information obtained in (A) and does not need its verification object. Therefore, the way the data and verification structure are coupled affects the performance of the verifiable query;

[0105] Figure 5(2) shows the use of MEHT of the present invention as an auxiliary index. The data and verification structure of MEHT are decoupled. The auxiliary index MEHT stores <secondary attribute, primary key> as a KV pair in the expandable hash table. The data The query can be implemented through an extensible hash table. The upper Merkle multi-tree is only a verification structure. Therefore, the verifiable many-to-many query is mainly divided into the following steps:

[0106] Step 1: Use the secondary attribute as the key to search from the expandable hash table of the auxiliary index MEHT to obtain the primary key information, which is step (A) in Figure 5(2);

[0107] Step 2: Use the primary key obtained in step 1 to query the complete record in the primary index MPT and obtain the verification object of the MPT, which is step (B) in Figure 5(2). At the same time, use the bucket BID where the secondary attributes obtained in step 1 are located. Concurrently obtain the verification object on MEHT, which is step (C) in Figure 5(2);

[0108] Because step (A) in 5(2) only needs to obtain data in the hash table, it is much faster than step A in Figure 5(1), and the overall query performance is higher than Figure 5(1). Compared with using MPT as an auxiliary index, the MEHT of the present invention can convert serialized queries into partial concurrent execution, which greatly improves the performance of many-to-many verifiable queries.

[0109] The protection content of the present invention is not limited to the above embodiments. Without departing from the spirit and scope of the inventive concept, changes and advantages that those skilled in the art can think of are included in the present invention, and are protected by the appended claims.

Claims

1. A multi-dimensional data verifiable query method in a blockchain scenario, characterized in that: The method is used to query and obtain primary key information corresponding to non-primary attribute multidimensional data and / or obtain complete information corresponding to non-primary attribute multidimensional data, and includes the following steps: Step 1: Initiate a query and query the pre-built verifiable auxiliary index Merkel extensible hash tree MEHT according to the non-primary attribute of the query to obtain the corresponding primary key information k; Step 2: Use the primary key information k obtained in step 1 to query the primary index to obtain the complete multidimensional data d and verification object VO1, and construct the verification object VO2 on the auxiliary index MEHT; Step 3: Return the query result k and verification object VO2 of the auxiliary index, as well as the query result d and verification object VO1 on the primary index as the result of the verifiable query to verify the correctness and completeness of the query.

2. The method according to claim 1, characterized in that In the Merkle extensible hash tree MEHT, data index and verifiable structure are decoupled, data index uses an extensible hash table located at the lower layer, and the verifiable structure uses a Merkle multi-branch tree located at the upper layer; the construction of the verification object of the auxiliary index is concurrent with the query and construction of the verification object of the primary index.

3. The method according to claim 2, characterized in that The Merkle extensible hash tree MEHT is constructed by the following steps: Step 1: Initialize the Merkle extensible hash tree according to the parameters, that is, construct the lower-level extensible hash table and the upper-level Merkle multi-branch tree; Step 2: When a new Key-Value pair is written, the storage bucket and its location in the bucket are determined based on the Key value of the data, and the data is written to the corresponding location. Step 3: When the new KV pair cannot be written into the corresponding bucket BIDold, it means that a hash conflict has occurred and the corresponding segment of the bucket BIDold is full, so a split operation is performed; Step 4: Recalculate the hash values ​​for all buckets that have been written, including buckets that have been split, and update the upper Merkle multitree.

4. The method according to claim 3, characterized in that Step 1 further comprises the following steps: Step 1-1: Initialize the data index extensible hash table using initialization parameters including the number of buckets BucketNums, the capacity of the bucket MaxEntry, and the segment length SegLength in the bucket; Step 1-2: Create a fingerprint array for each bucket in the extensible hash table. Each fingerprint array has the same number of slots as the bucket, which is used to record the fingerprint of the data stored in each slot in the bucket. Step 1-3: Initialize the upper Merkle multitree.

5. The method according to claim 3, characterized in that: Step 2 further comprises the following steps: Step 2-1: Determine the bucket BID and segment SID to be written based on the Key value in the KV pair; Step 2-2: Check the segment corresponding to the bucket obtained in step 2-1 to determine whether the KV pair can be written. If it can be written, select a free slot in the segment as the data writing location; if the segment is full, it means that a hash conflict has occurred, split the bucket BID, and jump to step 3; Step 2-3: Write the KV pair into the slot corresponding to the SID segment of the bucket, and write the fingerprint of the KV pair into the corresponding position of the fingerprint array. The data writing is completed.

6. The method according to claim 3, characterized in that Step 3 further includes the following steps: Step 3-1: Calculate the new bucket BIDnew generated by split, and update the metadata including the depth of the Key and the bucket depth array; Step 3-2: Read all KV pairs stored in the BIDold slot of the conflicting bucket, and re-partition each KV pair; Step 3-3: Rewrite the KV pair that failed to be written due to hash conflict in step 2. If the writing still fails, repeat step 3 for the bucket that caused the hash conflict until it can be written.

7. The method according to claim 3, characterized in that Step 4 further includes the following steps: Step 4-1: For each bucket, read all segments that have been written, reconstruct the Merkle binary tree for each segment, and write the hash value of the root node of the Merkle binary tree into the corresponding leaf node; Step 4-2: According to the bucket BID, obtain all the intermediate nodes in the upper Merkle multi-branch tree corresponding to the bucket, and update the hash values ​​stored in these intermediate nodes.

8. A system for implementing the method according to any one of claims 1 to 7, characterized in that: The system comprises: Input module, verifiable query module, output module; The input module is used to input the non-primary attribute information to be queried into the system; The verifiable query module is used to obtain the primary key information corresponding to the non-primary attribute multidimensional data and / or obtain the complete information corresponding to the non-primary attribute multidimensional data based on the METH query of the non-primary attribute information; The output module returns the query result for subsequent verification of the correctness and completeness of the query.