






技术领域technical field
本发明涉及计算机技术领域,尤其涉及一种区块链中随机数的生成方法及装置。The present invention relates to the field of computer technology, in particular to a method and device for generating random numbers in a block chain.
背景技术Background technique
随机数在区块链中有很多的应用场景,例如私钥的生成和竞猜类应用等。随着区块链的不断发展,区块链中随机数的应用还将继续增加。因此,如何生成区块链中可信的随机数,对于区块链中资产的安全性和应用的公平性来说十分重要。Random numbers have many application scenarios in the blockchain, such as the generation of private keys and guessing applications. With the continuous development of the blockchain, the application of random numbers in the blockchain will continue to increase. Therefore, how to generate credible random numbers in the blockchain is very important for the security of assets in the blockchain and the fairness of applications.
现有技术中常用的随机数生成方式为:区块生产者基于区块链中一个或多个区块的哈希值作为自己的随机数种子,以计算随机数。The random number generation method commonly used in the prior art is: the block producer uses the hash value of one or more blocks in the blockchain as its own random number seed to calculate the random number.
在实现本发明过程中,发明人发现现有技术中至少存在如下问题:区块生产者可以通过增加或放弃部分交易的方式来调整随机数,也就是说,区块生产者在随机数生成过程中存在作弊的可能,这导致生成的随机数的可信度较低。In the process of realizing the present invention, the inventors found that there are at least the following problems in the prior art: the block producer can adjust the random number by adding or abandoning some transactions, that is to say, the block producer There is a possibility of cheating in , which leads to low confidence in the generated random numbers.
发明内容Contents of the invention
有鉴于此,本发明实施例提供一种区块链中随机数的生成方法及装置,区块链中的各个区块链节点先分别在本地生成第一随机数以及第一随机数的第一摘要值,然后分两个阶段(第一预设时长和第二预设时长)分别向智能合约提交第一摘要值和第一随机数,智能合约对接收到的第一摘要值及其对应的第一随机数进行校验,并根据校验成功的第一随机数生成第二随机数。由此,通过两个阶段分别向智能合约提交第一摘要值和第一随机数,并由智能合约对第一摘要值和第一随机数进行校验,避免了随机数生成过程中作弊的可能,从而提高了随机数的可信度。进一步地,根据生成的可信随机数启动业务,可保证业务结果的随机性,避免人为干预带来的作弊可能,从而保证业务结果的公平性。In view of this, the embodiments of the present invention provide a method and device for generating random numbers in the blockchain. Each blockchain node in the blockchain first generates the first random number and the first random number of the first random number locally. The summary value, and then submit the first summary value and the first random number to the smart contract in two stages (the first preset duration and the second preset duration), and the smart contract will receive the first summary value and its corresponding The first random number is verified, and the second random number is generated according to the first random number whose verification is successful. Therefore, the first digest value and the first random number are submitted to the smart contract in two stages, and the smart contract verifies the first digest value and the first random number, avoiding the possibility of cheating in the random number generation process , thus improving the reliability of the random number. Furthermore, starting the business according to the generated trusted random number can guarantee the randomness of the business results, avoid the possibility of cheating caused by human intervention, and thus ensure the fairness of the business results.
为实现上述目的,根据本发明实施例的一个方面,提供了一种区块链中随机数的生成方法。To achieve the above purpose, according to an aspect of the embodiments of the present invention, a method for generating random numbers in a blockchain is provided.
本发明实施例的一种区块链中随机数的生成方法包括:至少一个区块链节点分别在本地生成第一随机数,以及所述第一随机数的第一摘要值;A method for generating a random number in a blockchain according to an embodiment of the present invention includes: at least one blockchain node locally generates a first random number and a first summary value of the first random number;
在第一预设时长内,所述至少一个区块链节点分别向所述区块链的智能合约提交所述第一摘要值;Within a first preset time period, the at least one block chain node submits the first abstract value to the smart contract of the block chain respectively;
在所述第一预设时长计时结束后启动的第二预设时长内,所述至少一个区块链节点向所述智能合约提交所述第一随机数;Within a second preset time period started after the first preset time period ends, the at least one blockchain node submits the first random number to the smart contract;
所述智能合约对接收到的至少一个所述第一摘要值以及所述第一摘要值对应的所述第一随机数进行校验;The smart contract checks the received at least one first digest value and the first random number corresponding to the first digest value;
根据校验成功的第一随机数,生成第二随机数;Generate a second random number according to the first random number successfully verified;
根据所述第二随机数,启动业务。Start a service according to the second random number.
可选地,当所述智能合约确定校验成功的所述第一随机数的数量不小于预设数量阈值时,根据校验成功的所述第一随机数,生成所述第二随机数。Optionally, when the smart contract determines that the number of the first random numbers that are verified successfully is not less than a preset number threshold, the second random number is generated according to the first random numbers that are successfully verified.
可选地,所述根据校验成功的所述第一随机数,生成第二随机数,包括:Optionally, the generating a second random number according to the first random number whose verification is successful includes:
按照预设运算法则对校验成功的所述第一随机数进行计算,以生成所述第二随机数。The first random number whose verification is successful is calculated according to a preset algorithm to generate the second random number.
可选地,所述根据校验成功的所述第一随机数,生成第二随机数,包括:Optionally, the generating a second random number according to the first random number whose verification is successful includes:
所述智能合约从所述至少一个区块链节点中,确定最后提交所述第一随机数的区块链节点;按照预设运算法则对所述最后提交所述第一随机数的区块链节点的摘要值以及所述校验成功的所述第一随机数进行计算,以生成所述第二随机数。The smart contract determines the blockchain node that submitted the first random number last from the at least one blockchain node; The digest value of the node and the first random number whose verification is successful are calculated to generate the second random number.
可选地,在所述第二预设时长内,所述智能合约每接收到一个所述第一随机数时,确定是否已接收到所述第一随机数对应的第一摘要值,且所述第一摘要值是在所述第一预设时长内接收的;如果是,对所述第一随机数以及对应的所述第一摘要值进行校验;Optionally, within the second preset time period, each time the smart contract receives one of the first random numbers, it determines whether the first digest value corresponding to the first random number has been received, and the The first digest value is received within the first preset duration; if so, verifying the first random number and the corresponding first digest value;
当校验成功时,递增校验成功的所述第一随机数的数量;When the verification is successful, increment the number of the first random numbers whose verification is successful;
当校验失败时,所述智能合约发出提示信息,以使提交所述第一随机数的所述区块链节点根据所述提示信息,在所述第二预设时长内重新提交所述第一随机数。When the verification fails, the smart contract sends a prompt message, so that the blockchain node that submitted the first random number resubmits the first random number within the second preset time period according to the prompt message. a random number.
可选地,所述智能合约对接收到的至少一个所述第一摘要值以及所述第一摘要值对应的所述第一随机数进行校验,包括:Optionally, the smart contract verifies the received at least one first digest value and the first random number corresponding to the first digest value, including:
针对每一对所述第一摘要值和第一随机数:所述智能合约根据所述第一随机数生成第二摘要值;其中,用于生成所述第一摘要值和所述第二摘要值的算法相同;For each pair of the first digest value and the first random number: the smart contract generates a second digest value according to the first random number; wherein, for generating the first digest value and the second digest The algorithm for the value is the same;
当所述第二摘要值和所述第一摘要值相同时,确定所述第一摘要值以及对应的第一随机数校验成功。When the second digest value is the same as the first digest value, it is determined that the verification of the first digest value and the corresponding first random number succeeds.
可选地,还包括:Optionally, also include:
所述智能合约确定校验成功的所述第一随机数对应的所述区块链节点,并向确定出的所述区块链节点发送虚拟资源。The smart contract determines the block chain node corresponding to the first random number that is verified successfully, and sends the virtual resource to the determined block chain node.
可选地,所述预设数量阈值根据所述至少一个区块链节点的数量来确定。Optionally, the preset quantity threshold is determined according to the quantity of the at least one blockchain node.
可选地,所述根据所述第二随机数,启动业务,包括:Optionally, the starting a service according to the second random number includes:
接收至少一个所述区块链节点分别提交的选择项;receiving at least one selection item respectively submitted by the blockchain nodes;
启动选择业务,以根据所述第二随机数,从所述至少一个区块链节点分别提交的所述选择项中确定出目标选择项。Start a selection service, so as to determine a target option from the options respectively submitted by the at least one blockchain node according to the second random number.
可选地,还包括:Optionally, also include:
向提交所述目标选择项的区块链节点发送虚拟资源。Sending the virtual resource to the block chain node that submitted the target selection item.
为实现上述目的,根据本发明实施例的又一方面,提供了一种区块链中随机数的生成装置。In order to achieve the above purpose, according to yet another aspect of the embodiments of the present invention, a device for generating random numbers in a blockchain is provided.
本发明实施例的一种区块链中随机数的生成装置包括:本地生成模块、提交模块、随机数生成模块和业务启动模块;其中,A device for generating random numbers in a block chain according to an embodiment of the present invention includes: a local generation module, a submission module, a random number generation module, and a business startup module; wherein,
所述本地生成模块,用于利用至少一个区块链节点分别在本地生成第一随机数,以及所述第一随机数的第一摘要值;The local generation module is configured to utilize at least one block chain node to locally generate a first random number and a first summary value of the first random number;
所述提交模块,用于在第一预设时长内,利用所述至少一个区块链节点分别向所述区块链的智能合约提交所述第一摘要值;在所述第一预设时长计时结束后启动的第二预设时长内,利用所述至少一个区块链节点想所述智能合约提交所述第一随机数;The submission module is configured to use the at least one blockchain node to submit the first summary value to the smart contract of the blockchain within a first preset time period; Within a second preset time period started after the timing ends, using the at least one blockchain node to submit the first random number to the smart contract;
所述随机数生成模块,用于利用所述智能合约对接收到的至少一个所述第一摘要值以及所述第一摘要值对应的所述第一随机数进行校验,并根据校验成功的第一随机数,生成第二随机数;The random number generation module is configured to use the smart contract to verify the received at least one first digest value and the first random number corresponding to the first digest value, and verify according to the verification success the first random number to generate the second random number;
所述业务启动模块,用于根据所述第二随机数,启动业务。The service starting module is configured to start a service according to the second random number.
可选地,所述随机数生成模块,用于当所述智能合约确定校验成功的所述第一随机数的数量不小于预设数量阈值时,根据校验成功的所述第一随机数,生成所述第二随机数。Optionally, the random number generation module is configured to, when the smart contract determines that the number of the first random numbers that are successfully verified is not less than a preset number threshold, according to the first random number that is successfully verified , to generate the second random number.
可选地,所述随机数生成模块,用于按照预设预算法则对校验成功的所述第一随机数进行计算,以生成所述第二随机数。Optionally, the random number generating module is configured to calculate the first random number that is verified successfully according to a preset budget rule, so as to generate the second random number.
可选地,所述随机数生成模块,用于利用所述智能合约从所述至少一个区块链节点中,确定最后提交所述第一随机数的区块链节点;按照预设运算法则对所述最后提交所述第一随机数的区块链节点的摘要值以及所述校验成功的所述第一随机数进行计算,以生成所述第二随机数。Optionally, the random number generation module is configured to use the smart contract to determine from the at least one blockchain node the blockchain node that submitted the first random number last; The digest value of the block chain node that submitted the first random number last and the first random number whose verification is successful are calculated to generate the second random number.
可选地,所述随机数生成模块,用于在所述第二预设时长内,当所述智能合约每接收到一个所述第一随机数时,确定是否已接收到所述第一随机数对应的第一摘要值,且所述第一摘要值是在所述第一预设时长内接收的;如果是,对所述第一随机数以及对应的第一摘要值进行校验;当校验成功时,递增校验成功的所述第一随机数的数量;当校验失败时,利用所述智能合约发出提示信息,以使提交所述第一随机数的所述区块链节点根据所述提示信息,在所述第二预设时长内重新提交所述第一随机数。Optionally, the random number generation module is configured to determine whether the first random number has been received each time the smart contract receives the first random number within the second preset time period. The first digest value corresponding to the number, and the first digest value is received within the first preset duration; if so, verify the first random number and the corresponding first digest value; when When the verification is successful, increment the number of the first random number that is successfully verified; when the verification fails, use the smart contract to send a prompt message so that the blockchain node that submitted the first random number According to the prompt information, resubmit the first random number within the second preset time period.
可选地,所述随机数生成模块,用于针对每一对所述第一摘要值和第一随机数:利用所述智能合约根据所述第一随机数生成第二摘要值;其中,用于生成所述第一摘要值和所述第二摘要值的算法相同;当所述第二摘要值和所述第一摘要值相同时,确定所述第一摘要值以及对应的第一随机数校验成功。Optionally, the random number generating module is configured to, for each pair of the first digest value and the first random number: use the smart contract to generate a second digest value according to the first random number; wherein, use The same as the algorithm for generating the first digest value and the second digest value; when the second digest value is the same as the first digest value, determine the first digest value and the corresponding first random number Validation succeeded.
可选地,所述随机数生成模块,还用于利用所述智能合约确定校验成功的所述第一随机数对应的区块链节点,并向确定出的所述区块链节点发送虚拟资源。Optionally, the random number generating module is further configured to use the smart contract to determine the block chain node corresponding to the first random number whose verification is successful, and send a virtual resource.
可选地,所述预设数量阈值根据所述至少一个区块链节点的数量来确定。Optionally, the preset quantity threshold is determined according to the quantity of the at least one blockchain node.
可选地,所述业务启动模块,用于接收至少一个所述区块链节点分别提交的选择项,启动选择业务,以根据所述第二随机数,从所述至少一个区块链节点分别提交的所述选择项中确定出目标选择项。Optionally, the service initiation module is configured to receive selection items submitted by at least one block chain node respectively, and start a selection service, so as to select from the at least one block chain node according to the second random number A target option is determined from the submitted options.
可选地,所述业务启动模块,还用于向提交所述目标选择项的区块链节点发送虚拟资源。Optionally, the service initiation module is further configured to send virtual resources to the blockchain node that submitted the target option.
为实现上述目的,根据本发明实施例的又一方面,提供了一种生成区块链中随机数的电子设备。To achieve the above purpose, according to yet another aspect of the embodiments of the present invention, an electronic device for generating random numbers in a blockchain is provided.
本发明实施例的一种生成区块链中随机数的电子设备包括:一个或多个处理器;存储装置,用于存储一个或多个程序,当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现本发明实施例的一种区块链中随机数的生成方法。An electronic device for generating random numbers in a blockchain according to an embodiment of the present invention includes: one or more processors; a storage device for storing one or more programs, when the one or more programs are used by the one or a plurality of processors, so that the one or more processors implement a method for generating random numbers in a blockchain according to an embodiment of the present invention.
为实现上述目的,根据本发明实施例的再一方面,提供了一种计算机可读存储介质。To achieve the above purpose, according to still another aspect of the embodiments of the present invention, a computer-readable storage medium is provided.
本发明实施例的一种计算机可读存储介质,其上存储有计算机程序,所述程序被处理器执行时实现本发明实施例的一种区块链中随机数的生成方法。A computer-readable storage medium according to an embodiment of the present invention stores a computer program thereon, and when the program is executed by a processor, a method for generating a random number in a block chain according to an embodiment of the present invention is implemented.
上述发明中的一个实施例具有如下优点或有益效果:区块链中的各个区块链节点先分别在本地生成第一随机数以及第一随机数的第一摘要值,然后分两个阶段(第一预设时长和第二预设时长)分别向智能合约提交第一摘要值和第一随机数,智能合约对接收到的第一摘要值及其对应的第一随机数进行校验,并根据校验成功的第一随机数生成第二随机数。由此,通过两个阶段分别向智能合约提交第一摘要值和第一随机数,并由智能合约对第一摘要值和第一随机数进行校验,避免了随机数生成过程中作弊的可能,从而提高了随机数的可信度。进一步地,根据生成的可信随机数启动业务,可保证业务结果的随机性,避免人为干预带来的作弊可能,从而保证业务结果的公平性。An embodiment of the above invention has the following advantages or beneficial effects: each blockchain node in the blockchain first generates the first random number and the first abstract value of the first random number locally, and then divides it into two stages ( The first preset duration and the second preset duration) respectively submit the first abstract value and the first random number to the smart contract, and the smart contract verifies the received first digest value and its corresponding first random number, and A second random number is generated according to the first random number whose verification is successful. Therefore, the first digest value and the first random number are submitted to the smart contract in two stages, and the smart contract verifies the first digest value and the first random number, avoiding the possibility of cheating in the random number generation process , thus improving the reliability of the random number. Furthermore, starting the business according to the generated trusted random number can guarantee the randomness of the business results, avoid the possibility of cheating caused by human intervention, and thus ensure the fairness of the business results.
上述的非惯用的可选方式所具有的进一步效果将在下文中结合具体实施方式加以说明。The further effects of the above-mentioned non-conventional alternatives will be described below in conjunction with specific embodiments.
附图说明Description of drawings
附图用于更好地理解本发明,不构成对本发明的不当限定。其中:The accompanying drawings are used to better understand the present invention, and do not constitute improper limitations to the present invention. in:
图1是根据本发明实施例的一种区块链中随机数的生成方法的主要步骤的示意图;Fig. 1 is a schematic diagram of the main steps of a method for generating random numbers in a block chain according to an embodiment of the present invention;
图2是根据本发明实施例的一种第一预设时长和第二预设时长的时间轴示意图;FIG. 2 is a schematic diagram of a time axis of a first preset duration and a second preset duration according to an embodiment of the present invention;
图3是根据本发明实施例的一种第一预设时长和第二预设时长的时间轴示意图;FIG. 3 is a schematic diagram of a time axis of a first preset duration and a second preset duration according to an embodiment of the present invention;
图4是根据本发明实施例的另一种区块链中随机数的生成方法的主要步骤的示意图;FIG. 4 is a schematic diagram of the main steps of another method for generating random numbers in a blockchain according to an embodiment of the present invention;
图5是根据本发明实施例的一种区块链中随机数的生成装置的主要模块的示意图;5 is a schematic diagram of a main module of a random number generating device in a block chain according to an embodiment of the present invention;
图6是本发明实施例可以应用于其中的示例性系统架构图;FIG. 6 is an exemplary system architecture diagram to which the embodiment of the present invention can be applied;
图7是适于用来实现本发明实施例的终端设备或服务器的计算机系统的结构示意图。Fig. 7 is a schematic structural diagram of a computer system suitable for implementing a terminal device or a server according to an embodiment of the present invention.
具体实施方式Detailed ways
以下结合附图对本发明的示范性实施例做出说明,其中包括本发明实施例的各种细节以助于理解,应当将它们认为仅仅是示范性的。因此,本领域普通技术人员应当认识到,可以对这里描述的实施例做出各种改变和修改,而不会背离本发明的范围和精神。同样,为了清楚和简明,以下的描述中省略了对公知功能和结构的描述。Exemplary embodiments of the present invention are described below in conjunction with the accompanying drawings, which include various details of the embodiments of the present invention to facilitate understanding, and they should be regarded as exemplary only. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
需要指出的是,在不冲突的情况下,本发明的实施例以及实施例中的技术特征可以相互结合。It should be noted that, in the case of no conflict, the embodiments of the present invention and the technical features in the embodiments can be combined with each other.
图1是根据本发明实施例的一种区块链中随机数的生成方法的主要步骤的示意图。Fig. 1 is a schematic diagram of main steps of a method for generating random numbers in a blockchain according to an embodiment of the present invention.
如图1所示,本发明实施例的区块链中随机数的生成方法主要包括以下步骤:As shown in Figure 1, the method for generating random numbers in the block chain of the embodiment of the present invention mainly includes the following steps:
步骤S101:至少一个区块链节点分别在本地生成第一随机数,以及所述第一随机数的第一摘要值。Step S101: At least one blockchain node locally generates a first random number and a first digest value of the first random number.
在本发明实施例中,每一个区块链节点与一个用户地址相对应,该用户地址可以与一个用户的用户信息相对应,也可以与服务器的地址相对应。In the embodiment of the present invention, each block chain node corresponds to a user address, and the user address may correspond to a user's user information, or may correspond to a server address.
在生成随机数时,区块链中的区块链节点先在本地生成第一随机数,并可通过安全散列算法生成第一随机数的第一摘要值,如通过sha256算法生成第一随机数对应的第一摘要值。为了便于描述,下面将区块链中第i个区块链节点生成的第一随机数表示为ki,将ki的第一摘要值表示为hi。When generating random numbers, the blockchain nodes in the blockchain first generate the first random number locally, and can generate the first summary value of the first random number through a secure hash algorithm, such as generating the first random number through the sha256 algorithm number corresponding to the first digest value. For the convenience of description, the first random number generated by the i-th blockchain node in the blockchain is denoted aski , and the first summary value ofki is denoted ashi .
步骤S102:在第一预设时长内,所述至少一个区块链节点分别向所述区块链的智能合约提交所述第一摘要值。Step S102: Within a first preset time period, the at least one blockchain node submits the first summary value to the smart contract of the blockchain respectively.
步骤S103:在所述第一预设时长计时结束后启动的第二预设时长内,所述至少一个区块链节点向所述智能合约提交所述第一随机数。Step S103: The at least one blockchain node submits the first random number to the smart contract within a second preset time period started after the first preset time period expires.
在区块链中的第i个区块链节点生成第一随机数ki和第一摘要值hi后,可根据智能合约的广播,在第一预设时长内向智能合约提交hi,也可以主动向智能合约提交hi。例如,第一预设时长为15min,则在这15min内,区块链中的任意区块链节点均可向智能合约提交其在本地生成的第一摘要值。在这15min结束后,智能合约标记进入第二预设时长。After the i-th blockchain node in the blockchain generates the first random number ki and the first summary valuehi , it can submit hi to the smart contract within the first preset time period according to the broadcast of the smart contract, and also You can actively submit hi to the smart contract. For example, if the first preset duration is 15 minutes, then within the 15 minutes, any blockchain node in the blockchain can submit the locally generated first summary value to the smart contract. After the end of the 15 minutes, the smart contract mark enters the second preset time period.
在第一预设时长结束后,智能合约启动第二预设时长,区块链节点不能向智能合约提交第一摘要值,而向智能合约提交第一随机数。例如,第二预设时长也为15min,则在第一预设时长结束后的15min内,区块链节点不能再向智能合约提交第一摘要值,而区块链中的第i个区块链节点可向智能合约提交第一随机数ki。After the first preset time period ends, the smart contract starts the second preset time period, and the blockchain node cannot submit the first summary value to the smart contract, but submits the first random number to the smart contract. For example, if the second preset duration is also 15 minutes, then within 15 minutes after the end of the first preset duration, the blockchain node can no longer submit the first summary value to the smart contract, and the i-th block in the blockchain The chain node can submit the first random numberki to the smart contract.
可以理解的是,第一预设时长与第二预设时长可以是相同的时长,也可以是不同的时长。It can be understood that the first preset duration and the second preset duration may be the same duration or different durations.
在第i个区块链节点根据智能合约的广播在第一预设时长内向智能合约提交hi的情况下,智能合约广播的内容可以包括:开始提交第一摘要值的提示信息和第一预设时长,在此情况下,第一预设时长的起始点为智能合约发出广播的时刻,由此使得各个区块链节点在接收到智能合约的广播后,在第一预设时长内向智能合约提交第一摘要值。此时第一预设时长、第二预设时长的时间轴以及接收到第一个第一摘要值h1的时间点的示意图可如图2所示。在图2中,h1表示智能合约在第一预设时长内接收到的第一个第一摘要值h1,hn表示智能合约在第一预设时长内接收到的最后一个第一摘要值。k1表示与h1对应的第一随机数,kn表示与hn对应的第一随机数。In the case that the i block chain node submits hi to the smart contract within the first preset time period according to the broadcast of the smart contract, the content broadcast by the smart contract may include: a prompt message to start submitting the first summary value and the first preset Set the duration. In this case, the starting point of the first preset duration is the moment when the smart contract sends out a broadcast, so that each blockchain node will send a message to the smart contract within the first preset duration after receiving the broadcast of the smart contract. Submit the first digest value. At this time, a schematic diagram of the time axis of the first preset duration, the second preset duration, and the time point when the first first digest value h1 is received may be shown in FIG. 2 . In Figure 2, h1 represents the first first digest value h1 received by the smart contract within the first preset duration, and hn represents the last first digest value received by the smart contract within the first preset duration value. k1 represents the first random number corresponding to h1 , and kn represents the first random number corresponding to hn .
从图2可以看出,智能合约接收各个第一摘要值及其分别对应的第一随机数的先后顺序可以不完全对应,也就是说,在第一预设时长内先接收到的第一摘要值(如h1),并不代表必须在第二时长内先接收到其对应的第一随机数(如k1),各个区块链节点仅需在第一预设时长内发送第一摘要值,在第二预设时长内发送第一随机数即可,而无需保证先发送第一摘要值的区块链节点也必须先发送第一随机数。当然,图2仅为一种可以实现的示意图,在本发明实施例中,也可能存在其他情况,例如,智能合约接收最后一个第一摘要值的时刻也可以在第一预设时长结束的时刻。再比如,智能合约接收各个第一摘要值及其分别对应的第一随机数的先后顺序相对应。It can be seen from Figure 2 that the order in which the smart contract receives each first digest value and its corresponding first random number may not exactly correspond, that is to say, the first digest received first within the first preset duration value (such as h1 ), it does not mean that the corresponding first random number (such as k1 ) must be received within the second duration, and each blockchain node only needs to send the first digest within the first preset duration value, it is sufficient to send the first random number within the second preset time period, and the blockchain nodes that do not need to guarantee to send the first summary value first must also send the first random number first. Of course, Figure 2 is only a schematic diagram that can be realized. In the embodiment of the present invention, other situations may also exist. For example, the moment when the smart contract receives the last first digest value can also be at the end of the first preset duration . For another example, the order in which the smart contract receives each first digest value and its corresponding first random number corresponds to the sequence.
另外,在第i个区块链节点主动在第一预设时长内向智能合约提交hi的情况下,智能合约在接收到第一个区块链节点发送的第一摘要值时,开始第一预设时长的计时。也就是说,在此情况下,第一预设时长的起始点为智能合约接收到第一个第一摘要值的时刻。此时第一预设时长、第二预设时长的时间轴以及接收到第一个第一摘要值h1的时间点的示意图可如图3所示。In addition, when the i block chain node actively submits hi to the smart contract within the first preset time period, the smart contract starts the first summary value sent by the first block chain node Timing for a preset duration. That is to say, in this case, the starting point of the first preset duration is the moment when the smart contract receives the first first digest value. At this time, a schematic diagram of the time axis of the first preset duration, the second preset duration, and the time point when the first first digest value h1 is received may be shown in FIG. 3 .
步骤S104:所述智能合约对接收到的至少一个所述第一摘要值以及所述第一摘要值对应的所述第一随机数进行校验。Step S104: The smart contract verifies the received at least one first digest value and the first random number corresponding to the first digest value.
在本发明一个实施例中,智能合约可采用如下方式对区块链节点提交的第一摘要值和第一随机数进行校验:在第二预设时长内,所述智能合约每接收到一个所述第一随机数时,确定是否已接收到所述第一随机数对应的第一摘要值,且所述第一摘要值是在所述第一预设时长内接收的;如果是,对所述第一随机数以及对应的所述第一摘要值进行校验;当校验成功时,递增校验成功的所述第一随机数的数量;当校验失败时,所述智能合约发出提示信息,以使提交所述第一随机数的所述区块链节点根据所述提示信息,在所述第二预设时长内重新提交所述第一随机数。In one embodiment of the present invention, the smart contract can check the first summary value and the first random number submitted by the blockchain nodes in the following manner: within the second preset time period, each time the smart contract receives a When the first random number is used, it is determined whether the first summary value corresponding to the first random number has been received, and the first summary value is received within the first preset time length; if yes, the The first random number and the corresponding first summary value are verified; when the verification is successful, the number of the first random number that is verified is incremented; when the verification fails, the smart contract sends Prompt information, so that the block chain node that submitted the first random number resubmits the first random number within the second preset time period according to the prompt information.
例如,在第二预设时长开始后,当智能合约接收到第i个区块链节点发送的第一随机数ki时,智能合约确定是否已在第一预设时长内接收到该第一随机数ki对应的hi,若智能合约确定出已在第一预设时长内接收到第一随机数ki对应的hi,则智能合约可校验这一对ki和hi。For example, after the start of the second preset time period, when the smart contract receives the first random numberki sent by the ith blockchain node, the smart contract determines whether the first random number ki has been received within the first preset time period. The hi corresponding to the random number ki, if the smart contract determines that the h icorresponding to the first random numberki has been received within the first preset time period, the smart contract can verify the pair ofki andhi .
具体地,在本发明一个实施例中,智能合约可采用以下方式来校验第一摘要值和第一随机数,针对每一对所述第一摘要值和第一随机数:根据所述第一随机数生成第二摘要值;其中,用于生成所述第一摘要值和所述第二摘要值的算法相同;当所述第二摘要值和所述第一摘要值相同时,确定所述第一摘要值以及对应的第一随机数校验成功。Specifically, in one embodiment of the present invention, the smart contract can verify the first digest value and the first random number in the following manner, for each pair of the first digest value and the first random number: according to the first A random number generates a second digest value; wherein, the algorithm used to generate the first digest value and the second digest value is the same; when the second digest value is the same as the first digest value, determine the The verification of the first digest value and the corresponding first random number succeeds.
仍以上述智能合约确定出已在第一预设时长内接收到第一随机数ki对应的hi为例,此时智能合约计算该第一随机数ki对应的第二摘要值h’i。值得一提的是,在计算第一随机数ki对应的第二摘要值h’i时,采用的算法与根据第一随机数ki计算第一摘要值hi的算法相同。例如,区块链节点在本地通过sha256算法计算第一随机数ki对应的第一摘要值hi,那么,在校验阶段,智能合约同样采用sha256算法计算第一随机数ki对应的第二摘要值h’i。为了便于智能合约对接收到的第一摘要值和第一随机数进行校验,计算第一随机数对应的摘要值的算法可预先写入智能合约中。Still taking the above smart contract to determine that hi corresponding to the first random number ki has been received within the first preset time period as an example, the smart contract calculates the second summary value h' corresponding to the first random number kii . It is worth mentioning that when calculating the second digest value h'i corresponding to the first random number k i, the algorithm adopted is the same as the algorithm for calculating the first digest value hi according to the first random number ki . For example, the blockchain node locally calculates the first digest value hi corresponding to the first random number ki through the sha256 algorithm, then, in the verification phase, the smart contract also uses the sha256 algorithm to calculate the first digest value hi corresponding to the first random number k i Two digest values h'i . In order for the smart contract to verify the received first digest value and the first random number, the algorithm for calculating the digest value corresponding to the first random number can be written into the smart contract in advance.
当第二摘要值h’i与第一摘要值hi相同时,确定第一摘要值hi和第一随机数ki校验成功,此时智能合约递增校验成功的第一随机数的数量。例如,在校验第一摘要值hi和第一随机数ki之前,智能合约已对i-1对第一摘要值和第一随机数进行校验,且均校验成功,即校验成功的第一随机数的数量为i-1。那么,在对第一摘要值hi和第一随机数ki进行校验之后,校验成功的第一随机数的数量递增为i。When the second digest value h'i is the same as the first digest value hi , it is determined that the verification of the first digest valuehi and the first random number ki is successful, and at this time the smart contract increments the value of the first random number successfully verified quantity. For example, before verifying the first digest value hi and the first random number ki , the smart contract has verified the first digest value and the first random number for i-1, and the verification is successful, that is, the verification The number of successful first random numbers is i-1. Then, after verifying the first digest value hi and the first random numberki , the number of first random numbers whose verification is successful is incremented to i.
当第二摘要值h’i与第一摘要值hi不相同时,确定第一摘要值hi和第一随机数ki校验失败,此时智能合约发出提示信息,以使提交第一随机数ki的第i个区块链节点根据提示信息,在第二预设时长内重新提交第一随机数,以便于可信随机数的生成。When the second summary value h'i is different from the first summary value hi , it is determined that the verification of the first summary value hi and the first random number ki fails. At this time, the smart contract sends a prompt message to make the first The i-th blockchain node of the random numberki resubmits the first random number within the second preset time period according to the prompt information, so as to facilitate the generation of trusted random numbers.
步骤S105:根据校验成功的第一随机数,生成第二随机数。Step S105: Generate a second random number according to the first random number whose verification is successful.
为了进一步提高生成第二随机数的可信度,在本发明实施例中,智能合约在确定校验成功的第一随机数的数量不小于预设数量阈值时,才根据校验成功的第一随机数,生成第二随机数。其中,所述预设数量阈值是根据所述至少一个区块链节点的数量来确定的。可以理解的是,当校验成功的第一随机数的数量小于预设数量阈值时,则无法生成第二随机数。若要继续生成第二随机数,需使得至少一个区块链节点重新提交第一摘要值和第一随机数。In order to further improve the credibility of generating the second random number, in the embodiment of the present invention, when the number of the first random numbers that have been successfully verified is determined by the smart contract to be not less than the preset number threshold, the Random number, generate a second random number. Wherein, the preset quantity threshold is determined according to the quantity of the at least one blockchain node. It can be understood that when the number of the first random numbers that are verified successfully is less than the preset number threshold, the second random number cannot be generated. To continue to generate the second random number, at least one blockchain node needs to resubmit the first summary value and the first random number.
例如,预设数量阈值可以为上述至少一个区块链节点的总数量。由于这至少一个区块链节点中,均在第一预设时长内向智能合约提交了第一摘要值,而预设数量阈值为至少一个区块链节点的总数量,则在第二预设时长内,要求这至少一个区块链节点必须提交与第一摘要值对应的第一随机数,智能合约才能根据提交的各个第一随机数生成第二随机数。也就是说,在此情况下,在第一预设时长内提交过第一摘要值,必须在第二预设时长内提交对应的第一随机数,智能合约才能生成第二随机数。For example, the preset quantity threshold may be the total quantity of the at least one blockchain node. Since at least one blockchain node has submitted the first abstract value to the smart contract within the first preset time period, and the preset quantity threshold is the total number of at least one blockchain node, then within the second preset time period Within, the at least one blockchain node is required to submit the first random number corresponding to the first summary value, so that the smart contract can generate the second random number according to the submitted first random numbers. That is to say, in this case, if the first digest value is submitted within the first preset time period, the corresponding first random number must be submitted within the second preset time period before the smart contract can generate the second random number.
上述方式对区块链中的各个区块链节点要求较为严格,若存在区块链节点在第一预设时长内提交了第一摘要值,而未在第二预设时长内提交对应的第一随机数,则会导致第二随机数生成失败。因此,为了提高生成可信随机数的成功率,在本发明优选的实施例中,将预设数量阈值设置为小于至少一个区块链节点的总数量(m)的值,例如,将预设数量阈值设置为m/2或3m/4。由此,当智能合约确定出验证成功的第一随机数的数量不小于预设数量阈值时,则无需再对之后收到的第一随机数进行验证,而直接根据已验证成功的第一随机数,生成第二随机数,由此提高生成第二随机数的成功率和效率。The above method has stricter requirements on each blockchain node in the blockchain. If there is a blockchain node that submits the first digest value within the first preset time period, but fails to submit the corresponding first summary value within the second preset time period One random number will cause the second random number to fail to be generated. Therefore, in order to improve the success rate of generating credible random numbers, in a preferred embodiment of the present invention, the preset number threshold is set to a value less than the total number (m) of at least one blockchain node, for example, the preset The quantity threshold is set to m/2 or 3m/4. Therefore, when the smart contract determines that the number of first random numbers that have been successfully verified is not less than the preset number threshold, there is no need to verify the first random number to generate a second random number, thereby improving the success rate and efficiency of generating the second random number.
当然,智能合约也可对在第二预设时长内接收到的所有第一随机数进行验证后,如在第二预设时长内接收到n个第一随机数,验证成功的第一随机数的数量为n-1个,且n-1大于预设数量阈值(假设预设数量阈值为n-5),则智能合约可根据验证成功的这n-1个第一随机数生成第二随机数。Of course, after the smart contract can also verify all the first random numbers received within the second preset time period, if n first random numbers are received within the second preset time period, the successfully verified first random numbers The number of is n-1, and n-1 is greater than the preset number threshold (assuming the preset number threshold is n-5), then the smart contract can generate the second random number based on the n-1 first random numbers that are successfully verified number.
在本发明实施例中,智能合约在根据验证成功的第一随机数生成第二随机数时,可按照预设运算法则对校验成功的所述第一随机数进行计算,以生成所述第二随机数。预设运算法则可以为或运算、与运算、或者异或运算等。优选地,本发明实施例采用异或运算对验证成功的第一随机数进行运算,以生成第二随机数。In the embodiment of the present invention, when the smart contract generates the second random number based on the first random number successfully verified, it can calculate the first random number successfully verified according to a preset algorithm to generate the second random number Two random numbers. The preset algorithm may be an OR operation, an AND operation, or an XOR operation, and the like. Preferably, in this embodiment of the present invention, an XOR operation is used to perform an operation on the successfully verified first random number to generate the second random number.
为了进一步提高第二随机数的随机性,智能合约在生成第二随机数时,还可从所述至少一个区块链节点中,确定最后提交所述第一随机数的区块链节点;然后按照预设运算法则对所述最后提交所述第一随机数的区块链节点的摘要值以及所述校验成功的所述第一随机数进行计算,以生成所述第二随机数。In order to further improve the randomness of the second random number, when the smart contract generates the second random number, it can also determine the blockchain node that submitted the first random number last from the at least one blockchain node; and then The digest value of the block chain node that submitted the first random number last and the first random number whose verification is successful are calculated according to a preset algorithm, so as to generate the second random number.
在此实施例中,最后提交第一随机数的区块链节点是指:在校验成功的第一随机数中,最后一个第一随机数的提交节点。例如,校验成功的第一随机数有n个,提交第n个第一随机数的区块链节点的摘要值为H,则智能合约可按照预设运算法则对这n个第一随机数和H进行计算,以生成第二随机数。预设运算法则可以为或运算、与运算、或者异或运算等。优选地,本发明实施例采用异或运算对验证成功的第一随机数和最后提交第一随机数的区块链节点的摘要值H进行运算,以生成第二随机数。In this embodiment, the blockchain node that submits the first random number last refers to: among the first random numbers that are successfully verified, the last node that submits the first random number. For example, there are n first random numbers that have successfully verified, and the digest value of the blockchain node that submitted the nth first random number and H to generate the second random number. The preset algorithm may be an OR operation, an AND operation, or an XOR operation, and the like. Preferably, in the embodiment of the present invention, an XOR operation is used to perform an operation on the successfully verified first random number and the digest value H of the blockchain node that submitted the first random number last, so as to generate the second random number.
另外,为了促使区块链中各个区块链节点的参与随机数的生成,也就是促使各个区块链节点在第一预设时长内发送第一摘要值以及在第二预设时长内发送第一随机数,在本发明实施例中,在生成第二随机数后,可通过智能合约向验证成功的第一随机数所对应的区块链节点发送虚拟资源,以向这些区块链节点发放奖励,从而促使更多的区块链节点通过在第一预设时长和第二预设时长发送对应的第一摘要值和第一随机数,来参与第二随机数的生成。In addition, in order to promote the generation of random numbers for each blockchain node in the blockchain, that is to prompt each blockchain node to send the first summary value within the first preset time period and the second digest value within the second preset time length. A random number. In the embodiment of the present invention, after the second random number is generated, virtual resources can be sent to the blockchain nodes corresponding to the successfully verified first random number through the smart contract, so as to issue virtual resources to these blockchain nodes Incentives, thereby prompting more blockchain nodes to participate in the generation of the second random number by sending the corresponding first digest value and the first random number at the first preset time length and the second preset time length.
步骤S106:根据所述第二随机数,启动业务。Step S106: Start a service according to the second random number.
可以理解的是,生成的可信第二随机数可应用于区块链中的多种业务,例如私钥的生成业务、测验类业务和选择类业务等。It can be understood that the generated trusted second random number can be applied to various services in the blockchain, such as private key generation services, test services, selection services, and the like.
本发明实施例以选择类业务为例,对可信第二随机数的应用进行说明。在区块链中可以通过随机数实现多种选择类业务,如体育彩票或福利彩票的生成以及中奖者的产生、招标时从多个条件相同的投标者中选择出中标者、在公司年会、推广活动或促销活动等多种活动中选择出中奖者。In the embodiment of the present invention, the application of the trusted second random number is described by taking the selection service as an example. In the blockchain, random numbers can be used to realize a variety of selection businesses, such as the generation of sports lottery or welfare lottery and the generation of winners, the selection of winners from multiple bidders with the same conditions during bidding, and the selection of winners at the company's annual meeting. Winners are selected from various activities such as promotional activities or promotional activities.
在启动选择业务时,可接收至少一个所述区块链节点分别提交的至少一个选择项;启动选择业务,以根据所述第二随机数,从所述至少一个区块链节点分别提交的所述选择项中确定出目标选择项。When the selection service is started, at least one selection item submitted by at least one block chain node may be received; the selection service is started, so that according to the second random number, the selected items respectively submitted from the at least one block chain node The target option is determined from the above options.
在此例中,区块链节点提交的选择项为区块链节点对应的选择,以在公司年会中选择出中奖者为例,该选择项对应每个员工对应的工号或其他标识,在根据第二随机数确定目标选择项的过程中,由于第二随机数是可信的,因此选择过程是随机的,避免了人为干预,因此根据第二随机数选择目标选择项的过程是随机且公平的。可以理解的是,选择出的目标选择项所对应的区块链节点即为中奖者对应的区块链节点。In this example, the option submitted by the blockchain node is the corresponding choice of the blockchain node. Taking the winner selected in the company's annual meeting as an example, the option corresponds to the job number or other identification corresponding to each employee. In the process of determining the target selection item according to the second random number, since the second random number is credible, the selection process is random and human intervention is avoided, so the process of selecting the target selection item according to the second random number is random And fair. It can be understood that the blockchain node corresponding to the selected target option is the blockchain node corresponding to the winner.
为了保证奖励发放过程的公开可信,在本发明一个实施例中,可通过智能合约向提交目标选择项的区块链节点发送虚拟资源,以向中奖者发放奖励。由此使得奖励发放过程也在区块链中进行,保证了奖励发放过程的真实可信。In order to ensure the openness and credibility of the award distribution process, in one embodiment of the present invention, virtual resources can be sent to the block chain node that submitted the target selection item through the smart contract, so as to issue rewards to the winners. As a result, the reward distribution process is also carried out in the blockchain, ensuring the authenticity of the reward distribution process.
根据上述实施例,如图4所示,本发明实施例提供的区块链中随机数的生成方法可以包括以下步骤:According to the above embodiments, as shown in Figure 4, the method for generating random numbers in the blockchain provided by the embodiments of the present invention may include the following steps:
步骤S401:至少一个区块链节点分别在本地生成第一随机数,以及所述第一随机数的第一摘要值。Step S401: At least one blockchain node locally generates a first random number and a first digest value of the first random number.
步骤S402:在第一预设时长内,所述至少一个区块链节点分别向所述区块链的智能合约提交所述第一摘要值。Step S402: Within a first preset time period, the at least one blockchain node submits the first summary value to the smart contract of the blockchain respectively.
步骤S403:在所述第一预设时长计时结束后启动的第二预设时长内,所述至少一个区块链节点向所述智能合约提交所述第一随机数。Step S403: The at least one blockchain node submits the first random number to the smart contract within a second preset time period started after the first preset time period expires.
步骤S404:在所述第二预设时长内,所述智能合约每接收到一个所述第一随机数时,根据在第一预设时长内已接收到的所述第一随机数对应的第一摘要值,对所述第一随机数进行校验,当校验成功时,执行步骤S405,校验失败时步骤S406。Step S404: Within the second preset time period, each time the smart contract receives one of the first random numbers, according to the first random number corresponding to the first random number received within the first preset time period, A digest value, check the first random number, if the check is successful, execute step S405, and if the check fails, step S406.
步骤S405:递增校验成功的所述第一随机数的数量,并执行步骤S407。Step S405: Increment the number of the first random numbers whose verification is successful, and execute step S407.
步骤S406:所述智能合约发出提示信息,以使提交所述第一随机数的所述区块链节点根据所述提示信息,在所述第二预设时长内重新提交所述第一随机数,并执行步骤S404。Step S406: The smart contract sends out a prompt message, so that the block chain node that submitted the first random number resubmits the first random number within the second preset time period according to the prompt message , and execute step S404.
步骤S407:当所述智能合约确定校验成功的所述第一随机数的数量不小于预设数量阈值时,按照异或运算对校验成功的所述第一随机数进行计算,以生成所述第二随机数。Step S407: When the smart contract determines that the number of the first random numbers that are successfully verified is not less than the preset number threshold, calculate the first random numbers that are successfully verified according to an XOR operation to generate the Describe the second random number.
步骤S408:接收至少一个所述区块链节点分别提交的选择项。Step S408: Receive at least one selection item submitted by each blockchain node.
步骤S409:启动选择业务,以根据所述第二随机数,从所述至少一个区块链节点分别提交的所述选择项中确定出目标选择项。Step S409: Start a selection service to determine a target option from the options respectively submitted by the at least one blockchain node according to the second random number.
步骤S410:向提交所述目标选择项的区块链节点发送虚拟资源。Step S410: sending the virtual resource to the blockchain node that submitted the target option.
根据本发明实施例的一种区块链中随机数的生成方法可以看出,区块链中的各个区块链节点先分别在本地生成第一随机数以及第一随机数的第一摘要值,然后分两个阶段(第一预设时长和第二预设时长)分别向智能合约提交第一摘要值和第一随机数,智能合约对接收到的第一摘要值及其对应的第一随机数进行校验,并根据校验成功的第一随机数生成第二随机数。由此,通过两个阶段分别向智能合约提交第一摘要值和第一随机数,并由智能合约对第一摘要值和第一随机数进行校验,避免了随机数生成过程中作弊的可能,从而提高了随机数的可信度。进一步地,根据生成的可信随机数启动业务,可保证业务结果的随机性,避免人为干预带来的作弊可能,从而保证业务结果的公平性。According to a method for generating random numbers in a block chain according to an embodiment of the present invention, it can be seen that each block chain node in the block chain first generates the first random number and the first summary value of the first random number locally , and then submit the first digest value and the first random number to the smart contract in two stages (the first preset duration and the second preset duration), and the smart contract will receive the first digest value and its corresponding first The random number is verified, and the second random number is generated according to the first random number whose verification is successful. Therefore, the first digest value and the first random number are submitted to the smart contract in two stages, and the smart contract verifies the first digest value and the first random number, avoiding the possibility of cheating in the random number generation process , thus improving the reliability of the random number. Furthermore, starting the business according to the generated trusted random number can guarantee the randomness of the business results, avoid the possibility of cheating caused by human intervention, and thus ensure the fairness of the business results.
图5是根据本发明实施例的一种区块链中随机数的生成装置的主要模块的示意图。Fig. 5 is a schematic diagram of main modules of a device for generating random numbers in a blockchain according to an embodiment of the present invention.
如图5所示,本发明实施例的一种区块链中随机数的生成装置500包括:本地生成模块501、提交模块502、随机数生成模块503和业务启动模块504;其中,As shown in Figure 5, a random
所述本地生成模块501,用于利用至少一个区块链节点分别在本地生成第一随机数,以及所述第一随机数的第一摘要值;The
所述提交模块502,用于在第一预设时长内,利用所述至少一个区块链节点分别向所述区块链的智能合约提交所述第一摘要值;在所述第一预设时长计时结束后启动的第二预设时长内,利用所述至少一个区块链节点想所述智能合约提交所述第一随机数;The
所述随机数生成模块503,用于利用所述智能合约对接收到的至少一个所述第一摘要值以及所述第一摘要值对应的所述第一随机数进行校验,并根据校验成功的第一随机数,生成第二随机数;The random
所述业务启动模块504,用于根据所述第二随机数,启动业务。The
在本发明一个实施例中,所述随机数生成模块503,用于当所述智能合约确定校验成功的所述第一随机数的数量不小于预设数量阈值时,根据校验成功的所述第一随机数,生成所述第二随机数。In an embodiment of the present invention, the random
在本发明一个实施例中,所述随机数生成模块503,用于按照预设预算法则对校验成功的所述第一随机数进行计算,以生成所述第二随机数。In one embodiment of the present invention, the random
在本发明一个实施例中,所述随机数生成模块503,用于利用所述智能合约从所述至少一个区块链节点中,确定最后提交所述第一随机数的区块链节点;按照预设运算法则对所述最后提交所述第一随机数的区块链节点的摘要值以及所述校验成功的所述第一随机数进行计算,以生成所述第二随机数。In one embodiment of the present invention, the random
在本发明一个实施例中,所述随机数生成模块503,用于在所述第二预设时长内,当所述智能合约每接收到一个所述第一随机数时,确定是否已接收到所述第一随机数对应的第一摘要值,且所述第一摘要值是在所述第一预设时长内接收的;如果是,对所述第一随机数以及对应的第一摘要值进行校验;当校验成功时,递增校验成功的所述第一随机数的数量;当校验失败时,利用所述智能合约发出提示信息,以使提交所述第一随机数的所述区块链节点根据所述提示信息,在所述第二预设时长内重新提交所述第一随机数。In one embodiment of the present invention, the random
在本发明一个实施例中,所述随机数生成模块503,用于针对每一对所述第一摘要值和第一随机数:利用所述智能合约根据所述第一随机数生成第二摘要值;其中,用于生成所述第一摘要值和所述第二摘要值的算法相同;当所述第二摘要值和所述第一摘要值相同时,确定所述第一摘要值以及对应的第一随机数校验成功。In one embodiment of the present invention, the random
在本发明一个实施例中,所述随机数生成模块503,还用于利用所述智能合约确定校验成功的所述第一随机数对应的区块链节点,并向确定出的所述区块链节点发送虚拟资源。In an embodiment of the present invention, the random
在本发明一个实施例中,所述预设数量阈值根据所述至少一个区块链节点的数量来确定。In an embodiment of the present invention, the preset quantity threshold is determined according to the quantity of the at least one blockchain node.
在本发明一个实施例中,所述业务启动模块504,用于接收至少一个所述区块链节点分别提交的选择项,启动选择业务,以根据所述第二随机数,从所述至少一个区块链节点分别提交的所述选择项中确定出目标选择项。In one embodiment of the present invention, the
在本发明一个实施例中,所述业务启动模块504,还用于向提交所述目标选择项的区块链节点发送虚拟资源。In an embodiment of the present invention, the
根据本发明实施例的一种区块链中随机数的生成装置可以看出,区块链中的各个区块链节点先分别在本地生成第一随机数以及第一随机数的第一摘要值,然后分两个阶段(第一预设时长和第二预设时长)分别向智能合约提交第一摘要值和第一随机数,智能合约对接收到的第一摘要值及其对应的第一随机数进行校验,并根据校验成功的第一随机数生成第二随机数。由此,通过两个阶段分别向智能合约提交第一摘要值和第一随机数,并由智能合约对第一摘要值和第一随机数进行校验,避免了随机数生成过程中作弊的可能,从而提高了随机数的可信度。进一步地,根据生成的可信随机数启动业务,可保证业务结果的随机性,避免人为干预带来的作弊可能,从而保证业务结果的公平性。According to a device for generating random numbers in a block chain according to an embodiment of the present invention, it can be seen that each block chain node in the block chain first generates the first random number and the first summary value of the first random number locally , and then submit the first digest value and the first random number to the smart contract in two stages (the first preset duration and the second preset duration), and the smart contract will receive the first digest value and its corresponding first The random number is verified, and the second random number is generated according to the first random number whose verification is successful. Therefore, the first digest value and the first random number are submitted to the smart contract in two stages, and the smart contract verifies the first digest value and the first random number, avoiding the possibility of cheating in the random number generation process , thus improving the reliability of the random number. Furthermore, starting the business according to the generated trusted random number can guarantee the randomness of the business results, avoid the possibility of cheating caused by human intervention, and thus ensure the fairness of the business results.
图6示出了可以应用本发明实施例的一种区块链中随机数的生成方法或一种区块链中随机数的生成装置的示例性系统架构600。Fig. 6 shows an
如图6所示,系统架构600可以包括终端设备601、602、603,网络604和服务器605。网络604用以在终端设备601、602、603和服务器605之间提供通信链路的介质。网络604可以包括各种连接类型,例如有线、无线通信链路或者光纤电缆等等。As shown in FIG. 6 , a
用户可以使用终端设备601、602、603通过网络604与服务器605交互,以接收或发送消息等。终端设备601、602、603上可以安装有各种通讯客户端应用,例如购物类应用、网页浏览器应用、搜索类应用、即时通信工具、邮箱客户端、社交平台软件等。Users can use
终端设备601、602、603可以是具有显示屏并且支持网页浏览的各种电子设备,包括但不限于智能手机、平板电脑、膝上型便携计算机和台式计算机等等。The
服务器605可以是提供各种服务的服务器,例如对用户利用终端设备601、602、603所浏览的购物类网站提供支持的后台管理服务器。后台管理服务器可以对接收到的产品信息查询请求等数据进行分析等处理,并将处理结果(例如目标推送信息、产品信息)反馈给终端设备。The
需要说明的是,本发明实施例所提供的一种区块链中随机数的生成方法一般由服务器605执行,相应地,一种区块链中随机数的生成装置一般设置于服务器605中。It should be noted that the method for generating random numbers in the blockchain provided by the embodiment of the present invention is generally executed by the
应该理解,图6中的终端设备、网络和服务器的数目仅仅是示意性的。根据实现需要,可以具有任意数目的终端设备、网络和服务器。It should be understood that the numbers of terminal devices, networks and servers in FIG. 6 are only illustrative. According to the implementation needs, there can be any number of terminal devices, networks and servers.
下面参考图7,其示出了适于用来实现本发明实施例的终端设备的计算机系统700的结构示意图。图7示出的终端设备仅仅是一个示例,不应对本发明实施例的功能和使用范围带来任何限制。Referring now to FIG. 7 , it shows a schematic structural diagram of a
如图7所示,计算机系统700包括中央处理单元(CPU)701,其可以根据存储在只读存储器(ROM)702中的程序或者从存储部分708加载到随机访问存储器(RAM)703中的程序而执行各种适当的动作和处理。在RAM 703中,还存储有系统700操作所需的各种程序和数据。CPU 701、ROM 702以及RAM 703通过总线704彼此相连。输入/输出(I/O)接口705也连接至总线704。As shown in FIG. 7 , a
以下部件连接至I/O接口705:包括键盘、鼠标等的输入部分706;包括诸如阴极射线管(CRT)、液晶显示器(LCD)等以及扬声器等的输出部分707;包括硬盘等的存储部分708;以及包括诸如LAN卡、调制解调器等的网络接口卡的通信部分709。通信部分709经由诸如因特网的网络执行通信处理。驱动器710也根据需要连接至I/O接口705。可拆卸介质711,诸如磁盘、光盘、磁光盘、半导体存储器等等,根据需要安装在驱动器710上,以便于从其上读出的计算机程序根据需要被安装入存储部分708。The following components are connected to the I/O interface 705: an
特别地,根据本发明公开的实施例,上文参考流程图描述的过程可以被实现为计算机软件程序。例如,本发明公开的实施例包括一种计算机程序产品,其包括承载在计算机可读介质上的计算机程序,该计算机程序包含用于执行流程图所示的方法的程序代码。在这样的实施例中,该计算机程序可以通过通信部分709从网络上被下载和安装,和/或从可拆卸介质711被安装。在该计算机程序被中央处理单元(CPU)701执行时,执行本发明的系统中限定的上述功能。In particular, according to the disclosed embodiments of the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the disclosed embodiments of the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, where the computer program includes program codes for executing the methods shown in the flowcharts. In such an embodiment, the computer program may be downloaded and installed from a network via
需要说明的是,本发明所示的计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质或者是上述两者的任意组合。计算机可读存储介质例如可以是——但不限于——电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。计算机可读存储介质的更具体的例子可以包括但不限于:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、随机访问存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑磁盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。在本发明中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。而在本发明中,计算机可读的信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。计算机可读的信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。计算机可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于:无线、电线、光缆、RF等等,或者上述的任意合适的组合。It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. A computer readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to, electrical connections with one or more wires, portable computer diskettes, hard disks, random access memory (RAM), read-only memory (ROM), erasable Programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, however, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, in which computer-readable program codes are carried. Such propagated data signals may take many forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. . Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
附图中的流程图和框图,图示了按照本发明各种实施例的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段、或代码的一部分,上述模块、程序段、或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个接连地表示的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图或流程图中的每个方框、以及框图或流程图中的方框的组合,可以用执行规定的功能或操作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。The flowchart and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, program segment, or portion of code that includes one or more logical functions for implementing specified executable instructions. It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or they may sometimes be executed in the reverse order, depending upon the functionality involved. It should also be noted that each block in the block diagrams or flowchart illustrations, and combinations of blocks in the block diagrams or flowchart illustrations, can be implemented by a dedicated hardware-based system that performs the specified function or operation, or can be implemented by a A combination of dedicated hardware and computer instructions.
描述于本发明实施例中所涉及到的模块可以通过软件的方式实现,也可以通过硬件的方式来实现。所描述的模块也可以设置在处理器中,例如,可以描述为:一种处理器包括本地生成模块、提交模块、随机数生成模块和业务启动模块。其中,这些模块的名称在某种情况下并不构成对该模块本身的限定,例如,随机数生成模块还可以被描述为“根据校验成功的第一随机数生成第二随机数的模块”。The modules involved in the embodiments described in the present invention may be realized by software or by hardware. The described modules can also be set in a processor, for example, it can be described as: a processor includes a local generation module, a submission module, a random number generation module and a service initiation module. Among them, the names of these modules do not constitute a limitation on the module itself under certain circumstances. For example, the random number generation module can also be described as "a module that generates a second random number based on the first random number that is verified successfully" .
作为另一方面,本发明还提供了一种计算机可读介质,该计算机可读介质可以是上述实施例中描述的设备中所包含的;也可以是单独存在,而未装配入该设备中。上述计算机可读介质承载有一个或者多个程序,当上述一个或者多个程序被一个该设备执行时,使得该设备包括:至少一个区块链节点分别在本地生成第一随机数,以及所述第一随机数的第一摘要值;在第一预设时长内,所述至少一个区块链节点分别向所述区块链的智能合约提交所述第一摘要值;在所述第一预设时长计时结束后启动的第二预设时长内,所述至少一个区块链节点向所述智能合约提交所述第一随机数;所述智能合约对接收到的至少一个所述第一摘要值以及所述第一摘要值对应的所述第一随机数进行校验;根据校验成功的第一随机数,生成第二随机数;根据所述第二随机数,启动业务。As another aspect, the present invention also provides a computer-readable medium. The computer-readable medium may be contained in the device described in the above embodiments, or it may exist independently without being assembled into the device. The above-mentioned computer-readable medium carries one or more programs, and when the above-mentioned one or more programs are executed by one of the devices, the device includes: at least one block chain node generates a first random number locally, and the The first summary value of the first random number; within the first preset time period, the at least one block chain node submits the first summary value to the smart contract of the block chain respectively; Within the second preset time period started after the end of the set time period, the at least one block chain node submits the first random number to the smart contract; the smart contract receives at least one of the first summary Value and the first random number corresponding to the first summary value are verified; a second random number is generated according to the first random number that is verified successfully; and a service is started according to the second random number.
根据本发明实施例的技术方案,区块链中的各个区块链节点先分别在本地生成第一随机数以及第一随机数的第一摘要值,然后分两个阶段(第一预设时长和第二预设时长)分别向智能合约提交第一摘要值和第一随机数,智能合约对接收到的第一摘要值及其对应的第一随机数进行校验,并根据校验成功的第一随机数生成第二随机数。由此,通过两个阶段分别向智能合约提交第一摘要值和第一随机数,并由智能合约对第一摘要值和第一随机数进行校验,避免了随机数生成过程中作弊的可能,从而提高了随机数的可信度。进一步地,根据生成的可信随机数启动业务,可保证业务结果的随机性,避免人为干预带来的作弊可能,从而保证业务结果的公平性。According to the technical solution of the embodiment of the present invention, each blockchain node in the blockchain first generates the first random number and the first abstract value of the first random number locally, and then divides it into two stages (the first preset duration and the second preset duration) respectively submit the first digest value and the first random number to the smart contract, and the smart contract verifies the received first digest value and its corresponding first random number, and according to the successful The first random number generates the second random number. Therefore, the first digest value and the first random number are submitted to the smart contract in two stages, and the smart contract verifies the first digest value and the first random number, avoiding the possibility of cheating in the random number generation process , thus improving the reliability of the random number. Furthermore, starting the business according to the generated trusted random number can guarantee the randomness of the business results, avoid the possibility of cheating caused by human intervention, and thus ensure the fairness of the business results.
上述具体实施方式,并不构成对本发明保护范围的限制。本领域技术人员应该明白的是,取决于设计要求和其他因素,可以发生各种各样的修改、组合、子组合和替代。任何在本发明的精神和原则之内所作的修改、等同替换和改进等,均应包含在本发明保护范围之内。The above specific implementation methods do not constitute a limitation to the protection scope of the present invention. It should be apparent to those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent replacements and improvements made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202110233267.5ACN112910643B (en) | 2021-03-03 | 2021-03-03 | Method and device for generating random number in block chain |
| PCT/CN2022/079062WO2022184137A1 (en) | 2021-03-03 | 2022-03-03 | Method and apparatus for generating random numbers in blockchain |
| US18/280,202US20240146509A1 (en) | 2021-03-03 | 2022-03-03 | Method and Apparatus for Generating Random Number in Blockchain |
| EP22762599.3AEP4304131A4 (en) | 2021-03-03 | 2022-03-03 | METHOD AND APPARATUS FOR GENERATING RANDOM NUMBERS IN A BLOCKCHAIN |
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202110233267.5ACN112910643B (en) | 2021-03-03 | 2021-03-03 | Method and device for generating random number in block chain |
| Publication Number | Publication Date |
|---|---|
| CN112910643A CN112910643A (en) | 2021-06-04 |
| CN112910643Btrue CN112910643B (en) | 2023-04-07 |
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202110233267.5AActiveCN112910643B (en) | 2021-03-03 | 2021-03-03 | Method and device for generating random number in block chain |
| Country | Link |
|---|---|
| CN (1) | CN112910643B (en) |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| WO2022184137A1 (en)* | 2021-03-03 | 2022-09-09 | 中国人民银行数字货币研究所 | Method and apparatus for generating random numbers in blockchain |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109558112A (en)* | 2018-11-14 | 2019-04-02 | 杭州复杂美科技有限公司 | Random digit generation method, anti-cheating block catenary system, equipment and storage medium |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN110868286B (en)* | 2018-12-29 | 2023-05-12 | 北京版全家科技发展有限公司 | Method for generating random number based on blockchain intelligent contract |
| WO2020146955A1 (en)* | 2019-01-18 | 2020-07-23 | Zeu Crypto Networks Inc. | A method for generating random numbers in blockchain smart contracts |
| CN110430045B (en)* | 2019-07-17 | 2021-10-01 | 上海朝夕网络技术有限公司 | Random number generation method based on distributed consensus algorithm |
| CN111327427B (en)* | 2020-02-02 | 2021-06-11 | 腾讯科技(深圳)有限公司 | Method, device, node equipment, system and storage medium for submitting alternative blocks |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109558112A (en)* | 2018-11-14 | 2019-04-02 | 杭州复杂美科技有限公司 | Random digit generation method, anti-cheating block catenary system, equipment and storage medium |
| Publication number | Publication date |
|---|---|
| CN112910643A (en) | 2021-06-04 |
| Publication | Publication Date | Title |
|---|---|---|
| US12126732B2 (en) | Blockchain consensus method, device and system | |
| US8225387B2 (en) | Method and system for access authentication | |
| CN110879903A (en) | Evidence storage method, evidence verification method, evidence storage device, evidence verification device, evidence storage equipment and evidence verification medium | |
| CN110602098A (en) | Identity authentication method, device, equipment and storage medium | |
| US20220217004A1 (en) | Systems and methods for non-parallelised mining on a proof-of-work blockchain network | |
| CN112910643B (en) | Method and device for generating random number in block chain | |
| CN109379179B (en) | Method and apparatus for updating digital certificates | |
| CN108449186B (en) | Security verification method and device | |
| CN114881789A (en) | Mobile banking carbon transaction method and device | |
| CN112968769B (en) | Method and device for generating random number in block chain | |
| CN110751467A (en) | A method and system for generating digital currency | |
| CN112905990A (en) | Access method, client, server and access system | |
| CN115037507B (en) | User access management method, device and system | |
| US8412844B2 (en) | Validating download success | |
| EP4365808A1 (en) | Data verification method and apparatus | |
| CN114422586B (en) | Event notification method, device, computer equipment and storage medium | |
| CN111786936A (en) | Method and device for authentication | |
| CN112383542B (en) | User login method and system, authentication end and user end | |
| CN114328731B (en) | Information processing method, device, electronic device and storage medium | |
| US20240193594A1 (en) | Method, Terminal and System for Splitting and Managing Digital Currency in Transaction | |
| EP4304131A1 (en) | Method and apparatus for generating random numbers in blockchain | |
| CN110688677B (en) | Method and device for executing intelligent contracts | |
| CN110602074A (en) | Service identity using method, device and system based on master-slave association | |
| CN117580004B (en) | Service processing method, device and system based on 5G message | |
| CN119512504B (en) | Random number generation method, device and electronic equipment |
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |