The QuantAMMCovarianceBasedRule contract handles negative prices asymmetrically compared to positive prices, leading to distorted covariance matrix calculations. While ChainlinkOracle enforces positive prices (require(data > 0)), negative prices can occur through the project's MultiHopOracle which performs mathematical operations that may result in negative values. This asymmetry (4.4% difference) causes imbalances in all covariance-based weight calculations and could impact pools using MultiHopOracle or similar oracles that support negative prices.
Location: pkg/pool-quantamm/contracts/rules/base/QuantammCovarianceBasedRule.sol
The issue occurs in the covariance calculation where negative prices produce asymmetric results compared to equivalent positive prices:
When handling negative prices, the sign propagation in the outer product calculation (u_i * v_j) causes asymmetric covariance values. For example, with identical magnitude price deviations but opposite signs:
Positive price deviation: covariance[0][0] = 4.800
Negative price deviation: covariance[0][0] = 5.010
Asymmetry: 4.4% difference
Test Results:
Asymmetric covariance calculations (4.4% difference for equivalent price movements)
Distortion of covariance-based weight calculations
Could lead to pool imbalances
Creates arbitrage opportunities
Compounds through intermediate state storage
Affects multiple rules that use covariance matrices
Breaks mathematical invariants for covariance calculations
Modify covariance calculation to handle signs correctly:
Consider architectural improvements:
Add explicit covariance sign handling
Implement covariance symmetry validation
Add covariance-specific invariant checks
Consider using absolute values for price differences
Add documentation about covariance calculation expectations
Consider extracting covariance calculation to a library
Add safeguards against extreme covariance values
Add comprehensive tests:
Test covariance symmetry with various price magnitudes
Test edge cases with extreme price values
Add property-based tests for covariance calculations
Test covariance state evolution over time
Test compounding effects through intermediate state
Test interactions with all covariance-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.