Failure in _calculateQuantAMMVariance
Function While Handling Odd Number of Assets
The _calculateQuantAMMVariance
function contains an error when handling pools with an odd number of assets. Specifically, it fails to decrement locals.nMinusOne
when lambda is a vector, unlike when lambda is a scalar. This inconsistency results in an out-of-bounds error, causing a Denial of Service (DoS) in operations like CalculateNewWeights
.
The _calculateQuantAMMVariance
function in the QuantammVarianceBasedRule
contract is responsible for computing:
The new intermediate state for the variance update.
The new variances vector based on the intermediate state.
Here's the implementation:
Root Cause
When lambda is a scalar and the pool has an odd number of assets, locals.nMinusOne
is correctly decremented to handle the odd index.
However, when lambda is a vector, the same decrement is not applied, leading to a discrepancy.
This results in an out-of-bounds error when the function attempts to access _poolParameters.lambda[locals.nMinusOne]
.
Denial of Service (DoS):
The function fails with an out-of-bounds revert, disrupting critical operations such as CalculateNewWeights.
Pools with odd-numbered assets and vector lambda are especially vulnerable.
Operational Failures:
Any operations relying on _calculateQuantAMMVariance will fail, rendering the pool unable to dynamically adjust weights or perform variance updates.
Manual Review
To resolve the issue, add a decrement for locals.nMinusOne
when lambda is a vector, ensuring consistent behavior.
Likelihood: Medium/High, odd asset number + lambda is a vector. Impact: Medium/High, DoS the update.
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.