Skip to content
Business logic Audit finding Intermediate

Position contract allows to interact with positions that are liquidated

The Position contract does not check whether a position has already been liquidated before letting the user add more collateral. A user who calls increaseMargin after liquidation has their new collateral locked, because closePosition always reverts when it tries to redeem the larger bath token amount.

rvierdiiev Follow

Originally disclosed on Code4rena

Submitted by rvierdiiev.

Position contract allows to interact with positions that are liquidated. Because of that user can loose funds.

Proof of Concept

When new position is created, the amount of tokens that were supplied as collateral are saved as well. Later, when the user wants to close position, they will redeem that amount. If a user wants to add collateral to avoid liquidation or for any other reason, they can call increaseMargin, which will increase their bath token amount that is used as collateral for the position.

In this case, if Position bathToken collateral is liquidated, that means that their debt becomes 0 and if they call closePosition, then the call will revert, as it will need to redeem bathToken amount that the Position contract doesn’t control anymore.

So in this case, if the user will call increaseMargin, just after it was liquidated, then the provided collateral will never be possible to withdraw, as closePosition will always revert.

Example:

  1. User has open position for bathUSDC, with an amount of 1000 bathUSDC.
  2. Their position is under liquidation so they want to increaseMargin with 100 USDC more.
  3. Liquidation happens before increaseMargin was called, so the Position contract bathUSDC balance is now 0 and increaseMargin mints 100 bathUSDC more.
  4. increaseMargin increased the position’s bath amount to 1100.
  5. The user realized that they couldn’t save position and now want to get back collateral, they call closePosition.
  6. closePosition reverts when redeeming as a Position contract that doesn’t have 1100 bathUSDC, only 100 USDC.

As a result, the user’s 100 USDC is locked and can be used only as collateral for borrowing.

Tools Used

VsCode

Recommended Mitigation Steps

Do not allow users to interact with liquidated positions.

daoio (Rubicon) confirmed


The original report as published on Code4rena, by rvierdiiev. 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

Likely the increaseMargin and closePosition functions do not check whether the position has already been liquidated, so the recorded bath token amount no longer matches the contract's real balance.

Impact

The user's newly added collateral is locked and can only serve as collateral for borrowing, not be withdrawn.

What the attacker needed

An open position; position gets liquidated; user calls increaseMargin afterwards

The fix

The contract should reject interactions such as increaseMargin and closePosition on positions that have already been liquidated.

How it was found

  1. Open a position with a bath token amount as collateral.
  2. The position becomes eligible for liquidation.
  3. Liquidation happens before the user calls increaseMargin, so the contract's bath token balance drops to zero.
  4. The user calls increaseMargin, which mints a new bath token amount and raises the recorded position amount.
  5. The user calls closePosition to recover collateral.
  6. closePosition reverts because the contract holds less bath token than the recorded amount.

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 position is a loan backed by collateral. If the loan goes bad, the system liquidates it, meaning the collateral is taken and the debt is cleared. Here the contract still let the user add more collateral to a position that had already been liquidated, and that extra money could not be taken back 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.

More by rvierdiiev

View all

72 more disclosed reports, best first.

More from Rubicon v2

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.