cachedUserRewards variable is never reset, so user can steal all rewards
A cached rewards variable was added to a user's claimable balance but never cleared after a claim. An attacker could therefore claim the same cached amount repeatedly and drain all reward tokens held by the contract.
Source: https://github.com/sherlock-audit/2023-02-olympus-judging/issues/43
Found by
CRYP70, ABA, ast3ros, nobody2018, minhtrng, saian, jonatascm, KingNFT, cducrest-brainbot, Ruhum, rvierdiiev
Summary
cachedUserRewards variable is never reset, so user can steal all rewards
Vulnerability Detail
When user wants to withdraw then _withdrawUpdateRewardState function is called.
This function updates internal reward state and claims rewards for user if he provided true as claim_ param.
In case if user didn't want to claim, and rewardDebtDiff > userRewardDebts[msg.sender][rewardToken.token] then cachedUserRewards variable will be set for him which will allow him to claim that amount later.
https://github.com/sherlock-audit/2023-02-olympus/blob/main/src/policies/lending/abstracts/SingleSidedLiquidityVault.sol#L583-L590
if (rewardDebtDiff > userRewardDebts[msg.sender][rewardToken.token]) {
userRewardDebts[msg.sender][rewardToken.token] = 0;
cachedUserRewards[msg.sender][rewardToken.token] +=
rewardDebtDiff -
userRewardDebts[msg.sender][rewardToken.token];
} else {
userRewardDebts[msg.sender][rewardToken.token] -= rewardDebtDiff;
}
When user calls claimRewards, then cachedUserRewards variable is added to the rewards he should receive.
The problem is that cachedUserRewards variable is never reset to 0, once user claimed that amount.
Because of that he can claim multiple times in order to receive all balance of token.
Impact
User can steal all rewards
Code Snippet
Provided above
Tool used
Manual Review
Recommendation
Once user received rewards, reset cachedUserRewards variable to 0. This can be done inside _claimInternalRewards function.
Discussion
0xLienid
This should be high severity
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the claim routine adds the cached reward amount to the payout but never zeroes the cached value afterwards.
Impact
A user could steal all rewards held by the contract.
What the attacker needed
A position in the liquidity vault; withdraw without claiming first
The fix
The cached rewards value should be reset to zero once the user has received the rewards, for example inside the internal claim function.
How it was found
- Withdraw without claiming so that the cached reward value is set for the caller
- Call claimRewards to receive the cached amount
- Call claimRewards again to receive the same cached amount repeatedly
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract keeps a note of rewards a user is owed but has not yet collected. When the user collects, the contract pays out but forgets to erase the note, so the user can ask again and again and be paid each time until the pool is empty.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.