Skip to content
Business logic Audit finding Intermediate

The fee calculation in settle_market is unreasonable.

The settle_market function only charges the taker fee, ignoring the maker fee, so a user who acts as both taker and maker during settlement can exploit negative fee rates to drain the fee account. Under certain conditions, a malicious actor can repeatedly place and settle orders to steal funds from the fee account.

shaflow1 Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#47330 [SC-Low] The fee calculation in `settle_market` is unreasonable.

Submitted on Jun 12th 2025 at 16:57:58 UTC by @shaflow1 for IOP | Paradex

Description

Brief/Intro

In the settle_market function, only the taker fee from the account is charged, which is unreasonable:

  1. Charging only the taker fee may result in a negative total fee, causing a loss to the fee account.
  2. In a settle trade, the user acts as both the taker and the maker, so both sides' fees should be charged to ensure that the total fee is not negative and to prevent losses to the fee account.

Vulnerability Details

Rust
        fn _settlement_fee_payments(
            ref self: ContractState,
            account: ContractAddress,
            account_state: @AccountState,
            pending_token_balance: i128, // usdc 
            token_balance_address: ContractAddress,
            trade_size: i128,
            trade_price: i128,
            settlement_token_price: NonZero<i128>,
            asset: @PerpetualMarketAsset,
        ) -> i128 {
            let fee_account = self.getFeeAccount();

            let base_fee = asset
                .calculate_fee(
                    *account_state.asset_data,
                    trade_size,
                    trade_price,
                    false,
                    account_state.fee_rates,
                );
            let (fee, referrer, fee_commission) = account_state
                .get_trade_fee_and_referral_commission(base_fee);
            let balance_after_fee = pending_token_balance - fee;

            self
                .token
                .write_asset_balance(account, token_balance_address, balance_after_fee.into());
            let settlement_token_address = self.getSettlementTokenAsset();

            let fee_in_settlement_token = div_128(fee, settlement_token_price);
            if fee_commission == 0 {
                self
                    .token
                    .upsert_asset_balance(
                        fee_account, settlement_token_address, fee_in_settlement_token.into(),
                    );
            } else {
                let fee_commission_in_settlement_token = div_128(
                    fee_commission, settlement_token_price,
                );
                self
                    .token
                    .upsert_asset_balance(
                        referrer,
                        settlement_token_address,
                        fee_commission_in_settlement_token.into(),
                    );
                self
                    .token
                    .upsert_asset_balance(
                        fee_account,
                        settlement_token_address,
                        (fee_in_settlement_token - fee_commission_in_settlement_token).into(),
                    );
            }

            self.emit(AccountComponent::Event::Fee(Fee { account: account, fee: fee.into() }));
            return balance_after_fee;
        }

_settlement_fee only charges the taker fee, which is inappropriate.

In a settlement trade, the user acts as both the taker and the maker, so charging only the taker fee is unreasonable.

Moreover, if one of the fee rates (taker or maker) is negative, for example, if the taker fee rate is negative, then the settlement operation would result in a negative fee, causing the feeAccount to lose funds.

Impact Details

The rewards from fee_account can be stolen under certain conditions

References

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

Proof of Concept

Proof of Concept

  1. Suppose the user's taker_fee_rate is -1% and the maker_fee_rate is 1.2%. A malicious actor can place an order and immediately settle it to steal funds from the fee_account.
  2. Assume that when placing the order, the user acts as the taker — in this case, the taker receives a 1% fee. If the user acts as the maker, they pay a 1.2% fee.
  3. Then the user immediately settles the trade, earning another 1% fee from the settlement operation.
  4. Summary:
    • If the user is the taker when placing the order:
      • User profit = 1% (order) + 1% (settlement) = 2%
      • fee_account loss = 1.2% (maker fee) - 1% (taker fee rebate) = 0.2%
    • If the user is the maker when placing the order:
      • User loss = 1.2% (maker fee) - 1% (settlement rebate) = 0.2%
      • fee_account gains 1.2% maker fee

In the first case, the user gains a large profit (2%). If the second case occurs, the loss is limited to only 0.2%. By repeatedly placing orders (e.g., 10 times), the user only needs to be the taker once to offset all losses and still profit, effectively draining value from the fee_account.

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 settlement fee calculation only considers the taker fee and ignores the maker fee, so when the taker fee rate is negative, the total fee becomes negative and the fee account loses funds.

Impact

The rewards from the fee account can be stolen under certain conditions, potentially draining value from the fee account.

What the attacker needed

Negative taker fee rate; positive maker fee rate; ability to place and settle orders

The fix

The settlement fee calculation should charge both the taker and maker fees to ensure the total fee is not negative and to prevent losses to the fee account.

How it was found

  1. Assume the user's taker fee rate is negative and maker fee rate is positive.
  2. The user places an order and immediately settles it.
  3. If the user is the taker when placing the order, they receive a fee rebate on the order and another rebate on settlement, while the fee account loses the difference between the maker fee and the taker rebate.
  4. By repeating this process, the user can offset any losses and drain value from the fee account.

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 trading, a taker is someone who places an order that matches an existing one, and a maker is someone whose order is waiting to be matched. Each pays a fee, which can be positive (you pay) or negative (you receive a rebate). The bug is that when a trade is settled, the code only charges the taker fee, so if the taker fee is negative, the user gets money from the fee account without paying the maker fee, allowing them to profit unfairly.

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.