# Based Pariksha

Solving real-life problems is, in my opinion, the best way to contribute to our country and humanity. This project is crucial, and I believe we can fully realize it. The main challenge I faced was joining the Based India hackathon late, which hindered my ability to create a working demo. However, I have developed the basic code for the project, which is ready for testing on the blockchain. Together, we can make a significant impact in combating paper leaks and restoring trust in our education system.<br>

<pre><code>// Based Pariksha Concept Code
// SPDX-License-Identifier: MIT 
pragma solidity ^0.8.17;

contract OnChainExam {
<strong>    // Admin address
</strong>    address public admin;
    
    // Struct to represent a student
<strong>    struct Student {
</strong>        address studentAddress;
        bool isRegistered;
        string studentName;
    }
    
    // Struct to represent an exam
    struct Exam {
        uint256 examId;
        string examHash; // IPFS hash of encrypted exam
        uint256 unlockTime; // Time when the exam can be accessed
        bool isActive; // Is the exam active
    }
    
    // Mapping of student addresses to student details
    mapping(address => Student) public students;
    // Mapping of exam ID to exam details
    mapping(uint256 => Exam) public exams;
    
    // Total number of students and exams
    uint256 public studentCount;
    uint256 public examCount;
    
    // Modifier to allow only admin to execute certain functions
    modifier onlyAdmin() {
        require(msg.sender == admin, "Only admin can call this function");
        _;
    }
    
    // Modifier to check if student is registered
    modifier onlyRegisteredStudent() {
        require(students[msg.sender].isRegistered, "You are not registered as a student");
        _;
    }
    
    // Event for student registration
    event StudentRegistered(address studentAddress, string studentName);
    
    // Event for new exam created
    event ExamCreated(uint256 examId, string examHash, uint256 unlockTime);
    
    // Constructor to initialize the contract
    constructor() {
        admin = msg.sender; // Set the deployer as admin
    }
    
    // Function to register a new student
    function registerStudent(address _studentAddress, string memory _studentName) public onlyAdmin {
        require(!students[_studentAddress].isRegistered, "Student already registered");
        students[_studentAddress] = Student(_studentAddress, true, _studentName);
        studentCount++;
        
        emit StudentRegistered(_studentAddress, _studentName);
    }
    
    // Function to create an exam
    function createExam(string memory _examHash, uint256 _unlockTime) public onlyAdmin {
        require(_unlockTime > block.timestamp, "Unlock time must be in the future");
        
        examCount++;
        exams[examCount] = Exam(examCount, _examHash, _unlockTime, true);
        
        emit ExamCreated(examCount, _examHash, _unlockTime);
    }
    
    // Function to access the exam (returns the IPFS hash)
    function accessExam(uint256 _examId) public view onlyRegisteredStudent returns (string memory) {
        Exam memory exam = exams[_examId];
        require(exam.isActive, "Exam is not active");
        require(block.timestamp >= exam.unlockTime, "Exam is locked until the unlock time");
    
        return exam.examHash;
    }
    
    // Function for admin to deactivate an exam after the exam window is over
    function deactivateExam(uint256 _examId) public onlyAdmin {
        require(exams[_examId].isActive, "Exam is already inactive");
        exams[_examId].isActive = false;
    }
}
</code></pre>

#### Key Features:

1. **Admin Role**: Only the admin can register students and upload exams.
2. **Student Registration**: Admin registers students using their wallet addresses.
3. **Exam Creation**: The admin uploads the exam paper (stored on IPFS) and sets a time when students can access it.
4. **Time-based Exam Access**: The contract checks the current block timestamp against the `unlockTime` to ensure students can only access the exam after it is released.
5. **Exam Deactivation**: Admin can deactivate the exam after it's done.

#### IPFS Integration:

You would store the encrypted exam paper on IPFS and include the IPFS hash in the `examHash` field of the contract. When students access the exam, they receive the IPFS link to download and decrypt the exam.

#### Additional Features (Next Steps):

1. **Exam Submissions**: A function to allow students to submit answers (possibly by uploading another IPFS hash containing their answers).
2. **AI Integration**: You can integrate off-chain AI verification systems for identity verification (e.g., face scanning) and store results on-chain.
3. **Smart Contract Security**: Implement security measures to prevent unauthorized access and tampering.

This is the foundation. we can expand it further with more features/
