Summary
Calculation error in contract QuantammGradientBasedRule.sol function_calculateQuantAMMGradient variable
`mulFactor`
https://github.com/Cyfrin/2024-12-quantamm/blob/a775db4273eb36e7b4536c5b60207c9f17541b92/pkg/pool-quantamm/contracts/rules/base/QuantammGradientBasedRule.sol#L41
QuantAMMGradientBasedRule contract calculates gradients for QuantAMM rules that use covariance matrices to calculate the new weights of a pool
this function is abstract so this inherited and implemented to be used and other contract.
Vulnerability Details
if (_poolParameters.lambda.length == 1) {
unchecked {
@> locals.mulFactor = oneMinusLambda.pow(THREE).div(convertedLambda);
if (notDivisibleByTwo) {
--numberOfAssetsMinusOne;
}
}
Impact:
Miscalculation to the whole protocol weight calculation and more contract is dependent on this calculation.
Tools Used
Manual Review
Recommendations
This is right calculation is recommanded check this out:
if (_poolParameters.lambda.length == 1) {
unchecked {
- locals.mulFactor = oneMinusLambda.pow(THREE).div(convertedLambda);
+ locals.mulFactor = convertedLambda.pow(THREE).div(oneMinusLambda);
if (notDivisibleByTwo) {
--numberOfAssetsMinusOne;
}
}