In the VectorRuleQuantAMMStorage contract, the _quantAMMUnpack128Matrix function is used for unpacking matrix data used in covariance calculations:
This function is called by QuantAMMCovarianceBasedRule during covariance matrix updates:
The validation is flawed because it only checks if _sourceArray.length * 2 >= _numberOfAssets * _numberOfAssets. This means an attacker could provide an oversized array that passes validation but contains excess data that would be incorrectly unpacked into the covariance matrix. For example, if a 2x2 matrix requires a source array of length 2, an attacker could pass an array of length 3 that would pass validation but cause incorrect unpacking.
Given that these matrices directly determine price calculations through the covariance update formula:
An attacker could manipulate the AMM's pricing by providing malformed matrix data that passes the loose validation.
The implementation assumes that having sufficient data length is adequate protection, not considering that excess data could corrupt the matrix operations used for price calculations.
An attacker wants to manipulate the AMM's price calculations. They observe that a 2x2 covariance matrix is being used for a specific trading pair. The matrix should have a source array of length 2, but they provide an array of length 3. The extra element contains carefully crafted data.
When calling the pool's update function, their array passes validation since 32 >= 22 (the current check). The unpacking function processes this oversized array, incorrectly incorporating the extra data into the covariance matrix. This corrupted matrix is then used in the next price calculation, causing the AMM to calculate incorrect prices for the trading pair.
Implement exact size validation using ceiling division for odd-sized matrices:
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.