The DifferenceMomentumUpdateRule contract handles negative prices asymmetrically compared to positive prices, leading to inconsistent weight calculations. This asymmetry is significantly larger than both MomentumUpdateRule and AntiMomentumUpdateRule, with a delta of 0.0875 (compared to 0.01875 and 0.017 respectively). 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 could cause severe pool imbalances in pools using MultiHopOracle or similar oracles that support negative prices.
Location: pkg/pool-quantamm/contracts/rules/DifferenceMomentumUpdateRule.sol
The issue occurs in the weight calculation where negative prices produce asymmetric results compared to equivalent positive prices:
When handling negative prices (which can occur through MultiHopOracle's mathematical operations), the sign propagates through multiple calculations affecting both the normalization factor and final weights. The asymmetry is amplified by the dual moving average system (MACD-style calculation).
Test Results:
Note that the asymmetry (0.0875) is significantly larger than in both MomentumUpdateRule (0.01875) and AntiMomentumUpdateRule (0.017). The weight difference is more than 8.7%, which could lead to substantial pool imbalances.
Severe asymmetric weight calculations for positive vs negative prices
Largest asymmetry among all momentum-based rules (0.0875 or 8.7%)
Inconsistent pool behavior depending on price sign
Could lead to significant weight distribution imbalances
May create substantial arbitrage opportunities due to predictable asymmetry
Breaks mathematical symmetry expected in price calculations
Could compound with other weight calculation issues
Particularly concerning due to interaction between short and long-term moving averages amplifying the asymmetry
Modify price handling to maintain symmetry:
Consider architectural improvements:
Add explicit sign handling throughout calculations
Implement symmetry validation in tests
Add invariant checks for price sign handling
Consider using absolute values for intermediate calculations
Add documentation about price sign handling expectations
Consider extracting common price handling logic to a shared library
Add specific checks for MACD-style calculations with negative prices
Add comprehensive tests:
Test symmetry with various price magnitudes
Test edge cases with extreme price values
Add property-based tests for price sign handling
Test interactions between short and long moving averages
Test compounding effects over multiple updates
Test interactions with other momentum-based rules
Add specific tests for MACD divergence 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.