Calculation, update, and reading methods and devices based on smart contracts, and electronic equipment

By introducing approximate computing and data sampling mechanisms into blockchain smart contracts, the problem of time-consuming calculation of big data sets on blockchain is solved, and efficient approximate computing results are achieved, ensuring computing efficiency and accuracy.

CN114693450BActive Publication Date: 2025-09-02ANT BLOCKCHAIN TECHNOLOGY (SHANGHAI) CO LTD

Patent Information

Application Number
CN202210332050.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-30
Publication Date
2025-09-02
Estimated Expiration
2042-03-30

AI Technical Summary

Technical Problem

When performing data calculation on blockchain, especially for the calculation of big data sets, the prior art takes a long time, and when approximate calculation results are required, it is impossible to effectively improve the computing efficiency and ensure accuracy.

Method used

Approximate calculation and data sampling mechanism are introduced in smart contracts on the blockchain. By dividing the data set into outlier data subsets and non-outlier data subsets, sampling and approximate calculations are performed on the non-outlier data subsets, and the merge results are used as the approximate calculation results of the data set.

Benefits of technology

Without sacrificing the accuracy of the approximate calculation results, the calculation time is significantly reduced, the calculation efficiency is improved, and the impact of outliers on the results is avoided.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114693450B_ABST
    Figure CN114693450B_ABST
Patent Text Reader

Abstract

A computing method based on a smart contract, wherein a smart contract for performing approximate computing is deployed on a blockchain, comprising: receiving a smart contract call transaction initiated by a computing initiator for the smart contract; the smart contract call transaction includes computing parameters corresponding to the approximate computing; the computing parameters include a data identifier of a data set participating in the approximate computing; in response to the smart contract call transaction, calling sampling logic contained in the smart contract call transaction, dividing the data set corresponding to the data identifier into an outlier data subset consisting of a plurality of outlier data samples and a non-outlier data subset consisting of a plurality of non-outlier data samples, and sampling non-outlier data samples in the non-outlier data subset; calling the computing logic contained in the smart contract call transaction, performing precise computing on the outlier data samples in the outlier data subset, performing approximate computing on the sampled non-outlier data samples, and merging the results of the precise computing and the approximate computing.
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 computing device and electronic device based on smart contracts. Background Art

[0002] Blockchain is a novel application model for computer technologies, including distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. In a blockchain system, data blocks are linked sequentially in chronological order to form a chain-like data structure, cryptographically guaranteeing an unalterable and unforgeable distributed ledger. Due to its decentralized, tamper-proof, and autonomous nature, blockchain is gaining increasing attention and application. Summary of the Invention

[0003] This specification proposes a smart contract-based computing method, applied to node devices in a blockchain, where a smart contract for performing approximate computing is deployed on the blockchain. The method includes:

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

[0005] In response to the smart contract call transaction, invoking sampling logic included in the smart contract call transaction, dividing the data set corresponding to the data identifier into an outlier data subset consisting of a plurality of outlier data samples and a non-outlier data subset consisting of a plurality of non-outlier data samples, and sampling the non-outlier data samples in the non-outlier data subset;

[0006] The computing logic included in the smart contract call transaction is further called to perform precise calculations on the outlier data samples in the outlier data subset, perform approximate calculations on the non-outlier data samples sampled from the non-outlier data subset, and combine the results of the precise calculations and the approximate calculations to serve as the approximate calculation result for the data set.

[0007] This specification also proposes a smart contract-based computing device, which is applied to a node device in a blockchain, where a smart contract for performing approximate computing is deployed on the blockchain. The device includes:

[0008] a receiving module configured to receive a smart contract call transaction initiated by a computation initiator for the smart contract; wherein the smart contract call transaction includes computation parameters corresponding to the approximate computation; and the computation parameters include data identifiers of data sets participating in the approximate computation;

[0009] a sampling module, in response to the smart contract call transaction, calling sampling logic included in the smart contract call transaction, dividing the data set corresponding to the data identifier into an outlier data subset consisting of a plurality of outlier data samples and a non-outlier data subset consisting of a plurality of non-outlier data samples, and sampling the non-outlier data samples in the non-outlier data subset;

[0010] The computing module further calls the computing logic included in the smart contract call transaction, performs precise computing on the outlier data samples in the outlier data subset, performs approximate computing on the non-outlier data samples sampled from the non-outlier data subset, and combines the results of the precise computing and the approximate computing to serve as the approximate computing result for the data set.

[0011] In the above technical solution, in the scenario where a smart contract is called to perform approximate calculations on a data set, by introducing a sampling mechanism for the data set into the smart contract, the time consumed in performing approximate calculations on the data set can be reduced without sacrificing the accuracy of the approximate calculation results, thereby improving the computational efficiency of the approximate calculations on the data set. Furthermore, since, during the approximate calculation of the data set, the outlier data in the data set is not sampled before performing the approximate calculation, but rather the precise calculation is performed directly without sampling, it is possible to further avoid the impact of these outlier data samples on the accuracy of the approximate calculation results for the data set when the data set includes outliers, thereby ensuring the accuracy of the approximate calculations on the data set to the greatest extent possible. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] Figure 1 is a flowchart of a smart contract-based calculation method provided by an exemplary embodiment;

[0013] Figure 2 is a flow chart of an optimization solution method provided by an exemplary embodiment;

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

[0015] Figure 4 It is a block diagram of a smart contract-based computing device provided by an exemplary embodiment. DETAILED DESCRIPTION

[0016] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. In the following description, when referring to the drawings, identical numerals in different figures represent identical or similar elements, unless otherwise indicated. The implementations described in the following exemplary embodiments are not intended to represent all implementations consistent with one or more embodiments of this specification. Rather, they are merely examples of apparatuses and methods consistent with certain aspects of one or more embodiments of this specification, as detailed in the appended claims.

[0017] It should be noted that in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the method may include more or fewer steps than those described in this specification. In addition, a single step described in this specification may be broken down into multiple steps for description in other embodiments, and multiple steps described in this specification may be combined into a single step for description in other embodiments.

[0018] With the continuous development of smart contract technology, when using smart contracts to connect with businesses, smart contracts have gradually begun to bear part of the computing power related to the business.

[0019] For example, in actual applications, the smart contract deployed on the blockchain for connecting with the business may include not only business logic related to the business, but also logic for calculating business data related to the business, so that users can complete calculations related to the business on the blockchain by calling the smart contract.

[0020] When using smart contracts to calculate a business-related data set, the total calculation time is usually determined by the time it takes to perform I / O operations on each piece of data separately and the time it takes to calculate the above set of data in batches.

[0021] For example, in actual applications, taking the case where a business-related data set is pre-stored on the blockchain, the total time consumed by the smart contract to calculate the business-related data set can usually be expressed using the following formula:

[0022]

[0023] Wherein, in the above formula, i represents the i-th data in the above data set; i Indicates the time taken to perform I / O operations on the i-th data; Operation i Indicates the time required to perform batch calculations on i pieces of data in a data set.

[0024] It should be noted that when data sets are stored on the blockchain, they are usually stored one by one in the form of key-value pairs in the storage medium equipped with the blockchain node device. Therefore, for the above data sets stored on the blockchain, data can usually only be read one by one from the storage medium equipped with the blockchain node device based on the key value of the data.

[0025] In some application scenarios that require high privacy and security of data calculations, the above-mentioned smart contracts can also be deployed in the TEE (Trusted execution environment) equipped with blockchain node devices.

[0026] In this case, the data in the aforementioned datasets typically needs to be stored encrypted. When using smart contracts to perform calculations on business-related datasets, the total computational time typically depends on the time required to perform I / O operations on each piece of data, the time required to decrypt each piece of data, and the time required to perform batch computations on the data.

[0027] For example, in actual applications, taking the case where a business-related data set is pre-stored on the blockchain, the total time consumed by the smart contract to calculate the business-related data set can usually be expressed using the following formula:

[0028]

[0029] Among them, in the above formula, Operation i Indicates the time it takes to decrypt the i-th piece of data in the data set.

[0030] From the above introduction, it is not difficult to see that in the scenario of using smart contracts to calculate business-related data sets, if the data set contains a large amount of data, it is very time-consuming to calculate the data set through smart contracts and obtain accurate calculation results.

[0031] In actual applications, in some business scenarios, precise calculation results for business-related data may not be required, but some loss of calculation accuracy can be tolerated.

[0032] For example, in the scenario of calculating the average age of users, accurate calculation results are not required in most cases. Usually, only an approximate calculation to obtain an average age range is sufficient.

[0033] Based on this, this specification proposes a technical solution that introduces a mechanism of approximate computing and data sampling into smart contracts to improve the computational efficiency of computing business-related data.

[0034] During implementation, a smart contract for data calculation can be deployed on the blockchain. The smart contract can include approximate calculation logic for approximate calculation and sampling logic for data sampling. The calculation initiator can call the smart contract to perform approximate calculation on the data set involved in the calculation by initiating a smart contract call transaction. 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 involved in the approximate calculation;

[0035] When the node device in the blockchain receives the smart contract call transaction initiated by the calculation initiator, it can respond to the smart contract call transaction, call the sampling logic contained in the smart contract call transaction, divide the data set corresponding to the data identifier into an outlier data subset consisting of several outlier data samples, and a non-outlier data subset consisting of several non-outlier data samples, and sample the non-outlier data samples in the non-outlier data subset; after the sampling is completed, the approximate calculation logic contained in the smart contract can be further called to perform precise calculation on the outlier data samples in the outlier data subset, perform approximate calculation on the non-outlier data samples sampled from the non-outlier data subset, and merge the results of the precise calculation and the approximate calculation as the approximate calculation result for the data set.

[0036] In the above technical solution, in the scenario where a smart contract is called to perform approximate calculations on a data set, by introducing a sampling mechanism for the data set in the smart contract, the time spent on approximate calculations on the data set can be reduced without sacrificing the accuracy of the approximate calculation results, and the computational efficiency of approximate calculations on the data set can be improved.

[0037] Moreover, since in the process of approximate calculation of the data set, the outlier data in the data set are not sampled and then approximate calculation is performed, but precise calculation is performed directly without sampling, it is possible to further avoid the influence of these outlier data samples on the accuracy of the approximate calculation results of the data set when the data set includes outlier data, and the accuracy of the approximate calculation of the data set can be ensured to the greatest extent.

[0038] See Figure 1 , Figure 1 This is a flowchart of a smart contract-based computing method provided by an exemplary embodiment. The method is applied to a node device in a blockchain; wherein a smart contract for performing approximate computing is deployed on the blockchain, and the method includes the following steps:

[0039] Step 102: Receive a smart contract call transaction initiated by a computation initiator for the smart contract; wherein the smart contract call transaction includes computation parameters corresponding to the approximate computation; the computation parameters include data identifiers of data sets participating in the approximate computation;

[0040] The aforementioned computation initiator may specifically be a party with data computation requirements. For example, in one example, the computation initiator may be a user with data computation requirements. In another example, in a scenario where smart contracts are integrated with businesses, the computation initiator may specifically be an off-chain business system with data computation requirements.

[0041] On the blockchain, a smart contract for data computation can be deployed. The execution logic corresponding to the contract code contained in the smart contract can specifically include approximate computation logic for approximate computation and sampling logic for data sampling. In this way, the logic for approximate computation and data sampling can be introduced into the smart contract.

[0042] 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, stratified sampling, etc. can be used.

[0043] The initiator of the above calculation can call the above smart contract to perform approximate calculations on the data set involved in the calculation by initiating a smart contract call transaction.

[0044] For example, taking the above-mentioned calculation initiator as a user and the above-mentioned blockchain as a blockchain adopting an account model, in this case, the above-mentioned smart contract can be understood as a contract account on the blockchain that is anchored with a 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.

[0045] It should be noted that, in the above-mentioned smart contract call transaction, calculation parameters corresponding to approximate calculations may be specifically included; the calculation parameters may include the data identifier of the data set participating in the approximate calculation.

[0046] When initiating a smart contract call transaction, if the computing initiator directly connects to a blockchain node, it can package a smart contract transaction and submit it point-to-point to the connected blockchain node device. If the computing initiator connects to the blockchain through a blockchain access service such as a Baas (Blockchain as a Service) platform, it can generate a call request for the smart contract and submit it to the Baas platform. The Baas platform then packages a smart contract call transaction based on the call parameters carried in the call request and submits it to the blockchain node device.

[0047] 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 calculations on the above-mentioned data set.

[0048] Step 104: In response to the smart contract call transaction, calling the sampling logic included in the smart contract call transaction, dividing the data set corresponding to the data identifier into an outlier data subset consisting of a plurality of outlier data samples and a non-outlier data subset consisting of a plurality of non-outlier data samples, and sampling the non-outlier data samples in the non-outlier data subset;

[0049] After receiving the above-mentioned smart contract call transaction initiated by the above-mentioned computing initiator, the blockchain node device can respond to the smart contract call transaction, call the sampling logic contained in the smart contract, and sample the data samples in the data set corresponding to the data identifier.

[0050] It should be noted that after receiving the smart contract invocation transaction initiated by the computation initiator, the blockchain node device typically needs to reach consensus on the smart contract invocation transaction and the execution result of the smart contract invocation transaction, based on the consensus algorithm supported by the blockchain, together with other blockchain nodes participating in the consensus. Since this specification does not involve improvements to the blockchain consensus process, the process of reaching consensus on the smart contract invocation transaction and the execution result of the smart contract invocation transaction will not be detailed in this specification.

[0051] In one embodiment shown, before calling the sampling logic contained in the smart contract and sampling the data sample in the data set corresponding to the data identifier, the blockchain node device can first obtain the above-mentioned data identifier contained in the above-mentioned smart contract call transaction, and read the data set participating in the approximate calculation based on the data identifier.

[0052] Among them, when reading the data set participating in the approximate calculation based on the data identifier, it can be read from the blockchain or from outside the chain, which is not specifically limited in this specification.

[0053] In one implementation, the data set can be pre-stored on the above-mentioned blockchain.

[0054] For example, a storage contract for data storage can be deployed on the blockchain. Before calling the above smart contract for calculation, the calculation initiator can publish the data set that needs to participate in the calculation to the storage contract for storage by packaging a storage transaction.

[0055] For example, the execution logic corresponding to the contract code contained in the aforementioned smart contract may include not only the aforementioned approximate calculation logic and sampling logic, but also data storage logic. In other words, in addition to being used for approximate calculations, the smart contract itself also has a built-in data storage function. In this case, before invoking the smart contract for calculation, the calculation initiator can also pre-publish the data set required for calculation to the smart contract for storage by packaging it with a storage transaction. The smart contract can then read the stored data set from its own contract storage space to perform approximate calculations.

[0056] In this case, the blockchain node device can obtain the data set corresponding to the data identifier stored on the blockchain based on the data identifier. For example, in this case, the data identifier can specifically be the hash returned by the blockchain node after the data set is successfully stored on the blockchain.

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

[0058] Specifically, the oracle program can be a centralized oracle program or a decentralized oracle program. When the oracle program is a centralized oracle program, it can be an oracle service program deployed on an off-chain service device. When the oracle program is a decentralized oracle program, it can be an oracle contract deployed on the blockchain that interfaces with the smart contract. It should be noted that since this specification does not involve improvements related to oracle programs, the specific implementation process of the smart contract obtaining the data set corresponding to the data identifier from the off-chain database through the corresponding oracle program will not be detailed in this specification.

[0059] The calculation parameters included in the above-mentioned smart contract call transaction may include, in addition to the data identifiers of the above-mentioned data sets, other forms of parameters related to approximate calculations may also be included in actual applications.

[0060] In one embodiment shown, the above calculation parameters may specifically include the various parameters shown in the following table:

[0061] Parameter Type Parameter meaning Dataset ID Represents the data set involved in approximate calculation Calculation Type ID Indicates the type of calculation that needs to be performed Error value Indicates the tolerable calculation error of the approximate calculation Confidence Probability Indicates the expected accuracy of the approximate calculation Sampling algorithm ID Indicates the specified sampling algorithm type

[0062] It should be noted that, except for the dataset ID, all other parameters in the above table are optional.

[0063] For example, if the calculation parameters in the smart contract call transaction do not include a calculation type ID, the smart contract is allowed to use the default calculation type to perform approximate calculations on the data set. If the calculation parameters in the smart contract call transaction do not include an error value, the tolerable calculation error is 0. If the calculation parameters in the smart contract call transaction do not include a confidence probability, the confidence probability is 100%, and the expected approximate calculation accuracy is 100%. In this case, the smart contract will perform precise calculations on the data set and no longer perform approximate calculations.

[0064] In one embodiment shown, when the blockchain node device calls the sampling logic contained in the above-mentioned smart contract and samples the data set corresponding to the above-mentioned data identifier, in order to avoid the outlier data in the above-mentioned data set from affecting the final approximate calculation result, the above-mentioned data set can be specifically divided into an outlier data subset consisting of several outlier data samples, and a non-outlier data subset consisting of several non-outlier data samples, and then only sampling is performed on the data samples in the non-outlier data subset.

[0065] Among them, the outlier data in the above data set can be specifically calculated by the above smart contract.

[0066] In one embodiment, the sampling logic included in the smart contract may further include logic for performing outlier calculations on the data set. In this case, when the blockchain node device invokes the sampling logic included in the smart contract and samples the data set corresponding to the data identifier, it may specifically execute the outlier calculation logic to perform outlier data calculations on the data samples in the data set, determine the outlier data samples and non-outlier data samples included in the data set, and then create an outlier data subset based on the determined outlier data samples and a non-outlier data subset based on the determined non-outlier data samples.

[0067] The process of calculating outlier data for data samples in the above-mentioned data set generally refers to the process of counting data samples in the above-mentioned data set that are significantly different from other data samples based on a certain statistical algorithm. The specific statistical calculation method is not particularly limited in this specification. For example, in one example, the median of the values ​​corresponding to the data samples in the above-mentioned data set can be calculated, and then based on the median, the data samples in the data set whose values ​​significantly deviate from the median can be screened out as outlier data samples.

[0068] Of course, in actual applications, the outlier data in the above-mentioned data set can also be manually pre-calibrated. In this case, the above-mentioned sampling logic contained in the above-mentioned smart contract can also specifically include logic for screening outlier data in the above-mentioned data set. When the blockchain node device calls the sampling logic contained in the above-mentioned smart contract and samples the data set corresponding to the above-mentioned data identifier, it can specifically execute the above-mentioned logic for screening outlier data, screen outlier data for the data samples in the above-mentioned data set, determine the outlier data samples and non-outlier data samples contained in the data set, and then create an outlier data subset based on the determined outlier data samples, and create a non-outlier data subset based on the determined non-outlier data samples.

[0069] In one embodiment shown, before sampling the data samples in the non-outlier data subset, the number of samples to be sampled for the data samples in the non-outlier data subset can be calculated first, and then the data samples in the non-outlier data subset can be sampled according to the calculated number of samples.

[0070] In one embodiment shown, Hoeffding's Inequality is generally used to describe a random variable and an upper bound on the probability of a deviation from its expected value. In the context of approximate calculation, the number of samples can be used as a random variable, the error value of the approximate calculation can be used as the deviation from the expected value, and the confidence probability of the approximate calculation can be used as the upper bound on the probability. Therefore, in this specification, Hoeffding's Inequality can be used to describe the mathematical relationship between the number of samples, the error value of the approximate calculation, and the confidence probability of the approximate calculation. In other words, in the context of approximate calculation, Hoeffding's Inequality can be used to derive the mathematical relationship between the number of samples, the error value of the approximate calculation, and the confidence probability of the approximate calculation.

[0071] When the Hoffding inequality is used to describe the mathematical relationship between the number of samples, the error value of the approximate calculation, and the confidence probability of the approximate calculation, the Hoffding inequality is expressed as the following formula:

[0072]

[0073] In the above formula, H represents the mathematical identifier of the Hoeffding inequality. g Indicates 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; ε g Indicates the error value corresponding to the above approximate calculation; N g Indicates the total number of data samples in the data set.

[0074] The mathematical relationship between the sampling quantity, the error value of the approximate calculation, and the confidence probability of the approximate calculation derived from the above formula can be expressed as follows:

[0075]

[0076] In the above-mentioned smart contract, the above-mentioned mathematical relationship can be maintained in advance. When the blockchain node device calls the above-mentioned smart contract to calculate the number of samples required for sampling the data samples in the above-mentioned non-outlier data subset, 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-mentioned smart contract call transaction. g , and then obtain the confidence probability δ and error value ε g The input is maintained in the above mathematical relationship to perform calculations to obtain the number of samples corresponding to the above non-outlier data subset.

[0077] It should be noted that the sampling method used for sampling data samples in the non-outlier data subset is not particularly limited in this specification; for example, random sampling, stratified sampling, etc. can be used.

[0078] In the following embodiments, random sampling and stratified sampling are used as examples to describe in detail the sampling process of non-outlier data samples in the non-outlier data subset.

[0079] In one embodiment shown, if random sampling is used to randomly sample data samples in the non-outlier data subset, in this case, when the blockchain node device calls the above-mentioned smart contract and randomly samples the above-mentioned data set based on the calculated sampling quantity, it can first obtain a random number for random sampling, and then randomly sample the non-outlier data samples in the non-outlier data subset based on the obtained random number to obtain data samples corresponding to the above-mentioned calculated sampling quantity.

[0080] The random number is specifically used to control the randomness of the non-outlier data sample sampled from the non-outlier data subset. In practical applications, the non-outlier data sample to be sampled from the non-outlier data subset can be determined according to the obtained random number. For example, in one example, a random number can be used to represent the sample identifier of the non-outlier data sample to be sampled. During the random sampling process, the random number can be used to randomly extract the non-outlier data sample from the non-outlier data subset using the value of the random number as the sample identifier to complete the data sampling.

[0081] It should be noted that the specific method of obtaining the above-mentioned random numbers can be generated on the blockchain or obtained from outside the chain, and is not particularly limited in this specification.

[0082] The following are several specific methods for obtaining random numbers shown in this manual:

[0083] In one embodiment, a random function for generating random numbers can be pre-deployed on the blockchain. For example, in practical applications, the random function can be deployed on the blockchain as a separate smart contract, or as the execution logic included in the smart contract for performing approximate calculations. In this case, a random tree can be generated on the blockchain by calling the random function.

[0084] In another embodiment, the blockchain node device may be equipped with a trusted execution environment (TEE). In the TEE, a random number seed for generating random numbers may be maintained in advance. In this case, random numbers can be generated based on the random seed in the TEE.

[0085] In the third approach shown, target data parameters that can serve as random number seeds can also be obtained from data parameters related to the data maintained by the smart contract used for approximate calculations. Random numbers can then be generated in the smart contract based on the obtained target data parameters. For example, unique parameters such as the hash value of the historical block maintained by the smart contract and the generation timestamp of the historical block can be used as random number seeds to calculate random numbers in the smart contract.

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

[0087] In the fifth approach, a random seed can be generated off-chain to further generate the aforementioned random numbers. In this case, the smart contract can also obtain the off-chain random seed through the oracle program corresponding to the smart contract, and then generate random numbers within the smart contract based on the obtained random seed.

[0088] In the sixth approach, the off-chain random seed can also be included as a calculation parameter in the smart contract invocation transaction. In this case, the off-chain random seed included in the smart contract invocation transaction can be obtained, and then random numbers can be generated within the smart contract based on the obtained random seed.

[0089] The above lists several common implementation methods for obtaining random numbers. It should be emphasized that in actual applications, it is obvious that methods other than the above-listed implementation methods can also be used to obtain random numbers, and they will not be listed one by one in this specification.

[0090] In one embodiment shown, if stratified sampling is used to randomly sample data samples from a non-outlier data subset, in this case, since stratified sampling is generally required to divide the non-outlier data subset into several buckets, and then sample data from these buckets separately. Therefore, when the blockchain node device calls the above-mentioned smart contract to calculate the number of samples required for stratified sampling, it can obtain the confidence probability δ corresponding to the approximate calculation and the error value ε corresponding to each bucket contained in the calculation parameters carried by the above-mentioned smart contract call transaction. k , and then the obtained confidence probability δ and the error value ε of each bucket k Calculations are performed in the above-mentioned mathematical relationship maintained by inputting the above-mentioned data to obtain the number of samples corresponding to each bucket divided into the above-mentioned non-outlier data subset.

[0091] It should be noted that when performing stratified sampling on the above non-outlier data subset, the number of buckets K that need to be divided and the error value ε corresponding to each bucket are k , can be specified by the initiator of the calculation and carried as a calculation parameter in the above smart contract call transaction. For example, in this case, the above calculation parameters need to carry a total error ε specified by the initiator for the approximate calculation of the above data set. g In addition, it is also necessary to carry K error values ​​ε corresponding to each bucket k .

[0092] In addition, when performing stratified sampling on the above non-outlier data subset, the number of buckets K that need to be divided and the error value ε corresponding to each bucket are k , specifically, it can also be the optimal value obtained by the above-mentioned smart contract through autonomous calculation on the chain.

[0093] In one embodiment shown, the number of buckets K to be divided and the error value ε corresponding to each bucket are k , which can be the optimal value solved by the above-mentioned smart contract using the optimization solution method.

[0094] In this case, when the blockchain node device calls the sampling logic contained in the above smart contract to perform stratified sampling on the non-outlier data samples in the non-outlier data subset, it can first use the optimization solution method to solve the optimal number K of buckets required for stratified sampling of the above non-outlier data subset and the optimal error value ε corresponding to each bucket. k, and then the confidence probability δ corresponding to the approximate calculation in the calculation parameters of the above smart contract call transaction and the optimal error value ε corresponding to each bucket solved k , and the above mathematical relationship is input and calculated to obtain the optimal number of samples corresponding to each bucket divided into the above non-outlier data subset. Then, based on the calculated optimal number K and the above optimal sampling number, stratified sampling can be performed on the data samples in the above non-outlier data subset.

[0095] It should be noted that the specific type of optimization solution method used by the above-mentioned smart contract is not specifically limited in this specification. In actual applications, those skilled in the art can flexibly adopt different optimization solution algorithms based on actual needs. For example, in actual applications, commonly used optimization solution algorithms such as Gradient Descent can be specifically adopted.

[0096] Optimization methods usually require explicit constraints, which can be set based on specific solution objectives in practical applications.

[0097] In the scenario of stratified sampling of the aforementioned non-outlier data subset, the optimization goal can include finding the optimal number of buckets, finding the optimal error value for each bucket, and so on. In practical applications, the aforementioned constraints can be set for the optimization method based on these optimization goals.

[0098] In one embodiment shown, based on the above-mentioned solution objective, setting constraints for the above-mentioned optimization solution method may specifically be:

[0099] A weighted average is calculated for the error values ​​corresponding to each bucket, and the obtained weighted average error value is the smallest and is no greater than the total error value corresponding to the approximate calculation for the above non-outlier data subset.

[0100] For example, the above constraints can be expressed as the following formula:

[0101]

[0102] In the above formula, ε g Represents the total error value corresponding to the approximate calculation for the above non-outlier data subset. N k represents the number of samples sampled from the kth bucket. N represents the total number of samples sampled from the above non-outlier data subset.

[0103] The following describes the specific algorithm flow of using the above constraints to solve the optimal number of buckets required for stratified sampling and the optimal error value of each bucket through the accompanying drawings and specific embodiments.

[0104] See Figure 2 , Figure 2 This is a flowchart of an optimization solution method shown in this specification, which includes the following execution steps:

[0105] Step 201: Initialize the value of i; wherein the value of i represents the number of samples contained in each bucket set by the initialization. Except for step 201, the following steps are iteratively executed:

[0106] Step 202, adjusting the value corresponding to the initialized i value;

[0107] The adjustment range of the i value can be flexibly set and is not particularly limited in this specification.

[0108] Step 203: Divide the non-outlier data subset into a plurality of buckets, each containing i samples;

[0109] In step 204, the confidence probability δ (i.e., the confidence probability δ included in the calculation parameters carried by the smart contract call transaction) and the adjusted i value (i.e., the number of samples corresponding to each bucket) are input into the mathematical relationship as calculation parameters to obtain the error value corresponding to each bucket. The error values ​​corresponding to each bucket are then weighted averaged to obtain the weighted average error value.

[0110] It should be noted that if it is the first round of iteration, after executing step 204, steps 202 to 204 will be executed again to perform the second round of iteration.

[0111] Step 205: Determine whether the weighted average error value is not greater than the total error value (i.e., the error value corresponding to the approximate calculation contained in the calculation parameters carried by the smart contract call transaction) and is less than the weighted average error value calculated in the previous round of iteration (i.e., the weighted average error value calculated based on the i value before adjustment in this round of iteration); if not, re-execute the above steps 202-205, continue to the next round of iteration, and repeat the above iterative process until the optimization solution algorithm converges and the iteration is stopped when the weighted average error value that satisfies the above constraints is calculated.

[0112] Step 206, after stopping the iteration, obtaining the optimal i value when the calculated weighted average error value satisfies the above constraint conditions;

[0113] Step 207, based on the optimal i value, determines the optimal number of buckets required for stratified sampling of the non-outlier data subset, and again inputs the above confidence probability and the above optimal i value into the mathematical relationship for calculation to obtain the optimal error value corresponding to each bucket. It should be noted that in the above embodiment, it is a specific implementation method for setting constraints for the above optimization solution method based on the solution goal described above. In practical applications, it is obvious that other forms of constraints can also be set for the above optimization solution method based on the above solution goal. In this specification, after the above smart contract uses the optimization solution method to solve the optimal number of buckets to be divided and the optimal sampling number corresponding to each bucket, the above non-outlier data subset can be stratified sampled based on the optimal number and the optimal error value.

[0114] In one embodiment, when performing stratified sampling on the non-outlier data subset based on the optimal number and the optimal error value, the smart contract may first divide the non-outlier data subset into a plurality of buckets according to the optimal number. For example, assuming the optimal number is K, the non-outlier data subset may be divided into K buckets. Then, data samples in each of the divided buckets may be sampled according to the optimal sampling number.

[0115] The specific sampling method used to sample the data samples in each bucket according to the above-mentioned optimal sampling quantity is not particularly limited in this specification.

[0116] For example, if random sampling is used to sample data samples in each bucket according to the optimal sampling number, a random number for random sampling can be first obtained, and then, based on the obtained random number, non-outlier data samples in each bucket can be randomly sampled to obtain non-outlier data samples corresponding to the calculated optimal sampling number. The specific method for obtaining the random number can be found in the description of the previous embodiment and will not be repeated here.

[0117] Step 106: further call the calculation logic contained in the smart contract call transaction, perform precise calculation on the outlier data samples in the outlier data subset, perform approximate calculation on the non-outlier data samples sampled from the non-outlier data subset, and merge the results of the precise calculation and the approximate calculation as the approximate calculation result for the data set.

[0118] In this specification, after completing the data sampling of the non-outlier data subset in the above non-outlier data subset, approximate calculations may be further performed on the sampled non-outlier data samples.

[0119] Among them, when performing approximate calculations on the non-outlier data samples obtained by sampling, the calculation type specified by the calculation initiator can be used for approximate calculations, or the default calculation type supported by the above-mentioned smart contract can be used for approximate calculations, which is not specifically limited in this specification.

[0120] For example, in one embodiment shown, the smart contract call transaction may also include a sampling algorithm ID. The sampling algorithm ID may be used to indicate the type of calculation specified by the calculation initiator to perform approximate calculations on the data set.

[0121] In this case, when performing approximate calculations on the non-outlier data samples obtained by sampling, the sampling algorithm ID included in the smart contract call transaction can be obtained, and then approximate calculations can be performed on the collected non-outlier data samples according to the calculation type indicated by the sampling algorithm ID.

[0122] Of course, if the above-mentioned smart contract call transaction does not include the above-mentioned sampling algorithm ID, that is, the calculation initiator has not specified the calculation type for approximate calculation of the above-mentioned data set, approximate calculation can also be performed on the non-outlier sample data obtained by sampling based on the default calculation type supported by the above-mentioned smart contract.

[0123] For the outlier data subset, the outlier data samples in the outlier data subset may not be sampled. At the same time, since the result of the approximate calculation for the outlier data samples will usually deviate from the approximate calculation result of the approximate calculation for the data set, the outlier data samples in the outlier data subset may not be approximate calculated, but accurately calculated.

[0124] Among them, when performing precise calculations on outlier data samples in the outlier data subset, the calculation type specified by the calculation initiator can be used for precise calculation, or the default calculation type supported by the above-mentioned smart contract can be used for precise calculation, which is not specifically limited in this specification.

[0125] For example, when performing approximate calculations on outlier data in an outlier data subset, the sampling algorithm ID included in the smart contract call transaction can be obtained, and then precise calculations can be performed on the outlier data samples in the outlier data subset according to the calculation type indicated by the sampling algorithm ID. Of course, if the smart contract call transaction does not include the sampling algorithm ID, precise calculations can also be performed on the outlier data in the outlier data subset based on the default calculation type supported by the smart contract.

[0126] It should be noted that the calculation types corresponding to the above-mentioned approximate calculation and precise calculation are not specifically limited in this specification. For example, they may include summation, average calculation, etc., which will not be listed one by one in this specification.

[0127] After completing the precise calculation of the outlier data samples in the outlier data subset and the approximate calculation of the non-outlier data samples sampled from the non-outlier data subset, the results of the above precise calculation and the above approximate calculation can be combined as the final approximate calculation result for the above data set.

[0128] In one embodiment shown, the above-mentioned smart contract for performing approximate computing can also be a privacy smart contract deployed in a trusted execution environment carried by a blockchain node device.

[0129] In this scenario, the calculation parameters in the smart contract call transaction and the data samples obtained from the data set are typically pre-encrypted. Before invoking the sampling logic contained in the smart contract to divide the data set into outlier and non-outlier data subsets, the blockchain node device can also decrypt the calculation parameters and the data samples obtained from the data set within the trusted execution environment.

[0130] For example, in one example, a pair of asymmetric key pairs for encrypting and decrypting data can be allocated to the trusted execution environment, and the private key of the asymmetric key can be stored in the trusted execution environment, and the public key of the asymmetric key can be released to the computation initiator. The computation parameters in the transaction invoked by the smart contract, as well as the data samples in the acquired data set, can be pre-encrypted based on the public key. Before the blockchain node device calls the sampling logic contained in the smart contract and randomly samples the data set corresponding to the acquired data identifier, it can also use the maintained private key in the trusted execution environment to decrypt the computation parameters and the data samples in the acquired data set, respectively. In the above technical solution, in the scenario where a smart contract is called to perform approximate computation on a data set, by introducing a sampling mechanism for the data set in the smart contract, the time consumed in performing approximate computation on the data set can be reduced without sacrificing the accuracy of the approximate computation results, thereby improving the computational efficiency of the approximate computation on the data set.

[0131] For example, if we still take the example of pre-storing business-related data sets on the blockchain, after introducing the data sampling mechanism into the smart contract, the total time consumed by the smart contract to calculate the business-related data sets can usually be expressed by the following formula:

[0132]

[0133] In the above formula, n g Represents the number of data samples sampled from the data set. N g Represents the total number of data samples in the data set. g The value of N g The difference is usually orders of magnitude compared to the value of . Therefore, after the sampling mechanism is introduced into the smart contract, the time spent on computing the data set through the smart contract will also be reduced by orders of magnitude. It can be seen that the introduction of the sampling mechanism into the smart contract can significantly shorten the time spent on computing the data set and improve the computational efficiency of the approximate calculations on the data set.

[0134] Moreover, since in the process of approximate calculation of the data set, the outlier data in the data set are not sampled and then approximate calculation is performed, but precise calculation is performed directly without sampling, it is possible to further avoid the influence of these outlier data samples on the accuracy of the approximate calculation results of the data set when the data set includes outlier data, and the accuracy of the approximate calculation of the data set can be ensured to the greatest extent.

[0135] Corresponding to the above method embodiments, the present application also provides device embodiments.

[0136] The device embodiments of this specification can be applied to electronic devices. Device embodiments can be implemented through software, hardware, or a combination of software and hardware. For example, a device implemented in software, as a logical device, is implemented by a processor of the electronic device in which it is located, reading corresponding computer program instructions from non-volatile memory into internal memory and executing them.

[0137] From the hardware level, Figure 3 The figure shows a hardware structure diagram of the electronic device where the device of this manual is located, except Figure 3 In addition to the processor, memory, network interface, and non-volatile memory shown, the electronic device in which the device is located in the embodiment may also include other hardware according to the actual function of the electronic device, which will not be described in detail.

[0138] Figure 4 This is a block diagram of a smart contract-based computing device shown in an exemplary embodiment of this specification.

[0139] Please refer to Figure 4 The computing device 40 based on smart contract can be applied in the aforementioned Figure 3In the electronic device shown, a smart contract for performing approximate computing is deployed on the blockchain, and the device 40 includes:

[0140] A receiving module 401 receives a smart contract call transaction initiated by a computation initiator for the smart contract; wherein the smart contract call transaction includes computation parameters corresponding to the approximate computation; the computation parameters include data identifiers of data sets participating in the approximate computation;

[0141] The sampling module 402, in response to the smart contract call transaction, calls the sampling logic included in the smart contract call transaction, divides the data set corresponding to the data identifier into an outlier data subset consisting of a plurality of outlier data samples and a non-outlier data subset consisting of a plurality of non-outlier data samples, and samples the non-outlier data samples in the non-outlier data subset;

[0142] The calculation module 403 further calls the calculation logic included in the smart contract call transaction, performs precise calculation on the outlier data samples in the outlier data subset, performs approximate calculation on the non-outlier data samples sampled from the non-outlier data subset, and combines the results of the precise calculation and the approximate calculation as the approximate calculation result for the data set.

[0143] In this embodiment, the device 40 further includes:

