WO2023185050A1 - 基于智能合约的计算、更新、读取方法及装置、电子设备 - Google Patents

基于智能合约的计算、更新、读取方法及装置、电子设备 Download PDF

Info

Publication number
WO2023185050A1
WO2023185050A1 PCT/CN2022/135402 CN2022135402W WO2023185050A1 WO 2023185050 A1 WO2023185050 A1 WO 2023185050A1 CN 2022135402 W CN2022135402 W CN 2022135402W WO 2023185050 A1 WO2023185050 A1 WO 2023185050A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
calculation
smart contract
sampling
data set
Prior art date
Application number
PCT/CN2022/135402
Other languages
English (en)
French (fr)
Inventor
周晨辉
闫莺
Original Assignee
蚂蚁区块链科技(上海)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 蚂蚁区块链科技(上海)有限公司 filed Critical 蚂蚁区块链科技(上海)有限公司
Publication of WO2023185050A1 publication Critical patent/WO2023185050A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • G06F16/2462Approximate or statistical queries
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F17/00Digital computing or data processing equipment or methods, specially adapted for specific functions
    • G06F17/10Complex mathematical operations
    • G06F17/17Function evaluation by approximation methods, e.g. inter- or extrapolation, smoothing, least mean square method
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F17/00Digital computing or data processing equipment or methods, specially adapted for specific functions
    • G06F17/10Complex mathematical operations
    • G06F17/18Complex mathematical operations for evaluating statistical data, e.g. average values, frequency distributions, probability functions, regression analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/64Protecting data integrity, e.g. using checksums, certificates or signatures

