This repository has been archived by the owner on May 26, 2023. It is now read-only.
obront - Liquidator can take all collateral and underlying tokens for a fraction of the correct price #127
Labels
Has Duplicates
A valid issue with 1+ other issues describing the same vulnerability
High
A valid High severity issue
Reward
A payout will be made for this issue
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Will Fix
The sponsor confirmed this issue will be fixed
obront
high
Liquidator can take all collateral and underlying tokens for a fraction of the correct price
Summary
When performing liquidation calculations, we use the proportion of the individual token's debt they pay off to calculate the proportion of the liquidated user's collateral and underlying tokens to send to them. In the event that the user has multiple types of debt, the liquidator will be dramatically overpaid.
Vulnerability Detail
When a position's risk rating falls below the underlying token's liquidation threshold, the position becomes liquidatable. At this point, anyone can call
liquidate()
and pay back a share of their debt, and receive a propotionate share of their underlying assets.This is calculated as follows:
To summarize:
repayInternal()
, which pays off the position and returns the amount paid and number of shares paid offThe problem comes in the calculations. The amount paid to the liquidator is calculated as:
These calculations are taking the total size of the collateral or underlying token. They are then multiplying it by
share / oldShare
. Butshare / oldShare
is just the proportion of that one type of debt that was paid off, not of the user's entire debt pool.Let's walk through a specific scenario of how this might be exploited:
pos.collateralSize * 11.8k / 11.8k
(same calculation for the other two formulas)Impact
If a position with multiple borrows goes into liquidation, the liquidator can pay off the smallest token (guaranteed to be less than half the total value) to take the full position, stealing funds from innocent users.
Code Snippet
https://github.com/sherlock-audit/2023-02-blueberry/blob/main/contracts/BlueBerryBank.sol#L511-L572
https://github.com/sherlock-audit/2023-02-blueberry/blob/main/contracts/BlueBerryBank.sol#L760-L787
Tool used
Manual Review
Recommendation
Adjust these calculations to use
amountPaid / getDebtValue(positionId)
, which is accurately calculate the proportion of the total debt paid off.The text was updated successfully, but these errors were encountered: