Summary
refund()
reentrancy risk. Update players[playerIndex]
state before sending the refund fee.
Vulnerability Details
File: PuppyRaffle.sol
096: function refund(uint256 playerIndex) public {
097: address playerAddress = players[playerIndex];
098: require(playerAddress == msg.sender, "PuppyRaffle: Only the player can refund");
099: require(playerAddress != address(0), "PuppyRaffle: Player already refunded, or is not active");
100:
101: payable(msg.sender).sendValue(entranceFee);
102:
103: players[playerIndex] = address(0);
104: emit RaffleRefunded(playerAddress);
105: }
Impact
Malicious actor can re-enter into refund()
to siphon all entrance fee in the contract.
Tools Used
manual review
Recommendations
updating the state before sending the fee to prevent reentrancy attack.
File: PuppyRaffle.sol
096: function refund(uint256 playerIndex) public {
097: address playerAddress = players[playerIndex];
098: require(playerAddress == msg.sender, "PuppyRaffle: Only the player can refund");
099: require(playerAddress != address(0), "PuppyRaffle: Player already refunded, or is not active");
100:
101: players[playerIndex] = address(0);
102: payable(msg.sender).sendValue(entranceFee);
103:
104: emit RaffleRefunded(playerAddress);
105: }