This critical vulnerability has been identified in the momentumUpdateRule.sol contract where the scalar computation of weights does not enforce non-negative constraints but the vector computation does. The implementation allows weight calculations to result in negative values, which is fundamentally incompatible with AMM (Automated Market Maker) operations.
Affected segment of code: https://github.com/Cyfrin/2024-12-quantamm/blob/a775db4273eb36e7b4536c5b60207c9f17541b92/pkg/pool-quantamm/contracts/rules/MomentumUpdateRule.sol#L97-L136
The issue is demonstrated in the provided proof of concept where weight calculations can produce negative values due to insufficient bounds checking. The test case shows that under certain market conditions and parameter configurations, specifically:
Using a scalar kappa of 0.8e18
With lambda set to 0.2e18
When there is a significant price divergence between assets
Initial weights of 0.5e18 for both assets
The calculation results in a negative weight of approximately -0.78e18 for one asset and 1.78e18 for the other, which violates fundamental AMM invariants.
Paste the following code into the QuantAMMMomentum.t.sol file
The presence of negative weights in an AMM system can have severe consequences:
Pool Invariant Violation: AMMs rely on constant product or similar invariants that assume positive weights. Negative weights break these fundamental assumptions.
Incorrect Price Formation: Negative weights lead to invalid price calculations, potentially causing:
Erroneous trade executions
Incorrect slippage calculations
Manipulation opportunities for attackers
Economic Implications:
Destabilized pool economics
System Instability:
Undefined behavior in core AMM functions
Potential for cascading failures in dependent protocols
Risk of permanent pool imbalance
Manual code review
Implement Weight Bounds:
_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.