_distributeRewardsPrivate
wrongly set unserIndex = 1
on first interaction, leading to erroneous reward distribution
#30
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-16
🤖_primary
AI based primary recommendation
🤖_06_group
AI based duplicate group recommendation
sufficient quality report
This report is of sufficient quality
unsatisfactory
does not satisfy C4 submission criteria; not eligible for awards
Lines of code
https://github.com/code-423n4/2024-10-loopfi/blob/d219f0132005b00a68f505edc22b34f9a8b49766/src/pendle-rewards/RewardManagerAbstract.sol#L68
Vulnerability details
Summary
User reward index is set to the wrong value on its first interaction with the Reward Manager.
Vulnerability details
RewardManagerAbstract::_distributeRewardsPrivate
distibute rewards to users based on:The index works like an exchange rate: when a user deposit, the vault index is saved for that user. Then when withdrawing, the saved index is compared to the new vault index, and tell how much of the generated rewards he now own.
Let's see how works the current implementation, see snippet below to follow.
userIndex == 0
, itsuserIndex
is set to a constantINITIAL_REWARD_INDEX == 1
.1
, the function continue and compute thedeltaIndex
withuserIndex == INITIAL_REWARD_INDEX == 1
So, the question is: how is index computed, and would be its value? We can find this in
rewardManager::_updateRewardIndex
:INITIAL_REWARD_INDEX == 1
index
is incremented by a value which is represented with decimals based on the reward token as it can be infered by the code inRewardManager::_updateRewardIndex()
where index is incremented byaccrued.divDown(totalShares)
, where both variables are token decimals, anddivDown
is from the PMath libraryNow let's say that vault
index == 1.5e18
anduserIndex == 1
We can see now how this line from the first snippet represent an issue:
The
deltaIndex
will be roughly equal toindex
, which represent a huge amount of accrual, while the user just deposited for the first time!Impact
Completely wrong computation of reward distribution
Tools Used
Manual review
Recommended Mitigation Steps
For its first interaction,
userIndex
should be set to the actual vaultindex
.The fix implementation should be review carefully as this might bring another issues.
Assessed type
Math
The text was updated successfully, but these errors were encountered: