Skip to content
Business logic Audit finding Advanced

The is_risky check is improper.

The is_risky check in the trading contract lets a user reduce an unhealthy position as long as the account value is non-negative, but it ignores the trade fee that is deducted afterwards. This can push the account value below zero and leave the protocol with bad debt.

shaflow1 Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

#47299 [SC-Insight] The `is_risky` check is improper.

Submitted on Jun 12th 2025 at 13:24:06 UTC by @shaflow1 for IOP | Paradex

Description

Brief/Intro

The is_risky check allows a trade to reduce position size even when the account has insufficient margin, as long as account_value >= 0. However, the protocol does not take trade_fee into account, which is deducted at the end of the trade. As a result, if the fee is not considered during the check, the post-trade account_value might fall below zero, potentially causing bad debt.

Vulnerability Details

Rust
        fn is_risky(
            self: @AccountState,
            position_size_before: felt252,
            position_size_after: felt252,
            trade_fee: i128,
        ) -> bool {
            let asset_value = self.get_asset_value();
            let (margin_requirement, total_upnl) = self
                .margin_requirement_and_total_upnl(MARGIN_CHECK_INITIAL);
            let account_value: i128 = asset_value + total_upnl;
            let free_balance = account_value - margin_requirement - trade_fee;
            if free_balance >= 0 {
                return false;
            }
            let abs_pos_before = abs_128(position_size_before.try_into().unwrap());
            let abs_pos_after = abs_128(position_size_after.try_into().unwrap());
            let position_decrease = abs_pos_before - abs_pos_after;
            if position_decrease >= 0 && account_value >= 0 {
                return false;
            }

The is_risky function allows reducing position size even when the account's health is insufficient, but it does not allow the trade to result in bad debt (i.e., account value < 0 after the trade). However, during the check, it does not take into account the trading fee that is immediately deducted from the account balance at the end of the trade. This means the account balance after the trade could likely fall below zero.

Therefore, fees should be taken into account to prevent bad debt from occurring after the trade.

Diff
-           if position_decrease >= 0 && account_value >= 0 {
+           if position_decrease >= 0 && account_value + trade_fee>= 0 {
                return false;
            }

Impact Details

The is_risky function may fail in certain cases and cannot prevent bad debt from occurring after a trade.

References

https://github.com/tradeparadex/audit-competition-may-2025/blob/0eb81b26a67666c399b4e16b39a96c19848ab7fd/paraclear/src/paraclear/paraclear.cairo#L599 https://github.com/tradeparadex/audit-competition-may-2025/blob/0eb81b26a67666c399b4e16b39a96c19848ab7fd/paraclear/src/account/account.cairo#L635

Proof of Concept

Proof of Concept

A user can deliberately choose specific trades under certain conditions to cause the protocol to incur bad debt.

  1. Position 1 of user1 is unhealthy, and user1 places an order to reduce the position.
  2. During the is_risky risk check, account_value < trade_fee, but the check still passes.
  3. At the end of the trade, trade_fee is deducted from user1’s account, causing account_value to fall below 0 and resulting in bad debt.

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

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 risk check compares account value against zero without subtracting the trade fee that is charged after the trade.

Impact

The check may fail to prevent bad debt after a trade, though the report only says this may happen in certain cases.

What the attacker needed

An unhealthy position; ability to place a reducing order

The fix

The check should include the trade fee when deciding whether the account value stays non-negative.

How it was found

  1. A user has an unhealthy position and places an order to reduce it.
  2. The is_risky check passes even though account value is less than the trade fee.
  3. The trade fee is deducted at the end, pushing account value below zero and creating bad debt.

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 trading platform checks whether an account is healthy before allowing a trade. This check lets someone shrink a losing position even when they barely have enough money, but it forgets that a fee is taken at the end. So the account can end up owing money, which the platform has to absorb.

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 shaflow1

View all

14 more disclosed reports, best first.

More from Paradex

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.