# A Research on Traceability Technology of Agricultural Products Supply Chain Based on Blockchain and IPFS

Authors: Lejun Zhang; Weimin Zeng; Zilong Jin; Yansen Su; Huiling Chen
Journal: Security and Communication Networks
 (2021)

---

## Abstract

Blockchain technology, the fundamental technology of Bitcoin, is featured with high transparency, decentralization, traceability, tamperproof nature, and anonymousness. In this thesis, a case study of the traceability of agricultural products is to explain a traceability solution of agricultural products supply chain based on blockchain and IPFS. The latter one is used to store large quantities of transactions data; and the former one is used for the safety of data storage and circulation. And consumers can know the quality of agricultural products in the shortest time through the evaluation function. As shown in the experiment, the solution is more efficient and secure compared with existing supply chain traceability methods, meeting the traceability requirements of security, transparency, and reliability. Furthermore, the traceability, safety, and performance of the scheme are also analyzed here.


---

## Body

## 1. Introduction

The consumption market in China is facing a brand new era of traceability, and product traceability has become a hot issue concerned by the society. Food security has become an escalating concern in the society. Even though national traceability standards for major products have been formulated by the government, incidents of counterfeit and inferior products often occur in the market. Thus, a series of food security problems have triggered the consumer trust crisis, which is also a major challenge to the efforts made in the progress of the national development of a credible society [1]. The food traceability system can identify the source of food and detail the whole process from food production to dining tables. In case of any food security and quality problem, it can quickly locate the key link of the problem and identify the subject of responsibility to contain the problem from worsening, which provides an effective way to solve the food security problems.The analysis of the current food information storage platforms and supply chains reveals that the current food traceability system is deficient with the following defects: It highly relies on centralized databases, exposing a hidden hazard of information tampering to many key links, such as storage, presentation, and maintenance of data[2]; The phenomenon of “information silo” undermines the current supply chains, as the internal systems of the entities possess most of the information. While the lateral interconnection between the systems is insufficient which makes it difficult to realize the linkage regulation, in the whole circulation process from food production to consumer consumption, the extent and efficiency of automation are insufficiently low in the links of food processing, warehousing, logistics, etc. With broad application of 5 G technology, the demand for data storage is surging sharply, and the market is facing overwhelming pressure with larger scales of data storage requirements. The emergence of IPFS is right on time. The Notice of the General Office of the National Radio and Television Administration on Issuing: A Series of White Papers on the Application of Blockchain Technology has repeatedly mentioned the distributed storage of IPFS and blockchain, affirming the application value and technical advantages of IPFS. The blockchain technology can magnify the function of IPFS, while IPFS can overcome the data storage constraints of blockchain. The combination of the two technologies is the trend of food traceability development in the future. In this thesis, grain traceability, as an example, is introduced to demonstrate the real-time monitoring of the supply chain, in which case effective tracing of grains and traceability of business transactions of agricultural products in the supply chain are realized by virtue of smart contracts deployed in the blockchain, in a bid to carry out real-time monitoring of the supply chain and improve transparency, and we call it Bc-IPFS.The main contributions can be summarized as follows:(i)
Combine blockchain technology and IPFS technology. The details of transactions are stored in IPFS and the hash is stored in the blockchain, which cannot only ensure data security and effectively overcome the shortcoming of constrained data storage capacity of blockchain.(ii)
Discuss the sequence of interaction and relations between major participants, the solution, and the key points resolved.(iii)
Propose the transaction assessment function and make the consumer information and purchased products private.(iv)
Deploy smart contracts based on Hyperledger to realize traceability of the food supply chain and verify the feasibility by the throughput capacity test and delay test.


## 2. Relevant Work

With the development of the blockchain technology, the unique decentralization, traceability, and tamperproof nature of blockchain have been promoting the transition from traditional traceability to blockchain traceability [3]. More and more scholars start to study blockchain-based food supply chain traceability. Yu and Huang [4] put forth the traceability solution for broiler chickens by combining the blockchain technology and RFID technology. With the solution, smart devices can be used to scan the traceable QR code on the chicken claw ring to retrieve the corresponding data and information, where the chicken claw ring is designed into an “inverted tooth” shape to prevent its secondary use. Tian et al. [5] developed an agricultural food supply chain traceability system, covering the whole process of data acquisition and information management of all links of the entire supply chain. The RFID technology is adopted to realize data acquisition, data circulation, and data sharing, and the blockchain technology is adopted to ensure data reliability. However, the RFID technology is deficient in high costs, such as the equipment costs of RFID transmitters, readers, and antennas. Besides, the availability of RFID frequency bands is varied in different countries. RFID is prone to inciting privacy leakage and other problems, and RFID can be easily impacted in an environment containing metal and moisture; thus RFID cannot be broadly utilized in large scale. Afterwards, Tian [6] proposed the food supply chain traceability based on hazard analysis and key control points (HACCP) by adoption of blockchain and Internet of things. Highly similar to the application scenario of [5], it adopts RFID for data acquisition, blockchain technology for ensuring data security, HACCP for monitoring and tracing of supply chains, and BigchainDB for storage and management of food supply chains data. However, on the one hand, BigchainDB is still exposed to the deficiency of RFID, and, on the other hand, it is not ideal for file storage, but for the structural data. Yang et al. [7] used Hyperledger as the traceability chain to store information in the local database, which is useful in solving the problem of blockchain deficiency in massive data storage. However, it is disadvantageous in high cost, slow data transition rate, low security, etc., in comparison with data storage by IPFS. Further, it does not provide the consumer with feedback function, so retailers cannot get access to product security and other aspects in the first time. Xie et al. [8] utilized the IoT technology to carry out ETH-based tracing of agricultural products, ensuring that data will not be maliciously tampered or damaged. However, on the data storage layer, data storage is blockchain-based; thus the network overheads will become increasingly greater with the increase of data volume. Hao et al. [9] researched the traceability storage solution based on the blockchain technology, which stores the crop growth information in IPFS and provides analysis of crop growth data by virtue of the auxiliary database. Although the solution overcomes the data storage constraint of blockchain, the focus of the system is on the acquisition of crop growth information, and thus the solution is not favorable to the information tracing subsequent to crop processing. Besides, the traceability of agricultural product supply chains includes the crop growth information and also the data and information subsequent to crop processing; thus traceability becomes a zero-distance shortcut from farmlands to dining tables. Salah et al. [10] researched the business transaction implementation method relying on ETH-based smart contract, in order to realize the traceability and transparency of soybean supply chain. However, due to the lack of consumer feedback function, retailers cannot gain access to safety problems in the first time after food is sold to consumers, and ETH involves data exploiting processes which consume time and resources.With the development of blockchain 2.0, smart contract has been widely applied, and this thesis discusses the realization of traceability function automation and the introduction of the consumer feedback function based on the smart contract deployed on the blockchain. It is intended that, in case of any agricultural product security problem, entities in the supply chains may respond in the first time.


## 3. A Agricultural Product Supply Chain Traceability Solution Based on Bc-IPFS

In terms of the traceability of agricultural product supply chains, there are high requirements for the backup of transaction data. The IPFS storage technology is to separate a file into many pieces scattered on different locations of the network, which provides more powerful backup capacity compared with cloud storage. The blockchain technology can ensure the integrity of the data stored in IPFS, which is ideal for the traceability of agricultural product supply chains. Thus, in this section, we use the Hyperledger to trace and implement the transactions in the agricultural product supply chains by deployment of smart contracts of chaincode and store transaction information in IPFS to effectively reduce the reliance on the centralized database. Store the hash in the blockchain to take advantage of the features of blockchain to provide secure and reliable transaction records for the management of supply chains and thus ensure the information authenticity and reliability of the agricultural product acquired by the consumers.


