First Flight #18: T-Swap

First Flight #18
Beginner FriendlyDeFiFoundry
100 EXP
View results
Submission Details
Severity: medium
Valid

`TSwapPool::deposit` is missing deadline check, causing transactions to complete even after the deadline

Summary

The deposit function accepts a deadline parameter, which according to the natspec is "The deadline for the transaction to be completed by". However, this parameter is never used. As a consequence, operations that add liquidity to the pool might be executed at unexpected times, in market conditions where the deposit rate is unfavorable.

Impact

The deadline parameter is unused. Transactions could be sent when market conditions are unfavorable (due to a MEV attack or regular usage) to deposit, even when adding a deadline parameter.

Proof of Concept

Include this test in TSwapPool.t.sol:

function testDepositIsMissingADeadlineCheck() public {
// Liquidity provider adds liquidity to the pool
testDeposit();
// The user specifies a max deadline for the deposit to happen
uint64 deadline = uint64(block.timestamp + 5 minutes);
// The transaction stays pending longer than specified in the deadline parameter and goes through
vm.warp(block.timestamp + 30 minutes);
// We assert than the current block.timestamp is greater than the deadline
assert(block.timestamp > deadline);
vm.startPrank(user);
poolToken.approve(address(pool), 1e18);
weth.approve(address(pool), 1e18);
// The user tries to deposit with a deadline in the past
uint256 liquidityTokensMinted = pool.deposit(1e18, 1e18, 1e18, deadline);
// Deposit goes through even though the deadline has passed, and liquidity tokens are minted
assert(liquidityTokensMinted > 0);
}

Tools Used

Foundry and manual review

Recommendations

Consider making the following change to the function.

function deposit(
uint256 wethToDeposit,
uint256 minimumLiquidityTokensToMint,
uint256 maximumPoolTokensToDeposit,
uint64 deadline
)
external
revertIfZero(wethToDeposit)
+ revertIfDeadlinePassed(deadline)
returns (uint256 liquidityTokensToMint)
Updates

Appeal created

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

`deposit` is missing deadline check causing transactions to complete even after the deadline

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.