Definitions

  • One or more embodiments of this specification relate to the field of blockchain technology, and in particular to a computing device and electronic equipment based on smart contracts.
  • Blockchain is a new application model of computer technology such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm.
  • data blocks are combined into a chained data structure in a chronological manner and are cryptographically guaranteed to be an untamperable and unforgeable distributed ledger. Due to the characteristics of blockchain, such as decentralization, non-tamperable information, and autonomy, blockchain has also received more and more attention and applications.
  • This specification proposes a calculation method based on smart contracts, which is applied to node devices in the blockchain. Smart contracts for performing approximate calculations are deployed on the blockchain. The method includes:
  • the approximate calculation logic contained in the smart contract call transaction is further called, and approximate calculation is performed based on the data samples obtained by hierarchical sampling from the data set to obtain an approximate calculation result for the data set.
  • This specification also proposes a computing device based on smart contracts, which is applied to node equipment in the blockchain. Smart contracts for performing approximate calculations are deployed on the blockchain.
  • the device includes:
  • a receiving module that receives a smart contract call transaction initiated by the 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 set participating in the approximate calculation data identification;
  • a sampling module in response to the smart contract call transaction, calls the sampling logic contained in the smart contract call transaction, and performs hierarchical sampling of the data samples in the data set corresponding to the data identifier;
  • the calculation module further calls the approximate calculation logic contained in the smart contract call transaction and performs approximate calculations based on the data samples obtained by hierarchical sampling from the data set to obtain approximate calculation results for the data set.
  • Figure 1 is a flow chart of a smart contract-based calculation method provided by an exemplary embodiment
  • Figure 2 is a flow chart of an optimization solution method provided by an exemplary embodiment
  • Figure 3 is a schematic structural diagram of an electronic device provided by an exemplary embodiment
  • FIG. 4 is a block diagram of a smart contract-based computing device provided by an exemplary embodiment.
  • the steps of the corresponding method are not necessarily performed in the order shown and described in this specification.
  • methods may include more or fewer steps than described in this specification.
  • 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 also be combined into a single step in other embodiments. describe.
  • smart contracts deployed on the blockchain to interface with businesses can include, in addition to business logic related to the business, logic for calculating business data related to the business. This allows users to complete business-related calculations on the blockchain by calling the smart contract.
  • the total calculation time usually depends on the time it takes to perform I/O operations on each piece of data and the time it takes to calculate the above set of data in batches.
  • the total time taken by a smart contract to calculate a business-related data set can usually be calculated using the following formula: To express:
  • i represents the i-th piece of data in the above-mentioned data set
  • IO i represents the time-consuming I/O operation for the i-th piece of data
  • Operation i represents the batch processing of the i-th piece of data in the data set. The time it takes to perform the calculation.
  • the above smart contracts can also be deployed in the TEE (Trusted execution environment) mounted on the blockchain node device.
  • TEE Trusted execution environment
  • the data in the above data collection usually needs to be encrypted and stored.
  • the total calculation time usually depends on the time it takes to perform I/O operations on each piece of data and the time it takes to decrypt each piece of data. , and the time it takes to calculate the above set of data in batches.
  • the total time taken by a smart contract to calculate a business-related data set can usually be calculated using the following formula: To express:
  • Operation i represents the time taken to decrypt the i-th piece of data in the data set.
  • this specification proposes a technical solution that introduces approximate calculation and stratified sampling mechanisms into smart contracts to improve the computational efficiency of calculating business-related data.
  • a smart contract for data calculation can be deployed on the blockchain, and the smart contract can contain approximate calculation logic for approximate calculation and sampling logic for stratified sampling.
  • the calculation initiator can initiate a smart contract call transaction to call the smart contract to perform approximate calculations on the data set participating in the calculation.
  • the smart contract call transaction may include calculation parameters corresponding to the approximate calculation; the calculation parameters may include the data identifier of the data set participating in the approximate calculation;
  • the node device in the blockchain 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, and process the data corresponding to the above data identification.
  • the data samples in the collection are hierarchically sampled.
  • the approximate calculation logic contained in the smart contract can be further called to perform approximate calculations based on the data samples obtained by hierarchical sampling from the above data collection to obtain the Approximate calculation results for a data set.
  • n g represents the number of data samples obtained by stratified sampling 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 an order of magnitude different from the value of N g , after the stratified sampling mechanism is introduced in the smart contract, the time-consuming calculation of the data set through the smart contract will also be reduced by an order of magnitude. .
  • Figure 1 is a flow chart of a smart contract-based calculation method provided by an exemplary embodiment.
  • the method is applied to node devices in the blockchain; wherein a smart contract for performing approximate calculations is deployed on the blockchain, and the method includes the following steps:
  • Step 102 Receive a smart contract call transaction for the smart contract initiated by the calculation initiator; wherein the smart contract call transaction includes calculation parameters corresponding to the approximate calculation; the calculation parameters include a data set participating in the approximate calculation data identification;
  • the above-mentioned calculation initiator may specifically be a party with data calculation requirements.
  • the above calculation initiator may be a user with data calculation requirements.
  • the calculation initiator in a scenario based on smart contracts and business docking, can also be an off-chain business system with data calculation requirements.
  • the smart contract contains execution logic corresponding to the contract code. Specifically, it can include approximate calculation logic for approximate calculation and sampling logic for data sampling. . In this way, the logic of approximate calculation of data and data sampling can be introduced into the smart contract.
  • 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. can be used.
  • the above data sampling is hierarchical sampling and the above sampling logic is hierarchical sampling logic as an example for explanation.
  • the above-mentioned calculation initiator can call the above-mentioned smart contract to perform approximate calculations on the data set participating in the calculation by initiating a smart contract call transaction.
  • the above smart contract can be understood as a contract code anchored on the blockchain.
  • Contract account and the user can register an external account on the blockchain, 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 contracts.
  • the calculation parameters corresponding to the approximate calculation may be included; the calculation parameters may include the data identifier of the data set participating in the approximate calculation.
  • the calculation initiator When the above calculation initiator initiates the above smart contract call transaction, if the calculation initiator directly connects with the blockchain node, it can package a smart contract transaction and directly submit it to the connected blockchain node device point-to-point. Can. If the calculation initiator accesses the blockchain through the blockchain connection service provided by the Baas (Blockchain as a Service) platform, it can generate a call request for the above 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.
  • the Baas Blockchain as a Service
  • 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, can respond to the smart contract call transaction and call the above-mentioned smart contract on the blockchain. Approximate calculations are performed on data sets.
  • Step 104 In response to the smart contract call transaction, call the sampling logic contained in the smart contract to perform hierarchical sampling of the data samples in the data set corresponding to the data identifier;
  • the blockchain node device 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 contained in the smart contract, and process the data set corresponding to the data identifier.
  • the data samples in are stratified sampled.
  • the blockchain node device after receiving the above-mentioned smart contract call transaction initiated by the above-mentioned calculation initiator, the blockchain node device usually needs to work with other blockchain nodes participating in the consensus based on the consensus algorithm supported by the blockchain. , perform consensus processing on the smart contract call transaction and the execution results of the smart contract call transaction. Since this manual does not involve improving the consensus process of the blockchain, the process of consensus processing of the smart contract call transaction and the execution results of the smart contract call transaction will not be described in detail in this manual.
  • the blockchain node device may 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.
  • the data set can be pre-certified on the above-mentioned blockchain.
  • a certificate deposit contract for data certificate can be deployed on the blockchain.
  • the calculation initiator can package a certificate deposit transaction to include the need in the calculation.
  • the data set is published to the certificate deposit contract for certificate deposit.
  • the execution logic corresponding to the contract code contained in the above-mentioned smart contract may include, in addition to the above-mentioned approximate calculation logic and the above-mentioned sampling logic, data storage logic. That is to say, in addition to being used for approximate calculations, the smart contract itself also has its own data storage function. At this time, before calling the smart contract for calculation, the calculation initiator can also package a certificate deposit transaction and pre-release the data set that needs to participate in the calculation to the smart contract for certificate deposit. Subsequently, the smart contract can Read the above-mentioned data set that has been certified from its own contract storage space to perform approximate calculations.
  • the blockchain node device can obtain the data set corresponding to the data identifier stored on the blockchain based on the above-mentioned data identifier.
  • the data identifier may be a certificate hash returned by the blockchain node after the above-mentioned data set is successfully certificated on the blockchain.
  • the data set can also be pre-stored in an off-chain database connected to the above-mentioned blockchain.
  • the smart contract can obtain the data set corresponding to the data identifier from the above-mentioned off-chain database through its corresponding oracle machine.
  • the above-mentioned oracle program can specifically be a centralized oracle program or a decentralized oracle program.
  • the oracle program may be an oracle service program deployed on a service device outside the chain.
  • the oracle program may be an oracle contract deployed on the blockchain that interfaces with the above-mentioned smart contract.
  • calculation parameters may specifically include various types of parameters shown in the following table:
  • Parameter Type meaning Data set ID Represents a collection of data involved in approximate calculations Calculation type ID The type of calculation that represents the approximate calculation that needs to be made difference Indicates the tolerable calculation error for approximate calculations confidence probability Indicates the expected accuracy of the approximate calculation Sampling algorithm ID Indicates the specified sampling algorithm type
  • calculation parameters in the above-mentioned smart contract call transaction do not contain the calculation type ID, it means that the above-mentioned smart contract is allowed to use the default calculation type to perform approximate calculations on the above-mentioned data set. If the calculation parameters in the above smart contract call transaction do not contain an error value, it means that the tolerable calculation error is 0. If the calculation parameters in the above-mentioned 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-mentioned smart contract will perform the above-mentioned data collection. Calculate exactly, no more approximations.
  • the blockchain node device when the blockchain node device calls the sampling logic contained in the above-mentioned smart contract to perform hierarchical sampling on the obtained data set corresponding to the above-mentioned data identifier, it may specifically calculate and perform hierarchical sampling first. number of samples, and then perform stratified sampling according to the calculated number of samples.
  • Hoeffding s Inequality is generally used to describe a random variable and an upper bound on the probability of its deviation from its expected value.
  • the above-mentioned sampling number can be used as a random variable
  • the error value of the above-mentioned approximate calculation can be used as the expected value deviation
  • the confidence probability of the above-mentioned approximate calculation can be used as the upper limit of the above-mentioned probability. Therefore, in this specification, Hoeffding's inequality can be used to describe the mathematical relationship between the above-mentioned sampling number, the error value of the above-mentioned approximate calculation, and the confidence probability of the above-mentioned approximate calculation.
  • Hoeffding's inequality can be used to derive the mathematical relationship between the above-mentioned sampling number, the error value of the above-mentioned approximate calculation, and the confidence probability of the above-mentioned approximate calculation.
  • Hoeffding's inequality is used to describe the mathematical relationship between the above-mentioned sampling number, the error value of the above-mentioned approximate calculation and the confidence probability of the above-mentioned approximate calculation, Hoeffding's inequality is expressed as the following formula:
  • H represents the mathematical identifier of Hoeffding's inequality.
  • n g represents the number of samples.
  • b g and a g respectively represent the maximum value and 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.
  • the above-mentioned mathematical relationship can be maintained in advance.
  • 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 in the calculation parameters in the above-mentioned smart contract call transaction, and the confidence probability ⁇ corresponding to the approximate calculation.
  • Error value ⁇ g and then input the obtained confidence probability ⁇ and error value ⁇ g into the above-mentioned mathematical relationship maintained for calculation, and obtain the number of samples corresponding to the above-mentioned data set.
  • 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 contained in the calculation parameters carried by the above-mentioned smart contract call transaction, and the confidence probability ⁇ corresponding to each The error value ⁇ k corresponding to the bucket, and then the obtained confidence probability ⁇ and the error value ⁇ k of each bucket are input into the above-mentioned mathematical relationship maintained for calculation respectively, and the number of samples corresponding to each bucket divided by the above-mentioned data set is obtained.
  • the number of buckets K that need to be divided and the error value ⁇ k corresponding to each bucket can be specified by the calculation initiator and carried as calculation parameters.
  • the above smart contract call transaction is in progress.
  • the above calculation parameters in addition to the total error ⁇ g specified by the calculation initiator for the approximate calculation of the above data set, the above calculation parameters also need to carry K error values ⁇ k corresponding to each bucket.
  • the number of buckets K needs to be divided, and the error value ⁇ k corresponding to each bucket. Specifically, it can also be performed independently by the above smart contract on the chain. The calculated optimal value.
  • the number K of buckets to be divided and the error value ⁇ k corresponding to each bucket can be the optimal value solved by the above-mentioned smart contract using the optimization solution method.
  • the blockchain node device calls the sampling logic contained in the above-mentioned smart contract to perform hierarchical sampling on the data set corresponding to the above-mentioned data identification, it can first use the optimization solution method, and the solution is based on the above-mentioned
  • the probability ⁇ , and the optimal error value ⁇ k corresponding to each solved bucket are input into the above mathematical relationship maintained for calculation respectively, and the optimal sampling number corresponding to each bucket divided by the above data set is obtained. Then, based on the calculated optimal number K and the optimal sampling number, stratified sampling can be performed on the data samples in the above data set.
  • optimization solution method used by the above-mentioned smart contract is not particularly limited in this specification.
  • those skilled in the art can flexibly adopt different optimal solutions based on actual needs.
  • Optimization solving algorithm For example, in practical applications, commonly used optimal solution algorithms such as gradient descent can be used.
  • the optimal solution goals may include finding the optimal number of divided buckets, finding the optimal error value corresponding to each bucket, and so on. Then, in practical applications, the above constraints can be set for the above optimization solution method based on the above optimization objectives.
  • setting constraints for the above optimization solution method may specifically be:
  • ⁇ g represents the total error value corresponding to the approximate calculation of the above data set.
  • N k represents the number of samples sampled from the k-th bucket.
  • N represents the total number of samples sampled from the above data set.
  • Figure 2 is a flow chart of an optimization solution method shown in this specification, including the following execution steps:
  • Step 201 Initialize the i value; where the i value represents the number of samples included in each bucket of the initialization settings.
  • the following steps are iteratively executed:
  • Step 202 adjust the value corresponding to the initialized i value
  • the adjustment range of the i value can be set flexibly and is not specifically limited in this manual.
  • Step 203 Divide the data set into several buckets each containing i samples
  • Step 204 Use the above-mentioned 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) as calculation parameters, and input them into the mathematical Calculate in the relationship to obtain the error value corresponding to each bucket, and perform a weighted average calculation on the error value corresponding to each bucket to obtain the weighted average error value;
  • the confidence probability ⁇ i.e., the confidence probability ⁇ included in the calculation parameters carried by the smart contract call transaction
  • the adjusted i value i.e., the number of samples corresponding to each bucket
  • steps 202 to 204 will be executed again to execute the second round of iteration.
  • Step 205 Determine whether the weighted average error value is not greater than the total error value (that is, 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 value calculated in the previous round of iterations.
  • the average error value that is, the weighted average error value calculated based on the i value before this round of iteration adjustment
  • re-execute the above steps 202 to 205 continue to execute the next round of iteration, and repeat the above iteration process, The iteration stops until the optimization solution algorithm converges and the weighted average error value that satisfies the above constraints is calculated.
  • Step 206 After stopping the iteration, obtain the optimal i value when the calculated weighted average error value satisfies the above constraints;
  • Step 207 Determine the optimal number of buckets to be divided when performing stratified sampling on the data set based on the optimal i value, and input the above confidence probability and the above optimal i value again into the Calculate the above mathematical relationship to obtain the optimal error value corresponding to each bucket.
  • the above-mentioned smart contract uses the optimization solution method to solve for the optimal number of buckets that need to be divided, and the optimal number of samples corresponding to each bucket, and then the optimal number and the optimal error value can be calculated based on the optimal number and the optimal error value.
  • the above data set was stratified sampled.
  • the above-mentioned data set can first be divided into several according to the optimal number. bucket; for example, assuming that the above optimal number is K, the above data set can be divided into K buckets. Then, from each divided bucket, the data samples in each bucket can be sampled according to the above-mentioned optimal sampling number.
  • the specific sampling method used to sample the data samples in each bucket according to the above-mentioned optimal sampling number is not particularly limited in this specification.
  • the specific sampling method used to sample the data samples in each bucket according to the above-mentioned optimal sampling number, specifically, random sampling can be used.
  • the random number used for random sampling can be obtained first, and then each bucket can be sampled based on the obtained random number.
  • the data samples in are randomly sampled to obtain data samples corresponding to the calculated optimal sampling number.
  • the above-mentioned random numbers are specifically used to control the randomness of the data samples sampled from each bucket.
  • the data samples that need to be sampled from each bucket can be determined according to the obtained random numbers.
  • a random number can be used to represent the sample identifier of the data sample to be sampled.
  • the random number can be randomly extracted from the bucket according to the random number and the value of the random number can be used as a sample.
  • the identified data sample completes data sampling.
  • a random function for generating random numbers can be pre-deployed on the blockchain.
  • the above random function can be deployed on the blockchain as an independent smart contract, or deployed in the smart contract as the execution logic contained in the smart contract for approximate calculation.
  • a random tree can be generated on the blockchain by calling the random function mentioned above;
  • the above-mentioned blockchain node device can be equipped with a Trusted Execution Environment (Trusted Execution Environment).
  • Trusted Execution Environment a Trusted Execution Environment
  • a random number seed for generating random numbers can be maintained in advance.
  • random numbers can be generated based on the random seed in the trusted execution environment.
  • the target data parameters that can be used as random number seeds can also be obtained from the data parameters related to the data maintained by the above-mentioned smart contract used for approximate calculation, and then the target data parameters can be obtained based on the obtained targets.
  • the data parameters generate random numbers in the above smart contract.
  • the unique parameters such as the hash value of the historical block maintained by the above-mentioned smart contract and the generation timestamp of the historical block can be used as a random number seed to calculate the random number in the smart contract.
  • the random numbers described above can be generated off-chain.
  • the above-mentioned smart contract can also obtain the random number generated outside the chain through the oracle program corresponding to the smart contract.
  • a random number seed for further generating the above-mentioned random numbers can be generated outside the chain.
  • the above-mentioned smart contract can also obtain the random number seed generated outside the chain through the oracle program corresponding to the smart contract, and then generate the random number seed in the smart contract based on the obtained random number seed. random number.
  • the random number seed generated outside the chain can also be carried as a calculation parameter in the smart contract call transaction.
  • 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.
  • each bucket is separately sampled according to the above-mentioned optimal sampling number.
  • the specific sampling method used to sample the data samples in is not limited to random sampling, and other forms of sampling methods other than random sampling can also be used, which will not be listed one by one in this specification.
  • Step 106 Further call the approximate calculation logic contained in the smart contract call transaction to perform approximate calculation based on the data samples obtained by hierarchical sampling from the data set to obtain an approximate calculation result for the data set.
  • the calculation type specified by the calculation initiator can be used for approximate calculation, or the default calculation type supported by the above-mentioned smart contract can be used for approximate calculation. Specially limited.
  • the sampling algorithm ID may also be included in the above-mentioned smart contract call transaction.
  • the sampling algorithm ID may be specifically used to indicate the calculation type specified by the calculation initiator to perform approximate calculation on the above-mentioned data set.
  • the above-mentioned smart contract call transaction does not include the above-mentioned sampling algorithm ID, that is, the calculation initiator does not specify a calculation type for approximate calculation of the above-mentioned data set, it can also be based on the default calculation type supported by the above-mentioned smart contract for the sampled results. Approximate calculations are performed on sample data.
  • calculation type corresponding to the above approximate calculation is not particularly limited in this specification.
  • it may include summing, averaging, etc., which will not be listed one by one in this specification.
  • the above-mentioned smart contract for performing approximate calculations may specifically be a privacy smart contract deployed in a trusted execution environment mounted on a blockchain node device.
  • the calculation parameters in the above-mentioned smart contract call transaction and the obtained data samples in the above-mentioned data collection are usually encrypted in advance.
  • the blockchain node device Before calling the sampling logic contained in the above-mentioned smart contract to randomly sample the data set corresponding to the above-mentioned data identifier, the blockchain node device can also perform the above-mentioned calculation parameters and the obtained data in the trusted execution environment.
  • the data samples in the above data set are decrypted respectively, and after decryption, the data samples in the above data set are randomly sampled according to the random sampling method described above. The specific process will not be described again.
  • the above-mentioned trusted execution environment may be assigned an asymmetric key pair for encryption and decryption of data, and the private key of the above-mentioned asymmetric key may be stored in the above-mentioned trusted execution environment, Publish the public key of the above-mentioned asymmetric key to the above-mentioned calculation initiator.
  • the calculation parameters in the above-mentioned smart contract call transaction and the obtained data samples in the above-mentioned data collection can be encrypted in advance based on the above-mentioned public key.
  • the blockchain node device Before calling the sampling logic contained in the above-mentioned smart contract to randomly sample the data set corresponding to the above-mentioned data identification, the blockchain node device can also use the maintained private key to calculate the above-mentioned calculation parameters in the trusted execution environment. And decrypt the obtained data samples in the above data set respectively.
  • n g represents the number of data samples obtained by stratified sampling 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 an order of magnitude different from the value of N g , after the stratified sampling mechanism is introduced in the smart contract, the time-consuming calculation of the data set through the smart contract will also be reduced by an order of magnitude. .
  • this application also provides device embodiments.
  • the embodiments of the device in this specification can be applied to electronic equipment.
  • the device embodiments may be implemented by software, or may be implemented by hardware or a combination of software and hardware.
  • Taking software implementation as an example as a logical device, it is formed by reading the corresponding computer program instructions in the non-volatile memory into the memory and running them through the processor of the electronic device where it is located.
  • FIG. 3 it is a hardware structure diagram of the electronic equipment where the device of this specification is located.
  • the electronic device in which the device in the embodiment is located usually may also include other hardware according to the actual functions of the electronic device, which will not be described again.
  • FIG. 4 is a block diagram of a smart contract-based computing device according to an exemplary embodiment of this specification.
  • the smart contract-based computing device 40 can be applied in the electronic device shown in Figure 3.
  • a smart contract for performing approximate calculations is deployed on the blockchain.
  • the device 40 includes:
  • the receiving module 401 receives a smart contract call transaction initiated by the 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 participating in the approximate calculation The data identifier of the collection;
  • the sampling module 402 in response to the smart contract call transaction, calls the sampling logic contained in the smart contract call transaction, and performs hierarchical sampling of the data samples in the data set corresponding to the data identifier;
  • the calculation module 403 further calls the approximate calculation logic contained in the smart contract call transaction and performs approximate calculations based on the data samples obtained by hierarchical sampling from the data set to obtain approximate calculation results for the data set.
  • the device 40 further includes:
  • the acquisition module 404 (not shown in Figure 4), before the sampling module performs hierarchical sampling of the data samples in the data set corresponding to the data identifier, acquires the certificates stored on the blockchain and The data set corresponding to the data identifier; 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.
  • 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 intelligence
  • the contract maintains the three parameters derived based on Hoeffding's inequality, 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.
  • the sampling module 402 is a sampling module 402
  • the confidence probability corresponding to the approximate calculation and the optimal error value corresponding to each data subset are input into the mathematical relationship for calculation to obtain the corresponding corresponding to each data subset.
  • Optimal sampling number
  • stratified sampling is performed on the data samples in the data set corresponding to the data identifier.
  • 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. ;
  • the sampling module 402 further performs the following steps:
  • Step A Adjust the value corresponding to the initialized i value
  • Step B Divide the data set into several data subsets each containing i number of samples
  • Step C Use the confidence probability and the number of samples corresponding to each data subset as calculation parameters, input them into the mathematical relationship for calculation, obtain error values corresponding to each data subset, and calculate The error values corresponding to each of the data subsets are calculated as a weighted average 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 less than the weighted average error value calculated based on the i value before this adjustment; if not, re-execute step A above -Step D, stop iteration until the calculated weighted average error value satisfies the constraint condition, and obtain the optimal i value when the weighted average error value satisfies the constraint condition;
  • Step E Determine the optimal number of data subsets that need to be divided when performing stratified sampling on the data set based on the optimal i value, and input the confidence probability and the optimal i value into Calculate the mathematical relationship to obtain the optimal error value corresponding to each data subset.
  • n g represents the number of samples
  • b g and a g represent the maximum and minimum values of the data samples in the data set respectively
  • represents the confidence probability
  • ⁇ g represents the error Value
  • N g represents the total number of data samples in the data set.
  • sampling module 402 further:
  • Data samples in each data subset are sampled according to the optimal sampling data.
  • the method of sampling data samples in each data subset includes random sampling
  • the sampling module 402 further:
  • the data samples in each data subset are randomly sampled based on the random numbers to obtain data samples corresponding to the optimal sampling number.
  • sampling module 402 further performs any of the following:
  • the target data parameter as the random number seed from the data parameters related to the data maintained by the smart contract, and generate random numbers for random sampling in the smart contract based on the acquired target data parameters;
  • the calculation parameters also include an algorithm identifier indicating the calculation type corresponding to the approximate calculation; the calculation module 403:
  • the smart contract is deployed in a trusted execution environment mounted on the node device; the calculation parameters and the data samples in the data set have been encrypted in advance;
  • the sampling module 402 further:
  • the calculation parameters and the obtained data samples in the data set are separately analyzed in the trusted execution environment. Decrypt.
  • a typical implementation device is a computer, which may be in the form of a personal computer, a laptop, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, or a game controller. desktop, tablet, wearable device, or a combination of any of these devices.
  • a computer includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
  • processors CPUs
  • input/output interfaces network interfaces
  • memory volatile and non-volatile memory
  • Memory may include non-permanent storage in computer-readable media, random access memory (RAM) and/or non-volatile memory in the form of read-only memory (ROM) or flash memory (flash RAM). Memory is an example of computer-readable media.
  • RAM random access memory
  • ROM read-only memory
  • flash RAM flash random access memory
  • Computer-readable media includes both persistent and non-volatile, removable and non-removable media that can be implemented by any method or technology for storage of information.
  • Information may be computer-readable instructions, data structures, modules of programs, 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), and read-only memory.
  • PRAM phase change memory
  • SRAM static random access memory
  • DRAM dynamic random access memory
  • RAM random access memory
  • read-only memory read-only memory
  • ROM read-only memory
  • EEPROM electrically erasable programmable read-only memory
  • flash memory or other memory technology
  • compact disc read-only memory CD-ROM
  • DVD digital versatile disc
  • Magnetic tape cartridges magnetic disk storage, quantum memory, graphene-based storage media or other magnetic storage devices, or any other non-transmission medium, can be used to store information that can be accessed by computing devices.
  • computer-readable media does not include transient computer-readable media (transitory media), such as modulated data signals and carrier waves.
  • first, second, third, etc. may use the terms first, second, third, etc. to describe various information, the information should not be limited to these terms. These terms are only used to distinguish information of the same type from each other.
  • first information may also be called second information, and similarly, the second information may also be called first information.
  • word “if” as used herein may be interpreted as "when” or “when” or “in response to determining.”

