Blockchain-based grain quality detection data traceability management method and system

By using blockchain technology to generate physical anti-counterfeiting labels, record process hash chains, and conduct smart contract judgments in grain quality testing, the problems of reliance on manual labor and easy data tampering in grain testing are solved, and the transparency of the testing process and the credibility of the results are improved.

CN122114957APending Publication Date: 2026-05-29黑龙江省粮食质量安全监测和技术中心
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
黑龙江省粮食质量安全监测和技术中心
Filing Date
2026-02-26
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

Current technologies for grain quality testing rely on manual sampling, resulting in low real-time information detection and a lack of verification mechanisms in data management and storage. This leads to data silos and susceptibility to tampering, resulting in inefficient testing results and difficulty in achieving transparent and intelligent adjudication.

Method used

A blockchain-based method for tracing and managing grain quality testing data is adopted. This method generates physical anti-counterfeiting labels and uploads them to the blockchain during the sampling process. The testing process records the process hash chain, and a smart contract is used for judgment after the testing is completed. This reconstructs a complete chain of evidence to ensure the immutability and credible verification of the data.

Benefits of technology

It has made the grain testing process transparent and automated, ensuring the authenticity and integrity of the data, improving the credibility of the test results and the effectiveness of supervision, eliminating human interference, and providing a reliable data foundation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122114957A_ABST
    Figure CN122114957A_ABST
Patent Text Reader

Abstract

The application discloses a grain quality detection data traceability management method and system based on a blockchain, and relates to the field of data management.The method comprises the following steps: collecting a sampling data packet, calculating and submitting a first hash value, generating a first transaction record and a physical anti-fake label; reading the physical anti-fake label to obtain on-chain information, calculating and submitting a second hash value, continuously calculating and storing key process data as process hash values to form a process hash chain; after detection, submitting detection result data and a result hash value, performing trusted verification and standard compliance determination on all chain data, and storing the determination conclusion as a determination transaction record; based on the determination transaction record, extracting and verifying the correlation between all hash values and determination transaction records, and reconstructing a complete grain quality detection evidence chain. The problems of the prior art, such as dependence of sampling information on manual work, low information detection real-time performance, lack of verification link in data management and storage, and low data monitoring and determination efficiency, are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data management, specifically to a blockchain-based method and system for tracing and managing grain quality testing data. Background Technology

[0002] The authenticity, completeness, and traceability of grain quality and safety testing data are core to ensuring food safety, achieving precise supervision, and building market trust.

[0003] Traditional grain quality testing and management primarily relies on paper records and information systems. In the sampling stage, sampling forms are typically filled out manually by sampling personnel, which is prone to errors and omissions, and is difficult to verify. In the testing stage, the lack of real-time recording of key process data leads to a lack of traceability and makes it impossible to effectively monitor operational compliance. In data management and judgment, test results are mostly stored in internal laboratory information systems or regional quality monitoring platforms, creating data silos that are vulnerable to single-point tampering; final qualification determination heavily relies on manual review, which is inefficient and susceptible to subjective interference.

[0004] Therefore, there is an urgent need for an innovative technological solution that can ensure the authenticity, integrity, and non-repudiation of data at all stages of grain testing from the source, achieve transparency and automated intelligent adjudication of the testing process, and build predictive risk models based on credible data, thereby comprehensively improving the effectiveness, credibility, and intelligence level of grain quality and safety monitoring. Summary of the Invention

[0005] This application provides a blockchain-based method and system for the traceability management of grain quality testing data, which addresses the problems in existing technologies such as reliance on manual sampling, low real-time information detection, lack of verification in data management and storage, and low efficiency in data monitoring and judgment.

[0006] In view of the above problems, this application provides a blockchain-based method for the traceability management of grain quality testing data.

[0007] Firstly, this application provides a blockchain-based method for tracing and managing grain quality testing data, the method comprising:

[0008] In the grain sampling process, a sampling data packet containing sample information is collected and a first hash value is calculated and submitted to the blockchain network to generate a first transaction record. Based on the first transaction record, a physical anti-counterfeiting label is generated and attached to the grain sample.

[0009] During the detection process, the physical anti-counterfeiting label is read to obtain on-chain information, detection start data is generated, and a second hash value is calculated and stored in the blockchain network. Key process data in the detection process are continuously calculated as process hash values ​​and stored in the blockchain network in chronological order to form a process hash chain.

[0010] After the test is completed, the test result data and the corresponding result hash value are submitted to the blockchain network. The pre-set smart contract performs credible verification and standard compliance judgment on the whole chain data of this test, and stores the generated judgment conclusion as a judgment transaction record in the blockchain network.

[0011] Based on the judgment transaction records, the correlation between the first hash value, the second hash value, the process hash chain, the result hash value, and the judgment transaction records is extracted and verified from the blockchain network to reconstruct a complete evidence chain for grain quality testing.

[0012] Secondly, this invention provides a blockchain-based grain quality testing data traceability management system, comprising:

[0013] The anti-counterfeiting label generation module is used in the grain sampling process to collect a sampling data packet containing sample information, calculate a first hash value, submit it to the blockchain network, generate a first transaction record, and generate a physical anti-counterfeiting label attached to the grain sample based on the first transaction record.

[0014] The quality inspection module is used to read the physical anti-counterfeiting label to obtain on-chain information during the inspection process, generate inspection start data and calculate the second hash value and store it in the blockchain network. It continuously calculates the key process data in the inspection process into process hash values ​​and stores them in the blockchain network in time sequence to form a process hash chain.

[0015] The test result determination module is used to submit the test result data and the corresponding result hash value to the blockchain network after the test is completed. The module uses a pre-set smart contract to perform credible verification and standard compliance determination on the entire chain data of this test, and stores the generated determination conclusion as a determination transaction record in the blockchain network.

[0016] The quality inspection evidence chain reconstruction module, based on the judgment transaction record, extracts and verifies the correlation between the first hash value, the second hash value, the process hash chain, the result hash value, and the judgment transaction record from the blockchain network, and reconstructs a complete grain quality inspection evidence chain.

[0017] One or more technical solutions provided in this application have at least the following technical effects or advantages:

[0018] This application first addresses the grain sampling stage by collecting sampling data packets containing multi-dimensional information, calculating a first hash value, and submitting them to the blockchain to generate a first transaction record. Simultaneously, a physical anti-counterfeiting label is generated based on this record. From the very beginning, the distributed consensus and immutability of the blockchain are utilized to solidify the spatiotemporal information, environmental evidence, and responsible party information of the sampling operation, preventing data forgery during the sampling phase. Furthermore, the physical anti-counterfeiting label establishes a unique query entry point from the physical grain to its on-chain digital identity, laying a reliable starting point for subsequent end-to-end traceability. Secondly, in the testing stage, on-chain information is obtained by reading the physical label, generating testing initiation data, calculating a second hash value, and uploading it to the chain. Then, key node data from the testing process are continuously calculated into process hash values ​​and uploaded to the chain in chronological order to form a process hash chain, achieving refined and chronological evidence storage of the testing process. Recording the status and time points of key operational steps affecting the credibility of the testing results on the blockchain in an immutable and logically continuous manner ensures the traceability of the testing activity itself and provides an objective data foundation for subsequent evaluation of the testing process.

[0019] Furthermore, after testing is completed, a smart contract for standard compliance is used to conduct full-chain data credibility verification and standard compliance determination, realizing the correlation between test results and compliance determination. The determination conclusion is stored as evidence in the transaction record, eliminating the subjective bias and inefficiency that may arise from human judgment. Finally, based on the final determination transaction record, a complete chain of evidence is reconstructed from the blockchain network, enabling any authorized party to trigger the system at any time based on an identifier to complete the process from on-chain data aggregation and logical correlation verification to the generation of structured reports. This enhances the credibility of grain quality testing information and forms an effective technical supervision of grain quality and safety. Attached Figure Description

[0020] Figure 1 This is a flowchart illustrating the blockchain-based data traceability management method for grain quality testing, as described in this application.

[0021] Figure 2 This is a schematic diagram of the structure of the blockchain-based grain quality testing data traceability management system proposed in this application.

[0022] In the attached diagram, the components represented by each number are as follows:

[0023] Anti-counterfeiting label generation module 11, quality inspection module 12, inspection result judgment module 13, and quality inspection evidence chain reconstruction module 14. Detailed Implementation

[0024] This application provides a blockchain-based method for the traceability and management of grain quality testing data, addressing the problems in existing technologies such as reliance on manual sampling, low real-time information detection, lack of verification in data management and storage, and low efficiency in data monitoring and judgment.

[0025] The present invention will now be described in detail with reference to the accompanying drawings.

[0026] Example 1, as Figure 1 As shown, this application provides a blockchain-based method for traceability management of grain quality testing data, the method comprising:

[0027] S10: In the grain sampling process, a sampling data packet containing sample information is collected and a first hash value is calculated and submitted to the blockchain network to generate a first transaction record. Based on the first transaction record, a physical anti-counterfeiting label is generated and attached to the grain sample.

[0028] In this embodiment, the sampling data packet is a set of structured data collected by a dedicated device during grain sampling, used to uniquely identify and describe the sample; the first hash value is a fixed-length, unique digital fingerprint obtained by calculating the sampling data packet using a cryptographic hash function; the first transaction record is a record that is packaged and permanently stored in the network after the transaction is confirmed by the blockchain network, publicly verifiable and tamper-proof; the physical anti-counterfeiting label is an entity label made based on the unique identifier of the first transaction record generated on the blockchain.

[0029] Specifically, sampling personnel use dedicated terminals to collect multidimensional data on-site. After forming a complete sampling data packet, the terminal immediately signs the data packet using the sampler's private key and calculates the first hash value. When the first hash value and signature are sent to the blockchain network, an immutable first transaction record is generated after confirmation. Finally, the system generates a QR code or RFID tag based on the on-chain address of the first transaction record, serving as a digital identity.

[0030] Step S10 in the method provided in this application embodiment includes:

[0031] The sampling terminal, equipped with a security encryption module, collects the geographical coordinates of the grain samples, the sampling time point, the environmental images of the sampling site, the temperature and humidity data of the sampling site, and the grain batch identifier, and generates a sampling data package.

[0032] The dedicated sampling terminal uses the sampling personnel's digital private key to digitally sign the sampling data packet and calculates the hash value of the sampling data packet as the first hash value;

[0033] The dedicated sampling terminal submits a sampling and evidence storage transaction containing a first hash value and the sampling personnel's digital certificate to the blockchain network. After verifying the digital signature in the sampling and evidence storage transaction, the blockchain network generates a first transaction record corresponding to this sampling in the blockchain network and returns a unique identifier of the first transaction record to the dedicated sampling terminal.

[0034] The dedicated sampling terminal generates a physical anti-counterfeiting label based on the unique identifier of the first transaction record and attaches the physical anti-counterfeiting label to the packaging of the collected grain sample.

[0035] In this embodiment, a dedicated sampling terminal equipped with a security encryption module first collects the geographical coordinates of the grain sample, the sampling time point, images of the sampling site environment, temperature and humidity data of the sampling site, and the grain batch identifier, generating a sampling data package. The dedicated sampling terminal is a specialized electronic device custom-developed for the grain sampling process. The security encryption module is a hardware security chip integrated into the dedicated sampling terminal or a software encryption environment achieving an equivalent security level.

[0036] Specifically, the process begins by acquiring the geographical coordinates, sampling time, environmental images of the sampling site, temperature and humidity data, and grain batch identifiers of the grain samples using a dedicated sampling terminal. This acquired data is then packaged into a sampling data package for the grain samples. The sampling terminal includes a core closed system to prevent the installation of unauthorized software and incorporates the necessary security modules and sensors. Specifically, it obtains precise geographical coordinates via built-in GPS; automatically records the sampling time; captures environmental images of the sampling site using a camera; and simultaneously reads temperature and humidity data from the sampling site using connected external or built-in sensors, ensuring the objectivity of the data source and the consistency of the data structure.

[0037] Secondly, after the dedicated sampling terminal generates the sampling data packet, it first uses the digital private key stored in a secure area by the sampling personnel to calculate a digital signature for the entire sampling data packet. The terminal then calculates the hash value of the sampling data packet, which serves as the first hash value. Associating the first hash value with the digital private key through the digital signature ensures data security. The digital private key is a secret parameter in asymmetric cryptography, paired with a publicly available digital certificate, and is exclusively possessed by the sampling personnel and securely stored in the secure encryption module of the dedicated terminal. The digital signature is the result of encrypting the data using the digital private key. The hash value is a fixed-length string calculated by inputting the entire sampling data packet into a cryptographic hash function.

[0038] Furthermore, a sampling and evidence storage transaction refers to a data request in a specific format constructed to store the fingerprint of sampled data into the blockchain. It typically includes a first hash value, the sampler's digital certificate containing a public key, digital signature, and other metadata. Blockchain network verification is the process by which blockchain nodes check transactions according to network consensus rules after receiving them.

[0039] Specifically, the dedicated sampling terminal packages the first hash value, the sampler's digital certificate, and the previously generated digital signature to construct a sampling and evidence preservation transaction. The terminal submits this transaction to the blockchain network. Upon receiving the transaction, nodes in the network first verify the validity of the sampler's digital certificate, then use the public key in the certificate to verify the signature, confirming it is a valid signature of the first hash value. After successful verification, the transaction is packaged into a new blockchain network as the first transaction record, and a unique identifier is generated and returned to the dedicated sampling terminal that initially submitted the transaction. The sampling evidence has thus completed sampling notarization.

[0040] Ultimately, the dedicated sampling terminal generates a physical anti-counterfeiting label based on the unique identifier of the first transaction record and affixes it to the packaging of the collected grain samples. Specifically, after receiving the unique identifier returned by the blockchain network, the dedicated sampling terminal calls the physical anti-counterfeiting label generation program, using the unique identifier as input to generate and print the physical anti-counterfeiting label. Sampling personnel then affix the newly generated physical anti-counterfeiting label to the packaging of the collected grain samples. By scanning the physical anti-counterfeiting label, all original sampling evidence stored on the blockchain can be retrieved and verified at any time.

[0041] In this embodiment, a dedicated sampling terminal equipped with a security encryption module collects the geographical coordinates, sampling time, environmental images of the sampling site, temperature and humidity data of the sampling site, and grain batch identifier of the grain sample to generate a sample data package, providing a sufficient data foundation for subsequent processing. The dedicated sampling terminal then digitally signs the sample data package using a digital private key and calculates a first hash value. Obtaining the digital signature through the digital private key ensures the security of data acquisition. The first hash value is submitted along with the sampling and storage transaction of the sampling personnel's digital certificate. After digital signature verification, a first transaction record is generated, and a unique identifier for the first transaction record is returned to the sampling terminal. The submission process involves reverse verification through the digital signature of the first transaction record, returning the unique identifier. This dual verification ensures the rigor of data management and improves data reliability. Finally, the unique identifier is used to generate a physical anti-counterfeiting label, which is attached to the grain sample packaging for subsequent security verification based on the anti-counterfeiting label.

[0042] S20: In the detection process, the physical anti-counterfeiting label is read to obtain on-chain information, detection start data is generated and the second hash value is calculated and stored in the blockchain network. The key process data in the detection process is continuously calculated as process hash value and stored in the blockchain network in time sequence to form a process hash chain.

[0043] In this embodiment, the detection start data is a dataset that marks the official start of a specific detection task, integrating on-chain sampling information parsed from the tags, the unique hardware identifier of the detection instrument, the task number of this detection, and a precise detection start timestamp; the second hash value is the digital fingerprint obtained after hash calculation of the detection start data; the key process data is the data generated in the analysis process of the grain quality testing laboratory that has a significant impact on the results or can prove the standardization of operations; the process hash value is the hash fingerprint of each key process data; the process hash chain refers to submitting the hash values ​​of each process to the blockchain network in the order of their generation. Due to the temporal characteristics of the blockchain, the hash value recorded in the later process can implicitly contain the hash of the previous block, or reference the transaction ID of the previous process in the transaction content, thus logically forming a tightly linked and strictly ordered data chain.

[0044] Specifically, the system first scans the sample label, then automatically queries and verifies the corresponding sampling record from the blockchain. Next, the trusted adapter of the testing instrument combines the device identity and task information to generate testing initiation data, calculates a second hash value, and immediately uploads it to the blockchain for evidence storage. During the testing process, the adapter automatically captures the status data of preset key nodes, calculates the process hash value, and submits it to the blockchain, ultimately integrating them to form a process hash chain.

[0045] Step S20 in the method provided in this application embodiment includes:

[0046] The testing instrument reads the physical anti-counterfeiting label attached to the grain sample packaging through a scanning device, and parses the unique identifier of the first transaction record from the physical anti-counterfeiting label;

[0047] The trusted adapter built into the detection instrument generates detection start data based on the unique identifier of the first transaction record, combined with the device hardware fingerprint of the detection instrument, the project code of this detection task, and the detection start timestamp.

[0048] The trusted adapter calculates the hash value of the detection startup data and submits the hash value as a second hash value to the blockchain network for evidence storage.

[0049] During the testing process, the trusted adapter obtains key process data from the testing instrument according to preset key step nodes and calculates the hash value of the key process data as the process hash value. Each process hash value, together with the corresponding timestamp, is submitted to the blockchain network in chronological order to form a process hash chain associated with the second hash value. The key step nodes include at least sample pretreatment completion, testing instrument calibration completion, and testing analysis completion.

[0050] In this embodiment, when a grain sample with a physical anti-counterfeiting label is ready for testing, the testing personnel place the sample in front of the testing instrument. The instrument's built-in or external scanning device scans the physical anti-counterfeiting label on the sample packaging. The raw data obtained from the scan is transmitted to the control software of the testing instrument and parsed according to predetermined encoding rules to extract the unique identifier of the first transaction record from the characters. The testing instrument is a professional grain quality testing device adapted to this traceability system module through modification or integration; it can be a near-infrared spectroscopy analyzer, liquid chromatograph, mycotoxin detector, etc. The scanning device is an automatic identification device integrated into or connected to the testing instrument; it can be a QR code scanner or RFID reader / writer.

[0051] Secondly, after parsing the sampling identifier, the trusted adapter built into the testing instrument is activated. First, it uses its securely stored key information to generate or retrieve the registered device hardware fingerprint. Then, it combines this with the project code for this testing task synchronized from the laboratory information management system and obtains the testing start timestamp generated by the secure clock. Finally, it combines these three pieces of information with the unique identifier of the first transaction record to generate testing start data according to a predetermined format. The trusted adapter is a key secure hardware module or protected core software component within the testing instrument, responsible for establishing a trusted channel between the testing instrument and the blockchain network; the device hardware fingerprint is a cryptographic identifier generated based on its inherent hardware characteristics, used to bind the responsible party for the testing behavior on the blockchain; and the project code is the number assigned to this specific testing task.

[0052] Next, after generating the detection startup data, the trusted adapter immediately calculates a hash value locally, which serves as the second hash value. Then, the trusted adapter digitally signs the second hash value using the detection instrument's device private key, proving that the startup action originated from a trusted device. Next, the trusted adapter packages the second hash value, the device digital signature, and the device certificate and submits them to the blockchain network. After verifying the validity of the device signature, the network node records it on the chain, generating a detection startup notarization transaction record. Notarization involves uploading the detection startup notarization transaction based on the second hash value to the blockchain network, awaiting confirmation and permanent recording by the blockchain network.

[0053] Finally, after the detection starts, the trusted adapter enters the monitoring state. When it runs to the critical step node, the trusted adapter obtains the key process data corresponding to the node from the detection instrument through the data interface. Immediately calculate the hash value to obtain the process hash value, and attach an accurate timestamp. Subsequently, the trusted adapter submits the process hash value to the blockchain. Repeat the generation and uploading of the process hash value before the detection analysis completion node. Finally, record all the hash values in chronological order to obtain the process hash chain. Any unauthorized person can verify the integrity and order of the process hash chain, but cannot obtain the generated data, which strengthens the privacy of the data while ensuring the transparency and trustworthiness of the process.

[0054] Exemplarily, after the detection is started, at the critical step node 1: completion of sample pretreatment, the trusted adapter captures the data, calculates the process hash value H1, timestamp T1, and submits it to the blockchain. Generate the start deposit transaction T1. At the critical step node 2: completion of detection instrument calibration, the trusted adapter captures the data, calculates the process hash value H2, timestamp T2, and submits it to the blockchain. Generate the start deposit transaction T2. And reference the unique identifier of T1 in the data to strengthen the association. At the critical step node 3: completion of detection analysis, the trusted adapter captures the data, calculates the process hash value H3, timestamp T3, and submits it to the blockchain. Generate the start deposit transaction T3. Finally, form a hash chain. On the blockchain, the start deposit transactions T0, T1, T2, T3 are arranged in the order of timestamp T0 < T1 < T2 < T3. Through business logic query, a process hash chain from start to analysis completion can be obtained.

[0055] In the embodiment of the present application, the physical anti-counterfeiting label on the sample package is read by the scanning device, and the unique identifier of the first transaction record is parsed. The trusted adapter is combined with the detection instrument to generate the detection start data. The unique identifier data is obtained by parsing, and the detection start data is generated according to the hardware device data of the detection instrument and the detection start timestamp, avoiding sample confusion or human input errors, and ensuring the source credibility of the detection object. Subsequently, calculate the second hash value of the detection start data and submit it to the blockchain network to establish a trusted deposit with device identity, task attributes, and accurate time. During the detection process, the trusted adapter captures the process data, calculates the process hash value, and uploads it to the blockchain in chronological order according to the preset key nodes during the detection process, forming a process hash chain, which provides a solid data basis for evaluating the standardization and consistency of the detection process by recording the transparency, real-time, and tamper-proof of the core detection operations inside the laboratory throughout the process.

[0056] S30: After the detection is completed, submit the detection result data and the corresponding result hash value to the blockchain network, perform trusted verification and standard compliance determination on the full-chain data of this detection through the preset smart contract, and deposit the generated determination conclusion as a determination transaction record into the blockchain network;

[0057] In this embodiment, the test result data is the final quantitative result of the grain quality index; the result hash value is the hash fingerprint of the test result data; the smart contract is a piece of automatically executable program code deployed on the blockchain; the trusted verification is the integrity check process of all blockchain data involved in this test, automatically executed by the smart contract; the standard compliance judgment is the judgment conclusion obtained by the smart contract by comparing the test result data with the standard limit according to the currently effective national grain quality standards; the judgment conclusion is the final ruling result output by the smart contract after performing trusted verification and standard compliance judgment; and the judgment transaction record is a new blockchain transaction record containing the judgment conclusion and key evidence of the smart contract execution process.

[0058] Specifically, after the final test result is generated, the hash value of the result is immediately calculated and submitted to the blockchain, simultaneously triggering the standard compliance smart contract deployed on the blockchain. Once activated, the contract first performs trusted verification, automatically extracting all hash values ​​related to this task from the blockchain. Only after all trusted verifications pass does the contract enter the standard compliance judgment stage, comparing the test results and generating a judgment conclusion. Finally, the contract packages the judgment conclusion along with key evidence from the verification process into a judgment transaction record and stores it on the blockchain. This constitutes the final quality judgment.

[0059] Step S30 in the method provided in this application embodiment includes:

[0060] After the test is completed, the test result data and the corresponding result hash value are submitted to the blockchain network, triggering the pre-set standard compliance smart contract in the blockchain network to perform integrity verification, one-time verification and correlation verification operations on the test data;

[0061] The standard compliance smart contract extracts and calculates the time-series deviation metric, statistical consistency metric, and instrument status metric for this test from the blockchain network;

[0062] After the integrity verification, single-use verification and correlation verification operations are all passed, the standard compliance smart contract calls the grain testing process credibility assessment model, inputs the time series deviation metric, statistical consistency metric, and instrument status metric, and outputs the comprehensive credibility score of this testing process.

[0063] If the overall credibility score is higher than the preset credibility threshold, the standard compliance smart contract will continue to execute the standard compliance judgment logic, automatically compare the test result data with the current grain quality standard rules stored in the blockchain network, and generate the final judgment conclusion.

[0064] The standard compliance smart contract will combine the final judgment conclusion, comprehensive credibility score, the time series deviation metric, statistical consistency metric, instrument status metric, and standard rule version number to generate a judgment transaction record and store it in the blockchain network.

