QuantAMM

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

Weight Calculations by Misaligned Price in the `_getWeights` Function of the `AntiMomentumUpdateRule.sol` Contract from its Corresponding Whitepaper

Summary

In the _getWeights function of the AntiMomentumUpdateRule.sol contract. The code implementation has use different price to calculate price gradient(∂p̅(t)/∂t) and price change rate(1/p(t)·∂p(t)/∂t) from its corresponding whitepaper as shown below:

Code: w(t) = w(t-1) + κ·(ℓp(t) - 1/p(t)·∂p̅(t)/∂t),or w(t) = w(t-1) + κ·(ℓp(t) - 1/p̅(t)·∂p̅(t)/∂t)
White paper: w(t) = w(t-1) + κ·(ℓp(t) - 1/p̅(t)·∂p(t)/∂t)

The use of moving average prices in gradient calculation introduces a “double smoothing” effect, delaying the reaction to actual market changes. And the flexibility to toggle between raw and moving average prices introduces unnecessary complexity and deviates from the whitepaper’s guidelines.

Vulnerability Details

Issue 1: Calculation of Price Gradient Using Moving Average Prices

  • Finding: The implementation uses moving average prices (p̄(t)) to compute price gradients (∂p(t)/∂t), while the whitepaper specifies raw prices (p(t)) for this calculation.

  • Root Cause: The use of moving average prices in gradient calculation introduces a “double smoothing” effect, delaying the reaction to actual market changes. Using smoothed prices for gradients compromises the strategy’s ability to respond to short-term market dynamics, reducing effectiveness and potentially leading to suboptimal decision-making.

Issue 2: Use of Moving Average Price in the Denominator

  • Finding: The implementation uses a conditional flag (useRawPrice) to determine whether to use raw prices or moving average prices in the denominator. This contradicts the whitepaper, which explicitly specifies the use of moving average prices (p̄(t)) for stability.

  • Root Cause: The flexibility to toggle between raw and moving average prices introduces unnecessary complexity and deviates from the whitepaper’s guidelines. Allowing raw prices in the denominator can increase sensitivity to noise and short-term price spikes, leading to potential overreaction and instability.

pkg/pool-quantamm/contracts/rules/AntimomentumUpdateRule.sol:_getWeights#L71-L77

/// @param _prevWeights the previous weights retrieved from the vault
/// @param _data the latest data from the signal, usually price
/// @param _parameters the parameters of the rule that are not lambda
/// @param _poolParameters pool parameters [0]=kappa can be per token (vector) or single for all tokens (scalar), [1][0]=useRawPrice
/// @notice w(t) = w(t − 1) + κ ·(ℓp(t) − 1/p(t) · ∂p(t)/∂t) where ℓp(t) = 1/N * ∑(1/p(t)i * (∂p(t)/∂t)i)
function _getWeights(
int256[] calldata _prevWeights,
int256[] memory _data,
int256[][] calldata _parameters,
QuantAMMPoolParameters memory _poolParameters
) internal override returns (int256[] memory newWeightsConverted) {
...
locals.newWeights = _calculateQuantAMMGradient(_data, _poolParameters);
// @audit uses moving average prices (`p̄(t)`) to compute price gradients (∂p(t)/∂t), while the whitepaper specifies raw prices (`p(t)`) for this calculation
for (locals.i = 0; locals.i < _prevWeights.length; ) {
locals.denominator = _poolParameters.movingAverage[locals.i];
if (locals.useRawPrice) {
locals.denominator = _data[locals.i];
}
// @audit uses a conditional flag (`useRawPrice`) to determine whether to use raw prices or moving average prices in the denominator, while the denominators use moving average prices (`p̄(t)`) for stability in the whitepaper.
...

Impact

  • Using raw prices for gradient calculations improves the timeliness and accuracy of market signals.

  • Adhering to moving average prices in the denominator enhances stability, reducing unnecessary noise and volatility in weight adjustments.

  • Deviating from whitepaper specifications increases the risk of overfitting to specific market conditions, compromising robustness in broader scenarios. Failing to adhere to the whitepaper’s guidelines undermines the trustworthiness of the implementation and its alignment with theoretical foundations.

Tools Used

Manual Review

Recommendations

  1. Use Raw Prices for Gradient Calculation:

    • Adjust _calculateQuantAMMGradient to compute gradients based on raw prices (p(t)), reflecting real-time market changes as intended by the whitepaper.

  2. Clear Explanations for useRawPrice Option in Denominator:

    • Update the relevant sections in useRawPrice option with clear explanations for the use of price types in different contexts to enhance code maintainability to ensure compliance with the whitepaper.

Updates

Lead Judging Commences

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

Support

FAQs

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

Give us feedback!