Skip to content
Business logic Audit finding Intermediate

Inability to Withdraw ETH/tokens in BorrowLiquidation Contract if `closeThePositionInSynthetix` is Called

The BorrowLiquidation contract can receive ETH or sETH when a Synthetix short position is closed, but it has no function to move those assets out. Funds returned from closing positions could therefore become permanently stuck in the contract.

0x23r0 Follow with 0x37, pashap9990 and 1 other

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/569

Found by

0x23r0, 0x37, pashap9990, valuevalk

Summary

The BorrowLiquidation contract lacks the ability to withdraw ETH/native tokens or other tokens received from closing positions in Synthetix, potentially locking these assets within the contract indefinitely.

Root Cause

Solidity

    function liquidationType2(
        address user,
        uint64 index,
        uint64 currentEthPrice
    ) internal {
        // Get the borrower and deposit details
        ITreasury.GetBorrowingResult memory getBorrowingResult = treasury.getBorrowing(user, index);
        ITreasury.DepositDetails memory depositDetail = getBorrowingResult.depositDetails;
        require(!depositDetail.liquidated, "Already Liquidated");

        // Check whether the position is eligible for liquidation
        uint128 ratio = BorrowLib.calculateEthPriceRatio(depositDetail.ethPriceAtDeposit, currentEthPrice);
        require(ratio <= 8000, "You cannot liquidate, ratio is greater than 0.8");

        uint256 amount = BorrowLib.calculateHalfValue(depositDetail.depositedAmountInETH);

        // Convert the ETH into WETH
        weth.deposit{value: amount}();
        // Approve it, to mint sETH
        bool approved = weth.approve(address(wrapper), amount);

        if (!approved) revert BorrowLiq_ApproveFailed();

        // Mint sETH
        wrapper.mint(amount);
        // Exchange sETH with sUSD
        synthetix.exchange(
            0x7345544800000000000000000000000000000000000000000000000000000000,
            amount,
            0x7355534400000000000000000000000000000000000000000000000000000000
        );

        // Calculate the margin
        int256 margin = int256((amount * currentEthPrice) / 100);
        // Transfer the margin to synthetix
        synthetixPerpsV2.transferMargin(margin);

        // Submit an offchain delayed order in synthetix for short position with 1X leverage
@>>        synthetixPerpsV2.submitOffchainDelayedOrder(
            -int((uint(margin * 1 ether * 1e16) / currentEthPrice)),
            currentEthPrice * 1e16
        );
    }

    /**
     * @dev Submit the order in Synthetix for closing position, can only be called by Borrowing contract
     */
    function closeThePositionInSynthetix() external onlyBorrowingContract {
        (, uint128 ethPrice) = borrowing.getUSDValue(borrowing.assetAddress(IBorrowing.AssetName.ETH));
        // Submit an order to close all positions in synthetix
@>>        synthetixPerpsV2.submitOffchainDelayedOrder(-synthetixPerpsV2.positions(address(this)).size, ethPrice * 1e16);
    }

    /**
     * @dev Execute the submitted order in Synthetix
     * @param priceUpdateData Bytes[] data to update price
     */
    function executeOrdersInSynthetix(
        bytes[] calldata priceUpdateData
    ) external onlyBorrowingContract {
        // Execute the submitted order
@>>        synthetixPerpsV2.executeOffchainDelayedOrder{value: 1}(address(this), priceUpdateData);
    }

https://github.com/sherlock-audit/2024-11-autonomint/blob/main/Blockchain/Blockchian/contracts/Core_logic/borrowLiquidation.sol#L323-L387

  • Liquidation Process: When an admin liquidates a position by opening a short position in Synthetix, several steps are involved:

    1. Liquidation Initiation: The admin calls borrowing::liquidate with liquidationType2.
    2. Position Opening: The borrowLiquidation contract executes liquidationType2, which opens a short position via submitOffchainDelayedOrder.
    3. Order Execution: The admin calls borrowing::executeOrdersInSynthetix, which in turn calls borrowLiquidation::executeOrdersInSynthetix to execute the order.
    4. Position Closing: The closeThePositionInSynthetix function is called to close the position.
  • Lack of Withdrawal Mechanism: If the closure of the position in Synthetix results in ETH or other tokens sETH being sent to the BorrowLiquidation contract, there is no function provided to withdraw these funds, thus locking them within the contract.

Internal pre-conditions

No response

External pre-conditions

  • An admin has initiated a liquidation through the borrowing contract.
  • Synthetix's market conditions allow for position closure, potentially returning ETH or other tokens.

Attack Path

No response

Impact

ETH or other tokens sETH received by the borrowingLiquidation contract cannot be withdrawn, leading to liquidity loss.

PoC

No response

Mitigation

Add a function like withdrawETH or withdrawTokens to allow authorized withdrawals.

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

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 contract implements flows that can send ETH or sETH to itself but omits any withdrawal function for those assets.

Impact

ETH or sETH returned to the contract could be permanently locked, causing a loss of liquidity, though the report does not show this happening in practice.

What the attacker needed

Admin initiates a liquidation; Synthetix position closure returns funds

The fix

A withdrawal function restricted to authorised callers should be added so the contract can release ETH and tokens it receives.

How it was found

  1. An admin liquidates a position through the borrowing contract using liquidationType2.
  2. The BorrowLiquidation contract opens a short position in Synthetix via a delayed order.
  3. The admin executes the delayed order through the borrowing contract.
  4. The position is closed in Synthetix, which may return ETH or sETH to the BorrowLiquidation contract.

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.

A smart contract can hold money, but only code written into it can send that money out. This contract can receive ETH or sETH after closing a trade, yet nobody wrote a way to withdraw it, so the money would sit there forever. sETH is a token representing staked Ether on Synthetix.

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 0x23r0

View all

23 more disclosed reports, best first.

More from Autonomint Colored Dollar V1

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.