Abstract

一种基于智能合约的计算方法,应用于区块链中的节点设备,所述区块链上部署了用于执行近似计算的智能合约,包括:接收计算发起方发起的针对所述智能合约的智能合约调用交易;其中,所述智能合约调用交易包括与所述近似计算对应的计算参数;所述计算参数包括参与近似计算的数据集合的数据标识;响应于所述智能合约调用交易,调用所述智能合约调用交易包含的采样逻辑,对与所述数据标识对应的所述数据集合中的数据样本进行分层采样;进一步调用所述智能合约调用交易包含的近似计算逻辑,基于从所述数据集合中分层采样得到的数据样本进行近似计算,以得到针对所述数据集合的近似计算结果。

Description

基于智能合约的计算、更新、读取方法及装置、电子设备
本公开要求于2022年3月20日提交中国专利局、申请号为202210334257.5、发明名称为“基于智能合约的计算、更新、读取方法及装置、电子设备”的中国专利申请的优先权,其全部内容通过引用结合在本公开中。
技术领域
本说明书一个或多个实施例涉及区块链技术领域,尤其涉及一种基于智能合约的计算装置、电子设备。
背景技术
区块链(Blockchain)是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。区块链系统中按照时间顺序将数据区块以顺序相连的方式组合成链式数据结构,并以密码学方式保证的不可篡改和不可伪造的分布式账本。由于区块链具有去中心化、信息不可篡改、自治性等特性,区块链也受到人们越来越多的重视和应用。
发明内容
本说明书提出一种基于智能合约的计算方法,应用于区块链中的节点设备,所述区块链上部署了用于执行近似计算的智能合约,所述方法包括:
接收计算发起方发起的针对所述智能合约的智能合约调用交易;其中,所述智能合约调用交易包括与所述近似计算对应的计算参数;所述计算参数包括参与近似计算的数据集合的数据标识;
响应于所述智能合约调用交易,调用所述智能合约调用交易包含的采样逻辑,对与所述数据标识对应的所述数据集合中的数据样本进行分层采样;
进一步调用所述智能合约调用交易包含的近似计算逻辑,基于从所述数据集合中分层采样得到的数据样本进行近似计算,以得到针对所述数据集合的近似计算结果。
本说明书还提出一种基于智能合约的计算装置,应用于区块链中的节点设备,所述区块链上部署了用于执行近似计算的智能合约,所述装置包括:
接收模块,接收计算发起方发起的针对所述智能合约的智能合约调用交易;其中,所述智能合约调用交易包括与所述近似计算对应的计算参数;所述计算参数包括参与近似计算的数据集合的数据标识;
采样模块,响应于所述智能合约调用交易,调用所述智能合约调用交易包含的采样逻辑,对与所述数据标识对应的所述数据集合中的数据样本进行分层采样;
计算模块,进一步调用所述智能合约调用交易包含的近似计算逻辑,基于从所述数据集合中分层采样得到的数据样本进行近似计算,以得到针对所述数据集合的近似计算结果。
以上技术方案中,在调用智能合约针对数据集合进行近似计算的场景下,通过在智能合约中引入针对该数据集合的分层采样机制,可以在不牺牲近似计算结果的准确度的基础上,降低对该数据集合进行近似计算时的耗时,提高针对该数据集合进行近似计算时的计算效率。
附图说明
图1是一示例性实施例提供的一种基于智能合约的计算方法的流程图;
图2是一示例性实施例提供的一种最优化求解方法的流程图;
图3是一示例性实施例提供的一种电子设备的结构示意图;
图4是一示例性实施例提供的一种基于智能合约的计算装置的框图。
具体实施方式
这里将详细地对示例性实施例进行说明,其示例表示在附图中。下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的要素。以下示例性实施例中所描述的实施方式并不代表与本说明书一个或多个实施例相一致的所有实施方式。相反,它们仅是与如所附权利要求书中所详述的、本说明书一个或多个实施例的一些方面相一致的装置和方法的例子。
需要说明的是:在其他实施例中并不一定按照本说明书示出和描述的顺序来执行相应方法的步骤。在一些其他实施例中,其方法所包括的步骤可以比本说明书所描述的更多或更少。此外,本说明书中所描述的单个步骤,在其他实施例中可能被分解为多个步骤进行描述;而本说明书中所描述的多个步骤,在其他实施例中也可能被合并为单个步骤进行描述。
随着智能合约技术的不断发展,在使用智能合约与业务进行对接时,智能合约也逐渐开始承担一部分与该业务相关的算力。
例如,在实际应用中,区块链上部署的用于与业务进行对接的智能合约中,除了可以包括与业务相关的业务逻辑以外,还可以包括针对该业务相关的业务数据进行计算的逻辑,从而使得用户可以通过调用该智能合约的方式,在区块链上完成针对该业务相关的计算。
当利用智能合约对与业务相关的数据集合进行计算时,其计算总耗时通常取决于针对每一条数据分别进行I/O操作的耗时和对上述一组数据批量进行计算的耗时。
例如,在实际应用中,以与业务相关的数据集合预先存证在区块链上为例,此时智能合约对与业务相关的数据集合进行计算时的总耗时,通常可以用如下的公式进行表示:
Figure PCTCN2022135402-appb-000001
其中,在上述公式中,i表示上述数据集合中的第i条数据;IO i表示针对第i条数据进行I/O操作处理操作的耗时;Operation i表示对数据集合中的i条数据批量进行计算的耗时。
需要说明的是,由于数据集合在区块链上进行存证时,通常是以key-Value键值对的形式,逐条的存储在区块链节点设备搭载的存储介质中,因此对于存储在区块链上的上述数据集合,通常只能根据数据的key键值,逐条的从区块链节点设备搭载的存储介质中来读取数据。
在一些对数据计算的隐私性和安全性要求较高的应用场景中,上述智能合约还可以部署在区块链节点设备搭载的TEE(Trusted execution environment,可信执行环境)中。
在这种情况下,上述数据集合中的数据,通常都需要加密存储。此时,利用智能合约对与业务相关的数据集合进行计算时,其计算总耗时则通常取决于针对每一条数据分别进行I/O操作的耗时、针对每一条数据分别进行解密的耗时、和对上述一组数据批量进行计算的耗时。
例如,在实际应用中,以与业务相关的数据集合预先存证在区块链上为例,此时智能合约对与业务相关的数据集合进行计算时的总耗时,通常可以用如下的公式进行表示:
Figure PCTCN2022135402-appb-000002
其中,在上述公式中,Operation i表示对数据集合中的第i条数据进行解密的耗时。
通过以上的介绍不难看出,在利用智能合约对与业务相关的数据集合进行计算的场景下,如果该数据集合包含的数据量比较大,通过智能合约对该数据集合进行计算,得到准确的计算结果是非常耗时的。
而在实际应用中,在一些业务场景之下,可能并不需要针对与业务相关的数据的精确计算结果,而是可以容忍一些计算精度上的损失。
例如,在计算用户平均年龄的计算场景下,大多数情况下是不需要准确的计算结果的,通常只需要近似计算得到一个平均年龄的区间即可。
基于此,本说明书提出一种在智能合约中引入近似计算和分层抽样的机制,来提升针对业务相关的数据进行计算的计算效率的技术方案。
在实现时,可以在区块链上部署用于进行数据计算的智能合约,在该智能合约中可以包含用于进行近似计算的近似计算逻辑和用于进行分层采样的采样逻辑。计算发起方可以通过发起一笔智能合约调用交易的方式,来调用该智能合约对参与计算的数据集合进行近似计算。其中,该智能合约调用交易可以包括与近似计算对应的计算参数;该计算参数可以包括参与近似计算的数据集合的数据标识;
而区块链中的节点设备在接收到计算发起方发起的该智能合约调用交易时,可以响应于智能合约调用交易,调用该智能合约调用交易包含的采样逻辑,对与上述数据标识对应的数据集合中的数据样本进行分层采样,在分层采样完成后,可以进一步调用该智能合约包含的近似计算逻辑,基于从上述数据集合中分层采样得到的数据样本进行近似计算,以得到针对该数据集合的近似计算结果。
在以上技术方案中,在调用智能合约针对数据集合进行近似计算的场景下,通过在智能合约中引入针对该数据集合的分层采样机制,可以在不牺牲近似计算结果的准确度的基础上,降低对该数据集合进行近似计算时的耗时,提高针对该数据集合进行近似计算时的计算效率。
例如,仍以与业务相关的数据集合预先存证在区块链上为例,在智能合约中引入了分层采样机制之后,此时智能合约对与业务相关的数据集合进行计算时的总耗时,通常可以用如下的公式进行表示:
Figure PCTCN2022135402-appb-000003
其中,在上述公式中,n g表示从数据集合中分层采样得到的数据样本的数量。N g表示数据集合中的数据样本的总数量。由于n g的数值与N g的数值相比,通常是数量级的差异,因此智能合约中引入了分层采样机制之后,通过该智能合约对数据集合进行计算时的耗时,也会数量级的减少。
可见,在智能合约中引入了分层采样机制,可以显著的提高针对该数据集合进行近似计算时的计算效率。
请参见图1,图1是一示例性实施例提供的一种基于智能合约的计算方法的流程图。所述方法应用于区块链中的节点设备;其中,所述区块链上部署了用于执行近似计算的智能合约,所述方法包括以下步骤:
步骤102,接收计算发起方发起的针对所述智能合约的智能合约调用交易;其中,所述智能合约调用交易包括与所述近似计算对应的计算参数;所述计算参数包括参与近似计算的数据集合的数据标识;
上述计算发起方,具体可以是具有数据计算需求的一方。例如,在一个例子中,上述计算发起方可以是一个具有数据计算需求的用户。在另一个例子中,在基于智能合约与业务对接的场景下,该计算发起方具体也可以是一个具有数据计算需求的链外业务系统。
在区块链上,可以部署用于进行数据计算的智能合约,该智能合约包含的合约代码对应的执行逻辑,具体可以包括用于进行近似计算的近似计算逻辑和用于进行数据采样的采样逻辑。通过这种方式,可以在该智能合约中引入对数据的近似计算和数据采样的逻辑。
其中,需要说明的是,上述数据采样所采用的采样方式,在本说明书中不进行特别限定;例如,可以采用随机采样(Random Sampling)、分层采样(Stratified Sampling),等等。
在以下实施例中,将以上述数据采样为分层采样,以及上述采样逻辑为分层采样逻辑为例进行说明。
上述计算发起方可以通过发起一笔智能合约调用交易的方式,来调用上述智能合约对参与计算的数据集合进行近似计算。
例如,以上述计算发起方为用户,以及上述区块链为采用账户模型的区块链为例,在这种情况下,上述智能合约可以理解为区块链上的一个锚定了合约代码的合约账户,而该用户可以在区块链上注册外部账户,并通过该外部账户发起一笔智能合约调用交易,并将该智能合约调用交易提交至接入的区块链节点设备,来调用该智能合约。
其中,需要说明的是,在上述智能合约调用交易中,具体可以包括与近似计算对应的计算参数;该计算参数可以包括参与近似计算的数据集合的数据标识。
上述计算发起方在发起上述智能合约调用交易时,如果该计算发起方直接与区块链节点进行对接,则可以打包一笔智能合约交易,点对点的直接提交至接入的区块链节点设备即可。而如果该计算发起方通过诸如Baas(Blockchain as a Service)平台提供的区块链接入服务接入区块链,则可以生成一个针对上述智能合约的调用请求,并将该调用请求提交至Baas平台,再由该Baas平台基于该调用请求中携带的调用参数打包一笔智能合约调用交易,提交至区块链节点设备。
区块链节点设备可以接收上述计算发起方发起的上述智能合约调用交易,并在接收到上述智能合约调用交易时,可以响应该智能合约调用交易,在区块链上调用上述智能合约,对上述数据集合进行近似计算。
步骤104,响应于所述智能合约调用交易,调用所述智能合约包含的采样逻辑,对与所述数据标识对应的所述数据集合中的数据样本进行分层采样;
区块链节点设备接收到上述计算发起方发起的上述智能合约调用交易之后,可以响应该智能合约调用交易,调用所述智能合约包含的采样逻辑,对与所述数据标识对应的所述数据集合中的数据样本进行分层采样。
其中,需要说明的是,区块链节点设备在接收到上述计算发起方发起的上述智能合约调用交易之后,通常还需要基于区块链支持的共识算法,与其它参与共识的区块链节点一起,对该智能合约调用交易以及该智能合约调用交易的执行结果进行共识处理。由于本说明书并不涉及对区块链的共识过程进行改进,故在本说明书中对该智能合约调用交易以及该智能合约调用交易的执行结果进行共识处理的过程不再进行详述。
在示出的一种实施方式中,区块链节点设备在调用所述智能合约包含的采样逻辑,对与所述数据标识对应的所述数据集合中的数据样本进行分层采样之前,可以先获取上述智能合约调用交易中包含的上述数据标识,并基于该数据标识来读取参与近似计算的数据集合。
其中,基于该数据标识来读取参与近似计算的数据集合时,具体可以从区块链上来读取,也可以从链外读取,在本说明书中不进行特别限定。
在一种实现方式中,该数据集合具体可以预先存证在上述区块链上。
例如,在区块链上还可以部署一个用于进行数据存证的存证合约,计算发起方在调用上述智能合约进行计算之前,可以通过打包一笔存证交易的方式,将该需要参与计算的数据集合发布至该存证合约进行存证。
又如,上述智能合约包含的合约代码对应的执行逻辑,除了可以包括上述近似计算逻辑和上述采样逻辑以外,还可以包含数据存证逻辑。也即,该智能合约除了可以用于进行近似计算以外,其本身也自带针对数据的存证功能。此时计算发起方在调用该智能合约进行计算之前,也可以先通过打包一笔存证交易的方式,将该需要参与计算的数据集合预先发布至该智能合约进行存证,后续该智能合约可以从自身的合约存储空间中来读取存证完毕的上述数据集合来进行近似计算。
在这种情况下,区块链节点设备可以基于上述数据标识,来获取区块链上存证的与该数据标识对应的数据集合。例如,在这种情况下,该数据标识具体可以是上述数据集合在区块链上存证成功之后,由区块链节点返回的存证hash。
在另一种实现方式中,该数据集合具体也可以预先存证在与上述区块链对接的链外数据库中。在这种情况下,该智能合约可以通过与其对应的预言机程序(oracle machine),从上述链外数据库中获取与该数据标识对应的数据集合。
其中,上述预言机程序具体可以是中心化的预言机程序,也可以是去中心化的预言机程序。当上述预言机程序为中心化的预言机程序时,此时该预言机程序可以是部署在链外的服务设备上的一个预言机服务程序。当上述预言机程序为去中心化的预言机程序时,此时该预言机程序可以是部署在区块链上的一个与上述智能合约进行对接的预言机合约。需要说明的是,由于本说明书并不涉及预言机程序相关的改进,故在本说明书中对上述智能合约通过与其对应的预言机程序,从上述链外数据库中获取与该数据标识对应的数据集合的具体实现过程,在本说明书中不再详述。
对于上述智能合约调用交易中包含的计算参数,除了可以包括以上提到的上述数据集合的数据标识以外,在实际应用中,还可以包括其它形式的与近似计算相关的参数。
在示出的一种实施方式中,上述计算参数具体可以包括下表中示出的各类参数:
参数类型 参数含义
数据集ID 表示参与近似计算的数据集合
计算类型ID 表示需要进行的近似计算的计算类型
误差值 表示可容忍的近似计算的计算误差
置信概率 表示期望的近似计算的准确度
采样算法ID 表示指定的采样算法类型
其中,需要说明的是,上表中除了数据集ID以外,其它参数均为可选参数。
例如,如果上述智能合约调用交易中的计算参数中,不包含计算类型ID,则表示允许上述智能合约采用默认的计算类型对上述数据集合进行近似计算。如果上述智能合约调用交易中的计算参数中,不包含误差值,则表示可容忍的计算误差为0。如果上述智能合约调用交易中的计算参数中,不包含置信概率,则表示置信概率为100%,期望的近似计算的准确度100%,在这种情况下,上述智能合约会针对上述数据集合进行精确计算,不再进行近似计算。
在示出的一种实施方式中,区块链节点设备在调用上述智能合约包含的采样逻辑,对获取到与上述数据标识对应的数据集合进行分层采样时,具体可以先计算进行分层采样的采样数量,然后再按照计算出的采样数量进行分层采样。
在示出的一种实施方式中,霍夫丁不等式(Hoeffding’s Inequality)通常用于描述随机变量和与其期望值偏差的概率上限。而在近似计算的场景下,上述采样数量可以作为随机 变量,上述近似计算的误差值可以作为期望值偏差,上述近似计算的置信概率可以作为上述概率上限。因此,在本说明书中可以利用霍夫丁不等式来描述上述采样数量、上述近似计算的误差值和上述近似计算的置信概率之间的数学关系。换言之,在近似计算的场景下,可以利用霍夫丁不等式来推导出上述采样数量、上述近似计算的误差值和上述近似计算的置信概率之间的数学关系。
其中,在利用霍夫丁不等式来描述上述采样数量、上述近似计算的误差值和上述近似计算的置信概率之间的数学关系时,霍夫丁不等式表示成如下公式:
Figure PCTCN2022135402-appb-000004
在上述公式中,H表示霍夫丁不等式的数学标识符。n g表示所述采样数量。b g、a g分别表示所述数据集合中的数据样本的最大值和最小值。δ表示所述置信概率;ε g表示与上述近似计算对应的误差值;N g表示所述数据集合中的数据样本的总数量。
而基于上述公式推导出的上述采样数量、上述近似计算的误差值和上述近似计算的置信概率之间的数学关系,则可以用如下公式表示:
Figure PCTCN2022135402-appb-000005
而在上述智能合约中,可以预先维护上述数学关系。区块链节点设备在调用上述智能合约计算进行分层采样所需的采样数量时,可以获取上述智能合约调用交易中的计算参数中的与近似计算对应的置信概率δ,以及与近似计算对应的误差值ε g,再将获取到的置信概率δ和误差值ε g输入维护的上述数学关系中进行计算,得到与上述数据集合对应的采样数量。
其中,由于采用分层采样时,通常需要将上述数据集合划分成若干个bucket(即上述数据子集),再从这些bucket中分别进行数据采样。因此,区块链节点设备在调用上述智能合约计算进行分层采样所需的采样数量时,可以获取上述智能合约调用交易携带的计算参数中包含的与近似计算对应的置信概率δ,以及与各个bucket对应的误差值ε k,再将获取到的置信概率δ和各个bucket的误差值ε k输入维护的上述数学关系中分别进行计算,得到与上述数据集合划分出的各个bucket对应的采样数量。
需要说明的是,在对上述数据集合进行分层采样时,需要划分出的bucket的数量K,以及每一个bucket对应的误差值ε k,可以由计算发起方来指定,并作为计算参数携带在上述智能合约调用交易中。例如,在这种情况下,上述计算参数中除了需要携带一个计算发起方指定的针对上述数据集合进行近似计算的总误差ε g以外,还需要携带K个与各个bucket对应的误差值ε k
除此之外,在对上述数据集合进行分层采样时,需要划分出的bucket的数量K,以及每一个bucket对应的误差值ε k,具体也可以是由上述智能合约在链上自主的进行计算得到的最优值。
在示出的一种实施方式中,需要划分出的bucket的数量K,以及每一个bucket对应的 误差值ε k,可以是由上述智能合约采用最优化求解方法求解出的最优值。
在这种情况下,区块链节点设备在调用上述智能合约包含的采样逻辑,对获取到与上述数据标识对应的数据集合进行分层采样时,可以先采用最优化求解方法,求解在针对上述数据集合进行分层采样时所需划分出的bucket的最优数量K,以及每一个bucket对应的最优误差值ε k,再将上述智能合约调用交易中的计算参数中与近似计算对应的置信概率δ,与求解出的各个bucket对应的最优误差值ε k,输入维护的上述数学关系中分别进行计算,得到与上述数据集合划分出的各个bucket对应的最优采样数量。然后,可以基于计算出的上述最优数量K和上述最优采样数量,对上述数据集合中的数据样本进行分层采样。
需要说明的是,上述智能合约所采用的最优化求解方法的具体类型,在本说明书中不进行特别限定,在实际应用中,本领域技术人员可以基于实际的需求,来灵活的采用不同的最优化求解算法。例如,在实际应用中,具体可以采用诸如梯度下降法(Gradient Descent)等常用的最优求解算法。
其中,对于最优化求解方法而言,通常需要设置一个明确的约束条件。而在实际应用中,通常可以基于具体的求解目标,来设置上述约束条件。
在对上述数据集合进行分层采样的场景下,最优化的求解目标可以包括求解划分出的bucket的最优数量、求解出各个bucket对应的最优误差值,等等。那么,在实际应用中,就可以基于上述优化目标来为上述最优化求解方法设置上述约束条件。
在示出的一种实施方式中,基于上述求解目标,为上述最优化求解方法设置约束条件具体可以是:
针对各个bucket对应的误差值进行加权平均计算,得到的加权平均误差值最小,并且不大于针对上述数据集合进行近似计算对应的总误差值。
例如,上述约束条件可以表示成如下的公式:
Figure PCTCN2022135402-appb-000006
以上公式中,ε g表示针对上述数据集合进行近似计算对应的总误差值。N k表示从第k个bucket中采样的样本数量。N表示从上述数据集合中采样的总样本数量。
以下通过附图和具体的实施例来描述采用上述约束条件,来求解分层采样所需的bucket的最优数量和各个bucket的最优误差值的具体算法流程。
请参见图2,图2为本说明书示出的一种最优化求解方法的流程图,包括以下的执行步骤:
步骤201,初始化i值;其中,所述i值表示初始化设置的各个bucket中包含的样本数量。除了步骤201以外,以下步骤为迭代执行的步骤:
步骤202,对初始化的i值对应的数值进行调整;
其中,对i值的调整幅度可以灵活设置,在本说明书中不进行特别限定。
步骤203,将所述数据集合划分为分别包含i个样本数量的若干bucket;
步骤204,将上述置信概率δ(即智能合约调用交易携带的计算参数中包含的置信概率δ)以及调整之后的i值(即与各个bucket对应的样本数量)作为计算参数,输入至所述数学关系中进行计算,得到与各个bucket分别对应的误差值,并对各个bucket对应的误差值进行加权平均计算,得到加权平均误差值;
其中,需要说明的是,如果是第一轮迭代,执行完步骤204,会重新执行步骤202-步骤204,执行第二轮迭代。
步骤205,确定所述加权平均误差值是否不大于所述总误差值(即智能合约调用交易 携带的计算参数中包含的与近似计算对应的误差值),并且小于上一轮迭代计算出的加权平均误差值(即基于本轮迭代调整之前的i值计算出的加权平均误差值);如果否,重新执行以上的步骤202-步骤205,继续执行下一轮迭代,并重复以上的迭代过程,直至最优化求解算法收敛,计算出满足上述约束条件的加权平均误差值时停止迭代。
步骤206,在停止迭代后,获取使得计算出的加权平均误差值满足上述约束条件时的最优i值;
步骤207,基于所述最优i值确定针对所述数据集合进行分层抽样时,所需划分出的bucket的最优数量,并再次将上述置信概率以及与上述最优i值,输入至所述数学关系中进行计算,得到与各个bucket对应的最优误差值。需要说明的是,在以上实施例中,是基于以上描述的求解目标为上述最优化求解方法设置约束条件的一种具体的实施方式,在实际应用中,显然也可以基于上述求解目标,来为上述最优化求解方法设置其它形式的约束条件。在本说明书中,上述智能合约采用最优化求解方法求解出需要划分出的bucket的最优数量,以及每一个bucket对应的最优采样数量之后,可以基于该最优数量和该最优误差值对上述数据集合进行分层采样。
在示出的一种实施方式中,上述智能合约在基于该最优数量和该最优误差值对上述数据集合进行分层采样时,首先可以按照该最优数量将上述数据集合划分为若干个bucket;比如,假设上述最优数量为K,则可以将上述数据集合划分为K个bucket。然后,可以从划分出的各个bucket中,按照上述最优采样数量分别对各个bucket中的数据样本进行采样。
其中,按照上述最优采样数量分别对各个bucket中的数据样本进行采样所采用的具体的采样方式,在本说明书中不进行特别限定。
在示出的一种实施方式中,按照上述最优采样数量分别对各个bucket中的数据样本进行采样所采用的具体的采样方式,具体可以采用随机采样的方式。
如果采用随机采样的方式,按照上述最优采样数量分别对各个bucket中的数据样本进行采样时,具体可以先获取用于进行随机采样的随机数,然后再基于获取到的该随机数对各个bucket中的数据样本进行随机采样,得到与计算出的上述最优采样数量对应的数据样本。
其中,上述随机数具体用于控制从各个bucket中采样的数据样本的随机性,在实际应用中,可以按照获取到的随机数,来确定需要从各个bucket中采样的数据样本。例如,在一个例子中,可以利用随机数来表示待采样的数据样本的样本标识,在进行随机采样的过程中,可以按照该随机数,随机的从bucket中抽取将该随机数的数值作为样本标识的数据样本完成数据采样。
需要说明的是,关于上述随机数具体的获取方式,可以在区块链上生成,也可以从链外获取,在本说明书中不进行特别限定。
以下是本说明书示出的几种用于获取随机数的具体方式:
在示出的一种方式中,在区块链上可以预先部署一个用于生成随机数的随机函数。例如,在实际应用中,上述随机函数具体可以作为一个独立的智能合约部署在区块链上,或者作为上述用于进行近似计算的智能合约包含的执行逻辑部署在该智能合约中。在这种情况下,可以通过调用上述随机函数在区块链上生成随机树;
在示出的另一种方式中,上述区块链节点设备上可以搭载一个可信执行环境(Trusted Execution Environment)。在该可信执行环境中,预先可以维护一个用于生成随机数的随机数种子。在这种情况下,可以通过在该可信执行环境中,基于该随机种子来生成随机数。
在示出的第三种方式中,也可以从用于进行近似计算的上述智能合约维护的数据相关的数据参数中,来获取可以作为随机数种子的目标数据参数,然后可以基于获取到的目标数据参数在上述智能合约中生成随机数。例如,还可以从上述智能合约维护的历史区块的 hash值、历史区块的生成时间戳这些具有唯一性的参数来作为随机数种子,在该智能合约中计算随机数。
在示出的第四种方式中,上述随机数可以在链外生成。在这种情况下,上述智能合约,也可以通过与该智能合约对应的预言机程序,来获取在链外生成的该随机数。
在示出的第五种方式中,可以在链外生成一个用于进一步生成上述随机数的随机数种子。在这种情况下,上述智能合约,也可以通过与该智能合约对应的预言机程序,来获取在链外生成的该随机数种子,然后基于获取到的该随机数种子在该智能合约中生成随机数。
在示出的第六种方式中,在链外生成的上述随机数种子,具体也可以作为计算参数携带在上述智能合约调用交易中。在这种情况下,可以获取该智能合约调用交易中包括的在链外生成的随机数种子,然后基于获取到的该随机数种子在该智能合约中生成随机数。
以上列举了几种用于获取随机数的常见实现方式,需要强调的是,在实际应用中,显然也可以采用以上列举的实现方式以外的方式来获取随机数,在本说明书中不再进行一一列举。
需要强调的是,在以上实施例中,以按照上述最优采样数量分别对各个bucket中的数据样本进行随机采样为例进行了说明书,在实际应用中,按照上述最优采样数量分别对各个bucket中的数据样本进行采样所采用的具体的采样方式,不限于是随机采样,也可以采用随机采样以外的其它形式的采样方法,在本说明书中不再进行一一列举。
步骤106,进一步调用所述智能合约调用交易包含的近似计算逻辑,基于从所述数据集合中分层采样得到的数据样本进行近似计算,以得到针对所述数据集合的近似计算结果。
在本说明书中,在针对采样得到的数据样本进行近似计算时,可以采用计算发起方指定的计算类型进行近似计算,也可以采用上述智能合约支持的默认计算类型进行近似计算,在本说明书中不进行特别限定。
例如,在示出的一种实施方式中,在上述智能合约调用交易中,还可以包括采样算法ID。该采样算法ID具体可以用于指示计算发起方指定的针对上述数据集合进行近似计算的计算类型。
在这种情况下,在针对采样得到的数据样本进行近似计算时,可以获取该智能合约调用交易中包括的采样算法ID,然后按照该采样算法ID指示的计算类型针对采集得到的数据样本进行近似计算。
当然,如果上述智能合约调用交易不包括上述采样算法ID,也即计算发起方并没有指定的针对上述数据集合进行近似计算的计算类型,也可以基于上述智能合约支持的默认计算类型针对采样得到的样本数据进行近似计算。
需要说明的是,上述近似计算对应的计算类型,在本说明书中不进行特别限定。例如,可以包括求和、求平均值,等等,在本说明书中不再进行一一列举。
在示出的一种实施方式中,上述用于进行近似计算的智能合约,具体还可以是一个部署在区块链节点设备搭载的可信执行环境中的隐私智能合约。
在这种场景下,上述智能合约调用交易中的计算参数,以及获取到的上述数据集合中的数据样本,通常都预先进行了加密处理。区块链节点设备在调用上述智能合约包含的采样逻辑,对获取到与上述数据标识对应的数据集合进行随机采样之前,还可以在该可信执行环境中,对上述计算参数以及对获取到的上述数据集合中的数据样本分别进行解密,并在解密之后,再按照以上描述的随机采样的方法,对上述数据集合中的数据样本进行随机采样,具体过程不再赘述。
例如,在一个例子中,可以为上述可信执行环境分配一对用于对数据进行加解密的非对称密钥对,并将上述非对称密钥的私钥存储在上述可信执行环境中,将上述非对称密钥的公钥发布给上述计算发起方。而上述智能合约调用交易中的计算参数,以及获取到的上 述数据集合中的数据样本,都可以预先基于上述公钥进行加密。区块链节点设备在调用上述智能合约包含的采样逻辑,对获取到与上述数据标识对应的数据集合进行随机采样之前,还可以在该可信执行环境中,使用维护的私钥对上述计算参数以及对获取到的上述数据集合中的数据样本分别进行解密。
在以上技术方案中,在调用智能合约针对数据集合进行近似计算的场景下,通过在智能合约中引入针对该数据集合的分层采样机制,可以在不牺牲近似计算结果的准确度的基础上,降低对该数据集合进行近似计算时的耗时,提高针对该数据集合进行近似计算时的计算效率。
例如,仍以与业务相关的数据集合预先存证在区块链上为例,在智能合约中引入了分层采样机制之后,此时智能合约对与业务相关的数据集合进行计算时的总耗时,通常可以用如下的公式进行表示:
Figure PCTCN2022135402-appb-000007
其中,在上述公式中,n g表示从数据集合中分层采样得到的数据样本的数量。N g表示数据集合中的数据样本的总数量。由于n g的数值与N g的数值相比,通常是数量级的差异,因此智能合约中引入了分层采样机制之后,通过该智能合约对数据集合进行计算时的耗时,也会数量级的减少。
可见,在智能合约中引入了分层采样机制,可以显著的缩短对数据集合进行计算时的耗时,提高针对该数据集合进行近似计算时的计算效率。
与上述方法实施例相对应,本申请还提供了装置的实施例。
本说明书的装置的实施例可以应用在电子设备上。装置实施例可以通过软件实现,也可以通过硬件或者软硬件结合的方式实现。以软件实现为例,作为一个逻辑意义上的装置,是通过其所在电子设备的处理器将非易失性存储器中对应的计算机程序指令读取到内存中运行形成的。
从硬件层面而言,如图3所示,为本说明书的装置所在电子设备的一种硬件结构图,除了图3所示的处理器、内存、网络接口、以及非易失性存储器之外,实施例中装置所在的电子设备通常根据该电子设备的实际功能,还可以包括其他硬件,对此不再赘述。
图4是本说明书一示例性实施例示出的一种基于智能合约的计算装置的框图。
请参考图4,所述基于智能合约的计算装置40可以应用在前述图3所示的电子设备中,所述区块链上部署了用于执行近似计算的智能合约,所述装置40包括:
接收模块401,接收计算发起方发起的针对所述智能合约的智能合约调用交易;其中,所述智能合约调用交易包括与所述近似计算对应的计算参数;所述计算参数包括参与近似计算的数据集合的数据标识;
采样模块402,响应于所述智能合约调用交易,调用所述智能合约调用交易包含的采样逻辑,对与所述数据标识对应的所述数据集合中的数据样本进行分层采样;
计算模块403,进一步调用所述智能合约调用交易包含的近似计算逻辑,基于从所述数据集合中分层采样得到的数据样本进行近似计算,以得到针对所述数据集合的近似计算结果。
在本实施例中,所述装置40还包括:
获取模块404(图4中未示出),在所述采样模块对与所述数据标识对应的所述数据集合中的数据样本进行分层采样之前,获取所述区块链上存证的与所述数据标识对应的数据集合;或者,通过与所述智能合约对应的预言机程序,从与所述区块链对接的链外数据库中获取与所述数据标识对应的数据集合。
在本实施例中,所述计算参数包括与所述近似计算对应的置信概率;以及,与所述近似计算对应的总误差值;所述置信概率表征所述近似计算的准确度;所述智能合约维护了基于霍夫丁不等式推导出的,用于描述与所述近似计算对应的置信概率,与所述近似计算对应的误差值,以及与参与近似计算的数据集合对应的采样数量三者之间的数学关系;
所述采样模块402:
采用最优化求解方法,求解在针对所述数据集合进行分层采样时所需划分出的数据子集的最优数量,以及与划分出的各个数据子集对应的最优误差值;
将与所述近似计算对应的所述置信概率以及与所述各个数据子集对应的所述最优误差值,输入至所述数学关系中进行计算,得到与所述各个数据子集分别对应的最优采样数量;
基于计算出的所述最优数量和所述最优采样数量,对与所述数据标识对应的所述数据集合中的数据样本进行分层采样。
在本实施例中,其中,所述最优化求解方法所采用的约束条件包括:针对各个数据子集对应的误差值进行加权平均计算得到的加权平均误差值最小,并且不大于所述总误差值;
所述采样模块402进一步执行如下步骤:
步骤A,对初始化的i值对应的数值进行调整;
步骤B,将所述数据集合划分为分别包含i个样本数量的若干数据子集;
步骤C,将所述置信概率以及与各个数据子集对应的所述样本数量作为计算参数,输入至所述数学关系中进行计算,得到与所述各个数据子集分别对应的误差值,并对所述各个数据子集对应的误差值进行加权平均计算,得到加权平均误差值;
步骤D,确定所述加权平均误差值是否不大于所述总误差值,并且小于基于本次调整之前的所述i值计算出的所述加权平均误差值;如果否,重新执行以上的步骤A-步骤D,直到计算出的所述加权平均误差值满足所述约束条件时停止迭代,并获取使得所述加权平均误差值满足所述约束条件时的最优i值;
步骤E,基于所述最优i值确定针对所述数据集合进行分层抽样时所需划分出的数据子集的最优数量,并将所述置信概率以及与所述最优i值,输入至所述数学关系中进行计算,得到与所述各个数据子集分别对应的最优误差值。
在本实施例中,所述数学关系利用如下的公式进行表示:
Figure PCTCN2022135402-appb-000008
其中,在上述公式中,n g表示所述采样数量;b g、a g分别表示所述数据集合中的数据样本的最大值和最小值;δ表示所述置信概率;ε g表示所述误差值;N g表示所述数据集合中的数据样本的总数量。
在本实施例中,所述采样模块402进一步:
按照所述最优数量将所述数据集合划分为若干个数据子集;
按照所述最优采样数据分别对各个数据子集中的数据样本进行采样。
在本实施例中,分别对各个数据子集中的数据样本进行采样的方式包括随机采样;
所述采样模块402进一步:
获取用于进行随机采样的随机数;
基于所述随机数分别对各个数据子集中的数据样本进行随机采样,得到与所述最优采样数量对应的数据样本。
在本实施例中,所述采样模块402进一步执行以下示出的任一:
调用所述区块链上部署的随机函数生成用于进行随机采样的随机树;
基于所述节点设备中搭载的可信执行环境中维护的随机数种子,在所述可信执行环境中生成随机数;
从所述智能合约维护的数据相关的数据参数中,获取作为所述随机数种子的目标数据参数,并基于获取到的目标数据参数在所述智能合约中生成用于进行随机采样的随机数;
通过与所述智能合约对应的预言机程序,获取在链外生成的用于进行随机采样的随机数;
通过与所述智能合约对应的预言机程序,获取在链外生成的用于生成随机数的随机数种子,并基于获取到的目标数据参数在所述智能合约中生成用于进行随机采样的随机数;获取所述计算参数中包括的在链外生成的随机数种子,基于所述随机数种子在所述智能合约中生成用于进行随机采样的随机数。在本实施例中,所述计算参数还包括指示所述近似计算对应的计算类型的算法标识;所述计算模块403:
基于从所述数据集合中分层采样得到的数据样本,按照所述算法标识指示的计算类型进行近似计算。
在本实施例中,所述智能合约部署在所述节点设备搭载的可信执行环境中;所述计算参数和所述数据集合中的数据样本预先经过了加密处理;
所述采样模块402进一步:
在对与所述数据标识对应的所述数据集合中的数据样本进行分层采样之前,在所述可信执行环境中对所述计算参数以及对获取到的所述数据集合中的数据样本分别进行解密。
上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机,计算机的具体形式可以是个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件收发设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任意几种设备的组合。
在一个典型的配置中,计算机包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。
内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带、磁盘存储、量子存储器、基于石墨烯的存储介质或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒 体(transitory media),如调制的数据信号和载波。
还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、商品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、商品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、商品或者设备中还存在另外的相同要素。
上述对本说明书特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实施方式中,多任务处理和并行处理也是可以的或者可能是有利的。
在本说明书一个或多个实施例使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本说明书一个或多个实施例。在本说明书一个或多个实施例和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包括多数形式,除非上下文清楚地表示其他含义。还应当理解,本文中使用的术语“和/或”是指并包含一个或多个相关联的列出项目的任何或所有可能组合。
应当理解,尽管在本说明书一个或多个实施例可能采用术语第一、第二、第三等来描述各种信息,但这些信息不应限于这些术语。这些术语仅用来将同一类型的信息彼此区分开。例如,在不脱离本说明书一个或多个实施例范围的情况下,第一信息也可以被称为第二信息,类似地,第二信息也可以被称为第一信息。取决于语境,如在此所使用的词语“如果”可以被解释成为“在……时”或“当……时”或“响应于确定”。
以上所述仅为本说明书一个或多个实施例的较佳实施例而已,并不用以限制本说明书一个或多个实施例,凡在本说明书一个或多个实施例的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本说明书一个或多个实施例保护的范围之内。