### 3.1. Schematic Design

The unique feature of the solution is that it adopts the blockchain as the foundation layer, allows transactions between mutually untrusted users through smart contract, and adopts the IPFS technology to resolve the data storage constraint of blockchain. Within a certain period after the closure of a transaction, the consumer may use the ring signature algorithm to carry out anonymous assessment on the retailer. Relevant regulatory authorities or product suppliers may determine the quality security problems of a certain batch of products in the first time through consumer feedback. The batch information of the product purchased by the consumer can be used to identify the specific product batch, and the smart contract can be used to trace the root cause.In this thesis, we propose the deployment of smart contract on Hyperledger, which can automatically send the preset data resources (including the triggering condition event) according to the contract information agreed in the smart contract when the triggering condition is met. Once the smart contract is deployed, it cannot be changed but can be upgraded to launch new functions or fix bugs [11]. The Fabric smart contract is independent of the underlying ledger, and it is not required to relocate the ledger data to the new smart contract when the smart contract is upgraded, which truly realizes the separation between logic and data. The smart contract of Fabric is referred to as chaincode, including system chaincode and user chaincode [12]. System chaincode is used to realize system-level functions and the processing logics of Fabric nodes, including system configuration, endorsement, and verification [13, 14]. User chaincode operates in an isolated chaincode container and is responsible for the user’s application function, providing status processing logics based on the distributed blockchain ledger. It is programed by application developers as a support to upper-level services. Smart contract receives transactions and triggers events in the form of function call, so that a participating entity can constantly monitor the events being sent in blockchain without too many expenses [15].Figure1 shows the traceability of agricultural products. The Hyperledger smart contract is adopted to record information, and all participants involved in the supply chain are added to the processes, which are used to trace the agricultural products from the place of origin to the end consumers in a digital manner. The supervisory and regulatory bodies or relevant government departments deploy the main smart contract which provides an interface to the entities in the supply chain for function call and transaction implementation. IPFS hash files are stored in blockchain, which can be processed within the specified time period if the product conforms to the buyer’s requirements. Supervisory and regulatory bodies almost deal with the entire supply chain. For instance, the agricultural bureau may carry out supervision, recording and management of farmer information, seed information, product information, etc., to ensure information authenticity. The quality supervision bureau must carry out supervision, management, and recording of processing plant information, retailer information, and product quality information and ensure security and quality of agricultural products. In order to improve the storage capacity, the information of all products and the data of all transactions and events are stored in IPFS, and the blockchain is only used to store the hash value of the data. IPFS is designed for distributed storage, which can be combined with Hyperledger to improve its throughput. The formula symbol description is shown in Table 1. Each transaction (TXtr) bears the product identifier (IDpro), product data hash (Hpro), identifier (IDown) of the product owner and its signature (Sigown), and public key (PKown)(1)TXtr=IDpro||Hpro||IDown||Sigown||Pkown,Hpro=Ptyp||Pquan||Ppri||Pori.Figure 1
Agricultural product supply chain traceability solution based on Bc-IPFS.Table 1
Symbol meaning.
SymbolMeaningIDIdentifierHHashSigUser signaturePKPublic keySKPrivate keymRTransaction order||Connection symbolςRing signatureInfoAssessment informationValuetrustTrust valueTotaltransTotal number of transactionsTXtr is stored in IPFS and hash is stored in blockchain. The product hash (Hpro) includes the product type (Ptyp), quantity (Pquan), price (Ppri), and place of origin (Pori). When a product is confirmed to have been delivered from the seller to the buyer in a transaction, Txtr = [IDpro||Hpro||IDbuy||Sigbuy||PKbuy||Sigsell||Pksell], where IDbuy, Sigbuy, and PKbuy represent the identifier, signature, and public key of the owner, respectively;(2)TXtr=IDpro||Hpro||IDbuy||Sigbuy||Pkbuy||Sigsell||Pksell.IDbuy, Sigsell , and PKsell represent the identifier, signature, and public key of the seller, that is, the signature (Sigown) and public key (PKown) of the product owner in (1). The identity is required to be transformed in the process of product transaction, the owner of a transaction will be the seller in a subsequent transaction, and the buyer will become the owner of the product when the transaction is complete. After the consumer buys the product from the retailer, the seller creates the transaction order mR(3)mR=Φmt,ςSKsell,mt.Only after obtaining the completed ordermR, can the consumer release a comment on the product. Firstly, the consumer verifies the transaction signature ςSKbuy,mt of the retailer(4)Φmt,PKsell,ςSKsell,mt=1.Then, he/she verifies the seller’s signature based on the seller’s public key. Secondly, the consumer creates the ring signatureς based on the assessment information Info=IDpro||Hpro||Psco||Ptxt and sends the Info,ς,mR to the blockchain. The blockchain verifies mR and ς, and, upon successful verification, Info will be stored in IPFS, and HInfo will be stored in the blockchain network. In addition, the trust value(5)Valuetrust=∑α⋅scoreser+β⋅scorequalTotaltrans,Totaltrans≥n, can be calculated through consumers’ evaluation of goods (scoreser), including service score and product quality score for retailers (scorequal), where the coefficient is α+β=1∨α,β∈0,1 and n refers to the number of transactions; even if individual consumers conduct malicious evaluation, the behavior will still have slight impact on the overall evaluation score, effectively reducing the negative effect of malicious evaluation on retailers [16, 17]. The total number of transactions must have at least n successful orders before the trust value is recognized, which can effectively protect new businesses from malicious comments at the initial stage. At the same time, only the first score of each natural month is valid for each user, thus avoiding malicious comments [18].


#### 3.1.1. Data Storage/Query

Any data created from a transaction between both parties will be stored. As shown in Figure2, first, the data will be sent by the http-post method, and when the predefined block size is achieved, the data will be partitioned, packed, and stored in IPFS, and the address of the IPFS storage block will be acquired. Then, the address will be stored in the Fabric blockchain, and the Fabric chaincode will be called to store the information in the peer node ledger for preservation. Upon data query, the http-get method will be adopted for data request, Fabric chain will be initiated to check whether the chaincode includes the IPFS address, and the transaction data will be retrieved from IPFS according to the hash address of the corresponding data block file on IPFS.Figure 2
Functional design of data storage and query.IPFS stores the data blocks of all source data, and the storage of data blocks is not subject to any sequence, but each data block is specifically correlated to the corresponding hash address, and the mapping relations between hash addresses and detail information is stored in the Fabric blockchain.Nowadays, many problems of cloud storage resulted from improper server management and maintenance provided by decentralized cloud service providers or excessively centralized distribution of cloud service providers. If a file is stored in the cloud hard disks provided by the cloud service provider, and if the hard disks are put together in a centralized manner, even if the file is provided with the corresponding backup file, the hard disk in which the backup file is located may be stored in the hard disk in which the original file is located. As a result, the servers malfunction in case of power outage or other failures happens, and it cannot be accessed externally; the only way to the problem is to wait for recovery of the servers. But IPFS is not limited, as IPFS is a new type of Internet technology comparative to the HTTP protocol, solving the data storage and distribution problems, and it is designed to create permanent and decentralized storage and file-sharing methods through peer-to-peer network (PPN), with the concept of separating a file into many pieces scattered on different locations of the network, which can be acquired simultaneously from multiple servers upon downloading of the file. Even if certain servers are malfunctioning, it will not create adverse influence on the access of external users to the entire network, nor on the users’ data acquisition. In addition, even if certain node data is completely lost due to improper operation, there are many backups on the entire network. The advantages of IPFS are ideal to tackle the shortcomings of traditional centralized cloud storage, e.g., vulnerability to data leakage, vulnerability to hardware damage, and poor repair capacity.In order to achieve large-scale distributed storage, there are three problems that need to be handled: (1) How to increase storage capacity, that is, to attract more users to provide storage resources, (2) how to improve retrieval efficiency and achieve rapid service response, and (3) how to guarantee that data storage and circulation are safe. In response to that, the researchers introduced blockchain technology as the incentive layer for distributed storage and obtained a series of research results. The most representative solution is a distributed storage system based on IPFS.The storage party can prove its effective storage capacity through the proof of storage mechanism (Proof of Storage) to obtain tokens (the first problem) [19, 20]. Retrieval service parties can provide data retrieval services, and efficient retrieval can obtain more tokens (the second problem). The data security can be solved by encryption technology, and the blockchain can provide evidence of data access.


#### 3.1.2. Relationship between Entity Sequences

As shown in Figure3, the relationship between entities shows some key properties and functions of smart contract. The relationship between entities and smart contract is shown in Figure 3. Each participating entity in the supply chain participates by invoking the functions in the smart contract. Therefore, the metadata and relationships are of great importance to the realization of the smart contract [21]. The regulatory authority creates a master smart contract to be invoked by other entities. If certain changes happen to the relationship between the buyer and the seller, the corresponding contract will be executed. Once the parties have agreed on the details of the agreement, the transaction can proceed.Figure 3
Entity relationship chart.


#### 3.1.3. Algorithm

As mentioned above, the relevant supervision departments deploy the master smart contract, and each entity can invoke the trade through the interface. In the initialization state, each transaction entity needs to be registered; otherwise the transaction cannot be carried out. Later, the process of user registration, transaction, and product evaluation will be described in detail. Table2 shows the interpretation of the variables in the algorithm.Table 2
Contract function description.
FunctionDescriptionnode_register()Only the supervisory authority can call users whose registration has been successfully verifiednode_record()Only the supervisory authority can call it to record the object that this batch of goods belongs to at the timerelease_pro()This is used to release the information of the batch of goodsTrans_Record()This is used to record transactionsDispute_event()Arbitrators or third-party agencies handle transaction disputesSignature()This is used for evaluation signatureStorage()This is used to store recordsCredit()This is used to update reputation value


### 3.2. User Registration

Algorithm1: when users register their identities, the input parameters include IDuser, VIDuser, User_address, and Pkuser. The algorithm is used for user registration, and the necessary user information is stored in the blockchain. Unregistered users cannot participate in the transaction. After the user registration verification is passed, the regulatory agencies call the smart contract interface node_register() to store user information in the blockchain.Algorithm 1: User registration algorithm.
Input:IDuser, VIDuser, User_address, PKuserOutput: Registration result(1)
Users sendIDuser, VIDuser, User_address and PKuser to regulatory agencies(2)
Regulatory agencies verify users’ identity information(3)
if the verification is successful then(4)
Regulatory agencies call node_register (User_address, PKuser)//Only the regulatory agencies can call, register the user with successful verification, and send the relationship of User_address and PKuser into address_pk.(5)
Update address_pk(6)
return “successfully registration”(7)
else(8)
return “registration failed. Please submit the real information to register again.”(9)
end if


### 3.3. Goods Registration

Algorithm2: firstly, the goods owner registers the products so that the buyer can view the information of the goods he/she needs to buy and input the information of the goods to save, which plays a vital role in traceability. The goods owner enters IDpro, Pro_Lot, Ptyp, Pquan, VIDpro, IDown, and PKown.Algorithm 2: Goods registration algorithm.
Input:IDpro, Pro_Lot, Ptyp, Pquan, VIDpro, IDown, PKown,Output: Registration result(1)
Goods owner uploadIDpro, Pro_Lot, Ptyp, VIDpro, IDown onto the IPFS(2)
Goods owner sendsHpro, VIDpro, PKown to regulatory authorities(3)
Regulatory agencies verify the owner of the goods(4)
if the verification is successful then(5)
Regulatory agencies call node_record (IDpro, IDown, Pro_Lot, Time)//It can only be called by regulatory agencies to record the owner of the commodity batch at that time(6)
return “successful registration” then(7)
Goods owner invokes release_pro (IDpro, Pro_Lot, Ptyp, Pquan)//The goods are successfully registered by the owner, Later, the information of this batch of goods can be released for buyers to choose.(8)
else(9)
return “failed verification, please submit the information again”(10)
end if


#### 3.3.1. Commodity Transaction

Algorithm3 is jointly implemented by the buyer and the seller. Both parties negotiate Ppri, Pquan, and Pqual requirements of the goods. After reaching an agreement, the buyer pays for the goods Pay_pri. At the same time, the seller submits the deposit Fine, which is one half of the commodity transaction price λ, λ ∈ (0, 1). The value of λ is decided by both parties, i.e.,(6)Fine=λ⋅Pay_pri,λ∈0,1,(7)Pay_pri=Ppri×Pquan&Fine=λ·Pay_pri.When formula (7) is satisfied, the smart contract triggers the function Sell_agree(). After the buyer confirms the receipt of the goods and the loan, the smart contract triggers Pay_agree() to pay the loan and deposit to the seller. If the buyer does not confirm the loan and there is no dispute, the transaction is considered to be successful within seven days, and the payment and deposit are also paid to the seller. When the transaction is done successfully, the smart contract calls Trans_Record() to record address_buyer and address_seller, as well as the information of the traded goods. If the buyer has disputes on the goods and does not agree to pay or the buyer has disputes over the goods within seven days, the Dispute_event() will be triggered and should be handled by an arbitrator or a third-party organization. The place where the commodity is sold should be recorded for a single completed transaction, so that the commodity circulation record can be checked. In other words, both the buyer’s and the seller’s user address should be recorded in the transaction records, and these two addresses refer to the addresses registered in Algorithm 1.Algorithm 3: Commodity trading algorithm.
Input:IDbuyer, IDseller, address_buyer, address_seller, Ppri, Pquan, Pqual, FineOutput: Transaction result(1)
The seller applies smart contract function: negotiate (IDbuyer, IDseller, Ppri, Pquan, Pqual)//Both parties can negotiate the commodity price, quantity and quality through this function.(2)
ifPay_pri = Ppri × Pquan||Fine = λ·Pay_prithen(3)
Contract status becomes Sell_agree(4)
if Confirm receipt or time stamp > deadline then(5)
Apply smart contract function: Trans_Record (payment, address_buyer, address_seller)(6)
else(7)
Trigger the contract event: Dispute_event (IDbuyer, IDseller, Ppri, Pquan, Pqual, Fine)(8)
end if(9)
else(10)
Contract status becomes Sell_disagree(11)
return (“transaction failed”)(12)
end if


### 3.4. Consumer Evaluation

In Algorithm4, consumers can score the product and service quality of this transaction after an order completed and then upload such evaluation to IPFS.Algorithm 4: Consumer evaluation algorithm.
Input:IDseller, mR,ςSKbuy,mt, PKsell,ς, InfoOutput: Evaluation agency verification results(1)
The seller applies evaluation contract function: comment (mR, ςSKbuy,mt, PKsell)(2)
ifΦmt,PKsell,ςSKsell,mt=1then(3)
Apply signature function: signature (Info,ς,mR)(4)
If block verification passed then(5)
Trigger contract storage function: storage (Info, HInfo)(6)
Trigger contract credit update function: credit (IDseller, Valuetrust)(7)
else(8)
return (“verification failed”)(9)
end if(10)
else(11)
return (“No review permission”)(12)
end if


## 3.1. Schematic Design

