Blockchain and smart contract based woven data security traceability method and system
By using blockchain and smart contract technologies, the security and privacy issues of weaving data traceability in textile manufacturing have been solved, realizing secure and reliable data traceability and efficient access, and avoiding the defects of centralized systems.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NANTONG HAIHUI SCI & TECH DEV CO LTD
- Filing Date
- 2026-03-26
- Publication Date
- 2026-06-23
Smart Images

Figure CN122263133A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of blockchain technology, and in particular to a method and system for secure traceability of textile data based on blockchain and smart contracts. Background Technology
[0002] In the textile manufacturing industry, especially in the production of high-end fabrics and precision textiles, the collection, recording, and traceability of data throughout the entire weaving process are crucial for ensuring product quality, optimizing processes, and meeting compliance requirements. Currently, the mainstream approach to achieving production data traceability typically relies on a centralized database management system. Specifically, various data generated during the operation of weaving equipment, such as warp and weft density, machine speed, number of yarn breaks, temperature, and humidity, are collected and uploaded to a central server or private cloud platform built by the enterprise for centralized storage. This data is usually stored in structured database tables, and the sequence of the production process is simulated by establishing foreign key relationships or timestamp indexes between data records, thus supporting a certain degree of data querying and backtracking. To control data access, the system sets up an account system based on usernames and passwords, assigning differentiated data viewing and operation permissions to users with different roles.
[0003] Conventional centralized data management methods have significant drawbacks: Firstly, their data security and credibility rely entirely on a single centralized institution. Data stored on central servers is at risk of malicious tampering by insiders or loss or damage due to system failures or cyberattacks. Once critical production process parameters or quality inspection data are modified, the foundation of trust in the entire traceability chain is destroyed, making it difficult to provide credible evidence in the event of quality disputes or compliance audits. Secondly, existing solutions present a contradiction between data privacy and flexible sharing. For reasons of trade secrets, companies often need to encrypt or completely isolate sensitive process parameters, while opening up some non-sensitive production process data to downstream partners or regulators in the supply chain. Traditional access control systems are coarse-grained, making it difficult to ensure the confidentiality of sensitive data while simultaneously supporting efficient and verifiable sharing and verification of publicly available data, resulting in low data flow efficiency and auditing difficulties. Summary of the Invention
[0004] This invention provides a method and system for secure traceability of textile data based on blockchain and smart contracts, which can solve the problems in the prior art.
[0005] A first aspect of this invention provides a method for secure traceability of textile data based on blockchain and smart contracts, comprising: Collect multi-source heterogeneous weaving data generated by the weaving equipment during the weaving process, encrypt and convert the sensitive weaving data of the multi-source heterogeneous weaving data to generate ciphertext data segments, extract features from the public weaving data of the multi-source heterogeneous weaving data to generate plaintext digest segments, and combine the ciphertext data segments and plaintext digest segments to form a hybrid structure weaving data package. The hash value of the woven data packet is calculated, and the hash value of the current woven data packet is chained together with the hash value of the previous woven data packet to generate a hash chain with time-series dependency. The hash chain is submitted to multiple verification nodes in the blockchain network. Each verification node performs distributed verification of the integrity and validity of the hash chain based on a preset consensus algorithm. When the preset verification threshold is reached, the hash chain is written into a block to form an immutable on-chain certificate. Deploy smart contracts on a blockchain network. The smart contracts are encoded with data access permission rules and key distribution rules. Receive traceability query requests from query requesters. The traceability query requests include the query target identifier and the query requester's digital signature. The smart contract verifies the matching relationship between the digital signature and the pre-stored authorized identity information. Once the verification is successful, the scope of accessible data is determined based on the permission level of the query requester. The hash chain corresponding to the query target identifier is read from the blockchain network, and the chain-like association relationship of the hash chain is traced back to the corresponding fabricated data packet.
[0006] The sensitive weaving data of the multi-source heterogeneous weaving data is encrypted and converted to generate ciphertext data segments. Features are extracted from the public weaving data of the multi-source heterogeneous weaving data to generate plaintext digest segments. The ciphertext data segments and plaintext digest segments are combined to form a hybrid structure weaving data packet, including: The multi-source heterogeneous weaving data is classified and labeled according to the preset data sensitivity classification rules. Weaving data involving process formula parameters and equipment operating parameters are labeled as sensitive weaving data, and weaving data involving product appearance parameters and production batch information are labeled as public weaving data. The sensitive weaving data is encrypted using a symmetric encryption algorithm to generate a ciphertext data segment. The encryption key used by the symmetric encryption algorithm is then encrypted using an asymmetric encryption method and stored in association with the ciphertext data segment. Feature extraction is performed on the publicly available weaving data to extract attribute values that characterize product quality status and production progress, and a plaintext summary segment is generated based on the attribute values. The ciphertext data segment, the encrypted encryption key, and the plaintext digest segment are encapsulated and combined according to a preset data structure format to form a woven data packet with a hybrid structure containing data type identifier, data length identifier, and data content.
[0007] The hash chain is submitted to multiple verification nodes in the blockchain network. Each verification node performs distributed verification of the integrity and validity of the hash chain based on a preset consensus algorithm. When a preset verification threshold is reached, the hash chain is written into a block to form an immutable on-chain certificate, including: The hash chain is broadcast to all verification nodes in the blockchain network. After receiving the hash chain, each verification node performs a correctness check on the chain association operation result between the hash value of the current woven data packet and the hash value of the previous woven data packet in the hash chain, and verifies whether the hash chain satisfies the preset time-series dependency relationship. Each verification node votes on the verified hash chain based on a preset consensus algorithm, counts the number of verification nodes that have passed the vote, and when the number of verification nodes that have passed the vote reaches a preset verification threshold, the accounting node in the blockchain network encapsulates the hash chain into a new block and adds the new block to the end of the main chain of the blockchain network to complete the generation of on-chain credentials. If the number of verification nodes that pass the vote does not reach the preset verification pass threshold, the hash chain will not be written into the block and a verification failure flag will be returned to the data submitter.
[0008] Each verification node votes on the verified hash chains based on a preset consensus algorithm, and the number of verification nodes that passed the vote is counted, including: Each verification node performs voting weight calculation according to a preset consensus algorithm. The voting weight calculation is based on the historical verification accuracy and online duration of the verification node to determine the voting weight coefficient of each verification node. Each verification node initiates a vote on the hash chain that has passed verification, generating a voting message containing the verification node identifier and the voting result. The voting message is signed by the verification node's private key and broadcast to the blockchain network. The consensus management module in the blockchain network collects the voting messages of all verification nodes, extracts the voting results from each voting message, and weights and accumulates the voting results according to the voting weight coefficient of the corresponding verification node. The consensus management module compares the weighted cumulative result with a preset verification pass threshold. When the weighted cumulative result is greater than or equal to the preset verification pass threshold, it is determined that the number of verification nodes that have passed the vote has reached the preset verification pass threshold.
[0009] The smart contract verifies the matching relationship between the digital signature and the pre-stored authorized identity information. Upon successful verification, it determines the accessible data range based on the requester's permission level, reads the hash chain corresponding to the query target identifier from the blockchain network, and traces the chain-like relationship of the hash chain to the corresponding fabricated data packet, including: The smart contract extracts the digital signature and the identity identifier of the querying party from the traceability query request, and reads the pre-stored authorized identity information database from the blockchain network. The authorized identity information database stores the mapping relationship between the identity identifiers of each authorized entity and the corresponding public key. The smart contract uses the public key corresponding to the identity identifier to decrypt and verify the digital signature, and determines whether the decryption result is consistent with the original content of the traceability query request. If they are consistent, the verification is deemed successful. The system retrieves the permission level of the requester from the pre-stored permission configuration table based on the identity identifier. The permission configuration table records the range of accessible data fields corresponding to each permission level. Based on the query target identifier, the system retrieves the corresponding hash chain from the blockchain network. Starting from the latest node of the hash chain, the smart contract traverses each hash node in reverse along the chain relationship until it locates the woven data packet that matches the query target identifier.
[0010] Based on the query target identifier, the corresponding hash chain is retrieved from the blockchain network. The smart contract starts from the latest node of the hash chain and traverses each hash node in reverse along the chain relationship until the woven data packet matching the query target identifier is located, including: The smart contract extracts the index field from the target identifier as the search condition. The index field includes the weaving equipment identifier and the weaving batch timestamp. The smart contract performs a hash chain location query based on the search condition in the index storage layer of the blockchain network to obtain the head node address of the hash chain that matches the search condition. The smart contract reads the latest hash node corresponding to the chain head node address, extracts the current weaving data packet hash value and the previous hash node address stored in the latest hash node, matches and compares the current weaving data packet hash value with the target hash feature value in the query target identifier, and terminates the traversal when the match is successful and returns the weaving data packet storage address associated with the current hash node. When a match fails, the smart contract reads the preceding hash node pointed to by the preceding hash node address, and repeats the hash value extraction and matching operation until a match is successful or the starting node of the hash chain is reached. Based on the weaving data packet storage address associated with the successfully matched hash node, the corresponding weaving data packet is read from the data storage layer of the blockchain network.
[0011] A second aspect of this invention provides a secure traceability system for textile data based on blockchain and smart contracts, comprising: The data acquisition unit is used to collect multi-source heterogeneous weaving data generated by the weaving equipment during the weaving process, encrypt and convert sensitive weaving data of the multi-source heterogeneous weaving data to generate ciphertext data segments, extract features from public weaving data of the multi-source heterogeneous weaving data to generate plaintext digest segments, and combine the ciphertext data segments and plaintext digest segments to form a hybrid structure weaving data packet. The hash chain generation unit is used to calculate the hash value of the woven data packet, perform chain association operation on the hash value of the current woven data packet and the hash value of the previous woven data packet to generate a hash chain with time-series dependency, and submit the hash chain to multiple verification nodes in the blockchain network. Each verification node performs distributed verification of the integrity and validity of the hash chain based on a preset consensus algorithm. When the preset verification threshold is reached, the hash chain is written into a block to form an immutable on-chain certificate. A smart contract unit is used to deploy smart contracts on a blockchain network. The smart contract is encoded with data access permission rules and key distribution rules. It receives traceability query requests from query requesters. The traceability query requests include the query target identifier and the query requester's digital signature. The traceability query unit is used by the smart contract to verify the matching relationship between the digital signature and the pre-stored authorized identity information. After the verification is successful, the range of accessible data is determined according to the permission level of the query requester. The hash chain corresponding to the query target identifier is read from the blockchain network, and the chain-like association relationship of the hash chain is traced back to the corresponding fabricated data packet.
[0012] A third aspect of the present invention provides an electronic device, comprising: processor; Memory used to store processor-executable instructions; The processor is configured to invoke instructions stored in the memory to execute the aforementioned method.
[0013] A fourth aspect of the present invention provides a computer-readable storage medium having stored thereon computer program instructions that, when executed by a processor, implement the aforementioned method.
[0014] This method achieves secure and reliable traceability of the entire weaving data process. By classifying and processing multi-source heterogeneous weaving data, sensitive data is encrypted and converted into ciphertext data segments, while features of publicly available data are extracted to generate plaintext digest segments. These are then combined to form a hybrid data packet structure. This approach ensures the security of sensitive information such as core process parameters while retaining publicly verifiable data features, thus balancing data confidentiality with the feasibility of traceability verification. The hybrid data packet structure effectively balances data privacy protection requirements with on-chain evidence storage and verification efficiency.
[0015] Hash chain technology is used to perform time-series correlation processing on the woven data packets. By calculating the hash value of the current data packet and performing a chain operation with the previous hash values, a hash chain with strict time-series dependencies is generated. This chain is then written into a block after being distributed verified by multiple verification nodes in the blockchain network based on a consensus algorithm, forming an immutable on-chain notarization. The hash chain structure ensures the continuity and integrity of data records; any data tampering at any stage will cause subsequent hash value verification to fail, thus establishing a full-process anti-tampering mechanism from data collection to on-chain notarization.
[0016] This system leverages smart contracts to achieve fine-grained data access control and automated traceability. The data access permission rules and key distribution rules encoded within the smart contract automatically verify the digital signature and permission level of the requesting party. Upon successful verification, the contract precisely defines the scope of accessible data according to preset rules and automatically executes the tracing process along the hash chain. This mechanism achieves programmatic and decentralized execution of the data traceability process, eliminating the risks of single points of failure and permission abuse in traditional centralized systems, and ensuring that data access strictly adheres to preset policies. Attached Figure Description
[0017] Figure 1 A flowchart illustrating a data security traceability method for textile fabrication based on blockchain and smart contracts; Figure 2 A flowchart for constructing a fabricated data package. Detailed Implementation
[0018] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0019] The technical solution of the present invention will be described in detail below with reference to specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.
[0020] refer to Figure 1 and Figure 2 A method for secure traceability of textile data based on blockchain and smart contracts includes: Collect multi-source heterogeneous weaving data generated by the weaving equipment during the weaving process, encrypt and convert the sensitive weaving data of the multi-source heterogeneous weaving data to generate ciphertext data segments, extract features from the public weaving data of the multi-source heterogeneous weaving data to generate plaintext digest segments, and combine the ciphertext data segments and plaintext digest segments to form a hybrid structure weaving data package. The hash value of the woven data packet is calculated, and the hash value of the current woven data packet is chained together with the hash value of the previous woven data packet to generate a hash chain with time-series dependency. The hash chain is submitted to multiple verification nodes in the blockchain network. Each verification node performs distributed verification of the integrity and validity of the hash chain based on a preset consensus algorithm. When the preset verification threshold is reached, the hash chain is written into a block to form an immutable on-chain certificate. Deploy smart contracts on a blockchain network. The smart contracts are encoded with data access permission rules and key distribution rules. Receive traceability query requests from query requesters. The traceability query requests include the query target identifier and the query requester's digital signature. The smart contract verifies the matching relationship between the digital signature and the pre-stored authorized identity information. Once the verification is successful, the scope of accessible data is determined based on the permission level of the query requester. The hash chain corresponding to the query target identifier is read from the blockchain network, and the chain-like association relationship of the hash chain is traced back to the corresponding fabricated data packet.
[0021] For example, the sensitive weaving data of the multi-source heterogeneous weaving data is encrypted to generate ciphertext data segments, features are extracted from the public weaving data of the multi-source heterogeneous weaving data to generate plaintext digest segments, and the ciphertext data segments and plaintext digest segments are combined to form a hybrid structure weaving data packet, including: The multi-source heterogeneous weaving data is classified and labeled according to the preset data sensitivity classification rules. Weaving data involving process formula parameters and equipment operating parameters are labeled as sensitive weaving data, and weaving data involving product appearance parameters and production batch information are labeled as public weaving data. The sensitive weaving data is encrypted using a symmetric encryption algorithm to generate a ciphertext data segment. The encryption key used by the symmetric encryption algorithm is then encrypted using an asymmetric encryption method and stored in association with the ciphertext data segment. Feature extraction is performed on the publicly available weaving data to extract attribute values that characterize product quality status and production progress, and a plaintext summary segment is generated based on the attribute values. The ciphertext data segment, the encrypted encryption key, and the plaintext digest segment are encapsulated and combined according to a preset data structure format to form a woven data packet with a hybrid structure containing data type identifier, data length identifier, and data content.
[0022] After collecting multi-source heterogeneous weaving data such as mechanical tension, warp and weft density, temperature and humidity, and rotation speed generated during the operation of the weaving equipment, the data is first scanned and classified line by line according to data sensitivity classification rules. Specifically, the data fields are compared one by one through a preset sensitive field matching table. When the data field contains information such as dye ratio, fiber blending ratio, and sizing formula components in the process formula, or when the data field contains information such as spindle speed setting value, tension control curve, and air jet pressure threshold in the equipment operating parameters, the weaving data is marked as sensitive weaving data and assigned a sensitive flag bit "1". When the data field contains product appearance parameters such as fabric surface gloss, color difference value, and defect coordinates, or production batch information such as production batch number, production timestamp, and shift code, the weaving data is marked as public weaving data and assigned a sensitive flag bit "0".
[0023] For data items labeled as sensitive textile data, AES-256 symmetric encryption algorithm is used for encryption. During encryption, a random generator produces a 256-bit encryption key. This key is used to encrypt the sensitive textile data in blocks of 128 bits each, using chain encryption in CBC mode to generate ciphertext data segments. To ensure secure transmission of the encryption key, RSA-2048 asymmetric encryption algorithm is used to encrypt the symmetric key. During encryption, a pre-distributed public key is used to perform encryption operations on the encryption key, resulting in encrypted key ciphertext. The key ciphertext and ciphertext data segments are bound and stored using an association identifier generated in UUID format, ensuring a unique mapping between each ciphertext data segment and its corresponding key ciphertext.
[0024] For data items labeled as publicly available weaving data, feature extraction was performed. During extraction, key attributes characterizing product quality were selected, including numerical attributes such as fabric weight, measured warp and weft density, breaking strength, and colorfastness grade. Attributes characterizing production progress were also extracted, including current production meters, percentage completed, and estimated completion time. The extracted attribute values were organized into a structured plaintext summary segment using a "attribute name-attribute value" key-value pair format. This plaintext summary segment was encoded in JSON format for easy subsequent parsing and display.
[0025] After encryption conversion and feature extraction, each data segment is encapsulated according to a preset data structure format. The data packet structure includes a header area and a data area. The header area contains a 4-byte data type identifier field to identify the data packet version, a 2-byte data length identifier field to record the total byte length of the data packet, and an 8-byte timestamp field to record the data packet generation time. The data area sequentially stores ciphertext data segments, encrypted key ciphertext, and plaintext digest segments, with delimiters separating the data segments. After encapsulation, a hybrid structured woven data packet is generated. This data packet contains both encrypted sensitive information and directly readable public digest information, achieving a balance between data security and traceability.
[0026] For example, the hash chain is submitted to multiple verification nodes in the blockchain network. Each verification node performs distributed verification of the integrity and validity of the hash chain based on a preset consensus algorithm. When a preset verification threshold is reached, the hash chain is written into a block to form an immutable on-chain certificate, including: The hash chain is broadcast to all verification nodes in the blockchain network. After receiving the hash chain, each verification node performs a correctness check on the chain association operation result between the hash value of the current woven data packet and the hash value of the previous woven data packet in the hash chain, and verifies whether the hash chain satisfies the preset time-series dependency relationship. Each verification node votes on the verified hash chain based on a preset consensus algorithm, counts the number of verification nodes that have passed the vote, and when the number of verification nodes that have passed the vote reaches a preset verification threshold, the accounting node in the blockchain network encapsulates the hash chain into a new block and adds the new block to the end of the main chain of the blockchain network to complete the generation of on-chain credentials. If the number of verification nodes that pass the vote does not reach the preset verification pass threshold, the hash chain will not be written into the block and a verification failure flag will be returned to the data submitter.
[0027] Once the data packet is encapsulated with a hybrid structure and the hash chain is calculated, the data-on-chain node encapsulates this hash chain into a broadcast message and transmits it to all registered verification nodes in the network via the blockchain's P2P communication protocol. The broadcast message contains the complete data structure of the hash chain, the submission timestamp, and the data source identifier. The verification node's receiving module continuously listens to the network port and immediately triggers the verification process upon receiving the broadcast message.
[0028] The verification node first parses the hash chain's data structure, extracting the hash value of the current woven data packet and the hash value of the preceding woven data packet. For the initial woven data packet, its preceding hash value is set to a predefined genesis hash value. The verification node, according to preset chain-association rules, concatenates the preceding hash value with some characteristic information of the current woven data packet (such as timestamp and device number), and then recalculates the hash value using the SHA-256 algorithm. The calculated hash value is compared byte-by-byte with the hash value of the current woven data packet recorded in the hash chain; if they match completely, the verification passes. Simultaneously, the verification node checks whether the timestamps of each data packet in the hash chain strictly increment to ensure that the temporal dependency is satisfied. If a timestamp is found to be backwards or the hash value does not match, the hash chain is marked as illegal and further processing is rejected.
[0029] After successful verification, the validating node generates a voting message according to a preset consensus algorithm. A commonly used consensus algorithm is a variant of the Byzantine Fault Tolerance algorithm. The validating node encapsulates its own node identifier, verification result, and current block height into a voting message, digitally signs it using its private key, and broadcasts it to the network. The statistics nodes in the blockchain network are responsible for collecting the voting messages from each validating node and verifying the digital signatures to prevent vote forgery. The statistics nodes maintain a real-time vote counter, incrementing it by one for each valid vote received. The preset verification pass threshold is set to two-thirds of the total number of validating nodes in the network; for example, if there are 15 validating nodes in the network, the threshold is 10.
[0030] When the voting counter reaches a preset threshold, the statistics node sends a sealing instruction to the ledger node. The ledger node retrieves the hash chain from the queue of hash chains to be recorded and constructs the data structure of the new block. The new block contains a block header and a block body. The block header records the hash value of the previous block, the timestamp of the current block, and the Merkle root value. The block body stores the hash chain and related metadata. The ledger node performs a hash operation on the entire block data to generate a block hash value, then appends the new block to the end of its local blockchain main chain and broadcasts the new block to the entire network for synchronization. Other nodes update their local blockchain copies after receiving the new block, thus completing the generation of on-chain credentials.
[0031] If the voting counter fails to reach the threshold within the preset voting waiting time window, the statistics node determines that consensus has failed. At this point, the verification failure handling process is triggered. The statistics node generates a verification failure identifier containing a failure reason code and returns it to the data submitter through the blockchain network's message feedback channel. Upon receiving the failure identifier, the data submitter's exception handling module analyzes the cause of failure. If it's due to network jitter, the submission can be resubmitted; if it's due to an incorrect data format, it needs to be corrected before resubmission. The entire verification process forms a complete closed-loop control mechanism, ensuring that only valid hash chains that pass distributed verification can be written to the blockchain.
[0032] For example, each verification node votes on the verified hash chain based on a preset consensus algorithm, and counts the number of verification nodes that passed the vote, including: Each verification node performs voting weight calculation according to a preset consensus algorithm. The voting weight calculation is based on the historical verification accuracy and online duration of the verification node to determine the voting weight coefficient of each verification node. Each verification node initiates a vote on the hash chain that has passed verification, generating a voting message containing the verification node identifier and the voting result. The voting message is signed by the verification node's private key and broadcast to the blockchain network. The consensus management module in the blockchain network collects the voting messages of all verification nodes, extracts the voting results from each voting message, and weights and accumulates the voting results according to the voting weight coefficient of the corresponding verification node. The consensus management module compares the weighted cumulative result with a preset verification pass threshold. When the weighted cumulative result is greater than or equal to the preset verification pass threshold, it is determined that the number of verification nodes that have passed the vote has reached the preset verification pass threshold.
[0033] After the hash chain of the data packet is fully validated, each validator node initiates the voting weight calculation process. Validator nodes read their historical validation records from the blockchain network's consensus management module. These records include the number of validations participated in over a past period (e.g., the last 30 days), the number of correct validations, and the node's cumulative online time. The historical validation accuracy is calculated by dividing the number of correct validations by the total number of validations, with a value between 0 and 1. Node online time is counted in hours, reflecting the validator node's continuous service capability. The voting weight coefficient is determined using a linear weighting method. The calculation multiplies the historical validation accuracy by a coefficient of 0.6 and the normalized online time (current online time divided by the maximum online time of all nodes) by a coefficient of 0.4. The two are then added together to obtain the final weight coefficient. Newly joined validator nodes are assigned an initial weight coefficient of 0.5 by default, which is adjusted based on actual performance after accumulating sufficient validation records.
[0034] After obtaining the voting weight coefficients, each validator node initiates a voting operation for the currently verified hash chain. The validator node generates a voting message data structure, which includes the validator node's unique identifier (generated from the node's public key hash value), a voting result flag (represented by a Boolean value, true for pass, false for rejection), a voting timestamp, and the corresponding hash chain identifier. The validator node digitally signs the voting message using its own private key, employing an elliptic curve digital signature algorithm, and appends the generated signature data to the end of the voting message. The signed voting message is broadcast to all other validator nodes and the consensus management module via the blockchain network's peer-to-peer communication protocol.
[0035] The consensus management module continuously monitors the broadcast of voting messages in the blockchain network. Upon receiving a voting message, it first verifies the validity of the digital signature in the message. It then verifies the signature using the public key corresponding to the verification node identifier in the voting message, confirming that the message has not been tampered with and indeed originates from the claimed verification node. After successful signature verification, it extracts the voting result flag and verification node identifier from the voting message. The consensus management module maintains a voting record table, indexed by the hash chain identifier, recording the voting result of each verification node. It queries the voting record table for the voting weight coefficient corresponding to the current voting node, multiplies this weight coefficient by the voting result, and assigns a weight value equal to the node's weight coefficient when the vote passes and zero weight value when the vote is rejected.
[0036] The consensus management module performs a weighted cumulative calculation on all received voting messages. It initializes the cumulative weight variable to zero, iterates through all voting records in the voting record table for that hash chain, and adds the weight coefficient of each validator node that passed the vote to the cumulative weight variable. The weighted cumulative process is updated in real time; the cumulative weight is recalculated each time a new voting message is received. The final weighted cumulative result is obtained when all validators have completed their voting or the preset voting deadline has been reached.
[0037] The consensus management module compares the weighted cumulative result with a preset verification threshold. This threshold is set based on the security requirements of the blockchain network, typically two-thirds of the total weight of all verification nodes, ensuring sufficient representativeness of the voting results. During the comparison, if the weighted cumulative result exceeds the preset threshold, the number of verification nodes that have passed the vote is considered to have reached the preset requirement, triggering the subsequent operation of writing the hash chain into a block. If the weighted cumulative result is less than the threshold, the hash chain fails consensus verification, the system records the reason for rejection, and notifies the submitter of the data packet to recheck data integrity.
[0038] For example, the smart contract verifies the matching relationship between the digital signature and the pre-stored authorized identity information. Upon successful verification, it determines the accessible data range based on the requester's permission level, reads the hash chain corresponding to the query target identifier from the blockchain network, and traces the chain-like association of the hash chain to the corresponding fabricated data packet, including: The smart contract extracts the digital signature and the identity identifier of the querying party from the traceability query request, and reads the pre-stored authorized identity information database from the blockchain network. The authorized identity information database stores the mapping relationship between the identity identifiers of each authorized entity and the corresponding public key. The smart contract uses the public key corresponding to the identity identifier to decrypt and verify the digital signature, and determines whether the decryption result is consistent with the original content of the traceability query request. If they are consistent, the verification is deemed successful. The system retrieves the permission level of the requester from the pre-stored permission configuration table based on the identity identifier. The permission configuration table records the range of accessible data fields corresponding to each permission level. Based on the query target identifier, the system retrieves the corresponding hash chain from the blockchain network. Starting from the latest node of the hash chain, the smart contract traverses each hash node in reverse along the chain relationship until it locates the woven data packet that matches the query target identifier.
[0039] Upon receiving a traceability query request, the smart contract first parses the request data structure to extract the requester's identity and digital signature information. The identity can be an address format derived from the public key, for example, the first 160 bits of the public key can be used as a unique identifier after performing a SHA-256 hash operation. The smart contract accesses the authorized identity information database stored in the blockchain network. This database uses a key-value pair structure to maintain the correspondence between the identity of each authorized entity and its public key. The public key is generated using the secp256k1 curve in elliptic curve cryptography and is 256 bits long.
[0040] In the digital signature verification process, the smart contract reads the public key that matches the identity identifier and then decrypts the digital signature. The digital signature is generated by the requesting party using their private key to sign the hash value of the traceability query request, employing the Elliptic Curve Digital Signature Algorithm (ECDSA). The smart contract uses its public key to decrypt and recover the signature, then compares the recovered result byte-by-byte with the hash value recalculated from the original content of the traceability query request. When the two hash values match perfectly, it proves that the request was indeed issued by the claimed identity holder and that the content has not been tampered with; verification is successful. If the hash values do not match or the public key cannot successfully decrypt the signature, the query request is rejected and an exception is logged.
[0041] After successful verification, the smart contract queries a pre-stored permission configuration table based on the identity identifier. This configuration table uses a hierarchical structure, dividing permission levels into five levels. Level 1 permissions allow access to encrypted data segments containing sensitive weaving data; Level 2 permissions only allow access to process parameters in plaintext digest segments; and Levels 3 through 5 progressively decrease the access scope. Each permission level in the configuration table corresponds to a whitelist of data fields, explicitly listing the names of the data fields that can be read at that level. Examples include public fields such as loom number, weaving time, and yarn batch, or sensitive fields such as equipment operating parameters and process formulas. After reading the permission level of the requesting party, the smart contract loads the corresponding data field whitelist and stores it in a temporary variable.
[0042] The smart contract receives a query target identifier, which can be a weaving batch number, product number, or timestamp range. The smart contract performs a retrieval operation in the blockchain network's state database, locating the corresponding hash chain through the query target identifier. Each node in the hash chain stores the hash value of the current weaving data packet and the hash value of the previous weaving data packet, forming a unidirectional chain structure. The smart contract obtains the starting hash value from the latest node in the hash chain and backtracks to historical nodes by reading the previous hash value field stored in the node. During traversal, the smart contract extracts the metadata of the weaving data packet associated with each node and checks the query target identifier field. When the identifier in the metadata matches the query target identifier, the smart contract locates the target weaving data packet and reads its storage address. Based on a whitelist of data fields corresponding to the permission level, the smart contract performs field-level filtering on the weaving data packet, returning only data content within the whitelist range. Sensitive fields outside the permission range are replaced with placeholders, ensuring that data access complies with the preset permission control policy.
[0043] For example, based on the query target identifier, the corresponding hash chain is retrieved from the blockchain network. The smart contract starts from the latest node of the hash chain and traverses each hash node backward along the chain relationship until the woven data packet matching the query target identifier is located, including: The smart contract extracts the index field from the target identifier as the search condition. The index field includes the weaving equipment identifier and the weaving batch timestamp. The smart contract performs a hash chain location query based on the search condition in the index storage layer of the blockchain network to obtain the head node address of the hash chain that matches the search condition. The smart contract reads the latest hash node corresponding to the chain head node address, extracts the current weaving data packet hash value and the previous hash node address stored in the latest hash node, matches and compares the current weaving data packet hash value with the target hash feature value in the query target identifier, and terminates the traversal when the match is successful and returns the weaving data packet storage address associated with the current hash node. When a match fails, the smart contract reads the preceding hash node pointed to by the preceding hash node address, and repeats the hash value extraction and matching operation until a match is successful or the starting node of the hash chain is reached. Based on the weaving data packet storage address associated with the successfully matched hash node, the corresponding weaving data packet is read from the data storage layer of the blockchain network.
[0044] For tracing the origin of weaving data, the smart contract receives a tracing query request containing the target identifier and initiates an on-chain data retrieval process. The target identifier employs a composite structure, with the index field carrying two key retrieval dimensions: the weaving equipment identifier and the weaving batch timestamp. The weaving equipment identifier uses a globally unique encoding rule, consisting of three segments: manufacturer code, equipment model, and serial number. For example, "WV-2024-A3-001287" represents the unique identity of a specific textile machine. The weaving batch timestamp records the precise moment the data packet was generated, with millisecond-level precision, in a Unix timestamp format plus a nanosecond offset, ensuring accurate time-series positioning.
[0045] The smart contract uses the parsed index field as a search condition to initiate a query request to the index storage layer of the blockchain network. The index storage layer maintains a B+ tree index structure built according to the two dimensions of weaving device identifier and timestamp. Each weaving device corresponds to a hash chain, and the address of the chain head node is stored in the leaf node of the index table. The query operation first matches the weaving device identifier to locate the index branch of the target device, then narrows the search range according to the timestamp range, and finally obtains the address of the chain head node that matches the hash chain. This address is a 32-byte hexadecimal storage pointer in the blockchain network.
[0046] After obtaining the address of the chain head node, the smart contract accesses that address through the blockchain network's state read interface to read the complete data structure of the latest hash node. The hash node stores four core fields: the hash value of the current woven data packet, the address of the previous hash node, the block height, and the timestamp. The hash value of the current woven data packet is generated using the SHA-256 algorithm and is a 64-character hexadecimal string. The smart contract extracts this hash value and compares it byte-by-byte with the target hash feature value carried in the query target identifier, using a constant-time comparison algorithm to avoid the risk of time-series attacks.
[0047] When a hash value match is successful, it indicates that the woven data packet associated with the current hash node is the query target. The smart contract reads the storage address of the woven data packet from the hash node. This address points to the IPFS content identifier or resource locator of the distributed storage node in the blockchain network's data storage layer. The smart contract terminates the hash chain traversal process, encapsulates the storage address in the response structure, and prepares to execute subsequent permission verification and data retrieval operations.
[0048] If a hash value match fails, the smart contract reads the address field of the preceding hash node from the current hash node. This field stores the position of the hash node generated earlier in time. The smart contract then backtracks along this address, reads the data structure of the preceding hash node, and repeats the iterative process of hash value extraction and matching. The traversal operation proceeds in reverse according to the chain relationship. Each iteration consumes a fixed gas fee. The smart contract has a built-in traversal depth counter to prevent infinite loops caused by abnormal data.
[0049] The traversal process continues until one of two termination conditions is triggered: either a successful hash value match locates the target woven data packet, or the starting node of the hash chain is reached, and the address field of the preceding hash node is null. If no match is found even after reaching the starting node, the smart contract determines that the query target identifier is invalid, generates an error code, and returns it to the query requester. The error message includes the number of hash nodes traversed and the earliest arrival timestamp, facilitating the identification of the cause of the deviation in the query parameters.
[0050] Once the storage address of the woven data packet is successfully located, the smart contract reads the complete woven data packet from the data storage layer based on that address. The data storage layer employs a sharding strategy, where large woven data packets are divided into multiple data blocks for distributed storage. Each data block is accompanied by a sequential index and an integrity check code. The smart contract reads each data block sequentially according to the sequential index, performs check code verification on each data block to confirm that no damage occurred during data transmission, and then reassembles the verified data blocks in sequence to form a complete woven data packet, completing the entire on-chain retrieval process for traceability.
[0051] A second aspect of this invention provides a secure traceability system for textile data based on blockchain and smart contracts, comprising: The data acquisition unit is used to collect multi-source heterogeneous weaving data generated by the weaving equipment during the weaving process, encrypt and convert sensitive weaving data of the multi-source heterogeneous weaving data to generate ciphertext data segments, extract features from public weaving data of the multi-source heterogeneous weaving data to generate plaintext digest segments, and combine the ciphertext data segments and plaintext digest segments to form a hybrid structure weaving data packet. The hash chain generation unit is used to calculate the hash value of the woven data packet, perform chain association operation on the hash value of the current woven data packet and the hash value of the previous woven data packet to generate a hash chain with time-series dependency, and submit the hash chain to multiple verification nodes in the blockchain network. Each verification node performs distributed verification of the integrity and validity of the hash chain based on a preset consensus algorithm. When the preset verification threshold is reached, the hash chain is written into a block to form an immutable on-chain certificate. A smart contract unit is used to deploy smart contracts on a blockchain network. The smart contract is encoded with data access permission rules and key distribution rules. It receives traceability query requests from query requesters. The traceability query requests include the query target identifier and the query requester's digital signature. The traceability query unit is used by the smart contract to verify the matching relationship between the digital signature and the pre-stored authorized identity information. After the verification is successful, the range of accessible data is determined according to the permission level of the query requester. The hash chain corresponding to the query target identifier is read from the blockchain network, and the chain-like association relationship of the hash chain is traced back to the corresponding fabricated data packet.
[0052] A third aspect of the present invention provides an electronic device, comprising: processor; Memory used to store processor-executable instructions; The processor is configured to invoke instructions stored in the memory to execute the aforementioned method.
[0053] A fourth aspect of the present invention provides a computer-readable storage medium having stored thereon computer program instructions that, when executed by a processor, implement the aforementioned method.
[0054] This invention can be a method, apparatus, system, and / or computer program product. The computer program product may include a computer-readable storage medium having computer-readable program instructions loaded thereon for performing various aspects of the invention.
[0055] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for woven data security traceability based on blockchain and smart contract, characterized in that, include: Collect multi-source heterogeneous weaving data generated by the weaving equipment during the weaving process, encrypt and convert the sensitive weaving data of the multi-source heterogeneous weaving data to generate ciphertext data segments, extract features from the public weaving data of the multi-source heterogeneous weaving data to generate plaintext digest segments, and combine the ciphertext data segments and plaintext digest segments to form a hybrid structure weaving data package. The hash value of the woven data packet is calculated, and the hash value of the current woven data packet is chained together with the hash value of the previous woven data packet to generate a hash chain with time-series dependency. The hash chain is submitted to multiple verification nodes in the blockchain network. Each verification node performs distributed verification of the integrity and validity of the hash chain based on a preset consensus algorithm. When the preset verification threshold is reached, the hash chain is written into a block to form an immutable on-chain certificate. Deploy smart contracts on a blockchain network. The smart contracts are encoded with data access permission rules and key distribution rules. Receive traceability query requests from query requesters. The traceability query requests include the query target identifier and the query requester's digital signature. The smart contract verifies the matching relationship between the digital signature and the pre-stored authorized identity information. Once the verification is successful, the scope of accessible data is determined based on the permission level of the query requester. The hash chain corresponding to the query target identifier is read from the blockchain network, and the chain-like association relationship of the hash chain is traced back to the corresponding fabricated data packet.
2. The method of claim 1, wherein, The sensitive weaving data of the multi-source heterogeneous weaving data is encrypted and converted to generate ciphertext data segments. Features are extracted from the public weaving data of the multi-source heterogeneous weaving data to generate plaintext digest segments. The ciphertext data segments and plaintext digest segments are combined to form a hybrid structure weaving data packet, including: The multi-source heterogeneous weaving data is classified and labeled according to the preset data sensitivity classification rules. Weaving data involving process formula parameters and equipment operating parameters are labeled as sensitive weaving data, and weaving data involving product appearance parameters and production batch information are labeled as public weaving data. The sensitive weaving data is encrypted using a symmetric encryption algorithm to generate a ciphertext data segment. The encryption key used by the symmetric encryption algorithm is then encrypted using an asymmetric encryption method and stored in association with the ciphertext data segment. Feature extraction is performed on the publicly available weaving data to extract attribute values that characterize product quality status and production progress, and a plaintext summary segment is generated based on the attribute values. The ciphertext data segment, the encrypted encryption key, and the plaintext digest segment are encapsulated and combined according to a preset data structure format to form a woven data packet with a hybrid structure containing data type identifier, data length identifier, and data content.
3. The method according to claim 1, characterized in that, The hash chain is submitted to multiple verification nodes in the blockchain network. Each verification node performs distributed verification of the integrity and validity of the hash chain based on a preset consensus algorithm. When a preset verification threshold is reached, the hash chain is written into a block to form an immutable on-chain certificate, including: The hash chain is broadcast to all verification nodes in the blockchain network. After receiving the hash chain, each verification node performs a correctness check on the chain association operation result between the hash value of the current woven data packet and the hash value of the previous woven data packet in the hash chain, and verifies whether the hash chain satisfies the preset time-series dependency relationship. Each verification node votes on the verified hash chain based on a preset consensus algorithm, counts the number of verification nodes that have passed the vote, and when the number of verification nodes that have passed the vote reaches a preset verification threshold, the accounting node in the blockchain network encapsulates the hash chain into a new block and adds the new block to the end of the main chain of the blockchain network to complete the generation of on-chain credentials. If the number of verification nodes that pass the vote does not reach the preset verification pass threshold, the hash chain will not be written into the block and a verification failure flag will be returned to the data submitter.
4. The method according to claim 3, characterized in that, Each verification node votes on the verified hash chains based on a preset consensus algorithm, and the number of verification nodes that passed the vote is counted, including: Each verification node performs voting weight calculation according to a preset consensus algorithm. The voting weight calculation is based on the historical verification accuracy and online duration of the verification node to determine the voting weight coefficient of each verification node. Each verification node initiates a vote on the hash chain that has passed verification, generating a voting message containing the verification node identifier and the voting result. The voting message is signed by the verification node's private key and broadcast to the blockchain network. The consensus management module in the blockchain network collects the voting messages of all verification nodes, extracts the voting results from each voting message, and weights and accumulates the voting results according to the voting weight coefficient of the corresponding verification node. The consensus management module compares the weighted cumulative result with a preset verification pass threshold. When the weighted cumulative result is greater than or equal to the preset verification pass threshold, it is determined that the number of verification nodes that have passed the vote has reached the preset verification pass threshold.
5. The method according to claim 1, characterized in that, The smart contract verifies the matching relationship between the digital signature and the pre-stored authorized identity information. Upon successful verification, it determines the accessible data range based on the requester's permission level, reads the hash chain corresponding to the query target identifier from the blockchain network, and traces the chain-like relationship of the hash chain to the corresponding fabricated data packet, including: The smart contract extracts the digital signature and the identity identifier of the querying party from the traceability query request, and reads the pre-stored authorized identity information database from the blockchain network. The authorized identity information database stores the mapping relationship between the identity identifiers of each authorized entity and the corresponding public key. The smart contract uses the public key corresponding to the identity identifier to decrypt and verify the digital signature, and determines whether the decryption result is consistent with the original content of the traceability query request. If they are consistent, the verification is deemed successful. The system retrieves the permission level of the requester from the pre-stored permission configuration table based on the identity identifier. The permission configuration table records the range of accessible data fields corresponding to each permission level. Based on the query target identifier, the system retrieves the corresponding hash chain from the blockchain network. Starting from the latest node of the hash chain, the smart contract traverses each hash node in reverse along the chain relationship until it locates the woven data packet that matches the query target identifier.
6. The method according to claim 5, characterized in that, Based on the query target identifier, the corresponding hash chain is retrieved from the blockchain network. The smart contract starts from the latest node of the hash chain and traverses each hash node in reverse along the chain relationship until the woven data packet matching the query target identifier is located, including: The smart contract extracts the index field from the target identifier as the search condition. The index field includes the weaving equipment identifier and the weaving batch timestamp. The smart contract performs a hash chain location query based on the search condition in the index storage layer of the blockchain network to obtain the head node address of the hash chain that matches the search condition. The smart contract reads the latest hash node corresponding to the chain head node address, extracts the current weaving data packet hash value and the previous hash node address stored in the latest hash node, matches and compares the current weaving data packet hash value with the target hash feature value in the query target identifier, and terminates the traversal when the match is successful and returns the weaving data packet storage address associated with the current hash node. When a match fails, the smart contract reads the preceding hash node pointed to by the preceding hash node address, and repeats the hash value extraction and matching operation until a match is successful or the starting node of the hash chain is reached. Based on the weaving data packet storage address associated with the successfully matched hash node, the corresponding weaving data packet is read from the data storage layer of the blockchain network.
7. A blockchain and smart contract-based secure traceability system for textile data, used to implement the method as described in any one of claims 1-6, characterized in that, include: The data acquisition unit is used to collect multi-source heterogeneous weaving data generated by the weaving equipment during the weaving process, encrypt and convert sensitive weaving data of the multi-source heterogeneous weaving data to generate ciphertext data segments, extract features from public weaving data of the multi-source heterogeneous weaving data to generate plaintext digest segments, and combine the ciphertext data segments and plaintext digest segments to form a hybrid structure weaving data packet. The hash chain generation unit is used to calculate the hash value of the woven data packet, perform chain association operation on the hash value of the current woven data packet and the hash value of the previous woven data packet to generate a hash chain with time-series dependency, and submit the hash chain to multiple verification nodes in the blockchain network. Each verification node performs distributed verification of the integrity and validity of the hash chain based on a preset consensus algorithm. When the preset verification threshold is reached, the hash chain is written into a block to form an immutable on-chain certificate. A smart contract unit is used to deploy smart contracts on a blockchain network. The smart contract is encoded with data access permission rules and key distribution rules. It receives traceability query requests from query requesters. The traceability query requests include the query target identifier and the query requester's digital signature. The traceability query unit is used by the smart contract to verify the matching relationship between the digital signature and the pre-stored authorized identity information. After the verification is successful, the range of accessible data is determined according to the permission level of the query requester. The hash chain corresponding to the query target identifier is read from the blockchain network, and the chain-like association relationship of the hash chain is traced back to the corresponding fabricated data packet.
8. An electronic device, characterized in that, include: processor; Memory used to store processor-executable instructions; The processor is configured to invoke instructions stored in the memory to execute the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having computer program instructions stored thereon, characterized in that, When the computer program instructions are executed by the processor, they implement the method described in any one of claims 1 to 6.