Computing Method, Device and Electronic Device Based on Smart Contract

By introducing a random sampling mechanism into smart contracts, the data sets on the blockchain are calculated approximately, which solves the problem of excessively long calculation of large data volumes and achieves a significant improvement in computing efficiency.

CN114693451BActive Publication Date: 2025-06-17ANT BLOCKCHAIN TECHNOLOGY (SHANGHAI) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210334237.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-30
Publication Date
2025-06-17
Estimated Expiration
2042-03-30

AI Technical Summary

Technical Problem

When performing smart contracts on blockchain to calculate data sets, the large amount of data makes the calculation time too long, making it difficult to meet the real-time and efficiency of business needs.

Method used

A random sampling mechanism is introduced in smart contracts to perform approximate calculations of data sets, and the amount of calculation data is reduced through random sampling, thereby improving computing efficiency.

Benefits of technology

Without sacrificing the accuracy of the approximate calculation results, the time-consuming and time-consuming calculation of the data set is significantly reduced and the calculation efficiency is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114693451B_ABST
    Figure CN114693451B_ABST
Patent Text Reader

Abstract

A computing method based on a smart contract, which is applied to a node device in a blockchain. A smart contract for performing approximate computing is deployed on the blockchain, and the method includes: receiving a smart contract call transaction initiated by a computing initiator for the smart contract; wherein the smart contract call transaction includes computing parameters corresponding to the approximate computing; the computing parameters include data identifiers of a data set participating in the approximate computing; in response to the smart contract call transaction, calling the sampling logic included in the smart contract to perform stratified sampling on data samples in the data set corresponding to the data identifiers, and further calling the approximate computing logic included in the smart contract to perform approximate computing based on the data samples obtained by stratified sampling from the data set, so as to obtain an approximate computing result for the data set.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] One or more embodiments of this specification relate to the field of blockchain technology, and in particular, to a calculation method and device based on smart contracts, and an electronic device. Background Art

[0002] Blockchain is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, and encryption algorithms. In a blockchain system, data blocks are combined into a chain data structure in a sequential connection manner according to the time sequence, and a distributed ledger that is tamper-proof and unforgeable is guaranteed by cryptographic means. Due to the characteristics of decentralization, information immutability, and autonomy of the blockchain, the blockchain has received more and more attention and applications. Summary of the Invention

[0003] This specification proposes a calculation method based on smart contracts, which is applied to a node device in a blockchain. A smart contract for performing approximate calculation is deployed on the blockchain. The method includes:

[0004] Receiving a smart contract call transaction initiated by a calculation initiator for the smart contract; wherein, the smart contract call transaction includes calculation parameters corresponding to the approximate calculation; the calculation parameters include data identifiers of a data set participating in the approximate calculation;

[0005] In response to the smart contract call transaction, invoking a sampling logic included in the smart contract to randomly sample data samples in the data set corresponding to the data identifier, and further invoking an approximate calculation logic included in the smart contract to perform an approximate calculation based on the data samples randomly sampled from the data set, so as to obtain an approximate calculation result for the data set.

[0006] This specification also proposes a calculation device based on smart contracts, which is applied to a node device in a blockchain. A smart contract for performing approximate calculation is deployed on the blockchain. The device includes:

[0007] A receiving module, configured to receive a smart contract call transaction initiated by a calculation initiator for the smart contract; wherein, the smart contract call transaction includes calculation parameters corresponding to the approximate calculation; the calculation parameters include data identifiers of a data set participating in the approximate calculation;

[0008] The computing module, in response to the smart contract call transaction, invokes the sampling logic included in the smart contract to randomly sample data samples in the data set corresponding to the data identifier, and further invokes the approximate computing logic included in the smart contract to perform approximate computing based on the data samples randomly sampled from the data set, so as to obtain an approximate computing result for the data set.

[0009] In the above technical solution, in the scenario of invoking a smart contract to perform approximate computing on a data set, by introducing a random sampling mechanism for the data set in the smart contract, it is possible to reduce the time consumption when performing approximate computing on the data set without sacrificing the accuracy of the approximate computing result, and improve the computing efficiency when performing approximate computing on the data set. Brief Description of the Drawings

[0010] Figure 1 is a flowchart of a computing method based on a smart contract provided by an exemplary embodiment;

[0011] Figure 2 is a schematic structural diagram of an electronic device provided by an exemplary embodiment;

[0012] Figure 3 is a block diagram of a computing device based on a smart contract provided by an exemplary embodiment. Detailed Description of the Embodiment

[0013] Here, the exemplary embodiments will be described in detail, and the examples are shown in the drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with one or more embodiments of this specification. On the contrary, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.

[0014] It should be noted that: in other embodiments, the steps of the corresponding methods are not necessarily executed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may also be combined into a single step for description in other embodiments.

[0015] With the continuous development of smart contract technology, when using smart contracts to interface with a business, smart contracts are gradually starting to undertake a part of the computing power related to the business.

[0016] For example, in practical applications, in the smart contract deployed on the blockchain for docking with the business, in addition to including the business logic related to the business, it can also include the logic for calculating the business data related to the business, so that users can complete the calculations related to the business on the blockchain by calling the smart contract.

[0017] When using a smart contract to calculate a data set related to a business, the total calculation time usually depends on the time taken for I / O operations for each piece of data separately and the time taken for batch calculations on the above set of data.

[0018] For example, in practical applications, taking the case where the data set related to the business is pre-archived on the blockchain as an example, the total time taken for the smart contract to calculate the data set related to the business can usually be expressed by the following formula:

[0019]

[0020] Among them, in the above formula, i represents the i-th piece of data in the above data set; IO i represents the time taken for I / O operation processing for the i-th piece of data; Operation i represents the time taken for batch calculations on i pieces of data in the data set.

[0021] It should be noted that since the data set is usually stored in the storage medium carried by the blockchain node device in the form of key-Value key-value pairs one by one when archived on the blockchain, for the above data set stored on the blockchain, usually only according to the key value of the data, the data can be read one by one from the storage medium carried by the blockchain node device.

[0022] In some application scenarios with high requirements for the privacy and security of data calculations, the above smart contract can also be deployed in the TEE (Trusted Execution Environment) carried by the blockchain node device.

[0023] In this case, the data in the above data set usually needs to be encrypted and stored. At this time, when using a smart contract to calculate a data set related to a business, the total calculation time usually depends on the time taken for I / O operations for each piece of data separately, the time taken for decryption for each piece of data separately, and the time taken for batch calculations on the above set of data.

[0024] For example, in practical applications, taking the example where a data set related to a business is pre-archived on a blockchain, the total time consumed when a smart contract calculates the data set related to the business can usually be expressed by the following formula:

[0025]

[0026] Among them, in the above formula, Operation i represents the time consumed for decrypting the i-th piece of data in the data set.

[0027] It is not difficult to see from the above introduction that in the scenario of using a smart contract to calculate a data set related to a business, if the amount of data contained in the data set is relatively large, it is very time-consuming to calculate the data set accurately through the smart contract.

[0028] In practical applications, in some business scenarios, it may not be necessary to obtain the exact calculation result of the data related to the business, but some loss in calculation accuracy can be tolerated.

[0029] For example, in the calculation scenario of calculating the average age of users, in most cases, an exact calculation result is not required, and usually only an approximate calculation to obtain an interval of the average age is needed.

[0030] Based on this, this specification proposes a technical solution that introduces an approximate calculation and random sampling mechanism in a smart contract to improve the calculation efficiency of calculating data related to a business.

[0031] When implemented, a smart contract for data calculation can be deployed on the blockchain. The smart contract can include an approximate calculation logic for approximate calculation and a sampling logic for random sampling. The calculation initiator can call the smart contract to perform an approximate calculation on the data set participating in the calculation by initiating a smart contract call transaction. Among them, the smart contract call transaction can include calculation parameters corresponding to the approximate calculation; the calculation parameters can include the data identifier of the data set participating in the approximate calculation;

[0032] When a node device in the blockchain receives the smart contract call transaction initiated by the calculation initiator, it can, in response to the smart contract call transaction, call the sampling logic included in the smart contract call transaction to randomly sample the data samples in the data set corresponding to the above data identifier. After the random sampling is completed, it can further call the approximate calculation logic included in the smart contract to perform an approximate calculation based on the data samples randomly sampled from the above data set to obtain an approximate calculation result for the data set.

[0033] In the above technical solution, in the scenario of invoking a smart contract to perform approximate calculations on a data set, by introducing a random sampling mechanism for the data set in the smart contract, it is possible to reduce the time consumed for performing approximate calculations on the data set and improve the calculation efficiency when performing approximate calculations on the data set without sacrificing the accuracy of the approximate calculation results.

[0034] Please refer to Figure 1 , Figure 1 which is a flowchart of a calculation method based on a smart contract provided by an exemplary embodiment. The method is applied to a node device in a blockchain; wherein, a smart contract for performing approximate calculations is deployed on the blockchain, and the method includes the following steps:

[0035] Step 102, receiving a smart contract call transaction for the smart contract initiated by a calculation initiator; wherein, the smart contract call transaction includes calculation parameters corresponding to the approximate calculation; the calculation parameters include data identifiers of a data set participating in the approximate calculation;

[0036] The above calculation initiator may specifically be a party with data calculation requirements. For example, in one example, the above calculation initiator may be a user with data calculation requirements. In another example, in the scenario of docking with a business based on a smart contract, the calculation initiator may specifically also be an off-chain business system with data calculation requirements.

[0037] On the blockchain, a smart contract for performing data calculations may be deployed. The execution logic corresponding to the contract code included in the smart contract may specifically include an approximate calculation logic for performing approximate calculations and a sampling logic for performing data sampling. In this way, the logic of approximate calculation and data sampling for data can be introduced into the smart contract.

[0038] It should be noted that the sampling method used for the above data sampling is not particularly limited in this specification; for example, random sampling (Random Sampling), stratified sampling (Stratified Sampling), etc. may be used.

[0039] In the following embodiments, the above data sampling is taken as random sampling, and the above sampling logic is taken as an example of a random sampling logic for description.

[0040] The above calculation initiator may call the above smart contract to perform approximate calculations on the data set participating in the calculation by initiating a smart contract call transaction.

[0041] For example, taking the above-mentioned calculation initiator as a user and the above-mentioned blockchain as a blockchain adopting an account model as an example, in this case, the above-mentioned smart contract can be understood as a contract account on the blockchain that anchors contract code, and the user can register an external account on the blockchain and initiate a smart contract call transaction through the external account, and submit the smart contract call transaction to the connected blockchain node device to call the smart contract.

[0042] It should be noted that in the above-mentioned smart contract call transaction, it may specifically include calculation parameters corresponding to approximate calculation; the calculation parameters may include data identifiers of data sets participating in approximate calculation.

[0043] When the above-mentioned calculation initiator initiates the above-mentioned smart contract call transaction, if the calculation initiator directly docks with the blockchain node, it can package a smart contract transaction and directly submit it point-to-point to the connected blockchain node device. If the calculation initiator accesses the blockchain through a blockchain access service provided by, for example, a Baas (Blockchain as a Service) platform, it can generate a call request for the above-mentioned smart contract and submit the call request to the Baas platform, and then the Baas platform packages a smart contract call transaction based on the call parameters carried in the call request and submits it to the blockchain node device.

[0044] The blockchain node device can receive the above-mentioned smart contract call transaction initiated by the above-mentioned calculation initiator, and when receiving the above-mentioned smart contract call transaction, it can respond to the smart contract call transaction, call the above-mentioned smart contract on the blockchain, and perform approximate calculation on the above-mentioned data set.

[0045] Step 104, in response to the smart contract call transaction, call the sampling logic included in the smart contract to randomly sample data samples in the data set corresponding to the data identifier;

[0046] After the blockchain node device receives the above-mentioned smart contract call transaction initiated by the above-mentioned calculation initiator, it can respond to the smart contract call transaction, call the sampling logic included in the smart contract, and randomly sample data samples in the data set corresponding to the data identifier.

[0047] It should be noted that after the blockchain node device receives the smart contract call transaction initiated by the above-mentioned calculation initiator, it usually needs to, together with other blockchain nodes participating in consensus, perform consensus processing on the smart contract call transaction and the execution result of the smart contract call transaction based on the consensus algorithm supported by the blockchain. Since this specification does not involve improving the consensus process of the blockchain, the process of performing consensus processing on the smart contract call transaction and the execution result of the smart contract call transaction will not be elaborated in this specification.

[0048] In an illustrated embodiment, before the blockchain node device invokes the sampling logic included in the smart contract to randomly sample the data samples in the data set corresponding to the data identifier, it may first obtain the data identifier included in the above smart contract call transaction and read the data set participating in the approximate calculation based on this data identifier.

[0049] When reading the data set participating in the approximate calculation based on this data identifier, it may specifically be read from the blockchain or read from off-chain, which is not particularly limited in this specification.

[0050] In one implementation, this data set may specifically be pre-archived on the above-mentioned blockchain.

[0051] For example, a deposit contract for data archiving may also be deployed on the blockchain. Before the calculation initiator invokes the above smart contract for calculation, it may publish the data set that needs to participate in the calculation to this deposit contract for archiving by packaging a deposit transaction.

[0052] Another example is that the execution logic corresponding to the contract code included in the above smart contract may include, in addition to the above approximate calculation logic and the above sampling logic, data archiving logic. That is, in addition to being used for approximate calculation, the smart contract itself also has a data archiving function for data. In this case, before the calculation initiator invokes this smart contract for calculation, it may also first publish the data set that needs to participate in the calculation to this smart contract for archiving by packaging a deposit transaction. Subsequently, this smart contract may read the archived data set from its own contract storage space for approximate calculation.

[0053] In this case, the blockchain node device may obtain the data set archived on the blockchain corresponding to this data identifier based on the above data identifier. For example, in this case, this data identifier may specifically be the deposit hash returned by the blockchain node after the data set is successfully archived on the blockchain.

[0054] In another implementation, the data set can also be specifically pre-certified in an off-chain database connected to the above blockchain. In this case, the smart contract can obtain the data set corresponding to the data identifier from the above off-chain database through its corresponding oracle machine.

[0055] Among them, the above oracle machine can specifically be a centralized oracle machine or a decentralized oracle machine. When the above oracle machine is a centralized oracle machine, the oracle machine can be an oracle service program deployed on an off-chain service device at this time. When the above oracle machine is a decentralized oracle machine, the oracle machine can be an oracle contract deployed on the blockchain and connected to the above smart contract at this time. It should be noted that since this specification does not involve improvements related to the oracle machine, the specific implementation process of the above smart contract obtaining the data set corresponding to the data identifier from the above off-chain database through its corresponding oracle machine will not be elaborated in this specification.

[0056] For the calculation parameters included in the above smart contract call transaction, in addition to the data identifier of the above data set mentioned above, in practical applications, other forms of parameters related to approximate calculation can also be included.

[0057] In an illustrated implementation, the above calculation parameters can specifically include various parameters shown in the following table:

[0058]

[0059]

[0060] Among them, it should be noted that except for the data set ID in the above table, other parameters are all optional parameters. For example, if the calculation parameters in the above smart contract call transaction do not include the calculation type ID, it means that the above smart contract is allowed to perform approximate calculation on the above data set using the default calculation type. If the calculation parameters in the above smart contract call transaction do not include the error value, it means that the tolerable calculation error is 0. If the calculation parameters in the above smart contract call transaction do not include the confidence probability, it means that the confidence probability is 100%, and the expected accuracy of the approximate calculation is 100%. In this case, the above smart contract will perform an exact calculation on the above data set and will no longer perform an approximate calculation.

[0061] In an illustrated embodiment, when the blockchain node device invokes the sampling logic included in the above smart contract to perform random sampling on the data set obtained corresponding to the above data identifier, it can specifically first calculate the sampling quantity for random sampling, and then perform random sampling according to the calculated sampling quantity.

[0062] In an illustrated embodiment, Hoeffding's Inequality is generally used to describe the upper bound of the probability of the deviation of the sum of random variables from its expected value. In the scenario of approximate calculation, the above sampling quantity can be regarded as a random variable, the error value of the above approximate calculation can be regarded as the deviation of the expected value, and the confidence probability of the above approximate calculation can be regarded as the above probability upper bound. Therefore, in this specification, Hoeffding's Inequality can be used to describe the mathematical relationship among the above sampling quantity, the error value of the above approximate calculation, and the confidence probability of the above approximate calculation. In other words, in the scenario of approximate calculation, Hoeffding's Inequality can be used to derive the mathematical relationship among the above sampling quantity, the error value of the above approximate calculation, and the confidence probability of the above approximate calculation.

[0063] Among them, when using Hoeffding's Inequality to describe the mathematical relationship among the above sampling quantity, the error value of the above approximate calculation, and the confidence probability of the above approximate calculation, Hoeffding's Inequality is expressed as the following formula:

[0064]

[0065] In the above formula, H represents the mathematical identifier of Hoeffding's Inequality. n g represents the sampling quantity. b g and a g respectively represent the maximum value and the minimum value of the data samples in the data set. δ represents the confidence probability; ε g represents the error value corresponding to the above approximate calculation; N g represents the total number of data samples in the data set.

[0066] And the mathematical relationship among the above sampling quantity, the error value of the above approximate calculation, and the confidence probability of the above approximate calculation derived based on the above formula can be expressed by the following formula:

[0067]

[0068] And in the above smart contract, the above mathematical relationship can be maintained in advance. When the blockchain node device invokes the above smart contract to calculate the sampling quantity required for random sampling, it can obtain the confidence probability δ corresponding to the approximate calculation and the error value ε corresponding to the approximate calculation in the calculation parameters of the above smart contract call transaction. g, and then input the obtained confidence probability δ and error value ε g into the above-mentioned maintained mathematical relationship for calculation to obtain the sampling quantity corresponding to the above data set.

