In over liquidation, if the liquidatee has USDC-denominated assets for sale, the liquidator can buy the assets with USDC to avoid paying USDC to the liquidatee
In over-liquidation, the liquidator can avoid paying the required USDC to the liquidatee by buying the liquidatee's USDC-denominated assets in the callback, which increases the liquidatee's USDC balance and satisfies the balance check. This lets the liquidator acquire collateral without compensating the liquidatee with additional USDC.
Source: https://github.com/sherlock-audit/2023-04-jojo-judging/issues/369
Found by
cccz, monrel
Summary
In over liquidation, if the liquidatee has USDC-denominated assets for sale, the liquidator can buy the assets with USDC to avoid paying USDC to the liquidatee
Vulnerability Detail
In JUSDBank contract, if the liquidator wants to liquidate more collateral than the borrowings of the liquidatee, the liquidator can pay additional USDC to get the liquidatee's collateral.
} else {
// actualJUSD = actualCollateral * priceOff
// = JUSDBorrowed * priceOff / priceOff * (1-insuranceFeeRate)
// = JUSDBorrowed / (1-insuranceFeeRate)
// insuranceFee = actualJUSD * insuranceFeeRate
// = actualCollateral * priceOff * insuranceFeeRate
// = JUSDBorrowed * insuranceFeeRate / (1- insuranceFeeRate)
liquidateData.actualCollateral = JUSDBorrowed
.decimalDiv(priceOff)
.decimalDiv(JOJOConstant.ONE - reserve.insuranceFeeRate);
liquidateData.insuranceFee = JUSDBorrowed
.decimalMul(reserve.insuranceFeeRate)
.decimalDiv(JOJOConstant.ONE - reserve.insuranceFeeRate);
liquidateData.actualLiquidatedT0 = liquidatedInfo.t0BorrowBalance;
liquidateData.actualLiquidated = JUSDBorrowed;
}
liquidateData.liquidatedRemainUSDC = (amount -
liquidateData.actualCollateral).decimalMul(price);
The liquidator needs to pay USDC in the callback and the JUSDBank contract will require the final USDC balance of the liquidatee to increase.
require(
IERC20(primaryAsset).balanceOf(liquidated) -
primaryLiquidatedAmount >=
liquidateData.liquidatedRemainUSDC,
JUSDErrors.LIQUIDATED_AMOUNT_NOT_ENOUGH
);
If the liquidatee has USDC-denominated assets for sale, the liquidator can purchase the assets with USDC in the callback, so that the liquidatee's USDC balance will increase and the liquidator will not need to send USDC to the liquidatee to pass the check in the JUSDBank contract.
Impact
In case of over liquidation, the liquidator does not need to pay additional USDC to the liquidatee
Code Snippet
https://github.com/sherlock-audit/2023-04-jojo/blob/main/JUSDV1/src/Impl/JUSDBank.sol#L188-L204
Tool used
Manual Review
Recommendation
Consider banning over liquidation
Discussion
JoscelynFarr
That is in our consideration, if the liquidation triggered, there is a possibility for liquidator to liquidate all collaterals, and the remain collateral will return by the USDC to liquidatee
JoscelynFarr
In fact, I don't understand how the attack occurs
Trumpero
This issue states that the USDC balance of a liquidated user will be validated as the result of liquidation. However, the liquidator can purchase USDC instead of directly transfer USDC in the callback function (when the liquidated user sells USDC elsewhere). After that, the balance check for liquidation is still fulfilled, but the liquidated user will lose assets.
hrishibhat
Additional comment from the Watson:
Assume liquidationPriceOff = 5% and ETH : USDC = 2000 : 1. Alice's unhealthy position is borrowed for 100000 JUSD, collateral is 60 ETH, meanwhile Alice sells 7 ETH for 14000 USDC in other protocol. Bob liquidates 60 ETH of Alice's position, Bob needs to pay 100000 JUSD, and 60 * 2000 - 100000 / 0.95 = 14737 USDC. In the JOJOFlashLoan callback, Bob sends 100000 JUSD to the contract and buys the 7 ETH that Alice sold in the other protocol (It increases Alice's USDC balance by 14000), and then Bob just send another 14737-14000=737 USDC to Alice to pass the following check
require(
IERC20(primaryAsset).balanceOf(liquidated) -
primaryLiquidatedAmount >=
liquidateData.liquidatedRemainUSDC,
JUSDErrors.LIQUIDATED_AMOUNT_NOT_ENOUGH
);
JoscelynFarr
fix commit: https://github.com/JOJOexchange/JUSDV1/commit/5918d68be9b5b021691f768da98df5f712ac6edd
IAm0x52
Need validation of amount sent to liquidated
IAm0x52
Fix looks good. Reentrancy exists if _primaryAsset is also a collateral but team has explicitly stated that this is never the case.
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
Likely the liquidation check only verifies that the liquidatee's USDC balance increased, without ensuring the increase came from the liquidator's payment.
Impact
In over-liquidation, the liquidator does not need to pay the additional USDC to the liquidatee, causing the liquidatee to lose assets.
What the attacker needed
Over-liquidation occurs; liquidatee has USDC-denominated assets for sale
The fix
The project fixed this by banning over-liquidation, as shown in the fix commit.
How it was found
- The liquidator initiates an over-liquidation where they take more collateral than the liquidatee's borrowings.
- In the flash loan callback, the liquidator buys the liquidatee's USDC-denominated assets that are for sale elsewhere.
- This purchase increases the liquidatee's USDC balance.
- The liquidator sends only the remaining USDC needed to satisfy the balance check, avoiding the full required payment.
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.
When someone's loan is liquidated, the liquidator must pay back the debt and also send extra USDC to the borrower if they take more collateral than the debt. The contract checks that the borrower's USDC balance increased by the required amount. The bug is that the liquidator can increase that balance by buying assets the borrower is selling, instead of actually paying the borrower, so the borrower loses out.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.