A Food Traceability System Based on Blockchain and Radio Frequency Identification Technologies

The frequent occurrence of food safety accidents at the global level has triggered consumer sensitivity. Establishing a food traceability system can effectively guarantee food safety and increase consumer confidence and satisfaction. Existing food traceability systems often ignore environmental factors that affect food quality at all stages of the supply chain, and the authenticity of the information obtained through traceability is difficult to guarantee. In this study, a food supply chain traceability model was established based on blockchain and radio frequency identification (RFID) technologies. The model focused on the traceability of environmental data during the various stages of the food supply chain and combined a centralized database and blockchain for data storage. The lot identification data of the various supply chain stages were stored in a centralized database, while the environmental data were stored in a blockchain. Thereby, the authenticity and accuracy of the traceability data were ensured. The blockchain part of the model has been simulated in the Ethereum test environment, and the experiment has achieved traceability of temperature data.


Introduction
In recent years, food safety accidents have occurred frequently [1] [2] [3]. The white paper Food Security in China issued by the State Council of the People's Republic of China highlights that "As food is essential to a nation's prosperity and its people's wellbeing, food security is a major prerequisite for national se-How to cite this paper: Deng, M.L. and Feng, P. (2020) A Food Traceability System Based on Blockchain and Radio Frequency Identification Technologies. Journal of Computer and Communications, 8, 17-27. curity" [4]. Environmental factors, such as temperature and humidity, need to be strictly controlled throughout the many stages of the food supply chain. Inappropriate production or processing environments at any stage may result in adverse consequences, such as mildew and insect damage. Therefore, to minimize food safety issues, it is essential to collect data regarding the supply chain and control the environmental factors of the supply chain that may threaten food safety. In addition, it is necessary to establish a food traceability system whereby authentic, reliable traceability data are accessible and the food supply chain is more transparent to the consumer.
Most existing food traceability systems rely on centralized databases. In such a system, only basic place-of-origin data are uploaded to the database; key environmental factors that affect food quality are not considered. In addition, there are no mechanisms for mutual authentication among the stages of the supply chain, thereby causing information islands. Furthermore, data uploading is usually done manually. Therefore, only limited data are accessible to the consumer, and the authenticity of data is difficult to ensure.
RFID is a non-contact automatic identification technology, and rapid, efficient, and non-visualized object identification even in harsh environments makes it extremely suitable for food traceability applications. An RFID system usually consists of three parts: readers, tags, and backend servers. Readers and tags wirelessly exchange data. A reader can read data from and write data into a tag. Each tag has a unique identification number and is capable of storing a certain amount of data.
Blockchain is a decentralized, distributed database technology. Using rigorous cryptographic algorithms, blockchain connects data-storing blocks in a chain structure according to the order of the generation time of blocks. Therefore, data stored using blockchain technology have a time stamp that cannot be tampered with or manipulated. All transaction records in a blockchain are verified with a complete evidence chain and a highly reliable traceability link. Therefore, the application of blockchain technology in a food traceability system can effectively prevent data tampering and manipulation by any users. Ethereum is a blockchain-based platform featuring smart contracts. Different from Bitcoin applications, which are only for transactions, Ethereum is a brand new, open blockchain platform that allows any user to develop and use decentralized applications based on blockchain technology on the platform. Ganache, which is an in-memory blockchain designed for development and testing, simulates the function of the real Ethereum network. Providing users with a readily available in-memory blockchain, Ganache supports the query of transaction logs and the status monitoring of smart contracts. In this study, a food traceability model was developed and tested in an Ethereum testing environment provided by Ganache.
Owing to its distributed consensus and anti-tampering capabilities, blockchain technology can be used for various applications and provides the highest level of security and trustworthiness [5]. Therefore, the application of blockchain technology to food traceability can effectively ensure the authenticity and reliability of the traceability data. Currently, there are few blockchain-based food tra-ceability systems.
Fabian [6] assessed the feasibility of using blockchain technology to realize the accuracy and transparency of traceability systems. Feng [7] highlighted the substantial advantages of radio frequency identification (RFID) and blockchainbased agri-food traceability systems, particularly their high level of security. Mao [8] designed a novel food trading system with consortium blockchain (FTSCON). Casado-Vara [9] investigated how blockchain technology can improve the supply chain based on a case study of the food supply chain. Xu [10] applied blockchain application design approaches proposed in software architecture community in a real-world project called orginChain and found that the structural design of smart contracts has large impact on the quality of system. Behnke [11] used a template analysis of 16 interviews to inveigated four case in the food supply chain, and proposed eighteen boundary conditions that need to be met to apply the blockchain technology to the food supply chain. Caro [12] used two different blockchain platforms, Ethereum and Hyperledager, to achieve food traceability, and compared the performance of the two platforms. Galvez [13] pointed out that even though the use of blockchain technology to ensure the traceability of food safety seems promising, it still needs to use RFID tags or barcodes to scan food to track data, and then connect the sensor to the blockchain. Therefore, if the attacker tampers with the information collected by the sensor, the information uploaded to the blockchain has been faked.
The existing research on the application of blockchain in food traceability seldom focuses on data regarding environmental factors and their uploading to the blockchain in a tamper-proof manner. In addition, there are no reports on the realization of consumer direct access to data regarding the relevant environmental factors during food production and processing. Therefore, further research is required to realize the uploading of environmental data from sensors to the blockchain and the access of these data from a web page.
Considering the above issues, in this study, a food supply chain traceability model focusing on the traceability of data on the environmental factors during food production and processing was established by combining blockchain and RFID technologies. The model was verified in the testing environment of the blockchain-based Ethereum platform. In particular, environmental data collected by sensors during food production and processing were automatically uploaded to the Ethereum blockchain and were made accessible to the consumer on a web page. The model eliminated the possibility of data tampering by any entity of the supply chain and provided the consumer with direct access to factual environmental data about the various supply chain stages, thereby ensuring reliable and authentic traceability data.

