The withdrawFees function in RockPaperScissors.sol is vulnerable to reentrancy attacks because it performs an external call to transfer ETH before updating the accumulatedFees state variable.
The withdrawFees function sends ETH to the admin address using a low-level call before subtracting the withdrawn amount from accumulatedFees. This allows a malicious admin contract to re-enter the function and withdraw more fees than available.
Vulnerable Code:
The state update (accumulatedFees -= amountToWithdraw) occurs after the external call (adminAddress.call), violating the checks-effects-interactions pattern.
A malicious admin contract could repeatedly call withdrawFees within the same transaction, draining the contract's entire ETH balance before accumulatedFees is updated, leading to loss of funds.
Manual code review
Slither (static analysis tool)
Follow the checks-effects-interactions pattern by updating the state before making external calls.
Consider using OpenZeppelin's ReentrancyGuard to prevent reentrancy.
Recommended Fix:
Add ReentrancyGuard from OpenZeppelin and include the nonReentrant modifier.
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.