A verifiable random lottery method based on Merkle tree and sorting
By using Merkel tree and sorting methods during the lottery process, random seeds are generated and verified, and the problems of inability to reproduce and insufficient transparency in the existing technology are solved, and the verifiability and fairness of the lottery results are achieved.
Patent Information
- Application Number
- CN202311405787.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-27
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2043-10-27
AI Technical Summary
The prior art cannot reproduce random seeds, and the random seeds are not related to user data, resulting in insufficient fairness and transparency of lottery results.
The Merkel tree and sorting method are used to construct the Merkel tree through the personal data and random timestamps of the participants, and random seeds are generated using the SM3 algorithm, and sort and verify them to ensure the verifiability of the lottery results.
The verifiability and fairness of the lottery results have been achieved, the user participation and transparency of the results have been improved, and the persuasiveness of the lottery has been enhanced.
Smart Images

Figure CN117218759B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of random algorithms and relates to a verifiable random lottery method based on Merkle trees and sorting. Background Art
[0002] In order to better achieve a fair distribution of market resources, lottery operations are increasingly being used for scenarios such as buying houses, cars, and schooling for school-age children in large cities. The large-scale lottery operations currently used can be roughly divided into two types: the first is to use random lottery balls to generate random seeds, and then call classic random number algorithms (rand and other functions) to generate random indicators to obtain lottery results, such as the housing qualification lottery operation in Beijing; the second is to directly call classic random number algorithms on the computer to generate random indicators to obtain lottery results, and the random seeds are generated using the entropy pool of the operating system, such as the housing qualification lottery operation in Hangzhou. However, both types of operations have the following weaknesses:
[0003] 1. Unable to reproduce the random seed. For the first type, since the lottery ball is a one-shot process, it cannot be reproduced. For the second type, the entropy source in the operating system's entropy pool is various non-deterministic device events, which is also impossible to reproduce.
[0004] 2. The random seed is unrelated to user data. Whether it is the lottery ball or the operating system entropy pool, its random seed is unrelated to the data of each lottery participant, resulting in low participation of each participant in the lottery.
[0005] As we all know, the Merkle tree is a binary hash tree and a classic algorithm for data verification. It can provide O(log2 n) proof to verify whether a member is in a set of n elements. Therefore, by combining the Merkle tree with a sorting method, we propose a new verifiable lottery algorithm. Summary of the Invention
[0006] To address the above-mentioned technical problems in the prior art, the present invention proposes a verifiable random lottery method based on Merkle trees and sorting, which can achieve subsequent verification of lottery results and fundamentally enhance the fairness and persuasiveness of lottery results. The specific technical solution is as follows:
[0007] A verifiable random lottery method based on Merkle tree and sorting, comprising the following steps:
[0008] Step 1: Determine the number of winners and participants in the lottery;
[0009] Step 2: Each party submits personal data;
[0010] Step 3: The lottery begins, and each participant clicks to confirm the random timestamp;
[0011] Step 4: The system records the personal data and random timestamp of each participant, constructs a Merkle tree using the SM3 algorithm, and uses the root of the Merkle tree as the random seed;
[0012] Step 5: Use the random seed as input and iteratively run the SM3 algorithm to obtain the random string of each participant;
[0013] Step 6: Sort all random strings from largest to smallest;
[0014] Step 7: The lottery winner is selected based on the given number of winners, and the lottery ends;
[0015] Step 8: Lottery random seed verification: A participant resubmits the data, and the system uses the membership proof function of the Merkle tree to verify the legitimacy of the random seed;
[0016] Step 9: Lottery result verification: Reproduce and verify the lottery result by iteratively running the SM3 algorithm on a valid random seed.
[0017] Furthermore, the step 1 includes the following specific steps:
[0018] Step 1.1: Determine the number of winners in the lottery, denoted as m;
[0019] Step 1.2: Determine the participants in the lottery, denoted as P0,…,P n-1 , the total number of participants is n, and m≤n is required.
[0020] Furthermore, the step 2 is specifically as follows: each participant P i Submit your own data D i Given a lottery system, where i=0,1,…,n-1.
[0021] Furthermore, the step 3 includes the following specific steps:
[0022] Step 3.1: The lottery starts and the time period is set;
[0023] Step 3.2: Each participant clicks on the system to confirm the lottery within the time period to determine their respective lottery timestamps t i .
[0024] Furthermore, the step 4 includes the following specific steps:
[0025] Step 4.1: The system records the data D of each participant i With random timestamp t i ;
[0026] Step 4.2: Calculate the number of layers in the Merkle tree For i = 0, 1, ..., n-1, let For i=n,n+1,…,2 d -1, Thus we get the Merkle tree 2 d leaf nodes When the number of layers is d, for i=0,1,…,2 d-1 -1, perform hash merge operation Where || represents the concatenation of two data, thus obtaining the 2 d-1 leaf nodes When the number of layers is d-1, for i=0,1,…,2 d-2 -1, perform hash merge operation Get 2 of the d-2th layer d-2 leaf nodes And so on, until the first layer, calculate the root node of the Merkle tree Then store all the nodes of the Merkle tree;
[0027] Step 4.3: The root node of the Merkle tree As a random seed value, and make the seed value public
[0028] Furthermore, the step 5 includes the following specific steps:
[0029] Step 5.1: Calculate the random string r0 = SM3(seed) for participant P0 based on the random seed value;
[0030] Step 5.2: For i = 0, 1, ..., n-1, iteratively calculate r i+1 =SM3(r i ), we get P1,…,P n-1 A random string.
[0031] Furthermore, the step 6 is specifically as follows: all participants P i The corresponding random string r i Sort from large to small, and arrange the order according to the corresponding binary value size to get And make the ranking results public.
[0032] Furthermore, the step 7 is specifically as follows: according to the sorting result of the random string: and the number of lottery winners m, select the lottery winner
[0033] Furthermore, the step 8 includes the following specific steps:
[0034] Step 8.1: A participant P i Resubmit data D i and random timestamp t i To the lottery verification system;
[0035] Step 8.2: The lottery verification system recalculates the leaf node And according to the stored Merkle tree, provide Verification node sequence to the root node where s(i)=i+(-1) i represents the adjacent nodes of node i, and Represents the parent node of node i;
[0036] Step 8.3: Execute the for loop, for j = d, d-1, ..., 1,
[0037] calculate
[0038] Update i = f(i);
[0039] Among them, if i is an even number, then conc(i,x,y)=x||y; if i is an odd number, then conc(i,x,y)=y||x;
[0040] This loop is executed to the end, and the recalculated root node is obtained contrast If the random seed value is equal to the previously disclosed random seed value, the lottery random seed value is considered legal and the verification is passed.
[0041] Furthermore, step 9 includes the following specific steps:
[0042] Step 9.1: Recalculate the random string of participant P0 based on the verified random seed value
[0043] Step 9.2: For i = 0, 1, ..., n-1, reiterate the calculation Get P1,…,P n-1 Random string
[0044] Step 9.3: For all random strings Sort by binary value from large to small to get the sort sequence Comparison with previously published sequencing If the two sequences are exactly the same, the lottery result verification is deemed successful.
[0045] Beneficial effects:
[0046] The present invention utilizes the SM3 national secret algorithm to ensure the randomness of the lottery content and the Merkle tree structure to provide verifiability of the lottery results, which not only ensures fairness and security, but also provides higher transparency and verification mechanism, effectively solving the problems of low user participation and low transparency of lottery results faced by current lottery algorithms, and realizing a more reliable and credible lottery solution. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 This is a schematic diagram of the main process of a verifiable random lottery method based on Merkle tree and sorting of the present invention. DETAILED DESCRIPTION
[0048] In order to make the purpose, technical solution and technical effect of the present invention more clear, the present invention is further described in detail below with reference to the accompanying drawings and embodiments.
[0049] like Figure 1 As shown, a verifiable random lottery method based on Merkle tree and sorting of the present invention includes the following steps:
[0050] Step 1: Determine the number of winners and participants in the lottery;
[0051] Step 2: Each party submits personal data;
[0052] Step 3: The lottery begins, and each participant clicks to confirm the random timestamp;
[0053] Step 4: The system records the personal data and random timestamp of each participant, constructs a Merkle tree using the SM3 algorithm, and uses the root of the Merkle tree as the random seed;
[0054] Step 5: Use the random seed as input and iteratively run the SM3 algorithm to obtain the random string of each participant;
[0055] Step 6: Sort all random strings from largest to smallest;
[0056] Step 7: The lottery winner is selected based on the given number of winners, and the lottery ends;
[0057] Step 8: Lottery random seed verification: Afterwards, a participant resubmits personal data, and the system uses the membership proof function of the Merkle tree to verify the legitimacy of the random seed;
[0058] Step 9: Lottery result verification: Reproduce and verify the lottery result by iteratively running the SM3 algorithm on a valid random seed.
[0059] Wherein, the step 1 includes the following specific steps:
[0060] Step 1.1: Determine the number of winners in the lottery, denoted as m;
[0061] Step 1.2: Determine the participants in the lottery, denoted as P0,…,P n-1 , the total number of participants is n, and m≤n is required.
[0062] The specific step 2 is: for i=0, 1, ..., n-1, each participant P i Submit your own data D i Give the lottery system.
[0063] The step 3 includes the following specific steps:
[0064] Step 3.1: The lottery starts and a 1-hour time period is set;
[0065] Step 3.2: Each participant clicks on the system to confirm the lottery within the time period to determine their respective lottery timestamps t i .
[0066] The step 4 includes the following specific steps:
[0067] Step 4.1: The system records the data D of each participant i With random timestamp t i ;
[0068] Step 4.2: Calculate the number of layers in the Merkle tree For i = 0, 1, ..., n-1, let For i=n,n+1,…,2 d -1, Thus we get the Merkle tree 2 d leaf nodes When the number of layers is d, for i=0,1,…,2 d-1 -1, perform hash merge operation Where || represents the concatenation of two data, thus obtaining the 2 d-1 leaf nodes When the number of layers is d-1, for i=0,1,…,2 d-2 -1, perform hash merge operation Get 2 of the d-2th layer d-2 leaf nodes And so on, until the first layer, calculate the root node of the Merkle tree Then store all the nodes of the Merkle tree;
[0069] Step 4.3: The root node of the Merkle tree As a random seed value, and make the seed value public.
[0070] The step 5 includes the following specific steps:
[0071] Step 5.1: Calculate the random string r0 = SM3(seed) for participant P0 based on the random seed value;
[0072] Step 5.2: For i = 0, 1, ..., n-1, iteratively calculate r i+1 =SM3(r i ), we get P1,…,P n-1 A random string.
[0073] The step 6 is specifically as follows: i The corresponding random string r i Sort from large to small, and arrange the order according to the corresponding binary value size to get And make the ranking results public.
[0074] The step 7 is specifically as follows: according to the sorting result of the random string: and the number of lottery winners m, select the lottery winner
[0075] The step 8 includes the following specific steps:
[0076] Step 8.1: A participant P i Resubmit data D i and random timestamp t i To the lottery verification system;
[0077] Step 8.2: The lottery verification system recalculates the leaf nodes And according to the stored Merkle tree, provide Verification node sequence to the root node where s(i)=i+(-1) i represents the neighboring nodes of node i, and Represents the parent node (father) of node i;
[0078] Step 8.3: Execute the for loop, for j = d, d-1, ..., 1:
[0079] calculate
[0080] Update i = f(i);
[0081] Wherein, if i is an even number, then conc(i,x,y)=x||y; if i is an odd number, then conc(i,x,y)=y||x; conc represents the concatenation calculation;
[0082] This loop is executed to the end, and the recalculated root node is obtained. contrast If the random seed value is equal to the previously disclosed random seed value, the lottery random seed value is considered legal and the verification is passed.
[0083] Step 9 includes the following specific steps:
[0084] Step 9.1: Recalculate the random string of participant P0 based on the verified random seed value
[0085] Step 9.2: For i = 0, 1, ..., n-1, reiterate the calculation Get P1,…,P n-1 Random string
[0086] Step 9.3: For all random strings Sort by binary value from large to small to get the sort sequence Comparison with previously published sequencing If the two sequences are exactly the same, the lottery result verification is deemed successful.
[0087] To help better understand the details of the present invention, the following example illustrates a specific implementation of a verifiable random lottery algorithm based on a Merkle tree structure and sorting method. Due to data size limitations, this example uses a scenario where eight people participate in the lottery and three people win. The Python Faker library is used to simulate and construct random user data, as follows:
[0088] (1) User data:
[0089] ID: 0001 Name: Liao Jun ID number: 3301XXXXXXXXXXXX45 Timestamp: 1421975140; ID: 0002 Name: Wang Juan ID number: 3301XXXXXXXXXXXX79 Timestamp: 883630529;
[0090] ID: 0003 Name: Xingang ID number: 3301XXXXXXXXXXXX28 Timestamp: 1059085504; ID: 0004 Name: Yang Na ID number: 3301XXXXXXXXXXXX10 Timestamp: 655185617;
[0091] ID: 0005 Name: Yue Qian ID number: 3301XXXXXXXXXXXX29 Timestamp: 481534905;
[0092] ID: 0006 Name: Zhang Cheng ID number: 3301XXXXXXXXXXXX62 Timestamp: 1341518705; ID: 0007 Name: Nie Ling ID number: 3301XXXXXXXXXXXX29 Timestamp: 492833261; ID: 0008 Name: Song Guirong ID number: 3301XXXXXXXXXXXX28 Timestamp: 1213306144.
[0093] Construct a Merkle tree with 8 leaf nodes, which has 3 layers. The data of the leaf nodes in the 3rd layer are:
[0094]
[0095] After hash merging, the data of the second-layer nodes is:
[0096]
[0097] Continuing with hash merging, the first-layer node data is:
[0098]
[0099] Finally, the hash is merged and the root of the tree is the initial seed. The result is:
[0100]
[0101] (2) Run the SM3 algorithm using the initial seed from (1) to calculate r0 = SM3(seed). For i = 0, 1, ..., n-1, iteratively calculate r i+1 =SM3(r i ), get the random strings of 8 people:
[0102] Liao Jun:
[0103] 3f1927472dd70dc678cadcef096a58d004d4cd5919cdb7c5c82aa9c4a2305578;
[0104] Wang Juan:
[0105] 3c32f908242e2eb8ad6ea3accd327535c9ec12b7dd7d98fdbeea18f7905871c7;
[0106] Xin Gang:
[0107] eb0991f12a3b7f5737d9f0dabc3fd0dd69933d993346b4c2faf87cbbe46aa3f3;
[0108] Yang Na:
[0109] a815cfb79e2bc5f75d8c8b99cd01e5e4f6328170d42ce63aabc6e3ea95969b53;
[0110] Le Qian:
[0111] cb97e8236838aa361671a6167611b7b543fa5a81b19f1950cd12a77568fda02e;
[0112] Zhang Cheng:
[0113] e83de8ad84b65b54650b5d8b55eb1eb8e0e424aaff42f70582e84a7c98102285;
[0114] Nie Ling:
[0115] 71845c8317dccd3789ee99d0b5e640bbb91e46cd28f9400e9c94fe2029ad9a6f;
[0116] Song Guirong:
[0117] 34d7228e9a7dc07c4a87849ce6718e423e4b35b609d538dc40f7d6e0d4508c82;
[0118] (3) Sort the 8 random strings from largest to smallest, and then get the user ranking as follows:
[0119] Xin Gang>Zhang Cheng>Le Qian>Yang Na>Nie Ling>Liao Jun>Wang Juan>Song Guirong,
[0120] Since the number of winners is 3, the winners are Xin Gang, Zhang Cheng, and Le Qian.
[0121] (4) Reuse user data and use the Merkle tree membership proof technology to verify the legitimacy of the initial seed. For example, for one of the winners, the SM3 hash value of the user data of Xin Gang is
[0122]
[0123] The lottery server can provide the node verification sequence
[0124]
[0125] And calculated in 3 steps:
[0126] get:
[0127]
[0128] It is the same as the initial seed calculated in (2), and the verification is successful.
[0129] (5) Using the seed from (4), iteratively run the SM3 algorithm to reproduce everyone's random string, and the result is:
[0130] Liao Jun:
[0131] 3f1927472dd70dc678cadcef096a58d004d4cd5919cdb7c5c82aa9c4a2305578;
[0132] Wang Juan:
[0133] 3c32f908242e2eb8ad6ea3accd327535c9ec12b7dd7d98fdbeea18f7905871c7;
[0134] Xin Gang:
[0135] eb0991f12a3b7f5737d9f0dabc3fd0dd69933d993346b4c2faf87cbbe46aa3f3;
[0136] Yang Na:
[0137] a815cfb79e2bc5f75d8c8b99cd01e5e4f6328170d42ce63aabc6e3ea95969b53;
[0138] Le Qian:
[0139] cb97e8236838aa361671a6167611b7b543fa5a81b19f1950cd12a77568fda02e;
[0140] Zhang Cheng:
[0141] e83de8ad84b65b54650b5d8b55eb1eb8e0e424aaff42f70582e84a7c98102285;
[0142] Nie Ling:
[0143] 71845c8317dccd3789ee99d0b5e640bbb91e46cd28f9400e9c94fe2029ad9a6f;
[0144] Song Guirong:
[0145] 34d7228e9a7dc07c4a87849ce6718e423e4b35b609d538dc40f7d6e0d4508c82;
[0146] The calculation result is consistent with that of (3), and the ranking result is also the same, that is, the winners are Xin Gang, Zhang Cheng, and Le Qian, and the verification is passed.
[0147] In summary, the present invention generates a Merkle tree structure based on the SM3 algorithm using the data submitted by each lottery participant and their confirmed random timestamps. The root of the Merkle tree is used as a random seed. The SM3 algorithm is then iteratively run using the random seed as input to obtain and sort the random strings for each participant, thereby determining the winner of the lottery. If a participant needs to verify the lottery results afterwards, they resubmit their data, and the legitimacy of the random seed is verified using the Merkle tree's membership proof technique. The random seed is then used as input to further generate random strings for all participants to verify the correctness of the final lottery results.
[0148] The present invention combines the generation of the initial seed with user data to enhance user participation in the lottery, and designs a verifiable mechanism. Compared with existing random lottery schemes, it can achieve the verifiability of the lottery results afterwards: classic random lottery schemes are all based on software-implemented pseudo-random number generators, and their seed selection depends on the real-time status parameters inside the computer or the ball lottery machine, and cannot be reproduced and verified afterwards; the present invention designs a verifiable mechanism, relying on the data of each participant and the random timestamp selected by each party to generate a random seed, and using the Merkle tree structure, after recording all the hash values of the Merkle tree, the random seed and the final lottery result can be verified, that is, allowing participants to provide information to verify the lottery results and process afterwards, enhancing the transparency and trust of the results, thereby improving the persuasiveness of the lottery results.
[0149] The above description is only a preferred embodiment of the present invention and does not constitute any form of limitation to the present invention. Although the implementation process of the present invention is described in detail above, it is still possible for those familiar with the art to modify the technical solutions described in the above examples or to replace some of the technical features therein with equivalents. Any modifications, equivalent replacements, etc. made within the spirit and principles of the present invention shall be included in the scope of protection of the present invention.
Claims
1. A verifiable random lottery method based on Merkle tree and sorting, characterized in that: The following steps are involved: Step 1: Determine the number of winners and participants in the lottery; Step 2: Each party submits personal data; Step 3: The lottery begins, and each participant clicks to confirm the random timestamp; Step 4: The system records the personal data and random timestamp of each participant, constructs a Merkle tree using the SM3 algorithm, and uses the root of the Merkle tree as the random seed; Step 5: Use the random seed as input and iteratively run the SM3 algorithm to obtain the random string of each participant; Step 6: Sort all random strings from largest to smallest; Step 7: The lottery winner is selected based on the given number of winners, and the lottery ends; Step 8: Lottery random seed verification: A participant resubmits the data, and the system uses the membership proof function of the Merkle tree to verify the legitimacy of the random seed; Step 9: Lottery result verification: Reproduce and verify the lottery result by iteratively running the SM3 algorithm on a valid random seed.
2. A verifiable random lottery method based on Merkle tree and sorting as claimed in claim 1, characterized in that: The step 1 includes the following specific steps: Step 1.1: Determine the number of winners in the lottery, denoted as m; Step 1.2: Determine the participants in the lottery, denoted as P0,…,P n-1 , the total number of participants is n, and m≤n is required.
3. A verifiable random lottery method based on Merkle tree and sorting as claimed in claim 2, characterized in that: The specific step 2 is: each participant P i Submit your own data D i Given a lottery system, where i=0,1,…,n-1.
4. A verifiable random lottery method based on Merkle tree and sorting as claimed in claim 3, characterized in that: The step 3 includes the following specific steps: Step 3.1: The lottery starts and the time period is set; Step 3.2: Each participant clicks on the system to confirm the lottery within the time period to determine their respective lottery timestamps t i .
5. A verifiable random lottery method based on Merkle tree and sorting as claimed in claim 4, characterized in that: The step 4 includes the following specific steps: Step 4.1: The system records the data D of each participant i With random timestamp t i ; Step 4.2: Calculate the number of layers in the Merkle tree For i = 0, 1, ..., n-1, let For i=n,n+1,…,2 d -1, Thus we get the Merkle tree 2 d leaf nodes When the number of layers is d, for i=0,1,…,2 d-1 -1, perform hash merge operation Where || represents the concatenation of two data, thus obtaining the 2 d-1 leaf nodes When the number of layers is d-1, for i=0,1,…,2 d-2 -1, perform hash merge operation Get 2 of the d-2th layer d-2 leaf nodes And so on, until the first layer, calculate the root node of the Merkle tree Then store all the nodes of the Merkle tree; Step 4.3: The root node of the Merkle tree As a random seed value, and make the seed value public.
6. A verifiable random lottery method based on Merkle tree and sorting as claimed in claim 5, characterized in that: The step 5 includes the following specific steps: Step 5.1: Calculate the random string r0 = SM3(seed) for participant P0 based on the random seed value; Step 5.2: For i = 0, 1, ..., n-1, iteratively calculate r i+1 =SM3(r i ), we get P1,…,P n-1 A random string.
7. A verifiable random lottery method based on Merkle tree and sorting as claimed in claim 6, characterized in that: The step 6 is specifically as follows: i The corresponding random string r i Sort from large to small, and arrange the order according to the corresponding binary value size to get And make the ranking results public.
8. A verifiable random lottery method based on Merkle tree and sorting as claimed in claim 7, characterized in that: The step 7 is specifically as follows: according to the sorting result of the random string: and the number of lottery winners m, select the lottery winner 9. A verifiable random lottery method based on Merkle tree and sorting as claimed in claim 8, characterized in that: The step 8 includes the following specific steps: Step 8.1: A participant P i Resubmit data D i and random timestamp t i To the lottery verification system; Step 8.2: The lottery verification system recalculates the leaf node And according to the stored Merkle tree, provide Verification node sequence to the root node where s(i)=i+(-1) i represents the adjacent nodes of node i, and Represents the parent node of node i; Step 8.3: Execute the for loop, for j = d, d-1, ..., 1, calculate Update i = f(i); Wherein, if i is an even number, then conc(i,x,y)=x||y; if i is an odd number, then conc(i,x,y)=y||x; conc represents the concatenation calculation; This loop is executed to the end, and the recalculated root node is obtained contrast If the random seed value is equal to the previously disclosed random seed value, the lottery random seed value is considered legal and the verification is passed.
10. A verifiable random lottery method based on Merkle tree and sorting as claimed in claim 9, characterized in that: The step 9 includes the following specific steps: Step 9.1: Recalculate the random string of participant P0 based on the verified random seed value Step 9.2: For i = 0, 1, ..., n-1, reiterate the calculation Get P1,…,P n-1 Random string Step 9.3: For all random strings Sort by binary value from large to small to get the sort sequence Comparison with previously published sequencing If the two sequences are exactly the same, the lottery result verification is deemed successful.
Citation Information
Patent Citations
Minimum Merkel proof generation and block chain transaction verification method supporting aggregation
CN115082068A
Merkle tree updating method, apparatus and device, and readable storage medium
WO2021233182A1