QuantAMM

QuantAMM
49,600 OP
View results
Submission Details
Severity: high
Invalid

Missing or Improper Fee Application in Swap Logic

Summary

In the onSwap function there is no explicit handling of fees apart from a comment that says:
// Fees are added after scaling happens, to reduce the complexity of the rounding direction analysis.

Vulnerability Details

  • For Exact-In Swap:

uint256 amountOutScaled18 = WeightedMath.computeOutGivenExactIn(
request.balancesScaled18\[request.indexIn],
tokenInWeight,
request.balancesScaled18\[request.indexOut],
tokenOutWeight,
request.amountGivenScaled18
);
  • The function calculates the amount of the output token the user will receive given their output. However, no explicit mention of fees is included in this calculation.

  • For Exact-Out Swap:

uint256 amountInScaled18 = WeightedMath.computeInGivenExactOut(
request.balancesScaled18[request.indexIn],
tokenInWeight,
request.balancesScaled18[request.indexOut],
tokenOutWeight,
request.amountGivenScaled18
);

The function calculates the amount of input tokens the user must provide to receive a specific amount of output tokens. Again no explicit handling of fees is included here.

The comment i provided above about fees implies that fees are added after scaling process but there is no visible implementation in the function

Impact

  • Absence of fees application can cause:
    Zero or reduced revenue:
    If fees are missing, the pool collects no revenue from swaps causing LPs to lose out on their expected returns.
    Economic Exploitation:
    Without fees, traders (especially arbitrageurs) can execute swaps at a much lower cost, extracting value from the pool with minimal penalties.
    Protocol Vulnerability:
    If fees are improperly applied, the protocol might not distribute them fairly among LPs leading to dissatisfaction and liquidity withdrawal.

Tools Used

Manual Review

Recommendations

Includes Fees in the Swap Logic
For Exact-In Swaps, after calculating amountOutScaled18, fees should be deducted from the output amount.
While for Exact-Out Swaps, before calculating amountInScaled18, fees should be added to the input amount

Use a Fee parameter
Define a feePercentage variable as it is done here in this code snippet:

uint256 private constant _MIN_SWAP_FEE_PERCENTAGE = 0.001e16; // 0.001%
uint256 private constant _MAX_SWAP_FEE_PERCENTAGE = 10e16; // 10%

Make sure the fee is applied consistently in both the Exact-In and Exact-Out calculations.

Updates

Lead Judging Commences

n0kto Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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