Skip to content
Business logic Audit finding Intermediate

Withdrawing uncollateralized deposits is possible even though the position is in liquidation mode

The withdrawal check for uncollateralized deposits uses the bare collateral value instead of the weighted collateral value, so a user can withdraw funds even when their position is liquidatable. An attacker could remove uncollateralized deposits to avoid liquidation, contrary to the protocol's stated intent.

0xStalin Follow

Originally disclosed on Code4rena

Submitted by 0xStalin

Users can withdraw uncollateralized deposits even though their position is liquidable, as opposed to the README. If the position is in liquidation mode, users should use their uncollateralized deposits to avoid liquidation instead of removing them.

Proof of Concept

When withdrawing deposits from public pools, at the end of the tx is executed the WiseLending._healthStateCheck() function, which depending on the value of the powerFarmCheck will determine if the position’s collateral is enough to cover the borrows.

  • If powerFarmCheck is true, it will use the bare value of the collateral; meaning, the collateralFactor is not applied to the collateral’s value.
  • If powerFarmCheck is false, it will use the weighted value of the collateral; meaning, the collateralFactor is applied to the collateral’s value.

When withdrawing an uncollateralized deposit, the WiseCore._coreWithdrawToken() function calls the WiseSecurity.checksWithdraw() function to determine the value of the powerFarmCheck. If the pool from where the tokens are being withdrawn is uncollateralized, the powerFarmCheck will be set to true, which will cause that the WiseLending._healthStateCheck() function uses the bare value of the full collateral to determine if the collateral can cover the existing borrows.

Using the bare value of the collateral does not accurately reflect if a position is liquidable or not, the liquidation’s logic in the WiseSecurity.checksLiquidation() function uses the weightedCollateral instead of the bareCollateral to determine if the position is liquidable or not. This difference to determine if the position’s collateral can cover the borrows when withdrawing uncollateralized deposits and when doing liquidation causes a discrepancy to allow the withdrawal of uncollateralized deposits even though the position is in liquidation mode.

For example, a user requests a withdrawal of an uncollateralized deposit in a position with the below values:

  • 1.5e18 ETH of bare collateral.

  • 1.2e18 ETH of weightedCollateral.

  • 1.3e18 ETH of borrows.

    • The withdrawal will be allowed even though the position is in liquidation mode. Because of the powerFarmCheck being set to true, the WiseLending._healthStateCheck() function will check if 95% of the bareCollateral can cover the borrows, 95% of 1.5e18 ETH would be 1.425e18 ETH. Thus, the withdrawal will be possible, even though the position is in liquidation mode.

WiseSecurity.sol:

function checksWithdraw(
    ...
)
    ...
{
    ...

    if (_isUncollateralized(_nftId, _poolToken) == true) {
        return true;
    }

    ...
}
    function _getState(
        uint256 _nftId,
        bool _powerFarm
    )
        internal
        view
        returns (bool)
    {
        ...

        //@audit-info => If `powerFarmCheck` is true, overalCollateral will be computed using the value of the `bareCollateral`
        //@audit-info => If `powerFarmCheck` is false, overalCollateral will be computed using the value of the `weightedCollateral`

        uint256 overallCollateral = _powerFarm == true
            ? overallETHCollateralsBare(_nftId)
            : overallETHCollateralsWeighted(_nftId);

        //@audit-info => If 95% of the overalCollateral > borrowAmount, withdrawal will be allowed!
        return overallCollateral
            * BORROW_PERCENTAGE_CAP
            / PRECISION_FACTOR_E18
            < borrowAmount;
    }

Now, when using the same values but for a liquidation, we have that the weightedCollateral is not enough to cover the borrows; thus, the position is liquidable.

WiseSecurity.sol:

    function checksLiquidation(
        ...
    )
        external
        view
    {
        ...

        //@audit-info => When doing liquidations, the value of the `weightedCollateral` is used to determine if the position is liquidable or not!
        canLiquidate(
            borrowETHTotal,
            weightedCollateralETH
        );

        ...
    }

Recommended Mitigation Steps

If the protocol wants to enforce that users use their uncollateralized deposits to avoid liquidations when the positions are liquidable, don’t set to true the powerFarmCheck when doing withdrawals for uncollateralized deposits. Allow the WiseLending._healthStateCheck() function to validate if the position is indeed in liquidation mode by using the weightedCollateral instead of the bareCollateral value.

WiseSecurity.sol:

    function checksWithdraw(
        ..
    )
        ..
    {
        ...

    -   if (_isUncollateralized(_nftId, _poolToken) == true) {
    -       return true;
    -   }

        ...
    }

Assessed type

Context

vonMangoldt (Wise Lending) commented:

That’s no issue since the additional check is reflecting a higher %. We will keep it like that.

Wise Lending commented:

Mitigated here.


The original report as published on Code4rena, by 0xStalin. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 withdrawal path sets a flag that makes the health check use bare collateral instead of weighted collateral, while liquidation uses weighted collateral, creating a discrepancy.

Impact

A user could withdraw uncollateralized deposits to avoid liquidation, contrary to the protocol's documented behaviour.

What the attacker needed

A position with borrows and uncollateralized deposits

The fix

The protocol mitigated the issue by removing the early return for uncollateralized deposits in checksWithdraw, so the health check uses weighted collateral.

How it was found

  1. Have a position with borrows and uncollateralized deposits.
  2. Request a withdrawal of the uncollateralized deposit.
  3. The withdrawal is allowed because the health check uses bare collateral, even though the position is liquidatable by weighted collateral.

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.

In lending protocols, a user's collateral is valued with a safety margin (weighted) to decide if they can be liquidated. This report found that when withdrawing a special type of deposit, the protocol checked the full collateral value without that margin, so users could take out funds even when their position was already unsafe.

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.

More by 0xStalin

View all

20 more disclosed reports, best first.

More from Wise Lending

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.