Open sherlock-admin2 opened 11 months ago
Hello
Indeed this is a real problem due the way that the invariant : Sum of all balanceOfYsCvg > totalSupply
And so some positions will become not claimable on the YsDistributor
.
We'll correct this by computing the same way the ysTotal & ysPartial on the balanceYs & ysCheckpoint
Very nice finding, it'd break the claim for the last users to claim.
Escalate
The amounts are scaled up by 1e18. The rounding down problem comes when dividing by MAX_PERCENTAGE
which equals 100. Worst case scenario (which will only happen if a user deposits an amount which is not divisible by 100), there will be rounding down of up to 99 wei. Not only it is insignificant, it is unlikely to happen as it requires a deposit of an amount not divisible by 1e2.
Believe issue should be marked as low.
Escalate The amounts are scaled up by 1e18. The rounding down problem comes when dividing by
MAX_PERCENTAGE
which equals 100. Worst case scenario (which will only happen if a user deposits an amount which is not divisible by 100), there will be rounding down of up to 99 wei. Not only it is insignificant, it is unlikely to happen as it requires a deposit of an amount not divisible by 1e2. Believe issue should be marked as low.
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
Worst case scenario, only the last user will be unable to claim their rewards (even though I described above why it is highly unlikely). In the rare situation it happens, it can be fixed by simply sending a few wei to the contract.
Imo, just off point 1 alone, this warrants medium severity at the least. The fact that a donation is required to fix this means there is a bug, and is not intended functionality of the function.
I agree that this is a borderline low/med. I don't see a reason to discriminate nonzero deposits mod 100. That said, I am siding with the escalation – the loss here is insufficient to consider it a material loss of funds (at no point in the lifetime of the codebase will it surpass $1), and a loss of protocol functionality isn't serious enough if simply sending some dust to the contract will resolve the issue.
Planning to accept the escalation and consider this a low severity issue.
@Czar102 please consider report #132 which I submitted which allows to steal an arbitrary amount from the rewards under some conditions, which is a higher impact.
My issue shares the same root cause as this one, so I did not escalate for deduplication. However if you think that this issue should be low, maybe it would be more fair to make my issue unique since the impact is sufficient.
Both examples present used involve relatively low amounts, so I'm unsure what is the exact impact
Comparing this issue attack path
by using increaseLockAmount with small amount values by which the total difference difference b/w the user's calculated balanceOfYsCvgAt and the accounted amount in totalSuppliesTracking can be increased
and #132
-> Alice locks some small amount for lockDuration = 64 so that it increases totalSupply by exactly 1 -> Alice proceeds to lock X times using the values:
Comparing this issue impact
This breaks the shares accounting of the treasury rewards. Some user's will get more than the actual intended rewards while the last withdrawals will result in a revert
and #132
Under specific circumstances (if the attacker is the only one to have allocated to YS during a TDE), an attacker is able to claim arbitrarily more rewards than is due to him, stealing rewards from other participants in the protocol
My opinion is both issues should remain valid medium severity issue based on impact highlighted in both issues.
After some discussion with @nevillehuang, agree that issues should stay duplicated and valid high/medium
given following reasons:
To summarize:
The highest impact described in #132 requires for the total balance to not simply be very low but in fact to be just a few wei. Not only it has to be a few wei, but it has to be a few wei for at least 12 weeks (until TDE payout). It is absolutely unrealistic to have a few wei total balance for 12 weeks.
Issue should remain Low severity
I agree that the fix of sending minor amounts of all reward tokens won't cost the team any considerable loss financially. But apart from the fix, the impact under reasonable conditions of user not being able to withdraw their rewards is certainly a major one. If issues existing on the contract are judged based on the ease of fixing/preventing, I think a lot more issues would exist under this category. Wouldn't it make almost all functionality breaks in up-gradable contracts low severity due to the fix being an upgrade?
Due to the additional impact noted (thank you @CergyK) I think the loss can be sufficient to warrant a medium severity for this issue (loss of funds, but improbable assumptions are made).
Result: Medium Has duplicates
This issue has been solved here :
https://github.com/Cvg-Finance/sherlock-cvg/pull/4
Follow the comments :
Fix looks good. Order of operations has been updated to consistently reflect the proper value
hash
medium
Division difference can result in a revert when claiming treasury yield and excess rewards to some users
Summary
Different ordering of calculations are used to compute
ysTotal
in different situations. This causes the totalShares tracked to be less than the claimable amount of sharesVulnerability Detail
ysTotal
is calculated differently when adding tototalSuppliesTracking
and when computingbalanceOfYsCvgAt
. When adding tototalSuppliesTracking
, the calculation ofysTotal
is as follows:In
balanceOfYsCvgAt
,ysTotal
is calculated as followsThis difference allows the
balanceOfYsCvgAt
to be greater than what is added tototalSuppliesTracking
POC
Calculation in
totalSuppliesTracking
gives:Calculation in
balanceOfYsCvgAt
gives:Example Scenario
Alice, Bob and Jake locks cvg for 1 TDE and obtains rounded up
balanceOfYsCvgAt
. A user who is aware of this issue can exploit this issue further by usingincreaseLockAmount
with small amount values by which the total difference difference b/w the user's calculatedbalanceOfYsCvgAt
and the accounted amount intotalSuppliesTracking
can be increased. Bob and Jake claims the reward at the end of reward cycle. When Alice attempts to claim rewards, it reverts since there is not enough reward to be sent.Impact
This breaks the shares accounting of the treasury rewards. Some user's will get more than the actual intended rewards while the last withdrawals will result in a revert
Code Snippet
totalSuppliesTracking
calculationIn
mintPosition
https://github.com/sherlock-audit/2023-11-convergence/blob/main/sherlock-cvg/contracts/Locking/LockingPositionService.sol#L261-L263In
increaseLockAmount
https://github.com/sherlock-audit/2023-11-convergence/blob/e894be3e36614a385cf409dc7e278d5b8f16d6f2/sherlock-cvg/contracts/Locking/LockingPositionService.sol#L339-L345In
increaseLockTimeAndAmount
https://github.com/sherlock-audit/2023-11-convergence/blob/main/sherlock-cvg/contracts/Locking/LockingPositionService.sol#L465-L470_ysCvgCheckpoint
https://github.com/sherlock-audit/2023-11-convergence/blob/main/sherlock-cvg/contracts/Locking/LockingPositionService.sol#L577-L584balanceOfYsCvgAt
calculation https://github.com/sherlock-audit/2023-11-convergence/blob/main/sherlock-cvg/contracts/Locking/LockingPositionService.sol#L673-L675Tool used
Manual Review
Recommendation
Perform the same calculation in both places