Claims (13)

  1. 一种基于智能合约的计算方法,应用于区块链中的节点设备,所述区块链上部署了用于执行近似计算的智能合约,所述方法包括:
    接收计算发起方发起的针对所述智能合约的智能合约调用交易;其中,所述智能合约调用交易包括与所述近似计算对应的计算参数;所述计算参数包括参与近似计算的数据集合的数据标识;
    响应于所述智能合约调用交易,调用所述智能合约调用交易包含的采样逻辑,对与所述数据标识对应的所述数据集合中的数据样本进行分层采样;
    进一步调用所述智能合约调用交易包含的近似计算逻辑,基于从所述数据集合中分层采样得到的数据样本进行近似计算,以得到针对所述数据集合的近似计算结果。
  2. 根据权利要求1所述的方法,所述对与所述数据标识对应的所述数据集合中的数据样本进行分层采样之前,还包括:
    获取所述区块链上存证的与所述数据标识对应的数据集合;或者,
    通过与所述智能合约对应的预言机程序,从与所述区块链对接的链外数据库中获取与所述数据标识对应的数据集合。
  3. 根据权利要求2所述的方法,所述计算参数包括与所述近似计算对应的置信概率;以及,与所述近似计算对应的总误差值;所述置信概率表征所述近似计算的准确度;所述智能合约维护了基于霍夫丁不等式推导出的,用于描述与所述近似计算对应的置信概率,与所述近似计算对应的误差值,以及与参与近似计算的数据集合对应的采样数量三者之间的数学关系;
    对与所述数据标识对应的所述数据集合中的数据样本进行分层采样,包括:
    采用最优化求解方法,求解在针对所述数据集合进行分层采样时所需划分出的数据子集的最优数量,以及与划分出的各个数据子集对应的最优误差值;
    将与所述近似计算对应的所述置信概率以及与所述各个数据子集对应的所述最优误差值,输入至所述数学关系中进行计算,得到与所述各个数据子集分别对应的最优采样数量;
    基于计算出的所述最优数量和所述最优采样数量,对与所述数据标识对应的所述数据集合中的数据样本进行分层采样。
  4. 根据权利要求3所述的方法,其中,所述最优化求解方法所采用的约束条件包括:针对各个数据子集对应的误差值进行加权平均计算得到的加权平均误差值最小,并且不大于所述总误差值;
    采用最优化求解方法,求解在针对所述数据集合进行分层采样时所需划分出的数据子集的最优数量,以及与划分出的各个数据子集对应的最优误差值,包括:
    步骤A,对初始化的i值对应的数值进行调整;
    步骤B,将所述数据集合划分为分别包含i个样本数量的若干数据子集;
    步骤C,将所述置信概率以及调整之后的i值作为计算参数,输入至所述数学关系中进行计算,得到与所述各个数据子集分别对应的误差值,并对所述各个数据子集对应的误差值进行加权平均计算,得到加权平均误差值;
    步骤D,确定所述加权平均误差值是否不大于所述总误差值,并且小于基于本次调整之前的所述i值计算出的所述加权平均误差值;如果否,重新执行以上的步骤A-步骤D,直到计算出的所述加权平均误差值满足所述约束条件时停止迭代,并获取使得所述加权平均误差值满足所述约束条件时的最优i值;
    步骤E,基于所述最优i值确定针对所述数据集合进行分层抽样时所需划分出的数据子集的最优数量,并将所述置信概率以及与所述最优i值,输入至所述数学关系中进行计算,得到与所述各个数据子集分别对应的最优误差值。
  5. 根据权利要求4所述的方法,所述数学关系利用如下的公式进行表示:
    Figure PCTCN2022135402-appb-100001
    其中,在上述公式中,n g表示所述采样数量;b g、a g分别表示所述数据集合中的数据样本的最大值和最小值;δ表示所述置信概率;ε g表示所述误差值;N g表示所述数据集合中的数据样本的总数量。
  6. 根据权利要求3所述的方法,对与所述数据标识对应的所述数据集合中的数据样本进行分层采样,包括:
    按照所述最优数量将所述数据集合划分为若干个数据子集;
    按照所述最优采样数据分别对各个数据子集中的数据样本进行采样。
  7. 根据权利要求6所述的方法,分别对各个数据子集中的数据样本进行采样的方式包括随机采样;
    按照所述最优采样数据分别对各个数据子集中的数据样本进行采样,包括:
    获取用于进行随机采样的随机数;
    基于所述随机数分别对各个数据子集中的数据样本进行随机采样,得到与所述最优采样数量对应的数据样本。
  8. 根据权利要求7所述的方法,所述获取用于进行随机采样的随机数,包括以下示出的任一:
    调用所述区块链上部署的随机函数生成用于进行随机采样的随机树;
    基于所述节点设备中搭载的可信执行环境中维护的随机数种子,在所述可信执行环境中生成随机数;
    从所述智能合约维护的数据相关的数据参数中,获取作为所述随机数种子的目标数据参数,并基于获取到的目标数据参数在所述智能合约中生成用于进行随机采样的随机数;
    通过与所述智能合约对应的预言机程序,获取在链外生成的用于进行随机采样的随机数;
    通过与所述智能合约对应的预言机程序,获取在链外生成的用于生成随机数的随机数种子,并基于获取到的目标数据参数在所述智能合约中生成用于进行随机采样的随机数;获取所述计算参数中包括的在链外生成的随机数种子,基于所述随机数种子在所述智能合约中生成用于进行随机采样的随机数。
  9. 根据权利要求1所述的方法,所述计算参数还包括指示所述近似计算对应的计算类型的算法标识;
    基于从所述数据集合中分层采样得到的数据样本进行近似计算,包括:
    基于从所述数据集合中分层采样得到的数据样本,按照所述算法标识指示的计算类型进行近似计算。
  10. 根据权利要求1所述的方法,所述智能合约部署在所述节点设备搭载的可信执行环境中;所述计算参数和所述数据集合中的数据样本预先经过了加密处理;
    所述对与所述数据标识对应的所述数据集合中的数据样本进行分层采样之前,还包括:
    在所述可信执行环境中对所述计算参数以及对获取到的所述数据集合中的数据样本分别进行解密。
  11. 一种基于智能合约的计算装置,应用于区块链中的节点设备,所述区块链上部署了用于执行近似计算的智能合约,所述装置包括:
    接收模块,接收计算发起方发起的针对所述智能合约的智能合约调用交易;其中,所述智能合约调用交易包括与所述近似计算对应的计算参数;所述计算参数包括参与近似计算的数据集合的数据标识;
    采样模块,响应于所述智能合约调用交易,调用所述智能合约调用交易包含的采样逻辑,对与所述数据标识对应的所述数据集合中的数据样本进行分层采样;
    计算模块,进一步调用所述智能合约调用交易包含的近似计算逻辑,基于从所述数据集合中分层采样得到的数据样本进行近似计算,以得到针对所述数据集合的近似计算结果。
  12. 一种电子设备,包括:
    处理器;
    用于存储处理器可执行指令的存储器;
    其中,所述处理器通过运行所述可执行指令以实现如权利要求1-10中任一项所述的方法的步骤。
  13. 一种计算机可读存储介质,其上存储有计算机指令,该指令被处理器执行时实现如权利要求1-10中任一项所述方法的步骤。
PCT/CN2022/135402 2022-03-30 2022-11-30 基于智能合约的计算、更新、读取方法及装置、电子设备 WO2023185050A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210334257.5 2022-03-30
CN202210334257.5A CN114708096A (zh) 2022-03-30 2022-03-30 基于智能合约的计算、更新、读取方法及装置、电子设备

Publications (1)

Publication Number Publication Date
WO2023185050A1 true WO2023185050A1 (zh) 2023-10-05

Family

ID=82170976

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/135402 WO2023185050A1 (zh) 2022-03-30 2022-11-30 基于智能合约的计算、更新、读取方法及装置、电子设备

Country Status (2)

Country Link
CN (1) CN114708096A (zh)
WO (1) WO2023185050A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117633090A (zh) * 2024-01-26 2024-03-01 粤港澳大湾区数字经济研究院(福田) 基于高性能区块链的数据交互方法、系统、终端及介质

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114708096A (zh) * 2022-03-30 2022-07-05 蚂蚁区块链科技(上海)有限公司 基于智能合约的计算、更新、读取方法及装置、电子设备
CN114693451A (zh) * 2022-03-30 2022-07-01 蚂蚁区块链科技(上海)有限公司 基于智能合约的计算方法及装置、电子设备

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107436954A (zh) * 2017-08-16 2017-12-05 吉林大学 一种在线流数据近似处理质量控制方法及装置
CN107704611A (zh) * 2017-10-20 2018-02-16 同济大学 一种面向大数据聚集分析的近似计算方法
US20200143479A1 (en) * 2018-11-03 2020-05-07 International Business Machines Corporation Detection of abnormal estimates
CN113077260A (zh) * 2021-04-13 2021-07-06 支付宝(杭州)信息技术有限公司 基于区块链的数据访问方法、装置及电子设备
CN114693450A (zh) * 2022-03-30 2022-07-01 蚂蚁区块链科技(上海)有限公司 基于智能合约的计算、更新、读取方法及装置、电子设备
CN114693451A (zh) * 2022-03-30 2022-07-01 蚂蚁区块链科技(上海)有限公司 基于智能合约的计算方法及装置、电子设备
CN114708096A (zh) * 2022-03-30 2022-07-05 蚂蚁区块链科技(上海)有限公司 基于智能合约的计算、更新、读取方法及装置、电子设备

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107436954A (zh) * 2017-08-16 2017-12-05 吉林大学 一种在线流数据近似处理质量控制方法及装置
CN107704611A (zh) * 2017-10-20 2018-02-16 同济大学 一种面向大数据聚集分析的近似计算方法
US20200143479A1 (en) * 2018-11-03 2020-05-07 International Business Machines Corporation Detection of abnormal estimates
CN113077260A (zh) * 2021-04-13 2021-07-06 支付宝(杭州)信息技术有限公司 基于区块链的数据访问方法、装置及电子设备
CN114693450A (zh) * 2022-03-30 2022-07-01 蚂蚁区块链科技(上海)有限公司 基于智能合约的计算、更新、读取方法及装置、电子设备
CN114693451A (zh) * 2022-03-30 2022-07-01 蚂蚁区块链科技(上海)有限公司 基于智能合约的计算方法及装置、电子设备
CN114708096A (zh) * 2022-03-30 2022-07-05 蚂蚁区块链科技(上海)有限公司 基于智能合约的计算、更新、读取方法及装置、电子设备

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117633090A (zh) * 2024-01-26 2024-03-01 粤港澳大湾区数字经济研究院(福田) 基于高性能区块链的数据交互方法、系统、终端及介质
CN117633090B (zh) * 2024-01-26 2024-04-12 粤港澳大湾区数字经济研究院(福田) 基于高性能区块链的数据交互方法、系统、终端及介质

