TempleGold

TempleDAO
Foundry
25,000 USDC
View results
Submission Details
Severity: medium
Invalid

If a user calls TempleGoldStaking.withdrawAll() with `claim` set to false, then he cannot withdraw the rewards anymore

Summary

Withdrawing all rewards when setting claim()as false will not allow the user to collect any rewards for that particular stakeInfo index anymore.

Vulnerability Details

When withdrawing TempleGold tokens from the TempleGoldStaking contract, users can set a parameter claimto decide whether or not to claim rewards.

function withdrawAll(uint256 stakeIndex, bool claim) external override {
StakeInfo storage _stakeInfo = _stakeInfos[msg.sender][stakeIndex];
_withdrawFor(_stakeInfo, msg.sender, msg.sender, stakeIndex, _stakeInfo.amount, claim, msg.sender);
}

If the user calls withdrawAll(), it means that they intend to withdraw all the amount from the _stakeInfo.amount. If claim is true, then _getReward() will be called:

if (claimRewards) {
// can call internal because user reward already updated
_getReward(staker, rewardsToAddress, stakeIndex);
}

If a user calls withdrawAll() with claim set to false, then he cannot withdraw his rewards anymore as his balances will become zero and withdrawFor does not allow zero value as the amount.

function _withdrawFor(
StakeInfo storage stakeInfo,
address staker,
address toAddress,
uint256 stakeIndex,
uint256 amount,
bool claimRewards,
address rewardsToAddress
) internal updateReward(staker, stakeIndex) {
> if (amount == 0) { revert CommonEventsAndErrors.ExpectedNonZero(); }

Users will not be able to claim their reward for that particular index.

Impact

Claim rewards will be stuck in contract.

Tools Used

Manual Review

Recommendations

Remove the zero check line. Users can set amount to zero just to claim their rewards.

- if (amount == 0) { revert CommonEventsAndErrors.ExpectedNonZero(); }
Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.