[0065] In this embodiment, after the detection is completed, the detection result data and its calculated result hash value are packaged into a result submission transaction and sent to the blockchain network. Subsequently, the standard compliance smart contract on the blockchain that listens for the result submission transaction is automatically triggered and activated, performing integrity verification, one-time verification, and correlation verification on the detection data. Specifically, the result hash value is a unique digital fingerprint obtained by cryptographically hashing the detection result data; the pre-set standard compliance smart contract is a program already deployed on the blockchain network; the integrity verification confirms that the submitted result data is consistent with its pre-registered hash fingerprint on the chain, preventing data tampering after submission and before being uploaded to the chain; the one-time verification ensures that the second hash value can only be used to generate a final judgment once; and the correlation verification checks whether all on-chain records from sampling to the end of the detection reference each other through hash pointers, forming a complete chain of evidence.

[0066] Secondly, after the basic verification is passed, the standard compliance smart contract first extracts the timestamps of each step from the hash chain record of this test process, calculates the actual interval, and compares it with the recommended time interval of the standard operating procedure stored on the chain to generate a time-series deviation metric. A higher time-series deviation metric indicates a more standardized operating rhythm and a lower probability of rushed or delayed operations. Next, based on the batch number of the sample, it queries the historical test results of all other samples in this batch on the blockchain, constructs a statistical distribution model, and substitutes the current result into the calculation to generate a statistical consistency metric. A higher consistency metric indicates that the current result is more consistent with the expected overall quality distribution of the batch of grain, and the risk of outliers is lower. Then, based on the device fingerprint in the test initiation data, it queries the corresponding device's work logs before and after this task, analyzes its task density and type, and generates an instrument status metric. Among them, the time deviation metric is used to evaluate the compliance and standardization of the experimental operation process in the time dimension; the statistical consistency metric is used to evaluate the rationality and credibility of the test results in the data dimension; and the instrument status metric is used to evaluate the stability of the instrument undertaking the test task in the operational status dimension.

[0067] Next, the calculated values ​​for integrity verification, single-use verification, and correlation verification are input into the grain testing process credibility assessment model. The time-series deviation metric, statistical consistency metric, and instrument status metric are used as input values. The model assesses the credibility of integrity verification, single-use verification, and correlation verification, ultimately outputting a comprehensive credibility score. This score is then compared with a preset credibility threshold to generate a further judgment. The grain testing process credibility assessment model quantifies the overall process credibility level reflected by the combined effect of the three metrics; the comprehensive credibility score comprehensively reflects the overall credibility of the testing process in terms of operational timing, statistical reasonableness of results, and instrument operating status.

[0068] Meanwhile, if the overall credibility score is lower than the preset credibility threshold, the test is deemed unreliable and ineligible for standard compliance assessment. Conversely, if the overall credibility score is higher than the preset credibility threshold, the test results are considered highly credible and eligible for standard compliance assessment. This triggers the standard compliance smart contract to continue executing the standard compliance assessment logic. First, the current grain quality standards applicable to the tested grain category are retrieved from the on-chain standard library. Then, the corresponding indicator values ​​are extracted from the submitted test result data and compared item by item with the limits in the standard rules. All comparisons are automatically completed based on the logic written in the code. Finally, based on the comparison results of all indicators, a clear final assessment conclusion is generated. The preset credibility threshold represents the minimum process credibility standard accepted by regulatory requirements or the quality management system.

[0069] For example, if the calculated time series deviation metric, statistical consistency metric, and instrument condition metric are TD=95, SC=88, and IS=92 respectively, then using the values ​​[95, 88, 92] as input, the grain testing process reliability assessment model is called, and the overall reliability score is output as 90.5. The preset reliability threshold is 80. Since 90.5 > 80, the condition is met, and a standard compliance judgment is performed.

[0070] Finally, after generating the final judgment, the standard compliance smart contract packages the final judgment, comprehensive credibility score, time series deviation metric, statistical consistency metric, instrument status metric, and the version number of the referenced standard rule into a judgment transaction record. The contract signs the judgment transaction record using its own contract account and submits it as a new transaction to the blockchain network. Once confirmed by the network, the record containing the complete judgment chain is permanently archived, becoming blockchain evidence for grain quality testing. The judgment transaction record is the smart contract's judgment data for this testing task.

[0071] In step S30 of the method provided in this application embodiment, the pre-set standard compliance smart contract in the blockchain network is triggered to perform integrity verification, one-time verification, and correlation verification operations on the data to be tested, including:

[0072] Extract the hash value of the results recorded for this detection task from the blockchain network, recalculate the hash value of the detection result data submitted this time, obtain the hash value of the submitted data, and compare the hash value of the submitted data with the hash value of the recorded results to confirm that the detection result data has not been tampered with since submission.

[0073] Extract the second hash value corresponding to this detection task from the blockchain network, and verify whether there is a corresponding valid record for the second hash value in the blockchain network. If there is a valid record, verify that the second hash value record has not been marked as being used for any previous judgment conclusion generation, so as to confirm the uniqueness and validity of this detection process.

[0074] Extract the first hash value, the second hash value, and all process hash values ​​contained in the process hash chain corresponding to this detection task from the blockchain network. Verify whether the first hash value is referenced by the transaction record where the second hash value is located, and verify whether each process hash value forms a continuous reference chain pointing to the second hash value in the blockchain network in chronological order, so as to confirm that the entire chain of data from sampling to detection is logically consistent and not fragmented.

[0075] In this embodiment, firstly, after the standard compliance smart contract is triggered, it is necessary to locate the result submission transaction related to this judgment task. The result hash value recorded on the blockchain is extracted from the content of the result submission transaction. Simultaneously, the standard compliance smart contract must obtain the complete content of the detection result data that triggered the current submission and recalculate the hash value using the same hash function. Finally, the contract executes the comparison logic: if the recorded result hash value is equal to the recalculated hash value, the verification passes, proving that the detection result data has not been tampered with in any way from the time the data was submitted to the blockchain to the time the smart contract started verification; otherwise, the verification fails, indicating that the data integrity has been compromised, and the contract will terminate all subsequent judgment processes and may record an abnormal event indicating a data integrity verification failure. The recorded result hash value is the hash value independently recorded on the blockchain as part of the result submission transaction when the detection result data is first submitted to the blockchain network.

[0076] Secondly, after passing integrity verification, the standard compliance smart contract locates the second hash value corresponding to this testing task based on the current context. Next, it queries the blockchain network to verify if a valid transaction record containing the second hash value exists. If no valid record is found, it indicates that the testing initiation process was not notarized by the blockchain, and the process is invalid. If a valid record is found, the standard compliance smart contract further checks the global state variables of the valid record to see if it has been marked as having already been used to generate a judgment conclusion. This is typically done by querying the used second hash value mapping table maintained by the smart contract. If it is not marked, the verification passes, indicating that this test is the first time it has been used to apply for a judgment; if it has been marked, the verification fails, indicating the possibility of duplicate report generation using the same test data, and the standard compliance smart contract will refuse to execute. This ensures the uniqueness of this testing process.

[0077] Finally, the first hash value, the second hash value, and all process hash values ​​contained in the process hash chain corresponding to this detection task are extracted from the blockchain network. It is verified whether the first hash value is referenced by the transaction record containing the second hash value, and whether each process hash value forms a continuous chain of references pointing to the second hash value in the blockchain network in chronological order. This confirms that the entire chain of data from sampling to detection is logically coherent and not fragmented. Here, a reference is defined as a transaction in the blockchain transaction data structure explicitly containing a mention of the transaction hash or hash value of another previous transaction.

[0078] Specifically, the standard compliance smart contract first verifies the binding relationship between sampling and detection. It extracts the first and second hash values, then checks whether the transaction record containing the second hash value references the first hash value or its corresponding sampling transaction in its data fields. If a reference exists, it indicates that the sample has been explicitly tested; otherwise, sampling and detection are disconnected. Secondly, the standard compliance smart contract verifies the continuity of the internal detection process. It extracts all process hash values ​​and their corresponding transactions from the process hash chain, checking whether a chain extending from the second hash value is formed through references between transactions and according to the blockchain timestamp order. If all process hash values ​​can be found in their corresponding positions on the process hash chain, it proves that the detection process record is complete; if there are broken references, reversed timestamps, or missing transactions at a key node, it indicates that the process record is incomplete or its order has been tampered with.

[0079] In step S30 of the method provided in this application embodiment, extracting and calculating the time series deviation metric, the statistical consistency metric, and the instrument status metric from the blockchain network includes:

[0080] Based on the timestamps of each record in the hash chain of this detection process in the blockchain network, the actual time interval between nodes of key steps is calculated;

[0081] Each actual time interval is compared with the pre-stored recommended time interval for the corresponding step to generate a time deviation metric that characterizes the time sequence compliance of this detection process.

[0082] Query the historical testing records of other samples from the same grain batch as the sample tested in this test from the blockchain network, and extract the corresponding historical test result data;

[0083] Based on the historical test results data, a historical numerical statistical distribution of key quality indicators is constructed, and the corresponding indicator values ​​in the current test results data are compared with the historical numerical statistical distribution. By calculating the relative position of the corresponding indicator values ​​to the mean of the historical numerical statistical distribution, a statistical consistency measure that characterizes the consistency between the current test results and the historical results of the same batch is generated.

[0084] Based on the device hardware fingerprint recorded in the data from this test start-up, query all other test task records of the testing instrument within the preset time interval before and after this test task.

[0085] Analyze the time distribution and task type of the other detection task records and their correlation with the current detection task to generate instrument status metrics that characterize the stability of the operating status and task exclusivity of the detection instrument during the current detection task.

[0086] In this embodiment, the actual time interval between key step nodes is first calculated based on the timestamps of each record in the hash chain of the current testing process within the blockchain network. Specifically, the actual time interval is calculated using these timestamps to determine the time difference between the recording of two adjacent key step nodes onto the chain. When the standard compliance smart contract needs to calculate timing deviations, it first queries and extracts all transaction records contained in the process hash chain from the blockchain network based on the unique identifier of this testing task. Then, it reads the timestamp of each transaction record from its metadata and synchronizes the time using the blockchain network's synchronous clock. Following the logical order of the testing process, it calculates the difference between the timestamps of adjacent steps to obtain the actual time interval. This reflects the real time consumed in each key step of the testing process, providing raw data for subsequent comparison with standard operating procedures.

[0087] For example, firstly, the on-chain records and their timestamps related to this detection are retrieved: Detection start record timestamp T0:14:00:05; Preprocessing completion record timestamp T1:14:30:25; Calibration completion record timestamp T2:14:45:10; Analysis completion record timestamp T3:15:30:15; Calculate the actual intervals: T1-T0=30min20s; T2-T1=14min45s; T3-T2=45min5s, obtaining actual time intervals of 30min20s, 14min45s, and 45min5s respectively.

[0088] Secondly, each actual time interval is compared with the pre-stored recommended time intervals for the corresponding steps to generate a time deviation metric that characterizes the time compliance of the testing process. The pre-stored recommended time intervals are reasonable time ranges set for each key testing step according to the standard operating procedures stipulated by the laboratory accreditation quality management system. The time deviation metric is a comparable indicator that aggregates the time compliance of multiple steps using a specific algorithm. Specifically, after obtaining the actual time intervals for each step, the standard compliance smart contract retrieves the recommended time intervals for the corresponding steps from on-chain storage. Then, the standard compliance smart contract compares each actual time interval with the corresponding recommended interval. This comparison is performed by calculating the score based on whether the actual value falls within the interval. Finally, the standard compliance smart contract comprehensively calculates the comparison scores of each step according to the importance of each step in the overall process, ultimately generating the time deviation metric. A higher value indicates that the entire testing process is more compliant with regulations in the time dimension.

[0089] For example, based on the three calculated actual intervals, recommended intervals are retrieved from the on-chain SOP library: the recommended interval for preprocessing is [25, 35] min; the recommended interval for calibration is [10, 20] min; and the recommended interval for analysis is [40, 50] min. Through comparison and calculation, it is found that: preprocessing takes 30 min 20 s, falling within the [25, 35] interval, with a score of 100; calibration takes 14 min 45 s, falling within the [10, 20] interval, with a score of 100; and analysis takes 45 min 5 s, falling within the [40, 50] interval, with a score of 100. Finally, the time series deviation metric is calculated as (100 + 100 + 100) / 3 = 100.

