QuantAMM

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

QuantAMMWeightedPool cannot be initialized

Summary

QuantAMMWeightedPool will revert when initialize() is called.

Vulnerability Details

When a QuantAMMWeightedPool is initialized, _setInitialWeights() is called with initialWeights as parameter. Each weight is checked to be valid, but this is done incorrectly: the function reverts whenever an initialWeights[i] < absoluteWeightGuardRail; however according to natspec this variable is the maximum allowed weight (not the minimum), so that the condition for reverting should be exactly the opposite:

///@dev Maximum absolute weight allowed.
uint64 public absoluteWeightGuardRail;

Impact

Impact is critical as pools can never be initialized with valid values, breaking the expected behaviour of the system.

Tools Used

Remix, manual testing

Recommendations

Update the condition for reverting only when maximum allowed weight is exceeded:

function _setInitialWeights(int256[] memory _weights) internal {
require(_normalizedFirstFourWeights == 0, "init");
require(_normalizedSecondFourWeights == 0, "init");
InputHelpers.ensureInputLengthMatch(_totalTokens, _weights.length);
int256 normalizedSum;
int256[] memory _weightsAndBlockMultiplier = new int256[]();
for (uint i; i < _weights.length; ) {
- if (_weights[i] < int256(uint256(absoluteWeightGuardRail))) {
+ if (_weights[i] > int256(uint256(absoluteWeightGuardRail))) {
- revert MinWeight();
+ revert MaxWeight();
}
_weightsAndBlockMultiplier[i] = _weights[i];
normalizedSum += _weights[i];
//Initially register pool with no movement, first update will come and set block multiplier.
_weightsAndBlockMultiplier[i + _weights.length] = int256(0);
unchecked {
++i;
}
}
// Ensure that the normalized weights sum to ONE
if (uint256(normalizedSum) != FixedPoint.ONE) {
revert NormalizedWeightInvariant();
}
if (_weightsAndBlockMultiplier.length > 8) {
int256[][] memory splitWeights = _splitWeightAndMultipliers(_weightsAndBlockMultiplier);
_normalizedFirstFourWeights = quantAMMPack32Array(splitWeights[0])[0];
_normalizedSecondFourWeights = quantAMMPack32Array(splitWeights[1])[0];
} else {
_normalizedFirstFourWeights = quantAMMPack32Array(_weightsAndBlockMultiplier)[0];
}
//struct allows one SSTORE
poolSettings.quantAMMBaseInterpolationDetails = QuantAMMBaseInterpolationVariables({
lastPossibleInterpolationTime: uint40(block.timestamp), //given muliplier is 0 on start
lastUpdateIntervalTime: uint40(block.timestamp)
});
emit WeightsUpdated(address(this), _weights);
}
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.

Give us feedback!