due to the following constraint on the current buggy implementation:
PuppyRaffle::refund allows you to withdraw from the event, but no enforcement on ended event that withdrawal is prohibited
PuppyRaffle::selectWinner contains weak randomness that can be guessed correctly
when someone calls selectWinner, MEV bot can hold the transaction, frontrun the transaction by checking the winner using the randomness formula, and potentially withdraw out from the event if the expected person isn't the winner (meaning it allows any loser withdraw out), only then allows the selectWinner function to executes
Likelihood: High
any loser can withdraw out right before the selectWinner function is called
Impact: High/Medium
loser can take this advantage to secure their fees deposited during the participation
winner will get less ETH
a casual ongoing raffle event, with participant coming in
after the time has passed, someone calls selectWinner to conclude the event and select winner
however, Alice hold this action (assuming Alice has participated the event)
Alice take advantage of the weak randomness to guess the winner. she realized that she is not the winner
Alice calls refund to withdraw herself off from the event, getting back her prior entrance fees deposits
then no.2 action goes through, winner has announced and the reward has distributed
Alice being the loser has successfully secured her deposits, while the actual winner receive less rewards than he should
create a new test file, paste the below PoC into the newly created test file, and run it.
consider adding a checks to ensure that refund (including enterRaffle) is only permitted right before the event has ended
## Description Malicious actors can watch any `selectWinner` transaction and front-run it with a transaction that calls `refund` to avoid participating in the raffle if he/she is not the winner or even to steal the owner fess utilizing the current calculation of the `totalAmountCollected` variable in the `selectWinner` function. ## Vulnerability Details The PuppyRaffle smart contract is vulnerable to potential front-running attacks in both the `selectWinner` and `refund` functions. Malicious actors can monitor transactions involving the `selectWinner` function and front-run them by submitting a transaction calling the `refund` function just before or after the `selectWinner` transaction. This malicious behavior can be leveraged to exploit the raffle in various ways. Specifically, attackers can: 1. **Attempt to Avoid Participation:** If the attacker is not the intended winner, they can call the `refund` function before the legitimate winner is selected. This refunds the attacker's entrance fee, allowing them to avoid participating in the raffle and effectively nullifying their loss. 2. **Steal Owner Fees:** Exploiting the current calculation of the `totalAmountCollected` variable in the `selectWinner` function, attackers can execute a front-running transaction, manipulating the prize pool to favor themselves. This can result in the attacker claiming more funds than intended, potentially stealing the owner's fees (`totalFees`). ## Impact - **Medium:** The potential front-running attack might lead to undesirable outcomes, including avoiding participation in the raffle and stealing the owner's fees (`totalFees`). These actions can result in significant financial losses and unfair manipulation of the contract. ## Recommendations To mitigate the potential front-running attacks and enhance the security of the PuppyRaffle contract, consider the following recommendations: - Implement Transaction ordering dependence (TOD) to prevent front-running attacks. This can be achieved by applying time locks in which participants can only call the `refund` function after a certain period of time has passed since the `selectWinner` function was called. This would prevent attackers from front-running the `selectWinner` function and calling the `refund` function before the legitimate winner is selected.
The contest is live. Earn rewards by submitting a finding.
Submissions are being reviewed by our AI judge. Results will be available in a few minutes.
View all submissionsThe contest is complete and the rewards are being distributed.