Trade order sizes are not validated properly
The settle_trade_v2 function only checks the top-level trade size and never validates the maker_order.size or taker_order.size fields inside the trade request. An attacker could submit a malformed trade whose internal order sizes are invalid, which the contract would still process, potentially causing inconsistency between the UI and the smart contract.
- Disclosed after under an hour
#46960 [SC-Insight] trade order sizes are not validated properly
Submitted on Jun 6th 2025 at 18:09:03 UTC by @gln for IOP | Paradex
- Report ID: #46960
- Report Type: Smart Contract
- Report severity: Insight
- Target: https://github.com/tradeparadex/audit-competition-may-2025/tree/main/paraclear
- Impacts:
Description
Brief/Intro
The function settle_trade_v2 does not verify maker_order.size and taker_order.size fields.
Vulnerability Details
Function settle_order_v2 takes a TradeRequestV2 struct as an argument, struct is defined like this:
#[derive(Copy, Drop, Serde, Debug, PartialEq)]
pub struct OrderV2 {
pub account: ContractAddress,
pub market: felt252,
pub side: felt252,
pub orderType: felt252,
pub size: felt252,
pub price: felt252,
pub signature_timestamp: felt252,
pub is_reduce_only: bool,
}
#[derive(Copy, Drop, Serde, Debug, PartialEq)]
pub struct TradeRequestV2 {
pub id: felt252,
pub size: felt252,
pub price: felt252,
pub traded_at: felt252,
pub maker_order: OrderV2,
pub taker_order: OrderV2,
}
Let's see at the code of this function from paraclear.cairo:
fn settle_trade_v2(ref self: ContractState, trade: TradeRequestV2) -> felt252 {
self._assert_only_executor();
let is_maker_order_reduce_only = trade.maker_order.is_reduce_only;
let is_taker_order_reduce_only = trade.taker_order.is_reduce_only;
1) assert(trade.size.into() > 1_u256, Errors::TRADE_SIZE_TOO_SMALL);
let traded_at: u64 = trade.traded_at.try_into().unwrap();
assert(traded_at > 0_u64, Errors::TRADE_TIME_INVALID);
assert(
trade.maker_order.market == trade.taker_order.market, Errors::TRADE_MARKET_MISMATCH,
);
assert(
trade.maker_order.account != trade.taker_order.account, Errors::TRADE_SAME_ACCOUNT,
);
assert(trade.maker_order.side != trade.taker_order.side, Errors::TRADE_SAME_SIDE);
let delegate = self.Paraclear_market_delegate.read(trade.maker_order.market);
if (delegate.is_non_zero()) {
let res = IParaclearDispatcher { contract_address: delegate }
.settle_trade_v2(trade);
return res;
}
...
}
- This the only line where trade.size is checked.
Notice that trade.maker_order.size and trade.taker_order.size fields are not checked at all.
Impact Details
Orders with invalid internal size fields might be processed by Paradex. It may introduce inconsistency between UI and smart contract.
Proof of Concept
Proof of Concept
How to reproduce:
To reproduce, we create a malformed trade request with invalid maker_order.size and taker_order.size fields and verify settle_trade_v2() call was successfull.
- add test to tests/test_paraclear_trades.cairo, see gist link - https://gist.github.com/gln7/fabee7f76d681c64ba5892c168d339c7
- run test:
$ snforge test test_settle_trade_issue
...
Collected 1 test(s) from paradex_paraclear package
Running 1 test(s) from tests/
XXXXKE settle_trade_v2 result 1
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
The settle_trade_v2 function validates only the top-level trade.size and omits any check on the nested maker_order.size and taker_order.size fields.
Impact
Orders with invalid internal size fields might be processed, which may introduce inconsistency between the UI and the smart contract; the report does not claim direct loss of funds.
What the attacker needed
Ability to submit a trade request; executor role or delegated call path
The fix
The contract should also validate maker_order.size and taker_order.size before settling a trade.
How it was found
- Add a test to the trades test file that builds a malformed trade request with invalid maker and taker order sizes.
- Run the test with the project's test runner.
- Observe that the settle_trade_v2 call succeeds despite the invalid sizes.
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 is a program that runs on a blockchain and handles things like trades. This one accepts a trade request containing several size values, but it only checks one of them and trusts the others without looking. That means someone could send a trade with nonsense sizes inside and the contract would still accept it.
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.