Skip to content

hackerpranavpandey/BlockChain-Course-Project

Repository files navigation

DeepFake Detection

This Project is a decentralized application demonstrating a system for detecting deepfakes in images/videos, verifying their authenticity using cryptographic hashes, storing them decentrally on IPFS, and managing sharing permissions securely via a blockchain smart contract.


Table of Contents


Introduction

Our project aims to tackle the challenges posed by deepfake technology to media authenticity by leveraging the combined power of blockchain and machine learning.

  1. Deepfake Detection: Uploaded media is analyzed by three backend nodes running a deep learning model to assess if it's likely a deepfake. A consensus mechanism can be used for higher reliability.
  2. Integrity Verification: A cryptographic hash (SHA-256) of the original media file is calculated before upload.
  3. Decentralized Storage: Verified authentic media is uploaded to IPFS via Pinata, ensuring content-addressable, decentralized storage.
  4. Immutable Record: The IPFS CID (Content Identifier) and the calculated hash are stored immutably on an Ethereum-compatible blockchain using a Solidity smart contract.
  5. Secure Sharing & Traceability: The smart contract manages fine-grained, item-level sharing permissions. Sharing actions are logged via events, enabling traceability of who shared what with whom.
  6. Client-Side Verification: When viewing media, the application fetches the content from IPFS, recalculates its hash, and verifies it against the hash stored on the blockchain, ensuring tamper-evidence.

Features

  • Deepfake Detection: Analyzes uploads using a Keras/TensorFlow model.
    • Supports a client-orchestrated consensus mechanism across multiple detection nodes.
  • Cryptographic Hashing: Generates SHA-256 hash for integrity verification.
  • IPFS Upload: Stores verified media on IPFS via Pinata pinning service.
  • Blockchain Anchoring: Records media CID, hash, and ownership on the blockchain (via Solidity Smart Contract).
  • Client-Side Verification: Verifies retrieved media integrity against the blockchain hash.
  • Item-Level Sharing: Allows owners (or those granted access) to securely share specific media items with other Ethereum addresses.
  • Sharing Traceability: Logs sharing events on the blockchain, allowing reconstruction of the sharing history.

Technology Stack

  • Frontend: React.js, Ethers.js
  • Backend: Python, Flask, TensorFlow/Keras
  • Blockchain: Solidity, Hardhat
  • Decentralized Storage: Pinata
  • Wallet: MetaMask

Requirements

Ensure you have the following installed before proceeding:

General:

Frontend:

Backend:

  • Python >= 3.12
  • Additional dependencies listed in requirement.txt

Install the required packages then only you will be able to start the DApp

# first activate your python virtual environment and install python dependencies mentioned in requirement.txt
pip install -r requirement.txt

Blockchain Development:

  • Hardhat (installed via npm in the project)

Services:

  • Pinata Account: Required for API Key and Secret Key to pin files to IPFS.

Installation

Clone this repository to your local machine:

git clone https://github.com/hackerpranavpandey/BlockChain-Course-Project.git
cd BlockChain-Course-Project

Running the Application (Local Development)

Please see this video on how to start the Application :-

[Link](https://youtu.be/aRHTKzFZOkw?si=3DcqbRniiuajmQTQ)

1. Start Backend Nodes

For the consensus mechanism, you need to run three instances of the Flask backend, each on a different port specified in client/src/components/FileUpload.jsx (e.g., 5001, 5002, 5003).

Commands common for three terminals

cd Backend
# Activate virtual environment if not already active
# source venv/bin/activate # (macOS/Linux) OR venv\Scripts\activate (Windows)

Terminal 1:

python backend1.py --port 5001

Terminal 2:

python backend2.py --port 5002

Terminal 3:

python backend3.py --port 5003

2. Start Local Blockchain Node

In a new terminal, start the Hardhat local node from the project root:

npm i # to install node modules
npx hardhat node

3. Deploy Smart Contract

In another new terminal, deploy the Upload.sol contract to the local Hardhat node:

npx hardhat run --network localhost scripts/deploy.js

IMPORTANT: Note the contract address printed in the console after successful deployment.

4. Update Frontend Configuration

Open the file in your frontend where the contract instance is initialized (client/src/App.js). Update the contractAddress variable with the address you noted in the previous step.

5. Start Frontend Application

cd client
npm i # to install node modules
npm start

File Structure

.
├── Backend/                  # Python Flask backend code
│   ├── backend1.py            # Main Flask application logic
│   ├── backend2.py            # Main Flask application logic
│   ├── backend3.py            # Main Flask application logic
│   └── deepfake_model.keras  # Trained deep learning model file for Image
│   └── deepfake-detection-model1.h5  # Trained deep learning model file for Video
├── client/                   # React frontend application (DApp)
│   ├── public/               # Static assets
│   └── src/                  # React source code
│       ├── artifacts/        # Contract artifacts generated by Hardhat (including ABI)
│       ├── components/       # React components (FileUpload, Display, TraceabilityModal, Modal, etc.)
│       ├── App.css           # Main app styles
│       ├── App.js            
│       ├── App.test.js       
│       ├── index.css         
│       ├── index.js
│       ├── reportWebVitals.js                     
│       └── setupTests.js
├── contracts/                # Solidity smart contract source code
│   └── Upload.sol            # The main smart contract
├── cache/                    # Hardhat cache 
├── ignition/                 # Hardhat Ignition deployment modules (if used)
├── scripts/                  # Deployment scripts (e.g., deploy.js)
├── screenshots               # It contain all the screenshots of the DApp
├── hardhat.config.js         # Hardhat configuration file
├── package-lock.json         # Exact dependency versions for npm
├── package.json              # Project metadata and Node.js dependencies
└── README.md                 # documentation file

Contributors

Pranav Kumar Pandey
Parikshit Gehlaut

Contributing

We welcome contributions to the our project! To contribute, please follow these steps:

  1. Fork the repository
  2. create a new branch
  3. Make and commit your changes
  4. Push to the branch
  5. Open a pull request

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors