The QuantAMM system's matrix packing mechanism has a significant vulnerability in the _quantAMMPack128Matrix function where matrix elements are lost during packing operations for odd-sized matrices. This issue directly affects the covariance calculations that are critical for the AMM's operation.
Here's the problematic code in VectorRuleQuantAMMStorage:
The issue occurs because when packing an odd-sized matrix (for example, a 3x3 matrix with 9 elements), the function maintains a leftInt value that is meant to be paired with the next element. However, when processing the final element, it ignores any stored leftInt and simply writes the last value alone. This manifests in the covariance calculations:
The loss of matrix elements during packing operations has direct consequences for the QuantAMM's price calculations. When processing odd-sized covariance matrices, the function drops one element (the stored leftInt) when handling the final value. In a 3x3 matrix for example, element 8 would be lost when processing element 9. This missing data creates a systemic error in the covariance calculations used by _calculateQuantAMMCovariance(), leading to skewed price calculations and incorrect pool weight adjustments. While the pattern of data loss is consistent and predictable, its effect on pricing compounds over time as the corrupted covariance matrix continues to influence trading decisions. The silent nature of this error and its direct impact on pricing calculations makes this a significant risk to the AMM's core operation.
Modify the final element handling to consider unpacked values:
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.