A method for storing IoT data based on blockchain smart contracts

Through the prediction function, match number issuer and validator of blockchain smart contract, the correlation relationship between hash value and match number is used to solve the high cost problem caused by frequent evidence storage of IoT data, and efficient and low-frequency data evidence storage and verification are achieved.

CN114266074BActive Publication Date: 2025-08-12ZHEJIANG DIGITAL QIN TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202111312340.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-08
Publication Date
2025-08-12
Estimated Expiration
2041-11-08

AI Technical Summary

Technical Problem

In the prior art, when IoT data needs to be continuously stored, it leads to the problem of high cost of blockchain evidence storage.

Method used

Using a blockchain smart contract method, the data proof is verified by using the arithmetic function, match number issuer and validator through the arithmetic relationship between hash value and match number, avoiding permanently storing the data hash value on the blockchain, and only storing a small amount of data on the blockchain and verifying the authenticity of the data through the smart contract.

Benefits of technology

It reduces the frequency and cost of IoT data storage, reduces the burden on blockchain, provides proof of data authenticity, and provides efficient and accurate verification process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114266074B_ABST
    Figure CN114266074B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of blockchain technology, and more particularly to a method for storing IoT data based on blockchain smart contracts, comprising: publishing a smart contract on a blockchain, the smart contract comprising a prophecy function, a matching number issuer, and a verifier, the matching number issuer receiving a hexadecimal number sent by a data node, substituting the result into the prophecy function, and feeding back the output of the prophecy function to the data node as a matching number; the IoT data node periodically generates data to be stored, extracts a hash value of the data to be stored, sends the hash value to the matching number issuer, and obtains a matching number fed back by the matching number issuer; the data to be stored is associated with the hash value and the matching number and stored; when verifying the stored data, the hash value and the matching number are sent to the verifier, the verifier substitutes the hash value into the prophecy function, and if the output of the prophecy function is the same as the matching number, the feedback indicates that the verification is successful. The substantial effect of the present invention is that a new blockchain data storage solution is provided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of blockchain technology, and in particular to a method for storing IoT data based on blockchain smart contracts. Background Art

[0002] Blockchain is a distributed, shared ledger. The data recorded on it is immutable, traceable, traceable, and transparent. These characteristics ensure the integrity and transparency of blockchain and lay the foundation for building trust. Blockchain's diverse application scenarios are largely based on its ability to resolve information asymmetry, enable collaborative trust and concerted action among multiple entities, and reduce the cost of trust. For example, this is reflected in the storage of electronic data. While electronic data is easy to store and transmit, it also has the disadvantage of being susceptible to tampering. With the development of IoT technology, a large amount of environmental monitoring and equipment transportation data is being collected. Using blockchain to store this IoT data ensures that it is immutable, authentic, and reliable, offering broad application prospects. However, the numerous data nodes in the IoT generate data constantly, placing significant computing and bandwidth pressure on the blockchain. Uploading data to the blockchain incurs fees. Currently, data storage involves uploading the data's hash value to the blockchain, making the cost of a single storage session relatively low. However, when storage is required on an ongoing basis, it still imposes financial costs on IoT companies. Therefore, it is necessary to research a technology that can reduce the frequency of data being uploaded to the chain while providing the required proof of authenticity.

[0003] Chinese patent CN112954039A, published on June 11, 2021, discloses a blockchain evidence storage method. The client generates a client verification code based on a preset calculation, taking as input a key, a client random number, a server random number, a client identifier, a server identifier, target data, and address information. The server generates a server verification code based on a preset calculation, taking as input a key, a client random number, a server random number, a client identifier, a server identifier, target data, and address information. If the server verifies that the client verification code and the server authentication code are equal, the server writes the evidence parameters, the client identifier, the server identifier, the address information, the client random number, the server random number, and the client verification code to the blockchain. This method has the advantage of only uploading the evidence identifier, the client identifier, the server identifier, the address information, the client random number, the server random number, and the client verification code to the blockchain. Even if a large amount of data needs to be stored, this method does not require extensive on-chain uploading and storage costs. However, this method does not address the cost associated with the continuous storage of IoT data. Summary of the Invention

[0004] This invention addresses the current lack of blockchain-based evidence storage methods that can reduce the frequency of data uploads. This paper proposes an IoT data evidence storage method based on blockchain smart contracts. This method utilizes smart contracts to store and verify data, eliminating the need to permanently store the data's hash value on the blockchain and providing a different approach to data evidence storage.

[0005] To solve the above technical problems, the technical solution adopted by the present invention is: a method for storing IoT data based on blockchain smart contracts, publishing a smart contract on the blockchain, the smart contract including a prophecy function, a matching number issuer and a verifier, the input number of the prophecy function is a hexadecimal number, the output of the prophecy function is a numerical value, the matching number issuer receives the hexadecimal number sent by the data node, substitutes it into the prophecy function, and feeds back the output of the prophecy function as the matching number to the data node; the data node of the IoT periodically generates data to be stored, extracts the hash value of the data to be stored, sends the hash value to the matching number issuer, and obtains the matching number fed back by the matching number issuer; the data to be stored is associated with the hash value and the matching number and stored to complete the storage of the expected data to be stored this week; when verifying the stored data, the hash value and the matching number are sent to the verifier, and the verifier substitutes the hash value into the prophecy function. If the output of the prophecy function is the same as the matching number, the feedback verification is passed, otherwise, the feedback verification fails.

[0006] Preferably, the oracle function is a polynomial with an input number as an independent variable, and the smart contract periodically replaces the oracle function. The method of replacing the oracle function includes: recording the coefficients of the polynomial terms to form a coefficient vector, and saving the coefficient vector in association with a timestamp; generating random numbers as the coefficients of the new polynomial terms; when verifying the data, submitting the timestamp of the data storage at the same time, and the verifier obtains the oracle function corresponding to the data storage according to the timestamp for verification.

[0007] Preferably, the data node sends the last N digits of the hash value to a matching number issuer, obtains the matching number corresponding to the last N digits of the hash value, stores the data to be stored in association with the hash value and the matching number, and when verifying the stored data, sends the last N digits of the hash value and the matching number to the verifier. The verifier substitutes the hash value into the prediction function. If the output of the prediction function is the same as the matching number, the feedback verification passes; otherwise, the feedback verification fails.

[0008] Preferably, the input of the oracle function includes an input number and a timestamp, the oracle function is the sum of a polynomial term and a timestamp term, the polynomial term is a polynomial of the input number, the timestamp term is the product of the difference between the timestamp and the starting timestamp and a weight, the weight is greater than the maximum value of the value range of the polynomial term, the data node sends the last N bits of the timestamp and hash value to the matching number issuer, the matching number issuer verifies whether the difference between the timestamp and the current time is less than a preset threshold, if the timestamp difference is less than the preset threshold, the matching number issuer substitutes the timestamp and the last N bits of the hash value submitted by the data node into the oracle function to obtain the matching number feedback by the matching number issuer, if the timestamp difference is not less than the preset threshold, no operation is performed.

[0009] Preferably, the smart contract includes multiple oracle functions, the matching number issuer receives the hexadecimal number sent by the data node, substitutes it into several oracle functions respectively, obtains the output of several oracle functions, and feeds back the minimum value of the output of several oracle functions to the data node as the matching number. When verifying the stored data, the hash value and the matching number are sent to the verifier, and the verifier substitutes the hash value into several oracle functions to obtain the output of several oracle functions. If the minimum value among the outputs of the oracle functions is the same as the matching number, the feedback verification is passed; otherwise, the feedback verification fails.

[0010] The substantial effect of the present invention is that when multiple data nodes perform evidence storage, the oracle function used is the same, so only the oracle function needs to be stored. When verifying data, the verification data node can provide the correct matching number corresponding to the hash value and the oracle function. Because the oracle function is confidential, the matching number can only be issued by the smart contract. If the data has been tampered with, the hash value of the tampered data, for example, no longer satisfies the corresponding relationship with the matching number, and the probability that the matching numbers between different data nodes are the same is extremely low. Therefore, it can be proved that the data with the correct matching number has not been tampered with. This method of storage does not require adding new data to the blockchain to complete the evidence storage, and provides a new blockchain data evidence storage solution. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] Figure 1 This is a flow chart of the method for storing IoT data in Example 1.

[0012] Figure 2 Schematic diagram of the method for periodically replacing the oracle function in Example 1.

[0013] Figure 3 This is a schematic diagram of data evidence storage in Example 1.

[0014] Among them: 10. Data to be recorded, 20. Record mark. DETAILED DESCRIPTION

