QuantAMM

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

`intermediateGradientStates` is setting wrong in the function `QuantAMMGradientBasedRule::_calculateQuantAMMGradient`.

Summary

The QuantAMMGradientBasedRule::_calculateQuantAMMGradient function calculates the new weights using the price gradients. However, the calculated weights are being set at the wrong indexes in the state variable.

Vulnerability Details

intermediateGradientStates[_poolParameters.pool][i] = _quantAMMPackTwo128(
locals.intermediateGradientState[i],
locals.secondIntermediateValue
);

Here, the i variable iterates with i = i + 2, causing one index to be skipped each time. As a result, the weights are stored incorrectly in the array, resulting in a pattern like this: [w1, 0, w2, 0, w3, 0, w4]. This is incorrect, and the wrong values are being updated in the state variable intermediateGradientStates.

Impact

The incorrect assignment of values in the state variable leads to inaccurate calculations, which can result in losses for both the protocol and its users.

Tools Used

Manual Review

Recommendations

To fix this issue, ensure the correct index is used for setting values in the intermediateGradientStates array. Use a separate storage index to avoid skipping array elements.

Suggested Fix

- intermediateGradientStates[_poolParameters.pool][i] = _quantAMMPackTwo128(
locals.intermediateGradientState[i],
locals.secondIntermediateValue
);
+ intermediateGradientStates[_poolParameters.pool][locals.storageArrayIndex] = _quantAMMPackTwo128(
locals.intermediateGradientState[i],
locals.secondIntermediateValue
);

Explanation of Fix

  • Replace the direct use of i as the index with locals.storageArrayIndex.

Updates

Lead Judging Commences

n0kto Lead Judge 10 months ago
Submission Judgement Published
Validated
Assigned finding tags:

finding_gradient_rules_more_than_3_assets_and_1_lambda_will_DoS_the_update

Likelihood: Medium/High, assets>4, lambdas > 1. Impact: Medium/High, DoS update but pool works fine. Pool with 5 assets will use incorrect weights.

Appeal created

nikhil20 Submitter
10 months ago
n0kto Lead Judge
9 months ago
n0kto Lead Judge 9 months ago
Submission Judgement Published
Validated
Assigned finding tags:

finding_gradient_rules_more_than_3_assets_and_1_lambda_will_DoS_the_update

Likelihood: Medium/High, assets>4, lambdas > 1. Impact: Medium/High, DoS update but pool works fine. Pool with 5 assets will use incorrect weights.

Support

FAQs

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