Error in Unpack Operation Causes Failure When requiresPrevAverage
is True
The CalculateNewWeights
function exposed an error when handling pools where requiresPrevAverage
is true. This issue arises due to incorrect handling of moving averages during unpacking by the _quantAMMUnpack128Array
function. Specifically, when previous averages are required, the unpacking logic fails, leading to index out-of-bound
errors. This causes the performUpdate function to fail after the first execution, resulting in a denial of service (DoS) for affected pools.
Here's the implementation of CalculateNewWeights
function of UpdateRule
contract:
Root Issue
In weighted pools using the minimum variance rule, the contract stores both the current and previous moving averages. These values are packed into a 128 array and stored in movingAverages[pool]
. When the performUpdate function is called, it fetches the packed data and invokes the CalculateNewWeights
function to determine new weights for the pool.
When requiresPrevAverage
is true, the previous average is included in the packed data, effectively doubling its length (e.g., from 2 to 4 for a two-asset pool). However, the _quantAMMUnpack128Array
function fails to correctly handle this scenario, resulting in an index out-of-bound
error during unpacking. This prevents the performUpdate function from being successfully executed after the initial call, halting all subsequent updates for affected pools.
This vulnerability causes a Denial of Service (DoS) for all pools using the minimum variance rule with requiresPrevAverage = true
. Notably, after the first call to performUpdate, subsequent updates fail due to unpacking errors, making the pools inoperable.
This disrupts pool rebalancing and weight adjustments, potentially leading to financial losses and system inefficiencies.
Manual Review
To address this issue, the _quantAMMUnpack128Array
function should be updated to correctly handle cases where the packed data includes both current and previous averages.
Likelihood: Medium, all rules using previous average. Impact: High, DoS CalculateNewWeights
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.