Also Published As

Publication number Publication date
CN114708096A (zh) 2022-07-05

Similar Documents

Publication Publication Date Title
WO2023185050A1 (zh) 基于智能合约的计算、更新、读取方法及装置、电子设备
WO2023185052A1 (zh) 基于智能合约的计算、更新、读取方法及装置、电子设备
WO2023185057A1 (zh) 基于智能合约的计算方法及装置、电子设备
US11956357B2 (en) Traceable key block-chain ledger
TWI735820B (zh) 資產管理方法及裝置、電子設備
WO2021047535A1 (en) Method, apparatus and system for secure vertical federated learning
US10733176B2 (en) Detecting phantom items in distributed replicated database
CN110135986B (zh) 一种基于区块链智能合约实现的可搜索加密文件数据方法
US20190205563A1 (en) User controlled storage and sharing of personal user information on a blockchain
US10789085B2 (en) Selectively providing virtual machine through actual measurement of efficiency of power usage
EP3853792A1 (en) Advanced smart contract with decentralized ledger in a multi-tenant environment
US10715321B2 (en) Physical unclonable function using message authentication code
US20230052525A1 (en) Complex composite tokens
WO2018233051A1 (zh) 数据发布方法、装置、服务器和存储介质
WO2022174533A1 (zh) 基于自组织集群的联邦学习方法、装置、设备及存储介质
WO2021208758A1 (zh) 数据权限管理
WO2020024650A1 (zh) 数据处理方法和装置、客户端
Keller et al. Balancing quality and efficiency in private clustering with affinity propagation
US11704150B2 (en) Systems and methods for dynamic job performance in secure multiparty computation
WO2023207087A1 (zh) 用于区块链的最优链路选择方法及装置和电子设备
WO2024021417A1 (zh) 数据账户创建方法及装置
US11907347B2 (en) System for secure verification of authentication data using quantum computing and a distributed server network
TW202008230A (zh) 事件預測方法及裝置、電子設備
US11321206B2 (en) Cluster feature activation and update system
WO2021127035A1 (en) Token processing to facilitate storage of transaction data in a blockchain

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22934868

Country of ref document: EP

Kind code of ref document: A1