The QuantAMM storage contract silently normalizes stored values using undocumented thresholds. Values between 1e9 and 2e9 are normalized to 1e9, and values below 1e9 are silently zeroed. This affects all values stored using this mechanism, including both pool weights and prices, potentially leading to unexpected pool behavior when oracle-provided values fall within these ranges.
Location: pkg/pool-quantamm/contracts/QuantAMMStorage.sol
The issue occurs in the storage encoding/decoding process where values are scaled by 1e9 during packing/unpacking operations. The critical code paths are:
Packing (storing values):
Unpacking (retrieving values):
The combination of:
int32 bounds (±2.147e9)
1e9 scaling factor
Bit shifting operations
Silent truncation
Creates several issues:
Values that don't cleanly divide by 1e9 lose precision
Values outside int32 bounds after scaling are truncated
The truncation happens silently without warning or events
Test results demonstrate the behavior:
This behavior affects all operations using the storage contract, including pool weights and price calculations.
Test Results:
Severity: HIGH
Justification:
Impact: HIGH
Complete zeroing of values below 1e9
Silent normalization of values between 1e9 and 2e9 to 1e9
Affects both weights and prices in the pool
No events or warnings when values are modified
Could lead to significant pool imbalances
Breaks core AMM invariants
Likelihood: MEDIUM
Occurs whenever oracle values fall in affected ranges
No validation or bounds checking on oracle inputs
Multiple values affected (both weights and prices)
Silent failure mode makes detection difficult
No recovery mechanism once values are corrupted
Technical Impact:
Silent normalization of values between 1e9 and 2e9 to 1e9
Complete zeroing of values below 1e9
No events emitted for value modifications
No reversion on unexpected values
Affects all stored values including weights and prices
Economic Impact:
Incorrect price calculations due to normalized/zeroed values
Pool imbalances from incorrect weight ratios
Loss of precision in both weight and price calculations
Potential for significant economic loss if oracle values consistently fall in affected ranges
While direct manipulation isn't possible (oracle-controlled), the impact when it occurs is severe
Note: While oracle manipulation is out of scope, the silent failure mode of the storage contract when handling valid oracle values represents a significant risk to the protocol's core functionality.
Foundry testing framework
Manual code review
Custom test suite for storage behavior
Console logging for value verification
Add Explicit Value Validation:
Implementation Changes:
Add explicit validation before packing/unpacking operations
Emit events for any value modifications
Document the valid ranges and behavior in comments
Consider using a different scaling factor to avoid precision loss
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.