Thus, when existingTotalShares equal 1, virtualRewardsToAdd becomes large.
totalRewards[poolID], which also becomes a large value.
But the problem is, userReward is calculated by dividing by totalShares[poolID], totalShares is a very small value,
So when the totalRewards increase, the userReward increase very quickly
Lines of code
https://github.com/code-423n4/2024-01-salty/blob/53516c2cdfdfacb662cdea6417c52f23c94d5b5b/src/staking/StakingRewards.sol#L81
Vulnerability details
Impact
The first user deposits 1 wei to the pool to attack the pool.
Proof of Concept
The calculations of
virtualRewardsToAdd
in the_increaseUserShare
function are as follows:Thus, when
existingTotalShares
equal 1,virtualRewardsToAdd
becomes large.totalRewards[poolID]
, which also becomes a large value.But the problem is,
userReward
is calculated by dividing bytotalShares[poolID]
,totalShares
is a very small value, So when thetotalRewards
increase, theuserReward
increase very quicklyThe test scenario is as follows:
SALTRewards
with 1000 ether is added during pool initialization.userReward
is 113427455640312821230 ether!Tools Used
vscode, manual
Recommended Mitigation Steps
Limit the minimum deposit amount.
Assessed type
Error