A Peer-to-Peer File Storage System Using Blockchain and Interplanetary File System

: People’s lives have been profoundly impacted by the headway of innovation which has worked on their lives from each viewpoint. Clearly, innovation assumes a significant part in each circle of life and information stockpiling and sharing is a significant part of it. Current information sharing and storage devices depend on trusted third parties (TTP) and because of the contribution of third parties, such frameworks need straightforwardness, security, trust and strength. To solve these issues, this paper proposes a blockchain-based secure information sharing application by consolidating the highlights of IPFS and Ethereum. In this proposed scheme ethereum blockchain, decentralized storage, encryption and IPFS are combined to build an application that maximizes the technological resources and provide with an effective storage website ,Ethereum blockchain, decentralized capacity, encryption, and InterPlanetary File System are consolidated to assemble an application that boosts the innovative assets and gives a viable storage site. To carry out the proposed situation, smart contracts are written in solidity and sent on the nearby Ethereum test network. The proposed plot accomplishes security, transparency, legitimacy of owner, access control and nature of information.


INTRODUCTION
Blockchain Technology (BT) has been a massive hit among the tech enthusiasts over the last few years.[9] Blockchain is known as a global record to provide immutability and store the transactions in a chain of blocks and is being researched uninterruptedly.Ethereum [1] is a blockchain platform with its own programming language, called Solidity and is a decentralized public ledger for verifying and recording transactions.Ethereum consists of smart contracts (SCs) [10] that are programmable in different programming languages such as solidity.
Trust and security are the most prominent features of blockchain, which is ensured by no involvement of third parties.Nakamoto introduced a peer to peer currency that is known as bitcoin in 2008 [1].This serves as a way to facilitate peer to peer transactions.Later, Nakamoto published a paper which laid the foundation of peer to peer transactions [4] using bitcoin.In today's world, blockchain is being utilized in different fields, like the internet of things (IoT), cloud, data handling, health care, and many more.The major underscored obstacles in data trading and storage is regarding misinterpretation and misuse of data and it is due to data sharing approaches that are still lagging behind in providing trust and security, that is being established among the tech community.To solve this problem, different strategies are being proposed, for example, securing the profiles of every individual and specific access to the data instead of making all the data open access.Even these strategies are not full proof in providing stability to data, traceability regarding data usage and trust in the process of data sharing.That is why there developed a need and urgency to use blockchain in the backend of storage websites.
In this proposed solution, a blockchain-integrated file storage application for document sharing to facilitate peer to peer collaboration in a secure, and decentralized manner, with no involvement of a centralized trusted entity or third party is proposed.This solution utilizes a blend of new technologies that primarily consists of (InterPlanetary File System) IPFS [3] that is used to store data with a high integrity and accessibility to all.The proposed solution provides privacy and security that cloud storage cannot achieve because all the files are accessed through content-based searching rather than location-based searching in the cloud.

RELATED WORK
Over the past few years decentralized technologies like blockchain and IPFS [21] are considered as fundamental technologies in redefining the future of data storage and data sharing, due to which various researchers and industrialists are taking part in creating a decentralized trust based and censorship resistant model [11].
Due to the advent of different technologies that are making the world more connected than before, the demand for data storage is at an all-time high.To meet these storage demands various cloud based centralized storage [3] solutions have emerged like iCloud, Google Drive and dropbox etc.But apart from some free amount of data storage [22] users have to pay a monthly fee.However this approach is inefficient and unsustainable in the long run.To provide an efficient way of solving this problem Vitalik Buterin [4] has provided a way of storing data in a decentralized way using Ethereum blockchain.According to Vitalik using ethereum smart contracts a decentralized file storage ecosystem [16] can be developed where users can be incentivized by renting out their hard drives and unused space.
Blockchain is considered to be the most important technology in paving the way towards a decentralized and censorship resistant future.To explore different possibilities of blockchain Min Xu, Xingtong Chen & Gang Kou [15] reviewed the current academic research conducted by different organizations on blockchain.They delved deeper in various research themes of blockchain and provide a pragmatic approach of using blockchain.They conduct a thorough analysis of different business and economic aspects of blockchain.Apart from this, different technical terms related to blockchain like smart contracts, cryptography and proof of work are also discussed.In the modern era of decentralization there have been numerous attempts of creating a distributed file storage system.Among these some have been extremely successful.And one such technology is the InterPlanetary FileSystem(IPFS) [3].In his research Juan Benet came up with a peer to peer file system [4] that attempts to overcome the problems faced by traditional centralized file systems.It is similar to how torrenting works.BitTorrent is a great example of how a decentralized file system could work [16].IPFS follows content based addressing to uniquely identify different files present in the network.Juan states that IPFS forms a merkle tree [23] like structure and it combines a distributed hash table for maintaining the addresses of different files.

WHY ETHEREUM?
Centralized systems have been targeted multiple times in recent years and a list of some prominent attacks have been organized by us Following are some of the major ones that caused the most commotion and harm.
1) The Bangladesh bank heist is considered to be the most astounding one, as it managed to by-pass the most secured SWIFT banking system.The gang managed to make $81 million from the attack!2) Mafia Boy(2000)-Mafia Boy virus was a dos(denial of service) attack that was developed by a teenager in Canada and it caused immense damages to some big conglomerates.Ethereum is a non-proprietary blockchain platform which allows users to build a range of decentralized and distributed applications [5].Similar to Bitcoin, it is a platform made and used by various open source communities worldwide.In contrast to Bitcoin protocol, adaptability and versatility were kept in mind while designing ethereum.It is simple and easy to create new applications on the Ethereum platform, and the new Homestead release helps in providing security to anyone using those applications.Ethereum integrates different technologies and features and also introduces different innovations and modifications of its own.Ethereum comprises different accounts and all accounts have a state associated with them.Ethereum maintains a global state of all these accounts.These accounts are divided in two types: • Contract Accounts, these contain smart contracts which are executed by EOAs.
• Externally Owned Accounts (EOAs),these are associated with private keys and public addresses.

Ethereum Accounts:
The states in ethereum are made from accounts, and every account has an address of 20 byte and different state transitions.An account in ethereum constitutes of these four fields: • Account's storage: (by default null) • Nonce: It is defined as a counter which is used to ensure every transaction is unique.
• Account balance of current account • Contract code of the account, if present "Ether" is known as the main internal Ethereum's crypto-fuel, which is used for handling transaction costs.2. After that GAS PRICE is used to calculate transaction fee.After this the sender's account address is determined using the given signature.Then the sender's account balance is reduced accordingly, along with the increment in nonce.In case of insufficient account balance an error is returned.3.After this if the transaction specifies a receiver then we are dealing with a message call otherwise it is a contract creation.To start a transaction some initial amount of START GAS is initialized and some amount is reduced to pay for bytes in transaction.4. Check if the receiver has an associated contract code.If it is not the case, the message call was successful.Then the contract code is executed until completion or it runs out of gas. 5.If there is a failure in a transaction due to the sender not having enough, all state changes are reverted except the payment of the fees and the same is deposited to the miner's account.6.In case of a successful transaction fees for any remaining gas is returned to the sender and fees for gas consumed is given to the miner.

PROPOSED MODEL
This model allows users to store and retrieve files in a censorship resistant fashion where all the files are stored in a decentralized way in the InterPlanetary File System(IPFS).The following diagram depicts the workflow of the proposed model: In traditional apps a web browser communicates to a centralized server which connects to a database to store and retrieve files but in our model a browser will use a cryptographic wallet to communicate to the ethereum blockchain which will contain aur smart contracts and we will be using smart contracts to store the location of files which are stored on the interplanetary file system.Users will directly interact with a web application built using Reacts and this app will interact with the ethereum blockchain as well as the InterPlanetary File System(IPFS).Whenever the web application is opened first all smart contracts are loaded onto the ethereum blockchain.Whenever a user uploads a file our app will interact with IPFS which will return a file hash and this hash will be stored on a smart contract which will be added to the ethereum blockchain.

IMPLEMENTATION
The proposed solution uses smart contracts to store the location of files present in the InterPlanetary File System (IPFS) [3].Solidity is used to write smart contracts in an efficient way which are later stored on the Ethereum blockchain.
File Upload Smart Contract Overview:

File Structure
The File Upload smart contract provides the functionality of storing different file hashes on the ethereum network.Each file has a predefined structure.This structure consists of data such as file size, file hash(as returned by the IPFS),file type, file description and file name.As soon as the Contract is created, the constructor is triggered and the aforementioned values are mapped to the created object which is of type File(structure defined in smart contract).The Smart Contract maintains a File Count which gets incremented whenever a new File is added.FileCount is used as an ID management system to provide different IDs for each file and to prevent overriding of data.struct File{ uint fileId; string fileHash; uint fileSize; string fileType; string fileName; string fileDescription; uint uploadTime; address uploader; }

Error Handling
The proposed system necessitates error free uploading of files.As mentioned above every file must adhere to a predefined structure and whenever a user uploads a file, before uploading this file to IPFS all the required parameters are checked.This is done by using the 'require' function of solidity which ensures validity of conditions which cannot be detected before execution.As a file is uploaded on the IPFS it returns a file hash along with some other metadata which is sent to ethereum smart contracts where a file object is created and all the metadata along with the file hash is mapped onto this object.To handle the mapping and uploading of this file on ethereum network a function is used which triggers an event.This event appends the newly created block or object onto the ethereum network.Less secured as data is stored at a particular single system called central storage system , so there is a single point of failure.

2.
Privacy As the data is spread across a large network of nodes, it isn't possible to steal it by attacking the entire network of nodes as it is impractical.
The data can be altered or lost as the host company has the authority to control or disclose the data to any third parties.

3.
Censorship No risk of censorship as there is no involvement of third parties in controlling the data.
Susceptible to censorship as the data is controlled by a central authority.

4.
Liveliness Liveness is a property with which a system will keep running even if certain components of it are not performing up to par.Here, even if one of the nodes goes down, the rest of the network will be more than capable of making up for the slack.
In a centralized cloud storage, if the server is down for whatever reason, the entire system goes down and this compromises with the liveliness of the application.

Figure 1 :
Figure 1: The money trail of Bangladesh Bank heist

Figure 4 :
Figure 4: Flowchart of the working model for the proposed application

Figure 5 :
Figure 5: Technical diagram of the implementation of application