-
Notifications
You must be signed in to change notification settings - Fork 0
0xDetermination - A borrower eligible for liquidation can pay an improperly large amount of fees, and may be unfairly liquidated #40
Comments
accLoanRatePerSeconds should not be updated since borrowedAmount are reduced, accordingly, a position debt also redused |
Invalid, agree with sponsors comments. This was previously discussed here |
Hi @nevillehuang @fann95 , posting commented PoC with console.logs below (modified test). The flow is like so:
|
I see in the tests that the amount of debt has decreased by part of the closed Lp-share, but the rest of the debt has been maintained, as expected. |
@fann95 That's weird, when I run in the contest repo the output is: Also, not sure if the test is passing on your end, but if it's passing I think the bug is there since the collateral is increased and emergency liq shouldn't happen |
It looks like this is a valid issue..I got different results since I ran your test in the updated version. The PR which corrected the problems with the distribution of commissions also corrected this problem. |
The protocol team fixed this issue in PR/commit RealWagmi/wagmi-leverage@84416fc. |
@fann95 @nevillehuang Fix code looks good to me, PoC doesn't pass in the main repo. In case my input is helpful- I think this issue is different than #41 since that issue describes a root cause/fix in |
@fann95 @0xDetermination I am trying to figure out how the original fix could have fixed this issue without first considering it, which leads me to believe they share the same root causes revolving around distribution of fees. I would have to take a closer look at the fix PR. |
This problem is indirectly related to the distribution of commissions. I got rid of the mechanism for accumulating a fee, therefore the current error was fixed. |
@Czar102 @0xDetermination What are your thoughts here based on duplication rules here? The core vulnerability seem to stem from erroneous distribution of fees which allowed for this issue to be possible in the first place. I am inclined to think this should be duplicated with #41
|
@nevillehuang @Czar102 The root cause and fix for this issue are both distinct from #41- the erroneous distribution of fees in #41 is caused by not harvesting fees when a new loan is taken with the This issue #40 is caused by the fee distribution mechanism in emergency liquidation mode in |
Since #39 and #41 talks about different types of fees, I agree they are not duplicates and they are both high severity findings. Given this erroneous fee calculation affects a large portion of the protocol, I agree with sponsor comments here and believe high severity is appropriate. However, I believe that #40 is a medium severity issue only possible because of the root cause of wrong computation of fees for borrowed positions within #41. This is evident from the fix employed without considering this issue in the first place. Hence, I am going to duplicate it with #41 and assign it as high severity based on sherlock rules despite it having only a medium severity impact. |
Escalate I understand @nevillehuang's point here, but I still think this shouldn't be a dup for the reasons I gave in my above comment. The fix PR changed a lot of things unrelated to validated issues, such as removal of the min fee mechanism. Will appreciate @Czar102's decision. Additionally, if validated as not a dup, not sure if this should be H or M based on the 'external conditions' criteria. |
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. |
@nevillehuang can you elaborate on how does a fix to #40 follows from #41? |
@nevillehuang what is the single logical error (maybe an assumption, maybe approach) that led to both of these issues? Having issue A which makes the sponsor want to restructure code and it accidentally removing issue B doesn't make them duplicates. |
I propose to confirm this issue and not consider it a duplicate. |
@Czar102 It stems from the logic for fee distribution. Although I disagree, seems like sponsor agrees to deduplicate so we can proceed with deduplication. |
@nevillehuang regarding this:
I believe it doesn't answer my question:
I wanted to have a one-sentence description of the common ground of these issues, and the fact that the issues "stem from the logic for fee distribution" (are in the same part of the code logic) doesn't make them duplicates. I'm planning to make this issue a unique issue, unless a justification (as mentioned above) is provided. What are the considerations regarding the severity? @nevillehuang
|
@Czar102 I'm not 100% sure whether this is better suited for H or M, as I don't have a ton of experience with Sherlock judging rules. Basically, the issue can cause serious loss of funds (borrower's entire collateral), but it is conditional on a partial emergency liquidation followed by the borrower increasing collateral. It looks more like M to me but I don't want to speak too soon, will leave it up to you and @nevillehuang. Happy to provide more info if needed. |
Yup @Czar102 I agree with your decision, I cannot pinpoint an exact singular approach/code logic given this is an update contest and would take up too much time. The reason I duplicated them was on the side of caution, given the sponsor quite literally fix this issue without even considering it. But since sponsor also agree with deduplication, lets move ahead |
In that case, planning to make this issue a unique Medium severity one. |
Result: |
Escalations have been resolved successfully! Escalation status:
|
Fix looks good, collection of fees in emergency mode |
The Lead Senior Watson signed off on the fix. |
0xDetermination
high
A borrower eligible for liquidation can pay an improperly large amount of fees, and may be unfairly liquidated
Summary
If a borrower is partially liquidated and then increases the collateral balance to avoid further liquidation, they will pay an improperly large amount of fees and can be unfairly liquidated.
Vulnerability Detail
The root cause is that partial emergency liquidation doesn't update
accLoanRatePerSeconds
(https://github.com/sherlock-audit/2024-02-leverage-contracts/blob/main/wagmi-leverage/contracts/LiquidityBorrowingManager.sol#L660-L666).If a borrower is partially liquidated, fees will be increased by the entire collateral amount (https://github.com/sherlock-audit/2024-02-leverage-contracts/blob/main/wagmi-leverage/contracts/LiquidityBorrowingManager.sol#L604-L633):
When liquidation occurs right after becoming liquidatable, the
collateralBalance
calculation inrepay()
above will be a small value like-1
; and essentially all the fees owed will be collected.If the borrower notices the partial liquidation and wishes to avoid further liquidation,
increaseCollateralBalance()
can be called to become solvent again. But since theaccLoanRatePerSeconds
wasn't updated, the borrower will have to doubly pay all the fees that were just collected. This will happen if a lender callsharvest()
or the loan is liquidated again. The loan can also be liquidated unfairly, because thecollateralBalance
calculated above will be much lower than it should be.Impact
The borrower may pay too many fees, and it's also possible to unfairly liquidate the position.
Code Snippet
https://github.com/sherlock-audit/2024-02-leverage-contracts/blob/main/wagmi-leverage/contracts/LiquidityBorrowingManager.sol#L660-L666
https://github.com/sherlock-audit/2024-02-leverage-contracts/blob/main/wagmi-leverage/contracts/LiquidityBorrowingManager.sol#L604-L633
Tool used
Manual Review
Recommendation
Update
accLoanRatePerSeconds
for incomplete emergency liquidations.The text was updated successfully, but these errors were encountered: