Using method and device of random number in block chain, computer equipment and storage medium

By generating random seeds in the blockchain and using system contract management, the problem of traditional random data acquisition methods being susceptible to external failures is solved, and the efficient and reliable execution of smart contracts is achieved.

CN119892364APending Publication Date: 2025-04-25TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311398817.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-10-25
Publication Date
2025-04-25

AI Technical Summary

Technical Problem

In the process of executing smart contracts, traditional random data acquisition methods are susceptible to network failures or device failures from external data sources, affecting the execution speed and reliability of smart contracts.

Method used

In blockchain, by generating random seeds in each round of consensus process and storing and managing random seeds using system contracts, a method of obtaining random numbers is provided to avoid performing a separate random number generation process every time a random number is needed.

Benefits of technology

By quickly obtaining random numbers through random seeds stored on the chain, the execution speed of smart contracts is improved, and it is not affected by network failures or device failures of external data sources, ensuring the smooth execution of smart contracts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119892364A_ABST
    Figure CN119892364A_ABST
Patent Text Reader

Abstract

The invention relates to a using method and device of random numbers in a block chain, computer equipment and a storage medium. The method comprises the steps of generating a random seed of a current round in a consensus process of entering a new round; determining a contract address of a pre-deployed system contract, and constructing and executing a system transaction for setting the random seed based on the random seed and the contract address; when the system transaction is executed, calling the system contract to store the random seed of the current round; and in the process of executing the user contract, if a scene using the random number exists, calling the system contract in a cross-contract manner to obtain a target random number generated based on the random seed of the current round. By adopting the method, the execution efficiency when the intelligent contract uses the random number can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of blockchain technology, and in particular to a method, device, computer equipment, storage medium and computer program product for using random numbers in a blockchain. Background Art

[0002] With the development of computer technology, blockchain technology has emerged. Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. It is essentially a decentralized database. Since blockchain has the characteristics of decentralization, immutability, traceability, openness and transparency, it naturally meets the execution environment required by smart contracts. Therefore, in actual applications, smart contracts are often deployed on blockchain to execute related contract operations.

[0003] Based on actual business needs, random data is often needed in the process of executing smart contracts. The traditional way of obtaining random data is usually to use an oracle to provide external random data for smart contracts, such as a certified random data provider or a trusted off-chain service. In the traditional way of using external random data, the external data source may experience downtime, delays or other technical failures, which will affect the execution speed of smart contracts. Summary of the invention

[0004] Based on this, it is necessary to provide a method, device, computer equipment, computer-readable storage medium and computer program product for using random numbers in a blockchain to address the above technical problems.

[0005] On the one hand, the present application provides a method for using random numbers in a blockchain, including:

[0006] When entering a new round of consensus, generate a random seed for the current round;

[0007] Determine the contract address of a pre-deployed system contract, construct and execute a system transaction for setting the random seed based on the random seed and the contract address;

[0008] When executing the system transaction, calling the system contract to store the random seed of the current round;

[0009] During the execution of the user contract, if there is a scenario where random numbers are used, the system contract is called across contracts to obtain the target random number generated based on the random seed of the current round.

[0010] On the other hand, the present application also provides a device for using random numbers in a blockchain, the device comprising:

[0011] The generation module is used to generate the random seed for the current round when entering a new round of consensus;

[0012] A construction module, used to determine the contract address of a pre-deployed system contract, construct and execute a system transaction for setting the random seed based on the random seed and the contract address;

[0013] A storage module, used to call the system contract to store the random seed of the current round when executing the system transaction;

[0014] The cross-contract calling module is used to call the system contract across contracts to obtain the target random number generated based on the random seed of the current round if there is a scenario of using random numbers during the execution of the user contract.

[0015] On the other hand, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.

[0016] On the other hand, the present application also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the steps of the above method when executed by a processor.

[0017] On the other hand, the present application also provides a computer program product, including a computer program, which implements the steps of the above method when executed by a processor.

[0018] The method, device, computer equipment, storage medium and computer program product for using random numbers in the above-mentioned blockchain generate a random seed for the current round in the process of entering a new round of consensus, and then construct a system transaction for setting the random seed based on the random seed and the contract address of the pre-deployed system contract and execute it. When executing the system transaction, the system contract is called to store the random seed of the current round, so that in the subsequent process of executing the user contract, if a random number is needed, the system contract can be directly called through a cross-contract call to obtain the target random number generated based on the random seed. In this way, when the user contract needs to access the random number, the random seed stored on the chain can be quickly obtained through a cross-contract call, avoiding the execution of a separate random number generation process every time a random number is needed, which greatly improves the execution speed of the user contract. In addition, the target random number used in this application does not need to be provided by an external data source, so it will not be affected by network failures or equipment failures of the external data source, which will further ensure the smooth execution of the user contract. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0020] Figure 1 This is an application environment diagram of a method for using random numbers in a blockchain in one embodiment;

[0021] Figure 2 is an optional schematic diagram of a block structure in an embodiment;

[0022] Figure 3 A flowchart of a method for using random numbers in a blockchain in one embodiment;

[0023] Figure 4 A flowchart of a method for using random numbers in a blockchain in another embodiment;

[0024] Figure 5 It is a flowchart of the steps of generating a random seed for the current round when entering a new round of consensus in one embodiment;

[0025] Figure 6 A schematic diagram of generating substitute random numbers in one embodiment;

[0026] Figure 7 A schematic diagram of random seed generation in one embodiment;

[0027] Figure 8 A schematic diagram of a process of generating and verifying system transactions in one embodiment;

[0028] Fig. 9 It is a structural block diagram of a device for using random numbers in a blockchain in one embodiment;

[0029] Fig.10 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0030] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0031] The method for using random numbers in a blockchain provided in the embodiments of the present application can be applied to Figure 1In the application environment shown. Among them, the blockchain network includes a proposal node 102 and multiple verification nodes 104, and the proposal node 102 communicates with multiple verification nodes 104 through the network. Both the proposal node 102 and the verification node 104 are consensus nodes, and are blockchain nodes in the blockchain network. The proposal node is the node responsible for generating new blocks in the blockchain network; the verification node is the node responsible for verifying new blocks in the blockchain network. It should be noted that in different rounds of consensus, the proposal node can be a different consensus node. For example, for consensus node A, in the first round of consensus, it may be a proposal node, and in the second round of consensus, it may participate in consensus as a verification node.

[0032] Both the proposal node and the verification node can be realized through a terminal or a server, where the terminal includes but is not limited to mobile phones, computers, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals, aircraft, portable wearable devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.

[0033] The method for using random numbers in the blockchain provided in the embodiment of the present application can be applied in the blockchain. Blockchain is a new application mode of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods, each of which contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, the platform product service layer, and the application service layer.

[0034] The underlying blockchain platform can include processing modules such as user management, basic services, smart contracts, and operation monitoring. Among them, the user management module is responsible for the identity information management of all blockchain participants, including maintaining public and private key generation (account management), key management, and the maintenance of the correspondence between the user's real identity and the blockchain address (authority management), etc., and, under authorization, supervises and audits the transactions of certain real identities and provides risk control rule configuration (risk control audit); the basic service module is deployed on all blockchain node devices to verify the validity of business requests, and records valid requests to storage after consensus is reached. For a new business request, the basic service first adapts the interface for parsing and authentication (interface adaptation), and then encrypts the business information through the consensus algorithm (consensus management). The smart contract module is responsible for the registration and issuance of contracts, as well as contract triggering and contract execution. Developers can define the contract logic in a programming language and publish it to the blockchain (contract registration). According to the logic of the contract terms, the key or other events are called to trigger the execution and complete the contract logic. It also provides the function of contract upgrade and cancellation. The operation monitoring module is mainly responsible for the deployment, configuration modification, contract setting, cloud adaptation and real-time status visualization output of the product during the product release process, such as alarm, network status monitoring, node equipment health status monitoring, etc.

[0035] The platform product service layer provides the basic capabilities and implementation framework of typical applications. Developers can superimpose business features based on these basic capabilities to complete the blockchain implementation of business logic. The application service layer provides application services based on blockchain solutions for business participants to use.

[0036] It should be noted that the blockchain includes a series of blocks that are connected to each other in the order of their generation. Once a new block is added to the blockchain, it will not be removed. The block records the record data submitted by the nodes in the blockchain system.

[0037] See also Figure 2 , Figure 2 This is an optional schematic diagram of the block structure provided by the embodiment of the present application. Each block includes the hash value of the transaction record stored in this block (the hash value of this block) and the hash value of the previous block. Each block is connected by the hash value to form a blockchain. In addition, the block can also include information such as the timestamp when the block was generated. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains relevant information for verifying the validity of its information (anti-counterfeiting) and generating the next block.

[0038] This application also involves the scenario of smart contracts. Smart contracts are computer protocols designed to disseminate, verify or execute contracts in an information-based manner. Smart contracts allow trusted transactions without a third party, and these transactions are queryable and irreversible. In layman's terms, a smart contract is a set computer program that can automatically execute the trusted contract content without the participation of a third-party intermediary, and all operations are publicly queryable and irreversible.

[0039] Based on actual business needs, random data is often needed in the process of executing smart contracts. The traditional way to obtain random data is usually to use an oracle to provide external random data for smart contracts, such as a certified random data provider or a trusted off-chain service. Alternatively, block hash-based random numbers use certain properties of the blockchain network as a source of random numbers, such as the hash value of the most recent block.

[0040] Generally speaking, the use of external random data may have the following risks: (1) Centralization risk: Certified random data providers or trusted off-chain services are centralized, which may reduce the decentralized nature. (2) Manipulation risk: The oracle data source may be manipulated. Malicious attackers may launch attacks on external data sources to manipulate random numbers. (3) Data reliability: External data sources may experience downtime, delays, or other technical failures, affecting the execution of smart contracts.

[0041] The random number method based on block hash may also have the following risks: (1) Miner manipulation risk: Miners may manipulate the block hash by selectively producing or discarding transactions, thereby manipulating the random number generation process. (2) Limited random source: Using a single blockchain attribute (such as block hash) as a random source may result in insufficient randomness.

[0042] Based on this, the present application provides a method for using random numbers in a blockchain. In each round of consensus, the proposal node requests the verification node to generate a random number, and constructs a random seed based on the random number generated by the verification node. This ensures that the source of the random number is distributed across multiple trusted verification nodes. On the one hand, it enriches the random source and has a strong randomness. On the other hand, it can reduce the risk of centralization and manipulation. In the process of using random numbers, the random seeds stored on the chain can be quickly obtained through cross-contract calls, avoiding the execution of a separate random number generation process every time a random number is needed, which greatly improves the execution speed of the user contract. In addition, the target random number used in this application does not need to be provided by an external data source, so it will not be affected by network failures or equipment failures of the external data source, which will further ensure the smooth execution of the user contract.

[0043] The present application is described in detail below through various embodiments:

[0044] In an exemplary embodiment, Figure 3 As shown, a method for using random numbers in a blockchain is provided, and the method is applied to Figure 1 The proposal node in is taken as an example to illustrate, including the following steps 302 to 308. Among them:

[0045] Step 302, when entering a new round of consensus, generate a random seed for the current round.

[0046] Among them, the random seed (random seed) can also be called a random number seed, which is the starting value or seed value used to generate random numbers. In machine learning and statistics, the use of random seeds can control the repeatability of random processes.

[0047] Specifically, in each round of consensus, the proposal node can generate a random seed for the current round. In some embodiments, the proposal node can generate a series of new random numbers by itself, and generate a random seed based on the series of random numbers. In other embodiments, the proposal node can obtain random numbers from other blockchain nodes, and generate a random seed based on the obtained random numbers.

[0048] Step 304, determine the contract address of the pre-deployed system contract, construct and execute a system transaction for setting the random seed based on the random seed and the contract address.

[0049] Among them, the system contract is a smart contract constructed by the blockchain system. The system contract in this application provides the functions of setting random seeds and obtaining random numbers. It should be noted that the system contract in this application is a pre-initialized smart contract, that is, when the blockchain is started, a system contract responsible for random seed storage and management is deployed.

[0050] The contract address is used to uniquely identify the address of a smart contract, and is used to implement operations such as calling the functions of the smart contract and querying the status of the smart contract. The contract address of the system contract is also used to uniquely identify the address of the system contract.

[0051] System transactions are transactions initiated by the blockchain system. In the blockchain system, interactive behaviors are collectively referred to as a transaction (Tx for short).

[0052] Specifically, in the proposal phase of each round of consensus, the proposal node will construct and execute a system transaction for setting the random seed, and the input parameter of the system transaction is the random seed generated in the previous step. The proposal node can specifically determine the contract address of the pre-deployed system contract, act as the initiator, take the random seed of the current round as the input parameter, and the contract address of the system contract as the receiver, construct and execute the system transaction for setting the random seed.

[0053] In some embodiments, the transaction content of the system transaction includes the following: initiator: proposal node; receiver: contract address of system contract; function parameter: random seed generated for the current round; transaction type: marked as system transaction; other elements of the transaction (for example, Nonce, Gas, etc., where Nonce represents a sequence number issued by the initiator to prevent transaction message replay, and Gas is the name of the cost that the transaction initiator needs to pay for each operation on the virtual machine).

[0054] In some embodiments, other nodes participating in this system transaction (such as verification nodes) need to verify and confirm the generated random seed. Specifically, the proposal node can add the system transaction for setting the random seed to the transaction list of the current block, so as to facilitate its subsequent broadcast to other nodes of the blockchain network. It should be noted that for the current block, the system transaction is the first transaction in the transaction list of the current block.

[0055] Step 306, when executing a system transaction, call the system contract to store the random seed of the current round.

[0056] Specifically, when executing a system transaction, the proposal node will call the system contract according to the contract address of the recipient in the transaction content of the system transaction, so that the system contract stores the random seed of the current round in the cache.

[0057] In some embodiments, the system contract can delete the random seeds stored in the cache and only keep the random seeds of the current round for use in the consensus phase of this round. In this way, it can be ensured that the random numbers used in the current consensus phase are generated based on the latest random seeds and will not overlap with the previous round or previous rounds, thereby improving randomness.

[0058] In some embodiments, when executing a system transaction, the system contract is called to store the random seed of the current round, including: in the process of executing the system transaction, the system contract is called to modify the random seed in the cache so that the random seed of the current round is stored in the cache.

[0059] In some embodiments, when the proposing node executes a system transaction to set a random seed, the system contract modifies the value of the random seed in the cache (Snapshot) so that the value in the cache is updated to the currently generated random seed.

[0060] In this way, when random numbers are subsequently generated through system synthesis, they can be generated based on the random seeds of the current round, ensuring that the random numbers used in the consensus phase of the current round are all generated based on the latest random seeds and will not overlap with the previous round or previous rounds, thereby improving randomness.

[0061] In some embodiments, the proposing node will add the system transaction to the transaction list of the current block after the system transaction is executed. In some embodiments, other nodes participating in this system transaction need to verify and confirm the generated random seed.

[0062] Step 308: During the execution of the user contract, if there is a scenario where random numbers are used, the system contract is called across contracts to obtain the target random number generated based on the random seed of the current round.

[0063] Among them, the user contract is a smart contract set by the user terminal, which is related to the actual business scenario. The execution conditions for execution are also agreed upon by the two or more users participating in the contract based on the contract content, and this embodiment of the application does not limit this. When the execution conditions of any user contract are met, the proposal node can automatically execute the user contract.

[0064] In some embodiments, the proposal node may receive a user transaction initiated by a user and execute a user contract through the user transaction.

[0065] In some embodiments, during the execution of a user contract, there is a scenario in which random numbers are used. This can be determined by whether there is a step of obtaining a random number during the execution of the user contract. If there is a step of obtaining a random number, it can be considered that there is a scenario in which random numbers are used. If the step of obtaining a random number is not performed, it can be considered that there is no scenario in which random numbers are used.

[0066] In some embodiments, when a proposal node is executing a user contract, if the execution of the user contract requires the use of a random number, the proposal node may call a system contract pre-deployed on the blockchain through a cross-contract call, and execute the system contract to generate a new random number based on the random seed stored in the cache, and provide the new random number as the target random number to the user contract for use, so that the user contract can continue the subsequent processing flow based on the target random number.

[0067] In some embodiments, after the user transaction is executed, the proposal node may add the user transaction to the transaction list of the current block.

[0068] In some embodiments, the method for using random numbers in the blockchain provided by the present application also includes a step of updating the random seed, which specifically includes: in the process of cross-contract calling the system contract to obtain the target random number, the system contract updates the random seed of the current round so that in the next cross-contract call process, a random number different from the target random number is generated.

[0069] Specifically, when the system contract executes the operation of obtaining a random number, it will use the random seed in the current cache to generate a new random number while performing an update operation (such as a shift operation) to ensure that the random numbers generated during multiple calls are different.

[0070] In this way, the system contract will update the random seed in the cache each time it executes the random number acquisition operation. Then the next time other user contracts call the system contract to obtain random numbers, based on obtaining new random numbers, it ensures that the random numbers used each time are different.

[0071] In some embodiments, when there is an operation to obtain a random number in some user contracts, the proposal node can call the system contract on the chain to obtain the random seed. When the system contract is executed, it returns the target random number generated by the random seed and shifts the random seed from the highest bit to the lowest bit to ensure that the random numbers returned are different when multiple calls are made. The shifted random seed will overwrite the previous random seed for the next call.

[0072] In some embodiments, whether it is a system transaction or a user transaction, the proposal node will add it to the transaction list of the current block, and when consensus is required, a consensus message will be generated and broadcast based on the transaction list. After receiving the consensus message, other nodes in the blockchain network (e.g., verification nodes and full nodes) begin to verify the legitimacy of the current block. Other nodes first verify the block header information, including the verification conditions required by the consensus protocol. If the verification conditions of the block header are met, the transaction list is further verified. When other nodes verify the transaction list, they will verify each transaction one by one. After other nodes complete the verification of all transactions, they will send the verification results to the proposal node according to the consensus protocol rules. When the proposal node determines that the consensus conditions are met based on the received verification results, the consensus is completed and the new block is confirmed. The proposal node will add the current block to the local blockchain storage and update the world state. Among them, the world state refers to a data set that records all state information on the current chain. This data set contains information such as all user accounts, smart contracts, on-chain assets and transaction records of the entire blockchain system.

[0073] Through the verification process, it can be ensured that the system transaction that sets the random seed is securely and correctly broadcast, verified, and executed in the blockchain network. This helps maintain the reliability and security of the random seed in the blockchain environment.

[0074] In the above embodiment, in the process of entering a new round of consensus, a random seed for the current round is generated, and then based on the random seed and the contract address of the pre-deployed system contract, a system transaction for setting the random seed is constructed and executed. When executing the system transaction, the system contract is called to store the random seed of the current round, so that in the subsequent execution of the user contract, if a random number is needed, the system contract can be directly called through a cross-contract call to obtain the target random number generated based on the random seed. In this way, when the user contract needs to access the random number, the random seed stored on the chain can be quickly obtained through a cross-contract call, avoiding the execution of a separate random number generation process every time a random number is needed, which greatly improves the execution speed of the user contract. In addition, the target random number used in this application does not need to be provided by an external data source, so it will not be affected by network failures or equipment failures of the external data source, which will further ensure the smooth execution of the user contract.

[0075] In some embodiments, please refer to Figure 4 , Figure 4 FIG. 1 is a flow chart of a method for using random numbers in a blockchain in one embodiment. Figure 4 As shown, the method comprises the following steps:

[0076] Step 402, initialize the system contract.

[0077] When the blockchain is started, a system contract responsible for random seed storage and management is deployed. This contract can provide the functions of setting random seeds and obtaining random numbers.

[0078] Step 404: The proposing node generates a system transaction for setting a random seed.

[0079] The proposal node generates a random seed using the random number data sent by the verification node during the consensus process. Then, it constructs a system transaction to set the random seed and adds this transaction to the current block.

[0080] Step 406, modify the value of the random seed in the cache.

[0081] When executing a system transaction that sets a random seed, the system contract will modify the value of the random seed in the cache and update it to the currently generated random seed.

[0082] Step 408: The user contract obtains a random number.

[0083] If a user contract needs to use a random number during execution, it can call the deployed system contract through a cross-contract call to obtain the random number.

[0084] Step 410, updating the random seed during the execution of the system contract.