[0069] Of course, in addition to automatically calculating the sampling quantity according to the above data relationship, in practical applications, the above sampling quantity can also be specified by the calculation initiator. For example, the sampling quantity specified by the calculation initiator can be carried as a calculation parameter in the above smart contract call transaction.

[0070] In an illustrated implementation manner, when the blockchain node device calls the above smart contract and randomly samples the above data set based on the calculated sampling quantity, specifically, it can first obtain a random number for random sampling, and then randomly sample the data samples in the data set based on the obtained random number to obtain data samples corresponding to the calculated above sampling quantity.

[0071] Among them, the above random number is specifically used to control the randomness of the data samples sampled from the above data set. In practical applications, the data samples to be sampled from the above data set can be determined according to the obtained random number. For example, in an example, the random number can be used to represent the sample identifier of the data sample to be sampled. During the random sampling process, the data sample with the value of the random number as the sample identifier can be randomly selected from the data set to complete the data sampling.

[0072] It should be noted that regarding the specific acquisition method of the above random number, it can be generated on the blockchain or obtained from off-chain, and it is not particularly limited in this specification.

[0073] The following are several specific ways shown in this specification for obtaining random numbers:

[0074] In an illustrated way, a random function for generating random numbers can be pre-deployed on the blockchain. For example, in practical applications, the above random function can specifically be deployed on the blockchain as an independent smart contract, or deployed as the execution logic included in the above smart contract for approximate calculation in this smart contract. In this case, a random tree can be generated on the blockchain by calling the above random function;

[0075] In another illustrated way, a Trusted Execution Environment can be installed on the above blockchain node device. In this trusted execution environment, a random number seed for generating random numbers can be pre-maintained. In this case, random numbers can be generated based on this random seed in this trusted execution environment.

[0076] In the third way shown, it is also possible to obtain a target data parameter that can be used as a random number seed from the data-related data parameters maintained by the above-mentioned smart contract for approximate calculation, and then a random number can be generated in the above-mentioned smart contract based on the obtained target data parameter. For example, it is also possible to use parameters with uniqueness such as the hash value of the historical block and the generation timestamp of the historical block maintained by the above-mentioned smart contract as the random number seed to calculate the random number in the smart contract.

[0077] In the fourth way shown, the above-mentioned random number can be generated off-chain. In this case, the above-mentioned smart contract can also obtain the random number generated off-chain through the oracle program corresponding to the smart contract.

[0078] In the fifth way shown, a random number seed for further generating the above-mentioned random number can be generated off-chain. In this case, the above-mentioned smart contract can also obtain the random number seed generated off-chain through the oracle program corresponding to the smart contract, and then generate a random number in the smart contract based on the obtained random number seed.

[0079] In the sixth way shown, the above-mentioned random number seed generated off-chain can specifically be carried as a calculation parameter in the above-mentioned smart contract call transaction. In this case, the random number seed generated off-chain included in the smart contract call transaction can be obtained, and then a random number can be generated in the smart contract based on the obtained random number seed.

[0080] The above lists several common implementation ways for obtaining random numbers. It should be emphasized that in practical applications, obviously, ways other than the implementation ways listed above can also be used to obtain random numbers, which will not be listed one by one in this specification.

[0081] Step 106: Further call the approximate calculation logic included in the smart contract, and perform approximate calculation based on the data samples randomly sampled from the data set to obtain an approximate calculation result for the data set.

[0082] In this specification, when performing approximate calculation on the sampled data samples, the approximate calculation can be performed using the calculation type specified by the calculation initiator, or the default calculation type supported by the above-mentioned smart contract. This is not particularly limited in this specification.

[0083] For example, in one of the illustrated embodiments, in the above smart contract call transaction, a sampling algorithm ID may also be included. The sampling algorithm ID may be used to indicate the type of calculation for approximate calculation specified by the calculation initiator for the above data set. In this case, when performing approximate calculation on the sampled data samples, the sampling algorithm ID included in the smart contract call transaction may be obtained, and then the approximate calculation may be performed on the collected data samples according to the type of calculation indicated by the sampling algorithm ID.

[0084] Of course, if the above smart contract call transaction does not include the above sampling algorithm ID, that is, the calculation initiator does not specify the type of calculation for approximate calculation for the above data set, in this case, the approximate calculation may be performed on the sampled sample data based on the default calculation type supported by the above smart contract.

[0085] It should be noted that the type of calculation corresponding to the above approximate calculation is not particularly limited in this specification. For example, it may include summation, average calculation, etc., which will not be listed one by one in this specification.

