A blockchain-based food traceability method and system

By leveraging blockchain technology and the SHA-256 algorithm, the problems of information silos and data inconsistencies in food traceability systems have been solved. This enables real-time and reliable tracking of food status and real-time updates of dynamic shelf life, enhancing the traceability of consumer feedback and improving the reliability of traceability information and the closed-loop management capability of the supply chain.

CN121073510BActive Publication Date: 2026-05-05FOSHAN POLYTECHNIC +1
View PDF 3 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
FOSHAN POLYTECHNIC
Filing Date
2025-11-06
Publication Date
2026-05-05

AI Technical Summary

Technical Problem

In existing food traceability systems, due to the large number of participants in the supply chain and the complexity of data sources, information is difficult to share in real time between different links, resulting in serious problems of information silos and data inconsistencies, and consumers cannot obtain timely and accurate information about the status of food.

Method used

By using blockchain technology, the system calculates the dynamic shelf life by obtaining the batch number, production date, transportation temperature, and storage humidity of food products. It also uses the SHA-256 algorithm to generate tamper-proof hash values, enabling real-time and reliable tracking and synchronization of food status, and generating a reliable QR code for consumers to query.

Benefits of technology

It enables real-time and reliable tracking of food status, real-time updates of dynamic shelf life, enhances the traceability of consumer feedback, improves the reliability of traceability information, and enhances the closed-loop management capability of the supply chain.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121073510B_ABST
    Figure CN121073510B_ABST
Patent Text Reader

Abstract

This invention relates to the field of blockchain food traceability technology, and discloses a blockchain-based food traceability method and system, comprising: timestamping batch number, production date, transportation temperature, and storage humidity, and calculating dynamic shelf life to generate traceability records; encrypting the batch number and dynamic shelf life to generate tamper-proof hash values; generating food status records by combining the hash values ​​when temperature and humidity exceed thresholds; synchronizing the food status records to supply chain nodes and performing consistency verification to obtain a shared dataset; generating a trusted QR code containing batch number, dynamic shelf life, and circulation records based on the shared dataset; performing verification after the consumer scans the code, extracting the shelf life field and circulation information summary, and comparing the dynamic shelf life with the current time to generate a user interface; extracting consumer feedback and verifying batch matching through timestamps to generate a food traceability report. This invention can reflect the food status in real time and prevent data tampering, improving the credibility of traceability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of blockchain food traceability technology, and in particular to a blockchain-based food traceability method and system. Background Technology

[0002] Currently, food traceability plays a crucial role in ensuring food safety and enhancing consumer trust. Its core lies in achieving traceability of food from production to consumption through transparent supply chain information, thereby ensuring quality and safety. However, in practical applications, due to the large number of participants in the supply chain and the complexity of data sources, traditional traceability methods generally rely on centralized databases. This makes it difficult to share information in real time between different stages, leading to information gaps between upstream and downstream of the supply chain and failing to comprehensively reflect the status of food at each stage of production, transportation, and sales.

[0003] In one existing technology, some systems record food batch information, production dates, and transportation data through a centralized management platform, and provide consumers with QR code query services. Consumers can scan the QR code to view basic traceability information of the food, such as the manufacturer and major transportation nodes. However, this type of method usually only records the initial shelf life and fixed distribution information, lacking real-time tracking and synchronization of dynamic changes during transportation and storage (such as shortened shelf life due to abnormal temperatures), resulting in traceability data that cannot accurately reflect the actual condition of the food during the distribution process.

[0004] Existing technologies suffer from information silos and data inconsistencies, making it difficult to guarantee the reliability and real-time nature of data when multiple parties are involved, resulting in consumers being unable to obtain timely and accurate information about the status of food. Summary of the Invention

[0005] This invention provides a blockchain-based food traceability method and system to solve the problems of information silos and data inconsistencies in existing technologies, and to achieve real-time and reliable tracking of food status.

[0006] Firstly, in order to solve the above-mentioned technical problems, the present invention provides a blockchain-based food traceability method, comprising:

[0007] The batch number, production date, transportation temperature and storage humidity of the food are obtained, and blockchain timestamp processing is performed to generate food processing data. The dynamic shelf life is calculated according to the preset shelf life calculation rules, and the food processing data and the dynamic shelf life are combined to form a food traceability record.

[0008] The batch number and dynamic shelf life in the food traceability record are encrypted using the SHA-256 algorithm to generate a tamper-proof hash value.

[0009] When the transportation temperature in the food traceability record is greater than a preset temperature threshold or the storage humidity data is greater than a preset humidity threshold, the dynamic shelf life is updated by combining the anti-tampering hash value and a new anti-tampering hash value is generated by encryption to obtain the food status record.

[0010] The food status records are synchronized to each supply chain node, and the consistency of batch number and shelf life is checked to obtain a shared food status dataset.

[0011] Based on the shared food status dataset, a reliable QR code containing batch number, dynamic shelf life, and circulation record is generated, resulting in a QR code image for consumers to scan.

[0012] If a consumer scans the QR code image, a validity and completeness comparison is performed based on the shared food status dataset to obtain the shelf life field and a summary of circulation information.

[0013] Based on the shelf-life field and the circulation information summary, the dynamic shelf-life is compared with the current time to determine whether the food is in an expiration state, and the expiration state, the shelf-life field, and the circulation information summary are combined to generate a user interface;

[0014] Based on the user interface, consumer feedback and evaluation are extracted and batch matching is verified by combining preset timestamps to obtain reliable feedback records.

[0015] Based on the trusted feedback records, the shared food status dataset is updated and synchronized to each supply chain node to generate a final food traceability report containing batch numbers and circulation information summaries.

[0016] Secondly, the present invention provides a blockchain-based food traceability system, comprising:

[0017] The data acquisition module acquires the batch number, production date, transportation temperature and storage humidity of the food, performs blockchain timestamp processing to generate food processing data, calculates the dynamic shelf life according to the preset shelf life calculation rules, and combines the food processing data and the dynamic shelf life to form a food traceability record.

[0018] The encryption generation module uses the SHA-256 algorithm to encrypt the batch number and dynamic shelf life in the food traceability record to generate a tamper-proof hash value.

[0019] The food status module is used to update the dynamic shelf life and encrypt and generate a new anti-tampering hash value when the transportation temperature in the food traceability record is greater than a preset temperature threshold or the storage humidity data is greater than a preset humidity threshold, thereby obtaining the food status record.

[0020] The shared data module is used to synchronize the food status records to each supply chain node, and to determine the consistency of batch number and shelf life to obtain a shared food status dataset.

[0021] The data integration module is used to generate a reliable QR code containing batch number, dynamic shelf life and circulation record based on the shared food status dataset, so as to obtain a QR code image for consumers to scan.

[0022] The status verification module is used to perform a validity and completeness comparison based on the shared food status dataset if a consumer scans and queries the QR code image, and obtain the shelf life field and circulation information summary.

[0023] The user interaction module is used to compare the dynamic shelf life with the current time based on the shelf life field and the circulation information summary to determine whether the food is in an expiration state, and to combine the expiration state, the shelf life field and the circulation information summary to generate a user interaction interface;

[0024] The trusted feedback module is used to extract consumer feedback and evaluation based on the user interaction interface and verify batch matching by combining a preset timestamp to obtain trusted feedback records.

[0025] The food traceability module is used to update the shared food status dataset and synchronize it to each supply chain node based on the trusted feedback records, generating a final food traceability report containing batch numbers and circulation information summaries.

[0026] Thirdly, the present invention also provides an electronic device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor executes the computer program to implement the blockchain-based food traceability method described in any one of the above.

[0027] Fourthly, the present invention also provides a computer-readable storage medium comprising a stored computer program, wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to execute any of the above-described blockchain-based food traceability methods.

[0028] Compared with the prior art, the present invention has the following beneficial effects:

[0029] (1) This invention effectively solves the problem of data inconsistency among multiple nodes in the supply chain. In existing food traceability systems, data between different nodes often becomes asynchronous due to differences in their storage and update mechanisms, leading to delays or even conflicts in the information retrieved by consumers. This solution stores the same traceability data at each node and uses hash values ​​for consistency comparison, enabling multiple nodes to quickly confirm data consistency after updates, thereby improving the reliability of traceability information. Since the data undergoes consistency verification, even if a subsequent node fails individually, it will not affect the credibility of the overall traceability chain.

[0030] (2) This invention enables real-time updating and reliable display of dynamic shelf-life. Traditional traceability methods are mostly based on static shelf-life. Once the transportation or storage environment changes, consumers cannot promptly know the true remaining shelf life. This solution introduces dynamic shelf-life calculation and adjusts it in real time when temperature or humidity exceeds limits. Simultaneously, this dynamic information is linked to a QR code, allowing consumers to directly see the latest status when scanning the code. This mechanism avoids misleading information caused by asynchronous environmental changes, helping consumers make more rational purchasing and consumption decisions.

[0031] (3) This invention enhances the value and traceability of consumer feedback in the traceability system. Most existing systems only provide one-way production-to-consumption information and lack effective utilization of consumer feedback. This solution binds consumer ratings and reviews to batch numbers via timestamps and writes them to the blockchain after consistency verification, achieving reliable traceability of feedback data. This not only helps supply chain participants understand the end-user experience and optimize production and transportation processes, but also provides transparent data support for regulatory authorities, thereby improving the closed-loop management capability of the entire traceability system.

[0032] (4) Through the dynamic shelf life update mechanism, whenever the dynamic shelf life is adjusted due to changes in environmental conditions, the system will recalculate the batch number and the hash value of the updated dynamic shelf life, and write the new tamper-proof hash value into the blockchain distributed ledger. This ensures that the latest valid hash value is always used in subsequent verification, avoiding the problem of verification failure caused by data updates. Attached Figure Description

[0033] Figure 1 This is a schematic diagram of the blockchain-based food traceability method provided in the first embodiment of the present invention;

[0034] Figure 2 This is a schematic diagram of the structure of a blockchain-based food traceability system provided in the second embodiment of the present invention. Detailed Implementation

[0035] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0036] Reference Figure 1 The first embodiment of the present invention provides a blockchain-based food traceability method, comprising the following steps:

[0037] S11: Obtain the batch number, production date, transportation temperature and storage humidity of the food, perform blockchain timestamp processing, generate food processing data, calculate the dynamic shelf life according to the preset shelf life calculation rules, and combine the food processing data and the dynamic shelf life to form a food traceability record.

[0038] S12, the batch number and dynamic shelf life in the food traceability record are encrypted using the SHA-256 algorithm to generate a tamper-proof hash value;

[0039] S13, when the transportation temperature in the food traceability record is greater than the preset temperature threshold or the storage humidity data is greater than the preset humidity threshold, the dynamic shelf life is updated by combining the anti-tampering hash value and a new anti-tampering hash value is generated by encryption to obtain the food status record.

[0040] S14, synchronize the food status record to each supply chain node, and determine the consistency of batch number and shelf life to obtain a shared food status dataset;

[0041] S15, Based on the shared food status dataset, generate a reliable QR code containing batch number, dynamic shelf life and circulation record, and obtain a QR code image for consumers to scan;

[0042] S16, if a consumer scans and queries the QR code image, then a validity and completeness comparison is performed based on the shared food status dataset to obtain the shelf life field and circulation information summary;

[0043] S17. Based on the shelf life field and the circulation information summary, compare the dynamic shelf life with the current time to determine whether the food is in an expiration state, and combine the expiration state, the shelf life field and the circulation information summary to generate a user interface.

[0044] S18. Based on the user interaction interface, extract consumer feedback and evaluation and verify batch matching by combining preset timestamps to obtain reliable feedback records.

[0045] S19, based on the trusted feedback record, update the shared food status dataset and synchronize it to each supply chain node to generate a final food traceability report containing batch number and circulation information summary.

[0046] In step S11, it is necessary to obtain the batch number, production date, transportation temperature, and storage humidity of the food, and perform blockchain timestamp processing to generate food processing data. The dynamic shelf life is calculated according to preset shelf life calculation rules, and the food processing data and the dynamic shelf life are combined to form a food traceability record, including:

[0047] In step S11, the system needs to acquire the food batch number, production date, transportation temperature, and storage humidity. It then performs blockchain timestamp processing on these data and calculates the dynamic shelf life according to preset shelf-life calculation rules, thereby obtaining the food traceability record and dynamic shelf life. Specifically, the system first extracts the above four types of basic data from various sensors or management systems in the production, transportation, and storage stages. The food batch number uniquely identifies the food batch, the production date records the production time, and the transportation temperature and storage humidity reflect the environmental conditions of the food during distribution. After data acquisition, the system calls the blockchain interface to generate a timestamp for each data entry and writes it to the distributed ledger to ensure the immutability and traceability of the data records. Subsequently, the system processes the data according to the preset shelf life calculation rules. These rules combine the basic shelf life of the food type with environmental condition correction coefficients. For example, when the temperature is higher than 4°C, the shelf life decreases by 1 day for every 1°C increase, and when the humidity is higher than 80%, the shelf life decreases by 0.5 days for every 5% increase. Through such calculations, a dynamic shelf life is obtained and formed into a food traceability record together with information such as batch number and production date.

[0048] For example, in the cold chain dairy product example, a batch of yogurt with batch number "Y20250801" and a production date of August 1, 2025, recorded an average temperature of 6°C and humidity of 85% during transportation. The standard shelf life for this type of yogurt is 30 days. The shelf life calculation rules stipulate that for every 1°C increase above 4°C, the shelf life is reduced by 1 day; and for every 5% increase above 80% humidity, the shelf life is reduced by 0.5 days. The calculated dynamic shelf life for this batch of yogurt is 27.5 days. The batch number, production date, environmental data, and dynamic shelf life are all written to the ledger using blockchain timestamps. The generated food traceability record can serve as the basis for subsequent QR code generation, consumer inquiries, and feedback verification.

[0049] It should be noted that the preset shelf-life calculation rule refers to a set of criteria for correcting the real-time shelf-life of food, based on the standard shelf-life of the food and combined with empirical parameters on the impact of transportation and storage environments. This rule typically pre-sets different basic shelf-lifes for different food categories (such as dairy products, meat, and fruits and vegetables), while also incorporating thresholds and influence coefficients of key indicators such as ambient temperature and humidity. For example, for dairy products, the standard shelf-life is 30 days. When the transportation or storage temperature exceeds 4°C, the shelf-life is reduced by 1 day for every 1°C increase; when the humidity exceeds 80%, the shelf-life is reduced by 0.5 days for every 5% increase. Such rules are formulated using historical quality testing data and food safety standards, ensuring their scientific validity and enforceability, and serve as a unified calculation basis in the blockchain traceability system.

[0050] It should be noted that the empirical parameters refer to the set of influence coefficients used to correct the dynamic shelf life of food. Their values ​​are derived from statistical analysis of food quality testing data, transportation and storage environment monitoring data, and food safety standards. These parameters are primarily used to quantify the impact of environmental indicators such as temperature and humidity on changes in food shelf life, forming correction factors that can be directly applied to dynamic shelf life calculations. In one specific embodiment, the system sets empirical parameters based on historical testing data and statistical analysis of food safety standards for cold chain dairy products, used to dynamically correct shelf life. These empirical parameters include a standard shelf life of 30 days, a temperature influence coefficient, and a humidity influence coefficient. The standard shelf life applies to food stored at 0℃~4℃ and 70%~80% humidity. When the transportation or storage temperature exceeds 4℃, the system corrects according to the rule of reducing the shelf life by 1 day for every 1℃ increase; when the humidity exceeds 80%, the system corrects according to the rule of reducing the shelf life by 0.5 days for every 5% increase. For example, if the transportation record for a batch of yogurt shows a temperature of 6℃ and a humidity of 85%, then exceeding the temperature limit by 2℃ will shorten the shelf life by 2 days, and exceeding the humidity limit by 5% will further shorten the shelf life by 0.5 days. Ultimately, the dynamic shelf life will be adjusted from 30 days to 27.5 days. The corrected dynamic shelf life, along with the batch number, is recorded in the blockchain ledger as the basis for subsequent traceability node synchronization, QR code generation, and consumer queries.