[0144] Get module 404 ( Figure 4 (not shown in the figure), before the sampling module 402 divides the data set corresponding to the data identifier into an outlier data subset consisting of a number of outlier data samples and a non-outlier data subset consisting of a number of non-outlier data samples, the data set corresponding to the data identifier stored on the blockchain is obtained; or, through the oracle program corresponding to the smart contract, the data set corresponding to the data identifier is obtained from an off-chain database connected to the blockchain.

[0145] In this embodiment, the sampling module 402:

[0146] Performing outlier data calculation on the data samples in the data set corresponding to the data identifier to determine outlier data samples and non-outlier data samples contained in the data set;

[0147] The outlier data subset is created based on the outlier data samples, and a non-outlier data subset is created based on the non-outlier data samples.

[0148] In this embodiment, the calculation parameters include a confidence probability corresponding to the approximate calculation; and a total 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 confidence probability corresponding to the approximate calculation, the error value corresponding to the approximate calculation, and the number of samples corresponding to the data set participating in the approximate calculation;

[0149] The sampling module 402 further:

[0150] Before sampling the data samples in the non-outlier data subset, the confidence probability corresponding to the approximate calculation and the error value corresponding to the approximate calculation are input into the mathematical relationship for calculation to obtain the sampling quantity corresponding to the non-outlier data subset.

[0151] In this embodiment, the mathematical relationship is expressed using the following formula:

[0152]

[0153] 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; ε g Represents the error value; N g Indicates the total number of data samples in the data set.

[0154] In this embodiment, the sampling module 402:

[0155] Sampling is performed on the non-outlier data samples in the non-outlier data subset according to the calculated sampling quantity.

[0156] In this embodiment, the sampling of the non-outlier data samples in the non-outlier data subset includes random sampling;

[0157] The sampling module 402 further:

[0158] Get random numbers for random sampling;

[0159] Random sampling is performed on non-outlier data samples in the non-outlier data subset based on the random number to obtain non-outlier data samples corresponding to the calculated sampling quantity.

[0160] In this embodiment, the sampling performed on the non-outlier data samples in the non-outlier data subset includes stratified sampling;

[0161] The sampling module 402 further:

[0162] Using an optimization solution method, solving the optimal number of data subsets required for stratified sampling on the non-outlier data subset, and the optimal error value corresponding to each divided data subset;

[0163] Inputting the confidence probability corresponding to the approximate calculation and the optimal error value corresponding to each data subset into the mathematical relationship for calculation, thereby obtaining the optimal sampling quantity corresponding to each data subset;

[0164] The data set is divided into a plurality of data subsets according to the optimal number, and non-outlier data samples in each data subset are sampled according to the optimal sampling data.

[0165] In this embodiment, the constraints adopted by the optimization solution method include: a weighted average error value obtained by performing weighted average calculation on the error values ​​corresponding to each data subset is the smallest and is not greater than the total error value;

[0166] The sampling module 402 further performs the following steps:

[0167] Step A, adjusting the value corresponding to the initialized i value;

[0168] Step B, dividing the non-outlier data subset into a plurality of data subsets each containing i number of samples;

[0169] Step C, inputting the confidence probability and the adjusted i value as calculation parameters into the mathematical relationship to perform calculations to obtain error values ​​corresponding to the respective data subsets, and performing weighted average calculations on the error values ​​corresponding to the respective data subsets to obtain a weighted average error value;

[0170] Step D: Determine whether the weighted average error value is not greater than the total error value and is less than the weighted average error value calculated based on the value of i before the current adjustment; if not, re-execute steps A to D above until the calculated weighted average error value satisfies the constraint condition, then stop iteration, and obtain the optimal value of i that makes the weighted average error value satisfy the constraint condition;

[0171] Step E: Based on the optimal i value, determine the optimal number of data subsets required for stratified sampling of the non-outlier data subset, and input the confidence probability and the optimal i value into the mathematical relationship for calculation to obtain the optimal error value corresponding to each data subset.

[0172] In this embodiment, the sampling module further:

[0173] Get random numbers for random sampling;

[0174] Based on the random number, random sampling is performed on non-outlier data samples in each data subset to obtain non-outlier data samples corresponding to the calculated optimal sampling number.

[0175] In this embodiment, the sampling module further performs any one of the following:

[0176] Calling a random function deployed on the blockchain to generate a random tree for random sampling;

[0177] Generating a random number in the trusted execution environment based on a random number seed maintained in the trusted execution environment carried by the node device;

[0178] Obtaining a target data parameter serving as the random number seed from data parameters related to the data maintained by the smart contract, and generating a random number for random sampling in the smart contract based on the obtained target data parameter;

[0179] Obtaining a random number generated off-chain for random sampling through the oracle program corresponding to the smart contract;

[0180] Through the oracle program corresponding to the smart contract, a random number seed generated outside the chain for generating random numbers is obtained, and a random number for random sampling is generated in the smart contract based on the obtained target data parameters; the random number seed generated outside the chain included in the calculation parameters is obtained, and a random number for random sampling is generated in the smart contract based on the random number seed.

[0181] In this embodiment, the calculation parameters also include an algorithm identifier;

[0182] The calculation module 403:

[0183] performing precise calculations on the outlier data samples in the outlier data subset according to the calculation type indicated by the algorithm identifier;

[0184] Performing approximate calculations on non-outlier data samples sampled from the non-outlier data subset, including:

[0185] According to the calculation type indicated by the algorithm identifier, approximate calculation is performed on the non-outlier data samples sampled from the non-outlier data subset.

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

[0187] The sampling module 402 further:

[0188] Before dividing the data set corresponding to the data identifier into an outlier data subset consisting of a plurality of outlier data samples and a non-outlier data subset consisting of a plurality of non-outlier data samples, the calculation parameters and the data samples in the acquired data set are decrypted separately in the trusted execution environment.

[0189] The systems, devices, modules, or units described in the above embodiments may be implemented by computer chips or entities, or by products having certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email transceiver, game console, tablet computer, wearable device, or any combination of these devices.

[0190] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

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

[0192] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information using 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 transitory media such as modulated data signals and carrier waves.

[0193] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.

[0194] The foregoing description of this specification describes specific embodiments. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0195] The terms used in one or more embodiments of this specification are for the purpose of describing specific embodiments only and are not intended to limit one or more embodiments of this specification. The singular forms "a," "an," "the," 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 otherwise. 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.

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

[0197] The above description is merely a preferred embodiment of one or more embodiments of this specification and is not intended to limit one or more embodiments of this specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of this specification shall be included in the scope of protection of one or more embodiments of this specification.

Claims

1. A smart contract-based computing method, applied to a node device in a blockchain, wherein a smart contract for performing approximate computing is deployed on the blockchain, the method comprising: Receiving a smart contract call transaction initiated by a computation initiator for the smart contract; wherein the smart contract call transaction includes computation parameters corresponding to the approximate computation; the computation parameters include a data identifier of a data set participating in the approximate computation, a confidence probability corresponding to the approximate computation, and a total error value corresponding to the approximate computation; the confidence probability represents the accuracy of the approximate computation; and the smart contract maintains a mathematical relationship derived based on the Hoeffding inequality, which is used to describe the confidence probability corresponding to the approximate computation, the error value corresponding to the approximate computation, and the number of samples corresponding to the data set participating in the approximate computation; In response to the smart contract call transaction, invoking sampling logic included in the smart contract call transaction to divide the data set corresponding to the data identifier into an outlier data subset consisting of a plurality of outlier data samples and a non-outlier data subset consisting of a plurality of non-outlier data samples; and inputting the confidence probability corresponding to the approximate calculation and the error value corresponding to the approximate calculation into the mathematical relationship for calculation to obtain a sampling quantity corresponding to the non-outlier data subset, and sampling the non-outlier data samples in the non-outlier data subset based on the sampling quantity; The computing logic included in the smart contract call transaction is further called to perform precise calculations on the outlier data samples in the outlier data subset, perform approximate calculations on the non-outlier data samples sampled from the non-outlier data subset, and combine the results of the precise calculations and the approximate calculations to serve as the approximate calculation result for the data set.

2. The method according to claim 1, before dividing the data set corresponding to the data identifier into an outlier data subset consisting of a plurality of outlier data samples and a non-outlier data subset consisting of a plurality of non-outlier data samples, further comprising: Obtaining a data set corresponding to the data identifier stored on the blockchain; or, Through the oracle program corresponding to the smart contract, a data set corresponding to the data identifier is obtained from an off-chain database connected to the blockchain.

3. The method according to claim 2, wherein the data set corresponding to the data identifier is divided into an outlier data subset consisting of a plurality of outlier data samples and a non-outlier data subset consisting of a plurality of non-outlier data samples, comprising: Performing outlier data calculation on the data samples in the data set corresponding to the data identifier to determine outlier data samples and non-outlier data samples contained in the data set; The outlier data subset is created based on the outlier data samples, and a non-outlier data subset is created based on the non-outlier data samples.