[0015] The specific implementation of the present invention will be further described below with reference to specific embodiments and in conjunction with the accompanying drawings.

[0016] Example 1:

[0017] A method for storing IoT data based on blockchain smart contracts, please refer to the attached Figure 1 , including: step A01) publishing a smart contract on the blockchain, the smart contract including a prophecy function, a matching number issuer and a verifier, the input number of the prophecy function is a hexadecimal number, the output of the prophecy function is a numerical value, the matching number issuer receives the hexadecimal number sent by the data node, substitutes it into the prophecy function, and feeds back the output of the prophecy function as the matching number to the data node; step A02) the data node of the Internet of Things periodically generates data 10 to be stored, extracts the hash value of the data 10 to be stored, sends the hash value to the matching number issuer, and obtains the matching number fed back by the matching number issuer; step A03) the data 10 to be stored is associated with the hash value and the matching number for storage, completing the storage of the data 10 expected to be stored this week; step A04) when verifying the stored data, the hash value and the matching number are sent to the verifier, and the verifier substitutes the hash value into the prophecy function. If the output of the prophecy function is the same as the matching number, the feedback verification is passed, otherwise, the feedback verification fails.

[0018] The oracle function is a polynomial with the input number as the independent variable. The smart contract periodically changes the oracle function. Please refer to the attached Figure 2 The method for replacing an oracle function includes: step B01) recording the coefficients of the polynomial terms to form a coefficient vector, and storing the coefficient vector in association with a timestamp; step B02) generating random numbers as the coefficients of the new polynomial terms; and step B03) submitting the timestamp of the data storage when verifying the data. The verifier obtains the oracle function corresponding to the data storage based on the timestamp and performs verification. Because each blockchain node in a blockchain generates different random values when executing random numbers, this can lead to discrepancies in smart contract execution on different blockchain nodes, causing errors in smart contract execution. Therefore, a better oracle function solution should be executed on a blockchain that has already published a smart contract for random number generation. The random number generating smart contract uses the random number generated by the earliest executed blockchain node as the basis, unifying the execution results of the smart contract and achieving random number generation. Smart contracts on the blockchain can call each other. Although smart contracts are Turing complete and theoretically support any operation, a more optimal execution solution is to re-publish a new smart contract after a period of time, attach a new oracle function to the new smart contract, and send the address of the new smart contract to the data node. The advantage of such execution is that smart contracts are less prone to errors when executed on the blockchain.

[0019] Unlike existing techniques, which upload the data's hash value to the blockchain for storage, verifying whether the data's hash value matches the hash value stored on the blockchain verifies whether the data has been tampered with. The technical solution provided by this embodiment permanently stores the matching relationship between the data's hash value and the matching number on the blockchain. This matching relationship remains the same for all data 10 to be stored within a certain period of time, requiring only a small amount of data to be stored on the blockchain. In storage, the data's hash value is no longer uploaded to the blockchain; instead, the same matching relationship is established for the new data 10 to be stored. However, data tampering will cause the data's hash value to change, thereby destroying the matching relationship between the hash value and the matching number. Verification through smart contracts can conveniently provide verification results. The oracle function provided in this embodiment is a polynomial function: matching number = a0 + a1 * hash value + a2 * hash value^2 + ... + n * hash value^n. a0 to an are randomly generated coefficients. To avoid an excessively large matching number, a0 to an can be set to smaller values, or the hash value can be divided by a preset constant before performing the polynomial calculation. The same calculation process is performed when generating the matching number and verifying the matching number.

[0020] Table 1 Smart contract structure used in this example

[0021] Smart contract address: 0x962…5AC Prediction function: Match number = 58CAF9*hash value^3-F8DC67*hash value^2-79B37D*hash value+B730 Match number distributor execution code segment Validator execution code snippet Hash value receiving address: URL_IN1: 236.35.12.05:260 / in1.jsp Match number output address: URL_OUT1: filled in by the requested data node Hash value and match number receiving address: URL_IN1: 236.35.12.05:260 / in2.jsp Verification result output address: URL_OUT2: filled in by the requester

