0% found this document useful (0 votes)
20 views7 pages

Assignment2 Ethereum Smart Contract

An Ethereum smart contract was created for a bug bounty program. The contract allows users to report bugs along with descriptions, and for the owner to mark bugs as fixed or verified, rewarding reporters. The contract was written in Solidity, deployed to the Ethereum blockchain using Remix, and tested by reporting, fixing, and verifying bugs. This demonstrated the successful development of a smart contract for a bug bounty program on Ethereum.

Uploaded by

SAI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views7 pages

Assignment2 Ethereum Smart Contract

An Ethereum smart contract was created for a bug bounty program. The contract allows users to report bugs along with descriptions, and for the owner to mark bugs as fixed or verified, rewarding reporters. The contract was written in Solidity, deployed to the Ethereum blockchain using Remix, and tested by reporting, fixing, and verifying bugs. This demonstrated the successful development of a smart contract for a bug bounty program on Ethereum.

Uploaded by

SAI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Blockchain Assignment-2: Ethereum Smart Contract

Date: 04/11/23

Team members:
Monish Kumar A (2020506055)
Sanjay T (2020506081)
Bala Natesh R M (2020506018)

An Ethereum smart contract is a self-executing contract with the terms of the agreement
directly written into code. These contracts run on the Ethereum blockchain, which is a
decentralized, distributed ledger that allows for the execution of code when certain conditions
are met. Ethereum smart contracts are written in a programming language called Solidity.

Steps to create an Ethereum smart contract:


1. Write the contract code in Solidity.
2. Compile the code to create a bytecode representation.
3. Deploy the contract to the Ethereum network using a tool like Remix, Truffle, or
Hardhat.
4. Once deployed, the contract's address is known, and it can be interacted with using
Ethereum transactions.

Here, we have made a bug bounty smart contract. A user can report a bug along with its
description. The owner of the program checks and fixes the bug. Once the bug is fixed, the
reporter is granted a reward.
Code:
bugBounty.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract BugBounty {
address public owner; // Owner of the bug bounty program
uint256 public reward; // Reward assigned for each bug fixed
// Contains values for bug status
enum BugStatus { Reported, Fixed, Verified }

// General structure for bug details


struct BugReport {
address reporter;
string description;
BugStatus status;
}

mapping(uint256 => BugReport) public bugReports;


uint256 public bugCount;

// Events to handle the program


event BugReported(uint256 indexed bugId, address indexed reporter, string description);
event BugFixed(uint256 indexed bugId);
event BugVerified(uint256 indexed bugId);

constructor() {
owner = msg.sender;
reward = 1 wei;
}

modifier onlyOwner() {
require(msg.sender == owner, "Only the owner can call this function");
_;
}

// Allows anyone to report a bug with a small description


// of the bug. The reported bugs are added to a list with
// "Reported" status
function reportBug(string memory description) public {
bugCount++;
bugReports[bugCount] = BugReport(msg.sender, description, BugStatus.Reported);
emit BugReported(bugCount, msg.sender, description);
}

// Can be called only by the owner of the bug bounty program


// Takes the bugID and changes it's status to "Fixed"
function fixBug(uint256 bugId) public onlyOwner {
require(bugId <= bugCount, "Bug report does not exist");
require(bugReports[bugId].status == BugStatus.Reported, "Bug is not in the Reported status");
bugReports[bugId].status = BugStatus.Fixed;
emit BugFixed(bugId);
}

// Can be called only by the owner of the bug bounty program


// Called once the reporter of the bug is ready to claim reward
// Takes bugID as parameter, checks for the status of bugID
// and transacts the reward to the reporter that reported the bug
function verifyBug(uint256 bugId) public onlyOwner payable {
require(bugId <= bugCount, "Bug report does not exist");
require(bugReports[bugId].status == BugStatus.Fixed, "Bug is not in the Fixed status");
bugReports[bugId].status = BugStatus.Verified;
payable(bugReports[bugId].reporter).transfer(reward);
emit BugVerified(bugId);
}
}
Screenshots:
1- Successful compilation of contract

2- The contract is deployed on Remix VM Merge blockchain. (Sandboxed)


3- Deployment of contract on the blockchain

4- The available methods and attributes of the contract


5- Report of bug to contract

6- Calls to view the current bugCount and status of bugReports


7- The status of bug is changed by bug fixed call

8- The bug is verified for "Fixed" status and the reward is transacted

Result:
Hence, an Ethereum smart contract has been developed and tested successfully

You might also like