If the borrower enters token blacklist, LP may never be able to retrieve Liquidity
The contract refunds surplus tokens to the borrower during position closure, but if the borrower is blacklisted by the token (e.g., USDC), the transfer reverts, blocking closure and locking LP liquidity. An attacker could exploit this to prevent liquidation and cause bad debt for LPs.
Submitted by bin2chen, also found by ladboy233 and said
Currently, there are two ways to retrieve Liquidity
borroweractively close position : callclosePosition()- be forced liquidation leads to close position :
liquidatePosition()->_closePosition()
No matter which one, if there is a profit in the end, it needs to be refunded to the borrower.
function _closePosition(
DataStruct.ClosePositionParams calldata params,
DataCache.ClosePositionCache memory cache,
Lien.Info memory lien,
address borrower
) internal {
..
if (lien.zeroForOne) {
cache.token0Owed = cache.token0Owed < cache.tokenToPremium ? cache.token0Owed : cache.tokenToPremium;
cache.token1Owed = cache.token1Owed < cache.tokenFromPremium ? cache.token1Owed : cache.tokenFromPremium;
@> Base.refundWithCheck(
borrower,
cache.tokenFrom,
cache.collateralFrom + cache.tokenFromPremium,
cache.amountSpent + cache.amountFromAdd + cache.token1Owed
);
@> Base.refundWithCheck(
borrower,
cache.tokenTo,
cache.amountReceived + cache.tokenToPremium,
cache.amountToAdd + cache.token0Owed
);
} else {
cache.token0Owed = cache.token0Owed < cache.tokenFromPremium ? cache.token0Owed : cache.tokenFromPremium;
cache.token1Owed = cache.token1Owed < cache.tokenToPremium ? cache.token1Owed : cache.tokenToPremium;
@> Base.refundWithCheck(
borrower,
cache.tokenFrom,
cache.collateralFrom + cache.tokenFromPremium,
cache.amountSpent + cache.amountFromAdd + cache.token0Owed
);
@> Base.refundWithCheck(
borrower,
cache.tokenTo,
cache.amountReceived + cache.tokenToPremium,
cache.amountToAdd + cache.token1Owed
);
}
function refund(address recipient, address token, uint256 amountExpected, uint256 amountActual) internal {
if (amountExpected > amountActual) {
@> TransferHelper.safeTransfer(token, recipient, amountExpected - amountActual);
}
}
In this way, if the borrower enters the token0 or token1 blacklist, such as USDC and the token always has a profit, then refund() -> TransferHelper.safeTransfer() will definitely revert, causing _closePositon() to always revert, and LP’s Liquidity is locked in the contract.
Impact
If the borrower enters the token blacklist and always has a profit, LP may not be able to retrieve Liquidity.
Recommended Mitigation
Add a new claims[token] mechanism.
If refund()-> transfer() fails, record claims[token]+= (amountExpected - amountActual).
And provide methods to support borrower to claim().
wukong-particle (Particle) commented:
Good suggestion, we will try something along this claims idea. Quick question, can’t we simply add the
claimamount intotokenOwedthat’s already there for LPs?Also, does it block all transfer method, or only
TransferHelper.safeTransfer? We are open to use other transfer method if it makes things simpler.
0xleastwood (Judge) commented:
Agree with this issue and it’s severity. I would say all transfer methods would be blocked by the blacklist typically. I would also avoid allowing the recipient to be arbitrarily set, imo, the recipient here should always be the borrower. This avoids any issues in regards to the protocol facilitating users sidestepping blacklists.
wukong-particle (Particle) confirmed, but disagreed with severity and commented:
Agree with the judge. We shouldn’t and won’t facilitate escaping the blacklist. Our current plan is to put the
claimintotokenOwed, unless the wardens have other opinion to raise here.Is the severity fair though? This only affect the trader that enters the blacklist, not a widespread fund stealing behavior, no?
0xleastwood (Judge) commented:
Is the severity fair though? This only affect the trader that enters the blacklist, not a widespread fund stealing behavior, no?
Agreed, there is no widespread stealing of funds but unhealthy positions are at risk of not being liquidatable. It’s possible LPs are left with bad debt right? Which is a core part of the protocol and should be prioritised above all else.
My understanding is still limited atm, but how can a position be liquidated when it is in profit? Is this state even possible in the first place? As far as I can see, liquidation only happens when token debt exceeds token premium or when the loan has “expired”. I think there is possibility for refunds to happen in all three cases but it’s unclear to me that a position is solvent in any case where a refund is sent out to the borrower. And on the other end, when a position is not solvent, LPs are still protected.
wukong-particle (Particle) commented:
Forgot to follow up on this. Re judge’s comment above, the bad state is e.g., when a loan has “expired” but still profitable. In this case, the LP will get their rightful amount back (the borrowed liquidity + interest), and whatever remains will be refunded to the borrower (could even be at a profit). (This is after solving the issue 26).
However, after revising the contract, our team decides to skip this black issue for now for 2 reasons.
(1) this should be a rare situation: a borrower was not in a blacklist, opens a position, then enters the blacklist before closing/liquidating the position. If this really happens once or twice, our protocol will have an insurance fund to repay the LP. If we observe it to be a frequently occurred issue, we will upgrade the contract with the suggested “try-catch-claim” pattern.
(2) the liquidator can control the “amountSwap” to reduce the refund amount of blacklisted token to 0, only refunding the other token (basically skipping the swap for this token). This can’t solve the problem if both tokens blacklist the borrower.
So we will update the tag to sponsor-acknowledged. And we maintain that this shouldn’t be a high severity issue since it should happen in very rare situation and ‘s not widespread. Thanks!
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The contract unconditionally attempts to transfer surplus tokens to the borrower during position closure, without handling the case where the borrower is blacklisted and the transfer reverts.
Impact
If the borrower is blacklisted and the position is profitable, LP liquidity may be locked and unhealthy positions may become unliquidatable, potentially causing bad debt for LPs.
What the attacker needed
Borrower is blacklisted by the token; position has a profit to refund
The fix
The contract should be updated to use a try-catch-claim pattern, recording failed refunds as claims for the borrower to withdraw later, or adding the amount to tokenOwed.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Some tokens like USDC can blacklist addresses, meaning those addresses cannot send or receive the token. If a borrower is blacklisted, the contract's attempt to send them leftover tokens fails, and the whole closing process stops. This can trap the liquidity provided by lenders (LPs) because the position cannot be closed or liquidated.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.