code-423n4 / 2024-04-panoptic-findings

9 stars 4 forks source link

`CollateralTracker` lacks slippage protection in `redeem()` and `withdraw()` functions #411

Closed c4-bot-4 closed 5 months ago

c4-bot-4 commented 6 months ago

Lines of code

https://github.com/code-423n4/2024-04-panoptic/blob/833312ebd600665b577fbd9c03ffa0daf250ed24/contracts/CollateralTracker.sol#L591-L626 https://github.com/code-423n4/2024-04-panoptic/blob/833312ebd600665b577fbd9c03ffa0daf250ed24/contracts/CollateralTracker.sol#L531-L566

Vulnerability details

Description

Users (who previously deposited assets) can withdraw and redeem their assets via functions withdraw() or redeem() at 1:1 ratio on a normal circumstance. Meaning, they are expecting an amount of at least equal to the amount that they have deposited.

However there will be occasions where their assets "withdrawals / redemptions" might be less than what they originally deposited. That scenario happens when the vault experiences losses.

Here's a scenario where the losses happen:

If only Alice knew that this will happen, she might have opted to wait until the assets goes back to at least 1:1 ratio to at least redeem back her original deposit amount. Without slippage protection, Alice has to suffer these losses.

This principle also applies to withdraw() but with a slight difference.

In redeem() the input (fixed) amount of shares is exchanged with assets. When losses occur, these fixed amount shares will produce lesser assets.

In withdraw() the input (fixed) amount of assets will cause to burn more shares to get the same asset amount which also in itself a loss.

Impact

Without slippage protection on redeem() and withdraw() functions, users will lose funds in the event of vault loss that suddenly happens in the middle of the redeem / withdraw transactions.

Proof of Concept

Tools Used

Manual Review

Recommended Mitigation Steps

Implement a function with the same name redeem / withdraw (to still be compliant with ERC4626 but with different set of parameters) but add parameters minAssets and maxShares respectively.

Assessed type

Other

c4-judge commented 5 months ago

Picodes marked the issue as duplicate of #365

c4-judge commented 5 months ago

Picodes changed the severity to QA (Quality Assurance)