[0086] In one of the illustrated embodiments, the above smart contract for performing approximate calculation may specifically be a privacy smart contract deployed in a trusted execution environment carried by a blockchain node device. In this scenario, the calculation parameters in the above smart contract call transaction and the data samples in the obtained above data set are usually pre-encrypted.

[0087] In this case, before the blockchain node device calls the sampling logic included in the above smart contract to randomly sample the obtained data set corresponding to the above data identifier, the above calculation parameters and the data samples in the obtained above data set may also be decrypted respectively in the trusted execution environment, and after decryption, the data samples in the above data set may be randomly sampled according to the random sampling method described above, and the specific process will not be elaborated.

[0088] For example, in an example, a pair of asymmetric key pairs for encrypting and decrypting data may be assigned to the above trusted execution environment, the private key of the above asymmetric key may be stored in the above trusted execution environment, and the public key of the above asymmetric key may be published to the above calculation initiator. The calculation parameters in the above smart contract call transaction and the data samples in the obtained above data set may both be pre-encrypted based on the above public key. Before the blockchain node device calls the sampling logic included in the above smart contract to randomly sample the obtained data set corresponding to the above data identifier, the above calculation parameters and the data samples in the obtained above data set may also be decrypted respectively in the trusted execution environment using the maintained private key.

[0089] In the above technical solution, in the scenario of invoking a smart contract to perform approximate calculations on a data set, by introducing a random sampling mechanism for the data set into the smart contract, it is possible to reduce the time consumption when performing approximate calculations on the data set and improve the calculation efficiency when performing approximate calculations on the data set, without sacrificing the accuracy of the approximate calculation results.

[0090] For example, still taking the case where a data set related to the business is pre-archived on the blockchain as an example, after introducing a random sampling mechanism into the smart contract, the total time consumption when the smart contract calculates the data set related to the business can usually be expressed by the following formula:

[0091]

[0092] Among them, in the above formula, n g represents the number of data samples randomly sampled from the data set. N g represents the total number of data samples in the data set. Since the value of n g is usually of an order of magnitude difference compared to the value of N g , after introducing a random sampling mechanism into the smart contract, the time consumption when calculating the data set through this smart contract will also be reduced by an order of magnitude.

[0093] It can be seen that introducing a random sampling mechanism into the smart contract can significantly shorten the time consumption when calculating the data set and improve the calculation efficiency when performing approximate calculations on the data set.

[0094] Corresponding to the above method embodiment, the present application also provides an embodiment of a device.

[0095] The embodiment of the device in this specification can be applied to an electronic device. The embodiment of the device can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a logically meaningful device, it is formed by the processor of the electronic device where it is located reading the corresponding computer program instructions in the non-volatile memory into the memory and running.

[0096] From the hardware level, as Figure 2 shown, it is a hardware structure diagram of the electronic device where the device in this specification is located. In addition to Figure 2 the shown processor, memory, network interface, and non-volatile memory, the electronic device where the device is located in the embodiment usually may also include other hardware according to the actual functions of the electronic device, which will not be elaborated here.

[0097] Figure 3It is a block diagram of a computing device based on a smart contract shown in an exemplary embodiment of this specification.

[0098] Please refer to Figure 3 The computing device 30 based on the smart contract can be applied to the aforementioned Figure 2 shown electronic device. A smart contract for performing approximate computing is deployed on the blockchain. The device 30 includes:

[0099] A receiving module 301 that receives a smart contract call transaction initiated by a computing initiator for the smart contract; wherein, the smart contract call transaction includes calculation parameters corresponding to the approximate computing; the calculation parameters include data identifiers of a data set participating in the approximate computing.

[0100] A calculation module 302 that, in response to the smart contract call transaction, calls the sampling logic included in the smart contract to randomly sample data samples in the data set corresponding to the data identifier, and further calls the approximate computing logic included in the smart contract to perform approximate computing based on the data samples randomly sampled from the data set to obtain an approximate computing result for the data set.

[0101] In this embodiment, the device 30 may further include:

[0102] An obtaining module 303 ( Figure 3 not shown in the figure) that, before the calculation module 302 randomly samples data samples in the data set corresponding to the data identifier, obtains the data set corresponding to the data identifier stored on the blockchain; or

[0103] Obtains the data set corresponding to the data identifier from an off-chain database docked with the blockchain through an oracle program corresponding to the smart contract.

[0104] In this embodiment, the calculation parameters include a confidence probability corresponding to the approximate computing; and an error value corresponding to the approximate computing; wherein, the confidence probability characterizes the accuracy of the approximate computing; the smart contract maintains a mathematical relationship among the confidence probability corresponding to the approximate computing, the error value corresponding to the approximate computing, and the sampling quantity corresponding to the data set participating in the approximate computing, which is derived based on the Hoeffding inequality.

[0105] The calculation module 302:

[0106] Inputs the confidence probability corresponding to the approximate computing and the error value corresponding to the approximate computing into the mathematical relationship for calculation to obtain the sampling quantity corresponding to the data set.

[0107] Based on the calculated number of samples, randomly sample the data samples in the data set corresponding to the data identifier.

[0108] In this embodiment, the mathematical relationship is represented by the following formula:

[0109]

[0110] Among them, in the above formula, n g represents the number of samples; b g , a g respectively represent the maximum and minimum values of the data samples in the data set; δ represents the confidence probability; ε b represents the error value; N g represents the total number of data samples in the data set.

[0111] In this embodiment, the calculation module 302 further:

[0112] Obtain a random number for random sampling;

[0113] Based on the random number, randomly sample the data samples in the data set to obtain data samples corresponding to the calculated number of samples.

[0114] In this embodiment, the calculation module 302 further executes any one of the following shown:

[0115] Call the random function deployed on the blockchain to generate a random tree for random sampling;

[0116] Based on the random number seed maintained in the trusted execution environment carried by the node device, generate a random number in the trusted execution environment;

[0117] From the data-related data parameters maintained by the smart contract, obtain the target data parameter as the random number seed, and generate a random number for random sampling in the smart contract based on the obtained target data parameter;

[0118] Obtain a random number for random sampling generated outside the chain through the oracle program corresponding to the smart contract;

[0119] Obtain a random number seed for generating a random number generated outside the chain through the oracle program corresponding to the smart contract, and generate a random number for random sampling in the smart contract based on the obtained target data parameter; obtain the random number seed generated outside the chain included in the calculation parameter, and generate a random number for random sampling in the smart contract based on the random number seed.

[0120] In this embodiment, the calculation parameter further includes an algorithm identifier indicating the calculation type corresponding to the approximate calculation;

[0121] The calculation module further:

[0122] Based on the data samples randomly sampled from the data set, perform approximate calculation according to the calculation type indicated by the algorithm identifier.

[0123] In this embodiment, the smart contract is deployed in the trusted execution environment carried by the node device; the calculation parameters and the data samples in the data set have been encrypted in advance;

[0124] The calculation module 302 further:

[0125] Before randomly sampling the data samples in the data set corresponding to the data identifier, decrypt the calculation parameters and the obtained data samples in the data set respectively in the trusted execution environment.

[0126] The system, device, module or unit illustrated in the above embodiments can be specifically implemented by a computer chip or an entity, or by a product with certain functions. A typical implementation device is a computer, and the specific form of the computer can be a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver device, a game console, a tablet computer, a wearable device, or any combination of several of these devices.

[0127] In a typical configuration, a computer includes one or more processors (CPUs), an input / output interface, a network interface, and a memory.

[0128] The memory may include non-permanent memory in the computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of, for example, read-only memory (ROM) or flash memory (flash RAM). The memory is an example of a computer-readable medium.

[0129] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0130] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0131] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0132] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0133] It should be understood that although the terms first, second, third, etc. may be used in one or more embodiments of this specification to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from each other. For example, without departing from the scope of one or more embodiments of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "when" or "while" or "in response to determining".

[0134] The above are only the preferred embodiments of one or more embodiments of this specification, and are not intended to limit one or more embodiments of this specification. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of one or more embodiments of this specification shall be included within the scope protected by one or more embodiments of this specification.

Claims

1. A computing method based on smart contracts, applied to node devices in a blockchain, where a smart contract for performing approximate computing is deployed on the blockchain. The method includes: Receive a smart contract call transaction initiated by a computing initiator for the smart contract; wherein, the smart contract call transaction includes calculation parameters corresponding to the approximate calculation; the calculation parameters include data identifiers of a data set participating in the approximate calculation, a confidence probability corresponding to the approximate calculation, and an error value corresponding to the approximate calculation; the confidence probability characterizes the accuracy of the approximate calculation; the smart contract maintains a mathematical relationship derived based on the Hoeffding inequality, which describes the relationship among the confidence probability corresponding to the approximate calculation, the error value corresponding to the approximate calculation, and the sampling quantity corresponding to the data set participating in the approximate calculation. In response to the smart contract call transaction, call the sampling logic included in the smart contract, input the confidence probability corresponding to the approximate calculation and the error value corresponding to the approximate calculation into the mathematical relationship for calculation, obtain the sampling quantity corresponding to the data set, and based on the calculated sampling quantity, randomly sample data samples in the data set corresponding to the data identifier, and further call the approximate calculation logic included in the smart contract to perform approximate calculation based on the data samples randomly sampled from the data set, so as to obtain an approximate calculation result for the data set.

2. The method according to claim 1, before randomly sampling data samples in the data set corresponding to the data identifier, further including: Obtain the data set corresponding to the data identifier stored on the blockchain. Or, Through an oracle program corresponding to the smart contract, obtain the data set corresponding to the data identifier from an off-chain database docked with the blockchain.

3. The method according to claim 1, the mathematical relationship is represented by the following formula: Wherein, In the above formula, n g represents the number of samplings; b g , a g respectively represent the maximum value and the minimum value of the data samples in the data set; δ represents the confidence probability; ε g represents the error value; N g represents the total number of data samples in the data set.

4. The method according to claim 1, based on the calculated sampling quantity, randomly sampling data samples in the data set corresponding to the data identifier, including: Obtain a random number for random sampling. Based on the random number, randomly sample data samples in the data set to obtain data samples corresponding to the calculated sampling quantity.

5. The method according to claim 4, obtaining a random number for performing random sampling includes any of the following: Invoking a random function deployed on the blockchain to generate a random tree for performing random sampling; Generate a random number in the trusted execution environment based on the random number seed maintained in the trusted execution environment carried by the node device. Obtain a target data parameter serving as the random number seed from the data parameters related to the data maintained by the smart contract, and generate a random number for random sampling in the smart contract based on the obtained target data parameter. Through an oracle program corresponding to the smart contract, obtain a random number for random sampling generated off-chain. Through an oracle program corresponding to the smart contract, obtain a random number seed for generating a random number generated off-chain, and generate a random number for random sampling in the smart contract based on the obtained target data parameter. Obtain the random number seed generated off-chain included in the calculation parameters, and generate a random number for random sampling in the smart contract based on the random number seed.

6. The method according to claim 1, the calculation parameter further includes an algorithm identifier indicating the calculation type corresponding to the approximate calculation; Based on the data samples randomly sampled from the data set, performing approximate computing includes: Based on the data samples randomly sampled from the data set, perform approximate calculation according to the calculation type indicated by the algorithm identifier.

7. The method according to claim 1, the smart contract is deployed in a trusted execution environment carried by the node device; the calculation parameter and the data samples in the data set have been pre-encrypted; Before randomly sampling data samples in the data set corresponding to the data identifier, further including: Decrypt the calculation parameters and the data samples in the obtained data set respectively in the trusted execution environment.

8. A computing device based on a smart contract, applied to a node device in a blockchain, where a smart contract for performing approximate computing is deployed on the blockchain, and the device includes: A receiving module that receives a smart contract call transaction initiated by a computing initiator for the smart contract; wherein the smart contract call transaction includes calculation parameters corresponding to the approximate calculation; the calculation parameters include data identifiers of a data set participating in the approximate calculation, a confidence probability corresponding to the approximate calculation, and an error value corresponding to the approximate calculation; the confidence probability represents the accuracy of the approximate calculation; the smart contract maintains a mathematical relationship derived based on the Hoeffding inequality, which describes the relationship among the confidence probability corresponding to the approximate calculation, the error value corresponding to the approximate calculation, and the sampling quantity corresponding to the data set participating in the approximate calculation. A calculation module that, in response to the smart contract call transaction, calls the sampling logic included in the smart contract, inputs the confidence probability corresponding to the approximate calculation and the error value corresponding to the approximate calculation into the mathematical relationship for calculation, obtains the sampling quantity corresponding to the data set, randomly samples data samples in the data set corresponding to the data identifier based on the calculated sampling quantity, and further calls the approximate calculation logic included in the smart contract to perform an approximate calculation based on the data samples randomly sampled from the data set, so as to obtain an approximate calculation result for the data set.

9. An electronic device, including: A processor; A memory for storing processor-executable instructions; Wherein, the processor realizes the steps of the method according to any one of claims 1-7 by running the executable instructions.

10. A computer-readable storage medium, on which computer instructions are stored, and when the instructions are executed by a processor, the steps of the method described in any one of claims 1-7 are implemented.

Citation Information

Patent Citations

  • Block chain technology-based shipping index calculation method

    CN108734524A

  • Product sampling detection method and device based on block chain, and medium

    CN111008849A