A vulnerability in the AMM weight adjustment logic (_getWeights) within the DifferenceMomentumUpdateRule.sol file allows weights to become negative under certain conditions when scalar logic is used, even though the function is designed to maintain non-negative weights. The issue arises due to insufficient bounds checking in the momentum-based weight adjustment calculation. This vulnerability is triggered when handling significant price divergences and unbalanced initial weights. Notably, this issue is effectively mitigated in the vector-based logic is employed.
The vulnerability exists in the weight calculation logic within the _getWeights function. The core issue lies in this calculation:
The function fails to properly validate that the resulting weight remains positive after applying the momentum adjustment. This becomes particularly problematic when:
Initial weights are significantly unbalanced (e.g., 0.1e18 vs 0.8e18)
There are large price divergences between assets
The kappa parameter amplifies the momentum effect
The vulnerability was confirmed through the following test scenario:
weights: [0.1e18, 0.8e18]
Price data: [2, 7] (3.5x difference)
Moving averages: All initialized to [1, 1] for short and [2, 2] for long
Kappa: 1.0 (scalar)
Lambda short: 0.9
Paste the following code into QuantAMMDifferenceMomentum.t.sol file
The ability to generate negative weights in an AMM system can lead to:
Pool Instability: Negative weights can cause incorrect price calculations and pool imbalances
Potential Economic Exploits: Traders could potentially exploit these negative weights for arbitrage opportunities
System Malfunction: Many AMM functions assume weights are positive, potentially leading to system-wide failures
Loss of Funds: In extreme cases, negative weights could lead to incorrect swap calculations and loss of user funds
Foundry Framework for testing
Manual code review
Implement Strict Weight Validation:
_clampWeights will check that these weights are positive and in the boundaries before writing them in storage.
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.