The gradient calculation in QuantAMMGradientBasedRule.sol performs numerical operations in a suboptimal order that can lead to significant precision loss and potential overflows/underflows:
The issue lies in computing (1-λ)³/λ as a separate factor before multiplication with the intermediate value. This ordering is problematic because:
Computing (1-λ)³ first can lead to overflow when λ is small
Subsequent division by λ further amplifies numerical instability
Precision loss occurs due to intermediate rounding in fixed-point arithmetic
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.
This fix:
Reduces intermediate value magnification
Maintains precision through fixed-point operations
Minimizes risk of overflow/underflow
Preserves mathematical equivalence
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.
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.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.