The unique feature of the solution is that it adopts the blockchain as the foundation layer, allows transactions between mutually untrusted users through smart contract, and adopts the IPFS technology to resolve the data storage constraint of blockchain. Within a certain period after the closure of a transaction, the consumer may use the ring signature algorithm to carry out anonymous assessment on the retailer. Relevant regulatory authorities or product suppliers may determine the quality security problems of a certain batch of products in the first time through consumer feedback. The batch information of the product purchased by the consumer can be used to identify the specific product batch, and the smart contract can be used to trace the root cause.In this thesis, we propose the deployment of smart contract on Hyperledger, which can automatically send the preset data resources (including the triggering condition event) according to the contract information agreed in the smart contract when the triggering condition is met. Once the smart contract is deployed, it cannot be changed but can be upgraded to launch new functions or fix bugs [11]. The Fabric smart contract is independent of the underlying ledger, and it is not required to relocate the ledger data to the new smart contract when the smart contract is upgraded, which truly realizes the separation between logic and data. The smart contract of Fabric is referred to as chaincode, including system chaincode and user chaincode [12]. System chaincode is used to realize system-level functions and the processing logics of Fabric nodes, including system configuration, endorsement, and verification [13, 14]. User chaincode operates in an isolated chaincode container and is responsible for the user’s application function, providing status processing logics based on the distributed blockchain ledger. It is programed by application developers as a support to upper-level services. Smart contract receives transactions and triggers events in the form of function call, so that a participating entity can constantly monitor the events being sent in blockchain without too many expenses [15].Figure1 shows the traceability of agricultural products. The Hyperledger smart contract is adopted to record information, and all participants involved in the supply chain are added to the processes, which are used to trace the agricultural products from the place of origin to the end consumers in a digital manner. The supervisory and regulatory bodies or relevant government departments deploy the main smart contract which provides an interface to the entities in the supply chain for function call and transaction implementation. IPFS hash files are stored in blockchain, which can be processed within the specified time period if the product conforms to the buyer’s requirements. Supervisory and regulatory bodies almost deal with the entire supply chain. For instance, the agricultural bureau may carry out supervision, recording and management of farmer information, seed information, product information, etc., to ensure information authenticity. The quality supervision bureau must carry out supervision, management, and recording of processing plant information, retailer information, and product quality information and ensure security and quality of agricultural products. In order to improve the storage capacity, the information of all products and the data of all transactions and events are stored in IPFS, and the blockchain is only used to store the hash value of the data. IPFS is designed for distributed storage, which can be combined with Hyperledger to improve its throughput. The formula symbol description is shown in Table 1. Each transaction (TXtr) bears the product identifier (IDpro), product data hash (Hpro), identifier (IDown) of the product owner and its signature (Sigown), and public key (PKown)(1)TXtr=IDpro||Hpro||IDown||Sigown||Pkown,Hpro=Ptyp||Pquan||Ppri||Pori.Figure 1
Agricultural product supply chain traceability solution based on Bc-IPFS.Table 1
Symbol meaning.
SymbolMeaningIDIdentifierHHashSigUser signaturePKPublic keySKPrivate keymRTransaction order||Connection symbolςRing signatureInfoAssessment informationValuetrustTrust valueTotaltransTotal number of transactionsTXtr is stored in IPFS and hash is stored in blockchain. The product hash (Hpro) includes the product type (Ptyp), quantity (Pquan), price (Ppri), and place of origin (Pori). When a product is confirmed to have been delivered from the seller to the buyer in a transaction, Txtr = [IDpro||Hpro||IDbuy||Sigbuy||PKbuy||Sigsell||Pksell], where IDbuy, Sigbuy, and PKbuy represent the identifier, signature, and public key of the owner, respectively;(2)TXtr=IDpro||Hpro||IDbuy||Sigbuy||Pkbuy||Sigsell||Pksell.IDbuy, Sigsell , and PKsell represent the identifier, signature, and public key of the seller, that is, the signature (Sigown) and public key (PKown) of the product owner in (1). The identity is required to be transformed in the process of product transaction, the owner of a transaction will be the seller in a subsequent transaction, and the buyer will become the owner of the product when the transaction is complete. After the consumer buys the product from the retailer, the seller creates the transaction order mR(3)mR=Φmt,ςSKsell,mt.Only after obtaining the completed ordermR, can the consumer release a comment on the product. Firstly, the consumer verifies the transaction signature ςSKbuy,mt of the retailer(4)Φmt,PKsell,ςSKsell,mt=1.Then, he/she verifies the seller’s signature based on the seller’s public key. Secondly, the consumer creates the ring signatureς based on the assessment information Info=IDpro||Hpro||Psco||Ptxt and sends the Info,ς,mR to the blockchain. The blockchain verifies mR and ς, and, upon successful verification, Info will be stored in IPFS, and HInfo will be stored in the blockchain network. In addition, the trust value(5)Valuetrust=∑α⋅scoreser+β⋅scorequalTotaltrans,Totaltrans≥n, can be calculated through consumers’ evaluation of goods (scoreser), including service score and product quality score for retailers (scorequal), where the coefficient is α+β=1∨α,β∈0,1 and n refers to the number of transactions; even if individual consumers conduct malicious evaluation, the behavior will still have slight impact on the overall evaluation score, effectively reducing the negative effect of malicious evaluation on retailers [16, 17]. The total number of transactions must have at least n successful orders before the trust value is recognized, which can effectively protect new businesses from malicious comments at the initial stage. At the same time, only the first score of each natural month is valid for each user, thus avoiding malicious comments [18].


### 3.1.1. Data Storage/Query

Any data created from a transaction between both parties will be stored. As shown in Figure2, first, the data will be sent by the http-post method, and when the predefined block size is achieved, the data will be partitioned, packed, and stored in IPFS, and the address of the IPFS storage block will be acquired. Then, the address will be stored in the Fabric blockchain, and the Fabric chaincode will be called to store the information in the peer node ledger for preservation. Upon data query, the http-get method will be adopted for data request, Fabric chain will be initiated to check whether the chaincode includes the IPFS address, and the transaction data will be retrieved from IPFS according to the hash address of the corresponding data block file on IPFS.Figure 2
Functional design of data storage and query.IPFS stores the data blocks of all source data, and the storage of data blocks is not subject to any sequence, but each data block is specifically correlated to the corresponding hash address, and the mapping relations between hash addresses and detail information is stored in the Fabric blockchain.Nowadays, many problems of cloud storage resulted from improper server management and maintenance provided by decentralized cloud service providers or excessively centralized distribution of cloud service providers. If a file is stored in the cloud hard disks provided by the cloud service provider, and if the hard disks are put together in a centralized manner, even if the file is provided with the corresponding backup file, the hard disk in which the backup file is located may be stored in the hard disk in which the original file is located. As a result, the servers malfunction in case of power outage or other failures happens, and it cannot be accessed externally; the only way to the problem is to wait for recovery of the servers. But IPFS is not limited, as IPFS is a new type of Internet technology comparative to the HTTP protocol, solving the data storage and distribution problems, and it is designed to create permanent and decentralized storage and file-sharing methods through peer-to-peer network (PPN), with the concept of separating a file into many pieces scattered on different locations of the network, which can be acquired simultaneously from multiple servers upon downloading of the file. Even if certain servers are malfunctioning, it will not create adverse influence on the access of external users to the entire network, nor on the users’ data acquisition. In addition, even if certain node data is completely lost due to improper operation, there are many backups on the entire network. The advantages of IPFS are ideal to tackle the shortcomings of traditional centralized cloud storage, e.g., vulnerability to data leakage, vulnerability to hardware damage, and poor repair capacity.In order to achieve large-scale distributed storage, there are three problems that need to be handled: (1) How to increase storage capacity, that is, to attract more users to provide storage resources, (2) how to improve retrieval efficiency and achieve rapid service response, and (3) how to guarantee that data storage and circulation are safe. In response to that, the researchers introduced blockchain technology as the incentive layer for distributed storage and obtained a series of research results. The most representative solution is a distributed storage system based on IPFS.The storage party can prove its effective storage capacity through the proof of storage mechanism (Proof of Storage) to obtain tokens (the first problem) [19, 20]. Retrieval service parties can provide data retrieval services, and efficient retrieval can obtain more tokens (the second problem). The data security can be solved by encryption technology, and the blockchain can provide evidence of data access.