[0022] As shown in Table 1, a smart contract is a piece of executable code stored on the blockchain. Due to the immutability of the blockchain, smart contracts are always executed according to the code at the time of publication. The current blockchain generally supports smart contracts, and fees will also be incurred during the execution of smart contracts, but the fees are different from storing data on the blockchain. As the blockchain runs, more and more data will be stored on the blockchain, which will eventually lead to higher and higher costs for fixing data on the blockchain. This embodiment only requires a small amount of data to be stored on the blockchain in the initial stage. When the evidence is subsequently stored, no new data that needs to be stored on the blockchain will be generated each time the evidence is stored. Therefore, it is more suitable for the storage of IoT data on the blockchain. Because the IoT not only has a large amount of data, but also sensors, equipment monitors, etc., which continuously generate data all the time. The solution of this embodiment can reduce the burden on the blockchain. Only part of the computing power on the blockchain needs to be consumed to complete the evidence storage. Please refer to the attached Figure 3After the attested data 10 is stored, only a small amount of local storage space is required. For example, in this embodiment, a periodic attestation tag 20 is created after the data in the storage space to store the hash value, match count, and timestamp of the attested data 10. The data stored in the IoT rarely needs to be verified for tampering. Therefore, permanently storing data on the blockchain is not cost-effective for the storage resources of blockchain nodes. Most of the stored data that does not require verification consumes only a small amount of computing power on the blockchain before and after storage, and then there is no further burden, reducing the consumption of blockchain resources.

[0023] The data node sends the last N digits of the hash value to the match number issuer, obtains the match number corresponding to the last N digits of the hash value, and stores the data to be stored in association with the hash value and the match number. When verifying the stored data, the last N digits of the hash value and the match number are sent to the verifier. The verifier substitutes the hash value into the oracle function. If the output of the oracle function is the same as the match number, the feedback verification passes; otherwise, the feedback verification fails. Hash values generated by hash algorithms vary in length. For example, SHA256 generates a 256-bit hexadecimal number. Directly using this value in the oracle function calculation results in an excessively large number of operations, reducing computational efficiency. Therefore, this embodiment provides a solution that uses the last N digits of the hash value in the oracle function calculation. When N is 10, the oracle function calculation involves a 10-digit hexadecimal number, i.e., 2^40, which is within the range of values representable in the data format bigint. This facilitates direct computational compatibility across various systems. After data tampering, the probability that the last 10 digits of the hash value remain unchanged is 1 / 16^10, which is still an extremely small probability.

[0024] The oracle function takes as input the input number and a timestamp. The oracle function is the sum of a polynomial term and a timestamp term. The polynomial term is a polynomial of the input number, and the timestamp term is the product of the difference between the timestamp and the starting timestamp and a weight. The weight is greater than the maximum value of the polynomial term's range. The data node sends the timestamp and the last N bits of the hash value to the match number issuer. The match number issuer verifies whether the difference between the timestamp and the current time is less than a preset threshold. If the timestamp difference is less than the preset threshold, the match number issuer substitutes the timestamp and the last N bits of the hash value submitted by the data node into the oracle function to obtain the match number returned by the match number issuer. If the timestamp difference is not less than the preset threshold, no action is taken. Smart contracts are published on the blockchain after being converted into binary machine code. Therefore, the disclosure of smart contracts does not mean the disclosure of the code, which effectively keeps the oracle function confidential. By associating the timestamp, the match number naturally contains the timestamp information, providing more information and improving the credibility of the data. Hash values are hexadecimal numbers and are relatively large. Normalizing the hash value yields the maximum possible value of the polynomial. For example, the maximum possible value of 9*normalized hash value^2 - 8*normalized hash value + 3 is 4, so a weight of 5 is sufficient. In other words, the number of matches = 4*timestamp + 9*normalized hash value^2 - 8*normalized hash value + 3. The normalized hash value has many decimal places, so you can choose the number of decimal places you want to retain.

[0025] The smart contract includes multiple oracle functions. The match number issuer receives the hexadecimal number sent by the data node and substitutes it into several oracle functions to obtain the outputs of several oracle functions. The minimum value of the outputs of several oracle functions is fed back to the data node as the match number. When verifying the stored data, the hash value and the match number are sent to the validator. The validator substitutes the hash value into several oracle functions to obtain the outputs of several oracle functions. If the minimum value of the oracle function output is the same as the match number, the feedback verification passes; otherwise, the feedback verification fails. The smart contract contains multiple oracle functions, and the minimum value obtained from each calculation is fed back to the data node as the final match value, making the match number more irregular. Even if it runs for a long time and generates a large number of hash value matching pairs, it is difficult to reverse-infer the accurate oracle function.

[0026] The beneficial technical effect of this embodiment is that when multiple data nodes perform evidence storage, the oracle function used is the same, so only the oracle function needs to be stored. When verifying data, the verification data node can provide the correct matching number corresponding to the hash value and the oracle function. Because the oracle function is confidential, the matching number can only be issued by the smart contract. If the data has been tampered with, the hash value of the tampered data, for example, no longer satisfies the corresponding relationship with the matching number, and the probability of the matching numbers between different data nodes being the same is extremely low. Therefore, it can be proved that the data with the correct matching number has not been tampered with. This method of storage does not require adding new data to the blockchain to complete the evidence storage, and provides a new blockchain data evidence storage solution.

[0027] The above embodiment is only a preferred solution of the present invention and does not limit the present invention in any form. Other variations and modifications are possible without exceeding the technical solution described in the claims.

Claims

1. A method for storing IoT data based on blockchain smart contracts. It is characterized by: include: Publishing a smart contract on the blockchain, the smart contract includes a prophecy function, a matching number issuer, and a verifier. The input number of the prophecy function is a hexadecimal number, and the output of the prophecy function is a numerical value. The matching number issuer receives the hexadecimal number sent by the data node, substitutes it into the prophecy function, and feeds back the output of the prophecy function as the matching number to the data node; The data nodes of the Internet of Things periodically generate data to be stored, extract the hash value of the data to be stored, send the hash value to the matching number issuer, and obtain the matching number fed back by the matching number issuer; The data to be stored is associated with the hash value and the matching number, completing the storage of the data expected to be stored this week; When verifying the stored data, the hash value and the number of matches are sent to the verifier. The verifier substitutes the hash value into the oracle function. If the output of the oracle function is the same as the number of matches, the feedback verification passes. Otherwise, the feedback verification fails. The data node sends the last N digits of the hash value to the matching number issuer, obtains the matching number corresponding to the last N digits of the hash value, associates the hash value and the matching number with the data to be stored, and sends the last N digits of the hash value and the matching number to the verifier when verifying the stored data. The verifier substitutes the hash value into the oracle function. If the output of the oracle function is the same as the matching number, the feedback verification passes; otherwise, the feedback verification fails. The input of the oracle function includes an input number and a timestamp. The oracle function is the sum of a polynomial term and a timestamp term. The polynomial term is a polynomial of the input number. The timestamp term is the product of the difference between the timestamp and the starting timestamp and the weight. The weight is greater than the maximum value of the value range of the polynomial term. The data node sends the last N bits of the timestamp and hash value to the matching number issuer. The matching number issuer verifies whether the difference between the timestamp and the current time is less than a preset threshold. If the timestamp difference is less than the preset threshold, the matching number issuer substitutes the timestamp and the last N bits of the hash value submitted by the data node into the oracle function to obtain the matching number fed back by the matching number issuer. If the timestamp difference is not less than the preset threshold, no operation is performed.

2. The method for storing IoT data based on blockchain smart contracts according to claim 1, characterized in that: The oracle function is a polynomial with an input number as an independent variable. The smart contract periodically changes the oracle function. The method of changing the oracle function includes: Record the coefficients of the polynomial to form a coefficient vector, and save the coefficient vector in association with the timestamp; Generate random numbers as coefficients of new polynomials; When verifying data, the timestamp of the data storage is submitted at the same time. The verifier obtains the corresponding oracle function when the data is stored according to the timestamp and performs verification.

3. The method for storing IoT data based on blockchain smart contracts according to claim 1 is characterized in that: The smart contract includes multiple oracle functions. The matching number issuer receives the hexadecimal number sent by the data node, substitutes it into several oracle functions respectively, obtains the output of several oracle functions, and feeds the minimum value of the output of several oracle functions as the matching number back to the data node. When verifying the stored data, the hash value and the number of matches are sent to the verifier. The verifier substitutes the hash value into several oracle functions to obtain the outputs of several oracle functions. If the minimum value among the outputs of the oracle functions is the same as the number of matches, the feedback verification passes; otherwise, the feedback verification fails.

Citation Information

Patent Citations

  • Block chain evidence storage method

    CN112954039A

  • Method for preventing network attack performed by using legal data or tampering legal data

    CN108494775A

  • Electronic evidence management method and device

    CN111428278A