This patent application claims the benefit and priority of Chinese Patent Application No. 202311405787.5, filed with the China National Intellectual Property Administration on Oct. 27, 2023, the disclosure of which is incorporated by reference herein in its entirety as part of the present application.
The present disclosure belongs to the field of random algorithms, and relates to a verifiable random lottery method based on a Merkle tree and a sorting manner.
For the sake of fairer distribution of market resources, lottery operations are increasingly used in house purchasing, car purchasing, school-age children enrollment and other scenarios in big cities. Nowadays, the large-scale lottery operations are mainly divided into two types. According to the first type of lottery operations, a random seed is generated with a random lottery ball, and then a random index is generated by invoking a classical random number algorithm (such as a rand function) to obtain a lottery result, for example, the lottery operations on house-purchasing qualification in Beijing. According to the second type of lottery operations, a random index is generated by directly invoking a classical random number algorithm on a computer to obtain a lottery result, and a random seed is generated by an entropy pool of an operation system, for example the lottery operations on house-purchasing qualification in Hangzhou. However, the two types of operations have the following defects:
As is known to all, the Merkle tree is a binary hash tree, and is a classical data verification algorithm. It can provide a proof with a size of 0(log2n), thereby verifying whether a member is included in an n-element set. Therefore, in combination with the Merkle tree and a sorting manner, a novel verifiable lottery algorithm is provided.
In view of the above-mentioned technical problems in the prior art, the present disclosure provides a verifiable random lottery method based on a Merkle tree and a sorting manner. The present disclosure can realize subsequent verification on a lottery result, and fundamentally enhance fairness and persuasiveness of the lottery result. Specific technical solutions of the present disclosure are as follows:
A verifiable random lottery method based on a Merkle tree and a sorting manner includes the following steps:
Further, the step 1 specifically includes:
Further, the step 2 specifically includes: allowing the participant Pi to submit the personal data Di to the lottery system, i=0, 1, . . . , n−1.
Further, the step 3 specifically includes:
Further, the step 4 specifically includes:
Further, the step 5 specifically includes:
Further, the step 6 specifically includes: sorting the random strings ri corresponding to all of the participants Pi in the descending manner according to corresponding binary values to obtain rt
Further, the step 7 specifically includes: selecting the winners Pt
Further, the step 8 specifically includes:
Further, the step 9 specifically includes:
The present disclosure achieves the following beneficial effects:
The present disclosure guarantees the randomness of the lottery content through the national cryptographic SM3 algorithm, and makes the lottery result verifiable through the Merkle tree. While ensuring fairness and security, the present disclosure provides a higher transparency and a verification mechanism, effectively solves the problems of a low degree of participation of users and a low transparency of the lottery result in existing lottery algorithms, and realizes a more reliable and credible lottery solution.
To make the objectives, technical solutions, and advantages of the present disclosure clearer, the present disclosure is described in further detail below with reference to the drawings and embodiments.
As shown in
Step 1: A number of winners in a lottery and participants in the lottery are determined.
Step 2: Each of the participants submits personal data.
Step 3: At the beginning of the lottery, the participant clicks and confirms a random timestamp.
Step 4: A lottery system records the personal data and the random timestamp of each participant, a Merkle tree is constructed with an SM3 algorithm, and a root of the Merkle tree is taken as a random seed.
Step 5: The random seed is taken as an input, and the SM3 algorithm is iteratively run to obtain a random string of the participant.
Step 6: All of the random strings are sorted in a descending manner.
Step 7: The winners in the lottery are selected according to the given number of winners, and the lottery is ended.
Step 8: The random seed of the lottery is verified: The participant resubmits the personal data, and the lottery system verifies a legality of the random seed with a membership certification function of the Merkle tree.
Step 9: A lottery result is verified: The SM3 algorithm is iteratively run on a legal random seed to reproduce and verify the lottery result.
The step 1 specifically includes:
Step 1.1: The number of winners in the lottery is determined, and labeled as m.
Step 1.2: The participants in the lottery are determined, and labeled as P0, . . . , Pn−1, a number of the participants being n, m≤n.
The step 2 specifically includes: For i=0,1, . . . , n−1, the participant Pi submits the personal data Di to the lottery system.
The step 3 specifically includes:
Step 3.1: A 1-h time period is set at the beginning of the lottery.
Step 3.2: The participant clicks a lottery confirmation through the lottery system in the time period, so as to determine the respective lottery timestamp ti.
The step 4 specifically includes:
Step 4.1: The lottery system records the data Di and the random timestamp ti of the participant.
Step 4.2: A number d=[log2n] of layers of the Merkle tree is calculated, hi(d)=SM3(Di∥ti) is assumed for i=0,1, . . . , n−1, and hi(d)=SM3(Dn−1∥tn−1) is assumed for i=n, n+1, . . . , 2d−1, thereby obtaining hi(d) for 2d leaf nodes of the Merkle tree. On a dth layer, for i=0,1, . . . , 2d−1−1, a hash merging operation h1(d−1)=SM3(h2i(d)∥h2i+1(d)) is performed, ∥ representing splicing on two pieces of data, thereby obtaining h1(d−1) for 2d−1 nodes on a (d−1)th layer. On the (d−1)th layer, for i=0,1, . . . ,2d−2−1, a hash merging operation hi(d−2)=SM3(h2i(d−1)∥h2i+1(d−1) is performed, thereby obtaining hi(d−2) for 2d−2 nodes on a (d−2)th layer. The same operation is performed until a first layer, h0(0)=SM3(h0(1)∥h1(1)) for the root of the Merkle tree is calculated, and all nodes of the Merkle tree are stored.
Step 4.3: The h0(0) for the root of the Merkle tree is taken as the random seed, and the seed is disclosed.
The step 5 specifically includes:
Step 5.1: The random string r0=SM3(seed) of the participant P0 is calculated according to the random seed.
Step 5.2: ri+1=SM3(ri) is iteratively calculated for i=0,1, . . . , n−1 to obtain the random strings for P1, . . . , Pn−1.
Further, the step 6 specifically includes: The random strings r1 corresponding to all of the participants Pi are sorted in a descending manner according to corresponding binary values to obtain rt
Further, the step 7 specifically includes: The winners Pt
The step 8 specifically includes:
Step 8.1: The participant Pi resubmits the data Di and the random timestamp ti to the lottery system.
Step 8.2: The lottery system recalculates {tilde over (h)}1(d)=SM3(Di∥t1) for the leaf nodes, and provides a verification node sequence VN=[hs(i)(d), hs(f(i))(d−1), hs(f(f(i)))(d−2), . . . hs(f
Step 8.3: A for circulation is calculated. For j=d, d−1, . . . , 1:
{tilde over (h)}f(i)(j−1)=SM3(conc(i, SM3({tilde over (h)}i(j)), SM3(hs(i)(j)))) is calculated.
i=f(i) is updated.
If i is an even number, conc(i, x, y)=x∥y. If i is an odd number, where conc(i, x, y)=y∥x. conc represents splicing.
A recalculated {tilde over (h)}0(0) of the root is obtained upon completion of the circulation, and the {tilde over (h)}0(0) is compared with a previously disclosed random seed. If the {tilde over (h)}0(0) and the previously disclosed random seed are the same, the random seed in the lottery is legal and is successfully verified.
The step 9 specifically includes:
Step 9.1: A random string {tilde over (r)}0=SM3(seed) of the participant P0 is recalculated according to a successfully verified random seed.
Step 9.2: {tilde over (r)}i+1=SM3({tilde over (r)}i) is iteratively recalculated for i=0,1, . . . , n−1 to obtain random strings {tilde over (r)}1, . . . , {tilde over (r)}n−1 for P1, . . . , Pn−1
Step 9.3: All of the random strings {tilde over (r)}i are sorted in the descending manner according to binary values to obtain a sorted sequence {tilde over (r)}t
In order to better understand the details of the present disclosure, a specific implementation example for the verifiable random lottery method based on a Merkle tree and a sorting manner is provided below. Due to limitations in data size, the following descriptions are made to a case including eight participants and three winners. A Faker library of python is used to simulate and construct random user data, specifically:
A Merkle tree with eight leaf nodes and three layers is constructed. Data of the leaf nodes on the third layer is as follows:
[h0(3), h1(3), h2(3), h3(3), h4(3), h5(3), h6(3), h7(3)]=[4e2459a9418948a071b94594df64d3526a0cbfce6e4c30283d387e417d871ae6, 907a03f009cc911e8f959e264fbccb69aeea18d6c8405ealecd63ed3d6395a0b, 454285e96ae19dd91beca9fb2909888c07dbf58cb7c1c48597d9dacda777fdb3, c75e7aafa53cf03c26d398d2c1884e8b94769f9db74f72fb0f2ee6d22993d17c, 8bf8b1391e44e3553d514ca5c6ab89cb73125911046f76a5b80df1160e2fe610, a19a4d406dbf7bd86327c9f196eedd9c5cdb8bb17c63028193612247dbf9bd9d, 65e068clfe56c52593e87a70e2a8836d4ecd4ef7a3ca973b2824f891d534fd83, f0a256d28ac64630f4185c6bc8d2a4f7feb3bfaa3be49913d4ef5ac32f03c62c].
Through hash merging, data of the nodes on the second layer is as follows:
[h0(2), h1(2), h2(2), h3(2)]=[08437ce83085caa2034b12c4d3fb573f0013c598533992ef9bf06441a0e3f7bc, 7ffb37d2e06d01d43a8207c72b19bac96eabac363d17d7ca895b091ec6f57d14, 86e8756dd63267bc8fe72c4ad92768858fbf3ffa2d4ff69ac3f3f1df5374ee3a, b1afe1db8d544e24c6121d2cc359d2b256a7cce92456d5fddd0b6eb53640c97b].
Through the hash merging, data of the nodes on the second layer is as follows:
[h0(1), h1(1)]=[a1fb50a4d0c64341e037789c513e15ae3238bf69845b8bf82e32a65f1745277f, a596f45cb2b2fceafdcedadc6628ed6659aaf2166bd5dd36ca5cceee522bb0cf].
Through the hash merging, a root obtained is taken as an initial seed, and the result is as follows:
h0(0)=3d2780bc197dec49b4e74dc60b804d00c53e0ff5f4fa9d03705f9dc081cdbe9d.
Liao Jun:
3f1927472dd70dc678cadcef096a58d004d4cd5919cdb7c5c82aa9c4a2305578.
Wang Juan:
3c32f908242e2eb8ad6ea3accd327535c9ec12b7dd7d98fdbeea18f7905871c7.
Xin Gang:
eb0991f12a3b7f5737d9f0dabc3fd0dd69933d993346b4c2faf87cbbe46aa3f3.
Yang Na:
a815cfb79e2bc5f75d8c8b99cd01e5e4f6328170d42ce63aabc6e3ea95969b53.
Le Qian:
cb97e8236838aa361671a6167611b7b543fa5a81b19f1950cd12a77568fda02e.
Zhang Cheng:
e83de8ad84b65b54650b5d8b55eb1eb8e0e424aaff42f70582e84a7c98102285.
Nie Ling:
71845c8317dccd3789ee99d0b5e640bbb91e46cd28f9400e9c94fe2029ad9a6f.
Song Guirong:
34d7228e9a7dc07c4a87849ce6718e423e4b35b609d538dc40f7d6e0d4508c82.
Xin Gang>Zhang Cheng>Le Qian>Yang Na>Nie Ling>Liao Jun>Wang Juan>Song Guirong.
The three winners are Xin Gang, Zhang Cheng and Le Qian.
A lottery server can provide a verification node sequence VN=[h3(3), h0(2), h1(1)]=[c75e7aafa53cf03c26d398d2c1884e8b94769f9db74f72fb0f2ee6d22993d17c, 08437ce83085caa2034b12c4d3fb573f0013c598533992ef9bf06441a0e3f7bc, a596f45cb2b2fceafdcedadc6628ed6659aaf2166bd5dd36ca5cceee522bb0cf].
Three steps are performed for calculation: {tilde over (h)}1(2)=SM3({tilde over (h)}2(3)∥h2(3)), {tilde over (h)}0(1)=SM3(h0(2)∥{tilde over (h)}1(2)), {tilde over (h)}0(0)=SM3(h0(1)∥{tilde over (h)}0(1)),
{tilde over (h)}0(0)=3d2780bc197dec49b4e74dc60b804d00c53e0ff5f4fa9d03705f9dc081cdbe9d.
The seed is the same as the initial seed calculated in (2), and is successfully verified.
Liao Jun:
3f1927472dd70dc678cadcef096a58d004d4cd5919cdb7c5c82aa9c4a2305578.
Wang Juan:
3c32f908242e2eb8ad6ea3accd327535c9ec12b7dd7d98fdbeea18f7905871c7.
Xin Gang:
eb0991f12a3b7f5737d9f0dabc3fd0dd69933d993346b4c2faf87cbbe46aa3f3.
Yang Na:
a815cfb79e2bc5f75d8c8b99cd01e5e4f6328170d42ce63aabc6e3ea95969b53.
Le Qian:
cb97e8236838aa361671a6167611b7b543fa5a81b19f1950cd12a77568fda02e.
Zhang Cheng:
e83de8ad84b65b54650b5d8b55eb1eb8e0e424aaff42f70582e84a7c98102285.
Nie Ling:
71845c8317dccd3789ee99d0b5e640bbb91e46cd28f9400e9c94fe2029ad9a6f.
Song Guirong:
34d7228e9a7dc07c4a87849ce6718e423e4b35b609d538dc40f7d6e0d4508c82.
The result is the same as that calculated in (3), and the sorted result is also the same. That is, the winners are Xin Gang, Zhang Cheng and Le Qian, and the result is verified successfully.
In conclusion, the present disclosure generates the structure of the Merkle tree based on the SM3 algorithm through submitted data and respective confirmed random timestamps of the participants in the lottery, takes a root of the Merkle tree as a random seed, takes the random seed as an input, iteratively runs the SM3 algorithm to obtain random strings of the participants, and sorts the random strings, thereby determining the winners in the lottery. If there is a need to verify a lottery result, the participant resubmits the data, and verifies a legality of the random seed with membership certification of the Merkle tree. By taking the random seed as the input, random strings of all participants are further generated to verify the lottery result.
By combining the initial seed with the user data, the present disclosure enhances a degree of participation of the users in the lottery. With the verifiable mechanism, the present disclosure can verify the lottery result subsequently compared with the existing random lottery solution. The classical random lottery solution is based on a software-implemented pseudo-random number generator, and the seed is selected depending on an internal real-time state parameter of a computer or a ball lottery machine and cannot be reproduced and verified. With the verifiable mechanism, the present disclosure generates the random seed depending on data and selected random timestamps of the participants. With the structure of the Merkle tree, after all hash values of the Merkle tree are recorded, the random seed and the final lottery result can be verified. That is, the participant can provide information subsequently to verify the lottery result and the process. The present disclosure makes the result more transparent and credible, and makes the lottery result more persuasive.
The above described are merely preferred implementations of the present disclosure rather than limitations to the present disclosure in any form. Although the implementation process of the present disclosure is described in detail with reference to the foregoing embodiments, those skilled in the art can still make modifications to the technical solutions described in the foregoing embodiments, or make equivalent replacement to some of the technical features. Any modifications and equivalent substitutions made within the spirit and principle of the present disclosure should be included within the protection scope of the present disclosure.
| Number | Date | Country | Kind |
|---|---|---|---|
| 202311405787.5 | Oct 2023 | CN | national |