# Research on Flexible Traceability System of _Agaricus bisporus_ Supply Chain
## 4 Design of the System
### Model Construction  
In response to consumers' demands for traceability information in the _Agaricus bisporus_ supply chain, we propose the establishment of a public chain. This chain will facilitate the upload of traceability information related to _Agaricus bisporus_, providing a transparent and accessible query interface. This ensures consumers' right to information and choice regarding food safety and quality.  
To enhance information sharing among upstream and downstream enterprises in the supply chain, we suggest the implementation of an enterprise chain. Through smart contracts, this chain will enable seamless data sharing and circulation between enterprises. This collaborative effort aims to improve the efficiency and quality across various stages of the supply chain.  
For regulatory authorities overseeing quality and safety information, we advocate for the establishment of a supervision chain. This chain will serve as a platform for recording quality and safety information and will include designated supervision nodes. This setup will ensure that regulatory authorities can promptly and effectively access information on food safety and quality, thereby safeguarding public interests.  
The multi-chain traceability model for _Agaricus bisporus_, tailored to the needs of different traceability stakeholders, is illustrated in Figure 3.  
In the multi-subject chain traceability system for _Agaricus bisporus_, the public chain directly uploads plaintext information on the blockchain. The enterprise chain stores plaintext hash values on the blockchain, while adopting a ciphertext approach for data storage and management off the blockchain. The supervision chain stores data information as a 46-character hash value on the blockchain, and in the off-chain domain, it is stored in the IPFS (InterPlanetary File System) file system [25].  
For consumers, their primary concerns usually revolve around data query speed and transparency. Therefore, in the consumer-oriented traceability chain, data are typically stored in plaintext on the blockchain. Consumers can directly query plaintext data through public chain nodes to quickly obtain the information they need.  
For the traceability information within the enterprise chain, the plaintext data undergoes a hash calculation using the SHA-512 algorithm, generating a 512-bit hash value that is uploaded to the enterprise chain to ensure data integrity. Subsequently, the plaintext data are converted into binary form and encrypted using the AES symmetric encryption algorithm, with the ciphertext stored in the local database to ensure data security and privacy. Following this, the ciphertext undergoes attribute-based encryption (CP-ABE) using the access policy vector as the key. During decryption, users are required to provide  
Figure 3: Multi-chain traceability model of _Agaricus bisporus_ for traceability subjects.  
their own attribute vector that complies with the access policy vector of the ciphertext, allowing them to use their private key to decrypt the plaintext data [26; 27; 28].  
CP-ABE technology empowers us to control data access based on specific conditions or attributes. Only users who meet these specific conditions can decrypt and access the data, providing a high level of security and flexibility. In contrast, the AES algorithm uses the same key for encryption and decryption, offering an efficient and reliable data protection mechanism.  
Regulators typically require strict real-time monitoring and review of data to ensure its accuracy and compliance. Since IPFS supports content addressing and content encryption, a file's unique identifier in the IPFS system is its content hash value. If the content of a file is modified, the hash value will also change. Additionally, IPFS supports an encryption file system based on public key cryptography. This system encrypts data using public key encryption algorithms before storing them in the IPFS network. Only users with the corresponding private key can decrypt and access these data, ensuring their security and privacy.