[0085] When the system contract executes the operation of obtaining random numbers, it will use the random seed in the current cache to generate new random numbers and perform update operations (shift operations) to ensure that the random numbers generated during multiple calls are different.

[0086] In the above embodiment, when the user contract needs to access the random number, the random seed stored on the chain can be quickly obtained through cross-contract calls in this application. In this way, it is possible to avoid executing a separate random number generation process every time a random number is needed, thereby improving the execution speed of the smart contract. In addition, the present application can be applied to various blockchain consensus algorithms and scenarios. Based on actual business needs, it can be applied to different types of blockchain systems to meet various practical needs, and it has strong adaptability. In addition, the present application stores the random seed in the on-chain state by using system transactions, and all random numbers requested by smart contracts will be traceable. This helps to verify and audit behavior on the blockchain and ensure that participants follow predetermined rules and protocols.

[0087] Please refer to Figure 5 In some embodiments, when entering a new round of consensus, generating a random seed for the current round includes:

[0088] Step 502, when entering a new round of consensus, broadcast a random number generation request to multiple verification nodes, where the random number generation request is used to instruct the verification node to generate an initial random number.

[0089] Specifically, in each round of consensus, the proposal node first initiates a random number generation request to multiple verification nodes in the blockchain network. To ensure distributed randomness, each verification node can use the random number generation interface of its own operating system to generate a random number. For ease of description, the random number generated by the verification node is called the initial random number. Subsequently, the verification node can sign the generated initial random number to prevent midway manipulation, and then send it back to the proposal node.

[0090] In some embodiments, the proposing node broadcasts a random number generation request to the verifying node. The random number generation request may use a general request format and may carry the following fields: request_id: a unique identifier used to identify the request; propose_round: the consensus round in which the proposing node is located; proposer_id: a unique identifier that identifies the proposing node; operation: a string indicating the request type, such as "generate_random_number".

[0091] In some embodiments, after receiving the random number generation request, the verification node may call the random number generation interface provided by the operating system, and generate a random number through the called random number generation interface, and use it as the initial random number. For example, for Linux or macOS operating systems (specific operating system names), the random number generation interface may be / dev / urandom; for Windows systems (a specific operating system name), the random number generation interface may be: CryptGenRandom.

[0092] In some embodiments, in order to prevent the initial random number from being tampered with during transmission, the verification node can associate the initial random number with the information sent by the proposing node when feeding back the initial random number, and then sign it to ensure that the data is not tampered with during transmission.

[0093] In some embodiments, the verification node can encrypt the initial random number with its own private key to obtain the signature information, and feed the initial random number and the signature information back to the proposal node. In other embodiments, the verification node can also adopt other signature methods, such as Hash signature, Rabin signature (a signature algorithm), or DSS (Digital Signature Standard, a signature algorithm standard) signature, etc., which is not limited in the embodiments of the present application.

[0094] In this way, in each round of consensus, the proposing node requests the verifying node to generate a random number, which ensures that the source of the random number is distributed across multiple nodes.

[0095] In some embodiments, the verification node can send the encrypted initial random number and signature information to the proposal node through a secure communication protocol (such as TLS, referring to the secure transport layer protocol). This can ensure that information leakage and man-in-the-middle attacks are prevented during the transmission process.

[0096] Step 504: Receive the initial random number fed back by each verification node.

[0097] In some embodiments, the proposal node receives the initial random number fed back by each verification node. In some embodiments, the feedback data sent by the verification node includes the initial random number and signature information. The proposal node can first verify the signature information and retain the initial random number after the verification is passed. The initial random number sent by the verification node that fails the verification is discarded.

[0098] In some embodiments, the random number generation request includes a timeout threshold, and receiving the initial random number fed back by each verification node includes: when the time interval between the current time and the initiation time of the random number generation request does not reach the timeout threshold, receiving the initial random number fed back by each verification node; when the time interval reaches the timeout threshold, stopping receiving the initial random number.

[0099] Specifically, when a new round of consensus begins, the proposing node first sets a timeout threshold to ensure the timely completion of the random number generation request. Then, the proposing node can add the timeout threshold to the random number generation request. If the time interval between the current time and the initiation time of the random number generation request does not reach the timeout threshold, the initial random number fed back by each verification node is received. If the time interval reaches the timeout threshold and the initial random number fed back by all verification nodes is not received, the initial random number is stopped from being received.

[0100] In the above embodiment, by setting the timeout threshold, timely completion of the random number generation request can be ensured.

[0101] Step 506: Generate a random seed based on the received initial random number.

[0102] Specifically, the proposal node may generate a random seed based on the received initial random number. In some embodiments, the proposal node may combine the received initial random numbers to obtain a random seed. In some embodiments, the proposal node may combine the received initial random numbers and then perform a hash operation to obtain a random seed to further strengthen the random source combination.

[0103] In some embodiments, the proposal node may combine the received initial random numbers according to a preset rule, and then perform a hash operation on the combined data to obtain a hash value, and use the hash value as a random seed. The preset rules may be, for example, the order of the time of receiving the initial random numbers, or the order of the verification nodes from which the initial random numbers are derived in the node list, or the order of the size of the random numbers, etc., which are not limited in the embodiments of the present application.

[0104] In some embodiments, if the proposal node only receives the initial random numbers fed back by some verification nodes, the missing initial random numbers can be supplemented before combining. The supplementation method can be, for example, replaced by a preset value, or obtained by combining the initial random numbers fed back by adjacent verification nodes, or replaced by the current timestamp, etc., which is not limited in the embodiments of the present application.

[0105] In some embodiments, when the proposal node only receives the initial random numbers fed back by some verification nodes, if the number of received initial random numbers is greater than or equal to a preset proportion of the total number of verification nodes, such as 2 / 3, a random seed can be directly generated based on the received initial random numbers, or the missing initial random numbers can be supplemented to generate a random seed. If the number of received initial random numbers is less than the preset proportion of the total number of verification nodes, such as less than 2 / 3, it may be because the proposal node itself has a network failure or equipment failure, so other nodes in the blockchain network can act as proposal nodes and re-initiate a round of requests to ensure that a random seed can be generated in this round of consensus.

[0106] In the above embodiment, multiple verification nodes can be used to feedback initial random numbers in the process of generating random seeds, which ensures that the source of random seeds is distributed across multiple nodes. By combining the initial random numbers generated by multiple verification nodes, the randomness of the final random seeds can be enhanced. This is conducive to achieving random results that are more difficult to predict and manipulate, thereby enhancing the security of various random number-based operations in the blockchain network, such as on-chain voting, encrypted resources, etc.

[0107] In some embodiments, an initial random number fed back by each verification node is received, and a random seed is generated based on the received initial random number, including: receiving feedback data sent by each verification node, the feedback data including the initial random number and signature information; verifying the verification node based on the signature information, combining the initial random numbers fed back by the verification nodes that pass the signature verification to obtain combined data; performing a hash operation based on the combined data to obtain a random seed.

[0108] Specifically, the proposal node can receive feedback data sent by each verification node, which includes an initial random number and signature information; then verify the verification node based on the signature information, combine the initial random numbers fed back by the verification nodes that pass the signature verification, and obtain combined data; perform hash operations based on the combined data to obtain a random seed.

[0109] In some embodiments, after receiving the feedback information sent by each verification node, the proposal node first verifies the validity of the signature information. For example, the signature information is decrypted by the public key of the verification node, and the decrypted data is matched with the initial random number. If the match is successful, the signature information is considered to have passed the verification. Alternatively, the proposal node can also verify the signature information using a symmetric key pre-negotiated with the verification node. The specific verification method adopted by the proposal node depends on the signature algorithm specifically adopted by the verification node when performing digital signature, and the embodiments of the present application do not limit this.

[0110] Furthermore, if the signature information passes the verification, the proposal node can retain the initial random number fed back by the verification node. If the signature information verification fails, it means that the initial random number may have been tampered with during the transmission process, so the initial random number is discarded.

[0111] Furthermore, the proposal node can combine the initial random numbers fed back by the verification nodes through signature verification in a preset order to obtain combined data, perform a hash operation based on the combined data to obtain a hash value (such as SHA-256, a hash algorithm), and use the hash value as a random seed. The preset order can be, for example, combined in the order in the consensus node list.

[0112] In the above embodiment, distributed random number generation is adopted, and each verification node generates and signs its own initial random number. In this way, it is difficult for a malicious node to manipulate the final generated initial random number without being detected by other nodes. And by signing the initial random number generated by the verification node and the related information sent, it can be ensured that the data in the transmission process is not tampered with. In addition, by performing a hash operation on the combined data to obtain a random seed, the security and randomness of the entire generation process can be further enhanced, making malicious behavior more difficult to implement.

[0113] In some embodiments, the initial random numbers fed back by the verification nodes that pass the signature verification are combined to obtain combined data, including: when the number of verification nodes that pass the signature verification reaches a preset number, directly combining the initial random numbers fed back by the verification nodes that pass the signature verification to obtain combined data; when the number of verification nodes that pass the signature verification does not reach a preset number, supplementing the missing initial random numbers until a preset number of initial random numbers is reached, and combining the preset number of initial random numbers to obtain combined data.

[0114] Specifically, if the number of verification nodes that pass the signature verification reaches a preset number, that is, the proposal node receives the initial random numbers fed back by all the verification nodes, the received initial random numbers can be directly combined to obtain the combined data. Among them, the preset number can be the total number of all verification nodes, that is, the total number of random number generation requests sent by the proposal node, and of course it can also be a preset value less than the total number of all verification nodes, which is not limited in the embodiment of the present application.

[0115] If the number of verification nodes that pass the signature verification does not reach the preset number, that is, the proposing node has not received the initial random numbers fed back by all the verification nodes, the missing initial random numbers can be supplemented until the preset number of initial random numbers is reached, and the preset number of initial random numbers can be combined to obtain combined data.

[0116] In some embodiments, the missing initial random number can be supplemented by, for example, replacing it with a preset value, or combining the initial random numbers fed back by adjacent verification nodes, or replacing it with the current timestamp, etc., which is not limited in the embodiments of the present application.

[0117] In some embodiments, the missing initial random number is supplemented, including: determining, based on a node list, a verification node that does not pass signature verification, and determining a first verification node before the determined verification node, and a second verification node after the determined verification node; obtaining a first initial random number originating from the first verification node, and obtaining a second initial random number originating from the second verification node; based on the first initial random number and the second initial random number, generating a substitute random number to supplement the missing initial random number.

[0118] Among them, the node list can specifically be a consensus node class list, in which the order of each node is set. The proposal node can determine the verification node that does not pass the signature verification based on the node list, and the determined verification signature can also be considered as a missing verification node. For each missing verification node, the proposal node can determine the first verification node before the missing verification node and the second verification node after the missing verification node based on the node list. Then, a part of the first initial random number derived from the first verification node and a part of the second initial random number derived from the second verification node are spliced ​​to form a substitute random number, and the substitute random number is used to supplement the missing initial random number.

[0119] In some embodiments, the first verification node may be an adjacent verification node before the missing verification. If the adjacent verification node is also missing, it may be moved forward until an existing verification node is determined as the first verification node. Alternatively, if the adjacent verification node is also missing, the preset value is directly used to make up for it. Correspondingly, the second verification node may be an adjacent verification node after the missing verification node. If the adjacent verification node is also missing, it may be moved backward until an existing verification node is determined as the second verification node. Alternatively, if the adjacent verification node is also missing, the preset value is directly used to make up for it.

[0120] refer to Figure 6 , Figure 6 A schematic diagram of generating a substitute random number in one embodiment. In some embodiments, the proposal node may obtain the second half of the first initial random number (i.e., the i-1th), and obtain the first half of the second initial random number (i.e., the i+1th), and splice them together to form a substitute random number (i.e., the ith). Alternatively, the proposal node may obtain the first half of the first initial random number, and obtain the second half of the second initial random number, and splice them together to form a substitute random number.

[0121] In some embodiments, if the verification nodes before and after the missing verification node do not feedback a valid initial random number, all preset values ​​are set, such as all 0. This increases the variety of random number combinations and reduces the risk of manipulating random numbers.

[0122] In this way, when the initial random numbers fed back by all verification nodes are not received, the supplementation strategy is used to supplement them, which also reduces the risk of manipulation, because it will be difficult for malicious nodes to predict which verification nodes' initial random numbers will be used for the combination.

[0123] In some embodiments, the proposing node may combine a preset number of initial random numbers according to certain rules, such as according to the order of the reception time of the initial random numbers, or according to the order of the verification nodes from which the initial random numbers come from in the node list, or according to the order of the size of the initial random numbers, etc. The embodiments of the present application are not limited to this.

[0124] In the above embodiment, when the number of verification nodes that have passed the signature verification reaches the preset number, the initial random numbers fed back by the verification nodes that have passed the signature verification are directly combined to obtain the combined data; when the number of verification nodes that have passed the signature verification does not reach the preset number, the missing initial random numbers are supplemented to obtain the combined data. This can greatly reduce the risk of manipulation, because it will be difficult for malicious nodes to predict which verification nodes' initial random numbers will be used for the combination, further ensuring the security of random number generation.

[0125] Please refer to Figure 7, Figure 7 A schematic diagram of random seed generation in one embodiment is shown below. Figure 7 As shown:

[0126] (1) At the beginning of a new round of consensus, the proposing node first sets a timeout threshold to ensure the timely completion of the random number request. Then, the proposing node sends a random number generation request to the verification node.

