The QuantAMMVarianceBasedRule contract handles negative prices extremely asymmetrically compared to positive prices, leading to severely distorted variance calculations. While ChainlinkOracle enforces positive prices (require(data > 0)), negative prices can still occur through the project's MultiHopOracle which performs mathematical operations that may result in negative values. This asymmetry (441.5x amplification) causes massive imbalances in all variance-based weight calculations and could severely impact pools using MultiHopOracle or similar oracles that support negative prices.
Location: pkg/pool-quantamm/contracts/rules/base/QuantammVarianceBasedRule.sol
The issue occurs in the variance calculation where negative prices produce extremely asymmetric results compared to equivalent positive prices:
When handling negative prices (which can occur through MultiHopOracle's mathematical operations), the sign propagation in the squared difference calculation causes extreme amplification of the variance values.
Test Results:
Note that the asymmetry (441.5x amplification) is extreme and directly affects all variance-based rules. This explains the larger asymmetries seen in MinimumVarianceUpdateRule (4.1%) compared to non-variance rules like AntiMomentumUpdateRule (1.7%).
Extreme asymmetric variance calculations (441.5x larger for negative prices)
Severe distortion of all variance-based weight calculations
Could lead to massive pool imbalances
Creates significant arbitrage opportunities
Compounds through intermediate state storage
Affects multiple rules (Minimum/Maximum Variance)
Breaks mathematical invariants for variance calculations
Modify variance calculation to use absolute values:
Consider architectural improvements:
Add explicit variance sign handling
Implement variance symmetry validation
Add variance-specific invariant checks
Consider using unsigned values for variance
Add documentation about variance calculation expectations
Consider extracting variance calculation to a library
Add safeguards against extreme variance values
Add comprehensive tests:
Test variance symmetry with various price magnitudes
Test edge cases with extreme price values
Add property-based tests for variance calculations
Test variance state evolution over time
Test compounding effects through intermediate state
Test interactions with all variance-based rules
Add specific tests for negative price scenarios
Multihop will call ChainlinkOracle and the check is in it: `require(data > 0, "INVLDDATA");` MultiHop is just here to combine Chainlinks feed when there is no direct USD price feed for a token.
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.