Random number generation algorithm method based on block chain
Technical Field
The invention relates to a random number generation algorithm method based on a block chain.
Background
The block chain technology, bt (block chain technology) for short, also called distributed book technology, is an internet database technology, and is characterized by decentralized and transparent disclosure, so that everyone can participate in database recording.
Transaction (Transaction): an operation, resulting in a change of the state of the ledger, such as adding a record;
block (Block): recording the transaction and state results occurring within a period of time, which is a consensus on the current ledger state;
chain (Chain): the system is formed by serially connecting blocks according to the occurrence sequence and is a log record of the whole state change.
If the blockchain is used as a state machine, each transaction is attempted to change state, and each consensus generated block is that the participant confirms the result of all transaction contents in the block that caused the state change.
Block chain technology has advanced rapidly and has found application in several areas. The block chain can solve the problems existing in some traditional fields by unique characteristics. In traditional applications, many scenarios place strong demands on openness, fairness, and random numbers that cannot be manipulated manually. But traditional centralization cannot meet this requirement. The block chain has the characteristics of transparency, openness, autonomy, non-tamper property and the like. By utilizing the characteristics of the block chain, a random number generation algorithm based on the block chain is provided, and a true random number which cannot be manually manipulated under the participation of multiple parties can be provided.
Disclosure of Invention
To solve the above technical problems, an object of the present invention is to provide a method for block chain-based random number generation algorithm.
In order to achieve the purpose, the invention adopts the following technical scheme:
a block chain based random number generation algorithm method comprises the following steps:
step 1: a participant selects a server side, the server side generates a random number, and the hash value of the random number is recorded on a block chain;
step 2: the server side sends the information on the block chain to other participants and collects random numbers of the other participants;
and step 3: the server side sends the random number of the participant, the random number generated by the server and the information of the number of the delay waiting blocks to a block chain together;
and 4, step 4: and (3) the server side sends the information on the block chain in the step (3) to other participants, and after all the participants wait for the set blocks, the final random number is calculated.
Preferably, the step 1 comprises the steps of:
all participants select a server, and the server generates a random number NserverAnd calculates HASH value HASH (N) of the random numberserver) Then, the server side sends the message1{ GameID | | | HASH (N)server) Sending to a block chain;
check the GameID on the blockchain, if it is not repeated with the previously existing flow, the message forwards the transaction to action1{ GameID | | | HASH (N)server) The form of the is recorded in the block chain.
Preferably, the GameID is a custom flow number.
Preferably, said steps 2 and 3 comprise the steps of:
the server side sends the GameID, the hash of transaction 1(transaction1) and the block height H1 of the transaction1 to all other participants, and the participants can use the GameID and the transaction hash to retrieve the flow information on the block chain;
if the process information is correct, the participant needs to randomly send random number information random { GameID | | | Ni } to the server, and Ni is a random number generated by the participant i; the server side uses a reply participant i to return a receipt message receive { random }, and indicates that the random number is received;
after the server collects the random numbers of all participants, the server sends a message
message2{GameID||HASH(Nserver)||Nserver||[Ni]| Hash (transaction1) | | waitingX } to blockchain;
wherein [ Ni ] is the set of random numbers sent by all participants to the server, and Hash (transaction1) is the Hash information of transaction 1; waitingX is a waiting block interval, which is an integer;
smart contracts examine the message2 for GameID, HASH (N)server) If the information matches the information in the transaction1, the calculation checks the message2 for NserverHASH value of (2) and HASH (N)server) Whether the two are consistent; if the checks are passed, a new transaction message is generated
transaction2{GameID||HASH(Nserver)||Nserver||[Ni]||Hash(transaction1)||waitingX}。
Preferably, said step 4 comprises the following steps:
the server side broadcasts the hash information of transaction 2(transaction2) and the height H2 of the block where the transaction is located to all participants;
if the random number of any participant is tampered, any participant can refuse to start the process and send the received receipt message receive { random } to the block chain to instruct and control the server side to cheat;
if the information is correct, all participants wait for the HASH value HASH (block (H2+ waitingX)) for a block of height H2+ waitingX;
then using Nserver、[Ni]And HASH (block (H2+ waitingX)) as input to the function f (x), and obtaining as output a number k, i.e. kIs the random number that is finally generated.
Preferably, the function f (x) may be any predetermined function.
By the scheme, the invention at least has the following advantages:
the invention provides an algorithm for generating random numbers by a server and all participants through a block chain, and the algorithm can ensure that a plurality of participants participate in the generation of the random numbers together, thereby ensuring that the random numbers cannot be manipulated by anyone. Meanwhile, the random number is recorded on the chain in the whole process by means of a block chain technology and is disclosed on the chain, so that the random number is prevented from being tampered, and the safety is improved.
The foregoing description is only an overview of the technical solutions of the present invention, and in order to make the technical solutions of the present invention more clearly understood and to implement them in accordance with the contents of the description, the following detailed description is given with reference to the preferred embodiments of the present invention and the accompanying drawings.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present invention and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained according to the drawings without inventive efforts.
FIG. 1 is a schematic flow diagram of the present invention;
FIG. 2 is a schematic flow chart of an embodiment of the present invention.
Detailed Description
The following detailed description of embodiments of the present invention is provided in connection with the accompanying drawings and examples. The following examples are intended to illustrate the invention but are not intended to limit the scope of the invention.
In order to make the technical solutions of the present invention better understood, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. The components of embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the present invention without making any creative effort, shall fall within the protection scope of the present invention.
Examples
As shown in fig. 1, a method for block chain-based random number generation algorithm includes the following steps:
step 1: a participant selects a server side, the server side generates a random number, and the hash value of the random number is recorded on a block chain;
step 2: the server side sends the information on the block chain to other participants and collects random numbers of the other participants;
and step 3: the server side sends the random number of the participant, the random number generated by the server and the information of the number of the delay waiting blocks to a block chain together;
and 4, step 4: and (3) the server side sends the information on the block chain in the step (3) to other participants, and after all the participants wait for the set blocks, the final random number is calculated.
As shown in figure 2 of the drawings, in which,
all participants select a server, and the server generates a random number NserverAnd calculates HASH value HASH (N) of the random numberserver) Then, the server side sends the message1{ GameID | | | HASH (N)server) Sending to a block chain;
the Smart contracts on the blockchain check for GameID, which if it does not repeat with the previously existing flow, the message forwards the transaction1{ GameID | | HASH (N)server) The format of the GameID is recorded in a block chain, wherein the GameID is a self-defined flow number.
The above-mentioned smart contract is a program executed at one end of the block chain, and is a technology known to those skilled in the art, and will not be described in any detail here.
The server side sends the GameID, the hash of transaction 1(transaction1) and the block height H1 of the transaction1 to all other participants, and the participants can use the GameID and the transaction hash to retrieve the flow information on the block chain;
if the process information is correct, the participant needs to randomly send random number information random { GameID | | | Ni } to the server, and Ni is a random number generated by the participant i; the server side uses a reply participant i to return a receipt message receive { random }, and indicates that the random number is received;
after the server collects the random numbers of all participants, the server sends a message
message2{GameID||HASH(Nserver)||Nserver||[Ni]| Hash (transaction1) | | waitingX } to blockchain;
wherein [ Ni ] is the set of random numbers sent by all participants to the server, and Hash (transaction1) is the Hash information of transaction 1; waitingX is a waiting block interval, which is an integer;
smart contracts examine the message2 for GameID, HASH (N)server) If the information matches the information in the transaction1, the calculation checks the message2 for NserverHASH value of (2) and HASH (N)server) Whether the two are consistent; if the checks are passed, a new transaction message is generated
transaction2{GameID||HASH(Nserver)||Nserver||[Ni]||Hash(transaction1)||waitingX}。
The server side broadcasts the hash information of transaction 2(transaction2) and the height H2 of the block where the transaction is located to all participants;
if the random number of any participant is tampered, any participant can refuse to start the process and send the received receipt message receive { random } to the block chain to instruct and control the server side to cheat;
if the information is correct, all participants wait for the HASH value HASH (block (H2+ waitingX)) for a block of height H2+ waitingX;
then using Nserver、[Ni]And HASH (block (H2+ waitingX)) as input to the function f (x), andand obtaining a number k as an output, wherein the number k is a random number finally generated.
The function f (x) may be any predetermined function, and is known to those skilled in the art, and will not be described in detail here.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, it should be noted that, for those skilled in the art, many modifications and variations can be made without departing from the technical principle of the present invention, and these modifications and variations should also be regarded as the protection scope of the present invention.