### 3.1.2. Relationship between Entity Sequences

As shown in Figure3, the relationship between entities shows some key properties and functions of smart contract. The relationship between entities and smart contract is shown in Figure 3. Each participating entity in the supply chain participates by invoking the functions in the smart contract. Therefore, the metadata and relationships are of great importance to the realization of the smart contract [21]. The regulatory authority creates a master smart contract to be invoked by other entities. If certain changes happen to the relationship between the buyer and the seller, the corresponding contract will be executed. Once the parties have agreed on the details of the agreement, the transaction can proceed.Figure 3
Entity relationship chart.


### 3.1.3. Algorithm

As mentioned above, the relevant supervision departments deploy the master smart contract, and each entity can invoke the trade through the interface. In the initialization state, each transaction entity needs to be registered; otherwise the transaction cannot be carried out. Later, the process of user registration, transaction, and product evaluation will be described in detail. Table2 shows the interpretation of the variables in the algorithm.Table 2
Contract function description.
FunctionDescriptionnode_register()Only the supervisory authority can call users whose registration has been successfully verifiednode_record()Only the supervisory authority can call it to record the object that this batch of goods belongs to at the timerelease_pro()This is used to release the information of the batch of goodsTrans_Record()This is used to record transactionsDispute_event()Arbitrators or third-party agencies handle transaction disputesSignature()This is used for evaluation signatureStorage()This is used to store recordsCredit()This is used to update reputation value


## 3.1.1. Data Storage/Query

Any data created from a transaction between both parties will be stored. As shown in Figure2, first, the data will be sent by the http-post method, and when the predefined block size is achieved, the data will be partitioned, packed, and stored in IPFS, and the address of the IPFS storage block will be acquired. Then, the address will be stored in the Fabric blockchain, and the Fabric chaincode will be called to store the information in the peer node ledger for preservation. Upon data query, the http-get method will be adopted for data request, Fabric chain will be initiated to check whether the chaincode includes the IPFS address, and the transaction data will be retrieved from IPFS according to the hash address of the corresponding data block file on IPFS.Figure 2
Functional design of data storage and query.IPFS stores the data blocks of all source data, and the storage of data blocks is not subject to any sequence, but each data block is specifically correlated to the corresponding hash address, and the mapping relations between hash addresses and detail information is stored in the Fabric blockchain.Nowadays, many problems of cloud storage resulted from improper server management and maintenance provided by decentralized cloud service providers or excessively centralized distribution of cloud service providers. If a file is stored in the cloud hard disks provided by the cloud service provider, and if the hard disks are put together in a centralized manner, even if the file is provided with the corresponding backup file, the hard disk in which the backup file is located may be stored in the hard disk in which the original file is located. As a result, the servers malfunction in case of power outage or other failures happens, and it cannot be accessed externally; the only way to the problem is to wait for recovery of the servers. But IPFS is not limited, as IPFS is a new type of Internet technology comparative to the HTTP protocol, solving the data storage and distribution problems, and it is designed to create permanent and decentralized storage and file-sharing methods through peer-to-peer network (PPN), with the concept of separating a file into many pieces scattered on different locations of the network, which can be acquired simultaneously from multiple servers upon downloading of the file. Even if certain servers are malfunctioning, it will not create adverse influence on the access of external users to the entire network, nor on the users’ data acquisition. In addition, even if certain node data is completely lost due to improper operation, there are many backups on the entire network. The advantages of IPFS are ideal to tackle the shortcomings of traditional centralized cloud storage, e.g., vulnerability to data leakage, vulnerability to hardware damage, and poor repair capacity.In order to achieve large-scale distributed storage, there are three problems that need to be handled: (1) How to increase storage capacity, that is, to attract more users to provide storage resources, (2) how to improve retrieval efficiency and achieve rapid service response, and (3) how to guarantee that data storage and circulation are safe. In response to that, the researchers introduced blockchain technology as the incentive layer for distributed storage and obtained a series of research results. The most representative solution is a distributed storage system based on IPFS.The storage party can prove its effective storage capacity through the proof of storage mechanism (Proof of Storage) to obtain tokens (the first problem) [19, 20]. Retrieval service parties can provide data retrieval services, and efficient retrieval can obtain more tokens (the second problem). The data security can be solved by encryption technology, and the blockchain can provide evidence of data access.


## 3.1.2. Relationship between Entity Sequences

As shown in Figure3, the relationship between entities shows some key properties and functions of smart contract. The relationship between entities and smart contract is shown in Figure 3. Each participating entity in the supply chain participates by invoking the functions in the smart contract. Therefore, the metadata and relationships are of great importance to the realization of the smart contract [21]. The regulatory authority creates a master smart contract to be invoked by other entities. If certain changes happen to the relationship between the buyer and the seller, the corresponding contract will be executed. Once the parties have agreed on the details of the agreement, the transaction can proceed.Figure 3
Entity relationship chart.


## 3.1.3. Algorithm

As mentioned above, the relevant supervision departments deploy the master smart contract, and each entity can invoke the trade through the interface. In the initialization state, each transaction entity needs to be registered; otherwise the transaction cannot be carried out. Later, the process of user registration, transaction, and product evaluation will be described in detail. Table2 shows the interpretation of the variables in the algorithm.Table 2
Contract function description.
FunctionDescriptionnode_register()Only the supervisory authority can call users whose registration has been successfully verifiednode_record()Only the supervisory authority can call it to record the object that this batch of goods belongs to at the timerelease_pro()This is used to release the information of the batch of goodsTrans_Record()This is used to record transactionsDispute_event()Arbitrators or third-party agencies handle transaction disputesSignature()This is used for evaluation signatureStorage()This is used to store recordsCredit()This is used to update reputation value


## 3.2. User Registration

Algorithm1: when users register their identities, the input parameters include IDuser, VIDuser, User_address, and Pkuser. The algorithm is used for user registration, and the necessary user information is stored in the blockchain. Unregistered users cannot participate in the transaction. After the user registration verification is passed, the regulatory agencies call the smart contract interface node_register() to store user information in the blockchain.Algorithm 1: User registration algorithm.
Input:IDuser, VIDuser, User_address, PKuserOutput: Registration result(1)
Users sendIDuser, VIDuser, User_address and PKuser to regulatory agencies(2)
Regulatory agencies verify users’ identity information(3)
if the verification is successful then(4)
Regulatory agencies call node_register (User_address, PKuser)//Only the regulatory agencies can call, register the user with successful verification, and send the relationship of User_address and PKuser into address_pk.(5)
Update address_pk(6)
return “successfully registration”(7)
else(8)
return “registration failed. Please submit the real information to register again.”(9)
end if


## 3.3. Goods Registration

Algorithm2: firstly, the goods owner registers the products so that the buyer can view the information of the goods he/she needs to buy and input the information of the goods to save, which plays a vital role in traceability. The goods owner enters IDpro, Pro_Lot, Ptyp, Pquan, VIDpro, IDown, and PKown.Algorithm 2: Goods registration algorithm.
Input:IDpro, Pro_Lot, Ptyp, Pquan, VIDpro, IDown, PKown,Output: Registration result(1)
Goods owner uploadIDpro, Pro_Lot, Ptyp, VIDpro, IDown onto the IPFS(2)
Goods owner sendsHpro, VIDpro, PKown to regulatory authorities(3)
Regulatory agencies verify the owner of the goods(4)
if the verification is successful then(5)
Regulatory agencies call node_record (IDpro, IDown, Pro_Lot, Time)//It can only be called by regulatory agencies to record the owner of the commodity batch at that time(6)
return “successful registration” then(7)
Goods owner invokes release_pro (IDpro, Pro_Lot, Ptyp, Pquan)//The goods are successfully registered by the owner, Later, the information of this batch of goods can be released for buyers to choose.(8)
else(9)
return “failed verification, please submit the information again”(10)
end if


### 3.3.1. Commodity Transaction

Algorithm3 is jointly implemented by the buyer and the seller. Both parties negotiate Ppri, Pquan, and Pqual requirements of the goods. After reaching an agreement, the buyer pays for the goods Pay_pri. At the same time, the seller submits the deposit Fine, which is one half of the commodity transaction price λ, λ ∈ (0, 1). The value of λ is decided by both parties, i.e.,(6)Fine=λ⋅Pay_pri,λ∈0,1,(7)Pay_pri=Ppri×Pquan&Fine=λ·Pay_pri.When formula (7) is satisfied, the smart contract triggers the function Sell_agree(). After the buyer confirms the receipt of the goods and the loan, the smart contract triggers Pay_agree() to pay the loan and deposit to the seller. If the buyer does not confirm the loan and there is no dispute, the transaction is considered to be successful within seven days, and the payment and deposit are also paid to the seller. When the transaction is done successfully, the smart contract calls Trans_Record() to record address_buyer and address_seller, as well as the information of the traded goods. If the buyer has disputes on the goods and does not agree to pay or the buyer has disputes over the goods within seven days, the Dispute_event() will be triggered and should be handled by an arbitrator or a third-party organization. The place where the commodity is sold should be recorded for a single completed transaction, so that the commodity circulation record can be checked. In other words, both the buyer’s and the seller’s user address should be recorded in the transaction records, and these two addresses refer to the addresses registered in Algorithm 1.Algorithm 3: Commodity trading algorithm.
Input:IDbuyer, IDseller, address_buyer, address_seller, Ppri, Pquan, Pqual, FineOutput: Transaction result(1)
The seller applies smart contract function: negotiate (IDbuyer, IDseller, Ppri, Pquan, Pqual)//Both parties can negotiate the commodity price, quantity and quality through this function.(2)
ifPay_pri = Ppri × Pquan||Fine = λ·Pay_prithen(3)
Contract status becomes Sell_agree(4)
if Confirm receipt or time stamp > deadline then(5)
Apply smart contract function: Trans_Record (payment, address_buyer, address_seller)(6)
else(7)
Trigger the contract event: Dispute_event (IDbuyer, IDseller, Ppri, Pquan, Pqual, Fine)(8)
end if(9)
else(10)
Contract status becomes Sell_disagree(11)
return (“transaction failed”)(12)
end if


## 3.3.1. Commodity Transaction

Algorithm3 is jointly implemented by the buyer and the seller. Both parties negotiate Ppri, Pquan, and Pqual requirements of the goods. After reaching an agreement, the buyer pays for the goods Pay_pri. At the same time, the seller submits the deposit Fine, which is one half of the commodity transaction price λ, λ ∈ (0, 1). The value of λ is decided by both parties, i.e.,(6)Fine=λ⋅Pay_pri,λ∈0,1,(7)Pay_pri=Ppri×Pquan&Fine=λ·Pay_pri.When formula (7) is satisfied, the smart contract triggers the function Sell_agree(). After the buyer confirms the receipt of the goods and the loan, the smart contract triggers Pay_agree() to pay the loan and deposit to the seller. If the buyer does not confirm the loan and there is no dispute, the transaction is considered to be successful within seven days, and the payment and deposit are also paid to the seller. When the transaction is done successfully, the smart contract calls Trans_Record() to record address_buyer and address_seller, as well as the information of the traded goods. If the buyer has disputes on the goods and does not agree to pay or the buyer has disputes over the goods within seven days, the Dispute_event() will be triggered and should be handled by an arbitrator or a third-party organization. The place where the commodity is sold should be recorded for a single completed transaction, so that the commodity circulation record can be checked. In other words, both the buyer’s and the seller’s user address should be recorded in the transaction records, and these two addresses refer to the addresses registered in Algorithm 1.Algorithm 3: Commodity trading algorithm.
Input:IDbuyer, IDseller, address_buyer, address_seller, Ppri, Pquan, Pqual, FineOutput: Transaction result(1)
The seller applies smart contract function: negotiate (IDbuyer, IDseller, Ppri, Pquan, Pqual)//Both parties can negotiate the commodity price, quantity and quality through this function.(2)
ifPay_pri = Ppri × Pquan||Fine = λ·Pay_prithen(3)
Contract status becomes Sell_agree(4)
if Confirm receipt or time stamp > deadline then(5)
Apply smart contract function: Trans_Record (payment, address_buyer, address_seller)(6)
else(7)
Trigger the contract event: Dispute_event (IDbuyer, IDseller, Ppri, Pquan, Pqual, Fine)(8)
end if(9)
else(10)
Contract status becomes Sell_disagree(11)
return (“transaction failed”)(12)
end if


## 3.4. Consumer Evaluation

In Algorithm4, consumers can score the product and service quality of this transaction after an order completed and then upload such evaluation to IPFS.Algorithm 4: Consumer evaluation algorithm.
Input:IDseller, mR,ςSKbuy,mt, PKsell,ς, InfoOutput: Evaluation agency verification results(1)
The seller applies evaluation contract function: comment (mR, ςSKbuy,mt, PKsell)(2)
ifΦmt,PKsell,ςSKsell,mt=1then(3)
Apply signature function: signature (Info,ς,mR)(4)
If block verification passed then(5)
Trigger contract storage function: storage (Info, HInfo)(6)
Trigger contract credit update function: credit (IDseller, Valuetrust)(7)
else(8)
return (“verification failed”)(9)
end if(10)
else(11)
return (“No review permission”)(12)
end if


## 4. Theory and Experiment Analysis

In this section, we analyze the traceability, security, and performance of the plan and make qualitative analysis by comparing this thesis with other papers at last.


### 4.1. Traceability Analysis

In this thesis, the solution of grain traceability of information is stored in IPFS files based on Hyperledger through chaincode (smart contract), in which transaction data is uploaded to IPFS to effectively solve the potential dangers such as high cost, waste of broadband, short text storage time, dependence on backbone network, DDOS, XSS, and CSRF attack[22–25]. Meanwhile, combined with blockchain technology, it makes hash stored in blockchain to solve the limited data storage in blockchain efficiently and keep data stored safe and not tampered [26–28]. The information of each transaction involves the previous owner’s information before and after the transaction. The unique identifier and batch number of the grain are added to each subsequent transaction to form a complete traceability chain. When consumers give negative evaluation to the quality and safety of commodity, the regulatory authorities and retailers can trace the source quickly according to the relevant product batches in the evaluation, determine the production batches of the products, and locate the product batches for inspection in time. Consumers can also screen and select suitable purchase objects based on the retailer’s reputation value and product evaluation [29].As shown in Figure4, the access query records for the uploaded file are displayed. Each record contains the hash value, owner name, visitor, and time stamp of the accessed file.Figure 4
On-chain metadata for accessing files.


### 4.2. Security Analysis

Unforgeability: distributed storage of data is allowed in IPFS, and the data will not be tampered and forged. The data stored in IPFS network cannot be altered without changing the data identifier. In IPFS, the identifier is an encrypted data hash [30]. It means that if the identifier of data is stored in the underlying distributed general ledger, noncritical data can be stored in IPFS. This can cut down consumption of operation in distributed ledger. Compared with centralized storage, if a hacker intercepts the request from hash and tries to send a malicious phishing site, the user can, with the help of data received through running hash function, compare the hash value of the data received with the one requested and reject the received data if not matched.Consumer privacy: consumers make an evaluation through ring signature after obtainingmR. The ring signature is anonymous, so attackers are not sure which ring member generates the signature. The probability is lower than 1/n even if the private key of ring member is acquired.Transparency: both the consumer evaluation and the credit value of retailers are open to the public. Other consumers can screen these contents during commodity purchase. Meanwhile, the credit value can only be shown by setting a certain amount of turnover, effectively lowering the negative effect due to malicious evaluation from malicious consumers.


### 4.3. Experimental Results and Analysis

The test is done under the circumstance of Ubuntu 20.04 LTS on a computer equipped with Intel(R) Core(TM) i7-10750H CPU @ 2.60 GHz, running memory of 64 G, 1T mechanical hard disk, and 500 GB solid state hard disk. Ubuntu is built in mechanical hard disk. Generate a local IPFS node and obtain its public ID, create an IPFS network, and embed it in the Fabric blockchain, Hyperledger Caliper, an open source blockchain performance evaluation tool, is used to test transaction throughput and delay, and the test results are shown in Figures5 and 6.Figure 5
Transaction throughput.Figure 6
Transaction delay.As shown in Figure5, the query transaction and the R/W transaction show a bottleneck at the throughput of 25 tps and 22 tps, respectively. In case of low transaction rate, the submitted transaction must wait. Furthermore, transactions are continuously sent through the client, and it will show low delay of subsequent transactions received in each block timeout period, as shown in Figure 6. When the transaction rate is 10 tps, the query delay drops to about 0.75 tps, and if the transaction rate exceeds the maximum throughput, the accumulated transactions will show higher delay. Therefore, the delay continues to increase after the transaction rate exceeds 20 tps. The performance is related to network delay, consensus delay, chaincode execution time, block verification delay, and other factors, but the system’s throughput always has linear relation to the number of channels [31].Since adding blockchain to IPFS will result in additional consumption of computing resources and time, thus this solution measures the performance variations of file reading when blockchain is adopted and when blockchain is not adopted. Thus, five files with the sizes of 0.5 T to 2.5 T are selected and uploaded to Ubuntu 20.04 LTS, data reading is conducted with the computers in the same network (Windows 10，Intel(R) Core(TM) i7-4720HQ CPU @ 2.60 GHz, 12 GB RAM, and 500 GB Hard Disk), and the test results are shown in Figure7. In the circumstance where blockchain is adopted, the file reading is slightly lower than that of ordinary IPFS, as a blockchain transaction relies on the completion of IPFS processes, and the transaction time may also be adversely influenced by the local network speed and computer operation capacity. However, regardless of the sizes of the files added to IPFS, the sizes of the metadata stored on the blockchain do not show any signs of evident changes, as shown in Figure 8.Figure 7
Compare the file read performance difference between IPFS and Bc-IPFS.Figure 8
Comparing the size of files on Bc-IPFS and the size of file metadata on blockchain ledger.


### 4.4. Scheme Comparison

First of all, Hyperledger is a private blockchain technology, distinctive from the blockchain technology such as ETH and Bitcoin, and the members of a blockchain network are known to each other, and the membership is available to the public, allowing new members to join in and carry out transactions on the network [32]. Hyperledger is a type of blockchain managed by multiple organizations or institutions, and its data can only be read, written, and maintained by those organizations or institutions. It effectively tackles the problem of “information silo” between different entities, which is ideal to the security traceability systems of agricultural products. The specific reasons of why Hyperledger Fabric is more adaptable to the solution proposed in this thesis, compared with ETH, are as follows:(1)
Expandability. One of the main characteristics distinguishing Hyperledger Fabric from other blockchain technologies such as ETH is its modularity, which provides an architectural structure of modularity and expandability applicable in various environments, making it more adaptable to the functional expansion of IPFS [33].(2)
Consensus Mechanism. The current ETH adopts the Proof of Work (POW) consensus mechanism, which is inefficient in accounting and vulnerable to 51% hash rate attack, and it consumes a great deal of computer resources. The Hyperledger adopts the Byzantine Fault Tolerance (PBFT) consensus mechanism, which provides an accounting efficiency at the sec level and low power consumption; thus it is ideal for the development of the traceability industry [34].(3)
Confidentiality. Since ETH is a public network irrelevant to the concept of authority and is completely transparent, thus all transactions recorded on the blockchain network can be available to and accessible by each counterparty, but Hyperledger is a blockchain platform with access authority and high levels of security; thus all transactions are only available to the ones with access authority.(4)
Interactivity. Hyperledger Fabric provides SDKs for interaction, so it can interact with IPFS and can effectively search the blockchain and provide data for review through the functions provided by SDKs.Then, we compare the traceability plan designed here with other plans, and the results are shown in Table3 [7]. The data is still stored centrally, although traceability is based on blockchain. In contrast, this plan has higher decentralization. In addition, in this plan, a supervision organization is set up to supervise the members of the supply chain and products, ensure the integrity and accuracy of information, and strengthen the supervision of the organization [10]. Obviously, relevant entities in the supply chain are not supervised efficiently. At the same time, the consumer evaluation function designed in this plan plays a strong role in retailers’ self-monitoring, and, through retailers’ credit value function, consumers are able to quickly screen the purchase objects so that it can effectively reduce the negative effects due to malicious evaluation behavior. K. Salah [35] solves the problem studied by Ethereum smart contract. This method needs to cost the Gas fee. Once the Gas is used up, the contract will not be executed and the used fee will not be refunded. However, Hyperledger is not involved in mining process, which can save resources and time, and has modularity and expansibility.Table 3
Plan comparison.
Characteristic[5][7][10][35]This workTraceabilityYesYesYesYesYesSupervisoryNoYesNoYesYesScalabilityNoYesYesYesYesEvaluationNoNoNoNoYesGas—NoYesYesNoOn-chain dataHighLowLowHighLow


## 4.1. Traceability Analysis

In this thesis, the solution of grain traceability of information is stored in IPFS files based on Hyperledger through chaincode (smart contract), in which transaction data is uploaded to IPFS to effectively solve the potential dangers such as high cost, waste of broadband, short text storage time, dependence on backbone network, DDOS, XSS, and CSRF attack[22–25]. Meanwhile, combined with blockchain technology, it makes hash stored in blockchain to solve the limited data storage in blockchain efficiently and keep data stored safe and not tampered [26–28]. The information of each transaction involves the previous owner’s information before and after the transaction. The unique identifier and batch number of the grain are added to each subsequent transaction to form a complete traceability chain. When consumers give negative evaluation to the quality and safety of commodity, the regulatory authorities and retailers can trace the source quickly according to the relevant product batches in the evaluation, determine the production batches of the products, and locate the product batches for inspection in time. Consumers can also screen and select suitable purchase objects based on the retailer’s reputation value and product evaluation [29].As shown in Figure4, the access query records for the uploaded file are displayed. Each record contains the hash value, owner name, visitor, and time stamp of the accessed file.Figure 4
On-chain metadata for accessing files.


## 4.2. Security Analysis

