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
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);
}
-
Liquidation Process: When an admin liquidates a position by opening a short position in Synthetix, several steps are involved:
- Liquidation Initiation: The admin calls
borrowing::liquidatewithliquidationType2. - Position Opening: The
borrowLiquidationcontract executesliquidationType2, which opens a short position viasubmitOffchainDelayedOrder. - Order Execution: The admin calls
borrowing::executeOrdersInSynthetix, which in turn callsborrowLiquidation::executeOrdersInSynthetixto execute the order. - Position Closing: The
closeThePositionInSynthetixfunction is called to close the position.
- Liquidation Initiation: The admin calls
-
Lack of Withdrawal Mechanism: If the closure of the position in Synthetix results in ETH or other tokens sETH being sent to the
BorrowLiquidationcontract, 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.
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
- An admin liquidates a position through the borrowing contract using liquidationType2.
- The BorrowLiquidation contract opens a short position in Synthetix via a delayed order.
- The admin executes the delayed order through the borrowing contract.
- 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.