Skip to content

Instantly share code, notes, and snippets.

View zaryab2000's full-sized avatar
💻
Deciphering Smart Contract Security

Zaryab zaryab2000

💻
Deciphering Smart Contract Security
View GitHub Profile
const { ether, balance } = require('@openzeppelin/test-helpers');
const { accounts, contract } = require('@openzeppelin/test-environment');
const SideEntranceLenderPool = contract.fromArtifact('SideEntranceLenderPool');
const SideEntranceAttacker = contract.fromArtifact('SideEntranceAttacker');
const { expect } = require('chai');
describe('[Challenge] Side entrance', function () {
const { ether, balance } = require('@openzeppelin/test-helpers');
const { accounts, contract, web3 } = require('@openzeppelin/test-environment');
const LenderPool = contract.fromArtifact('NaiveReceiverLenderPool');
const FlashLoanReceiver = contract.fromArtifact('FlashLoanReceiver');
const myAttackContract = contract.fromArtifact('AttackContract');
const { expect } = require('chai');
describe('[Challenge] Naive receiver', function () {
contract UnstoppableLender is ReentrancyGuard {
using SafeMath for uint256;
IERC20 public damnValuableToken;
uint256 public poolBalance;
constructor(address tokenAddress) public {
require(tokenAddress != address(0), "Token address cannot be zero");
damnValuableToken = IERC20(tokenAddress);
}
const { ether, expectRevert } = require('@openzeppelin/test-helpers');
const { accounts, contract } = require('@openzeppelin/test-environment');
const DamnValuableToken = contract.fromArtifact('DamnValuableToken');
const UnstoppableLender = contract.fromArtifact('UnstoppableLender');
const ReceiverContract = contract.fromArtifact('ReceiverUnstoppable');
const { expect } = require('chai');
describe('[Challenge] Unstoppable', function () {
pragma solidity ^0.6.2;
import "../../introspection/IERC165.sol";
interface IERC721 is IERC165 {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
//DONATING FUNDS TO PATIENTS
function donateAmount(address _pid) public payable{
require((msg.sender).balance >= msg.value);
patientList[_pid].donatedAmount = msg.value;
donorList[msg.sender] = msg.value;
donorCount++;
donationHistoryList[donorCount] = donationHistory(_pid, msg.sender,now,msg.value,patientList[_pid].name);
}
//Withdrawing Funds from Patient
function withdrawInsurance(address _pid, uint256 _amountRequired) public{
// Checkpoints Before execution
require(doctorList[msg.sender]);
require(patientList[_pid].doctorAddress == msg.sender);
require(patientList[_pid].insuranceAmount >= _amountRequired);
// If all Conditions are satisfied, Funds are transferred to the assigned doctor
address payable recepientDoctor = msg.sender;
// Add a New DOCTOR
function setDoctor(address _docAddress,string memory _name, string memory _spec) public onlyOwner{
require(!doctorList[_docAddress]);
doctorList[_docAddress] = true;
doctorDetailList[_docAddress].docAdress = _docAddress;
doctorDetailList[_docAddress].docName = _name;
doctorDetailList[_docAddress].docSpecialization = _spec;
doctorCount++;
docAddressList[doctorCount] = _docAddress;
}
//Function to add a New Patient
function setPatientData(string memory _name, string memory _disease,string memory _ipfsHash) public payable onlyOwner{
//GENERATING a UNIQUE ID for Patient
address pid = address(bytes20(keccak256(abi.encodePacked(msg.sender,now))));
patientList[pid] = Patient(now,0,0,_name,_disease,' ',_ipfsHash,0x0000000000000000000000000000000000000000,pid,true,false);
// Adding Insurance Amount
patientList[pid].insuranceAmount = msg.value;
mapping( address => bool) public doctorList;
mapping(address => uint256) public donorList;
mapping(uint => address) public pidList;
mapping(address => Patient) public patientList;
mapping(address => Doctor) public doctorDetailList;
mapping(uint => donationHistory) public donationHistoryList;
mapping(uint => withdrawHistory) public withdrawHistoryList;