[0051] It should be noted that the calculation of dynamic shelf life is performed after collecting the food batch number, production date, transportation temperature, and storage humidity. The system first matches the standard shelf life according to the food type, and then calls preset correction rules to adjust the standard shelf life based on environmental conditions: first, it checks whether the transportation or storage temperature exceeds a threshold; if so, the shelf life is reduced by the amount of temperature exceeding the threshold. Then, it checks whether the humidity exceeds a threshold; if so, the shelf life is further reduced by the amount of humidity exceeding the threshold. Finally, the corrected shelf life is combined with the production date to calculate the remaining shelf life days for the food batch. The entire calculation result, along with the food batch number and environmental records, is written into a blockchain timestamp, forming a unique and tamper-proof dynamic shelf life information, providing real-time and reliable basic data for subsequent QR code generation and consumer queries.

[0052] In one specific embodiment, the matching of standard shelf life and correction coefficients is achieved through a preset food category parameter table. This parameter table is established during system initialization and is grouped according to food type (such as dairy products, meat, fruits and vegetables). Each group contains the corresponding standard shelf life value, temperature threshold, humidity threshold, and corresponding correction coefficient. For example, the standard shelf life of the dairy product group is set to 30 days, the temperature threshold is 4°C, the humidity threshold is 80%, and the correction coefficient is "deduct 1 day for every 1°C increase in temperature and deduct 0.5 days for every 5% increase in humidity"; the standard shelf life of the meat group is set to 14 days, the temperature threshold is 0°C, the humidity threshold is 75%, and the correction coefficient is "deduct 0.8 days for every 1°C increase in temperature and deduct 0.3 days for every 5% increase in humidity".

[0053] After collecting the food batch number, the system quickly retrieves the corresponding parameter table entry using the preset category coding field in the batch number (e.g., "MLK" for dairy products, "MEAT" for meat, and "VEG" for fruits and vegetables) or the food category information entered by the manufacturer. It then automatically matches the standard shelf life and correction rules for that food item. When calculating the dynamic shelf life, the system first reads the standard shelf life from the matching results, then calls the temperature and humidity correction rules for that type of food to deduct or extend the shelf life. This method automates and differentiates the calculation of dynamic shelf life for different food categories, ensuring the accuracy and scalability of the calculation results.

[0054] In step S12, the batch number and dynamic shelf life in the food traceability record need to be encrypted using the SHA-256 algorithm to generate a tamper-proof hash value, including:

[0055] Based on the batch number and dynamic shelf life in the food traceability record, the SHA-256 algorithm is used to perform encryption operations to generate the first hash value;

[0056] The first hash value and the food traceability record are written together into a preset blockchain distributed ledger, so that the first hash value is distributed and stored among multiple nodes;

[0057] The food traceability record is retrieved from the preset blockchain distributed ledger, and the batch number and the dynamic shelf life are re-encrypted using the SHA-256 algorithm to generate a second hash value;

[0058] When the second hash value is equal to the first hash value, the second hash value is determined as the tamper-proof hash value.

[0059] First, based on the food batch number and dynamic shelf-life date in the food traceability record, an encryption algorithm is used to combine these two fields and input them into the SHA-256 algorithm. SHA-256 (Secure Hash Algorithm 256-bit) is a secure hash algorithm that outputs a hash value of fixed length 256 bits. This algorithm uses multiple rounds of bitwise operations, logical operations, and modulo addition operations to generate a fixed-length, irreversible digital digest of the input data. Even if the input data is slightly modified, the output hash value will be completely different. In this way, it can be ensured that any modification to the batch number and dynamic shelf-life date during storage and transmission can be detected. After the SHA-256 operation, the first hash value is generated and represented in hexadecimal string form for easy storage and comparison in the blockchain ledger.

[0060] Next, the first hash value and the corresponding food traceability record are written into a pre-defined blockchain distributed ledger. This ledger is a distributed storage system maintained by multiple nodes, each holding a copy of the ledger. The writing process uses a blockchain consensus mechanism (such as PoW or PoS) to ensure that all nodes maintain consistency when recording hash values, avoiding single points of failure or malicious tampering. This distributed storage mode ensures that the first hash value is stored synchronously across multiple nodes. If any node's data is maliciously altered, the anomaly can be detected by comparing it with other nodes, ensuring data integrity and reliability.

[0061] In one specific embodiment, the first hash value and the corresponding food traceability record are stored as the same transaction in the blockchain distributed ledger to ensure that the two are recorded synchronously on the chain and maintain a one-to-one correspondence; at the same time, the hash value can also be used as an index field to participate in the generation of the ledger verification structure (such as a Merkle tree) so as to quickly confirm the integrity of the traceability data during subsequent cross-node verification or batch queries.

[0062] Subsequently, upon receiving a traceability query request, the system retrieves the record corresponding to the latest dynamic shelf-life from the blockchain distributed ledger and re-executes a SHA-256 encryption operation on the food batch number and dynamic shelf-life in that record to generate a second hash value. This process is identical to the initial encryption, using the same encryption rules to ensure that the outputs of the two operations are exactly the same when the input data is identical. By generating the second hash value and comparing it with the first hash value stored in the ledger, it is possible to quickly determine whether the record has been tampered with.

[0063] Finally, when the second hash value equals the first hash value, it indicates that the queried record is completely consistent with the data first written into the ledger with the latest dynamic shelf life, and no modifications have occurred. In this case, the second hash value is determined as the tamper-proof hash value. This tamper-proof hash value can serve as a verification mark for the integrity of food traceability records, providing a fast and reliable verification method when consumers scan codes for queries or when regulatory audits are conducted, thereby ensuring the security and reliability of the food traceability system. If the second hash value does not equal the first hash value, the system determines that the batch of records has a risk of tampering or anomalies, automatically marks the record as abnormal, triggers the inter-node comparison and anomaly location process, and simultaneously sends an alarm to the management backend and regulatory end, prompting the batch of food to undergo further verification or isolation to prevent the misuse of erroneous information.

[0064] It should be noted that the pre-defined blockchain distributed ledger refers to a blockchain network ledger configured and used for food traceability data storage and verification before the implementation of this invention. This ledger is maintained by multiple nodes distributed across different stages of the supply chain, such as producer nodes, logistics nodes, retail nodes, and regulatory agency nodes. Each node stores a complete copy of the ledger, forming a decentralized distributed storage structure. The ledger adopts a chain-like data block structure, where each data block contains a timestamp, the hash value of the previous block, and the transaction record of the current block. Immutable connections between blocks are achieved through hash pointers.

[0065] During the data writing process, the pre-defined ledger uses a consensus algorithm (such as Proof-of-Stake (PoS) or Modified Byzantine Fault Tolerance (PBFT)) to ensure that all nodes reach agreement on the newly added data, preventing the risks of single-point manipulation and data forgery. The ledger supports timestamp recording, meaning that a corresponding write time identifier is automatically generated for each piece of data written, used for subsequent traceability and validity verification. Furthermore, the data stored in the ledger is recorded using hash values ​​and transaction indexes, and does not contain plaintext food information, thus ensuring the security and privacy of sensitive data.

[0066] In the food traceability method of this invention, a pre-set blockchain distributed ledger is mainly used to record food batch numbers, dynamic shelf life, environmental data hash values, and consumer feedback verification results. When a consumer or regulator initiates a query, the system can retrieve ledger data from any node and verify its integrity and authenticity through hash comparison. This ledger structure ensures that traceability data is synchronized and consistent throughout the entire supply chain. Even if some nodes are offline or attacked, other nodes can still provide reliable traceability information, ensuring the robustness and trustworthiness of the system.

[0067] In step S13, when the transportation temperature in the food traceability record is greater than a preset temperature threshold or the storage humidity data is greater than a preset humidity threshold, the dynamic shelf life is updated by combining the anti-tampering hash value and a new anti-tampering hash value is generated through encryption to obtain the food status record, including:

[0068] When the transportation temperature in the food traceability record is greater than a preset temperature threshold or the storage humidity data is greater than a preset humidity threshold, an environmental anomaly marker is generated.

[0069] Based on the environmental anomaly marker and the anti-tampering hash value, the dynamic shelf life is corrected according to the preset shelf life adjustment rules, and the batch number and the corrected dynamic shelf life are re-encrypted using the SHA-256 algorithm to generate a new anti-tampering hash value, thus forming an updated food status record.

[0070] The system first compares the real-time collected transportation temperature and storage humidity data against thresholds. The preset temperature and humidity thresholds are set in advance according to the type of food and national food safety standards. For example, the temperature threshold for cold chain dairy products can be 4℃, and the humidity threshold can be 80%. When any environmental parameter exceeds the threshold range, the system immediately generates an environmental anomaly marker and binds the anomaly marker to the unique tamper-proof hash value of the food batch to ensure that the subsequent status correction process is traceable and tamper-proof.

[0071] Subsequently, the system triggers shelf-life correction logic based on environmental anomaly markers, recalculating the original dynamic shelf-life using preset adjustment rules. These adjustment rules consider not only the magnitude of exceeding the threshold but also the duration of exceeding it. The duration is quantified through sampling records from environmental monitoring sensors. The system collects transport or storage temperature and humidity data at fixed time intervals (e.g., every 10 minutes). Timing begins when consecutive recorded values ​​exceed the threshold and stops when the data returns to normal. The accumulated time exceeding the threshold is then factored into the shelf-life deduction calculation, either in hours or days. For example, for every 1°C increase in temperature lasting 24 hours, 1 day of shelf-life is deducted; if it only lasts 12 hours, 0.5 days are deducted. Similarly, for every 5% increase in humidity lasting 24 hours, 0.5 days are deducted, and so on.

[0072] Furthermore, the system can dynamically fine-tune the deduction coefficient based on historical quality inspection data. Specifically, during long-term operation, the system accumulates a large amount of batch environmental data and actual shelf-life test results, and corrects them through statistical analysis or modeling methods. One approach is to use a linear regression model, with the degree of temperature exceedance, humidity exceedance, and duration of exceedance as independent variables, and the measured number of days of shelf-life reduction as the dependent variable, to fit a new deduction coefficient. Another approach is to use machine learning algorithms (such as random forests or gradient boosting trees) to automatically learn the non-linear relationship between environmental parameters and shelf-life reduction, thereby dynamically optimizing the correction rules under different seasons and different food categories.

[0073] For example, during the transportation of cold chain yogurt, batch number Y20250801 has a standard shelf life of 30 days. Real-time monitoring showed a temperature of 7°C and humidity of 85%. Based on thresholds (temperature 4°C, humidity 80%), the transportation environment was deemed to have exceeded both temperature and humidity limits, triggering an environmental anomaly flag. According to adjustment rules, a 3°C temperature exceedance corresponds to a 3-day reduction, and a 5% humidity exceedance corresponds to a 0.5-day reduction. The dynamic shelf life was adjusted from 30 days to 26.5 days, and an updated food status record was generated. This record includes the batch number, tamper-proof hash value, updated shelf life, and an explanation of the anomaly, ensuring that subsequent consumer scanning or regulatory inspections can directly trace the environmental anomaly and the basis for the shelf life adjustment.

[0074] It should be noted that the preset temperature threshold refers to the upper limit of the standard used to determine whether the temperature of food is abnormal during transportation or storage. This threshold is configured according to the food category and food safety standards before the implementation of this method. This threshold typically refers to cold chain food safety regulations; for example, the threshold for dairy products and meat can be set at 4℃, while for frozen foods it can be as low as -18℃. The temperature threshold is determined based on the physicochemical properties and perishability of the food, and is obtained through analysis of historical transportation environment data and quality inspection results. When the real-time monitored temperature exceeds this threshold, the system will immediately generate an environmental anomaly flag and trigger dynamic shelf-life correction logic to reflect the impact of temperature anomalies on food quality.

[0075] It should be noted that the preset humidity threshold is a reference value used to determine whether the humidity of stored food exceeds the standard. It is also set before the method is implemented based on the food characteristics and relevant standards. This threshold is generally applicable to humidity-sensitive foods, such as baked goods, dairy products, or dried goods, and is often set to 80% relative humidity. When the monitored humidity exceeds this threshold, it indicates a risk to the packaging protection or refrigeration environment, which may lead to food spoilage or packaging damage. The system will mark the anomaly and adjust the shelf life in conjunction with temperature data. The humidity threshold can be dynamically optimized based on product moisture protection requirements and the climate conditions of the transportation route to improve the applicability of the calculation.

[0076] It should be noted that the preset shelf-life adjustment rule refers to a calculation method for dynamically adjusting the shelf-life based on the degree to which temperature and humidity exceed the limits. Before deploying the method, standard shelf-life models are established for various food products, and corresponding adjustment coefficients are defined. For example, when the temperature exceeds 4°C, the shelf-life is reduced by 1 day for every 1°C increase; when the humidity exceeds 80%, the shelf-life is reduced by 0.5 days for every 5% increase; if both temperature and humidity exceed the limits simultaneously, the reduction is cumulative. This rule is verified through experimental data and historical quality cases and is uniformly stored in the blockchain to ensure that all nodes calculate the dynamic shelf-life using the same logic, thereby avoiding discrepancies in results between different nodes.

[0077] It should be noted that during the dynamic shelf-life update process, the system will synchronously recalculate the batch number and the hash value of the updated dynamic shelf-life, and write the new tamper-proof hash value into the blockchain distributed ledger to ensure that the latest valid hash value is always used in subsequent verifications.

[0078] In step S14, the food status records need to be synchronized to each supply chain node, and the consistency of batch number and shelf life needs to be checked to obtain a shared food status dataset, including:

[0079] The food status records are distributed and synchronized according to the preset supply chain node identifiers to form a synchronized status dataset for each supply chain node.

[0080] A hash value is generated for the batch number and dynamic shelf life in the synchronization status dataset, and the hash values ​​are compared between each supply chain node. When the hash values ​​of each supply chain node are consistent, the consistency check is determined to be successful, and the consistency check result is obtained.

[0081] The consistency verification results are recorded in a preset blockchain distributed ledger to form a shared food status dataset that can be accessed later.

[0082] The system first performs distributed synchronization of food traceability records based on preset supply chain node identifiers. These supply chain node identifiers are unique codes assigned to each participating node (including manufacturers, logistics providers, warehousing nodes, retailers, and regulatory agencies) during the system deployment phase, ensuring accurate data delivery to the corresponding node during synchronization. Synchronization is achieved through a distributed communication protocol, typically implemented in two ways: One is asynchronous transmission based on message queues, such as using Kafka or RabbitMQ to build a distributed message channel. The system encapsulates food traceability records into message packets, which are sent to the message queue by producer nodes. Consumer nodes (such as logistics providers or retailers) subscribe to the corresponding topics and receive the messages, thus achieving low-latency, scalable multi-node synchronization. The other is a blockchain broadcast mechanism based on peer-to-peer networks, such as using IPFS (InterPlanetary File System) or the underlying Gossip protocol of the blockchain. The system divides the traceability data into blocks and broadcasts them among nodes. Each node verifies data consistency through hash verification, ensuring that the ledgers of each node are updated to the latest state almost simultaneously. Once synchronization is complete, all nodes form their own synchronization status datasets, which include batch numbers, dynamic shelf life, and environmental labeling information, providing a data foundation for subsequent consistency verification and QR code generation.

[0083] Subsequently, the system performs hash generation on the batch number and dynamic shelf-life fields in the synchronization status dataset to form a data digest for consistency verification. Specifically, the system first concatenates the batch number and dynamic shelf-life into a string to be hashed according to a unified combination format, preferably using the order "[batch number]||[dynamic shelf-life]", where the separator "||" is a fixed symbol used to avoid field confusion. The concatenated string is then uniformly converted into a byte stream using UTF-8 encoding format to ensure that the byte streams obtained by different nodes in different operating system or character set environments are consistent, thereby ensuring the comparability of subsequent hash results.

[0084] The hash calculation process uses the same SHA-256 secure hash algorithm as the previous steps, performing a one-way hash operation on the encoded combined byte stream to generate a fixed-length 256-bit hash string. Each node compares the generated hash string using a blockchain consensus algorithm (such as PoW, PoS, or PBFT). Once the hash results of all nodes are consistent, it can be confirmed that the data has not been tampered with during synchronous transmission, and that the batch number and dynamic shelf life are completely consistent across all nodes.

[0085] If discrepancies are found in the comparison results, the system will automatically trigger a retransmission or conflict resolution mechanism. Specifically, conflict resolution prioritizes the earliest timestamp principle: the data version earliest written to the blockchain ledger and confirmed by a majority of nodes is used as the benchmark, and its batch number and dynamic shelf life are broadcast to other nodes to overwrite the update; if multiple versions have the same timestamp, the version with the highest consistency is confirmed by a majority vote of the nodes and written to the blockchain ledger as the final version. The retransmission process redistributes the standard version data through a distributed message queue or blockchain broadcast protocol to ensure that all nodes' records remain consistent and to avoid incomplete traceability records due to data tampering or loss.

[0086] Once the consistency verification passes, the system records the consistency result in a pre-defined blockchain distributed ledger. This record includes not only a verification success identifier but also a timestamp and the identifiers of the nodes participating in the verification, for subsequent traceability and verification. The resulting shared food status dataset can be directly accessed by all parties in the supply chain and by consumers during the barcode scanning process, enabling consistent traceability information display across nodes.

[0087] For example, in a dairy cold chain transportation scenario, yogurt with batch number Y20250801 has its dynamic shelf life calculated to be 27.5 days during the production process and then synchronized. The manufacturer node generates a hash value and broadcasts it to the logistics and retail nodes. After receiving the data, the logistics node also calculates the hash value and compares it. If the result is consistent, the verification result is recorded in the blockchain ledger. When retailers subsequently scan and display the product, they can directly access this shared food status dataset to display a unified dynamic shelf life and distribution path, avoiding information conflicts caused by asynchronous node data.

[0088] It should be noted that the pre-set supply chain node identifier refers to a unique identification code assigned to each participating node in the supply chain before system deployment. This identifier is used to distinguish node identities and ensure the accuracy of data transmission paths during the synchronization and verification of traceability data. This identifier typically consists of a node type code and a node sequence number. For example, a manufacturer node might use "P-001," a logistics node "L-001," and a retail node "R-001," to quickly identify the data source and its role in the supply chain. The identifier configuration can be based on a supply chain registration mechanism. During system initialization, the traceability platform generates a node identifier for each legitimate participant and registers and publishes it through the blockchain network. Once generated, the identifier remains fixed and is bound to the node's public key for subsequent data synchronization, hash comparison, and consistency verification, ensuring that no unregistered node can write to or tamper with traceability data.

[0089] In step S15, a reliable QR code containing batch number, dynamic shelf life, and circulation record needs to be generated based on the shared food status dataset to obtain a QR code image for consumers to scan, including:

[0090] The shared food status dataset is parsed into structured food information data, and the batch number is used as the primary key to associate dynamic shelf life and circulation records.

[0091] A real-time information string is generated based on the structured food information data;

[0092] The data encryption key is retrieved from the preset key library to encrypt the real-time information string, resulting in an encrypted information string;

[0093] The encrypted information string is encoded into a QR code to obtain a QR code image for consumers to scan.

[0094] The system first parses the shared food status dataset, extracting and organizing information such as batch number, dynamic shelf life, and production and transportation records into structured food information data. This structuring process uses the batch number as the primary key, associating the corresponding dynamic shelf life with the complete distribution path field, thus creating an independent and complete traceable information unit for each batch. This structured data not only facilitates subsequent encryption processing but also allows consumers to quickly locate relevant information after scanning.

[0095] Subsequently, the system generates a real-time information string based on the structured food information data. This string concatenates the batch number, dynamic shelf life, and distribution path according to a preset format, such as a combination of "batch number_shelf life_distribution path_timestamp," to ensure information integrity and decoding readability. The real-time information string may include key time nodes (such as production date, transportation transit time, and retail warehousing time) and status identifiers, which are used to directly present the full status of the food during subsequent display.

[0096] After the information is generated, the system retrieves the data encryption key from the preset key library to encrypt the real-time information string. The key library is configured during system initialization. To ensure long-term security, key management includes a rotation and destruction mechanism: new keys are preferably generated according to food batches or at fixed time periods (such as every 24 hours), and expired keys are securely destroyed. The destruction methods include erasing from memory and storage media and confirming complete deletion through hash verification to avoid the risk of key leakage.

[0097] The encryption algorithm employs symmetric encryption, preferably using AES-128 or AES-256, and specifies the working mode and padding scheme. Specifically, CBC (Cipher Block Chaining) mode is preferred to enhance resistance to analysis, combined with the PKCS#7 padding scheme to ensure the plaintext length is aligned with the encrypted block. The encryption process converts the UTF-8 encoded real-time message string into ciphertext and uses a batch unique identifier as part of the initialization vector (IV) to improve randomness and prevent the problem of identical plaintext generating identical ciphertext.

[0098] After encryption, the system converts the ciphertext into an encodeable string format (such as Base64) and then performs encoding using a standard QR code generation algorithm. During QR code generation, the error correction level (L / M / Q / H) can be selected based on the application scenario. For example, a medium level (M) can be selected for retail terminals to balance capacity and error correction capabilities, while a high level (H) can be selected for cold chain transportation to improve resistance to contamination. The final generated QR code image is used by consumers for scanning and querying, ensuring the security and availability of data during transmission and display.

[0099] For example, in a dairy product supply chain scenario, the shared dataset for yogurt with batch number Y20250801 contains a dynamic shelf life of 27.5 days and a distribution path of "producer-logistics provider-retailer". After parsing this dataset, the system generates structured data and concatenates it into a real-time information string "Y20250801_27.5days_A-B-C_20250805". This string is then encrypted using AES-128, further encoded to generate a 200×200 pixel QR code image, and printed on the yogurt packaging. Consumers can scan the code to decrypt and obtain the batch number, shelf life, and distribution summary, achieving a secure and transparent display of food traceability information.

[0100] In step S16, if a consumer scans the QR code image, a validity and completeness comparison is performed based on the shared food status dataset to obtain the shelf-life field and a distribution information summary, including:

[0101] If a consumer scans the QR code image, the QR code image is parsed to obtain an encrypted information string, and the encrypted information string is decrypted and the food batch number is extracted using a preset decryption module.

[0102] Based on the food batch number, retrieve the corresponding shared record from the shared food status dataset;

[0103] The timestamp field in the shared record is validated to confirm that the data generation time is within the preset allowed time limit;

[0104] An integrity comparison is performed on the hash value field in the shared record to confirm that the record has not been tampered with;

[0105] If both the timestamp and hash value pass verification, output the shelf life field and a summary of circulation information.

[0106] Consumers use their mobile devices' scanning interfaces to read the QR code image on food packaging. The system first calls a QR code decoding tool to parse the image, extracting an encrypted information string. Then, it obtains a decryption key through a trusted Key Management Service (KMS) or a preset decryption module to decrypt the encrypted information string and identify the food batch number. Based on the batch number, the system locates the corresponding shared record in the shared food status dataset and extracts the timestamp field, dynamic shelf-life field, and hash value field associated with that batch.

[0107] Next, the system performs a validity comparison on the extracted timestamp field. The timestamp is an automatically generated time identifier when a food traceability record is written to the blockchain, used to characterize the record's generation time and storage order. During the comparison, the system calculates the difference between the timestamp and the current system time and determines whether it falls within a preset allowed time limit (e.g., 24 hours or 48 hours). If it exceeds this range, the system determines that the data may be expired or has a synchronization anomaly, and stops subsequent display operations.

[0108] Subsequently, the system performs an integrity comparison on the extracted hash value field. This hash value is a tamper-proof hash value (first hash value), generated by the food batch number and its corresponding dynamic shelf life using the SHA-256 algorithm and stored in the ledger when the data is first written to the blockchain. When a consumer scans the code to query, the system re-executes the SHA-256 encryption operation based on the batch number and dynamic shelf life in the current shared record to generate a second hash value. The system compares this second hash value bit by bit with the first hash value recorded in the ledger: if they match, it means that the batch number and the latest dynamic shelf life of the batch record have not been tampered with since being written, and the dynamic shelf life is the current valid value; if they do not match, it means that the record is at risk of tampering or abnormal updates, and the system automatically marks it as an abnormal state and triggers a security warning.

[0109] When both the timestamp comparison and hash value comparison pass, the system confirms that the queried record is authentic and valid. It then outputs the corresponding shelf life field and circulation information summary, and generates a user interface to display the food status and circulation path.

[0110] Once both the timestamp and hash value verification pass, the system outputs the shelf-life field and distribution information summary from the batch of records to the user interface. The shelf-life field displays the remaining expiration date or estimated expiration date of the food, while the distribution information summary presents the main flow nodes of the food from production to retail in a simplified path format, such as "Manufacturer A → Logistics Provider B → Retailer C". In this way, consumers can intuitively confirm the current status and distribution path of the food, helping to enhance transparency and trust in food safety.

[0111] For example, in a cold chain dairy product scenario, after a consumer scans the QR code of yogurt with batch number Y20250801, the system decodes it to obtain the encrypted string "Y20250801_27.5days_A-B-C_20250805". The system locates the shared data record based on the batch number and extracts the timestamp "2025-08-05 10:00:00" and its corresponding hash value. The timestamp differs from the current time by 6 hours, falling within the preset 24-hour validity period. The system then regenerates the hash value using the SHA-256 algorithm and compares it with the record; the result matches, confirming the data's reliability. Finally, the interface displays "Remaining shelf life: 27.5 days, distribution path: Manufacturer A → Logistics provider B → Retailer C," providing consumers with a reference for purchasing or consumption decisions.

[0112] In step S17, it is necessary to compare the dynamic shelf life with the current time based on the shelf life field and the distribution information summary to determine whether the food is in an expiration state. The expiration state, the shelf life field, and the distribution information summary are then combined to generate a user interface, including:

[0113] The dynamic shelf life is compared with the current time to determine whether the food is within its expiration date;

[0114] When the food is within its expiration date, the expiration date status, the shelf life field, and the circulation information summary are combined into status data;

[0115] The state data is converted into interface display elements to generate the user interaction interface.

[0116] The system first retrieves the shared data records that passed the previous verification, extracts the dynamic shelf-life information, and compares it with the current system time. This comparison process uses the expiration date calculated from the dynamic shelf-life as the benchmark. For example, the production date is added to the number of days in the dynamic shelf-life to obtain the estimated expiration date. Then, it determines whether the current time is earlier than this expiration date to ascertain whether the food is within its expiration period. If the current time has exceeded the expiration date corresponding to the dynamic shelf-life, the system will mark it as expired and prompt the consumer to stop consuming it or return it for a refund or exchange.

[0117] When food is within its expiration date, the system combines the verified shelf-life field with the distribution information summary to generate status data. This status data includes the remaining shelf-life days or expected expiration date, key distribution nodes (such as production, transportation, and retail), and necessary status descriptions, such as "cold chain transportation qualified" or "dynamic shelf-life adjusted." This structured status data is then passed to the interface rendering module as the core content displayed on the screen.

[0118] The system then converts the status data into interface elements, generating a user interface. The interface can use a combination of graphics and text to display key parameters and path information, and uses color coding to indicate the current status (e.g., green for normal, red for expired, and yellow for soon-to-expire). The interface can also provide interactive functions; for example, consumers can click on a distribution node to view detailed transportation temperature and humidity records or node timestamps, enabling a hierarchical display of traceability information.

[0119] For example, in the dairy product scenario, yogurt with batch number Y20250801 has a dynamic shelf life of 27.5 days, corresponding to an expiration date of August 28, 2025. When a consumer scans the code to check the expiration date on August 10, 2025, the system compares the current time with the expiration date and determines that the food is still within its validity period. The interface displays "Remaining shelf life: 18 days, distribution path: Manufacturer A → Logistics provider B → Retailer C," and indicates that the status is normal with a green icon. If the current time is August 30, the comparison result shows that it has expired, and the interface highlights "Shelf life exceeded" in red, while also displaying suggestions for return, exchange, or damage reporting.

[0120] In step S18, consumer feedback evaluations need to be extracted based on the user interaction interface and batch matching needs to be verified using a preset timestamp to obtain reliable feedback records, including:

[0121] Consumer ratings and reviews from the user interface are organized into structured feedback records, and evaluation data is generated based on the structured feedback records and the food batch number.

[0122] A preset timestamp is added to the evaluation data and bound to the food batch number to form time-stamped constrained evaluation data;

[0123] When the batch number of the constraint evaluation data matches the preset food batch number, a reliable feedback record is generated.

[0124] After consumers complete their food status inquiry, the system provides feedback entry points in the user interface, including rating input (such as star ratings or numerical values) and text comment input. The ratings and comments submitted by consumers are uploaded to the server after being validated by the client. The server then organizes the feedback content into a structured feedback record. The structured feedback record includes the consumer's rating value, comment text, submission time, and food batch number for subsequent verification and data storage.

[0125] Subsequently, the system combines the structured feedback records with the food batch numbers to generate initial evaluation data and adds a preset timestamp. The preset timestamp is a unique time identifier generated by the system before the data is written to the blockchain or database, recording the exact time the feedback was submitted. The timestamp not only confirms the timeliness of the feedback data but also verifies whether the feedback information is synchronized with the food traceability records during subsequent traceability queries. This timestamp is bound to the evaluation data, forming time-stamped constrained evaluation data, which serves as the basis for subsequent batch matching and reliable verification.

[0126] Finally, the system performs batch matching verification on the timestamped constraint evaluation data. This verification is accomplished by comparing the batch number in the evaluation data with the preset batch number in the shared food status dataset. If the match is successful, it indicates that the feedback evaluation did indeed come from the consumer who queried that food batch, and the feedback can be considered credible; if the match fails, the feedback is determined to be possibly invalid or erroneously submitted and will not be included in the credible record. The credible feedback records generated in this way will serve as an important basis for subsequent updates to the traceability dataset and optimization of supply chain management.

[0127] For example, in a cold chain yogurt scenario, after querying the dynamic shelf life and distribution information of batch number Y20250801, consumers submit feedback via the interface stating "Good taste, intact packaging" and selecting a 4-star rating. The system integrates the rating and review into a structured feedback record, adds a timestamp "2025-08-10 14:05:00," and binds it to the batch number to form constrained evaluation data. Verification results show that the batch number matches the centralized record in the traceability data; therefore, the feedback is marked as a trusted feedback record and stored in the blockchain ledger for subsequent quality analysis and product improvement.

[0128] It should be noted that the pre-assigned food batch number refers to a code pre-assigned and fixed during the food production process to uniquely identify each batch of food, used for data association and verification throughout the subsequent traceability process. This number is usually generated by the manufacturer during the production planning stage, using a fixed format coding strategy to distinguish between the production date, production line, and batch number. For example, it can use a combination of "product code + production date + batch number," such as "MLK20250801-01" representing the first batch of milk products produced on August 1, 2025. The generation of the number is generally completed automatically by the company's production management system (such as MES or ERP system), ensuring that the batch number is unique and cannot be repeated throughout the entire factory. After generation, the batch number will be identified on the product packaging in the form of a barcode or QR code during the production process and simultaneously recorded in the blockchain ledger of the food traceability system, used as an index key for subsequent dynamic shelf-life calculation, environmental monitoring, consumer scanning query, and feedback matching. In the method of this invention, the pre-assigned food batch number runs through the entire food traceability process: it is the basic field for timestamp processing, hash generation, dynamic shelf-life update, node consistency verification, and consumer feedback verification. By using the same number consistently, the system can ensure that data at each stage is correctly linked and achieve unified identification across multiple nodes, avoiding data breakage or traceability failure due to inconsistent numbering.

[0129] In step S19, the shared food status dataset needs to be updated and synchronized to each supply chain node based on the trusted feedback record, and a final food traceability report containing batch number and circulation information summary needs to be generated.

[0130] The trusted feedback records are integrated with the batch numbers and circulation information in the shared food status dataset to generate an updated traceability dataset;

[0131] The traceability dataset is synchronized to the supply chain nodes, and the consistency of the synchronized data at each node is compared.

[0132] If the consistency comparison passes, a final food traceability report containing batch number and a summary of distribution information is generated.

[0133] The system first integrates the trusted feedback records submitted and verified by consumers with the original traceability information of the corresponding batches in the pre-set blockchain traceability dataset. The integration process combines the ratings, comments, timestamps, and core fields such as food batch numbers, dynamic shelf-life, and distribution paths from the feedback data. This ensures that the updated traceability data not only reflects the food production and distribution process but also includes quality evaluation information from end consumers, thus forming a more complete traceability dataset.

[0134] Subsequently, the system synchronizes the updated traceability dataset to all nodes in the supply chain via a distributed communication mechanism. During synchronization, the system broadcasts data to manufacturers, logistics providers, retailers, and regulatory agencies based on preset supply chain node identifiers to ensure data consistency across nodes. After synchronization, each node performs a consistency comparison: by comparing the hash values ​​of the batch number and the dynamic shelf life, it confirms that the data stored by each node is completely consistent and has not been tampered with. If the comparison results are consistent, the system determines that synchronization was successful and generates a final confirmation status for that batch.

[0135] Upon successful consistency verification, the system generates a final food traceability report. This report includes batch number, dynamic shelf life, a summary of key distribution points, and a summary of consumer feedback, along with a blockchain timestamp to verify the data's generation time and authenticity. The report can be used by consumers for scanning and querying, as well as by regulatory authorities for spot checks and by companies for internal quality traceability, thus achieving transparent and auditable management across the entire supply chain.

[0136] For example, in the cold chain dairy product scenario, after consumer feedback regarding the yogurt batch number Y20250801 as having "good taste and stable transportation" was verified as credible, this feedback was merged and updated with existing traceability data (such as production time, transportation temperature and humidity records, and dynamic shelf life). The updated data was synchronized to production, logistics, retail, and regulatory nodes via a blockchain network, and after consistency verification through hash comparison, a final traceability report was generated. The report included the batch number, remaining shelf life of 18 days, the distribution path "Manufacturer A → Logistics Provider B → Retailer C," and a summary of the consumer's 4-star rating, providing a reliable basis for subsequent quality supervision and consumer trust.

[0137] In summary, this invention provides a blockchain-based food traceability method and system to solve the problems of information silos and data inconsistencies in existing technologies, and to achieve real-time and reliable tracking of food status.

[0138] Reference Figure 2 The second embodiment of the present invention provides a blockchain-based food traceability system, comprising:

[0139] The data acquisition module acquires the batch number, production date, transportation temperature, and storage humidity of the food, performs blockchain timestamp processing to generate food processing data, calculates the dynamic shelf life according to the preset shelf life calculation rules, and combines the food processing data and the dynamic shelf life to form a food traceability record.

[0140] The encryption generation module uses the SHA-256 algorithm to encrypt the batch number and dynamic shelf life in the food traceability record to generate a tamper-proof hash value.

[0141] The food status module is used to update the dynamic shelf life and encrypt and generate a new anti-tampering hash value when the transportation temperature in the food traceability record is greater than a preset temperature threshold or the storage humidity data is greater than a preset humidity threshold, thereby obtaining the food status record.

[0142] The shared data module is used to synchronize the food status records to each supply chain node, and to determine the consistency of batch number and shelf life to obtain a shared food status dataset.

[0143] The data integration module is used to generate a reliable QR code containing batch number, dynamic shelf life and circulation record based on the shared food status dataset, so as to obtain a QR code image for consumers to scan.

[0144] The status verification module is used to perform a validity and completeness comparison based on the shared food status dataset if a consumer scans and queries the QR code image, and obtain the shelf life field and circulation information summary.

[0145] The user interaction module is used to compare the dynamic shelf life with the current time based on the shelf life field and the circulation information summary to determine whether the food is in an expiration state, and to combine the expiration state, the shelf life field and the circulation information summary to generate a user interaction interface;

[0146] The trusted feedback module is used to extract consumer feedback and evaluation based on the user interaction interface and verify batch matching by combining a preset timestamp to obtain trusted feedback records.

[0147] The food traceability module is used to update the shared food status dataset and synchronize it to each supply chain node based on the trusted feedback records, generating a final food traceability report containing batch numbers and circulation information summaries.

[0148] It should be noted that the blockchain-based food traceability system provided in this embodiment of the invention is used to execute all the process steps of the blockchain-based food traceability method in the above embodiment. The working principles and beneficial effects of the two are one-to-one, so they will not be described again.

[0149] This invention also provides an electronic device. The electronic device includes a processor, a memory, and a computer program stored in the memory and executable on the processor, such as a trusted feedback program. When the processor executes the computer program, it implements the steps described in the various blockchain-based food traceability method embodiments above, for example... Figure 1 The step S11 shown. Alternatively, when the processor executes the computer program, it implements the functions of each module / unit in the above system embodiments, such as the trusted feedback module.

[0150] For example, the computer program may be divided into one or more modules / units, which are stored in the memory and executed by the processor to complete the present invention. The one or more modules / units may be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of the computer program in the electronic device.

[0151] The electronic device may be a desktop computer, laptop, handheld computer, or smart tablet, etc. The electronic device may include, but is not limited to, a processor and memory. Those skilled in the art will understand that the above components are merely examples of electronic devices and do not constitute a limitation on the electronic device. It may include more or fewer components than described above, or combine certain components, or different components. For example, the electronic device may also include input / output devices, network access devices, buses, etc.

[0152] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor. The processor is the control center of the electronic device, connecting all parts of the electronic device via various interfaces and lines.

[0153] The memory can be used to store the computer programs and / or modules. The processor implements various functions of the electronic device by running or executing the computer programs and / or modules stored in the memory and by calling data stored in the memory. The memory may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the mobile phone (such as audio data, phonebook, etc.). In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as hard disk, memory, plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, at least one disk storage device, flash memory device, or other volatile solid-state storage device.

[0154] If the modules / units integrated into the electronic device are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of the present invention can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or system capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.

[0155] It should be noted that the system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Furthermore, in the accompanying drawings of the system embodiments provided by this invention, the connection relationships between modules indicate that they have communication connections, which can be specifically implemented as one or more communication buses or signal lines. Those skilled in the art can understand and implement this without any creative effort.

[0156] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. In particular, it should be noted that any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention for those skilled in the art.

Claims

1. A blockchain-based food traceability method, characterized in that, include: The batch number, production date, transportation temperature and storage humidity of the food are obtained, and blockchain timestamp processing is performed to generate food processing data. The dynamic shelf life is calculated according to the preset shelf life calculation rules, and the food processing data and the dynamic shelf life are combined to form a food traceability record. The batch number and dynamic shelf life in the food traceability record are encrypted using the SHA-256 algorithm to generate a tamper-proof hash value. When the transportation temperature in the food traceability record is greater than a preset temperature threshold or the storage humidity data is greater than a preset humidity threshold, the dynamic shelf life is updated by combining the anti-tampering hash value and a new anti-tampering hash value is generated by encryption to obtain the food status record. The food status records are synchronized to each supply chain node, and the consistency of batch number and shelf life is checked to obtain a shared food status dataset. Based on the shared food status dataset, a reliable QR code containing batch number, dynamic shelf life, and circulation record is generated, resulting in a QR code image for consumers to scan. If a consumer scans the QR code image, a validity and completeness comparison is performed based on the shared food status dataset to obtain the shelf life field and a summary of circulation information. Based on the shelf-life field and the circulation information summary, the dynamic shelf-life is compared with the current time to determine whether the food is in an expiration state, and the expiration state, the shelf-life field, and the circulation information summary are combined to generate a user interface; Based on the user interface, consumer feedback and evaluation are extracted and batch matching is verified by combining preset timestamps to obtain reliable feedback records. Based on the trusted feedback records, the shared food status dataset is updated and synchronized to each supply chain node to generate a final food traceability report containing batch numbers and circulation information summaries. Wherein, when the transportation temperature in the food traceability record is greater than a preset temperature threshold or the storage humidity data is greater than a preset humidity threshold, the dynamic shelf life is updated by combining the anti-tampering hash value and a new anti-tampering hash value is generated through encryption to obtain the food status record, including: When the transportation temperature in the food traceability record is greater than a preset temperature threshold or the storage humidity data is greater than a preset humidity threshold, an environmental anomaly marker is generated. Based on the environmental anomaly marker and the anti-tampering hash value, the dynamic shelf life is corrected according to the preset shelf life adjustment rules, and the batch number and the corrected dynamic shelf life are re-encrypted using the SHA-256 algorithm to generate a new anti-tampering hash value, thus forming an updated food status record. The preset shelf-life adjustment rules include: The adjustment rules not only consider the magnitude of exceeding the threshold but also the duration of exceeding the threshold, converting the accumulated over-threshold duration into hours or days for shelf-life deduction calculations. The system can dynamically fine-tune the deduction coefficient based on historical quality inspection data. In long-term operation, the system will accumulate a large amount of batch environmental data and actual shelf-life inspection results, and correct them through statistical analysis or modeling methods. One implementation method is to use a linear regression model, with the magnitude of temperature exceeding the standard, the magnitude of humidity exceeding the standard, and the duration of exceeding the standard as independent variables, and the measured number of days of shelf-life reduction as the dependent variable, to fit a new deduction coefficient. Another implementation method is to use machine learning algorithms to automatically learn the nonlinear relationship between environmental parameters and shelf-life reduction, thereby dynamically optimizing and correcting the rules under different seasons and different food categories. The step of performing validity and integrity comparison based on the shared food status dataset includes: The system performs a validity comparison on the extracted timestamp field. The timestamp is a time identifier automatically generated when food traceability records are written into the blockchain, used to characterize the generation time and storage order of the record. During the comparison process, the system calculates the difference between the timestamp and the current system time and determines whether it is within the preset allowed time limit. If it exceeds the preset allowed time limit, it is determined that the data may be expired or there is a synchronization anomaly, and subsequent display operations are stopped.

2. The food traceability method based on blockchain according to claim 1, characterized in that, The step of encrypting the batch number and dynamic shelf life in the food traceability record using the SHA-256 algorithm to generate a tamper-proof hash value includes: Based on the batch number and dynamic shelf life in the food traceability record, the SHA-256 algorithm is used to perform encryption operations to generate the first hash value; The first hash value and the food traceability record are written together into a preset blockchain distributed ledger, so that the first hash value is distributed and stored among multiple nodes; The food traceability record is retrieved from the preset blockchain distributed ledger, and the batch number and the dynamic shelf life are re-encrypted using the SHA-256 algorithm to generate a second hash value; When the second hash value is equal to the first hash value, the second hash value is determined as the tamper-proof hash value.

3. The food traceability method based on blockchain according to claim 1, characterized in that, The process of synchronizing the food status records to each supply chain node and verifying the consistency of batch numbers and shelf lives to obtain a shared food status dataset includes: The food status records are distributed and synchronized according to the preset supply chain node identifiers to form a synchronized status dataset for each supply chain node. A hash value is generated for the batch number and dynamic shelf life in the synchronization status dataset, and the hash values ​​are compared between each supply chain node. When the hash values ​​of each supply chain node are consistent, the consistency check is determined to be successful, and the consistency check result is obtained. The consistency verification results are recorded in a preset blockchain distributed ledger to form a shared food status dataset that can be accessed later.

4. The food traceability method based on blockchain according to claim 1, characterized in that, The step of generating a trusted QR code containing batch number, dynamic shelf life, and circulation record based on the shared food status dataset, and obtaining a QR code image for consumers to scan, includes: The shared food status dataset is parsed into structured food information data, and the batch number is used as the primary key to associate dynamic shelf life and circulation records. A real-time information string is generated based on the structured food information data; The data encryption key is retrieved from the preset key library to encrypt the real-time information string, resulting in an encrypted information string; The encrypted information string is encoded into a QR code to obtain a QR code image for consumers to scan.

5. The food traceability method based on blockchain according to claim 1, characterized in that, If a consumer scans the QR code image, a validity and completeness comparison is performed based on the shared food status dataset to obtain the shelf-life field and a distribution information summary, including: If a consumer scans the QR code image, the QR code image is parsed to obtain an encrypted information string, and the encrypted information string is decrypted and the food batch number is extracted using a preset decryption module. Based on the food batch number, retrieve the corresponding shared record from the shared food status dataset; The timestamp field in the shared record is validated to confirm that the data generation time is within the preset allowed time limit; An integrity comparison is performed on the hash value field in the shared record to confirm that the record has not been tampered with; If both the timestamp and hash value pass verification, output the shelf life field and a summary of circulation information.

6. The food traceability method based on blockchain according to claim 1, characterized in that, The step involves comparing the dynamic shelf life with the current time based on the shelf life field and the distribution information summary to determine whether the food is in an expiration state, and combining the expiration state, the shelf life field, and the distribution information summary to generate a user interface, including: The dynamic shelf life is compared with the current time to determine whether the food is within its expiration date; When the food is within its expiration date, the expiration date status, the shelf life field, and the circulation information summary are combined into status data; The state data is converted into interface display elements to generate the user interaction interface.

7. The food traceability method based on blockchain according to claim 5, characterized in that, The process of extracting consumer feedback and evaluations based on the user interface, verifying batch matching with a preset timestamp to obtain credible feedback records, and generating a final food traceability report based on the credible feedback records includes: Consumer ratings and reviews from the user interface are organized into structured feedback records, and evaluation data is generated based on the structured feedback records and the food batch number. A preset timestamp is added to the evaluation data and bound to the food batch number to form time-stamped constrained evaluation data; When the batch number of the constraint evaluation data matches the preset food batch number, a reliable feedback record is generated. The trusted feedback records are integrated with the batch numbers and circulation information in the shared food status dataset to generate an updated traceability dataset; The traceability dataset is synchronized to the supply chain nodes, and the consistency of the synchronized data at each node is compared. If the consistency comparison passes, a final food traceability report containing batch number and a summary of distribution information is generated.

8. A blockchain-based food traceability system, characterized in that, The method for implementing the blockchain-based food traceability method as described in any one of claims 1 to 7 includes: The data acquisition module acquires the batch number, production date, transportation temperature, and storage humidity of the food, performs blockchain timestamp processing to generate food processing data, calculates the dynamic shelf life according to the preset shelf life calculation rules, and combines the food processing data and the dynamic shelf life to form a food traceability record. The encryption generation module uses the SHA-256 algorithm to encrypt the batch number and dynamic shelf life in the food traceability record to generate a tamper-proof hash value. The food status module is used to update the dynamic shelf life and encrypt and generate a new anti-tampering hash value when the transportation temperature in the food traceability record is greater than a preset temperature threshold or the storage humidity data is greater than a preset humidity threshold, thereby obtaining the food status record. The shared data module is used to synchronize the food status records to each supply chain node, and to determine the consistency of batch number and shelf life to obtain a shared food status dataset. The data integration module is used to generate a reliable QR code containing batch number, dynamic shelf life and circulation record based on the shared food status dataset, so as to obtain a QR code image for consumers to scan. The status verification module is used to perform a validity and completeness comparison based on the shared food status dataset if a consumer scans and queries the QR code image, and obtain the shelf life field and circulation information summary. The user interaction module is used to compare the dynamic shelf life with the current time based on the shelf life field and the circulation information summary to determine whether the food is in an expiration state, and to combine the expiration state, the shelf life field and the circulation information summary to generate a user interaction interface; The trusted feedback module is used to extract consumer feedback and evaluation based on the user interaction interface and verify batch matching by combining a preset timestamp to obtain trusted feedback records. The food traceability module is used to update the shared food status dataset and synchronize it to each supply chain node based on the trusted feedback records, generating a final food traceability report containing batch numbers and circulation information summaries.

Citation Information

Patent Citations

  • Traceability and quality monitoring service system and method based on food safety

    CN113435909A

  • Probiotic plant beverage production method and system

    CN120678174A

  • Agricultural ecological member data security management method and system

    CN120811719A