The _setInitialMovingAverages function of QuantammMathMovingAverage contract and lacks proper validation when setting initial moving averages. This could lead to incorrect initialization of moving averages if the provided data does not match the expected number of assets.
The _setInitialMovingAverages function uses a conditional statement with a logical OR (||) operator to check two conditions:
If movingAverageLength is 0, indicating that there are no existing moving averages for the specified pool.
If the length of _initialMovingAverages matches _numberOfAssets.
Due to the nature of short-circuit evaluation in logical expressions, if the first condition (movingAverageLength == 0) evaluates to true, the second condition (_initialMovingAverages.length == _numberOfAssets) is never evaluated. This means that the function can proceed to set moving averages if there are no existing moving averages for the specified pool without validating whether the provided initial averages correspond to the expected number of assets.
The function may set moving averages with an incorrect number of values if _initialMovingAverages does not match _numberOfAssets if there are no existing moving averages for the specified pool. This can result in inconsistent or invalid state within the contract.
Manual Review
Ensure both conditions are independently validated. Use an && operator to enforce that both movingAverageLength == 0 and _initialMovingAverages.length == _numberOfAssets must be true before setting the moving averages.
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.
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.