jennifer37 - swap may be reverted if the input amount is not large enough, especially for low decimal tokens #52
Labels
Has Duplicates
A valid issue with 1+ other issues describing the same vulnerability
Medium
A Medium severity issue.
Reward
A payout will be made for this issue
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Will Fix
The sponsor confirmed this issue will be fixed
jennifer37
Medium
swap may be reverted if the input amount is not large enough, especially for low decimal tokens
Summary
The swap fees will be sent to the
externalBribe
. If the calculated swap fee is round down to zero, possible in low decimal tokens, the swap transaction will be reverted becauseexternalBribe
does not accept 0 fee.Vulnerability Detail
In swap(), the swap fees will be calculated based on the token's input amount. If the pool has one gauge, the swap fees will be sent to the
externalBribe::notifyRewardAmount()
.The vulnerability is that function
notifyRewardAmount
will be reverted if the fee amount is zero and the pool contract will send the swap fee if the inputAmount is larger than 0. So if theamount0In
oramount1In
is larger than 0 and the calculated swap fee is 0, the swap will be reverted.The above scenario is unlikely triggered when the input token's decimal is high, for example 18. But when it comes to low decimal, it's possible.
For example:
GUSD, as one stable coin, it's decimal is 2. Checking the default swap fee ratio from the pariFactory, the default stable pool's swap fee ratio is 0.03%. Imagine we swap 30 dollar GUSD(3000GUSD) into another token, the swap fee will be zero.
Poc
Add the below test case into FeesToBribes.t.sol. The test case will be reverted.
Impact
Pools with low decimal tokens may be reverted if the swap amount is not large enough.
Code Snippet
https://github.com/sherlock-audit/2024-06-velocimeter/blob/main/v4-contracts/contracts/Pair.sol#L295-L336
Tool used
Manual Review
Recommendation
If the calculated fee is 0, do not need to send fees to the
externalBribe
The text was updated successfully, but these errors were encountered: