A vulnerability exists in the _quantAMMUnpack128Array function's core logic within the ScalarRuleQuantAMMStorage contract. The function incorrectly unpacks 128-bit integers that represent pool weights, variances, and gradients by double-incrementing array indices, leading to data corruption.
The vulnerability specifically appears in this code section:
This function is critical because it's used throughout the QuantAMM system for unpacking:
Pool weights in gradient calculations (used in QuantAMMGradientBasedRule.sol)
Variance values (used in QuantAMMVarianceBasedRule.sol)
Intermediate states for mathematical calculations
The double increment causes a cascading failure across the system's core mathematical functions. In the gradient calculations, the corrupted unpacking leads to incorrect weight positions:
Similarly, in variance calculations, the unpacking error propagates through the variance state management:
The corruption manifests in two critical ways: First, pool weights end up in incorrect positions, which directly corrupts price calculations and swap amounts in the AMM's core pricing functions. Second, since variance calculations rely on properly ordered values, the risk assessment mechanism receives corrupted data sequences. Eventually, as the index skipping continues, array bounds are exceeded, leading to memory corruption that can crash transactions entirely.
When pool weights are unpacked into incorrect positions, it directly corrupts the gradient-based price calculations and variance assessments. This corruption propagates through every swap operation, causing severe miscalculation of token amounts and prices. Since the function also handles unpacking of intermediate states for variance calculations, risk assessment mechanisms receive corrupted data sequences, leading to incorrect pool behavior under varying market conditions. The severity is amplified by memory corruption when skipped indices eventually exceed array bounds, potentially crashing transactions and freezing pool operations. This represents a critical failure point that compromises both the financial accuracy and operational stability of the entire AMM system.
Remove the second increment of targetIndex and only increment after successfully writing a value:
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.