Melted Shadow Otter
Medium
The withdraw and getReward functions transfer tokens to users before updating the user's balance or rewards. This could lead to reentrancy attacks.
Use the ReentrancyGuard from OpenZeppelin or follow the Checks-Effects-Interactions pattern by updating state variables before transferring tokens.
function withdraw(uint _amount) external updateReward(msg.sender) {
require(_amount > 0, "amount = 0");
require(balanceOf[msg.sender] >= _amount, "withdrawal exceeds balance");
balanceOf[msg.sender] -= _amount;
totalSupply -= _amount;
// Transfer tokens after state updates
stakingToken.transfer(msg.sender, _amount);
}
No response
No response
No response
No response
No response
No response