QuantAMM

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

Precision loss in DifferenceMomentumUpdateRule.

Summary

In DifferenceMomentumUpdateRule.sol, precision loss occurs along with the possibility of the exponentially weighted moving average (EWMA) portion changing to ‘0’ when the EWMA(long) exceeds ‘1’.

Vulnerability Details

In the function _getWeights of DifferenceMomentumUpdateRule contract, for the computation of ((EWMA_short - EWMA_long) / EWMA_long), reciprocal of EWMA_long is computed and then this is multiplied with (EWMA_short - EWMA_long).

https://github.com/Cyfrin/2024-12-quantamm/blob/a775db4273eb36e7b4536c5b60207c9f17541b92/pkg/pool-quantamm/contracts/rules/DifferenceMomentumUpdateRule.sol#L105

locals.newWeights[locals.i] = ONE.div(locals.denominator).mul(locals.newWeights[locals.i]);

The issue with this approach is (i) precision loss (ii) the reciprocal will be ‘0’ the moment EWMA_long crosses ONE.

Tools Used

Manual review

Recommended Mitigation

Consider doing direct division. The suggested line #105 can be modified as

locals.newWeights[locals.i] = (locals.newWeights[locals.i]) .div(locals.denominator);
Updates

Lead Judging Commences

n0kto Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Known issue
Assigned finding tags:

invalid_Rules_getWeights_precision_loss_div_mul

## [Low-24] Divide before multiply

Support

FAQs

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