QuantAMM

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

Reverse Index Iteration Safety Issue

Summary

[https://github.com/Cyfrin/2024-12-quantamm/blob/a775db4273eb36e7b4536c5b60207c9f17541b92/pkg/pool-hooks/contracts/hooks-quantamm/UpliftOnlyExample.sol#](https://github.com/Cyfrin/2024-12-quantamm/blob/a775db4273eb36e7b4536c5b60207c9f17541b92/pkg/pool-hooks/contracts/hooks-quantamm/UpliftOnlyExample.sol#L471

Vulnerability Details

In the onAfterRemoveLiquidity() function, there is a code snippet written as follows:

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

In Solidity 0.8 and above, when a uint256 value decrements below 0, it triggers an underflow, causing the contract to revert. This introduces a Denial of Service (DoS) risk. For example, if feeDataArrayLength == 1, during the first iteration of the loop, i would be 0. Decrementing i (--i) would then result in an underflow, causing the contract to revert. This means users would be unable to withdraw liquidity or execute related logic.

This issue could be maliciously exploited in the following ways:
Exploitation Method: If an attacker can manipulate the contract into a state where there is only one or very few FeeData records, requiring reverse iteration, they could effectively block legitimate users from successfully calling the function. This could lead to a partial or complete contract “freeze.”

Impact

Users would be unable to withdraw liquidity, and project teams might need to urgently upgrade or apply special handling to resolve the issue. This would cause severe usability problems.

While this does not fall under the category of “fund theft” attacks, it constitutes a critical denial-of-service attack. On the mainnet, if contract logic contains similar flaws, the contract could become frozen in certain scenarios, preventing the execution of critical operations. This would result in significant financial losses and reputational damage.

Tools Used

Recommendations

To safely perform reverse iteration, it is recommended to use the following pattern:

for (uint256 i = feeDataArray.length; i > 0; i--) {
uint256 index = i - 1;
...
}

This ensures that no underflow occurs, thereby mitigating the risk of such DoS vulnerabilities.

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.