4. The method according to claim 1, wherein the mathematical relationship is expressed using the following formula: in, 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; ε g Represents the error value; N g Indicates the total number of data samples in the data set.

5. The method according to claim 1, wherein sampling non-outlier data samples in the non-outlier data subset comprises: Sampling is performed on the non-outlier data samples in the non-outlier data subset according to the calculated sampling quantity.

6. The method according to claim 5, wherein the sampling of the non-outlier data samples in the non-outlier data subset comprises random sampling; Sampling non-outlier data samples in the non-outlier data subset according to the calculated sampling quantity includes: Get random numbers for random sampling; Random sampling is performed on non-outlier data samples in the non-outlier data subset based on the random number to obtain non-outlier data samples corresponding to the calculated sampling quantity.

7. The method according to claim 5, wherein the sampling of the non-outlier data samples in the non-outlier data subset comprises stratified sampling; Sampling non-outlier data samples in the non-outlier data subset according to the calculated sampling quantity includes: Using an optimization solution method, solving the optimal number of data subsets required for stratified sampling on the non-outlier data subset, and the optimal error value corresponding to each divided data subset; Inputting the confidence probability corresponding to the approximate calculation and the optimal error value corresponding to each data subset into the mathematical relationship for calculation, thereby obtaining the optimal sampling quantity corresponding to each data subset; The data set is divided into a plurality of data subsets according to the optimal number, and non-outlier data samples in each data subset are sampled according to the optimal sampling number.

8. The method according to claim 7, wherein: The constraints adopted by the optimization solution method include: the weighted average error value obtained by performing weighted average calculation on the error values ​​corresponding to each data subset is the smallest and is not greater than the total error value; An optimization solution method is used to solve the optimal number of data subsets required for stratified sampling of the non-outlier data subset and the optimal error value corresponding to each divided data subset, including: Step A, adjusting the value corresponding to the initialized i value; Step B, dividing the non-outlier data subset into a plurality of data subsets each containing i number of samples; Step C, inputting the confidence probability and the adjusted i value as calculation parameters into the mathematical relationship to perform calculations to obtain error values ​​corresponding to the respective data subsets, and performing weighted average calculations on the error values ​​corresponding to the respective data subsets to obtain a weighted average error value; Step D: Determine whether the weighted average error value is not greater than the total error value and is less than the weighted average error value calculated based on the value of i before the current adjustment; if not, re-execute steps A to D above until the calculated weighted average error value satisfies the constraint condition, then stop iteration, and obtain the optimal value of i that makes the weighted average error value satisfy the constraint condition; Step E: Based on the optimal i value, determine the optimal number of data subsets required for stratified sampling of the non-outlier data subset, and input the confidence probability and the optimal i value into the mathematical relationship for calculation to obtain the optimal error value corresponding to each data subset.

9. The method according to claim 7, wherein sampling non-outlier data samples in each data subset according to the optimal sampling quantity comprises: Get random numbers for random sampling; Based on the random number, random sampling is performed on non-outlier data samples in each data subset to obtain non-outlier data samples corresponding to the calculated optimal sampling number.

10. The method according to claim 6 or 9, wherein obtaining a random number for random sampling comprises any one of the following: Calling a random function deployed on the blockchain to generate a random tree for random sampling; Generating a random number in the trusted execution environment based on a random number seed maintained in the trusted execution environment carried by the node device; Obtaining a target data parameter serving as the random number seed from data parameters related to the data maintained by the smart contract, and generating a random number for random sampling in the smart contract based on the obtained target data parameter; Obtaining a random number generated off-chain for random sampling through the oracle program corresponding to the smart contract; Obtaining, through an oracle program corresponding to the smart contract, a random number seed generated off-chain for generating random numbers, and generating a random number for random sampling in the smart contract based on the obtained target data parameters; Obtain a random number seed generated off-chain and included in the calculation parameters, and generate a random number for random sampling in the smart contract based on the random number seed.

11. The method according to claim 1, wherein the calculation parameters further include an algorithm identifier; Performing precise calculations on outlier data samples in the outlier data subset includes: performing precise calculations on the outlier data samples in the outlier data subset according to the calculation type indicated by the algorithm identifier; Performing approximate calculations on non-outlier data samples sampled from the non-outlier data subset, including: According to the calculation type indicated by the algorithm identifier, approximate calculation is performed on the non-outlier data samples sampled from the non-outlier data subset.

12. The method according to claim 1, wherein the smart contract is deployed in a trusted execution environment carried by the node device; the calculation parameters and the data samples in the data set are pre-encrypted; Before dividing the data set corresponding to the data identifier into an outlier data subset consisting of a plurality of outlier data samples and a non-outlier data subset consisting of a plurality of non-outlier data samples, the method further includes: The calculation parameters and the acquired data samples in the data set are decrypted respectively in the trusted execution environment.

13. A computing device based on a smart contract, applied to a node device in a blockchain, wherein a smart contract for performing approximate computing is deployed on the blockchain, the device comprising: A receiving module is 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 a data identifier of a data set participating in the approximate calculation, a confidence probability corresponding to the approximate calculation, and a total error value corresponding to the approximate calculation; the confidence probability represents the accuracy of the approximate calculation; and the smart contract maintains a mathematical relationship derived based on the Hoeffding inequality, which is used to describe the confidence probability corresponding to the approximate calculation, the error value corresponding to the approximate calculation, and the number of samples corresponding to the data set participating in the approximate calculation; a sampling module, in response to the smart contract call transaction, calling the sampling logic included in the smart contract call transaction, dividing the data set corresponding to the data identifier into an outlier data subset consisting of a plurality of outlier data samples and a non-outlier data subset consisting of a plurality of non-outlier data samples; and inputting the confidence probability corresponding to the approximate calculation and the error value corresponding to the approximate calculation into the mathematical relationship for calculation to obtain a sampling quantity corresponding to the non-outlier data subset, and sampling the non-outlier data samples in the non-outlier data subset based on the sampling quantity; The computing module further calls the computing logic included in the smart contract call transaction, performs precise computing on the outlier data samples in the outlier data subset, performs approximate computing on the non-outlier data samples sampled from the non-outlier data subset, and combines the results of the precise computing and the approximate computing to serve as the approximate computing result for the data set.

14. An electronic device comprising: processor; a memory for storing processor-executable instructions; The processor implements the steps of the method according to any one of claims 1 to 12 by running the executable instructions.

15. A computer-readable storage medium having computer instructions stored thereon, wherein when the instructions are executed by a processor, the steps of the method according to any one of claims 1 to 12 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

Cited By

  • Micro-data transfer using a dual transmission network

    US12475453B1