Blockchain random number generation method, device, equipment and computer storage medium
By performing distributed key initialization and signature processing on blockchain service nodes, the problem of blockchain random number acquisition being limited by a single node is solved, and the availability and applicability of random numbers in most scenarios are achieved.
Patent Information
- Application Number
- CN202011524078.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-21
- Publication Date
- 2025-10-10
- Estimated Expiration
- 2040-12-21
AI Technical Summary
When obtaining random numbers, the blockchain is easily restricted by a single node, which affects the availability of random numbers in the event of network instability or failure, making it unsuitable for most scenarios.
By initializing the distributed keys of all service nodes in the blockchain, obtaining the random number service provider group, controlling the service nodes to parse the random number request parameters, calculating the final random number and signing it, and finally writing it back to the user contract in the blockchain.
It realizes that the blockchain is not restricted to a single node in obtaining random numbers, improves the availability and applicability of random numbers, and is suitable for most scenarios.
Smart Images

Figure CN112631550B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of financial technology (Fintech), and in particular to a blockchain random number generation method, apparatus, device, and computer storage medium. Background Art
[0002] With the development of computer technology, more and more technologies (such as big data, distributed systems, blockchain, and artificial intelligence) are being applied in the financial sector. Traditional finance is gradually shifting towards Fintech. However, the security and real-time requirements of the financial industry have also placed higher demands on blockchain random number generation technology. Currently, blockchains obtain random numbers through oracle services, including centralized and decentralized oracles. Centralized oracles obtain random numbers through off-chain APIs (Application Programming Interfaces), and then have centralized oracle services upload the random numbers to the blockchain. However, this method of obtaining random numbers is vulnerable to various attacks. Decentralized oracles generate verifiable random numbers through user-generated random number seeds and oracle service nodes providing private keys. However, this method is subject to network failures and node failures. Furthermore, under the staking mechanism used by decentralized oracles, nodes that fail to respond or cause network instability will be fined, and problematic nodes will be removed from the list of random number generators. Low-quality or non-compliant oracle service nodes will suffer significant short- and long-term economic losses, making them unsuitable for many scenarios, such as consortium chains. Therefore, how to ensure that blockchains can obtain random numbers without being restricted by a single node and that they can obtain random numbers applicable to a wide range of scenarios has become an urgent issue. Summary of the Invention
[0003] The main purpose of the present invention is to propose a blockchain random number generation method, device, equipment and computer storage medium, aiming to solve the technical problem of how to enable the blockchain to obtain random numbers without being restricted by a single node and to obtain random numbers applicable to most scenarios.
[0004] To achieve the above objectives, the present invention provides a blockchain random number generation method, which comprises the following steps:
[0005] Initialize the distributed key of the random array of all service nodes in the blockchain to obtain the random number service provider group;
[0006] Control each of the service nodes to parse the request parameters corresponding to the random number request sent by the smart contract in the blockchain to determine all target service nodes corresponding to the random number request;
[0007] Calculating a final random number based on the random number service providing group and each of the target service nodes, and determining a final signature result based on the final random number and each of the service nodes;
[0008] Based on the final signature result, the final random number is written back to the user contract in the blockchain as the target random number.
[0009] Optionally, the steps of performing distributed key initialization on random arrays of all service nodes in the blockchain to obtain a random number service provider group include:
[0010] Obtain random arrays of all service nodes in the blockchain, and calculate the key exchange content of each service node based on a preset key distribution function and each random array;
[0011] If all the key exchange contents are legal, the private key and public key of each service node are calculated according to the key exchange contents, and the private key and public key of each service node are used as a random number service providing group.
[0012] Optionally, before the step of calculating the final random number according to the random number service providing group and each of the target service nodes, the method further includes:
[0013] Traversing each of the target service nodes in sequence, and determining the private key of the traversed target service node according to the random number service providing group;
[0014] A hash calculation is performed based on the private key and a preset random number algorithm to obtain a node random number and a random number result corresponding to the traversed target service node.
[0015] Optionally, the step of calculating a final random number according to the random number service providing group and each of the target service nodes includes:
[0016] If all the target service nodes can respond normally, the random number results corresponding to the target service nodes are obtained, and the average value of the random number results is calculated, and the average value is used as the final random number.
[0017] Optionally, the step of determining a final signature result according to the final random number and each of the service nodes includes:
[0018] Sign the final random number according to the private key of each target service node to obtain a node signature corresponding to each target service node;
[0019] If all the node signatures are valid signatures, the node signatures are added together to obtain the final signature result.
[0020] Optionally, before the step of writing the final random number back to the user contract in the blockchain based on the final signature result, the step includes:
[0021] Determine the number of nodes of each of the target service nodes, perform a remainder calculation on the number of search nodes according to the final random number, and determine the on-chain node of the blockchain according to the remainder calculation result, wherein the on-chain node uploads the final random number and the final signature result to the blockchain.
[0022] Optionally, the step of writing the final random number back to the user contract in the blockchain based on the final signature result includes:
[0023] A preset pairing function is started according to the blockchain, and the final signature result and the final random number are verified according to the pairing function. If the verification result is that the verification passes, the final random number is written back to the user contract in the blockchain.
[0024] In addition, to achieve the above-mentioned purpose, the present invention also provides a blockchain random number generation device, the blockchain random number generation device comprising:
[0025] The acquisition module is used to initialize the distributed key of the random arrays of all service nodes in the blockchain to obtain the random number service provider group;
[0026] A parsing module, configured to control each of the service nodes to parse the request parameters corresponding to the random number request sent by the smart contract in the blockchain, so as to determine all target service nodes corresponding to the random number request;
[0027] a calculation module, configured to calculate a final random number based on the random number service providing group and each of the target service nodes, and determine a final signature result based on the final random number and each of the service nodes;
[0028] A write-back module is configured to write the final random number as a target random number back to the user contract in the blockchain based on the final signature result.
[0029] In addition, to achieve the above-mentioned purpose, the present invention also provides a blockchain random number generation device, which includes: a memory, a processor, and a blockchain random number generation program stored on the memory and runnable on the processor. When the blockchain random number generation program is executed by the processor, the steps of the blockchain random number generation method described above are implemented.
[0030] In addition, to achieve the above-mentioned purpose, the present invention also provides a computer storage medium, on which a blockchain random number generation program is stored. When the blockchain random number generation program is executed by a processor, the steps of the blockchain random number generation method as described above are implemented.
[0031] The present invention performs distributed key initialization on the random arrays of all service nodes in the blockchain to obtain a random number service provider group; controls each service node to parse the request parameters corresponding to the random number request sent by the smart contract in the blockchain to determine all target service nodes corresponding to the random number request; calculates a final random number based on the random number service provider group and each target service node, and determines a final signature result based on the final random number and each service node; and writes the final random number back to the user contract in the blockchain as the target random number based on the final signature result. By performing distributed key initialization on the random arrays of all service nodes in the blockchain to obtain a random number service provider group, and controlling each service node to parse the random number request to determine all target service nodes, and then calculating the final random number based on the random number service provider group and each target service node, and writing the final random number as the target random number to the user contract based on the final signature result, the present invention avoids the phenomenon in the prior art that the availability of random numbers is affected due to node unresponsiveness or network instability when obtaining random numbers from the blockchain, and realizes that the acquisition of random numbers from the blockchain is not limited to a single node, and random numbers suitable for most scenarios can be obtained. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 This is a schematic diagram of the structure of a blockchain random number generator in the hardware operating environment involved in the embodiment of the present invention;
[0033] Figure 2 This is a flow chart of the first embodiment of the blockchain random number generation method of the present invention;
[0034] Figure 3 Schematic diagram of the device module of the blockchain random number generation device of the present invention.
[0035] The purpose, features and advantages of the present invention will be further described with reference to the accompanying drawings and in conjunction with the embodiments. DETAILED DESCRIPTION
[0036] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0037] like Figure 1 As shown, Figure 1 This is a schematic diagram of the structure of a blockchain random number generation device in the hardware operating environment involved in the embodiment of the present invention.
[0038] The blockchain random number generating device in the embodiment of the present invention can be a PC or a server device, on which a Java virtual machine runs.
[0039] like Figure 1 As shown, the blockchain random number generation device may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. The communication bus 1002 is used to implement communication between these components. The user interface 1003 may include a display screen and an input unit such as a keyboard. Optionally, the user interface 1003 may also include a standard wired interface or a wireless interface. The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory, such as a disk storage device. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0040] Those skilled in the art will understand that Figure 1 The blockchain random number generation device structure shown in the figure does not constitute a limitation of the device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0041] like Figure 1 As shown, the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a blockchain random number generation program.
[0042] exist Figure 1 In the blockchain random number generation device shown, the network interface 1004 is mainly used to connect to the backend server and communicate data with the backend server; the user interface 1003 is mainly used to connect to the client (user end) and communicate data with the client; and the processor 1001 can be used to call the blockchain random number generation program stored in the memory 1005 and perform the operations in the following blockchain random number generation method.
[0043] Based on the above hardware structure, an embodiment of the blockchain random number generation method of the present invention is proposed.
[0044] Reference Figure 2 , Figure 2 This is a flow chart of the first embodiment of the blockchain random number generation method of the present invention, which includes:
[0045] Step S10, initializing the distributed key of the random arrays of all service nodes in the blockchain to obtain a random number service provider group;
[0046] Since the current method of generating random numbers on the blockchain has the problem of single-point failure or deliberate non-response of the oracle service node, in this embodiment, multiple oracle service nodes are used to provide random arrays to generate verifiable random numbers, thereby effectively avoiding the phenomenon of single-point evil. In addition, in this embodiment, the random numbers provided by each oracle service node (i.e., service node) are averaged to obtain the final random number, and the remainder of the final random number is taken to select the on-chain node from the oracle service node, and the on-chain node will upload the final result to the chain. Each oracle service node performs off-chain signature aggregation on the final result, and the on-chain node will also upload the signature result to the chain. In this embodiment, the centralized oracle machine is oraclize, and the decentralized oracle machine is chainlink.
[0047] In addition, the key terms in this embodiment are explained as follows:
[0048] The public key is a public key parameter in public key cryptography that must be published and used for encryption and signature verification. In the blockchain account system, a public key corresponds to an account address. The private key is a private key parameter in public key cryptography that is used for decryption and signing. In the blockchain account system, the private key controls the ownership and use rights of the account. The address is the identifier of the account. For external accounts, the address represents the last 20 bytes of the account's public key. Signature aggregation combines multiple signatures for one or more messages (transactions) into a single signature for verification. The identity of each individual signature is irrelevant; as long as the aggregated signature passes verification, all signatures pass verification. Public key aggregation combines multiple public keys into a single public key.
[0049] Furthermore, in this embodiment, assuming user A needs to generate a verifiable random number on the blockchain (i.e., the target random number), it is necessary to randomly generate a random number seed on the blockchain and select all oracle service nodes (i.e., service nodes) or N service nodes in the oracle service network to assist in random number generation. It is assumed that only M (M less than or equal to N) service nodes are required to complete random number generation. In other words, in this embodiment, N service nodes in the blockchain are first determined to provide random numbers, and the priorities of the random numbers of the N service nodes are set and recorded in the address list of the blockchain smart contract. Distributed key initialization is then performed on the random arrays of all selected service nodes in the blockchain (e.g., N oracle service nodes) to obtain a random number service provider group. First, each oracle service node i generates its own random array, ran_i, which is kept secret from other nodes. Each service node generates a random array visible only to itself. Furthermore, the service node determines how many service nodes to broadcast the random array to. Assuming that the random array needs to be broadcast to j service nodes (where j is the service node number and 1≤j≤N), the random arrays in j service nodes must be encrypted before broadcasting. For example, when broadcasting the random array from service node i to service node j, the random array is first encrypted using a preset key distribution function with its own private key fragment to obtain the key exchange content. This key exchange content is then broadcast from service node i to service node j. Here, the key exchange content is send_{ij} = f(ran_i,j), where ran_i is the random array to be broadcast by service node i, j is the number of the service node to which service node i needs to broadcast, and f is the key distribution function. In this embodiment, each service node collects the key exchange content sent by other service nodes, namely send_{1j}, send_{2j},..., send_{Nj}. After collecting the key exchange content, each service node needs to verify the legitimacy of the key exchange content. In other words, the key exchange content is verified based on the public key information disclosed by each service node to determine whether it is legal. When all the data of each service node is legal, each service node can extract its own node's private key s_j and group public key P (the public key aggregation of the public keys of each service node) based on the obtained key exchange content. This is then broadcast to the blockchain, completing the distributed key initialization process. Among them, the random number service provider group includes the private key, public key, and group public key P of each service node.
[0050] Step S20: Control each of the service nodes to parse the request parameters corresponding to the random number request sent by the smart contract in the blockchain to determine all target service nodes corresponding to the random number request;
[0051] In this embodiment, the random numbers provided by M oracle service nodes can be aggregated in an average (avg) manner on the blockchain. Then, by calling an oracle contract (such as a chainlink contract), the above parameters (M, N, seed, avg) and the addresses of N oracle nodes are passed to the address list in the oracle contract. After each service node monitors the random number request event issued by the oracle contract, it will parse whether its address is in the address list recorded by the smart contract. If so, it is determined to be the target service node. That is, each service node will parse the request parameters of the random number request issued by the smart contract oracle contract in the blockchain to determine all target service nodes corresponding to the random number request. In this embodiment, the number of target service nodes is M, which is the number in the address list recorded by the smart contract. In this embodiment, each target service node will perform the following steps. When the target service node is node j, node j uses the distributed private key s_j (1≤j≤N) and calculates the random number hash value based on the random number seed to obtain the final random number result random_j. At the same time, it is also necessary to generate a random number proof to obtain the specific random number proof_j. The random number proof can be generated by first taking the public key pub_j, the private key s_j, and the random number seed as input, and then performing the corresponding function operation to obtain the random number proof. The random number result and the verifiable random number are then broadcasted to the other N nodes.
[0052] After receiving the verifiable random numbers sent by other service nodes, each service node verifies the correctness of the verifiable random numbers. This involves decoding the verifiable random numbers and verifying them against the public key pub_j to determine if they are correct. pub_j is the public key of node j. If verification is successful, the random number result and the verifiable random number for node j are recorded. Therefore, after all service nodes have passed verification, M service nodes are selected as target service nodes. The selection rule can be based on the order of the service nodes in the address list recorded by the smart contract. The first M service nodes are selected as target service nodes, and the random number and random number result of each target service node are obtained.
[0053] Step S30, calculating a final random number according to the random number service providing group and each of the target service nodes, and determining a final signature result according to the final random number and each of the service nodes;
[0054] After determining each target service node, the private key, random number, and random number result of each target service node can be determined according to the random number service provider group. If the random numbers of M service nodes are received, the average is calculated. If any of the M service nodes does not respond, the next node is selected in turn until M random numbers are obtained. The final random number is then calculated. The calculation formula for the final random number can be:
[0055] random is the final random number.
[0056] In this embodiment, after calculating the final random number random, it is necessary to take the remainder of M, that is, index = ramdom % M. The resulting index is the following table in the address list of the blockchain smart contract for the oracle node responsible for uploading the result. This randomly determines the node to be uploaded to the chain. After determining the node to be uploaded to the chain, it is also necessary to calculate the final signature result SIG of the first M nodes. That is, the first M oracle service node i (i.e., the target service node) uses its own private key (s_i) to sign the final random number result random, sig_i = s_i * H (ramdom), where H is a hash function. Node i's signature is sig_i, and sig_i is broadcast to the first M nodes. In other words, the hash value of the final random number result of the target service node is first calculated, and the product of the target service node's private key and the hash value is calculated. This product is used as the signature of the target service node, and the signature is then broadcast to the first M nodes. Each node j collects sig_i broadcast by other members, and uses pub_i (public key) to verify the signature (that is, verify the node signature), and verify whether e(pub_i, H(ramdom)) = e(G, s_i) is equal, where e is the pairing function, that is, if e(public key pub_i, hash value of the final random number H(ramdom)) = e(s_i*G, hash value of the final random number) = e(G, s_i), then the verification is determined to be successful, and the node signature is accepted as a valid signature. After collecting M valid signatures, these valid signatures are added, and the added sum is used as the final signature result SIG, and the final signature result SIG is broadcast.
[0057] Step S40: Based on the final signature result, the final random number is written back to the user contract in the blockchain as the target random number.
[0058] In this embodiment, the node responsible for uploading the information to the blockchain will pass the proof_i{(i=1,2,...,M)} generated by M nodes, the final signature result SIG, the group private key S, and the random number result random to the oracle contract. After receiving the information uploaded by the uplink node, the oracle contract on the blockchain needs to perform signature verification. After the signature verification passes, it will write the final random number as the target random number back to the user contract on the blockchain. Among them, signature verification includes random number signature verification and distributed signature verification.
[0059] In this embodiment, a random number service provider group is obtained by performing distributed key initialization on the random arrays of all service nodes in the blockchain; each service node is controlled to parse the request parameters corresponding to the random number request sent by the smart contract in the blockchain to determine all target service nodes corresponding to the random number request; a final random number is calculated based on the random number service provider group and each target service node, and a final signature result is determined based on the final random number and each service node; and the final random number is written back to the user contract in the blockchain as the target random number based on the final signature result. By performing distributed key initialization on the random arrays of all service nodes in the blockchain to obtain the random number service provider group, and controlling each service node to parse the random number request to determine all target service nodes, a final random number is calculated based on the random number service provider group and each target service node, and the final random number is written to the user contract as the target random number based on the final signature result, thereby avoiding the phenomenon in the prior art of random number acquisition on the blockchain that the availability of random numbers is affected due to node unresponsiveness or network instability. This ensures that random number acquisition on the blockchain is not limited to a single node, and random numbers suitable for most scenarios can be obtained.
[0060] Furthermore, based on the first embodiment of the present invention, a second embodiment of the blockchain random number generation method of the present invention is proposed. In this embodiment, step S10 in the above embodiment, performing distributed key initialization on the random arrays of all service nodes in the blockchain to obtain the steps of the random number service provider group, includes:
[0061] Step a: Obtain a random array of all service nodes in the blockchain, and calculate the key exchange content of each service node based on a preset key distribution function and each random array;
[0062] In this embodiment, when preparing to obtain a random number from a blockchain, it is necessary to obtain the random arrays of all service nodes in the blockchain, or N service nodes pre-set by the user. For example, to obtain the random arrays of N service nodes, each member i of the N service nodes generates its own random array ran_i. This random array is kept secret from other nodes, that is, each service node generates a random array visible only to itself. In addition, the service node first determines how many service nodes to broadcast the random array to. Assuming that j service nodes need to be broadcast (where j is the service node number and 1≤j≤N), the random arrays in j service nodes need to be encrypted before broadcasting. For example, when broadcasting the random array of service node i to service node j, the random array is first encrypted using a preset key distribution function based on its own private key fragment to obtain key exchange content, and then the key exchange content is broadcast from service node i to service node j. Among them, the key exchange content send_{ij}=f(ran_i,j), ran_i is the random array that service node i needs to broadcast, j is the number of the service node that service node i needs to broadcast to, and f is the key distribution function, which can be set according to user needs.
[0063] Step b: If all the key exchange contents are legal, the private key and public key of each service node are calculated according to each key exchange content, and the private key and public key of each service node are used as a random number service providing group.
[0064] Each service node collects the key exchange content sent by other service nodes, namely send_{1j}, send_{2j}, ..., send_{Nj}. After collecting the key exchange content, each service node needs to verify the legitimacy of the key exchange content. This means verifying the key exchange content based on the public key information disclosed by each service node to determine its legality. Once all data from each service node is legal, each service node can extract its own node private key s_j and group public key P (the public key aggregation of the public keys of each service node) based on the obtained key exchange content. This is then broadcast to the blockchain, completing the distributed key initialization process. The random number service provider group includes the private key, public key, and group public key P of each service node.
[0065] In this embodiment, the key exchange content of each service node is calculated based on the random array of all service nodes in the preset key distribution function blockchain, and when all the key exchange contents are legal, the private key and public key of each service node are calculated based on each key exchange content, and used as the random number service provider group, thereby ensuring the accuracy of the obtained random number service provider group.
[0066] Furthermore, before the step of calculating the final random number according to the random number service providing group and each of the target service nodes, the method further includes:
[0067] Step c, traversing each of the target service nodes in turn, and determining the private key of the traversed target service node according to the random number service providing group;
[0068] In this embodiment, after determining all M number of target service nodes, each target service node can be traversed in turn. Since the random number service provider group contains information such as the private key, public key and group public key P of all service nodes, the private key of the traversed target service node can be determined in the random number service provider group.
[0069] Step d: performing a hash calculation based on the private key and a preset random number algorithm to obtain a node random number and a random number result corresponding to the traversed target service node.
[0070] Then, based on the private key of the target service node and the pre-set random number algorithm, hash calculation and proof calculation are performed to obtain the node random number and random number result corresponding to the traversed target service node. That is, the target service node j uses the distributed private key s_j (1≤j≤N) and calculates the random number hash value based on the random number seed to obtain the final random number result random_j. At the same time, a random number proof needs to be generated to obtain the specific random number proof_j. Among them, the generation of the random number proof can be to first take the public key pub_j and private key s_j, as well as the random number seed as input, and then obtain the random number proof, that is, the random number, through the corresponding function operation, and broadcast its own random number result and random number (that is, the verifiable random number) to the other N nodes.
[0071] In this embodiment, by traversing each target service node, a hash calculation is performed based on the private key of the traversed target service node and a preset random number algorithm to obtain the node random number and random number result corresponding to the target service node, thereby providing a basis for the subsequent calculation of the final random number.
[0072] Furthermore, the step of calculating a final random number based on the random number service providing group and each of the target service nodes includes:
[0073] Step e: If all the target service nodes can respond normally, obtain the random number results corresponding to the target service nodes, calculate the average value of the random number results, and use the average value as the final random number.
[0074] In this embodiment, when calculating the final random number, it is necessary to first determine whether each target service node can respond normally. If each target service node can respond normally, the random number results corresponding to the M target service nodes are obtained, and then the average of the random number results is calculated, and the average is used as the final random number. The calculation formula for the final random number can be the final random number:
[0075] random is the final random number.
[0076] In this embodiment, when each target service node can respond normally, the average value of the random number results of each target service node is calculated, and the average value is used as the final random number, thereby ensuring the accuracy of the final random number obtained.
[0077] Furthermore, the step of determining a final signature result based on the final random number and each of the service nodes includes:
[0078] Step f, signing the final random number according to the private key of each target service node to obtain a node signature corresponding to each target service node;
[0079] In this embodiment, to obtain the final signature result, it is necessary to first obtain the private key of each target service node. Each target service node then signs the final random number using its own private key to obtain the node signature corresponding to each target service node, i.e., sig_i = s_i * H(ramdom), where H is a hash function and the signature of node i is sig_i. sig_i is then broadcast to the first M nodes. In other words, the hash value of the final random number result of the target service node is first calculated, and the product of the target service node's private key and the hash value is calculated. This product is used as the signature of the target service node, and the signature is then broadcast to the first M nodes.
[0080] Step g: If all the node signatures are valid signatures, add the node signatures to obtain a final signature result.
[0081] Each node j collects sig_i broadcast by other members and uses pub_i to verify the signature (i.e., verify the node signature), verifying whether e(pub_i, H(ramdom)) = e(G, s_i) is equal, where e is the pairing function. That is, if e(public key pub_i, hash value of the final random number H(ramdom)) = e(s_i*G, hash value of the final random number) = e(G, s_i), then the verification is determined to be successful, and the node signature is accepted as a valid signature. After M valid signatures are collected, these valid signatures are added together to restore the final signature result SIG of the threshold signature, and the final signature result SIG is broadcast.
[0082] In this embodiment, the final random number is signed according to the private key of each target service node to obtain the node signature, and the core is added when each node signature is a valid signature to obtain the final signature result, thereby ensuring the accuracy of the obtained final signature result.
[0083] Furthermore, before the step of writing the final random number back to the user contract in the blockchain based on the final signature result, the method further includes:
[0084] Step h: Determine the number of nodes of each target service node, and perform a remainder calculation on the number of search nodes based on the final random number, and determine the on-chain node of the blockchain based on the remainder calculation result, wherein the on-chain node uploads the final random number and the final signature result to the blockchain.
[0085] In this embodiment, the final random number and other information must be uploaded to the blockchain via the on-chain node, so the on-chain node must be determined. Specifically, the number of nodes of each target service node can be determined first. If the number of nodes is M, the final random number ramdom can be used to perform a modulo calculation on the number of nodes. The on-chain node of the blockchain can then be determined based on the modulo calculation result, i.e., index = ramdom % M. The resulting index is the lower table in the address list of the oracle node responsible for uploading the result to the blockchain, thus randomly determining the on-chain node. Furthermore, in this embodiment, the on-chain node uploads the final random number and final signature result to the oracle contract in the blockchain. That is, the on-chain node responsible for uploading the result will pass the proof_i {(i = 1, 2, ..., M)} generated by the M nodes, the final signature result SIG, the group private key S, and the random number result random to the oracle contract.
[0086] In this embodiment, the number of nodes of the target service node is modulo the final random number so that the blockchain's on-chain node can be determined based on the modulo calculation result, thereby ensuring the randomness of the acquired on-chain node and reducing the probability of the node failing to upload.
[0087] Furthermore, the step of writing the final random number back to the user contract in the blockchain based on the final signature result includes:
[0088] Step k: start a preset pairing function according to the blockchain, and verify the final signature result and the final random number according to the pairing function. If the verification result is that the verification passes, the final random number is written back to the user contract in the blockchain.
[0089] In this embodiment, after receiving information uploaded by an on-chain node, the oracle contract on the blockchain needs to perform signature verification. Once the signature verification passes, the final random number is written back to the user contract on the blockchain as the target random number. Signature verification includes random number signature verification and distributed signature verification. The specific signature verification steps are as follows: Calculate the correctness of each node's proof (random number) based on the specific random number and public key of each node; Analyze the random number result random_i using the random number algorithm's hash function; Obtain the random number generated by each node; Average the random numbers of M nodes and verify that they are equal to the random value. If the verification passes, the random number verification is considered to have passed, which means that the random number signature verification has passed. Based on the final random number random, the group public key, and the group private key, verify that e(P, H(ramdom)) = e(G, S). If they are equal, the distributed signature is successful. The random number random callback is written to the user contract, and the user obtains the random number. Where e is the pairing function.
[0090] In this embodiment, the final signature result and the final random number are verified according to the budgeted pairing function, and when the verification passes, the final random number is written back to the user contract of the blockchain, thereby ensuring that the user can obtain the random number in a timely manner.
[0091] The present invention also provides a blockchain random number generation device, referring to Figure 3 , the blockchain random number generation device includes:
[0092] The acquisition module A10 is used to initialize the distributed key of the random arrays of all service nodes in the blockchain to obtain the random number service provider group;
[0093] The parsing module A20 is used to control each of the service nodes to parse the request parameters corresponding to the random number request sent by the smart contract in the blockchain to determine all target service nodes corresponding to the random number request;
[0094] a calculation module A30, configured to calculate a final random number based on the random number service providing group and each of the target service nodes, and determine a final signature result based on the final random number and each of the service nodes;
[0095] The write-back module A40 is configured to write the final random number as a target random number back to the user contract in the blockchain based on the final signature result.
[0096] Optionally, the acquisition module A10 is used to:
[0097] Obtain random arrays of all service nodes in the blockchain, and calculate the key exchange content of each service node based on a preset key distribution function and each random array;
[0098] If all the key exchange contents are legal, the private key and public key of each service node are calculated according to the key exchange contents, and the private key and public key of each service node are used as a random number service providing group.
[0099] Optionally, the computing module A30 is configured to:
[0100] Traversing each of the target service nodes in sequence, and determining the private key of the traversed target service node according to the random number service providing group;
[0101] A hash calculation is performed based on the private key and a preset random number algorithm to obtain a node random number and a random number result corresponding to the traversed target service node.
[0102] Optionally, the computing module A30 is configured to:
[0103] If all the target service nodes can respond normally, the random number results corresponding to the target service nodes are obtained, and the average value of the random number results is calculated, and the average value is used as the final random number.
[0104] Optionally, the computing module A30 is configured to:
[0105] Sign the final random number according to the private key of each target service node to obtain a node signature corresponding to each target service node;
[0106] If all the node signatures are valid signatures, the node signatures are added together to obtain the final signature result.
[0107] Optionally, the write-back module A40 is configured to:
[0108] Determine the number of nodes of each of the target service nodes, perform a remainder calculation on the number of search nodes according to the final random number, and determine the on-chain node of the blockchain according to the remainder calculation result, wherein the on-chain node uploads the final random number and the final signature result to the blockchain.
[0109] Optionally, the write-back module A40 is configured to:
[0110] A preset pairing function is started according to the blockchain, and the final signature result and the final random number are verified according to the pairing function. If the verification result is that the verification passes, the final random number is written back to the user contract in the blockchain.
[0111] The methods executed by the above-mentioned program units can refer to the various embodiments of the blockchain random number generation method of the present invention, and will not be repeated here.
[0112] The present invention also provides a computer storage medium.
[0113] The computer storage medium of the present invention stores a blockchain random number generation program, which, when executed by a processor, implements the steps of the blockchain random number generation method described above.
[0114] Among them, the method implemented when the blockchain random number generation program running on the processor is executed can refer to the various embodiments of the blockchain random number generation method of the present invention, and will not be repeated here.
[0115] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or system comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or system. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or system comprising the element.
[0116] The serial numbers of the above embodiments of the present invention are for description only and do not represent the advantages or disadvantages of the embodiments.
[0117] Through the description of the above embodiments, those skilled in the art can clearly understand that the above embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better embodiment. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0118] The above are only preferred embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention description and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A blockchain random number generation method, characterized in that: The blockchain random number generation method comprises the following steps: Initialize the distributed key of the random array of all service nodes in the blockchain to obtain the random number service provider group; Control each of the service nodes to parse the request parameters corresponding to the random number request sent by the smart contract in the blockchain to determine all target service nodes corresponding to the random number request; Calculating a final random number based on the random number service providing group and each of the target service nodes, and determining a final signature result based on the final random number and each of the service nodes; Determining the number of nodes of each target service node, performing a remainder calculation on the number of search nodes according to the final random number, and determining an on-chain node of the blockchain according to the remainder calculation result, wherein the on-chain node uploads the final random number and the final signature result to the blockchain; A preset pairing function is started according to the blockchain, and the final signature result and the final random number are verified according to the pairing function. If the verification result is that the verification passes, the final random number is written back to the user contract in the blockchain as the target random number; wherein, the verification of the final signature result according to the pairing function includes random number signature verification and distributed signature verification; the distributed signature verification formula is e(P, H(random))=e(G, S), if they are equal, the distributed signature verification is successful; e is the pairing function, P is the group public key, H is the hash function, random is the final random number, G is the final signature result, and S is the group private key.
2. The blockchain random number generation method according to claim 1, wherein: The step of performing distributed key initialization on the random arrays of all service nodes in the blockchain to obtain a random number service provider group includes: Obtain random arrays of all service nodes in the blockchain, and calculate the key exchange content of each service node based on a preset key distribution function and each random array; If all the key exchange contents are legal, the private key and public key of each service node are calculated according to the key exchange contents, and the private key and public key of each service node are used as a random number service providing group.
3. The blockchain random number generation method according to claim 1, wherein: Before the step of calculating the final random number according to the random number service providing group and each of the target service nodes, the method includes: Traversing each of the target service nodes in sequence, and determining the private key of the traversed target service node according to the random number service providing group; A hash calculation is performed based on the private key and a preset random number algorithm to obtain a node random number and a random number result corresponding to the traversed target service node.
4. The blockchain random number generation method according to claim 1, wherein: The step of calculating a final random number according to the random number service providing group and each target service node includes: If all the target service nodes can respond normally, the random number results corresponding to the target service nodes are obtained, and the average value of the random number results is calculated, and the average value is used as the final random number.
5. The blockchain random number generation method according to claim 1, wherein: The step of determining the final signature result according to the final random number and each of the service nodes includes: Sign the final random number according to the private key of each target service node to obtain a node signature corresponding to each target service node; If all the node signatures are valid signatures, the node signatures are added together to obtain the final signature result.
6. A blockchain random number generation device, characterized in that: The blockchain random number generating device includes: The acquisition module is used to initialize the distributed key of the random arrays of all service nodes in the blockchain to obtain the random number service provider group; A parsing module, configured to control each of the service nodes to parse the request parameters corresponding to the random number request sent by the smart contract in the blockchain, so as to determine all target service nodes corresponding to the random number request; a calculation module, configured to calculate a final random number based on the random number service providing group and each of the target service nodes, and determine a final signature result based on the final random number and each of the service nodes; a node determination module, configured to determine the number of nodes of each target service node, perform a remainder calculation on the number of search nodes according to the final random number, and determine an on-chain node of the blockchain according to the remainder calculation result, wherein the on-chain node uploads the final random number and the final signature result to the blockchain; A write-back module is configured to start a preset pairing function according to the blockchain, and verify the final signature result and the final random number according to the pairing function. If the verification result is a pass, the final random number is written back to the user contract in the blockchain as the target random number; wherein, verifying the final signature result according to the pairing function includes random number signature verification and distributed signature verification; the distributed signature verification formula is e(P, H(random))=e(G, S), if they are equal, the distributed signature verification is successful; e is the pairing function, P is the group public key, H is the hash function, random is the final random number, G is the final signature result, and S is the group private key.
7. A blockchain random number generation device, characterized in that: The blockchain random number generation device includes: a memory, a processor, and a blockchain random number generation program stored in the memory and executable on the processor. When the blockchain random number generation program is executed by the processor, the steps of the blockchain random number generation method according to any one of claims 1 to 5 are implemented.
8. A computer storage medium, characterized in that The computer storage medium stores a blockchain random number generation program, which, when executed by a processor, implements the steps of the blockchain random number generation method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Random number generation method, block chain node, system and medium
CN110825349A