[0127] (2) After receiving the random number generation request, the verification node (including verification node 1, verification node 2... verification node N, where N is a natural number greater than 1) can verify whether the request comes from the proposal node. If so, it will call the operating system random number generation interface to generate a random number locally (the random number is the initial random number mentioned above). Then, to ensure the secure transmission and integrity of the random number, the verification node will call a signature algorithm (such as ECDSA, elliptic curve digital signature algorithm) to sign the generated random number.

[0128] (3) The verification node sends the encrypted random number and signature information to the proposal node through a secure communication protocol. This ensures that information leakage and man-in-the-middle attacks are prevented during the transmission process.

[0129] (4) After receiving the random numbers sent by each verification node, the proposal node first verifies the validity of the signature. After the signature verification is passed, the aggregation algorithm will be used to combine the received random numbers to obtain a string. Specifically, the string can be combined in the order in the consensus node list. In the case of receiving random numbers fed back by some verification nodes, the proposal node uses an alternative solution (such as combining part of the random numbers of adjacent nodes or using all 0 values) to generate a substitute random number. This combination process helps to enhance randomness and ensure the reliability of the missing random numbers.

[0130] (5) The combined string is hashed to generate a hash value, which will be used as a random seed.

[0131] In the above embodiment, by combining the random numbers generated by multiple verification nodes, the randomness of the final random seed can be enhanced. This is conducive to achieving random results that are more difficult to predict and manipulate, thereby enhancing the security of various random number-based operations in the blockchain network. In addition, due to the use of distributed random number generation, each verification node generates and signs its own random number. In this way, it is difficult for malicious nodes to manipulate the final generated random number without being noticed by other nodes. In addition, the processing strategy for the random numbers of unreceived verification nodes also reduces the risk of manipulation, because it will be difficult for malicious nodes to predict which verification nodes' random numbers will be used for combination. In addition, since the random number generation method involves multiple verification nodes and proposal nodes in the complete process. The random number generation of each verification node and the splicing and hash calculation of the random seed are completely transparent to the entire network. This is conducive to improving the credibility of the blockchain network and helps prevent fraud.

[0132] In some embodiments, the method for using random numbers in the blockchain specifically includes the following steps: multiple nodes generate random numbers, that is, in each round of consensus, the proposal node requests the verification node to generate random numbers, which ensures that the sources of random numbers are distributed across multiple nodes. In addition, the proposal node can further strengthen the combination of random sources, that is, after the proposal node receives the random number from the verification node, it combines and hashes it according to certain rules to enhance randomness. When the random numbers from all verification nodes are not received, missing random numbers can be generated to make up for it. Next, the proposal node constructs a system transaction and executes it, that is, the proposal stage of each round of consensus will execute a system transaction for setting the random seed. Finally, when the user transaction is executed, the part involving random number operations obtains the random number through a cross-contract call, and the random seed is shifted after each call to ensure that multiple calls generate different random numbers.

[0133] In some embodiments, the method for using random numbers in the blockchain also includes a transaction list construction step, specifically including: adding system transactions to the transaction list of the current block; adding user transactions that trigger user contract execution to the transaction list of the current block.

[0134] Specifically, when the proposal node executes each transaction, it will add it to the transaction list after the execution is completed, so that when consensus is needed, the transaction to be verified can be obtained from the transaction list to generate a consensus message and broadcast it. In some embodiments, the consensus message can specifically be a message containing the current block.

[0135] In some embodiments, the method also includes a consensus operation, specifically including the following steps: broadcasting the transaction list of the current block to other blockchain nodes in the blockchain network to instruct other blockchain nodes to perform verification; receiving verification results fed back by other blockchain nodes, and when it is determined that the consensus conditions are met based on the verification results, adding the current block to the blockchain.

[0136] In some embodiments, whether it is a system transaction or a user transaction, the proposal node will add it to the transaction list of the current block, and when consensus is required, a consensus message will be generated and broadcast based on the transaction list. After receiving the consensus message, other nodes in the blockchain network (e.g., verification nodes and full nodes) begin to verify the legitimacy of the current block. Other nodes first verify the block header information, including the verification conditions required by the consensus protocol. If the verification conditions of the block header are met, the transaction list is further verified. When other nodes verify the transaction list, they will verify each transaction one by one. After other nodes complete the verification of all transactions, they will send the verification results to the proposal node according to the consensus protocol rules. When the proposal node determines that the consensus conditions are met based on the received verification results, the consensus is completed and the new block is confirmed. The proposal node will add the current block to the local blockchain storage and update the world state.

[0137] The following is an example of system transaction verification:

[0138] Please refer to Figure 8 , Figure 8 FIG. 1 is a flow chart of system transaction generation and verification in one embodiment. Figure 8 As shown, the generation and verification process of the system transaction for setting the random seed is as follows:

[0139] Generation process:

[0140] (1) During the consensus process, the proposing node first collects initial random numbers from other verification nodes and combines them, and then calculates the random seed.

[0141] (2) The proposal node constructs a system transaction for setting the random seed, and adds the system transaction for setting the random seed to the transaction list of the current block. The transaction data of the system transaction includes the following:

[0142] Initiator: Proposal node;

[0143] Receiver: the contract address of the system contract;

[0144] Function parameters: generated random seed;

[0145] Transaction type: Mark as system transaction;

[0146] Other elements of the transaction (e.g., Nonce, Gas, etc.).

[0147] (3) The proposing node broadcasts the transaction list to other nodes in the blockchain network (such as verification nodes).

[0148] Verification process:

[0149] (1) After receiving the current block containing the system transaction for setting the random seed, other nodes, such as the verification node, begin to verify the legitimacy of the current block. The verification node first verifies the block header information of the current block. If the block header information meets the verification conditions of the block header, it further verifies the transaction list.

[0150] (2) Verify each transaction in the transaction list one by one. The first transaction in the current block is a system transaction. The verification of the system transaction requires the following verification:

[0151] Transaction type: confirm whether the received transaction is a system transaction;

[0152] Initiator: Check whether the initiator is the proposal node;

[0153] Receiver: Check if the receiver is the contract address of the system contract;

[0154] Function parameters: confirm the generated random seed parameters;

[0155] Other elements to verify the transaction (e.g., Nonce, Gas, etc.).

[0156] (3) If the system transaction with the random seed is verified, the verification node continues to verify other transactions and obtains the verification result after completing the verification of all transactions.

[0157] (4) The verification node will send the verification result to the proposal node according to the consensus protocol rules. When the consensus conditions are met, the consensus is completed and the new block is confirmed. The proposal node or consensus node will add the current block to the local blockchain storage and update the world state.

[0158] Through the above generation and verification process, it can be ensured that the system transaction for setting the random seed is safely and correctly broadcast, verified and executed in the blockchain network. This helps to maintain the reliability and security of the random seed in the blockchain environment.

[0159] In a specific application scenario, the user contract includes a node election contract, and the method also includes: according to the obtained target random number, the node in the node list that matches the target random number is used as the proposal node for the next round of consensus, and the other nodes in the node list are used as the verification nodes for the next round of consensus.

[0160] Specifically, the proposal node can use the node in the node list that matches the target random number as the proposal node for the next round of consensus, and use the other nodes in the node list as the verification nodes for the next round of consensus.

[0161] The following is an explanation in conjunction with the specific steps of this application: in the process of entering a new round of consensus, the proposal node generates a random seed for the current round; the proposal node determines the contract address of the pre-deployed system contract, constructs and executes a system transaction for setting the random seed based on the random seed and the contract address; when executing the system transaction, the system contract is called to store the random seed for the current round; when executing the user contract for electing the proposal node for the next round, the system contract is called across contracts to obtain the target random number generated based on the random seed for the current round, and the consensus node referred to by the target random number is used as the proposal node for the next round, and the other consensus nodes are used as the verification nodes for the next round.

[0162] In the above embodiment, node election can be implemented in a safe and fast manner to determine the proposal nodes and verification nodes for the next round.

[0163] Of course, the present application can also be applied to other scenarios where random numbers are required, such as scenarios where random numbers are required to perform related calculations, etc., and the embodiments of the present application are not limited to this.

[0164] In a specific embodiment, the method for using random numbers in the blockchain in the present application includes the following steps:

[0165] When entering a new round of consensus, the proposing node broadcasts a random number generation request to multiple verification nodes. The random number generation request is used to instruct the verification node to generate an initial random number.

[0166] If the time interval between the current time and the initiation time of the random number generation request does not reach the timeout threshold, the proposal node receives the feedback data sent by each verification node; if the time interval reaches the timeout threshold, it stops receiving the initial random number. The feedback data includes the initial random number and signature information.

[0167] The proposal node verifies the verification node based on the signature information. When the number of verification nodes that have passed the signature verification reaches the preset number, the initial random numbers fed back by the verification nodes that have passed the signature verification are directly combined to obtain the combined data; when the number of verification nodes that have passed the signature verification does not reach the preset number, the verification nodes that do not pass the signature verification are determined according to the node list, and the first verification node before the determined verification node and the second verification node after the determined verification node are determined; the first initial random number from the first verification node is obtained, and the second initial random number from the second verification node is obtained; according to the first initial random number and the second initial random number, a substitute random number is generated to supplement the missing initial random number, and the preset number of initial random numbers are combined to obtain the combined data. The proposal node performs a hash operation based on the combined data to obtain a random seed.

[0168] The proposal node determines the contract address of the pre-deployed system contract, constructs a system transaction for setting the random seed based on the random seed and the contract address, and executes it; in the process of executing the system transaction, the system contract is called to modify the random seed in the cache so that the random seed of the current round is stored in the cache. The system transaction is added to the transaction list of the current block.

[0169] When the proposal node is executing the user contract, if there is a scenario where random numbers are used, the cross-contract call to the system contract is used to obtain the target random number generated based on the random seed of the current round. In the process of calling the system contract across contracts to obtain the target random number, the system contract updates the random seed of the current round so that a random number different from the target random number can be generated during the next cross-contract call. The proposal node adds the user transaction that triggers the execution of the user contract to the transaction list of the current block.

[0170] The proposal node broadcasts the transaction list of the current block to other blockchain nodes in the blockchain network to instruct other blockchain nodes to verify it; receives the verification results fed back by other blockchain nodes, and adds the current block to the blockchain when it determines that the consensus conditions are met based on the verification results.

[0171] The method for using random numbers in the above blockchain, on the one hand, can enhance the randomness of the final random seed by combining the random numbers generated by multiple verification nodes. This is conducive to achieving random results that are more difficult to predict and manipulate, thereby enhancing the security of various random number-based operations in the blockchain network. On the other hand, due to the use of distributed random number generation, each verification node generates and signs its own random number. In this way, it is difficult for malicious nodes to manipulate the final generated random number without being noticed by other nodes. In addition, supplementing the random numbers that have not been received from the verification nodes also reduces the risk of manipulation, because it will be difficult for malicious nodes to predict which verification nodes' random numbers are used for combination. On the other hand, in this application, by signing the random numbers generated by the verification nodes and the relevant information sent, the verification nodes can ensure that the data during transmission is not tampered with. In addition, the cross-contract call method and the hash operation of the random seed further enhance the security of the entire generation process, making it more difficult to implement malicious behavior. On the other hand, when the user contract needs to access the random number, the random seed stored in the on-chain state is quickly obtained by cross-contract call in this application. In this way, it is possible to avoid executing a separate random number generation process every time a random number is needed, thereby improving the execution speed of the smart contract. Moreover, by adopting system transactions to store random number seeds in the on-chain state, the random numbers requested by all smart contracts will be traceable. This helps to verify and audit the behavior on the blockchain and ensure that participants follow the predetermined rules and protocols. This application involves multiple verification nodes and proposal nodes in the implementation of the entire scheme. The random number generation of each verification node and the splicing and hash calculation of the random seeds are completely transparent to the entire network, which is conducive to improving the credibility of the blockchain network and helping to prevent fraud. In addition, the design of this application can be applied to various blockchain consensus algorithms and scenarios. By adjusting certain parameters and implementation details in the scheme, it can be applied to different types of blockchain systems to meet various practical needs.

[0172] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0173] Based on the same inventive concept, the embodiment of the present application also provides a device for using random numbers in a blockchain for implementing the method for using random numbers in the blockchain involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the embodiments of the device for using random numbers in one or more blockchains provided below can be referred to the limitations of the method for using random numbers in the blockchain above, and will not be repeated here.

[0174] In an exemplary embodiment, Fig. 9 As shown, a device 900 for using random numbers in a blockchain is provided, comprising: a generation module 901, a construction module 902, a storage module 903 and a cross-contract calling module 904, wherein:

[0175] The generation module 901 is used to generate a random seed for the current round when entering a new round of consensus.

[0176] Construction module 902 is used to determine the contract address of the pre-deployed system contract, construct and execute a system transaction for setting the random seed based on the random seed and the contract address.

[0177] Storage module 903 is used to call the system contract to store the random seed of the current round when executing system transactions.

[0178] The cross-contract calling module 904 is used to call the system contract across contracts to obtain the target random number generated based on the random seed of the current round if there is a scenario of using random numbers during the execution of the user contract.

[0179] In some embodiments, the device also includes an update module, which is used for the system contract to update the random seed of the current round during the process of cross-contract calling the system contract to obtain the target random number, so as to generate a random number different from the target random number during the next cross-contract call.

[0180] In some embodiments, the generation module is specifically used to broadcast a random number generation request to multiple verification nodes during a new round of consensus, where the random number generation request is used to instruct the verification node to generate an initial random number; receive the initial random number fed back by each verification node, and generate a random seed based on the received initial random number.

[0181] In some embodiments, the random number generation request includes a timeout threshold, and the generation module is specifically used to receive the initial random number fed back by each verification node when the time interval between the current time and the initiation time of the random number generation request does not reach the timeout threshold; when the time interval reaches the timeout threshold, stop receiving the initial random number.

[0182] In some embodiments, the generation module is specifically used to: receive feedback data sent by each verification node, the feedback data including an initial random number and signature information; verify the verification node based on the signature information, combine the initial random numbers fed back by the verification nodes that pass the signature verification to obtain combined data; perform hash operations based on the combined data to obtain a random seed.

[0183] In some embodiments, the generation module is specifically used to: when the number of verification nodes that have passed the signature verification reaches a preset number, directly combine the initial random numbers fed back by the verification nodes that have passed the signature verification to obtain combined data; when the number of verification nodes that have passed the signature verification does not reach a preset number, supplement the missing initial random numbers until a preset number of initial random numbers is reached, and combine the preset number of initial random numbers to obtain combined data.

[0184] In some embodiments, the generation module is specifically used to: determine, based on a node list, a verification node that does not pass signature verification, and determine a first verification node before the determined verification node, and a second verification node after the determined verification node; obtain a first initial random number originating from the first verification node, and obtain a second initial random number originating from the second verification node; based on the first initial random number and the second initial random number, generate a substitute random number to supplement the missing initial random number.

[0185] In some embodiments, the storage module is specifically used to call the system contract to modify the random seed in the cache during the execution of the system transaction, so that the random seed of the current round is stored in the cache.

[0186] In some embodiments, the device further includes an adding module for adding the system transaction to the transaction list of the current block; and adding the user transaction that triggers the execution of the user contract to the transaction list of the current block.

[0187] In some embodiments, the device also includes a verification module for broadcasting the transaction list of the current block to other blockchain nodes in the blockchain network to instruct other blockchain nodes to perform verification; receiving the verification results fed back by other blockchain nodes, and adding the current block to the blockchain when it is determined that the consensus conditions are met based on the verification results.

[0188] In some embodiments, the user contract includes a node election contract, and the device also includes a processing module for using the nodes in the node list that match the target random number as proposal nodes for the next round of consensus based on the acquired target random number, and using other nodes in the node list as verification nodes for the next round of consensus.

[0189] Each module in the use of random numbers in the above blockchain can be implemented in whole or in part by software, hardware, or a combination thereof. Each of the above modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.

[0190] In an exemplary embodiment, a computer device is provided, which is used to implement the function of a proposal node, and can be a terminal or a server. The internal structure diagram thereof can be as follows: Fig.10 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store messages. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for using random numbers in a blockchain is implemented.

[0191] Those skilled in the art will understand that Fig.10 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0192] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.

[0193] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.

[0194] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.

[0195] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.

[0196] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0197] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0198] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A method for using random numbers in a blockchain, characterized in that: The method comprises: When entering a new round of consensus, generate a random seed for the current round; Determine the contract address of a pre-deployed system contract, construct and execute a system transaction for setting the random seed based on the random seed and the contract address; When executing the system transaction, calling the system contract to store the random seed of the current round; During the execution of the user contract, if there is a scenario where random numbers are used, the system contract is called across contracts to obtain the target random number generated based on the random seed of the current round.

2. The method according to claim 1, characterized in that The method further comprises: In the process of cross-contract calling the system contract to obtain the target random number, the system contract updates the random seed of the current round so as to generate a random number different from the target random number during the next cross-contract call.

3. The method according to claim 1, characterized in that In the process of entering a new round of consensus, the random seed for the current round is generated, including: In the process of entering a new round of consensus, a random number generation request is broadcast to multiple verification nodes, wherein the random number generation request is used to instruct the verification nodes to generate an initial random number; Receive the initial random number fed back by each of the verification nodes, and generate a random seed based on the received initial random number.

4. The method according to claim 3, characterized in that: The random number generation request includes a timeout threshold, and the receiving of the initial random number fed back by each verification node includes: When the time interval between the current time and the initiation time of the random number generation request does not reach the timeout threshold, receiving the initial random number fed back by each of the verification nodes; When the time interval reaches the timeout threshold, the receiving of the initial random number is stopped.

5. The method according to claim 3, characterized in that: The receiving the initial random number fed back by each verification node, and generating a random seed based on the received initial random number, includes: Receiving feedback data sent by each of the verification nodes, wherein the feedback data includes an initial random number and signature information; Verifying the verification node based on the signature information, combining the initial random numbers fed back by the verification node that passed the signature verification to obtain combined data; A hash operation is performed based on the combined data to obtain a random seed.

6. The method according to claim 5, characterized in that The initial random numbers fed back by the verification nodes that pass the signature verification are combined to obtain combined data, including: When the number of verification nodes that have passed the signature verification reaches a preset number, the initial random numbers fed back by the verification nodes that have passed the signature verification are directly combined to obtain combined data; When the number of verification nodes that pass the signature verification does not reach a preset number, the missing initial random numbers are supplemented until the preset number of initial random numbers is reached, and the preset number of initial random numbers are combined to obtain combined data.

7. The method according to claim 6, characterized in that The missing initial random number is supplemented, including: Determine, according to the node list, a verification node that does not pass the signature verification, and determine a first verification node before the determined verification node, and a second verification node after the determined verification node; Obtain a first initial random number from the first verification node, and obtain a second initial random number from the second verification node; Based on the first initial random number and the second initial random number, a substitute random number is generated to make up for the missing initial random number.

8. The method according to claim 1, characterized in that When executing the system transaction, calling the system contract to store the random seed of the current round includes: During the execution of the system transaction, the system contract is called to modify the random seed in the cache so that the random seed of the current round is stored in the cache.

9. The method according to claim 1, characterized in that: The method further comprises: Add the system transaction to the transaction list of the current block; Add the user transaction that triggers the execution of the user contract to the transaction list of the current block.

10. The method according to claim 9, characterized in that The method further comprises: Broadcasting the transaction list of the current block to other blockchain nodes in the blockchain network to instruct the other blockchain nodes to verify; Receive the verification results fed back by the other blockchain nodes, and when it is determined that the consensus condition is met according to the verification results, add the current block to the blockchain.

11. The method according to any one of claims 1 to 9, characterized in that The user contract includes a node election contract, and the method further includes: According to the obtained target random number, the node in the node list that matches the target random number is used as the proposal node for the next round of consensus, and the other nodes in the node list are used as the verification nodes for the next round of consensus.

12. A device for using random numbers in a blockchain, characterized in that: The device comprises: The generation module is used to generate the random seed for the current round when entering a new round of consensus; A construction module, used to determine the contract address of a pre-deployed system contract, construct and execute a system transaction for setting the random seed based on the random seed and the contract address; A storage module, used to call the system contract to store the random seed of the current round when executing the system transaction; The cross-contract calling module is used to call the system contract across contracts to obtain the target random number generated based on the random seed of the current round if there is a scenario of using random numbers during the execution of the user contract.

13. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 11 are implemented.

14. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.

15. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.