Closed c4-bot-8 closed 8 months ago
Picodes marked the issue as duplicate of #614
Picodes marked the issue as satisfactory
This is not the same problem as #614 : In #614 ,in the initial state totalShares = 0 In this case is totalRewards = 0
uint256 rewardsShare = (totalRewards[poolID] * user.userShare) / totalShares[poolID];
Fixing the problem in 614 will not solve the problem
Picodes marked the issue as not a duplicate
Picodes marked the issue as unsatisfactory: Invalid
Indeed this is not a duplicate of #614. The report is unclear because addSALTRewards
of the staking contract updates totalRewards
so it's not clear how rewards end up on this contract.
Indeed this is not a duplicate of #614. The report is unclear because
addSALTRewards
of the staking contract updatestotalRewards
so it's not clear how rewards end up on this contract.
StakingRewards#addSALTRewards and _increaseUserShare
both increase totalRewards
,
This has no effect on the attacker, who can manipulate totalRewards
to equal 0
There are 2 addSALTRewards
StakingRewards#addSALTRewards
and
liquidityRewardsEmitter#addSALTRewards
pool initialization doesn't call StakingRewards#addSALTRewards
immediately, so totalRewards
could be equal to 0.
Yes but clearly https://github.com/code-423n4/2024-01-salty/blob/53516c2cdfdfacb662cdea6417c52f23c94d5b5b/src/rewards/RewardsEmitter.sol#L57 doesn't send SALT to the StakingRewards
contract but only stores them in the rewardsEmitter contract.
On a wider scale, please only comment with coded PoCs once your finding has been judged unclear once.
Lines of code
https://github.com/code-423n4/2024-01-salty/blob/53516c2cdfdfacb662cdea6417c52f23c94d5b5b/src/staking/StakingRewards.sol#L121
Vulnerability details
Impact
When
totalRewards
is equal to 0, the attacker can steal the salt token in the contract.Proof of Concept
When the DAO initializes the pool, it adds
SALTRewards
:However,
liquidityRewardsEmitter
does not increase the pool'stotalRewards
immediately, but records it in thependingReward
first:Therefore, when the user is staking or adding liquidity, the
totalRewards
in theStakingRewards
may be 0.In addition, the
StakingRewards#_decreaseUserShare
function reducestotalRewards
:Assume that some users increase
UserShare
whentotalRewards
equals 0,totalRewards
will not increase at this time, aftertotalRewards
is greater than 0, For these users after decrease UserShare, if they reduced their rewards by an amount equal tototalRewards
, it would still result intotalRewards
equal to 0.Let's look at the problems that
totalRewards
equals 0 can cause:totalRewards
is 0, user.virtualRewards = 0. After addingSALTRewards
, the user can get extra userReward.user.virtualRewards
equals 0 andvirtualRewardsToRemove
equals 0, an attacker could obtain the salt token with _decreaseUserShare.totalRewards
will not increase if totalRewards=0 at the first time, buttotalRewards
will always decrease at _decreaseUserShare).In addition, the first depository can also use
_decreaseUserShare
to increasetotalRewards
to 0.totalShares
are 0 on the first deposit, so there will also be no increase intotalRewards
when_increaseUserShare
. If the first user adds a large number of userShare(greater thantotalRewards
), that user can use_decreaseUserShare
to settotalRewards
to 0.Tools Used
vscode, manual
Recommended Mitigation Steps
Ensure that totalRewards is not 0 when initializing the pool.
Assessed type
Error