Open sherlock-admin4 opened 1 month ago
This is a valid issue, will fix by not accounting the fee when users provide RA
The protocol team fixed this issue in the following PRs/commits: https://github.com/Cork-Technology/Depeg-swap/pull/77
All the selected duplicates describe different issues:
Escalate above comment
Escalate above comment
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.
I will agree with the previous comment. #57, #153, #179 really describe the same root cause issue and based on other groupings of issues in this contest, maybe they have to be counted as one with the issue described here. I thought that when two similar issues happen in different places in the code, they should be separated as fixing one would not fix the other.
I know this is not part of the original escalation, but since the issue is escalated, I believe it should be of high severity, as it essentially results in the first users that withdraw stealing funds from the last users that withdraw.
I agree with the duplication explained in this comment and plan to apply it. About the severity, as I understand, there are indeed no limitations on this issue and a couple of last users could end up with no rewards at all. Hence, planning to accept the escalation, apply the duplication explained here and increase the severity to high.
Result: High Has duplicates
vinica_boy
High
Wrong accounting of locked RA when repurchasing DS+PA with RA
Summary
Users have the option to repurchase DS + PA by providing RA to the PSM. A portion of the RA provided is taken as a fee, and this fee is used to mint CT + DS for providing liquidity to the AMM pair.
Vulnerability Detail
NOTE: Currently
PsmLib.sol
incorrectly useslockUnchecked()
for the amount of RA provided by the user. As discussed with sponsor it should belockFrom()
in order to account for the RA provided.After initially locking the RA provided, part of this amount is used to provide liquidity to the AMM via
VaultLibrary.provideLiquidityWithFee()
provideLiqudityWithFee
internally uses__provideLiquidityWithRatio()
which calculates the amount of RA that should be used to mint CT+DS in order to be able to provide liquidity.__provideLiquidity()
usesPsmLibrary.unsafeIssueToLv()
to account the RA locked.RA locked is incremented with the amount of CT tokens minted.
Consider the following scenario: For simplicity the minted values in the example may not be accurate, but the idea is to show the wrong accounting of locked RA.
__provideLiquidity()
let say 3 of those 5 RA are used to mint CT+DS.PsmLibrary.unsafeIssueToLv()
would add 3 RA to the locked amount, making the psm.balances.ra.locked = 1103 while the real balance would still be 1100.Impact
Wrong accounting of locked RA would lead to over-distribution of rewards for users + after time last users to redeem might not be able to redeem as there wont be enough RA in the contract due to previous over-distribution. This breaks a core functionality of the protocol and the likelihood of this happening is very high, making the overall severity High.
Code Snippet
PsmLib.repurchase()
: https://github.com/sherlock-audit/2024-08-cork-protocol/blob/db23bf67e45781b00ee6de5f6f23e621af16bd7e/Depeg-swap/contracts/libraries/PsmLib.sol#L293Tool used
Manual Review
Recommendation
Consider either not accounting for the fee used to mint CT+DS as it is already accounted or do not initially account for the fee when users provide RA.