Unforgeability: distributed storage of data is allowed in IPFS, and the data will not be tampered and forged. The data stored in IPFS network cannot be altered without changing the data identifier. In IPFS, the identifier is an encrypted data hash [30]. It means that if the identifier of data is stored in the underlying distributed general ledger, noncritical data can be stored in IPFS. This can cut down consumption of operation in distributed ledger. Compared with centralized storage, if a hacker intercepts the request from hash and tries to send a malicious phishing site, the user can, with the help of data received through running hash function, compare the hash value of the data received with the one requested and reject the received data if not matched.Consumer privacy: consumers make an evaluation through ring signature after obtainingmR. The ring signature is anonymous, so attackers are not sure which ring member generates the signature. The probability is lower than 1/n even if the private key of ring member is acquired.Transparency: both the consumer evaluation and the credit value of retailers are open to the public. Other consumers can screen these contents during commodity purchase. Meanwhile, the credit value can only be shown by setting a certain amount of turnover, effectively lowering the negative effect due to malicious evaluation from malicious consumers.


## 4.3. Experimental Results and Analysis

The test is done under the circumstance of Ubuntu 20.04 LTS on a computer equipped with Intel(R) Core(TM) i7-10750H CPU @ 2.60 GHz, running memory of 64 G, 1T mechanical hard disk, and 500 GB solid state hard disk. Ubuntu is built in mechanical hard disk. Generate a local IPFS node and obtain its public ID, create an IPFS network, and embed it in the Fabric blockchain, Hyperledger Caliper, an open source blockchain performance evaluation tool, is used to test transaction throughput and delay, and the test results are shown in Figures5 and 6.Figure 5
Transaction throughput.Figure 6
Transaction delay.As shown in Figure5, the query transaction and the R/W transaction show a bottleneck at the throughput of 25 tps and 22 tps, respectively. In case of low transaction rate, the submitted transaction must wait. Furthermore, transactions are continuously sent through the client, and it will show low delay of subsequent transactions received in each block timeout period, as shown in Figure 6. When the transaction rate is 10 tps, the query delay drops to about 0.75 tps, and if the transaction rate exceeds the maximum throughput, the accumulated transactions will show higher delay. Therefore, the delay continues to increase after the transaction rate exceeds 20 tps. The performance is related to network delay, consensus delay, chaincode execution time, block verification delay, and other factors, but the system’s throughput always has linear relation to the number of channels [31].Since adding blockchain to IPFS will result in additional consumption of computing resources and time, thus this solution measures the performance variations of file reading when blockchain is adopted and when blockchain is not adopted. Thus, five files with the sizes of 0.5 T to 2.5 T are selected and uploaded to Ubuntu 20.04 LTS, data reading is conducted with the computers in the same network (Windows 10，Intel(R) Core(TM) i7-4720HQ CPU @ 2.60 GHz, 12 GB RAM, and 500 GB Hard Disk), and the test results are shown in Figure7. In the circumstance where blockchain is adopted, the file reading is slightly lower than that of ordinary IPFS, as a blockchain transaction relies on the completion of IPFS processes, and the transaction time may also be adversely influenced by the local network speed and computer operation capacity. However, regardless of the sizes of the files added to IPFS, the sizes of the metadata stored on the blockchain do not show any signs of evident changes, as shown in Figure 8.Figure 7
Compare the file read performance difference between IPFS and Bc-IPFS.Figure 8
Comparing the size of files on Bc-IPFS and the size of file metadata on blockchain ledger.


## 4.4. Scheme Comparison

First of all, Hyperledger is a private blockchain technology, distinctive from the blockchain technology such as ETH and Bitcoin, and the members of a blockchain network are known to each other, and the membership is available to the public, allowing new members to join in and carry out transactions on the network [32]. Hyperledger is a type of blockchain managed by multiple organizations or institutions, and its data can only be read, written, and maintained by those organizations or institutions. It effectively tackles the problem of “information silo” between different entities, which is ideal to the security traceability systems of agricultural products. The specific reasons of why Hyperledger Fabric is more adaptable to the solution proposed in this thesis, compared with ETH, are as follows:(1)
Expandability. One of the main characteristics distinguishing Hyperledger Fabric from other blockchain technologies such as ETH is its modularity, which provides an architectural structure of modularity and expandability applicable in various environments, making it more adaptable to the functional expansion of IPFS [33].(2)
Consensus Mechanism. The current ETH adopts the Proof of Work (POW) consensus mechanism, which is inefficient in accounting and vulnerable to 51% hash rate attack, and it consumes a great deal of computer resources. The Hyperledger adopts the Byzantine Fault Tolerance (PBFT) consensus mechanism, which provides an accounting efficiency at the sec level and low power consumption; thus it is ideal for the development of the traceability industry [34].(3)
Confidentiality. Since ETH is a public network irrelevant to the concept of authority and is completely transparent, thus all transactions recorded on the blockchain network can be available to and accessible by each counterparty, but Hyperledger is a blockchain platform with access authority and high levels of security; thus all transactions are only available to the ones with access authority.(4)
Interactivity. Hyperledger Fabric provides SDKs for interaction, so it can interact with IPFS and can effectively search the blockchain and provide data for review through the functions provided by SDKs.Then, we compare the traceability plan designed here with other plans, and the results are shown in Table3 [7]. The data is still stored centrally, although traceability is based on blockchain. In contrast, this plan has higher decentralization. In addition, in this plan, a supervision organization is set up to supervise the members of the supply chain and products, ensure the integrity and accuracy of information, and strengthen the supervision of the organization [10]. Obviously, relevant entities in the supply chain are not supervised efficiently. At the same time, the consumer evaluation function designed in this plan plays a strong role in retailers’ self-monitoring, and, through retailers’ credit value function, consumers are able to quickly screen the purchase objects so that it can effectively reduce the negative effects due to malicious evaluation behavior. K. Salah [35] solves the problem studied by Ethereum smart contract. This method needs to cost the Gas fee. Once the Gas is used up, the contract will not be executed and the used fee will not be refunded. However, Hyperledger is not involved in mining process, which can save resources and time, and has modularity and expansibility.Table 3
Plan comparison.
Characteristic[5][7][10][35]This workTraceabilityYesYesYesYesYesSupervisoryNoYesNoYesYesScalabilityNoYesYesYesYesEvaluationNoNoNoNoYesGas—NoYesYesNoOn-chain dataHighLowLowHighLow


## 5. Conclusion

The Bc-IPFS-based solution proposed in this thesis tackles the problem of “information silo” between entities by the alliance blockchain Hyperledger and realizes the automation of traceability through the smart contract deployed on Hyperledger Fabric, so as to improve efficiency. The IPFS technology is adopted to ensure data security and overcome the data storage constraint of blockchain for overwhelming data, the ring signature algorithm is adopted to privatize consumer information and encourage consumers to timely feedback product problems, and performance evaluation is conducted by virtue of throughput capacity and delay, in addition to security analysis of the solution. The solution is developed with comprehensive considerations to traceability, transaction, and retailer reputation, and the established reputation function can be used to maintain the reputation of the entities in the supply chains of agricultural products and the quality rating of the products. This thesis describes the plan design, overall structure, entity relationship diagram, interaction, and details related to implementation algorithm and shows how to apply the plan to track grain supply chain. The plan designed can provide and meet reliable decentralized traceability demands for any crop in agricultural supply chain.Up to now, the system based on blockchain is still challenged by its practical implementation. In the future, we plan to integrate protection of enterprise and consumer privacy in agricultural food trade. Similarly, the retailer’s credit value comes from consumers’ evaluation, which may be biased or falsified. As a result, we plan to design a supervision mechanism for comment information to help improve such accuracy.



---

*Source: 3298514-2021-11-12.xml*