Skip to content
Business logic Audit finding Intermediate

Missing deadline param in swapExactAmountOut() allowing outdated slippage and allow pending transaction to be executed unexpectedly

The swap functions in the liquidation router and pair lack a deadline parameter, so a transaction can be held by a validator and executed later at a worse price. This could cause users or the protocol to lose funds due to outdated slippage.

SanketKogekar Follow with bin2chen, MohammedRizwan and 2 others

Originally disclosed on Code4rena

Submitted by SanketKogekar, also found by bin2chen, MohammedRizwan, cartlex_, and piyushshukla

https://github.com/GenerationSoftware/pt-v5-cgda-liquidator/blob/7f95bcacd4a566c2becb98d55c1886cadbaa8897/src/LiquidationRouter.sol#L63-L80 https://github.com/GenerationSoftware/pt-v5-cgda-liquidator/blob/7f95bcacd4a566c2becb98d55c1886cadbaa8897/src/LiquidationPair.sol#L211-L226

Loss of funds/tokens for the protocol, since block execution is delegated to the block validator without a hard deadline.

Proof of Concept

The function swapExactAmountOut() from LiquidationRouter.sol and LiquidationPair.sol use these methods to swap tokens:

source.liquidate(_account, tokenIn, swapAmountIn, tokenOut, _amountOut);

and

_liquidationPair.swapExactAmountOut(_receiver, _amountOut, _amountInMax);

https://github.com/GenerationSoftware/pt-v5-cgda-liquidator/blob/7f95bcacd4a566c2becb98d55c1886cadbaa8897/src/LiquidationPair.sol#L211-L226

https://github.com/GenerationSoftware/pt-v5-cgda-liquidator/blob/7f95bcacd4a566c2becb98d55c1886cadbaa8897/src/LiquidationRouter.sol#L63-L80

Both methods make sure to pass slippage (minimum amount out), but miss to provide the deadline which is crucial to avoid unexpected trades/losses for users and protocol.

Without a deadline, the transaction might be left hanging in the mempool and be executed way later than the user wanted.

That could lead to users/protocol getting a worse price, because a validator can just hold onto the transaction. And when it does get around to putting the transaction in a block

One part of this change is that PoS block proposers know ahead of time if they’re going to propose the next block. The validators and the entire network know who’s up to bat for the current block and the next one.

This means the block proposers are known for at least 6 minutes and 24 seconds and at most 12 minutes and 48 seconds.

Further reading: https://blog.bytes032.xyz/p/why-you-should-stop-using-block-timestamp-as-deadline-in-swaps

Recommended Mitigation Steps

Let users provide a fixed deadline as param, and also never set deadline to block.timestamp.

asselstine (PoolTogether) confirmed

hickuphh3 (judge) commented:

The main argument here is the user will lose out on positive slippage if the exchange rate becomes favourable when the tx is included in a block.

As to why it’s Medium severity: when the value lost is guaranteed to be very large and preventing the mistake has a very low cost, it is reasonable to assign a medium risk rating. The closer the cost/benefit ratio gets to zero, the more likely the issue should be rated QA.


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

The swap functions omit a deadline parameter, allowing transactions to be executed at any future time.

Impact

A validator could hold a transaction and include it later, causing the user or protocol to receive a worse price and lose funds.

What the attacker needed

User initiates a swap; validator can delay transaction

The fix

The swap functions should accept a user-provided deadline parameter, and the deadline should never be set to block.timestamp.

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.

When you swap tokens, you usually set a deadline so the trade fails if it is not confirmed in time. Here, the swap functions did not have that deadline, so a miner could delay the transaction and execute it when the price is worse for you.

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 SanketKogekar

View all

1 more disclosed report, best first.

More from PoolTogether

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.