System Architecture Design
In this study, the food supply chain was divided into five stages: farming, sto-rage, transportation, processing, and sales. In each stage, sensors are used to collect data on environmental factors that affect food quality. Foods are a bulk, low-value commodity, making accurate tracing of foods very difficult. Therefore, in the food traceability model proposed in this study, foods are labelled (lot number) at the farming stage. Each lot has an attached RFID tag. A traceability code is assigned to each lot at each stage and is written into the tag. The environmental data collected by sensors are tagged with the corresponding codes, thereby ensuring the accuracy and traceability of the data. At the processing stage, the traceability codes of the previous stage are encrypted to generate a final traceability code, which is printed in the form of two-dimensional barcodes (QR codes) on the outer packaging of the product. The consumer can use the QR code to access all information about the supply chain stages. Therefore, the system generates two types of data that are stored separately: 1) The stages of the supply chain jointly maintain a centralized database. At each stage, the corresponding traceability codes of each food lot are uploaded to the central database in batches, and the data are transparent to all the participating stages in the supply chain. 2) The environmental data of food in each processing stage are collected by sensors and directly uploaded to the blockchain. In each stage, the data collected by sensors are tagged with the corresponding traceability codes so that the environmental data from each stage of each food lot can be retrieved using the corresponding traceability codes. The overall architecture of the food traceability model is shown in Figure 1.

Centralized Database
At the farming stage, foods are identified by paddy field. That is, the food produced by a paddy field is represents a lot and has an RFID tag attached for storing the traceability codes assigned to the lot. The tag is permanently attached to into several sublots at a later stage, a new tag is generated and attached to each new sublot, and the lot subdivision is recorded by adding a leaf note in a tree structure. The traceability tree structure improves the accuracy of food traceability. Figure 2 illustrates the traceability tree structure.
As shown in Figure 2, Z represents the traceability code of the farming stage. Similarly, S represents the traceability code in the storage stage, T represents the traceability code in the transportation stage, and P represents the traceability code in the processing stage. Z 1 is the farming-stage traceability code for the food lot produced by paddy field 001. In the storage stage, the food lot is subdivided into three sublots and stored in three warehouses. In addition to the original tag Z 1 , a new tag is added to each sublot (S 1 , S 2 , and S 3 ) to identify the warehouse. The sublot stored in warehouse 001 is transported by three vehicles. The sublot transported by vehicle 001 is processed in workshop 001, and the food sublots transported by vehicles 002 and 003 are processed in workshop 004. The final traceability code is generated according to the traceability codes for the various stages and is printed in the form of a QR code on the outer packaging of the food product to facilitate query by the consumer.

Blockchain Database
The current blockchain can be categorized into three types: public, private, and consortium. In a public blockchain, all users can visit any notes and have the right to access data and submit transactions. For a public blockchain, the more the users there are, the more the decentralized and the more secure the blockchain is. However, this makes public blockchain slow in data processing. Bitcoin is a typical public blockchain. A private blockchain can be established by a company or a person who alone has the right to write data to the blockchain. Therefore, a private blockchain is not decentralized and is more like a centralized database. A consortium blockchain is established and managed jointly by several entities or organizations. It has a processing speed higher than that of a public blockchain but is decentralized. After the establishment of a consortium blockchain jointly maintained by supply chain entities, the data on the environmental factors throughout the supply chain stages are uploaded to the consortium blockchain to realize mutual authentication and consensus among the users of the consortium blockchain. This design eliminates information islands, ensures the authenticity and validity of the uploaded data, and satisfies the required data processing speed.
Data on the environmental factors throughout the food supply chain are collected using sensors. The entities throughout the supply chain can monitor the environmental data and make the necessary adjustments in a timely manner by means of the cloud platform provided by the sensor supplier. In addition, the sensor data are uploaded automatically to the blockchain according to a pre-set frequency through the application programming interface (API) provided by the supplier, thereby preventing human tampering or errors associated with manual data uploading and providing consumers with authentic traceability data. Figure   3 illustrates the flow of sensor data.

