QuantAMM

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

Precision Loss in QuantAMM's Gradient Calculations Compromises Core Portfolio Rebalancing Strategies

Description

The gradient calculation in QuantAMMGradientBasedRule.sol performs numerical operations in a suboptimal order that can lead to significant precision loss and potential overflows/underflows:

https://github.com/Cyfrin/2024-12-quantamm/blob/a775db4273eb36e7b4536c5b60207c9f17541b92/pkg/pool-quantamm/contracts/rules/base/QuantammGradientBasedRule.sol#L41

locals.mulFactor = oneMinusLambda.pow(THREE).div(convertedLambda);
locals.finalValues[i] = locals.mulFactor.mul(locals.intermediateValue);

The issue lies in computing (1-λ)³/λ as a separate factor before multiplication with the intermediate value. This ordering is problematic because:

  1. Computing (1-λ)³ first can lead to overflow when λ is small

  2. Subsequent division by λ further amplifies numerical instability

  3. Precision loss occurs due to intermediate rounding in fixed-point arithmetic

Impact

This numerical instability fundamentally compromises the core mathematical infrastructure across QuantAMM's entire suite of trading strategies. In the Anti-Momentum strategy, where precise gradient calculations are essential for determining mean reversion signals, the imprecise computation of (ℓp(t) − 1/p(t) · ∂p(t)/∂t) can lead to incorrect weight adjustments, potentially causing the strategy to move against its intended mean-reverting behavior.

The precision loss propagates differently through each strategy type. In the Momentum strategy, the distorted gradient calculations affect price momentum detection, particularly during periods of high volatility where precise signal detection is crucial. The Channel Following strategy suffers compound effects, as both its trend-following and mean-reverting components rely on accurate gradient computations for determining optimal position boundaries and adjustment magnitudes.

The Power Channel strategy is particularly vulnerable due to its use of power transformations on gradient values. The initial numerical instability becomes amplified through these power operations, making channel boundary detection increasingly unreliable as the exponent increases. This instability is especially pronounced when dealing with higher volatility assets or during market stress periods.

The economic impacts extend beyond mere mathematical imprecision. During periods of market volatility, when precise rebalancing is most crucial, the weight adjustments can become erratic due to accumulated numerical errors. This compromises the protocol's MEV resistance mechanisms and exposes LPs to increased impermanent loss through suboptimal rebalancing. The protocol's fundamental ability to maintain mathematically optimal portfolio weights becomes unreliable, potentially undermining its core value proposition of sophisticated on-chain portfolio management.

Recommended Mitigation Steps

// Reorder calculations to maintain precision
locals.finalValues[i] = locals.intermediateValue
.mul(oneMinusLambda.pow(THREE))
.div(convertedLambda);

This fix:

  1. Reduces intermediate value magnification

  2. Maintains precision through fixed-point operations

  3. Minimizes risk of overflow/underflow

  4. Preserves mathematical equivalence

  5. Works consistently across all strategy implementations

The fix should be applied with high priority as it affects core portfolio rebalancing mechanics across all strategy types.

Updates

Lead Judging Commences

n0kto Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational or Gas / Admin is trusted / Pool creation is trusted / User mistake / Suppositions

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelyhood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.

Support

FAQs

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