QuantAMM

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

`ChannelFollowingUpdateRule` implementation differs from the protocol Whitepaper.

Vulnerability Details

ChannelFollowingUpdateRule is the logic for calculating the new weights of a QuantAMM pool using the channel following strategy.

When calculating the TrendPortion in _getWeights(), we scale the price_gradient like this:
abs(price_gradient) / (2 * preExpScaling)

If we look at the whitepaper:
alt text

The scaledAbsGradient should not be done for trend calculation which is a redundant and undefined step done in the calculation of the weights. We just need the price_gradient in the trend portion formula.

function _getWeights(
int256[] calldata _prevWeights,
int256[] memory _data,
int256[][] calldata _parameters,
QuantAMMPoolParameters memory _poolParameters
) internal override returns (int256[] memory newWeightsConverted) {
...
...
else {
int256 widthSquared = locals.width[locals.i].mul(locals.width[locals.i]);
envelope = (-gradientSquared.div(widthSquared.mul(TWO))).exp();
// Calculate scaled price gradient: π * price_gradient / (3 * width)
int256 scaledGradient = PI.mul(locals.newWeights[locals.i]).div(locals.width[locals.i].mul(THREE));
// Calculate channel portion
channelPortion = locals
.amplitude[locals.i]
.mul(envelope)
.mul(scaledGradient - scaledGradient.mul(scaledGradient).mul(scaledGradient).div(SIX))
.div(locals.inverseScaling[locals.i]);
// Calculate trend portion
int256 absGradient = locals.newWeights[locals.i] >= 0
? locals.newWeights[locals.i]
: -locals.newWeights[locals.i];
@> int256 scaledAbsGradient = absGradient.div(locals.preExpScaling[locals.i].mul(TWO));
// abs(price_gradient) / (2 * preExpScaling)
// @audit this shouldn't be done a/c to the whitepaper
trendPortion = _pow(scaledAbsGradient, locals.exponents[locals.i]);
// |scaledAbsGradient / (2 * preExpScaling)|^exponent
}
...
...
}

Impact

ChannelFollowingUpdateRule will update the weights wrongly as if differs from the whitepaper specification.

Tools Used

Manual Review.

Recommendations

We recommend to change necessary formula according to the whitepaper only.

Updates

Lead Judging Commences

n0kto Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement
Assigned finding tags:

invalid_ChannelFollowingUpdateRule_whitepaper_incorrect_implementation

The formula here is the one in Whitepaper page 11, which is right and the division is explained on the last line : "Finally note …".

Support

FAQs

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