QuantAMM

QuantAMM
49,600 OP
View results
Submission Details
Severity: low
Invalid

Incorrect normalizationFactor used when kappa vector length exceeds number of assets due to insufficient validation

Summary

In multiple update rule contracts (MomentumUpdateRule, PowerChannelUpdateRule, DifferenceMomentumUpdateRulem AntiMomentumUpdateRule), the validParameters function does not validate that the kappa vector length matches the number of assets. This can lead to incorrect normalization factor calculations when summing kappa values, as the function may sum more kappa values than there are assets.

Vulnerability Details

In MomentumUpdateRule and other update rules, when using vector kappa mode, the normalization factor calculation sums all kappa values:

// MomentumUpdateRule.sol
if (locals.kappaStore.length == 1) {
// scalar case...
} else {
// vector case
int256 sumKappa;
for (locals.i = 0; locals.i < locals.kappaStore.length; ) { // @audit uses kappaStore.length
sumKappa += locals.kappaStore[locals.i];
unchecked {
++locals.i;
}
}
locals.normalizationFactor = locals.normalizationFactor.div(sumKappa);
// Later uses _prevWeights.length for weight updates
for (locals.i = 0; locals.i < _prevWeights.length; ) {
locals.res = int256(_prevWeights[locals.i]) +
locals.kappaStore[locals.i].mul(locals.newWeights[locals.i] - locals.normalizationFactor);
// ...
}
}

The issue arises in case that there are more kappa values in kappaStore than there is assets. This is possible because validParameters doesn't validate kappa vector length - it only checks that kappa values are greater than 0:

function validParameters(
int256[][] calldata _parameters
) external pure override returns (bool) {
if (
_parameters.length == 1 ||
(_parameters.length == 2 && _parameters[1].length == 1)
) {
int256[] memory kappa = _parameters[0];
uint16 valid = uint16(kappa.length) > 0 ? 1 : 0;
for (uint i; i < kappa.length; ) {
if (!(kappa[i] > 0)) {
valid = 0;
break;
}
unchecked {
++i;
}
}
return valid == 1;
}
return false;
}

Example scenario:

  1. Pool has 3 assets

  2. Rule's kappa vector is initialized with 4 values: [1e18, 1e18, 1e18, 1e18]

  3. In weight update process, normalization will sum all 4 kappas = 4e18

  4. But weight updates only use first 3 values

  5. Results in incorrect normalization factor: dividing by 4 instead of 3

Impact

I consider this medium severity because:

  1. Leads to incorrect weight calculations due to wrong normalization factor used

  2. Affects core pool feature of correctly updating the weights

  3. It is a silent issue - there will be no failures or reverts, but weight calculations will be consistently off

Tools Used

Manual review

Recommendations

Add kappa vector length validation in validParameters, or when summing the sumKappa number of iterations should go up to the number of assets in pool.

Updates

Lead Judging Commences

n0kto Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational or Gas / Admin is trusted / Pool creation is trusted / User mistake / Suppositions

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelyhood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.