QuantAMM

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

Arithmetic Underflow in Loops

Summary

In onAfterRemoveLiquidity function, there is a potential for arithmetic underflow in the loop iterating over the feeDataArray when processing liquidity removal. This issue arises from the use of a decrementing loop that does not properly handle the underflow condition for a uint256 variable. This can lead to unintended behavior, including infinite loops and out-of-bounds access.

Vulnerability Details

In the onAfterRemoveLiquidity the issue is found in the line of code below

>> for (uint256 i = localData.feeDataArrayLength - 1; i >= 0; --i) {
localData.lpTokenDepositValue = feeDataArray[i].lpTokenDepositValue;
  • The loop initializes i to localData.feeDataArrayLength - 1, which is the last valid index of the feeDataArray.

  • When i reaches 0, the next decrement (--i) causes i to underflow, wrapping around to 2^256 - 1.

  • This results in an infinite loop, as the condition i >= 0 will always evaluate to true for unsigned integers.

Impact

The contract may become unresponsive, consuming gas indefinitely, which can lead to denial of service for users attempting to interact with the contract.

Tools Used

Manual Review

Recommendations

Modify the loop to start from localData.feeDataArrayLength and check that i is greater than 0 to prevent underflow.

//...SNIP...
- for (uint256 i = localData.feeDataArrayLength - 1; i >= 0; --i) {
+ for (uint256 i = localData.feeDataArrayLength; i > 0; --i) {
//...SNIP...
}
Updates

Lead Judging Commences

n0kto Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

invalid_onAfterRemoveLiquidity_loop_underflow

That’s definitely not the best way to handle that but there is indeed no impact. If someone tries to get more than their deposits, it must revert, and thanks to that "fancy mistake"(or genius code ?), it does.

Support

FAQs

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

Give us feedback!