[0090] Furthermore, the system queries the blockchain network for historical testing records of other samples belonging to the same grain batch as the sample tested this time, and extracts the corresponding historical testing results data. These other samples belonging to the same grain batch are all grain samples in the blockchain traceability system that are labeled with the exact same grain batch identifier as the current sample; historical testing records are the testing task data of the aforementioned other samples in the same batch that have been fully verified through the blockchain; historical testing results data are the final testing results extracted from the historical testing records. Specifically, the standard compliance smart contract first extracts the grain batch identifier from the context information of this test. Then, using this batch identifier as the key query condition, it searches the blockchain network for all historical testing records containing this batch identifier that have been judged. Due to the immutable and traceable nature of blockchain data, authentic and valid historical testing records can be obtained. The standard compliance smart contract extracts the historical testing results data for each record, forming the original dataset for statistical comparison.

[0091] Furthermore, based on historical test result data, a historical statistical distribution of key quality indicators is constructed. The corresponding indicator values ​​in the current test result data are compared with these historical statistical distributions. By calculating the relative position of the corresponding indicator value to the mean of the historical statistical distribution, a statistical consistency metric is generated, representing the consistency between the current test result and historical results from the same batch. Specifically, after obtaining the historical data set of a certain indicator from the same batch, the standard compliance smart contract first calculates the mean and standard deviation of the historical data set to construct a simplified statistical distribution model. Then, the corresponding indicator value X is extracted from the current test result data, and the relative position Z = (X - μ) / σ is calculated based on the corresponding indicator value and the mean and standard deviation of the historical data set. Finally, according to a preset scoring function, with base e, the ratio of the square of -Z to 2 is used as the exponent to map the Z value to a statistical consistency metric, where the statistical consistency metric = 100 × exp[ ... (-Z² / 2) When Z=0, the score is 100 points. The larger the absolute value of Z, the score decreases exponentially.

[0092] For example, suppose we have 20 historical data points, where the mean μ = 13.2% and the standard deviation σ = 0.3%. The protein content detected in this study is X = 13.5%. The relative position Z = (13.5% - 13.2%) / 0.3% = 1.0. The statistical consistency measure = 100 × exp[[...]]. (-1.0² / 2) ≈60.65.

[0093] Furthermore, based on the device hardware fingerprint recorded in the data initiating this test, all other test task records of the testing instrument within a preset time interval before and after this test task are queried. The preset time interval before and after is a time window defined by system rules or smart contract parameters; other test task records are all test task records executed by the same testing instrument and recorded on the blockchain within the preset time interval, excluding this test task. Specifically, the standard compliance smart contract first extracts the device hardware fingerprint from the test initiation data of this test. Then, a reasonable preset time interval is determined, assuming it can be based on the start time T0 of this test, extending before and after by a period of time (a hours) to form a query window [T0-a, T0+ΔT+a], where ΔT is the total estimated duration of this test. Further, using the device fingerprint and time window as conditions, all other test task records that meet the conditions are queried in the blockchain network. The query results list includes information such as the identifier, start time, and task type of all other test tasks initiated on the same instrument within that time period.

[0094] Finally, the temporal distribution and task types of other testing task records are analyzed to determine their correlation with the current testing task. This analysis generates instrument status metrics that characterize the stability and task exclusivity of the testing instrument during the current testing task. The temporal distribution refers to the arrangement of other testing task records on the timeline, primarily examining their temporal overlap and interval density with the current testing task. The correlation between task types and the current testing task indicates whether the testing items of other tasks are the same as those of the current testing task, or whether they require the same testing modules, reagents, or pretreatment methods.

[0095] Specifically, after obtaining records from other testing tasks, the time distribution is first analyzed to check if any task time intervals overlap with the core execution period of this task. If there is overlap, it indicates the instrument may be operating in parallel, resulting in significant point deductions. Secondly, the density of other tasks in the immediate preceding and following time periods of this task is checked. Excessive density may indicate insufficient instrument maintenance or calibration. Subsequently, task correlation is analyzed. If other tasks are highly related to the type of this task, continuous testing may lead to contamination due to incomplete cleaning; if the types are completely different, rapid switching may affect instrument stability. Finally, the contract quantifies the analysis results into instrument status metrics according to preset scoring rules.

[0096] For example, a query retrieves another task record: Moisture Detection, started at 15:45:00. Analysis time distribution: The protein detection analysis was completed at 15:30:15. The moisture detection started at 15:45:00, approximately 15 minutes apart, therefore there is no time overlap. No other tasks were inserted during this task's execution. Analysis of task correlation: Protein detection and moisture detection use different detection principles and modules, resulting in low correlation. According to the rules, no overlap and reasonable task intervals (>10 minutes) earn high scores; irrelevant task types do not incur additional deductions. After comprehensive calculation, the instrument status metric is 92 points, indicating that the instrument's working state was focused and stable during this task.

[0097] In this embodiment, the integrity, singleness, and relevance of smart contract execution are verified by triggering the process. Three metrics—timing deviation, statistical consistency, and instrument status—are introduced for credibility assessment. By calculating these three metrics and applying a comprehensive credibility score, the operational quality and reasonableness of the testing process are, for the first time, quantifiable evaluation criteria are applied. This identifies potential risks such as rushed operations, abnormal results, and unstable instrument status, significantly improving the credibility of the process upon which the judgment conclusions rely. Based on verified data and credibility assessments, the smart contract is driven to automatically execute standard compliance judgments, ensuring the objectivity and consistency of quality assessments. Furthermore, the inputs and conclusions of the adjudication process are permanently stored as judgment transaction records, forming a reliable judgment process and enhancing the credibility of grain quality testing reports. Ultimately, this achieves automated standard compliance judgment, transforming traditional manual review and judgment work into a highly efficient, code-driven verification process.

[0098] S40: Based on the judgment transaction record, extract and verify the correlation between the first hash value, the second hash value, the process hash chain, the result hash value and the judgment transaction record from the blockchain network, and reconstruct a complete evidence chain for grain quality testing.

[0099] In this embodiment, the traceability request is a query request initiated by any authorized party to the system to understand the quality testing details of a batch of grain; the association verification is the active verification of all hash values ​​stored on the blockchain during traceability to see if they form a chain through the hash pointers of transaction records; the reconstruction of the complete grain quality testing evidence chain is the evidence chain formed by the system reorganizing key information scattered in different blocks and transactions of the blockchain according to the verified association, in chronological and logical order.

[0100] Specifically, when relevant parties need to trace back, starting with the identified transaction record, all related transactions are crawled from the blockchain in reverse. Verification is then performed: checking whether each transaction is authentic and valid; checking whether the referencing relationships between transactions are correct. After successful verification, the original data fragments are reorganized according to the timeline from sampling to judgment to generate a full-chain evidence report.

[0101] Step S40 in the method provided in this application embodiment includes:

[0102] The blockchain network receives a traceability request, wherein the traceability request includes a unique identifier for determining the transaction record or a batch identifier for the grain to be traced;

[0103] Based on the unique identifier or batch identifier, query and extract all on-chain transaction records related to this testing task from the blockchain network. The all on-chain transaction records include sampling and evidence storage transaction records, testing initiation and evidence storage transaction records, process hash chain evidence storage transaction records, testing result data submission transaction records, and judgment transaction records.

[0104] Based on all the on-chain transaction records, verify whether the first hash value, the second hash value, the process hash values ​​in the process hash chain, the result hash value, and the judgment conclusion form a logically continuous and tamper-proof chain of evidence through the hash pointer reference relationship of the transaction records.

[0105] After verification, the key information of all on-chain transaction records is organized in chronological order to generate and output a structured full-chain evidence report for grain quality testing.

[0106] After generating the full-chain evidence report for grain quality testing, the test results data of this test, along with the recalculated time-series deviation metric, statistical consistency metric, and instrument status metric, are input into the pre-trained quality risk early warning model. The model outputs the future quality deterioration risk level of this batch of grain and obtains the process anomaly risk score and suspicious link location information for this test task through the process anomaly monitoring process.

[0107] The future quality deterioration risk level, key influencing factor analysis, process anomaly risk score, and suspicious link location information are added as supplementary information to the grain quality testing full-chain evidence report to complete and output an enhanced grain quality testing evidence chain.

[0108] In this embodiment, the blockchain network first receives a traceability request, which includes a unique identifier for the transaction record or a batch identifier for the grain to be traced. The traceability request is a formal query instruction initiated by an external user to the blockchain network or the traceability platform with which it interacts, in order to obtain a complete and verifiable quality inspection history of a batch of grain. Specifically, the system continuously listens for and receives traceability requests from users. The traceability request must contain a valid query key, a unique identifier for the transaction record, or a batch identifier for the grain to be traced. Subsequently, after receiving the traceability request, the system parses the identifier in the traceability request and prepares to proceed with data retrieval.

[0109] Secondly, based on the unique identifier or batch identifier, all on-chain transaction records related to this testing task are queried and extracted from the blockchain network. These on-chain transaction records include sampling and evidence storage transactions, testing initiation and evidence storage transactions, process hash chain evidence storage transactions, test result data submission transactions, and judgment transactions. These on-chain transaction records constitute the blockchain evidence of all independent stages of the complete grain quality testing activity.

[0110] Specifically, the system employs different query strategies based on the type of identifier received. If the input is a unique identifier for a judgment transaction record, it first queries this judgment transaction, parses the detection result data submission transaction record from its transaction content, and then traces back to find the process chain, detection initiation, and sampling record. If the input is a batch identifier, the system queries the event log indexed by batch in the smart contract to find all sampling and evidence storage transaction records related to the batch and the final judgment transaction record, and then selects one of the detections for in-depth tracing. Finally, through tracing, all on-chain transaction records constituting the detection evidence chain are extracted.

[0111] Furthermore, based on all on-chain transaction records, it is verified whether the first hash value, the second hash value, the process hash values ​​in the process hash chain, the result hash value, and the judgment conclusion form a logically continuous and tamper-proof evidence chain through the hash pointer reference relationship between transaction records. Here, the hash pointer reference relationship is a fundamental characteristic of blockchain data structure; transaction data content can also contain references to other related transaction hashes. The logically continuous and tamper-proof evidence chain starts from the first hash value and ends at the final judgment conclusion. The second hash value, each process hash value, and the result hash value in between can be linked together through the hash pointer reference relationship between transactions, forming a reference network. Furthermore, the hash value of each link corresponds to the original data, and the entire network is coherent in both time and logic.

[0112] Specifically, after aggregating all transaction records, the system initiates an automatic verification process. First, it checks the validity of each transaction itself. Then, it focuses on verifying the reference relationships between transactions: checking if the detection start record references the hash of the sampling record; checking if each process record references the process record of the detection start record; checking if the result submission record references related process records or start records; and finally checking if the judgment record explicitly references the result submission record. Simultaneously, all timestamps are compared to obtain the order: Sampling < Start < Process 1 < Process 2 < Process 3 < Result < Judgment. Only when all these reference relationships exist, are correct, and are chronologically ordered, is it determined to be a logically continuous and tamper-proof chain of evidence. Any missing or incorrect reference in any link indicates a broken chain of evidence or potential tampering, and verification will fail.

[0113] Furthermore, after successful verification, the system organizes key information from all on-chain transaction records chronologically to generate and output a structured end-to-end evidence report for grain quality testing. The chronological organization method sorts and connects the verified, discrete transaction records based on their timestamps on the blockchain, forming a narrative timeline from morning to night. Key information is extracted from each transaction record, focusing on the data most valuable to the user's understanding of the testing process. The structured end-to-end evidence report for grain quality testing is a standardized, easy-to-read electronic document or visual interface generated by the system. It is not a mere compilation of raw blockchain data, but rather presents the extracted key information clearly and systematically according to the logical sequence of sampling < testing initiation < process step 1 < process step 2 < process step 3 < result output < intelligent judgment, forming a complete end-to-end evidence report for grain quality testing.

[0114] Specifically, after verification, all transaction records are first sorted by timestamp. Then, a template is designed for each type of record, from which key information is extracted and formatted. Finally, the sections are organized chronologically and output to the requester. The report itself does not need to be stored and can be regenerated and verified by anyone at any time based on on-chain data.

[0115] Furthermore, after generating a full-chain evidence report for grain quality testing, the test results data, along with recalculated time-series deviation, statistical consistency, and instrument status metrics, are input into a pre-trained quality risk early warning model. The model outputs the future quality deterioration risk level of this batch of grain. Through a process anomaly monitoring process, a process anomaly risk score and suspicious link location information for this testing task are obtained. Specifically, the process anomaly monitoring process analyzes the structural characteristics of the time-series dependency graph composed of all transaction records within a single testing task, comparing it with graphs of numerous historical normal / abnormal processes to determine whether there are hidden anomaly patterns in the current testing process itself, and provides a risk score and location.

[0116] Specifically, after generating the basic evidence report, two analysis tasks are initiated in parallel. First, a pre-trained quality risk early warning model is invoked. Input features include the number of detection results, recalculated time-series deviation metrics, statistical consistency metrics, and instrument status metrics. Then, these features are input into the model, which outputs the future quality deterioration risk level and an analysis of potential key influencing factors. Next, the system initiates a process anomaly monitoring process. Based on all related transaction records from this detection, a time-series dependency graph is constructed and input into the trained compliance analysis model. The final output is a process anomaly risk score; a higher score indicates a greater risk, and a smaller time interval between the location information of suspicious links and the calibration process.

[0117] Finally, the risk level of future quality deterioration, analysis of key influencing factors, risk scoring of process anomalies, and information on the location of suspicious links are added as supplementary information to the full-chain evidence report for grain quality testing, completing and outputting an enhanced chain of evidence for grain quality testing. This supplementary information consists of analytical conclusions that go beyond the scope of basic traceability. Specifically, all generated data is appended to the generated full-chain evidence report for grain quality testing. The merged report is then output as the final result to the original traceability requester. Thus, users obtain tamper-proof notarized testing history, resulting in an enhanced chain of evidence for grain quality testing.

[0118] In step S40 of the method provided in this application embodiment, the process of constructing the quality risk early warning model includes:

[0119] Multiple historical grain batch testing task records are selected from the blockchain network. Each historical grain batch testing task record has a full chain record of the first warehousing test and subsequent on-chain records generated in the storage or circulation process that can indicate observable deterioration in quality.

[0120] For each historical grain batch testing task record, the test result data is extracted from the entire chain record of the first warehousing test. The historical time series deviation metric, historical statistical consistency metric, and historical instrument status metric are calculated and used as a set of input features. Based on the degree of quality deterioration or the time of occurrence indicated by the subsequent chain records, a future quality deterioration risk level is marked as a training label.

[0121] The input features are paired with the corresponding training labels to form a training sample, and all training samples are collected to form a training set for the quality risk warning model.

[0122] Obtain the original transaction identifier in the blockchain network corresponding to each training sample in the training set of the quality risk early warning model, and use all the obtained original transaction identifiers as the data basis to construct a Merkle tree and calculate the root hash value of the Merkle tree.

[0123] The machine learning algorithm is trained using the training set of the quality risk early warning model to obtain the parameters of the trained quality risk early warning model.

[0124] In this embodiment, multiple historical grain batch inspection task records are first selected from the blockchain network. Each historical grain batch inspection task record has a complete chain record of the initial warehousing inspection and subsequent on-chain records generated during storage or circulation that indicate observable deterioration in quality. The on-chain records of observable deterioration are those generated after the initial warehousing inspection, when the grain is re-inspected due to quality changes during subsequent storage, transportation, or processing, and the new inspection results are stored on the blockchain. The complete chain record of the initial warehousing inspection is a complete set of blockchain transaction records, from sampling to smart contract determination, generated when a batch of grain first enters the warehouse or circulation process and undergoes quality inspection.

[0125] Specifically, the process begins by identifying the complete chain record of the first-time warehousing inspection for the same batch. This can be determined by querying the earliest timestamp and the specific warehousing inspection business type. Secondly, records from the same batch generated at a later time with inspection results indicating non-compliance or significant deterioration of key indicators are found on the blockchain to prove that degradation has indeed occurred. A subset of historical batches that simultaneously meet the criteria of a complete first-time warehousing inspection record and observable degradation on-chain records are selected for the training set, ultimately resulting in a training set containing all samples.

[0126] Secondly, the historical time series deviation metric, historical statistical consistency metric, and historical instrument status metric are recalculated based on the historical first-time warehousing and testing process chain data; the future quality deterioration risk level is manually or systematically labeled based on the degree of quality deterioration or the time of occurrence indicated by subsequent on-chain records.

[0127] Specifically, for each historical grain batch testing task, the testing results data are extracted from the initial warehousing testing record. Using the same calculation method, the historical time-series deviation metric, historical statistical consistency metric, and historical instrument condition metric of the testing results data are recalculated and used as a set of inputs for the model. Simultaneously, based on subsequent deterioration records of the batch, the severity and speed of deterioration are analyzed, and a future quality deterioration risk level is labeled according to predefined standards as a training label. Specifically, if deterioration occurs rapidly and is severe, with multiple key indicators exceeding standards, it is labeled as high risk; if deterioration occurs moderately but relatively quickly, it is labeled as medium risk; and if deterioration occurs slowly and is minor, it is labeled as low risk. These labeled future quality deterioration risk levels are then used as supervision labels for subsequent model training.

[0128] Next, the input features are paired with their corresponding training labels to form a training sample. All training samples are then aggregated to form the training set for the quality risk warning model. In machine learning, a training sample is a complete learning instance, containing both input features and expected output labels. Pairing involves associating and storing the input feature array generated in each historical batch with the training labels labeled in the same batch, forming a one-to-one corresponding data record.

[0129] Specifically, after feature extraction and labeling of all selected historical batches are completed, a data record is created for each batch. The record stores the feature vector and corresponding risk level label of the batch in a standardized structure. For example, the first to sixth columns are feature values, and the seventh column is the label "high risk". After all historical batches have completed such record creation, they are aggregated to form the training set of the quality risk early warning model.

[0130] Simultaneously, the original transaction identifiers in the blockchain network corresponding to each training sample in the quality risk early warning model training set are obtained. Using all obtained original transaction identifiers as the data foundation, a Merkle tree is constructed, and the root hash value of the Merkle tree is calculated. Here, the original transaction identifier is the unique identifier for each sample in the training set corresponding to the transaction record in the blockchain network; a Merkle tree is a cryptographic data structure whose core principle is to pair up a set of data for hash calculation, then continue hashing the results pairwise, iterating in this way until a unique root hash is generated; the root hash value is the hash value finally calculated at the top layer of the Merkle tree.

[0131] Specifically, after the training set is formed, the system obtains the original transaction identifier corresponding to each sample in the training set, forming a unique identifier list. Then, the system constructs a Merkle tree using the unique identifier list as leaf nodes: first, it calculates the hash value of each unique identifier as the leaf node hash; then, it concatenates the hashes of two adjacent leaf nodes and hashes again to form the parent node; this process is recursively repeated until a unique root hash value is generated. Finally, the root hash value is submitted to the blockchain as a special notarized transaction for permanent storage. If there are subsequent doubts about the model's prediction results, verification of the training data can be requested: the provider only needs to provide the original unique identifier list and Merkle tree structure at the time, and the root hash can be recalculated and compared with the root hash stored on the chain. If the comparison matches, it proves that the data used in the training set was indeed the original, tamper-proof record specified on the chain at the time; if the comparison does not match, it proves that the data has been tampered with.

[0132] Finally, the machine learning algorithm is trained using the quality risk warning model training set to obtain the parameters of the trained quality risk warning model. Specifically, first, a machine learning algorithm is selected, and then the prepared quality risk warning model training set is divided into training, validation, and test sets according to a certain ratio. Next, the model is trained based on the training set, with feature vectors input to obtain preliminary predicted labels, which are then compared with the true labels to calculate the error. Based on the error, the algorithm adjusts its internal model parameters using mathematical methods such as backpropagation and gradient descent. This process is repeated thousands of times until the model's prediction accuracy on the training and validation sets stabilizes and reaches a satisfactory level. After training, the final parameters of the quality risk warning model are obtained.

[0133] For example, the specific steps for constructing a quality risk early warning model based on a fully connected neural network and obtaining the parameters of the quality risk early warning model are as follows:

[0134] For example, a quality risk early warning model is constructed using a fully connected neural network. Its structure includes an input layer, hidden layers, and an output layer. The input layer receives the input data. The hidden layers perform complex nonlinear transformations on the data to extract deep features. Each neuron in the hidden layer receives input from the neurons in the previous layer, and through weighted summation, bias correction, and activation functions, uses this input as the input to the next layer. The output layer generates the final prediction result.

[0135] A quality risk early warning model was trained using a fully connected neural network. The training, validation, and test sets were divided in a 7:2:1 ratio, with the training set used as the model's input. Training parameters were set with a learning rate of 0.001, and the Adam optimizer was used. Forward propagation involved weighted summation of the input data using weights and biases, followed by a nonlinear transformation using an activation function. This nonlinear transformation learned the complex relationship between the input data and the target output. Backpropagation was then used to calculate the gradient information of the output error, and gradient descent was used to update the weights and biases in the network. Optimization continuously reduced the model's prediction error. After training, the model's performance on the reserved validation set was evaluated. If the average absolute error between the predicted real-time coefficient and the expert-annotated value decreased to within 0.05, the quality risk early warning model was considered successful.

[0136] In step S40 of the method provided in this application embodiment, the process anomaly monitoring process is used to obtain the process anomaly risk score and suspicious link location information for this detection task, including:

[0137] Obtain complete historical evidence data of a large number of historical detection tasks from the blockchain network;

[0138] For each complete historical evidence data, all related transaction records on the blockchain network are extracted. Each transaction record is used as a node, and the reference relationship and time sequence between transaction records are used as directed edges to construct a historical time-series dependency graph with time attributes. Each historical time-series dependency graph is labeled with a corresponding process compliance label to form an abnormal risk assessment dataset.

[0139] The abnormal risk assessment dataset is used as training data to train the graph neural network model, resulting in a trained compliance analysis model.

[0140] Extract all related transaction records associated with this detection task from the blockchain network, and construct a directed temporal dependency graph with time attributes, using each transaction record as a node and the reference relationship and time sequence between transaction records as directed edges.

[0141] The directed temporal dependency graph is input into the trained compliance analysis model, and the output is the abnormal risk score and suspicious link location information for this detection task process.

[0142] In this embodiment, firstly, a large amount of complete historical evidence data of historical detection tasks is obtained from the blockchain network. Complete historical evidence data is a collection of all on-chain transaction records constituting a historical detection task. Specifically, by accessing the full node or index service of the blockchain network, a massive amount of historical detection task records are obtained, including task sampling evidence records, detection initiation evidence records, complete process hash chain evidence records, detection result submission records, and final judgment records. The obtained historical evidence data is a complete collection of all related transaction records scattered across the blockchain for each historical detection task, forming structured complete historical evidence data, which can then be used as raw material for graph-based processing.

[0143] Secondly, for each complete historical evidence record, all related transaction records on the blockchain network are extracted. Using each transaction record as a node and the reference relationships and chronological order between transaction records as directed edges, a historical temporal dependency graph with time attributes is constructed. Each historical temporal dependency graph is then labeled with a corresponding process compliance label, forming an anomaly risk assessment dataset. Here, nodes are the basic building blocks of a graph; directed edges are used in graph theory to connect two nodes, indicating a relationship between them; the historical temporal dependency graph with time attributes is a special type of directed graph that can intuitively and structurally represent the logical order and temporal relationships of all stages in a detection task; and process compliance labels are used to indicate the anomaly type, judging whether the process of a historical detection task is compliant or non-compliant based on post-audit or known rules.

[0144] Specifically, firstly, using the obtained complete historical evidence data as the search criteria, all matching related transaction records on the blockchain network are extracted. These historical evidence data are then used as nodes, and their key attributes are extracted as node features. Secondly, the relationships between related transaction records are analyzed: it is checked whether the input data of each transaction references the hashes of other transactions, and timestamps are compared. For each pair of referenced and chronologically ordered transactions, an adjacency matrix is ​​created to describe the connections between nodes. Assuming node A is referenced by node B, and node A predates node B, a connection from A to B is created between the corresponding nodes A and B.

[0145] Simultaneously, information such as time difference is used as an attribute of the edges. All records from a detection task are constructed into a temporal dependency graph, displaying the data flow and the progression of the timeline. Finally, experts assess the compliance of the obtained temporal dependency graph based on the violation records and label the process with compliance tags according to the assessment results. All temporal dependency graphs and their labels are then aggregated to form an anomaly risk assessment dataset for training graph neural networks.

[0146] Next, the anomaly risk assessment dataset is used as training data to train a graph neural network model, resulting in a trained compliance analysis model. The graph neural network model is a deep learning model specifically designed to handle graph-structured data. Specifically, the anomaly risk assessment dataset is first divided proportionally into training, validation, and test sets. Then, a graph neural network model architecture is selected for model training. The model's input is the anomaly risk assessment dataset, and its output is the predicted results of process compliance. The training process begins by having the model read the temporal dependency graph from the training set, calculate the loss by comparing it with the true labels through forward propagation, and calculate the gradient of the loss with respect to the model parameters using the backpropagation algorithm, updating the parameters to reduce the loss. This process is iterated several times until the model's performance on the validation set reaches its optimal and stabilizes. Finally, the trained model parameters are saved, resulting in the compliance analysis model.

[0147] For example, a compliance analysis model is constructed using a Graph Convolutional Network (GCN). A GCN is a neural network structure used to process graph data, capable of directly operating on the graph and utilizing its structural information. When processing graph data, it considers both node features and the graph's structure. Therefore, it is suitable for node classification tasks. The specific steps for constructing a compliance analysis model using a GCN are as follows:

[0148] First, the constructed anomaly risk assessment dataset is divided into training, validation, and test sets according to a preset ratio of 7:2:1. It is important to maintain the integrity of the graph structure during partitioning, typically using node-level partitioning, assigning set labels to each node to ensure that training, validation, and test nodes do not overlap.

[0149] Secondly, based on the relationships between entities, the adjacency matrix A∈R^ is constructed for the graph. (N×N) A is used to describe the connection relationships between nodes. Typically, A is normalized to improve training stability. Label definition involves defining a compliance label for each process or entity node that needs to be evaluated, forming a label vector.

[0150] Next, a single-layer GCN graph convolutional network is constructed, where the model structure includes an input layer, a single GCN layer, and an output layer. The input layer directly receives the anomaly risk assessment dataset and reads the temporal dependency graph; the GCN layer performs graph convolution operations on the temporal dependency graph to aggregate information from direct and indirect neighborhoods; the formula for the single-layer GCN is:

[0151] ;

[0152] in, X is the standardized adjacency matrix; X is the node feature matrix (X=H (0) H (0)W represents the initial hidden state, i.e., the original node features. (0) σ is the weight matrix (learnable parameters) of the first layer; σ is the activation function.

[0153] For node classification tasks, the output layer, in its final stage, passes through a softmax function to generate the class distribution for each node, outputting the compliance prediction probability for each node. The formula for the class distribution is:

[0154] ;

[0155] Among them, H i (L) It is the final representation of the i-th node; The node classification task requires providing node labels.

[0156] Ultimately, with an initial learning rate of 0.001, the Adam optimizer is used to update model parameters based on the calculated gradients to minimize the loss. Supervised learning is performed on labeled nodes using the Cross Entropy Loss function. Through forward propagation, features and graph structure of the training set nodes are read, and information is propagated and aggregated through a GCN layer to output the prediction result. The prediction result is then compared with the true label using the Cross Entropy Loss function to calculate the loss value and quantify the model's prediction error. Backpropagation is used to calculate the gradient of the loss with respect to all trainable parameters of the model. The process iterates continuously, updating parameters, and evaluating model performance on a validation set after each training epoch. If the validation set performance no longer improves over several consecutive epochs, an early stopping mechanism is triggered to prevent overfitting.

[0157] After training, the final model is comprehensively evaluated on a test set that was never used in the training. Key metrics such as accuracy, recall, and AUC are reported to objectively measure its generalization ability. Model storage: The weights and biases of the trained and optimally performing model are saved to generate a deployable compliance analysis model that can receive new anomaly risk assessment graph data and output accurate predictions of process compliance risks.

[0158] For example, during training, the loss value of the GCN model gradually decreases, while the accuracy on the validation set gradually increases. After 200 rounds of training on the test set, the GCN model typically achieves a test accuracy of approximately 80%-85% on the dataset, indicating that the model has good generalization ability and is thus considered a compliance analysis model.

[0159] Simultaneously, all related transaction records associated with this detection task are extracted from the blockchain network. Using each transaction record as a node and the reference relationships and temporal order between transactions as directed edges, a directed temporal dependency graph with time attributes is constructed. Specifically, when process anomaly monitoring is required for a detection task, firstly, all related transaction records for this task are extracted from the blockchain based on the task's unique identifier. Then, according to the temporal dependency graph construction algorithm, each transaction is used as a node, and directed edges are defined based on the reference relationships and temporal order between transactions, thereby constructing a directed temporal dependency graph specific to this detection task.

[0160] Finally, the compliance analysis model, trained using a directed temporal dependency graph, outputs an anomaly risk score and suspicious link location information for the current detection task process. The anomaly risk score, ranging from 0 to 100, represents the overall probability or risk level of an anomaly in the detection process, with higher scores indicating a more suspicious process. The suspicious link location information is an interpretable output provided by the model.

[0161] Specifically, the constructed task graph is input into the deployed compliance analysis model. The model performs forward inference, using its internal graph neural network layer to aggregate and transform node and edge information in the graph through multiple rounds, ultimately forming a vector representing the characteristics of the entire process. An anomaly risk score is then calculated based on this vector. Simultaneously, the model's interpretability module analyzes the calculation process, identifying the nodes or edges that have the greatest impact on anomaly judgment and generating suspicious link location information. Based on the characteristics of GNNs, the model can not only assess the risk of the entire graph but also identify which nodes or edges are most likely to lead to anomaly judgments by analyzing the contribution of nodes or edges in the final decision, thus pinpointing suspicious issues to specific sampling, initiation, preprocessing, and calibration stages. The formatted output is returned as an important supplementary evaluation of the quality of this detection task process.

[0162] For example, the model receives the graph, performs internal calculations, and outputs an anomaly risk score of 15, indicating that the model considers the process to be compliant overall with very low risk; the location information of suspicious links shows that no significant abnormal links were found, the attention weights are displayed, the links are connected normally, and the reference relationships are complete.

[0163] The embodiments of this application, through the above specific implementation methods, achieve the following technical effects:

[0164] In this embodiment, a dedicated sampling terminal equipped with a security encryption module first collects the geographical coordinates, sampling time, environmental images of the sampling site, temperature and humidity data of the sampling site, and grain batch identifier of the grain sample, generating a sample data package to provide a sufficient data foundation for subsequent processing. Subsequently, the dedicated sampling terminal uses a digital private key to digitally sign the sample data package and calculates a first hash value. Obtaining the digital signature through the digital private key ensures the security of data acquisition. The first hash value is then submitted along with the sampling and storage transaction of the sampling personnel's digital certificate. After digital signature verification, a first transaction record is generated, and a unique identifier for the first transaction record is returned to the sampling terminal. The submission process involves reverse verification through the digital signature of the first transaction record, returning the unique identifier. This dual verification ensures the rigor of data management and improves data reliability. Finally, the unique identifier is used to generate a physical anti-counterfeiting label, which is attached to the grain sample packaging for subsequent security verification based on the anti-counterfeiting label.

[0165] Secondly, by scanning the physical anti-counterfeiting labels on the sample packaging and parsing the unique identifier of the first transaction record, a trusted adapter is combined with the testing instrument to generate testing initiation data. This data, containing the unique identifier obtained through parsing, is used in conjunction with the hardware data of the testing instrument and the testing initiation timestamp to generate the testing initiation data. This avoids sample confusion or human input errors, ensuring the source credibility of the tested object. Subsequently, a second hash value of the testing initiation data is calculated and submitted to the blockchain network, establishing a trusted record with device identity, task attributes, and precise time. During the testing process, the trusted adapter captures process data at preset key nodes, calculates process hash values, and uploads them to the blockchain in chronological order, forming a process hash chain. This provides a transparent, real-time, and tamper-proof record of the core testing operations within the laboratory, offering a solid data foundation for assessing the standardization and consistency of the testing process.

[0166] Furthermore, by triggering smart contract execution integrity, single-use, and correlation verification, and introducing three metrics—timing deviation, statistical consistency, and instrument status—for credibility assessment, a comprehensive credibility score is derived from calculating these three metrics. This approach, for the first time, incorporates the operational quality and result rationality of the testing process into a quantifiable evaluation framework, identifying potential risks such as rushed operations, abnormal results, and unstable instrument status, significantly improving the credibility of the process upon which the judgment conclusions rely. Based on verified data and credibility assessments, the smart contract is driven to automatically execute standard compliance judgments, ensuring the objectivity and consistency of quality assessments. The inputs and conclusions of the adjudication process are permanently stored as judgment transaction records, forming a reliable judgment process and enhancing the credibility of grain quality testing reports. Ultimately, this achieves automated standard compliance judgment, transforming traditional manual review and judgment work into a highly efficient, code-driven verification process.

[0167] Ultimately, based on the complete evidence chain traceability and verification, quality risk early warning and process anomaly monitoring are implemented. A quality risk early warning model, built upon historical deterioration data and Merkle tree evidence, is trained using massive, reliable historical data accumulated through blockchain to produce a reliable prediction model. This model can scientifically predict the future quality deterioration risk level of this batch of grain based on current testing results and process characteristics, providing forward-looking data insights for grain storage management, circulation cycle planning, and precise supervision. The process anomaly monitoring process, trained based on historical time-series dependency graphs and graph neural networks, intelligently identifies hidden, rule-intensive, and difficult-to-exhaustively-enumerate abnormal structural patterns in individual testing tasks from complex transaction reference relationships and time series. It provides quantified risk scores and suspicious link locations, achieving automated, in-depth auditing of the health of the testing process itself. Finally, the analysis results are added as supplementary information to the end-to-end evidence report, forming an enhanced system integrating historical evidence, objective quality judgment, scientific risk early warning, and intelligent process diagnosis. This comprehensively improves the intelligence level, risk prediction capability, and regulatory penetration of grain quality and safety management.

[0168] Example 2, as Figure 2 As shown, based on the same inventive concept as the blockchain-based grain quality testing data traceability management method provided in Embodiment 1, this embodiment of the invention also provides a blockchain-based grain quality testing data traceability management system, including:

[0169] The anti-counterfeiting label generation module 11 is used to collect a sampling data packet containing sample information and calculate a first hash value in the grain sampling process, submit it to the blockchain network, generate a first transaction record, and generate a physical anti-counterfeiting label attached to the grain sample based on the first transaction record.

[0170] The quality inspection module 12 is used to read the physical anti-counterfeiting label to obtain on-chain information, generate inspection start data and calculate the second hash value and store it in the blockchain network during the inspection process, and continuously calculate the key process data in the inspection process into process hash values ​​and store them in the blockchain network in time sequence to form a process hash chain.

[0171] The detection result judgment module 13 is used to submit the detection result data and the corresponding result hash value to the blockchain network after the detection is completed. The module uses a pre-set smart contract to perform credible verification and standard compliance judgment on the whole chain data of this detection, and stores the generated judgment conclusion as a judgment transaction record in the blockchain network.

[0172] Quality inspection evidence chain reconstruction 14: Based on the judgment transaction record, extract and verify the correlation between the first hash value, the second hash value, the process hash chain, the result hash value and the judgment transaction record from the blockchain network, and reconstruct a complete grain quality inspection evidence chain.

[0173] In one embodiment, the anti-counterfeiting label generation module 11 is used for:

[0174] The sampling terminal, equipped with a security encryption module, collects the geographical coordinates of the grain samples, the sampling time point, the environmental images of the sampling site, the temperature and humidity data of the sampling site, and the grain batch identifier, and generates a sampling data package.

[0175] The dedicated sampling terminal uses the sampling personnel's digital private key to digitally sign the sampling data packet and calculates the hash value of the sampling data packet as the first hash value;

[0176] The dedicated sampling terminal submits a sampling and evidence storage transaction containing a first hash value and the sampling personnel's digital certificate to the blockchain network. After verifying the digital signature in the sampling and evidence storage transaction, the blockchain network generates a first transaction record corresponding to this sampling in the blockchain network and returns a unique identifier of the first transaction record to the dedicated sampling terminal.

[0177] The dedicated sampling terminal generates a physical anti-counterfeiting label based on the unique identifier of the first transaction record and attaches the physical anti-counterfeiting label to the packaging of the collected grain sample.

[0178] In one embodiment, the anti-counterfeiting label generation module 12 is used for:

[0179] The testing instrument reads the physical anti-counterfeiting label attached to the grain sample packaging through a scanning device, and parses the unique identifier of the first transaction record from the physical anti-counterfeiting label;

[0180] The trusted adapter built into the detection instrument generates detection start data based on the unique identifier of the first transaction record, combined with the device hardware fingerprint of the detection instrument, the project code of this detection task, and the detection start timestamp.

[0181] The trusted adapter calculates the hash value of the detection startup data and submits the hash value as a second hash value to the blockchain network for evidence storage.

[0182] During the testing process, the trusted adapter obtains key process data from the testing instrument according to preset key step nodes and calculates the hash value of the key process data as the process hash value. Each process hash value, together with the corresponding timestamp, is submitted to the blockchain network in chronological order to form a process hash chain associated with the second hash value. The key step nodes include at least sample pretreatment completion, testing instrument calibration completion, and testing analysis completion.

[0183] In one embodiment, the detection result determination module 13 is used for:

[0184] The generated judgment conclusion will be stored in the blockchain network as a judgment transaction record, including:

[0185] After the test is completed, the test result data and the corresponding result hash value are submitted to the blockchain network, triggering the pre-set standard compliance smart contract in the blockchain network to perform integrity verification, one-time verification and correlation verification operations on the test data;

[0186] The standard compliance smart contract extracts and calculates the time-series deviation metric, statistical consistency metric, and instrument status metric for this test from the blockchain network;

[0187] After the integrity verification, single-use verification and correlation verification operations are all passed, the standard compliance smart contract calls the grain testing process credibility assessment model, inputs the time series deviation metric, statistical consistency metric, and instrument status metric, and outputs the comprehensive credibility score of this testing process.

[0188] If the overall credibility score is higher than the preset credibility threshold, the standard compliance smart contract will continue to execute the standard compliance judgment logic, automatically compare the test result data with the current grain quality standard rules stored in the blockchain network, and generate the final judgment conclusion.

[0189] The standard compliance smart contract will combine the final judgment conclusion, comprehensive credibility score, the time series deviation metric, statistical consistency metric, instrument status metric, and standard rule version number to generate a judgment transaction record and store it in the blockchain network.

[0190] Specifically, the execution of pre-built standard compliance smart contracts in the blockchain network to perform integrity verification, one-time verification, and correlation verification operations on the data from this test includes:

[0191] Extract the hash value of the results recorded for this detection task from the blockchain network, recalculate the hash value of the detection result data submitted this time, obtain the hash value of the submitted data, and compare the hash value of the submitted data with the hash value of the recorded results to confirm that the detection result data has not been tampered with since submission.

[0192] Extract the second hash value corresponding to this detection task from the blockchain network, and verify whether there is a corresponding valid record for the second hash value in the blockchain network. If there is a valid record, verify that the second hash value record has not been marked as being used for any previous judgment conclusion generation, so as to confirm the uniqueness and validity of this detection process.

[0193] Extract the first hash value, the second hash value, and all process hash values ​​contained in the process hash chain corresponding to this detection task from the blockchain network. Verify whether the first hash value is referenced by the transaction record where the second hash value is located, and verify whether each process hash value forms a continuous reference chain pointing to the second hash value in the blockchain network in chronological order, so as to confirm that the entire chain of data from sampling to detection is logically consistent and not fragmented.

[0194] This includes extracting and calculating time-series deviation metrics, statistical consistency metrics, and instrument status metrics from the blockchain network, including:

[0195] Based on the timestamps of each record in the hash chain of this detection process in the blockchain network, the actual time interval between nodes of key steps is calculated;

[0196] Each actual time interval is compared with the pre-stored recommended time interval for the corresponding step to generate a time deviation metric that characterizes the time sequence compliance of this detection process.

[0197] Query the historical testing records of other samples from the same grain batch as the sample tested in this test from the blockchain network, and extract the corresponding historical test result data;

[0198] Based on the historical test results data, a historical numerical statistical distribution of key quality indicators is constructed, and the corresponding indicator values ​​in the current test results data are compared with the historical numerical statistical distribution. By calculating the relative position of the corresponding indicator values ​​to the mean of the historical numerical statistical distribution, a statistical consistency measure that characterizes the consistency between the current test results and the historical results of the same batch is generated.

[0199] Based on the device hardware fingerprint recorded in the data from this test start-up, query all other test task records of the testing instrument within the preset time interval before and after this test task.

[0200] Analyze the time distribution and task type of the other detection task records and their correlation with the current detection task to generate instrument status metrics that characterize the stability of the operating status and task exclusivity of the detection instrument during the current detection task.

[0201] In one embodiment, the quality inspection evidence chain reconstruction 14 is used for:

[0202] The blockchain network receives a traceability request, wherein the traceability request includes a unique identifier for determining the transaction record or a batch identifier for the grain to be traced;

[0203] Based on the unique identifier or batch identifier, query and extract all on-chain transaction records related to this testing task from the blockchain network. The all on-chain transaction records include sampling and evidence storage transaction records, testing initiation and evidence storage transaction records, process hash chain evidence storage transaction records, testing result data submission transaction records, and judgment transaction records.

[0204] Based on all the on-chain transaction records, verify whether the first hash value, the second hash value, the process hash values ​​in the process hash chain, the result hash value, and the judgment conclusion form a logically continuous and tamper-proof chain of evidence through the hash pointer reference relationship of the transaction records.

[0205] After verification, the key information of all on-chain transaction records is organized in chronological order to generate and output a structured full-chain evidence report for grain quality testing.

[0206] After generating the full-chain evidence report for grain quality testing, the test results data of this test, along with the recalculated time-series deviation metric, statistical consistency metric, and instrument status metric, are input into the pre-trained quality risk early warning model. The model outputs the future quality deterioration risk level of this batch of grain and obtains the process anomaly risk score and suspicious link location information for this test task through the process anomaly monitoring process.

[0207] The future quality deterioration risk level, key influencing factor analysis, process anomaly risk score, and suspicious link location information are added as supplementary information to the grain quality testing full-chain evidence report to complete and output an enhanced grain quality testing evidence chain.

[0208] The process of constructing the quality risk early warning model includes:

[0209] Multiple historical grain batch testing task records are selected from the blockchain network. Each historical grain batch testing task record has a full chain record of the first warehousing test and subsequent on-chain records generated in the storage or circulation process that can indicate observable deterioration in quality.

[0210] For each historical grain batch testing task record, the test result data is extracted from the entire chain record of the first warehousing test. The historical time series deviation metric, historical statistical consistency metric, and historical instrument status metric are calculated and used as a set of input features. Based on the degree of quality deterioration or the time of occurrence indicated by the subsequent chain records, a future quality deterioration risk level is marked as a training label.

[0211] The input features are paired with the corresponding training labels to form a training sample, and all training samples are collected to form a training set for the quality risk warning model.

[0212] Obtain the original transaction identifier in the blockchain network corresponding to each training sample in the training set of the quality risk early warning model, and use all the obtained original transaction identifiers as the data basis to construct a Merkle tree and calculate the root hash value of the Merkle tree.

[0213] The machine learning algorithm is trained using the training set of the quality risk early warning model to obtain the parameters of the trained quality risk early warning model.

[0214] The process anomaly monitoring process obtains a process anomaly risk score and suspicious step location information for this detection task, including:

[0215] Obtain complete historical evidence data of a large number of historical detection tasks from the blockchain network;

[0216] For each complete historical evidence data, all related transaction records on the blockchain network are extracted. Each transaction record is used as a node, and the reference relationship and time sequence between transaction records are used as directed edges to construct a historical time-series dependency graph with time attributes. Each historical time-series dependency graph is labeled with a corresponding process compliance label to form an abnormal risk assessment dataset.

[0217] The abnormal risk assessment dataset is used as training data to train the graph neural network model, resulting in a trained compliance analysis model.

[0218] Extract all related transaction records associated with this detection task from the blockchain network, and construct a directed temporal dependency graph with time attributes, using each transaction record as a node and the reference relationship and time sequence between transaction records as directed edges.

[0219] The directed temporal dependency graph is input into the trained compliance analysis model, and the output is the abnormal risk score and suspicious link location information for this detection task process.

[0220] The embodiments of this application, through the above specific implementation methods, achieve the following technical effects:

[0221] In this embodiment, the anti-counterfeiting label generation module 11 first uses a dedicated sampling terminal equipped with a security encryption module to collect the geographical coordinates, sampling time, environmental images of the sampling site, temperature and humidity data of the sampling site, and grain batch identifier of the grain sample, generating a sample data package to provide a sufficient data foundation for subsequent processing. Then, the dedicated sampling terminal uses a digital private key to digitally sign the sampling data package and calculates a first hash value. The digital signature is obtained through the digital private key, ensuring the security of data acquisition. The first hash value is submitted along with the sampling evidence transaction of the sampling personnel's digital certificate. After digital signature verification, a first transaction record is generated, and a unique identifier for the first transaction record is returned to the sampling terminal. The submission process involves reverse verification through the digital signature of the first transaction record, returning a unique identifier. This dual verification ensures the rigor of data management and improves data reliability. Finally, the unique identifier is used to generate a physical anti-counterfeiting label, which is attached to the packaging of the grain sample for subsequent security verification based on the anti-counterfeiting label.

[0222] Secondly, through the anti-counterfeiting label generation module 12, the scanning device reads the physical anti-counterfeiting label on the sample packaging and parses the unique identifier of the first transaction record. The trusted adapter, combined with the testing instrument, generates testing start data. This data, containing the unique identifier obtained through parsing, is used in conjunction with the hardware data of the testing instrument and the testing start timestamp to generate the testing start data. This avoids sample confusion or human input errors, ensuring the source credibility of the tested object. Subsequently, the second hash value of the testing start data is calculated and submitted to the blockchain network, establishing a trusted record with device identity, task attributes, and precise time. During the testing process, the trusted adapter captures process data at preset key nodes, calculates process hash values, and uploads them to the blockchain in chronological order, forming a process hash chain. This provides a transparent, real-time, and tamper-proof record of the core testing operations within the laboratory, offering a solid data foundation for evaluating the standardization and consistency of the testing process.

[0223] Furthermore, through the detection result judgment module 13, the integrity, singleness, and relevance of the smart contract execution are verified. Three metrics—time series deviation, statistical consistency, and instrument status—are introduced for credibility assessment. By calculating these three metrics and applying a comprehensive credibility score, the operational quality and reasonableness of the detection process are, for the first time, quantifiable evaluation criteria are applied. This identifies potential risks such as rushed operations, abnormal results, and unstable instrument status, significantly improving the credibility of the process upon which the judgment conclusions rely. Based on the verified data and credibility assessment, the smart contract is driven to automatically execute standard compliance judgments, ensuring the objectivity and consistency of quality judgments. The inputs and conclusions of the adjudication process are permanently stored as judgment transaction records, forming a reliable judgment process and enhancing the credibility of grain quality testing reports. Ultimately, automatic standard compliance judgment is achieved, transforming traditional manual review and judgment work into a highly efficient verification process driven by code.

[0224] Ultimately, by reconstructing the quality inspection evidence chain14, and based on achieving complete evidence chain traceability and verification, quality risk early warning and process anomaly monitoring are implemented. A quality risk early warning model, constructed based on historical deterioration data and Merkle tree evidence, is trained using massive, reliable historical data accumulated through blockchain to generate a reliable prediction model. This model can scientifically predict the future quality deterioration risk level of this batch of grain based on current inspection results and process characteristics, providing forward-looking data insights for grain storage management, circulation cycle planning, and precise supervision. The process anomaly monitoring process, trained based on historical time-series dependency graphs and graph neural networks, intelligently identifies hidden, rule-intensive, and difficult-to-exhaustively enumerate abnormal structural patterns in individual inspection tasks from complex transaction reference relationships and time series, providing quantified risk scores and suspicious link locations, achieving automated, in-depth auditing of the health of the inspection process itself. Finally, the analysis results are added as supplementary information to the full-chain evidence report, forming an enhanced system integrating historical evidence, objective quality judgment, scientific risk early warning, and intelligent process diagnosis, comprehensively improving the intelligence level, risk prediction capability, and regulatory penetration of grain quality and safety management.

Claims

1. A blockchain-based method for tracing and managing grain quality testing data, characterized in that: The method includes: In the grain sampling process, a sampling data packet containing sample information is collected and a first hash value is calculated and submitted to the blockchain network to generate a first transaction record. Based on the first transaction record, a physical anti-counterfeiting label is generated and attached to the grain sample. During the detection process, the physical anti-counterfeiting label is read to obtain on-chain information, detection start data is generated, and a second hash value is calculated and stored in the blockchain network. Key process data in the detection process are continuously calculated as process hash values ​​and stored in the blockchain network in chronological order to form a process hash chain. After the test is completed, the test result data and the corresponding result hash value are submitted to the blockchain network. The pre-set smart contract performs credible verification and standard compliance judgment on the whole chain data of this test, and stores the generated judgment conclusion as a judgment transaction record in the blockchain network. Based on the judgment transaction records, the correlation between the first hash value, the second hash value, the process hash chain, the result hash value, and the judgment transaction records is extracted and verified from the blockchain network to reconstruct a complete evidence chain for grain quality testing.

2. The method for traceability management of grain quality testing data based on blockchain according to claim 1, characterized in that, In the grain sampling process, a sampling data packet containing sample information is collected, a first hash value is calculated, and submitted to the blockchain network to generate a first transaction record. Based on the first transaction record, a physical anti-counterfeiting label is generated and attached to the grain sample, including: The sampling terminal, equipped with a security encryption module, collects the geographical coordinates of the grain samples, the sampling time point, the environmental images of the sampling site, the temperature and humidity data of the sampling site, and the grain batch identifier, and generates a sampling data package. The dedicated sampling terminal uses the sampling personnel's digital private key to digitally sign the sampling data packet and calculates the hash value of the sampling data packet as the first hash value; The dedicated sampling terminal submits a sampling and evidence storage transaction containing a first hash value and the sampling personnel's digital certificate to the blockchain network. After verifying the digital signature in the sampling and evidence storage transaction, the blockchain network generates a first transaction record corresponding to this sampling in the blockchain network and returns a unique identifier of the first transaction record to the dedicated sampling terminal. The dedicated sampling terminal generates a physical anti-counterfeiting label based on the unique identifier of the first transaction record and attaches the physical anti-counterfeiting label to the packaging of the collected grain sample.

3. The method for traceability management of grain quality testing data based on blockchain according to claim 1, characterized in that, In the detection phase, the physical anti-counterfeiting label is read to obtain on-chain information, detection start data is generated, and a second hash value is calculated and stored in the blockchain network. Key process data during the detection process is continuously calculated as process hash values ​​and stored in the blockchain network in chronological order, forming a process hash chain, including: The testing instrument reads the physical anti-counterfeiting label attached to the grain sample packaging through a scanning device, and parses the unique identifier of the first transaction record from the physical anti-counterfeiting label; The trusted adapter built into the detection instrument generates detection start data based on the unique identifier of the first transaction record, combined with the device hardware fingerprint of the detection instrument, the project code of this detection task, and the detection start timestamp. The trusted adapter calculates the hash value of the detection startup data and submits the hash value as a second hash value to the blockchain network for evidence storage. During the testing process, the trusted adapter obtains key process data from the testing instrument according to preset key step nodes and calculates the hash value of the key process data as the process hash value. Each process hash value, together with the corresponding timestamp, is submitted to the blockchain network in chronological order to form a process hash chain associated with the second hash value. The key step nodes include at least sample pretreatment completion, testing instrument calibration completion, and testing analysis completion.

4. The method for traceability management of grain quality testing data based on blockchain according to claim 1, characterized in that, The test results data and corresponding result hash values ​​are submitted to the blockchain network. A pre-built smart contract performs trusted verification and standard compliance determination on the entire chain of data for this test, and the generated determination conclusion is stored in the blockchain network as a determination transaction record, including: After the test is completed, the test result data and the corresponding result hash value are submitted to the blockchain network, triggering the pre-set standard compliance smart contract in the blockchain network to perform integrity verification, one-time verification and correlation verification operations on the test data; The standard compliance smart contract extracts and calculates the time-series deviation metric, statistical consistency metric, and instrument status metric for this test from the blockchain network; After the integrity verification, single-use verification and correlation verification operations are all passed, the standard compliance smart contract calls the grain testing process credibility assessment model, inputs the time series deviation metric, statistical consistency metric, and instrument status metric, and outputs the comprehensive credibility score of this testing process. If the overall credibility score is higher than the preset credibility threshold, the standard compliance smart contract will continue to execute the standard compliance judgment logic, automatically compare the test result data with the current grain quality standard rules stored in the blockchain network, and generate the final judgment conclusion. The standard compliance smart contract will combine the final judgment conclusion, comprehensive credibility score, the time series deviation metric, statistical consistency metric, instrument status metric, and standard rule version number to generate a judgment transaction record and store it in the blockchain network.

5. The blockchain-based method for traceability management of grain quality testing data according to claim 4, characterized in that, The pre-built standard compliance smart contract in the blockchain network is triggered to perform integrity verification, single-use verification, and correlation verification operations on the data tested, including: Extract the hash value of the results recorded for this detection task from the blockchain network, recalculate the hash value of the detection result data submitted this time, obtain the hash value of the submitted data, and compare the hash value of the submitted data with the hash value of the recorded results to confirm that the detection result data has not been tampered with since submission. Extract the second hash value corresponding to this detection task from the blockchain network, and verify whether there is a corresponding valid record for the second hash value in the blockchain network. If there is a valid record, verify that the second hash value record has not been marked as being used for any previous judgment conclusion generation, so as to confirm the uniqueness and validity of this detection process. Extract the first hash value, the second hash value, and all process hash values ​​contained in the process hash chain corresponding to this detection task from the blockchain network. Verify whether the first hash value is referenced by the transaction record where the second hash value is located, and verify whether each process hash value forms a continuous reference chain pointing to the second hash value in the blockchain network in chronological order, so as to confirm that the entire chain of data from sampling to detection is logically consistent and not fragmented.

6. The method for traceability management of grain quality testing data based on blockchain according to claim 4, characterized in that, Extract and calculate time-series deviation metrics, statistical consistency metrics, and instrument status metrics from the blockchain network, including: Based on the timestamps of each record in the hash chain of this detection process in the blockchain network, the actual time interval between nodes of key steps is calculated; Each actual time interval is compared with the pre-stored recommended time interval for the corresponding step to generate a time deviation metric that characterizes the time sequence compliance of this detection process. Query the historical testing records of other samples from the same grain batch as the sample tested in this test from the blockchain network, and extract the corresponding historical test result data; Based on the historical test results data, a historical numerical statistical distribution of key quality indicators is constructed, and the corresponding indicator values ​​in the current test results data are compared with the historical numerical statistical distribution. By calculating the relative position of the corresponding indicator values ​​to the mean of the historical numerical statistical distribution, a statistical consistency measure that characterizes the consistency between the current test results and the historical results of the same batch is generated. Based on the device hardware fingerprint recorded in the data from this test start-up, query all other test task records of the testing instrument within the preset time interval before and after this test task. Analyze the time distribution and task type of the other detection task records and their correlation with the current detection task to generate instrument status metrics that characterize the stability of the operating status and task exclusivity of the detection instrument during the current detection task.

7. The method for traceability management of grain quality testing data based on blockchain according to claim 1, characterized in that, Based on the aforementioned judgment transaction records, the correlation between the first hash value, the second hash value, the process hash chain, the result hash value, and the judgment transaction records is extracted and verified from the blockchain network to reconstruct a complete evidence chain for grain quality testing, including: The blockchain network receives a traceability request, wherein the traceability request includes a unique identifier for determining the transaction record or a batch identifier for the grain to be traced; Based on the unique identifier or batch identifier, query and extract all on-chain transaction records related to this testing task from the blockchain network. The all on-chain transaction records include sampling and evidence storage transaction records, testing initiation and evidence storage transaction records, process hash chain evidence storage transaction records, testing result data submission transaction records, and judgment transaction records. Based on all the on-chain transaction records, verify whether the first hash value, the second hash value, the process hash values ​​in the process hash chain, the result hash value, and the judgment conclusion form a logically continuous and tamper-proof chain of evidence through the hash pointer reference relationship of the transaction records. After verification, the key information of all on-chain transaction records is organized in chronological order to generate and output a structured full-chain evidence report for grain quality testing. After generating the full-chain evidence report for grain quality testing, the test results data of this test, along with the recalculated time-series deviation metric, statistical consistency metric, and instrument status metric, are input into the pre-trained quality risk early warning model. The model outputs the future quality deterioration risk level of this batch of grain and obtains the process anomaly risk score and suspicious link location information for this test task through the process anomaly monitoring process. The future quality deterioration risk level, key influencing factor analysis, process anomaly risk score, and suspicious link location information are added as supplementary information to the grain quality testing full-chain evidence report to complete and output an enhanced grain quality testing evidence chain.

8. The method for traceability management of grain quality testing data based on blockchain according to claim 7, characterized in that, The process of constructing a quality risk early warning model includes: Multiple historical grain batch testing task records are selected from the blockchain network. Each historical grain batch testing task record has a full chain record of the first warehousing test and subsequent on-chain records generated in the storage or circulation process that can indicate observable deterioration in quality. For each historical grain batch testing task record, the test result data is extracted from the entire chain record of the first warehousing test. The historical time series deviation metric, historical statistical consistency metric, and historical instrument status metric are calculated and used as a set of input features. Based on the degree of quality deterioration or the time of occurrence indicated by the subsequent chain records, a future quality deterioration risk level is marked as a training label. The input features are paired with the corresponding training labels to form a training sample, and all training samples are collected to form a training set for the quality risk warning model. Obtain the original transaction identifier in the blockchain network corresponding to each training sample in the training set of the quality risk early warning model, and use all the obtained original transaction identifiers as the data basis to construct a Merkle tree and calculate the root hash value of the Merkle tree. The machine learning algorithm is trained using the training set of the quality risk early warning model to obtain the parameters of the trained quality risk early warning model.

9. The method for traceability management of grain quality testing data based on blockchain according to claim 7, characterized in that, Through the process anomaly monitoring process, obtain the process anomaly risk score and suspicious link location information for this detection task, including: Obtain complete historical evidence data of a large number of historical detection tasks from the blockchain network; For each complete historical evidence data, all related transaction records on the blockchain network are extracted. Each transaction record is used as a node, and the reference relationship and time sequence between transaction records are used as directed edges to construct a historical time-series dependency graph with time attributes. Each historical time-series dependency graph is labeled with a corresponding process compliance label to form an abnormal risk assessment dataset. The abnormal risk assessment dataset is used as training data to train the graph neural network model, resulting in a trained compliance analysis model. Extract all related transaction records associated with this detection task from the blockchain network, and construct a directed temporal dependency graph with time attributes, using each transaction record as a node and the reference relationship and time sequence between transaction records as directed edges. The directed temporal dependency graph is input into the trained compliance analysis model, and the output is the abnormal risk score and suspicious link location information for this detection task process.

10. A blockchain-based grain quality testing data traceability management system, characterized in that, The system for implementing the method according to any one of claims 1-9 comprises: The anti-counterfeiting label generation module is used in the grain sampling process to collect a sampling data packet containing sample information, calculate a first hash value, submit it to the blockchain network, generate a first transaction record, and generate a physical anti-counterfeiting label attached to the grain sample based on the first transaction record. The quality inspection module is used to read the physical anti-counterfeiting label to obtain on-chain information during the inspection process, generate inspection start data and calculate the second hash value and store it in the blockchain network. It continuously calculates the key process data in the inspection process into process hash values ​​and stores them in the blockchain network in time sequence to form a process hash chain. The test result determination module is used to submit the test result data and the corresponding result hash value to the blockchain network after the test is completed. The module uses a pre-set smart contract to perform credible verification and standard compliance determination on the entire chain data of this test, and stores the generated determination conclusion as a determination transaction record in the blockchain network. The quality inspection evidence chain reconstruction module, based on the judgment transaction record, extracts and verifies the correlation between the first hash value, the second hash value, the process hash chain, the result hash value, and the judgment transaction record from the blockchain network, and reconstructs a complete grain quality inspection evidence chain.