Objective of Test
A test was conducted to verify the automatic uploading of temperature data collected by sensors to the blockchain and the access of the data stored in the blockchain on a web page.
• Operating system: Remix integrated development environment (IDE) for compiling and deploying smart contracts, located at http://remix.ethereum.org/; Ganache for providing a testing environment of the Ethereum blockchain; Web3.js for allowing the Ethereum blockchain to interact with the external environment; HyperText Markup Language (HTML) for writing the visual interface; JQuery for selecting and manipulating HTML elements; JavaScript for uploading and fetching data.

Testing Procedure
To simplify the test, only temperature data uploaded via the sensor API were tested. The testing procedure is as follows: 1) Establish an Ethereum testing environment using Ganache. The testing environment was configured with 7545 ports and five initial accounts. Each account was allocated 100,000 Ethers for deploying contracts and verifying transactions.
2) Connect the Remix interface with the testing environment provided by Ganache. The Remix interface was configured with the same number of ports (7545) and connected with Ganache.
3) Write smart contracts using the Solidity.The contracts were configured with two methods: a) getData() for fetching data from the blockchain and b) setData() for uploading data to the blockchain. 4) Compile the contract in the Remix interface to get the ABI (application binary interface) of the contract and deploy it to the test environment provided by Ganache. 5) Write HTML and JavaScript codes for fetching data from the API, and display them on the HTML interface. 6) Upload the API data from the HTML interface to the blockchain.The interaction with the Ethereum blockchain was realized using the libraries of web3.js.
The first step was to configure the provider. Next, the ABI data obtained from the contract compilation were initialized. Finally, the setData() of the contracts was called to upload the fetched API data to the blockchain. 7) Write HTML, JavaScript, and Web3.js codes to access data in the blockchain on a web page.

Testing Results and Analysis
In the test, the API port provided by the sensor supplier was called to realize the automatic uploading of the sensor data to the blockchain. The automatic uploading of the data eliminated the possibility of data tampering through manual data uploading. The temperature changes constantly, but it is not necessary to upload all the real-time temperature data to the blockchain. In addition, uploading all the real-time temperature data leads to a low data storage efficiency and a substantial waste of resources. Thus, at each stage, the frequency of temperature data uploading was different. For example, the frequency was three times a week for the farming stage and once every day for the transportation stage. In this way, not only can data authenticity and validity be ensured but also data storage resources can be saved.
The consumer can access the basic data and environment data of a food product by inputting the final traceability code at the traceability data query page. Figure 4 shows the traceability data query page.
The data regarding the supply chain stages of a food product can be accessed by inputting the traceability code and then clicking the Query button. The place-of-origin data are fetched from the centralized database, while the detailed environmental data are fetched from the blockchain. Figure 5 shows the temperature data obtained from the blockchain.  If an input traceability code does not exist, then an error message appears on the page, reminding the consumer to beware of counterfeiting，as shown in Figure 6.

Conclusions
The authenticity of the traceability data of existing food traceability systems is difficult to ensure. Blockchain technology is popular owing to its anti-tampering capabilities; however, its application in production and everyday life is difficult due to its inability to actively obtain external data. In this study, the traceability of a food supply chain was realized by automatically fetching data collected by sensors from an API and uploading them to a blockchain. With this traceability system, the consumer can access the data stored in the blockchain by inputting the traceability code on a web page, thereby realizing the interaction between the blockchain and the external environment. Our study has reference value for the application of blockchains.
Although assuring food traceability with blockchain and RFID technology looks promising, there remain some limits to be considered. One is that most of the current relevant research focuses on the technical level, and the reason why the research has been unable to be applied in real life may be the limitation of the supply chain organization. Therefore, we suggest that in the research process of applying blockchain technology to achieve food traceability, we should not be limited to technical research, and the supply chain itself should also make corresponding changes to achieve integration with blockchain technology. In addition, in the existing related research, when scholars design the system, because of the inherent security of blockchain technology, they default to the security of the designed system. This idea is biased. Therefore, the author suggests that when designing a food traceability system, a comprehensive analysis of the safety of the design architecture should be carried out, and corresponding defensive measures should be taken against components with potential safety hazards. For example, Figure 6. Warning interface. encrypt the communication process of RFID. The actual measures to be taken need to be decided according to the specific system.