Insufficient Time Validation in function settle_trade_v2
The settle_trade_v2 function only checks that a trade's timestamp is greater than zero, without comparing it to the current block time. An attacker could submit trades with old or future timestamps, potentially replaying stale trades or executing them at favourable moments.
- Disclosed after under an hour
#46675 [SC-Insight] Insufficient Time Validation in function settle_trade_v2
Submitted on Jun 3rd 2025 at 08:40:59 UTC by @Catchme for IOP | Paradex
- Report ID: #46675
- Report Type: Smart Contract
- Report severity: Insight
- Target: https://github.com/tradeparadex/audit-competition-may-2025/tree/main/paraclear
- Impacts:
- Griefing (e.g. no profit motive for an attacker, but damage to the users or the protocol)
- Contract fails to deliver promised returns, but doesn't lose value
Description
Brief/Intro
The settle_trade_v2 function in Paraclear has a timestamp validation vulnerability. The function only checks if the trade timestamp is greater than zero (traded_at > 0_u64), without verifying that it's recent or valid relative to the current block time. This enables various time-based attacks including trade replay attacks, stale trade execution, and price manipulation that could lead to direct financial losses for users through unfair trade execution and potential theft of funds.
Vulnerability Details
The vulnerable code exists in the settle_trade_v2 function:
let traded_at: u64 = trade.traded_at.try_into().unwrap();
assert(traded_at > 0_u64, Errors::TRADE_TIME_INVALID);
This validation is severely inadequate for several reasons:
- No recency check: The function doesn't compare
traded_atwith the current block timestamp to ensure the trade is recent. As long astraded_at > 0, any timestamp (even from years ago) would be accepted. - No maximum age enforcement: There is no mechanism to enforce a maximum staleness period for trades. This means executors can hold onto trades and execute them much later when market conditions are favorable to them.
- No protection against future timestamps: Since there's no upper bound check, trade timestamps set in the future would also be accepted.
Impact Details
- Trade Replay Attacks: An attacker could potentially resubmit old trades, especially if IDs can be reused or manipulated. This would result in unauthorized duplicate trades.
- Price Manipulation: By holding onto trades and executing them at opportune moments with manipulated oracle data, a malicious executor could generate artificial profits at the expense of users.
Proof of Concept
Proof of Concept
let trade_request = TradeRequestV2 {
id: 1000,
size: 2_u128.into(),
price: 800000_u128.into(),
traded_at: 11111111111, // history timestamp
maker_order: OrderV2 {
account: maker_account,
market: market,
side: SELL_SIDE,
orderType: 0,
size: 2_u128.into(),
price: 800000_u128.into(),
signature_timestamp: get_block_timestamp().into(),
is_reduce_only: false,
},
taker_order: OrderV2 {
account: taker_account,
market: market,
side: BUY_SIDE,
orderType: 0,
size: 2_u128.into(),
price: 800000_u128.into(),
signature_timestamp: get_block_timestamp().into(),
is_reduce_only: false,
},
};
The attacker calls settle_trade_v2 with this trade:
paraclear.settle_trade_v2(manipulated_trade);
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 missing comparison between the trade timestamp and the current block timestamp, allowing any positive value to pass validation.
Impact
An attacker could potentially replay old trades or execute them at opportune moments, leading to unfair trade execution and possible financial loss for users.
What the attacker needed
Ability to call settle_trade_v2
The fix
The function should be fixed by comparing the trade timestamp against the current block time and enforcing a maximum allowed age and rejecting future timestamps.
How it was found
- Construct a trade request with a historical timestamp.
- Call settle_trade_v2 with the crafted trade.
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 function that settles trades checks the trade's timestamp but only to see if it is above zero. It never checks whether that timestamp is close to the current time. This means someone could send a trade with a very old or future timestamp 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.