User can drain entire reward balance due to accounting issue in _claimInternalRewards and _claimExternalRewards
The contract stores user reward debt with 36 decimal places but updates it with an 18 decimal place reward amount when claiming, so the debt is understated. An attacker could repeatedly claim rewards and drain the contract's entire reward balance.
Source: https://github.com/sherlock-audit/2023-02-olympus-judging/issues/161
Found by
Aymen0909, Bahurum, 0xlmanini, ABA, Met, carrot, chaduke, nobody2018, GimelSec, Bauer, KingNFT, cducrest-brainbot, 0x52, rvierdiiev
Summary
The userRewardDebts array stores the users debt to 36 dp but in _claimInternalRewards and _claimExternalRewards the 18 dp reward token amount. The result is that usersRewardDebts incorrectly tracks how many rewards have been claimed and would allow an adversary to claim repeatedly and drain the entire reward balance of the contract.
Vulnerability Detail
When calculating the total rewards owed a user it subtracts userRewardDebts from lpPositions[user_] * accumulatedRewardsPerShare. Since lpPositions[user_] and accumulatedRewardsPerShare are both 18 dp values, this means that userRewardDebts should store the debt to 36 dp.
In _depositUpdateRewardDebts we can see that userRewardDebts is in fact stored as a 36 dp value because lpReceived_ and rewardToken.accumulatedRewardsPerShare are both 18 dp values.
When claiming tokens, userRewardDebts is updated with the raw 18 dp reward amount NOT a 36 dp value like it should. The result is that userRewardDebts is incremented by a fraction of what it should be. Since it isn't updated correctly, subsequent claims will give the user too many tokens. An malicious user could abuse this to repeatedly call the contract and drain it of all reward tokens.
Impact
Contract will send to many reward tokens and will be drained
Code Snippet
Tool used
ChatGPT
Recommendation
Scale the reward amount by 1e18:
uint256 fee = (reward * FEE) / PRECISION;
- userRewardDebts[msg.sender][rewardToken.token] += reward;
+ userRewardDebts[msg.sender][rewardToken.token] += reward * 1e18;
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
The reward debt is stored with 36 decimal places but updated with an 18 decimal place value, causing a unit mismatch.
Impact
The contract could send too many reward tokens and be completely drained.
What the attacker needed
A user position in the vault; ability to call claim function repeatedly
The fix
The reward amount should be scaled by 1e18 before adding to the user's reward debt.
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 tracks how many rewards each user has already claimed using a number called 'reward debt'. When a user claims, the contract should increase that debt by the correct amount, but it adds a number that is a trillion times too small. This means the contract thinks the user has claimed far less than they actually have, so the user can keep claiming and take all the rewards.
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.